Exemple #1
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());
            }
        }
Exemple #2
0
 public static void Switch_Off(App.trackItem item)
 {
     item.grid.Children.Add(new CircularProgressBarView
     {
         Progress                = 100,
         StrokeThickness         = Device.OnPlatform(2, 4, 16),
         BackgroundColor         = Color.Transparent,
         ProgressBackgroundColor = App.config.BackGroundColor,
         ProgressColor           = App.config.ValueColor,
         Scale = 0.5f
     }, item.px, item.py);
 }
Exemple #3
0
        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());
            }
        }
Exemple #4
0
 public static void Switch_On(App.trackItem item)
 {
     item.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
     }, item.px, item.py);
 }
Exemple #5
0
        public static void OnDimmerButtonClicked(object sender, EventArgs e)
        {
            Button button = sender as Button;

            App.trackItem item = null;
            string        link = button.StyleId;

            //Find current item
            foreach (App.trackItem i in App.config.items)
            {
                if (i.link.Equals(link))
                {
                    item = i;
                    break;
                }
            }

            CrossLogger.Current.Debug("Dimmer", "Button ID: '" + button.Id.ToString() + "', URL: '" + button.StyleId + "', State: '" + item.state + "'");

            PreviousPage = Application.Current.MainPage;
            Application.Current.MainPage = CreateSliderPage(item);
        }
Exemple #6
0
        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 { }
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        private static ContentPage CreateSliderPage(App.trackItem item)
        {
            //Capture un-initialized values
            double value = 50.0f;

            try
            {
                value = Convert.ToDouble(item.state);
            }
            catch
            {}

            Label heading = new Label
            {
                Text                    = item.header,
                FontSize                = 72,
                TextColor               = App.config.TextColor,
                BackgroundColor         = App.config.BackGroundColor,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Start
            };

            Slider slider = new Slider
            {
                Minimum           = 0.0f,
                Maximum           = 100.0f,
                Value             = value,
                HeightRequest     = 30,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                TranslationY      = 100,
                StyleId           = item.link,
            };

            slider.Effects.Add(Effect.Resolve("Effects.SliderEffect"));
            slider.ValueChanged += OnSliderValueChanged;

            Button button = new Button
            {
                Text              = "Close",
                FontSize          = 50,
                TextColor         = App.config.TextColor,
                BackgroundColor   = App.config.BackGroundColor,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.End,
                TranslationY      = 200
            };

            button.Clicked += (sender, e) => {
                Application.Current.MainPage = PreviousPage;
            };


            StackLayout sl = new StackLayout
            {
                Children          = { heading, slider, button },
                BackgroundColor   = App.config.BackGroundColor,
                Orientation       = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            ContentPage cp = new ContentPage();

            cp.Content = sl;

            return(cp);
        }
Exemple #9
0
        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
        }