예제 #1
0
        public static void Sensor(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Sensor Widget");
            CrossLogger.Current.Debug("Sensor", "Creating Sensor Widget");

            Models.Sitemap.Widget3      item = null;
            Dictionary <string, string> widgetKeyValuePairs = null;

            //Master Grid for Widget
            Grid Widget_Grid = new Grid
            {
                RowDefinitions = new RowDefinitionCollection {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
                RowSpacing        = 0,
                ColumnSpacing     = 0,
                BackgroundColor   = App.Config.CellColor,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
            };

            grid.Children.Add(Widget_Grid, px, px + sx, py, py + sy);

            try
            {
                item = data.ToObject <Models.Sitemap.Widget3>();
                widgetKeyValuePairs = Helpers.SplitCommand(item.Label);

                App.TrackItem i = new App.TrackItem
                {
                    Grid   = Widget_Grid,
                    Name   = item.Item.Name,
                    Header = header,
                    Icon   = widgetKeyValuePairs["icon"],
                    State  = item.Item.State,
                    Type   = Itemtypes.Sensor
                };
                App.Config.Items.Add(i);

                Sensor_update(true, i);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Sensor", "Sensor crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #2
0
        public static void Music(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Music Widget");
            CrossLogger.Current.Debug("Music", "Creating Music Widget");

            Models.Sitemap.Widget3      item = null;
            Dictionary <string, string> widgetKeyValuePairs = null;

            try
            {
                item = data.ToObject <Models.Sitemap.Widget3>();
                widgetKeyValuePairs = Helpers.SplitCommand(item.Label);

                App.TrackItem i = new App.TrackItem
                {
                    //Grid = grid,
                    Name   = item.Item.Name,
                    Header = header,
                    Icon   = widgetKeyValuePairs["icon"],
                    State  = item.Item.State,
                    Type   = Itemtypes.Sensor
                };
                App.Config.Items.Add(i);

                Music_update(true, i);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Music", "Sensor crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #3
0
파일: Sitemap.cs 프로젝트: ralle12345/Kala
        public static Models.Sitemaps.Sitemap GetActiveSitemap(string SitemapName)
        {
            Models.Sitemaps.Sitemaps sitemaps = new RestService().ListSitemaps();

            if (sitemaps != null && sitemaps.sitemap != null)
            {
                //Loop through each sitemap
                foreach (Models.Sitemaps.Sitemap s in sitemaps.sitemap)
                {
                    Dictionary <string, string> keywords = Helpers.SplitCommand(s.label);
                    if (keywords != null && keywords.ContainsKey("kala") && keywords["kala"].Contains("true"))
                    {
                        if (s.name.Equals(SitemapName))
                        {
                            CrossLogger.Current.Info("Kala", "Label: " + s.label);
                            CrossLogger.Current.Info("Kala", "Name: " + s.name);
                            CrossLogger.Current.Info("Kala", "Link: " + s.link);

                            return(s);
                        }
                    }
                }
            }

            return(null);
        }
예제 #4
0
        public static void Dimmer(Grid grid, string x1, string y1, string header, JObject data)
        {
            int px = 0;
            int py = 0;

            Models.Sitemap.Widget3      item = null;
            Dictionary <string, string> widgetKeyValuePairs = null;

            //If this fails, we dont know where to show an error
            try
            {
                item = data.ToObject <Models.Sitemap.Widget3>();
                widgetKeyValuePairs = Helpers.SplitCommand(item.label);
                CrossLogger.Current.Debug("Dimmer", "Label: " + widgetKeyValuePairs["label"]);

                px = Convert.ToInt16(x1);
                py = Convert.ToInt16(y1);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Dimmer", "Widgets.Switch crashed: " + ex.ToString());
            }

            try
            {
                //Slider button
                Button dimmerButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                    StyleId           = item.item.link //StyleID is not used on buttons
                };
                dimmerButton.Clicked += OnDimmerButtonClicked;
                CrossLogger.Current.Debug("Dimmer", "Button ID: " + dimmerButton.Id + " created.");
                grid.Children.Add(dimmerButton, px, py);

                App.trackItem i = new App.trackItem
                {
                    grid   = grid,
                    px     = px,
                    py     = py,
                    header = header,
                    state  = item.item.state,
                    unit   = widgetKeyValuePairs["unit"],
                    icon   = widgetKeyValuePairs["icon"],
                    link   = item.item.link,
                    type   = Models.Itemtypes.Dimmer
                };
                App.config.items.Add(i);

                Dimmer_update(true, i);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Dimmer", "Widgets.Switch crashed: " + ex.ToString());
                Error(grid, px, py, ex.ToString());
            }
        }
예제 #5
0
파일: Sensor.cs 프로젝트: ralle12345/Kala
        public static void Sensor(Grid grid, string x1, string y1, string x2, string y2, string header, JObject data)
        {
            CrossLogger.Current.Debug("Sensor", "Creating Sensor Widget");

            int px = 0;
            int py = 0;
            int sx = 0;
            int sy = 0;

            //If this fails, we don't know where to show the error
            try
            {
                px = Convert.ToInt16(x1);
                py = Convert.ToInt16(y1);
                sx = Convert.ToInt16(x2);
                sy = Convert.ToInt16(y2);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Sensor", "Crashed: " + ex.ToString());
            }

            Models.Sitemap.Widget3      item = null;
            Dictionary <string, string> widgetKeyValuePairs = null;

            try
            {
                item = data.ToObject <Models.Sitemap.Widget3>();
                widgetKeyValuePairs = Helpers.SplitCommand(item.label);

                App.trackItem i = new App.trackItem
                {
                    grid   = grid,
                    px     = px,
                    py     = py,
                    sx     = sx,
                    sy     = sy,
                    link   = item.item.link,
                    header = header,
                    icon   = widgetKeyValuePairs["icon"],
                    state  = item.item.state,
                    type   = Itemtypes.Sensor
                };
                App.config.items.Add(i);

                Sensor_update(true, i);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Sensor", "Sensor crashed: " + ex.ToString());
                Error(grid, px, py, ex.ToString());
            }
        }
예제 #6
0
파일: Sitemap.cs 프로젝트: johnjore/Kala
        public static Models.Sitemaps.Sitemap GetActiveSitemap(string SitemapName)
        {
            Models.Sitemaps.Sitemaps sitemaps = new RestService().ListSitemaps();

            if (sitemaps != null && sitemaps.Sitemap != null)
            {
                //Loop through each sitemap
                foreach (Models.Sitemaps.Sitemap s in sitemaps.Sitemap)
                {
                    if (s.Label.Contains("kala=true") && (Helpers.SplitCommand(s.Label) != null) && (s.Name.Equals(SitemapName)))
                    {
                        CrossLogger.Current.Info("Kala", "Label: " + s.Label);
                        CrossLogger.Current.Info("Kala", "Name: " + s.Name);
                        CrossLogger.Current.Info("Kala", "Link: " + s.Link);

                        return(s);
                    }
                }
            }

            return(null);
        }
예제 #7
0
파일: Sitemap.cs 프로젝트: johnjore/Kala
        /// <summary>
        /// Parse Sitemap file
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseSitemap(Models.Sitemap.Sitemap items)
        {
            try
            {
                foreach (Models.Sitemap.Widget page in items.Homepage.Widgets)
                {
                    CrossLogger.Current.Debug("Kala", "Label: " + page.Label);

                    //Populate Page, if it contains elements to parse
                    if (page.Label != string.Empty)
                    {
                        Dictionary <string, string> pageKeyValuePairs = Helpers.SplitCommand(page.Label);
                        CrossLogger.Current.Debug("Kala", "Label: " + pageKeyValuePairs["label"]);

                        #region page
                        if (page.LinkedPage != null)
                        {
                            if (pageKeyValuePairs.ContainsKey("sx") && pageKeyValuePairs.ContainsKey("sy") && pageKeyValuePairs.ContainsKey("label"))
                            {
                                if (!pageKeyValuePairs.ContainsKey("icon"))
                                {
                                    pageKeyValuePairs.Add("icon", null);
                                }

                                CrossLogger.Current.Debug("Kala", "Sitemap - Create Grid using: " + pageKeyValuePairs["label"] + ", " + pageKeyValuePairs["sx"] + ", " + pageKeyValuePairs["sy"] + ", " + pageKeyValuePairs["icon"]);
                                Grid grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], pageKeyValuePairs["icon"]);

                                foreach (Models.Sitemap.Widget3 item in page.LinkedPage.Widgets)
                                {
                                    ParseWidgets(grid, item);
                                }
                            }
                        }
                        #endregion page
                        else
                        {
                            CrossLogger.Current.Warn("Kala", "Unknown: " + ToString());

                            switch (pageKeyValuePairs["widget"].ToUpper())
                            {
                            case "SITEMAP":
                                CrossLogger.Current.Debug("Kala", "Sitemap:" + pageKeyValuePairs["name"]);

                                Models.Sitemaps.Sitemap sitemaps = GetActiveSitemap(pageKeyValuePairs["name"]);
                                if (sitemaps != null)
                                {
                                    Sitemap sitemap = new Sitemap();
                                    sitemap.CreateSitemap(sitemaps);

                                    CrossLogger.Current.Debug("Kala", "Got ActiveSitemap");
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Sitemap", "ParseSitemap() crashed: " + ex.ToString());
            }
        }
예제 #8
0
파일: Voice.cs 프로젝트: dragonxu/Kala
        public static void Voice(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Voice Widget");

            try
            {
                Models.Sitemap.Widget3      item = data.ToObject <Models.Sitemap.Widget3>();
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                CrossLogger.Current.Debug("Voice", "Label: " + widgetKeyValuePairs["label"]);

                //Master Grid for Widget
                Grid Widget_Grid = new Grid
                {
                    RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        }
                    },
                    ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    },
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                };
                grid.Children.Add(Widget_Grid, px, px + sx, py, py + sy);

                //Header
                Widget_Grid.Children.Add(new Label
                {
                    Text                    = header,
                    FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                    TextColor               = App.Config.TextColor,
                    BackgroundColor         = App.Config.CellColor,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start
                }, 0, 0);

                //Background
                Widget_Grid.Children.Add(new ShapeView()
                {
                    ShapeType         = ShapeType.Circle,
                    StrokeColor       = App.Config.ValueColor,
                    Color             = App.Config.ValueColor,
                    StrokeWidth       = 10.0f,
                    Scale             = 2,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center
                }, 0, 0);

                //Image
                Widget_Grid.Children.Add(new Image
                {
                    Source            = widgetKeyValuePairs["icon"],
                    Aspect            = Aspect.AspectFill,
                    BackgroundColor   = Color.Transparent,
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center
                }, 0, 0);

                //Button must be added last
                var voiceButton = new VoiceButton
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    StyleId           = item.Item.Name //StyleID not used on buttons
                };
                Widget_Grid.Children.Add(voiceButton, 0, 0);

                voiceButton.OnTextChanged += (s) =>
                {
                    Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Voice", "Text: " + s));
                    Task.Run(async() =>
                    {
                        await new RestService().SendCommand(voiceButton.StyleId, s);
                    });
                };
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Voice", "Widgets.Voice crashed: " + ex.ToString());
                Error(grid, px, py, 1, 1, ex.ToString());
            }
        }
예제 #9
0
파일: Launcher.cs 프로젝트: dragonxu/Kala
        public static void Launcher(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Launcher Widget");

            try
            {
                Models.Sitemap.Widget3      item = data.ToObject <Models.Sitemap.Widget3>();
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                CrossLogger.Current.Debug("Launcher", "Label: " + widgetKeyValuePairs["label"]);

                //Master Grid for Widget
                Grid Widget_Grid = new Grid
                {
                    RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        }
                    },
                    ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    },
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                };

                //Header
                Widget_Grid.Children.Add(new Label
                {
                    Text                    = header,
                    FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                    TextColor               = App.Config.TextColor,
                    BackgroundColor         = App.Config.CellColor,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start
                }, 0, 0);

                //Circle
                Widget_Grid.Children.Add(new ShapeView()
                {
                    ShapeType         = ShapeType.Circle,
                    StrokeColor       = App.Config.ValueColor,
                    Color             = App.Config.ValueColor,
                    StrokeWidth       = 10.0f,
                    Scale             = 2,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center
                }, 0, 0);

                //Image
                Widget_Grid.Children.Add(new Image
                {
                    Source            = widgetKeyValuePairs["icon"],
                    Aspect            = Aspect.AspectFill,
                    BackgroundColor   = Color.Transparent,
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center
                }, 0, 0);

                //Button must be last to be added to work
                Button launcherButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                    StyleId           = widgetKeyValuePairs["url"] //StyleID is not used on buttons
                };
                Widget_Grid.Children.Add(launcherButton, 0, 0);
                launcherButton.Clicked += OnLauncherButtonClicked;
                CrossLogger.Current.Debug("Launcher", "Button ID: " + launcherButton.Id + " created.");

                grid.Children.Add(Widget_Grid, px, px + sx, py, py + sy);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Launcher", "Widgets.Launcher crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #10
0
파일: Map.cs 프로젝트: ralle12345/Kala
        public static void Map(Grid grid, string x1, string y1, string x2, string y2, string maptype, JArray data)
        {
            CrossLogger.Current.Debug("Map", "Creating Map Widget");

            int px = 0;
            int py = 0;
            int sx = 0;
            int sy = 0;

            //If this fails, we don't know where to show the error
            try
            {
                px = Convert.ToInt16(x1);
                py = Convert.ToInt16(y1);
                sx = Convert.ToInt16(x2);
                sy = Convert.ToInt16(y2);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Map", "Crashed: " + ex.ToString());
            }

            try
            {
                var map = new Map() //MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(0.3)))
                {
                    IsShowingUser   = true,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    MapType         = GetMapType(maptype)
                };
                itemMaps.Add(map);

                //Items in Map widget
                List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >();
                CrossLogger.Current.Debug("Map", "Items: " + items.Count.ToString());

                var latitudes  = new List <double>();
                var longitudes = new List <double>();

                foreach (Models.Sitemap.Widget3 item in items)
                {
                    //Add the Pins to list and map
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.label);

                    double lat = 0.0;
                    double lon = 0.0;
                    string url = String.Empty;

                    if (item.item != null)
                    {
                        var b = item.item.state.Split(',');

                        lat = Convert.ToDouble(b[0]);
                        lon = Convert.ToDouble(b[1]);
                        url = item.item.link;
                    }
                    else
                    {
                        lat = Convert.ToDouble(widgetKeyValuePairs["lat"]);
                        lon = Convert.ToDouble(widgetKeyValuePairs["lon"]);
                    }

                    latitudes.Add(lat);
                    longitudes.Add(lon);

                    var pin = new Pin()
                    {
                        Type     = PinType.Place,
                        Label    = widgetKeyValuePairs["label"],
                        Tag      = url,
                        Position = new Position(lat, lon),
                        Icon     = BitmapDescriptorFactory.DefaultMarker(Color.Red)
                    };

                    //Color keywords
                    if (widgetKeyValuePairs.ContainsKey("color"))
                    {
                        pin.Icon = BitmapDescriptorFactory.DefaultMarker(GetColor(widgetKeyValuePairs["color"]));
                    }

                    map.Pins.Add(pin);
                }
                MapUpdate(latitudes, longitudes, map);

                grid.Children.Add(map, px, px + sx, py, py + sy);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Info("Map", "Crashed:" + ex.ToString());
            }
        }
예제 #11
0
파일: Calendar.cs 프로젝트: johnjore/Kala
        //Create / Update GUI
        private static void Create_Calendar()
        {
            try
            {
                #region ParseItems
                //We know there are x items. Divide by 4 and create and initialize an array for the items
                Models.Calendar[] calEvents = new Models.Calendar[ItemCalendar.Count / 4];

                //Make sure we have something to process
                if (ItemCalendar.Count == 0)
                {
                    return;
                }

                ItemCalendar[0].Grid.Children.Clear();

                //Loop through the items
                foreach (Models.CalItems item in ItemCalendar)
                {
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);

                    if (widgetKeyValuePairs.ContainsKey("item"))
                    {
                        //Event ID Number
                        int.TryParse(Regex.Replace(widgetKeyValuePairs["item"], @"\D", ""), out int id);
                        id--;

                        //Initialize
                        if (calEvents[id] == null)
                        {
                            calEvents[id] = new Models.Calendar();
                        }

                        if (widgetKeyValuePairs["item"].ToLower().Contains("title"))
                        {
                            CrossLogger.Current.Debug("Calendar", "Nr: " + id.ToString() + ", Title:" + item.State);
                            calEvents[id].Title = item.State;
                        }
                        else if (widgetKeyValuePairs["item"].ToLower().Contains("location"))
                        {
                            CrossLogger.Current.Debug("Calendar", "Nr: " + id.ToString() + ", Location:" + item.State);
                            calEvents[id].Location = item.State;
                        }
                        else if (widgetKeyValuePairs["item"].ToLower().Contains("start-time"))
                        {
                            CrossLogger.Current.Debug("Calendar", "Nr: " + id.ToString() + ", Start:" + item.State);

                            DateTime tmp = DateTime.MinValue;
                            DateTime.TryParseExact(item.State, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out tmp);

                            if (tmp == DateTime.MinValue)
                            {
                                DateTime.TryParseExact(item.State, "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None, out tmp);
                            }

                            if (tmp == DateTime.MinValue)
                            {
                                CrossLogger.Current.Debug("Calendar", "Failed to DateTime convert: '" + item.State + "'");
                            }

                            calEvents[id].Start = tmp;
                        }
                        else if (widgetKeyValuePairs["item"].ToLower().Contains("end-time"))
                        {
                            CrossLogger.Current.Debug("Calendar", "Nr: " + id.ToString() + ", End:" + item.State);

                            DateTime tmp = DateTime.MinValue;
                            DateTime.TryParseExact(item.State, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out tmp);

                            if (tmp == DateTime.MinValue)
                            {
                                DateTime.TryParseExact(item.State, "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None, out tmp);
                            }

                            if (tmp == DateTime.MinValue)
                            {
                                CrossLogger.Current.Debug("Calendar", "Failed to DateTime convert: '" + item.State + "'");
                            }
                            calEvents[id].End = tmp;
                        }
                    }
                }

                for (int i = 0; i < calEvents.Count(); i++)
                {
                    calEvents[i].Hours = calEvents[i].Start.ToString("HH:mm") + ":" + calEvents[i].End.ToString("HH:mm");
                    CrossLogger.Current.Debug("Calendar", "Title:" + calEvents[i].Title + ", Time:" + calEvents[i].Start + "-" + calEvents[i].End + ", Location:" + calEvents[i].Location + ", Hours:" + calEvents[i].Hours);
                }
                #endregion ParseItems

                #region GUI
                //calEvents contain the list of events. Parse it to create the GUI as elements may span multiple days
                List <Models.Calendar> guiEvents = new List <Models.Calendar>();

                for (int i = 0; i < calEvents.Length; i++)
                {
                    int days = (calEvents[i].End - calEvents[i].Start).Days;

                    if (days > 0)
                    {
                        for (int j = 0; j < days; j++)
                        {
                            Models.Calendar a = GuiRecord(calEvents[i], j);
                            if (a != null)
                            {
                                guiEvents.Add(a);
                            }
                        }
                    }
                    else
                    {
                        Models.Calendar a = GuiRecord(calEvents[i], 0);
                        if (a != null)
                        {
                            guiEvents.Add(a);
                        }
                    }
                }

                //Sort the list
                SortedList = guiEvents.OrderBy(x => x.Start).ToList();

                for (int i = 0; i < SortedList.Count; i++)
                {
                    //Remove duplicate Day/DayOfWeek
                    for (int j = i + 1; j < SortedList.Count; j++)
                    {
                        if (SortedList[i].Day == SortedList[j].Day)
                        {
                            SortedList[j].Day       = string.Empty;
                            SortedList[j].DayOfWeek = string.Empty;
                        }
                    }

                    CrossLogger.Current.Debug("Calendar", SortedList[i].Day + "," + SortedList[i].DayOfWeek + "," + SortedList[i].Title + "," + SortedList[i].Hours + "," + SortedList[i].Location);
                }

                //Add today if missing from list
                if (SortedList.Count > 0 && SortedList[0].Start.Date > DateTime.Today.Date)
                {
                    Models.Calendar a = new Models.Calendar
                    {
                        Start     = DateTime.Today.Date,
                        Day       = DateTime.Now.Day.ToString(),
                        DayOfWeek = DateTime.Now.DayOfWeek.ToString().Substring(0, 3),
                        Title     = "Today"
                    };

                    SortedList.Insert(0, a);
                }
                #endregion GUI

                #region Render
                ListView lvCalendar = new ListView
                {
                    HorizontalOptions   = LayoutOptions.FillAndExpand,
                    VerticalOptions     = LayoutOptions.FillAndExpand,
                    SeparatorColor      = App.Config.BackGroundColor,
                    BackgroundColor     = App.Config.CellColor,
                    SeparatorVisibility = SeparatorVisibility.Default,
                    RowHeight           = 100,
                    HasUnevenRows       = true,
                    ItemsSource         = SortedList,
                    ItemTemplate        = new DataTemplate(() =>
                    {
                        // Create views with bindings for displaying each property
                        Label titleLabel = new Label
                        {
                            FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                            TextColor       = App.Config.TextColor,
                            BackgroundColor = App.Config.CellColor,
                            FontAttributes  = FontAttributes.Bold,
                        };
                        titleLabel.SetBinding(Label.TextProperty, "Title");

                        Label hourLabel = new Label
                        {
                            FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                            TextColor       = App.Config.TextColor,
                            BackgroundColor = App.Config.CellColor,
                        };
                        hourLabel.SetBinding(Label.TextProperty, "Hours");

                        Label locationLabel = new Label
                        {
                            FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                            TextColor       = App.Config.TextColor,
                            BackgroundColor = App.Config.CellColor,
                        };
                        locationLabel.SetBinding(Label.TextProperty, "Location");

                        Label dayLabel = new Label
                        {
                            FontSize                = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                            TextColor               = App.Config.ValueColor,
                            BackgroundColor         = App.Config.CellColor,
                            FontAttributes          = FontAttributes.Bold,
                            HorizontalTextAlignment = TextAlignment.End
                        };
                        dayLabel.SetBinding(Label.TextProperty, "Day");

                        Label whenLabel = new Label
                        {
                            FontSize                = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                            TextColor               = App.Config.ValueColor,
                            BackgroundColor         = App.Config.CellColor,
                            FontAttributes          = FontAttributes.Bold,
                            HorizontalTextAlignment = TextAlignment.End
                        };
                        whenLabel.SetBinding(Label.TextProperty, "DayOfWeek");

                        // Return an assembled ViewCell
                        return(new ViewCell
                        {
                            View = new StackLayout
                            {
                                Padding = new Thickness(1, 1, 1, 1),
                                Orientation = StackOrientation.Horizontal,
                                Children =
                                {
                                    new StackLayout
                                    {
                                        Padding = new Thickness(10, 1, 10, 1),
                                        VerticalOptions = LayoutOptions.Start,
                                        Spacing = 0,
                                        WidthRequest = 50,
                                        MinimumWidthRequest = 50,
                                        Children =
                                        {
                                            dayLabel,
                                            whenLabel
                                        }
                                    },
                                    new StackLayout
                                    {
                                        Padding = new Thickness(10, 1, 0, 1),
                                        VerticalOptions = LayoutOptions.Start,
                                        Spacing = 5,
                                        Children =
                                        {
                                            titleLabel,
                                            hourLabel,
                                            locationLabel
                                        }
                                    }
                                }
                            }
                        });
                    }),
                };
                lvCalendar.ItemTapped += OnItemTapped; //Prevent selection of items and background color

                ItemCalendar[0].Grid.Children.Add(lvCalendar, 0, 0);
                #endregion Render

                lvCalendar.ItemAppearing += LvCalendar_ItemAppearing;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Calendar", "Crashed: " + ex.ToString());
            }
        }
예제 #12
0
파일: Weather.cs 프로젝트: johnjore/Kala
        public static void Weather(Grid grid, int px, int py, int sx, int sy, string header, JArray data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Weather Widget");

            try
            {
                //Items in Weather widget
                List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >();
                CrossLogger.Current.Debug("Weather", "Items: " + items.Count.ToString());

                #region w_grid
                //Create grid layout
                Grid w_grid = new Grid();
                grid.Children.Add(w_grid, px, px + sx, py, py + sy);

                w_grid.RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(2)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                };
                w_grid.ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = new GridLength(110)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                };
                w_grid.Padding           = new Thickness(0, 20, 0, 2);
                w_grid.RowSpacing        = 0;
                w_grid.ColumnSpacing     = 0;
                w_grid.BackgroundColor   = App.Config.CellColor;
                w_grid.VerticalOptions   = LayoutOptions.FillAndExpand;
                w_grid.HorizontalOptions = LayoutOptions.FillAndExpand;
                #endregion w_grid

                #region t_grid
                //Create grid layout for status bar
                //How many rows & columns in status field
                int status_c = 0;
                int status_r = 0;
                foreach (Models.Sitemap.Widget3 item in items)
                {
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                    if (!widgetKeyValuePairs.ContainsKey("item"))
                    {
                        int tmp_c = Convert.ToInt16(widgetKeyValuePairs["px"]);
                        if (tmp_c > status_c)
                        {
                            status_c = tmp_c;
                        }
                    }
                }

                Grid t_grid = new Grid
                {
                    RowDefinitions = new RowDefinitionCollection()
                };
                for (int i = 0; i <= status_r; i++)
                {
                    t_grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    });
                }

                t_grid.ColumnDefinitions = new ColumnDefinitionCollection();
                for (int i = 0; i <= status_c; i++)
                {
                    t_grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                }
                t_grid.Padding           = new Thickness(0, 0, 0, 0);
                t_grid.RowSpacing        = 0;
                t_grid.ColumnSpacing     = 0;
                t_grid.BackgroundColor   = App.Config.CellColor;
                t_grid.VerticalOptions   = LayoutOptions.FillAndExpand;
                t_grid.HorizontalOptions = LayoutOptions.FillAndExpand;
                w_grid.Children.Add(t_grid, 0, 0 + 3, 3, 3 + 1); //Add in bottom row, across all columns in w_grid
                #endregion t_grid

                #region Separator
                //Boxview (Line)
                BoxView bv = new BoxView
                {
                    Color = App.Config.BackGroundColor
                };
                w_grid.Children.Add(bv, 0, 0 + 3, 2, 2 + 1);
                #endregion Separator

                #region Header
                //Header (Location)
                ItemLabel l_header = new ItemLabel
                {
                    Text              = header,
                    FontSize          = 30,
                    TextColor         = App.Config.TextColor,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.End,
                    TranslationY      = -5
                };
                w_grid.Children.Add(l_header, 1, 0);
                #endregion Header

                #region Fields
                foreach (Models.Sitemap.Widget3 item in items)
                {
                    int counter = 0;
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);

                    if (widgetKeyValuePairs.ContainsKey("item"))
                    #region mandatory
                    {
                        switch (widgetKeyValuePairs["item"].ToUpper())
                        {
                        case "CONDITION-CAPTION":
                            ItemLabel l_condition = new ItemLabel
                            {
                                Text              = item.Item.State,
                                FontSize          = 20,
                                TextColor         = App.Config.TextColor,
                                BackgroundColor   = App.Config.CellColor,
                                HorizontalOptions = LayoutOptions.Start,
                                VerticalOptions   = LayoutOptions.Start,
                                Name              = item.Item.Name,
                                TranslationY      = -5
                            };
                            App.Config.Itemlabels.Add(l_condition);
                            w_grid.Children.Add(l_condition, 1, 1);
                            break;

                        case "TEMPERATURE":
                            var temp = Digits(widgetKeyValuePairs, item.Item.State);

                            ItemLabel l_temperature = new ItemLabel
                            {
                                Post              = "\u00B0" + widgetKeyValuePairs["unit"] + " ",
                                Text              = temp.Item1.ToString() + "\u00B0" + widgetKeyValuePairs["unit"] + " ",
                                FontSize          = 40,
                                TextColor         = App.Config.TextColor,
                                BackgroundColor   = App.Config.CellColor,
                                HorizontalOptions = LayoutOptions.End,
                                VerticalOptions   = LayoutOptions.FillAndExpand,
                                Digits            = temp.Item2,
                                Name              = item.Item.Name,
                                TranslationY      = -5
                            };
                            App.Config.Itemlabels.Add(l_temperature);
                            w_grid.Children.Add(l_temperature, 2, 2 + 1, 0, 0 + 2);
                            break;

                        case "CONDITION":
                            string strFontFamily = null;
                            switch (Device.RuntimePlatform)
                            {
                            case Device.Android:
                                strFontFamily = "weathericons-regular-webfont.ttf#Weather Icons";
                                break;
                            }

                            ItemLabel l_image = new ItemLabel
                            {
                                Text              = WeatherCondition(item.Item.State),
                                TextColor         = App.Config.TextColor,
                                FontFamily        = strFontFamily,
                                FontSize          = 68,
                                HorizontalOptions = LayoutOptions.Center,
                                VerticalOptions   = LayoutOptions.StartAndExpand,
                                Name              = item.Item.Name,
                                Type              = Models.Itemtypes.Weathericon,
                                TranslationY      = -15
                            };
                            App.Config.Itemlabels.Add(l_image);
                            w_grid.Children.Add(l_image, 0, 0 + 1, 0, 0 + 2);
                            break;

                        case "default":
                            break;
                        }
                    }
                    #endregion mandatory
                    else if (widgetKeyValuePairs.ContainsKey("widget"))
                    {
                        switch (widgetKeyValuePairs["widget"].ToUpper())
                        {
                        case "WIND":
                            CrossLogger.Current.Debug("Weather", "Wind");
                            List <Models.Sitemap.Widget3> winds = (JArray.FromObject(item.Widgets)).ToObject <List <Models.Sitemap.Widget3> >();

                            //Wind direction and speed
                            int    w_direction         = 0;
                            string wind_direction_name = string.Empty;
                            string wind_speed          = string.Empty;
                            string wind_speed_name     = string.Empty;
                            int    digits          = -1;
                            string wind_speed_post = string.Empty;

                            foreach (Models.Sitemap.Widget3 wind in winds)
                            {
                                Dictionary <string, string> windKeyValuePairs = Helpers.SplitCommand(wind.Label);
                                switch (windKeyValuePairs["item"].ToUpper())
                                {
                                case "WIND-DIRECTION":
                                    Helpers.wind_direction.TryGetValue(wind.Item.State.ToLower(), out w_direction);
                                    wind_direction_name = wind.Item.Name;
                                    break;

                                case "WIND-SPEED":
                                    var tmpdigits = Digits(windKeyValuePairs, wind.Item.State);
                                    digits          = tmpdigits.Item2;
                                    wind_speed      = tmpdigits.Item1;
                                    wind_speed_name = wind.Item.Name;
                                    wind_speed_post = " " + windKeyValuePairs["unit"];
                                    break;

                                default:
                                    CrossLogger.Current.Warn("Weather", "Unknown item");
                                    break;
                                }
                            }

                            string strFontFamily = null;
                            switch (Device.RuntimePlatform)
                            {
                            case Device.Android:
                                strFontFamily = "weathericons-regular-webfont.ttf#Weather Icons";
                                break;
                            }

                            ItemLabel l_winddirection = new ItemLabel
                            {
                                Type              = Models.Itemtypes.Winddirection, //Special. Rotate label, depending on item value
                                Text              = "\uf0b1",
                                FontSize          = 30,
                                FontFamily        = strFontFamily,
                                TextColor         = App.Config.TextColor,
                                Rotation          = w_direction,
                                BackgroundColor   = App.Config.CellColor,
                                HorizontalOptions = LayoutOptions.Center,
                                VerticalOptions   = LayoutOptions.Center,
                                TranslationX      = -45,
                                Name              = wind_direction_name
                            };
                            App.Config.Itemlabels.Add(l_winddirection);
                            t_grid.Children.Add(l_winddirection, Convert.ToInt16(widgetKeyValuePairs["px"]), Convert.ToInt16(widgetKeyValuePairs["py"]));

                            ItemLabel l_windspeed = new ItemLabel
                            {
                                Text              = wind_speed + wind_speed_post,
                                FontSize          = 20,
                                TextColor         = App.Config.TextColor,
                                BackgroundColor   = App.Config.CellColor,
                                HorizontalOptions = LayoutOptions.Center,
                                VerticalOptions   = LayoutOptions.Center,
                                TranslationX      = 20,
                                Name              = wind_speed_name,
                                Post              = wind_speed_post,
                                Digits            = digits
                            };
                            App.Config.Itemlabels.Add(l_windspeed);
                            t_grid.Children.Add(l_windspeed, Convert.ToInt16(widgetKeyValuePairs["px"]), Convert.ToInt16(widgetKeyValuePairs["py"]));
                            break;

                        default:
                            CrossLogger.Current.Warn("Weather", "Unknown frame type");
                            break;
                        }

                        CrossLogger.Current.Debug("Weather", "Items: " + items.Count.ToString());
                    }
                    else
                    {
                        var digits = Digits(widgetKeyValuePairs, item.Item.State);

                        string strFontFamily = null;
                        switch (Device.RuntimePlatform)
                        {
                        case Device.Android:
                            strFontFamily = "weathericons-regular-webfont.ttf#Weather Icons";
                            break;
                        }

                        ItemLabel l1 = new ItemLabel
                        {
                            Text              = widgetKeyValuePairs["font"] + "  " + digits.Item1 + " " + widgetKeyValuePairs["unit"],
                            FontSize          = 20,
                            FontFamily        = strFontFamily,
                            TextColor         = App.Config.TextColor,
                            BackgroundColor   = App.Config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.Center,
                            Pre    = widgetKeyValuePairs["font"] + "  ",
                            Name   = item.Item.Name,
                            Post   = " " + widgetKeyValuePairs["unit"],
                            Digits = digits.Item2
                        };
                        App.Config.Itemlabels.Add(l1);
                        t_grid.Children.Add(l1, Convert.ToInt16(widgetKeyValuePairs["px"]), Convert.ToInt16(widgetKeyValuePairs["py"]));

                        CrossLogger.Current.Debug("Weather", "No item defined: " + counter++.ToString() + ", font:" + widgetKeyValuePairs["font"] + ", pos: " + widgetKeyValuePairs["px"]);
                    }
                }
                #endregion Fields

                //Button must be last to be added to work
                Button dummyButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                };
                grid.Children.Add(dummyButton, px, px + sx, py, py + sy);
                dummyButton.Clicked += OnDummyButtonClicked;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Weather", "Crashed:" + ex.ToString());
            }
        }
예제 #13
0
파일: Gauge.cs 프로젝트: johnjore/Kala
        private static void Create_Gauge(Grid t_grid, int i, Models.Sitemap.Widget3 item, int x, int y)
        {
            try
            {
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                var digits = Digits(widgetKeyValuePairs, item.Item.State);

                #region Center unit
                t_grid.Children.Add(new Label
                {
                    Text              = widgetKeyValuePairs["unit"],
                    FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                    TextColor         = App.Config.TextColor,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center,
                    TranslationY      = 5
                }, x, y);
                #endregion Center unit

                #region Image
                string strSource = widgetKeyValuePairs["icon"];

                t_grid.Children.Add(new Image
                {
                    Source            = strSource,
                    Aspect            = Aspect.AspectFill,
                    BackgroundColor   = App.Config.CellColor,
                    VerticalOptions   = LayoutOptions.End,
                    HorizontalOptions = LayoutOptions.Center
                }, x, y);
                #endregion Image

                #region Center Text / Value
                string s_value = "N/A";
                if (!(digits.Item1.ToLower().Equals("uninitialized")))
                {
                    s_value = digits.Item1;
                }

                ItemLabel l_value = new ItemLabel
                {
                    Text              = s_value,
                    FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                    TextColor         = App.Config.TextColor,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center,
                    TranslationY      = -20,
                    Name              = item.Item.Name,
                    Digits            = digits.Item2
                };
                App.Config.Itemlabels.Add(l_value);
                t_grid.Children.Add(l_value, x, y);

                float.TryParse(widgetKeyValuePairs["min"].Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out float min);
                float.TryParse(widgetKeyValuePairs["max"].Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out float max);
                float.TryParse(digits.Item1.Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out float value);

                if (value > max)
                {
                    max = value;
                }
                if (value < min)
                {
                    min = value;
                }

                //Handle negative ranges
                if (min < 0)
                {
                    max   += Math.Abs(min);
                    value += Math.Abs(min);
                    min    = 0;
                }

                t_grid.Children.Add(new ShapeView()
                {
                    ShapeType           = ShapeType.Arc,
                    StrokeColor         = App.Config.BackGroundColor,
                    StrokeWidth         = 1.0f,
                    Scale               = 3.0,
                    Padding             = 1,
                    IndicatorPercentage = 100,
                    HorizontalOptions   = LayoutOptions.Center,
                    VerticalOptions     = LayoutOptions.Center
                }, x, y);

                ShapeView progressArc = new ShapeView
                {
                    ShapeType           = ShapeType.Arc,
                    StrokeColor         = App.Config.ValueColor,
                    StrokeWidth         = 1.0f,
                    Scale               = 3.0,
                    Padding             = 1,
                    IndicatorPercentage = ((value - min) / (max - min) * 100.0f),
                    HorizontalOptions   = LayoutOptions.Center,
                    VerticalOptions     = LayoutOptions.Center,
                    Name = item.Item.Name,
                    Min  = min,
                    Max  = max
                };
                App.Config.ItemShapeViews.Add(progressArc);
                t_grid.Children.Add(progressArc, x, y);
                #endregion Arc

                //Button must be last to be added to work
                Button dummyButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                };
                t_grid.Children.Add(dummyButton, x, y);
                dummyButton.Clicked += OnDummyButtonClicked;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Gauge", "Crashed: " + ex.ToString());
                Error(t_grid, i, 1, 1, 1, ex.ToString());
            }
        }
예제 #14
0
파일: Sitemap.cs 프로젝트: ralle12345/Kala
        /// <summary>
        /// Create GUI
        /// </summary>
        /// <returns>nothing</returns>
        public void CreateSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            Models.Sitemap.Sitemap items = new RestService().LoadItemsFromSitemap(sitemap);

            //Configuration
            Dictionary <string, string> entry = Helpers.SplitCommand(items.label);

            //Settings
            if (entry.ContainsKey("fullscreen"))
            {
                //Setting is stored locally, else its read too late to take effect on device
                try
                {
                    Settings.Fullscreen = Convert.ToBoolean(entry["fullscreen"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'fullscreen' value: '" + entry["fullscreen"] + "'");
                }
            }

            if (entry.ContainsKey("screensaver"))
            {
                try
                {
                    //Setting is stored locally, else its read too late to take effect on device
                    Settings.Screensaver = Convert.ToInt16(entry["screensaver"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'screensaver' value: '" + entry["screensaver"] + "'");
                }
            }

            if (entry.ContainsKey("kala"))
            {
                try
                {
                    App.config.Valid = Convert.ToBoolean(entry["kala"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'kala' identifier: '" + entry["kala"] + "'");
                }
            }

            if (entry.ContainsKey("background"))
            {
                try
                {
                    App.config.BackGroundColor = Color.FromHex(entry["background"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'background' value: '" + entry["background"] + "'");
                }
            }

            if (entry.ContainsKey("cell"))
            {
                try
                {
                    App.config.CellColor = Color.FromHex(entry["cell"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'cell' value: '" + entry["cell"] + "'");
                }
            }
            if (entry.ContainsKey("text"))
            {
                try
                {
                    App.config.TextColor = Color.FromHex(entry["text"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'text' value: '" + entry["text"] + "'");
                }
            }
            if (entry.ContainsKey("value"))
            {
                try
                {
                    App.config.ValueColor = Color.FromHex(entry["value"]);
                }
                catch
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'value' value: '" + entry["value"] + "'");
                }
            }


            CrossLogger.Current.Info("Kala", "Fullscreen : " + Settings.Fullscreen.ToString());
            CrossLogger.Current.Info("Kala", "Screensaver: " + Settings.Screensaver.ToString());
            CrossLogger.Current.Info("Kala", "Sitemap: " + Settings.Fullscreen.ToString());

            if (App.config.Valid)
            {
                ParseSitemap(items);

                //Enable screensaver?
                if (Settings.Screensaver > 0)
                {
                    Widgets.Screensaver(Settings.Screensaver);
                }
            }
        }
예제 #15
0
파일: Sitemap.cs 프로젝트: ralle12345/Kala
        /// <summary>
        /// Parses / creates Widgets
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseWidgets(Grid grid, Models.Sitemap.Widget3 item)
        {
            try
            {
                CrossLogger.Current.Debug("Kala", "Widget : " + item.widget + ", ID: " + item.widgetId);
                Dictionary <string, string> itemKeyValuePairs = Helpers.SplitCommand(item.label);

                if (itemKeyValuePairs != null && itemKeyValuePairs.ContainsKey("widget") && itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py"))
                {
                    switch (itemKeyValuePairs["widget"].ToUpper())
                    {
                    case "AVATAR":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Avatar(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], (JObject)item.widget);
                        }
                        break;

                    case "BLANK":
                        Widgets.Blank(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"]);
                        break;

                    case "CALENDAR":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Calendar(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], (JArray)item.widget);
                        }
                        break;

                    case "CLOCK":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Clock(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"]);
                        }
                        break;

                    case "DIMMER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Dimmer(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "SENSOR":
                        string sx = "1";
                        string sy = "1";
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            sx = itemKeyValuePairs["sx"];
                            sy = itemKeyValuePairs["sy"];
                        }

                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Sensor(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "GAUGE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "GAUGE-GROUP":
                        if (itemKeyValuePairs.ContainsKey("label") && itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            var token = JToken.Parse(item.widget.ToString());
                            if (token is JArray)
                            {
                                Widgets.Gauge_Group(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                            }
                            else if (token is JObject)
                            {
                                Widgets.Gauge_Group(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JObject)item.widget);
                            }
                        }
                        break;

                    case "IMAGE":
                        //Parameters
                        if (!itemKeyValuePairs.ContainsKey("aspect"))
                        {
                            itemKeyValuePairs.Add("aspect", "aspectfill");
                        }

                        if (itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py") && itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Image(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], itemKeyValuePairs["aspect"], (JObject)item.widget);
                        }
                        break;

                    case "MAP":
                        //Parameters
                        if (!itemKeyValuePairs.ContainsKey("type"))
                        {
                            itemKeyValuePairs.Add("type", "street");
                        }

                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy"))
                        {
                            Widgets.Map(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["type"], (JArray)item.widget);
                        }
                        break;

                    case "SWITCH":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Switch(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["label"], (JObject)item.widget);
                        }
                        break;

                    case "WEATHER":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Weather(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                        }
                        break;

                    case "WEATHERFORECAST":
                        if (itemKeyValuePairs.ContainsKey("sx") && itemKeyValuePairs.ContainsKey("sy") && itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.WeatherForecast(grid, itemKeyValuePairs["px"], itemKeyValuePairs["py"], itemKeyValuePairs["sx"], itemKeyValuePairs["sy"], itemKeyValuePairs["label"], (JArray)item.widget);
                        }
                        break;

                    default:
                        CrossLogger.Current.Warn("Kala", "Failed to parse widget. Unknown type: " + item.ToString());
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Kala", "Failed to parse widget: " + ex.ToString());
            }
        }
예제 #16
0
파일: Sitemap.cs 프로젝트: ralle12345/Kala
        /// <summary>
        /// Parse Sitemap file
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseSitemap(Models.Sitemap.Sitemap items)
        {
            foreach (Models.Sitemap.Widget page in items.homepage.widget)
            {
                CrossLogger.Current.Debug("Kala", "Label: " + page.label);

                //Populate Page, if it contains elements to parse
                if (page.label != string.Empty)
                {
                    Dictionary <string, string> pageKeyValuePairs = Helpers.SplitCommand(page.label);
                    CrossLogger.Current.Debug("Kala", "Label: " + pageKeyValuePairs["label"]);

                    #region page
                    if (page.linkedPage != null)
                    {
                        Grid grid = null;

                        if (pageKeyValuePairs.ContainsKey("sx") && pageKeyValuePairs.ContainsKey("sy"))
                        {
                            if (pageKeyValuePairs.ContainsKey("icon"))
                            {
                                grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], pageKeyValuePairs["icon"]);
                            }
                            else
                            {
                                grid = CreatePage(pageKeyValuePairs["label"], pageKeyValuePairs["sx"], pageKeyValuePairs["sy"], null);
                            }
                        }

                        //Shortcut
                        var w = page.linkedPage.widget;

                        //If more than one item page frame
                        if (w.GetType() == typeof(JArray))
                        {
                            List <Models.Sitemap.Widget3> w_items = ((JArray)w).ToObject <List <Models.Sitemap.Widget3> >();
                            foreach (Models.Sitemap.Widget3 item in w_items)
                            {
                                ParseWidgets(grid, item);
                            }
                        }
                        //If one item in page frame
                        else if (w.GetType() == typeof(JObject))
                        {
                            Models.Sitemap.Widget3 item = ((JObject)w).ToObject <Models.Sitemap.Widget3>();
                            ParseWidgets(grid, item);
                        }
                        else
                        {
                            CrossLogger.Current.Warn("Kala", "Unknown: " + w.ToString());
                        }
                    }
                    #endregion page
                    else
                    {
                        CrossLogger.Current.Warn("Kala", "Unknown: " + ToString());

                        switch (pageKeyValuePairs["widget"].ToUpper())
                        {
                        case "SITEMAP":
                            CrossLogger.Current.Debug("Kala", "Sitemap:" + pageKeyValuePairs["name"]);

                            Models.Sitemaps.Sitemap sitemaps = GetActiveSitemap(pageKeyValuePairs["name"]);
                            if (sitemaps != null)
                            {
                                Sitemap sitemap = new Sitemap();
                                sitemap.CreateSitemap(sitemaps);

                                CrossLogger.Current.Debug("Kala", "Got ActiveSitemap");
                            }
                            break;
                        }
                    }
                }
            }
        }
예제 #17
0
파일: Blind.cs 프로젝트: johnjore/Kala
        public static void Blind(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Blind Widget");

            Models.Sitemap.Widget3      item = null;
            Dictionary <string, string> widgetKeyValuePairs = null;

            try
            {
                item = data.ToObject <Models.Sitemap.Widget3>();
                widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Blind", "Crashed: " + ex.ToString());
            }

            try
            {
                #region w_grid
                Grid w_grid = new Grid
                {
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    Padding           = new Thickness(0, 0, 0, 0),
                    BackgroundColor   = App.Config.CellColor,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };
                grid.Children.Add(w_grid, px, px + sx, py, py + sy);

                //Vertical
                if (sx < sy)
                {
                    w_grid.ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    };

                    w_grid.RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },                                                                   //Up
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },                                                                   //Stop
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },                                                                   //Down
                    };

                    //Header
                    w_grid.Children.Add(new Label
                    {
                        Text                    = header,
                        FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                        TextColor               = App.Config.TextColor,
                        BackgroundColor         = App.Config.CellColor,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Start
                    }, 0, 0);

                    //Control buttons
                    AddControlImage(w_grid, widgetKeyValuePairs["up_icon"], 0, 0, item.Item.Name, "UP");
                    AddControlImage(w_grid, widgetKeyValuePairs["icon"], 0, 1, item.Item.Name, "STOP");
                    AddControlImage(w_grid, widgetKeyValuePairs["down_icon"], 0, 2, item.Item.Name, "DOWN");
                }
                else if (sx > sy) //Horizontal
                {
                    w_grid.ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },                                                                     //Up
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },                                                                     //Stop
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },                                                                     //Down
                    };

                    w_grid.RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                    };

                    //Header
                    w_grid.Children.Add(new Label
                    {
                        Text                    = header,
                        FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                        TextColor               = App.Config.TextColor,
                        BackgroundColor         = App.Config.CellColor,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Start
                    }, 1, 0);

                    AddControlImage(w_grid, widgetKeyValuePairs["up_icon"], 0, 0, item.Item.Name, "UP");
                    AddControlImage(w_grid, widgetKeyValuePairs["icon"], 1, 0, item.Item.Name, "STOP");
                    AddControlImage(w_grid, widgetKeyValuePairs["down_icon"], 2, 0, item.Item.Name, "DOWN");
                }
                else
                {
                    w_grid.ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    };

                    w_grid.RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                    };

                    //Header
                    w_grid.Children.Add(new Label
                    {
                        Text                    = header,
                        FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                        TextColor               = App.Config.TextColor,
                        BackgroundColor         = App.Config.CellColor,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Start
                    }, 1, 0);

                    //Control buttons
                    AddControlImage(w_grid, widgetKeyValuePairs["up_icon"], 0, 0, item.Item.Name, "UP");
                    AddControlImage(w_grid, widgetKeyValuePairs["icon"], 1, 1, item.Item.Name, "STOP");
                    AddControlImage(w_grid, widgetKeyValuePairs["down_icon"], 2, 2, item.Item.Name, "DOWN");
                }
                #endregion w_grid
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Blind", "Widgets.Blind crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #18
0
파일: Sitemap.cs 프로젝트: johnjore/Kala
        /// <summary>
        /// Parses / creates Widgets
        /// </summary>
        /// <returns>nothing</returns>
        private void ParseWidgets(Grid grid, Models.Sitemap.Widget3 item)
        {
            try
            {
                CrossLogger.Current.Debug("Kala", "ID: " + item.WidgetId);
                Dictionary <string, string> itemKeyValuePairs = Helpers.SplitCommand(item.Label);

                if (itemKeyValuePairs != null && itemKeyValuePairs.ContainsKey("widget") && itemKeyValuePairs.ContainsKey("px") && itemKeyValuePairs.ContainsKey("py"))
                {
                    //Position
                    int.TryParse(itemKeyValuePairs["px"], out int px);
                    int.TryParse(itemKeyValuePairs["py"], out int py);

                    //Size
                    int sx = 1;
                    if (itemKeyValuePairs.ContainsKey("sx"))
                    {
                        int.TryParse(itemKeyValuePairs["sx"], out sx);
                    }
                    int sy = 1;
                    if (itemKeyValuePairs.ContainsKey("sy"))
                    {
                        int.TryParse(itemKeyValuePairs["sy"], out sy);
                    }

                    //Gauge-Group
                    int rx = 1;
                    if (itemKeyValuePairs.ContainsKey("rx"))
                    {
                        int.TryParse(itemKeyValuePairs["rx"], out rx);
                    }
                    int ry = 1;
                    if (itemKeyValuePairs.ContainsKey("ry"))
                    {
                        int.TryParse(itemKeyValuePairs["ry"], out ry);
                    }

                    switch (itemKeyValuePairs["widget"].ToUpper())
                    {
                    case "AVATAR":
                        Widgets.Avatar(grid, px, py, sx, sy, JArray.FromObject(item.Widgets));
                        break;

                    case "BARCODE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Barcode(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "BLIND":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Blind(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "BLANK":
                        Widgets.Blank(grid, px, py, sx, sy);
                        break;

                    case "CALENDAR":
                        Widgets.Calendar(grid, px, py, sx, sy, JArray.FromObject(item.Widgets));
                        break;

                    case "CHART":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Chart(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "CLOCK":
                        Widgets.Clock(grid, px, py, sx, sy);
                        break;

                    case "DIMMER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Dimmer(grid, px, py, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "FLOORMAP":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.FloormapAsync(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "GAUGE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge(grid, px, py, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "GAUGE-GROUP":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Gauge_Group(grid, px, py, sx, sy, rx, ry, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    case "IMAGE":
                        if (!itemKeyValuePairs.ContainsKey("aspect"))
                        {
                            itemKeyValuePairs.Add("aspect", "aspectfill");
                        }

                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Image(grid, px, py, sx, sy, itemKeyValuePairs["label"], itemKeyValuePairs["aspect"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "LAUNCHER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Launcher(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "MAP":
                        if (!itemKeyValuePairs.ContainsKey("type"))
                        {
                            itemKeyValuePairs.Add("type", "street");
                        }
                        Widgets.Map(grid, px, py, sx, sy, itemKeyValuePairs["type"], JArray.FromObject(item.Widgets));
                        break;

                    case "NUMERICINPUT":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.NumericInput(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "SENSOR":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Sensor(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "SWITCH":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Switch(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "VOICE":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Voice(grid, px, py, sx, sy, itemKeyValuePairs["label"], (JObject)item.Widgets[0]);
                        }
                        break;

                    case "WEATHER":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.Weather(grid, px, py, sx, sy, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    case "WEATHERFORECAST":
                        if (itemKeyValuePairs.ContainsKey("label"))
                        {
                            Widgets.WeatherForecast(grid, px, py, sx, sy, itemKeyValuePairs["label"], JArray.FromObject(item.Widgets));
                        }
                        break;

                    default:
                        CrossLogger.Current.Warn("Kala", "Failed to parse widget. Unknown type: " + item.ToString());
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Kala", "Failed to parse widget: " + ex.ToString());
            }
        }
예제 #19
0
파일: Sitemap.cs 프로젝트: johnjore/Kala
        /// <summary>
        /// Create GUI
        /// </summary>
        /// <returns>nothing</returns>
        public void CreateSitemap(Models.Sitemaps.Sitemap sitemap)
        {
            Models.Sitemap.Sitemap items = new RestService().LoadItemsFromSitemap(sitemap);

            //Configuration
            Dictionary <string, string> entry = Helpers.SplitCommand(items.Label);

            //Settings
            if (entry.ContainsKey("fullscreen"))
            {
                try
                {
                    App.Config.FullScreen = Convert.ToBoolean(entry["fullscreen"]);
                    DependencyService.Get <IScreen>().SetFullScreen(App.Config.FullScreen);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'fullscreen' value: '" + entry["fullscreen"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("screensaver"))
            {
                try
                {
                    App.Config.ScreenSaver = Convert.ToInt64(entry["screensaver"]);
                    IScreen ss = DependencyService.Get <IScreen>();
                    ss.ScreenSaver(App.Config.ScreenSaver);

                    App.Config.ScreenSaverType = Models.ScreenSaverTypes.Clock;
                    if (entry.ContainsKey("screensavertype"))
                    {
                        App.Config.ScreenSaverType = (Models.ScreenSaverTypes)Enum.Parse(typeof(Models.ScreenSaverTypes), entry["screensavertype"], true);
                    }

                    switch (App.Config.ScreenSaverType)
                    {
                    case Models.ScreenSaverTypes.Images:
                        if (entry.ContainsKey("screensaverurl"))
                        {
                            Widgets.SetUrl(entry["screensaverurl"]);
                        }
                        else
                        {
                            App.Config.ScreenSaverType = Models.ScreenSaverTypes.Clock;
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'screensaver' value: '" + entry["screensaver"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("kala"))
            {
                try
                {
                    App.Config.Valid = Convert.ToBoolean(entry["kala"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'kala' identifier: '" + entry["kala"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("background"))
            {
                try
                {
                    App.Config.BackGroundColor = Color.FromHex(entry["background"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'background' value: '" + entry["background"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("cell"))
            {
                try
                {
                    App.Config.CellColor = Color.FromHex(entry["cell"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'cell' value: '" + entry["cell"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("text"))
            {
                try
                {
                    App.Config.TextColor = Color.FromHex(entry["text"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'text' value: '" + entry["text"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("value"))
            {
                try
                {
                    App.Config.ValueColor = Color.FromHex(entry["value"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to convert 'value' value: '" + entry["value"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("screenorientation"))
            {
                try
                {
                    IScreen so = DependencyService.Get <IScreen>();
                    so.SetScreenOrientation(entry["screenorientation"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to action 'screenorientation' value: '" + entry["screenorientation"].ToString() + "', " + ex.ToString());
                }
            }

            if (entry.ContainsKey("settings"))
            {
                try
                {
                    App.Config.Settings = Convert.ToBoolean(entry["settings"]);
                }
                catch (Exception ex)
                {
                    CrossLogger.Current.Error("Kala", "Failed to action 'settings' value: '" + entry["settings"].ToString() + "', " + ex.ToString());
                }
            }

            if (App.Config.Valid)
            {
                ParseSitemap(items);

                //Enable screensaver?
                if (App.Config.ScreenSaver > 0)
                {
                    Widgets.Screensaver(App.Config.ScreenSaver);
                    App.Config.ScreenSaver = 0;
                }
            }
        }
예제 #20
0
        public static void WeatherForecast(Grid grid, int px, int py, int sx, int sy, string header, JArray data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create WeatherForecast Widget");
            CrossLogger.Current.Debug("WeatherForecast", "Creating Weather forecast :" + data.ToString());

            try
            {
                List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >();

                #region t_grid
                Grid t_grid = new Grid
                {
                    Padding           = new Thickness(0, 0, 0, 0),
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    BackgroundColor   = App.Config.CellColor,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,

                    RowDefinitions = new RowDefinitionCollection
                    {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                    }
                };

                //Columns
                for (int i = 0; i < items.Count; i++)            //Each day has 3 items
                {
                    int day = 0;
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(items[i].Label);
                    if (widgetKeyValuePairs.ContainsKey("item"))
                    {
                        day = Convert.ToInt16(widgetKeyValuePairs["item"].Substring(3, 1));
                    }
                    var digits = Digits(widgetKeyValuePairs, items[i].Item.State);

                    #region Header
                    if (i % 3 == 0)
                    {
                        string DayOfWeek = "Today";
                        int    DayNumber = -1;
                        if (i / 3 != 0)
                        {
                            DayNumber = (int)DateTime.Now.AddDays(i / 3.0).DayOfWeek;
                            DayOfWeek = ((DayOfWeek)DayNumber).ToString().Substring(0, 3);
                        }

                        ItemLabel l_header = new ItemLabel
                        {
                            Digits            = DayNumber,
                            Text              = DayOfWeek,
                            FontSize          = 20,
                            TextColor         = App.Config.TextColor,
                            BackgroundColor   = App.Config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.Start,
                            Type              = Models.Itemtypes.NameOfDay,
                        };
                        App.Config.Itemlabels.Add(l_header);
                        t_grid.Children.Add(l_header, i / 3, 0);
                    }
                    #endregion Header

                    #region Condition
                    if (items[i].Label.Contains("condition"))
                    {
                        string strFontFamily = null;
                        switch (Device.RuntimePlatform)
                        {
                        case Device.Android:
                            strFontFamily = "weathericons-regular-webfont.ttf#Weather Icons";
                            break;
                        }

                        ItemLabel l_image = new ItemLabel
                        {
                            Text              = WeatherCondition(items[i].Item.State),
                            TextColor         = App.Config.TextColor,
                            FontFamily        = strFontFamily,
                            FontSize          = 68,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.Center,
                            TranslationY      = -5,
                            Name              = items[i].Item.Name,
                            Type              = Models.Itemtypes.Weathericon
                        };
                        App.Config.Itemlabels.Add(l_image);
                        t_grid.Children.Add(l_image, day, 1);
                    }
                    #endregion Condition

                    #region Temperature
                    if (items[i].Label.Contains("temperature-high"))
                    {
                        ItemLabel l_temp_high = new ItemLabel
                        {
                            FontSize          = 20,
                            TextColor         = App.Config.TextColor,
                            BackgroundColor   = App.Config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.End,
                            TranslationX      = -30,
                            Name   = items[i].Item.Name,
                            Pre    = "   ",
                            Post   = "\u00B0",
                            Text   = digits.Item1 + " \u00B0",
                            Digits = digits.Item2
                        };
                        App.Config.Itemlabels.Add(l_temp_high);
                        t_grid.Children.Add(l_temp_high, day, 2);
                    }

                    if (items[i].Label.Contains("temperature-low"))
                    {
                        ItemLabel l_temp_low = new ItemLabel
                        {
                            FontSize          = 20,
                            TextColor         = App.Config.TextColor,
                            BackgroundColor   = App.Config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.End,
                            TranslationX      = 30,
                            Name   = items[i].Item.Name,
                            Post   = " \u00B0",
                            Text   = digits.Item1 + " \u00B0  ",
                            Digits = digits.Item2
                        };
                        App.Config.Itemlabels.Add(l_temp_low);
                        t_grid.Children.Add(l_temp_low, day, 2);
                    }
                    #endregion Temperature
                }

                //Button must be last to be added to work
                Button dummyButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                };
                t_grid.Children.Add(dummyButton, px, px + sx, py, py + sy);
                dummyButton.Clicked += OnDummyButtonClicked;

                grid.Children.Add(t_grid, px, px + sx, py, py + sy);
                #endregion t_grid

                // Check if we've crossed midnight as first entry is now yesterday
                DayOfWeek Today = DateTime.Today.DayOfWeek;
                Device.StartTimer(TimeSpan.FromSeconds(60), () =>
                {
                    if (DateTime.Today.DayOfWeek != Today)
                    {
                        CrossLogger.Current.Debug("WeatherForecast", "Update WeatherForecast DayOfWeek as we've crossed midnight");
                        Today = DateTime.Today.DayOfWeek;

                        foreach (ItemLabel lbl in App.Config.Itemlabels)
                        {
                            if (lbl.Type.Equals(Models.Itemtypes.NameOfDay) && (lbl.Digits != -1))
                            {
                                lbl.Digits = (lbl.Digits + 1) % 7;
                                lbl.Text   = ((DayOfWeek)lbl.Digits).ToString().Substring(0, 3);
                            }
                        }
                    }

                    return(true);
                });
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("WeatherForecast", "Crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #21
0
파일: Calendar.cs 프로젝트: ralle12345/Kala
        //Intial creation
        public static void Calendar(Grid grid, string x1, string y1, string x2, string y2, JArray data)
        {
            CrossLogger.Current.Info("Calendar", "Widget Processing Started");
            //CrossLogger.Current.Debug("Calendar", data.ToString());

            try
            {
                //Size of Calendar widget
                int px = Convert.ToInt16(x1);
                int py = Convert.ToInt16(y1);
                int sx = Convert.ToInt16(x2);
                int sy = Convert.ToInt16(y2);

                //Items in Calendar widget
                List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >();

                //Loop through the items and save to custom list
                foreach (Models.Sitemap.Widget3 item in items)
                {
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.label);

                    Models.calItems a = new Models.calItems();
                    a.Label = item.label;
                    a.State = item.item.state;
                    a.Link  = item.item.link;

                    a.grid = grid;
                    a.px   = px;
                    a.py   = py;
                    a.sx   = sx;
                    a.sy   = sy;

                    itemCalendar.Add(a);
                }

                lock (itemCalendar)
                {
                    Create_Calendar();
                }

                // Check if we've crossed midnight as first entry is now yesterday
                Device.StartTimer(TimeSpan.FromSeconds(60), () =>
                {
                    if (SortedList != null && SortedList.Count > 0)
                    {
                        if (DateTime.Today.Date != SortedList[0].Start.Date)
                        {
                            CrossLogger.Current.Debug("Calendar", "Update Calendar as we've crossed midnight");
                            lock (itemCalendar)
                            {
                                Create_Calendar();
                            }
                        }
                    }

                    return(true);
                });
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Calendar", "Crashed: " + ex.ToString());
            }
        }
예제 #22
0
파일: Launcher.cs 프로젝트: johnjore/Kala
        public static void Launcher(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Launcher Widget");

            try
            {
                Models.Sitemap.Widget3      item = data.ToObject <Models.Sitemap.Widget3>();
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                CrossLogger.Current.Debug("Launcher", "Label: " + widgetKeyValuePairs["label"]);

                //Master Grid for Widget
                Grid Widget_Grid = new Grid
                {
                    RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(2, GridUnitType.Star)
                        },
                    },
                    ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    },
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    Padding           = new Thickness(0, 0, 0, 10),
                };

                //Header
                Widget_Grid.Children.Add(new Forms9Patch.Label
                {
                    Text                    = header.Replace("\"", " "),
                    FontSize                = 100,
                    TextColor               = App.Config.TextColor,
                    BackgroundColor         = App.Config.CellColor,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start,
                    LineBreakMode           = LineBreakMode.NoWrap,
                    Lines                   = 1,
                    AutoFit                 = Forms9Patch.AutoFit.Width,
                }, 0, 0);

                //Circle
                SvgCachedImage svg = new SvgCachedImage
                {
                    DownsampleToViewSize = false,
                    Aspect = Aspect.AspectFit,
                    BitmapOptimizations = false,
                    Source = SvgImageSource.FromSvgString(@"<svg viewBox=""0 0 100 100""><circle cx=""50"" cy=""50"" r=""50"" fill=""" + App.Config.ValueColor.ToHex().ToString() + @""" /></svg>"),
                };
                Widget_Grid.Children.Add(svg, 0, 1);

                //Image
                Widget_Grid.Children.Add(new Image
                {
                    Source            = widgetKeyValuePairs["icon"],
                    Aspect            = Aspect.AspectFit,
                    BackgroundColor   = Color.Transparent,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                }, 0, 1);

                //Button must be last to be added to work
                Button launcherButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                    StyleId           = widgetKeyValuePairs["url"] //StyleID is not used on buttons
                };
                Widget_Grid.Children.Add(launcherButton, 0, 1, 0, 2);

                launcherButton.Clicked += OnLauncherButtonClicked;
                CrossLogger.Current.Debug("Launcher", "Button ID: " + launcherButton.Id + " created.");

                grid.Children.Add(Widget_Grid, px, px + sx, py, py + sy);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Launcher", "Widgets.Launcher crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #23
0
        public static void Barcode(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Barcode Widget");

            try
            {
                Models.Sitemap.Widget3      item = data.ToObject <Models.Sitemap.Widget3>();
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);
                CrossLogger.Current.Debug("Barcode", "Label: " + widgetKeyValuePairs["label"]);

                //Master Grid for Widget
                Grid Widget_Grid = new Grid
                {
                    RowDefinitions = new RowDefinitionCollection {
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Star)
                        },
                    },
                    ColumnDefinitions = new ColumnDefinitionCollection {
                        new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        },
                    },
                    RowSpacing        = 0,
                    ColumnSpacing     = 0,
                    BackgroundColor   = App.Config.CellColor,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                };
                grid.Children.Add(Widget_Grid, px, px + sx, py, py + sy);

                //Header
                Widget_Grid.Children.Add(new Label
                {
                    Text                    = header,
                    FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                    TextColor               = App.Config.TextColor,
                    BackgroundColor         = App.Config.CellColor,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start
                }, 0, 0);

                //Background
                Widget_Grid.Children.Add(new ShapeView()
                {
                    ShapeType         = ShapeType.Circle,
                    StrokeColor       = App.Config.ValueColor,
                    Color             = App.Config.ValueColor,
                    StrokeWidth       = 1.0f,
                    Scale             = 2.5f,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                }, 0, 1);

                //Image
                Widget_Grid.Children.Add(new Image
                {
                    Source            = widgetKeyValuePairs["icon"],
                    Aspect            = Aspect.AspectFill,
                    BackgroundColor   = Color.Transparent,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                }, 0, 1);

                //Options
                widgetKeyValuePairs.TryGetValue("UseFrontCameraIfAvailable", out string strUseFrontCameraIfAvailable);
                if (strUseFrontCameraIfAvailable == null)
                {
                    strUseFrontCameraIfAvailable = "false";
                }

                var mobileBarcodeScanningOptions = new MobileBarcodeScanningOptions
                {
                    AutoRotate                = false,
                    TryHarder                 = false,
                    TryInverted               = false,
                    DisableAutofocus          = false,
                    UseNativeScanning         = true,
                    UseFrontCameraIfAvailable = bool.Parse(strUseFrontCameraIfAvailable),

                    PossibleFormats = new List <ZXing.BarcodeFormat> {
                        ZXing.BarcodeFormat.EAN_13,
                        ZXing.BarcodeFormat.EAN_8
                    },

                    CameraResolutionSelector = availableResolutions =>
                    {
                        string[] resolution = new string[0];
                        if (widgetKeyValuePairs.ContainsKey("CameraResolutionSelector"))
                        {
                            resolution = widgetKeyValuePairs["CameraResolutionSelector"].Split('x');
                        }
                        foreach (var ar in availableResolutions)
                        {
                            CrossLogger.Current.Debug("Barcode", "Resolution: " + ar.Width + "x" + ar.Height);
                            if (resolution.Length > 0 && (resolution[0] == ar.Width.ToString() && resolution[1] == ar.Height.ToString()))
                            {
                                CrossLogger.Current.Debug("Barcode", "Found match: " + ar.Width + "x" + ar.Height);
                                return(ar);
                            }
                        }
                        CrossLogger.Current.Debug("Barcode", "Using default resolution");
                        return(null);
                    }
                };

                //Button must be added last
                Button barcodeButton = new BarcodeButton
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                    Name    = item.Item.Name,
                    Options = mobileBarcodeScanningOptions,
                };
                barcodeButton.Clicked += OnBarcodeButtonClicked;

                Widget_Grid.Children.Add(barcodeButton, 0, 1, 0, 2);
                CrossLogger.Current.Debug("Barcode", "Button ID: " + barcodeButton.Id + " created.");
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Barcode", "Widgets.Barcode crashed: " + ex.ToString());
                Error(grid, px, py, 1, 1, ex.ToString());
            }
        }
예제 #24
0
파일: Gauge.cs 프로젝트: ralle12345/Kala
        private static void Create_Gauge(Grid t_grid, int i, Models.Sitemap.Widget3 item)
        {
            try
            {
                Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.label);
                var digits = Digits(widgetKeyValuePairs, item.item.state);

                #region Center unit
                t_grid.Children.Add(new Label
                {
                    Text              = widgetKeyValuePairs["unit"],
                    FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                    TextColor         = App.config.TextColor,
                    BackgroundColor   = App.config.CellColor,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center,
                    TranslationY      = 5
                }, i, 1);
                #endregion Center unit

                #region Image
                t_grid.Children.Add(new Image
                {
                    Source            = Device.OnPlatform(widgetKeyValuePairs["icon"], widgetKeyValuePairs["icon"], "Assets/" + widgetKeyValuePairs["icon"]),
                    Aspect            = Aspect.AspectFill,
                    BackgroundColor   = App.config.CellColor,
                    VerticalOptions   = LayoutOptions.End,
                    HorizontalOptions = LayoutOptions.Center
                }, i, 1);
                #endregion Image

                #region Center Text / Value
                string s_value = String.Empty;
                if (digits.Item1.ToLower().Equals("uninitialized"))
                {
                    s_value = "N/A";
                }
                else
                {
                    s_value = digits.Item1;
                }

                ItemLabel l_value = new ItemLabel
                {
                    Text              = s_value,
                    FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                    TextColor         = App.config.TextColor,
                    BackgroundColor   = App.config.CellColor,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.Center,
                    TranslationY      = -20,
                    Link              = item.item.link,
                    Digits            = digits.Item2
                };
                App.config.itemlabels.Add(l_value);
                t_grid.Children.Add(l_value, i, 1);
                #endregion Center Text / Value

                #region Arc
                float min   = 0.0f;
                float max   = 0.0f;
                float value = 0.0f;
                Single.TryParse(widgetKeyValuePairs["min"].Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out min);
                Single.TryParse(widgetKeyValuePairs["max"].Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out max);
                Single.TryParse(digits.Item1.Replace(".", CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator), out value);

                //Basic sanity checks
                if (value > max)
                {
                    max = value;
                }
                if (value < min)
                {
                    min = value;
                }

                //Handle negative ranges
                if (min < 0)
                {
                    max   += Math.Abs(min);
                    value += Math.Abs(min);
                    min    = 0;
                }

                t_grid.Children.Add(new ShapeView()
                {
                    ShapeType           = ShapeType.Arc,
                    StrokeColor         = App.config.BackGroundColor,
                    StrokeWidth         = 1.0f,
                    Scale               = 3.0,
                    Padding             = 1,
                    IndicatorPercentage = 100,
                    HorizontalOptions   = LayoutOptions.Center,
                    VerticalOptions     = LayoutOptions.Center
                }, i, 1);

                if (item.item.link.Contains("Sensor_MasterBedroom_Temperature"))
                {
                    CrossLogger.Current.Error("Update", "1");
                }

                ShapeView progressArc = new ShapeView
                {
                    ShapeType           = ShapeType.Arc,
                    StrokeColor         = App.config.ValueColor,
                    StrokeWidth         = 1.0f,
                    Scale               = 3.0,
                    Padding             = 1,
                    IndicatorPercentage = ((value - min) / (max - min) * 100.0f),   //Calculate indicator percentage
                    HorizontalOptions   = LayoutOptions.Center,
                    VerticalOptions     = LayoutOptions.Center,
                    Link = item.item.link,
                    Min  = min,
                    Max  = max
                };
                App.config.itemShapeViews.Add(progressArc);
                t_grid.Children.Add(progressArc, i, 1);
                #endregion Arc
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Gauge", "Crashed: " + ex.ToString());
                Error(t_grid, i, 1, ex.ToString());
            }
        }
예제 #25
0
파일: Map.cs 프로젝트: johnjore/Kala
        public static void Map(Grid grid, int px, int py, int sx, int sy, string maptype, JArray data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Map Widget");
            CrossLogger.Current.Debug("Map", "Creating Map Widget");

            try
            {
                var map = new Map() //MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(0.3)))
                {
                    MyLocationEnabled = false,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    MapType           = GetMapType(maptype)
                };
                map.UiSettings.MyLocationButtonEnabled = false;
                ItemMaps.Add(map);

                //Items in Map widget
                List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >();
                CrossLogger.Current.Debug("Map", "Items: " + items.Count.ToString());

                var latitudes  = new List <double>();
                var longitudes = new List <double>();

                foreach (Models.Sitemap.Widget3 item in items)
                {
                    //Add the Pins to list and map
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(item.Label);

                    double lat  = 999.0;
                    double lon  = 999.0;
                    string name = string.Empty;

                    if (item.Item != null)
                    {
                        var b = item.Item.State.Split(',');

                        if (b.Count() >= 2)
                        {
                            double.TryParse(b[0], out lat);
                            double.TryParse(b[1], out lon);
                            name = item.Item.Name;
                        }
                    }
                    else
                    {
                        double.TryParse(widgetKeyValuePairs["lat"], out lat);
                        double.TryParse(widgetKeyValuePairs["lon"], out lon);
                    }

                    var pin = new Pin()
                    {
                        Type     = PinType.Place,
                        Label    = widgetKeyValuePairs["label"],
                        Tag      = name,
                        Position = new Position(lat, lon),
                        Icon     = BitmapDescriptorFactory.DefaultMarker(Color.Red)
                    };

                    //Color keywords
                    if (widgetKeyValuePairs.ContainsKey("color"))
                    {
                        pin.Icon = BitmapDescriptorFactory.DefaultMarker(GetColor(widgetKeyValuePairs["color"]));
                    }

                    //If valid, add it
                    if (lat != 999.0 && lon != 999.0)
                    {
                        latitudes.Add(lat);
                        longitudes.Add(lon);
                    }

                    map.Pins.Add(pin);
                }

                MapUpdate(latitudes, longitudes, map);

                grid.Children.Add(map, px, px + sx, py, py + sy);
                map.MapClicked  += Map_MapClicked;
                map.CameraIdled += Map_CameraIdled;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Map", "Crashed:" + ex.ToString());
            }
        }
예제 #26
0
        public static void WeatherForecast(Grid grid, string x1, string y1, string x2, string y2, string header, JArray data)
        {
            CrossLogger.Current.Debug("WeatherForecast", "Creating Weather forecast :" + data.ToString());

            List <Models.Sitemap.Widget3> items = null;
            int px = 0;
            int py = 0;
            int sx = 0;
            int sy = 0;

            try
            {
                //Position & Size
                px = Convert.ToInt16(x1);
                py = Convert.ToInt16(y1);
                sx = Convert.ToInt16(x2);
                sy = Convert.ToInt16(y2);

                //Items
                items = data.ToObject <List <Models.Sitemap.Widget3> >();
                CrossLogger.Current.Debug("WeatherForecast", "Nr of items: " + items.Count.ToString());
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("WeatherForecast", "Crashed:" + ex.ToString());
            }

            try
            {
                #region t_grid
                Grid t_grid = new Grid();
                t_grid.Padding           = new Thickness(0, 0, 0, 0);
                t_grid.RowSpacing        = 0;
                t_grid.ColumnSpacing     = 0;
                t_grid.BackgroundColor   = App.config.CellColor;
                t_grid.VerticalOptions   = LayoutOptions.FillAndExpand;
                t_grid.HorizontalOptions = LayoutOptions.FillAndExpand;

                //Rows
                t_grid.RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                    //new RowDefinition { Height = GridLength.Auto },
                    //new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
                };

                //Columns
                for (int i = 0; i < items.Count; i++)            //Each day has 3 items
                {
                    int day = 0;
                    Dictionary <string, string> widgetKeyValuePairs = Helpers.SplitCommand(items[i].label);
                    if (widgetKeyValuePairs.ContainsKey("item"))
                    {
                        day = Convert.ToInt16(widgetKeyValuePairs["item"].Substring(3, 1));
                    }
                    var digits = Digits(widgetKeyValuePairs, items[i].item.state);

                    #region Header
                    if (i % 3 == 0)
                    {
                        string DayOfWeek = "Today";
                        if (i / 3 != 0)
                        {
                            DayOfWeek = DateTime.Now.AddDays(i / 3).DayOfWeek.ToString().Substring(0, 3);
                        }

                        ItemLabel l_header = new ItemLabel
                        {
                            Text              = DayOfWeek,
                            FontSize          = 20,
                            TextColor         = App.config.TextColor,
                            BackgroundColor   = App.config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.Start
                        };
                        t_grid.Children.Add(l_header, i / 3, 0);
                    }
                    #endregion Header

                    #region Condition
                    if (items[i].label.Contains("condition"))
                    {
                        ItemLabel l_image = new ItemLabel
                        {
                            Text              = WeatherCondition(items[i].item.state),
                            TextColor         = App.config.TextColor,
                            FontFamily        = Device.OnPlatform(null, "weathericons-regular-webfont.ttf#Weather Icons", null),
                            FontSize          = 68,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.Center,
                            TranslationY      = -5,
                            Link              = items[i].item.link,
                            Type              = Models.Itemtypes.Weathericon
                        };
                        App.config.itemlabels.Add(l_image);
                        t_grid.Children.Add(l_image, day, 0);
                    }
                    #endregion Condition

                    #region Temperature
                    if (items[i].label.Contains("temperature-high"))
                    {
                        ItemLabel l_temp_high = new ItemLabel
                        {
                            FontSize          = 20,
                            TextColor         = App.config.TextColor,
                            BackgroundColor   = App.config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.End,
                            TranslationX      = -30,
                            Link   = items[i].item.link,
                            Pre    = "   ",
                            Post   = "\u00B0",
                            Text   = digits.Item1 + " \u00B0",
                            Digits = digits.Item2
                        };
                        App.config.itemlabels.Add(l_temp_high);
                        t_grid.Children.Add(l_temp_high, day, 0);
                    }

                    if (items[i].label.Contains("temperature-low"))
                    {
                        ItemLabel l_temp_low = new ItemLabel
                        {
                            FontSize          = 20,
                            TextColor         = App.config.TextColor,
                            BackgroundColor   = App.config.CellColor,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions   = LayoutOptions.End,
                            TranslationX      = 30,
                            Link   = items[i].item.link,
                            Post   = " \u00B0",
                            Text   = digits.Item1 + " \u00B0  ",
                            Digits = digits.Item2
                        };
                        App.config.itemlabels.Add(l_temp_low);
                        t_grid.Children.Add(l_temp_low, day, 0);
                    }
                    #endregion Temperature
                }

                grid.Children.Add(t_grid, px, px + sx, py, py + sy);
                #endregion t_grid
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("WeatherForecast", "Crashed: " + ex.ToString());
                Error(grid, px, py, ex.ToString());
            }
        }