private static Grid Create_GaugeHeader(string header, int rx, int ry) { #region t_grid Grid t_grid = new Grid { Padding = new Thickness(3, 3, 3, 3), RowSpacing = 5, ColumnSpacing = 5, BackgroundColor = App.Config.CellColor, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; #endregion t_grid for (int r = 0; r < rx; r++) { t_grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); } //Header t_grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); //Body for (int r = 0; r < ry; r++) { t_grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); } //Header is in Row 0 ItemLabel l_header = new ItemLabel { Text = header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.Config.TextColor, BackgroundColor = App.Config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start }; t_grid.Children.Add(l_header, 0, 0 + rx, 0, 1); return(t_grid); }
private static Grid Create_GaugeHeader(string header, int sx) { #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 = GridLength.Auto }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, }; #endregion t_grid //Header is in Row 0 ItemLabel l_header = new ItemLabel { Text = header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start }; t_grid.Children.Add(l_header, 0, 0 + sx, 0, 1); return(t_grid); }
private static void Music_update(bool Create, App.TrackItem item) { #region Header (Also clears the old status) item.Grid.Children.Add(new Label { Text = item.Header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.Config.TextColor, BackgroundColor = App.Config.CellColor, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Start }, 0, 0); #endregion Header #region State if (!item.State.ToUpper().Equals("UNINITIALIZED")) { try { if (item.State.ToUpper().Equals("CLOSED")) { Music_Off(item); } else { Music_On(item); } } catch (Exception ex) { Error(item.Grid, 0, 0, 1, 1, ex.ToString()); } } else { item.State = "N/A"; } #endregion State #region Image item.Grid.Children.Add(new Xamarin.Forms.Image { Source = item.Icon, Aspect = Aspect.AspectFill, BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 0, 0, 1, 1); #endregion Image #region Status Text ItemLabel l_status = new ItemLabel { Text = item.State.ToUpper(), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = App.Config.TextColor, BackgroundColor = App.Config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, TranslationY = -10, Name = item.Name }; item.Grid.Children.Add(l_status, 0, 0); #endregion Status Text }
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()); } }
public static void Avatar(Grid grid, int px, int py, int sx, int sy, JArray data) { Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Avatar Widget"); CrossLogger.Current.Debug("Avatar", "Creating Avatar Widget"); try { List <Models.Sitemap.Widget3> items = data.ToObject <List <Models.Sitemap.Widget3> >(); #region w_grid Grid w_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 = GridLength.Auto }, }, ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, }, }; grid.Children.Add(w_grid, px, px + sx, py, py + sy); #endregion w_grid foreach (Models.Sitemap.Widget3 item in items) { if (item.Url != null) { var img = new CachedImage() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.StartAndExpand, DownsampleToViewSize = false, Aspect = Aspect.AspectFill, RetryCount = 999, RetryDelay = 1000, BitmapOptimizations = true, Transformations = new List <ITransformation>() { new CircleTransformation() }, Source = item.Url, }; w_grid.Children.Add(img, 0, 0); } else { var state = Helpers.GetTrueState(item); ItemLabel l_mode = new ItemLabel { Text = state.Item1, FontSize = 20, TextColor = App.Config.TextColor, BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, Name = item.Item.Name, Transformed = state.Item2 }; App.Config.Itemlabels.Add(l_mode); w_grid.Children.Add(l_mode, 0, 1); } } //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("Avatar", "Crashed: " + ex.ToString()); Error(grid, px, py, sx, sy, ex.ToString()); } }
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()); } }
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()); } }
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()); } }
public static void Dimmer_update(bool Create, App.trackItem item) { item.grid.Children.Add(new Label { Text = item.header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Start }, item.px, item.py); item.grid.Children.Add(new Image { Source = Device.OnPlatform(item.icon, item.icon, "Assets/" + item.icon), Aspect = Aspect.AspectFill, BackgroundColor = App.config.CellColor, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, item.px, item.px + 1, item.py, item.py + 1); ItemLabel l_status = new ItemLabel { Text = item.state, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, TranslationY = -10, Link = item.link }; l_status.HorizontalOptions = LayoutOptions.End; ItemLabel l_unit = new ItemLabel { Text = item.unit, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.End, TranslationY = -10, Link = item.link }; //Grid for status text at the bottom Grid g = new Grid(); g.RowDefinitions = new RowDefinitionCollection(); g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); g.ColumnDefinitions = new ColumnDefinitionCollection(); g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); g.RowSpacing = 6; g.ColumnSpacing = 6; g.BackgroundColor = App.config.CellColor; g.HorizontalOptions = LayoutOptions.Center; g.VerticalOptions = LayoutOptions.End; g.Children.Add(l_status, 0, 0); g.Children.Add(l_unit, 1, 0); item.grid.Children.Add(g, item.px, item.py); //Capturs non-initialized item try { item.grid.Children.Add(new CircularProgressBarView { Progress = Convert.ToInt16(item.state), StrokeThickness = Device.OnPlatform(2, 4, 16), BackgroundColor = Color.Transparent, ProgressBackgroundColor = App.config.BackGroundColor, ProgressColor = App.config.ValueColor, Scale = 0.5f }, item.px, item.py); } catch { } }
public static void Switch_update(bool Create, App.trackItem item) { string status = "N/A"; //Header (Also clears the old status) item.grid.Children.Add(new Label { Text = item.header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Start }, item.px, item.py); if (!item.state.Equals("Uninitialized")) { try { int stat; if (int.TryParse(item.state, out stat)) { if (stat > 0) { Switch_On(item); status = "ON"; } else { Switch_Off(item); status = "OFF"; } } else { if (item.state.ToUpper().Equals("OFF")) { Switch_Off(item); status = "OFF"; } else { Switch_On(item); status = "ON"; } } } catch (Exception ex) { Error(item.grid, item.px, item.py, ex.ToString()); } } //Image item.grid.Children.Add(new Image { Source = Device.OnPlatform(item.icon, item.icon, "Assets/" + item.icon), Aspect = Aspect.AspectFill, BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, item.px, item.px + 1, item.py, item.py + 1); //Status ItemLabel l_status = new ItemLabel { Text = status.ToUpper(), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, TranslationY = -10, Link = item.link }; item.grid.Children.Add(l_status, item.px, item.py); }
public static void Avatar(Grid grid, string x1, string y1, string x2, string y2, JObject data) { CrossLogger.Current.Debug("Avatar", "Creating Avatar 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("Avatar", "Crashed: " + ex.ToString()); } try { Models.avatar item = data.ToObject<Models.avatar>(); #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 = GridLength.Auto }, }; w_grid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, }; w_grid.Padding = new Thickness(0, 0, 0, 0); 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 var image = new CachedImage() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.StartAndExpand, DownsampleToViewSize = false, CacheDuration = TimeSpan.FromMilliseconds(1000), Aspect = Aspect.AspectFill, RetryCount = 0, RetryDelay = 250, BitmapOptimizations = true, Transformations = new List<ITransformation>() { new CircleTransformation() }, Source = item.url, }; w_grid.Children.Add(image, 0, 0); ItemLabel l_mode = new ItemLabel { Text = item.item.state, FontSize = 20, TextColor = App.config.TextColor, BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, Link = item.item.link }; App.config.itemlabels.Add(l_mode); w_grid.Children.Add(l_mode, 0, 1); } catch (Exception ex) { CrossLogger.Current.Error("Avatar", "Crashed: " + ex.ToString()); Error(grid, px, py, ex.ToString()); } }
public static void Sensor_update(bool Create, App.trackItem item) { #region Header (Also clears the old status) item.grid.Children.Add(new Label { Text = item.header, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Start }, item.px, item.py); #endregion Header #region State if (!item.state.ToUpper().Equals("UNINITIALIZED")) { try { if (item.state.ToUpper().Equals("CLOSED")) { Sensor_Off(item); } else { Sensor_On(item); } } catch (Exception ex) { Error(item.grid, item.px, item.py, ex.ToString()); } } else { item.state = "N/A"; } #endregion State #region Image item.grid.Children.Add(new Image { Source = Device.OnPlatform(item.icon, item.icon, "Assets/" + item.icon), Aspect = Aspect.AspectFill, BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, item.px, item.px + 1, item.py, item.py + 1); #endregion Image #region Status Text ItemLabel l_status = new ItemLabel { Text = item.state.ToUpper(), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = App.config.TextColor, BackgroundColor = App.config.CellColor, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End, TranslationY = -10, Link = item.link }; item.grid.Children.Add(l_status, item.px, item.py); #endregion Status Text }
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()); } }