public static void Gauge(Grid grid, string x1, string y1, string header, JObject data) { int px = 0; int py = 0; //If this fails, we dont know where to show an error try { px = Convert.ToInt16(x1); py = Convert.ToInt16(y1); } catch (Exception ex) { CrossLogger.Current.Error("Gauge", "Crashed: " + ex.ToString()); } try { //Create Grid w/header Grid t_grid = Create_GaugeHeader(header, 1); //Item Models.Sitemap.Widget3 item = data.ToObject <Models.Sitemap.Widget3>(); //Column Create_Gauge(t_grid, 0, item); grid.Children.Add(t_grid, px, py); } catch (Exception ex) { CrossLogger.Current.Error("Gauge", "Crashed: " + ex.ToString()); Error(grid, px, py, ex.ToString()); } }
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()); } }
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()); } }
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()); } }
public static Tuple <string, bool> GetTrueState(Models.Sitemap.Widget3 item) { if (item.Item.TransformedState == null || item.Item.TransformedState.Equals(string.Empty)) { return(Tuple.Create(item.Item.State, false)); } else { return(Tuple.Create(item.Item.TransformedState, true)); } }
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()); } }
public static void Gauge(Grid grid, int px, int py, string header, JObject data) { Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Gauge Widget"); try { Models.Sitemap.Widget3 item = data.ToObject <Models.Sitemap.Widget3>(); Grid t_grid = Create_GaugeHeader(header, 1, 1); Create_Gauge(t_grid, 0, item); grid.Children.Add(t_grid, px, py); } catch (Exception ex) { CrossLogger.Current.Error("Gauge", "Crashed: " + ex.ToString()); Error(grid, px, py, 1, 1, ex.ToString()); } }
public static void Chart(Grid grid, int px, int py, int sx, int sy, string header, JObject data) { Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Chart Widget"); CrossLogger.Current.Debug("Chart", "Creating Chart Widget"); try { Models.Sitemap.Widget3 item = data.ToObject <Models.Sitemap.Widget3>(); //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 List <Entry> entries = new List <Entry> { new Entry(200) { Label = "January", ValueLabel = "200", Color = SKColor.Parse("#266489") }, new Entry(400) { Label = "February", ValueLabel = "400", Color = SKColor.Parse("#68B9C0") }, new Entry(-100) { Label = "March", ValueLabel = "-100", Color = SKColor.Parse("#90D585") } }; var cv = new ChartView(); cv.Chart = new BarChart() { Entries = entries }; // or: var chart = new PointChart() { Entries = entries }; // or: var chart = new LineChart() { Entries = entries }; // or: var chart = new DonutChart() { Entries = entries }; // or: var chart = new RadialGaugeChart() { Entries = entries }; // or: var chart = new RadarChart() { Entries = entries }; #region Button 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; #endregion Button } catch (Exception ex) { CrossLogger.Current.Error("Chart", "Crashed: " + ex.ToString()); Error(grid, px, py, 1, 1, ex.ToString()); } }
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()); } }
/// <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()); } }
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()); } }
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()); } }
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()); } }
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()); } }
/// <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()); } }
/// <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; } } } } }
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()); } }
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()); } }