コード例 #1
0
        private static void Music_Off(App.TrackItem item)
        {
            int intStrokeThickness = 1;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                intStrokeThickness = 2;
                break;

            case Device.Android:
                intStrokeThickness = 4;
                break;
            }

            item.Grid.Children.Add(new CircularProgressBarView
            {
                Progress                = 100,
                StrokeThickness         = intStrokeThickness,
                BackgroundColor         = Color.Transparent,
                ProgressBackgroundColor = App.Config.BackGroundColor,
                ProgressColor           = App.Config.ValueColor,
                Scale = 0.5f
            }, 0, 0);
        }
コード例 #2
0
        public static void Music(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Music Widget");
            CrossLogger.Current.Debug("Music", "Creating Music Widget");

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

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

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

                Music_update(true, i);
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Music", "Sensor crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
ファイル: Floormap.cs プロジェクト: dragonxu/Kala
 private static void Floorplan_update(App.TrackItem item)
 {
     foreach (App.TrackItem floormap in App.Config.Items.Where(n => n.Type == Itemtypes.Floormap))
     {
         floormap.State           = UpdateOnOff(item, floormap.State);
         floormap.SvgImage.Source = SvgImageSource.FromSvgString(floormap.State);
         floormap.SvgImage.ReloadImage();
     }
 }
コード例 #5
0
ファイル: Slider.cs プロジェクト: johnjore/Kala
        private static ContentPage CreateSliderPage(App.TrackItem item)
        {
            double.TryParse(item.State, out double value);

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

            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;
            };

            App.Config.LastActivity = DateTime.Now;

            return(new ContentPage {
                Content = new StackLayout
                {
                    Children = { new Label
                                 {
                                     Text = item.Header,
                                     FontSize = 72,
                                     TextColor = App.Config.TextColor,
                                     BackgroundColor = App.Config.BackGroundColor,
                                     HorizontalTextAlignment = TextAlignment.Center,
                                     VerticalTextAlignment = TextAlignment.Start
                                 },
                                 slider, button },
                    BackgroundColor = App.Config.BackGroundColor,
                    Orientation = StackOrientation.Vertical,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                }
            });
        }
コード例 #6
0
        private static void OnDimmerButtonClicked(object sender, EventArgs e)
        {
            Button button = sender as Button;
            string name   = button.StyleId;

            //Find item
            App.TrackItem item = App.Config.Items.Find(i => i.Name == name);
            Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Dimmer", "Button ID: '" + button.Id.ToString() + "', URL: '" + button.StyleId + "', State: '" + item.State + "'"));

            PreviousPage = Application.Current.MainPage;
            Application.Current.MainPage = CreateSliderPage(item);
        }
コード例 #7
0
 private static void Sensor_Off(App.TrackItem item)
 {
     item.Grid.Children.Add(new CircularProgressBarView
     {
         Progress                = 100,
         StrokeThickness         = 1,
         BackgroundColor         = Color.Transparent,
         ProgressBackgroundColor = App.Config.BackGroundColor,
         ProgressColor           = App.Config.ValueColor,
         Scale = 1.5f,
     }, 0, 1);
 }
コード例 #8
0
 private static void Music_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
     }, 0, 0);
 }
コード例 #9
0
ファイル: Floormap.cs プロジェクト: dragonxu/Kala
        private static string UpdateOnOff(App.TrackItem item, string svg)
        {
            int on  = 1;
            int off = 0;

            if (item.State.ToUpper().Equals("CLOSED"))
            {
                on  = 0;
                off = 1;
            }

            RegexOptions options = RegexOptions.IgnoreCase;

            svg = Regex.Replace(svg, "(.*" + item.Name + ".on.*stroke-opacity:)([0-1])(.*)", m => m.Groups[1].Value + on.ToString() + m.Groups[3].Value, options);
            svg = Regex.Replace(svg, "(.*" + item.Name + ".off.*stroke-opacity:)([0-1])(.*)", m => m.Groups[1].Value + off.ToString() + m.Groups[3].Value, options);

            return(svg);
        }
コード例 #10
0
        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
        }
コード例 #11
0
        public static void Dimmer_update(bool Create, App.TrackItem item)
        {
            item.Grid.Children.Clear();

            //Header
            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,
                VerticalOptions         = LayoutOptions.Start,
                HorizontalOptions       = LayoutOptions.Center
            }, 0, 2, 0, 1);

            //Center image
            item.Grid.Children.Add(new Image
            {
                Source            = item.Icon,
                Aspect            = Aspect.AspectFill,
                BackgroundColor   = App.Config.CellColor,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            }, 0, 2, 1, 2);

            //Progress bar around image
            try
            {
                int intStrokeThickness = 2;
                switch (Device.RuntimePlatform)
                {
                case Device.Android:
                    intStrokeThickness = 4;
                    break;
                }

                item.Grid.Children.Add(new CircularProgressBarView
                {
                    Progress                = Convert.ToInt16(item.State),
                    StrokeThickness         = intStrokeThickness,
                    BackgroundColor         = Color.Transparent,
                    ProgressBackgroundColor = App.Config.BackGroundColor,
                    ProgressColor           = App.Config.ValueColor,
                    Scale = 0.8f
                }, 0, 2, 1, 2);
            }
            catch
            {
                //Nothing to process
            }

            //Number value of progress bar
            switch (item.State.ToUpper())
            {
            case "ON": item.State = "100";
                break;

            case "OFF": item.State = "0";
                break;
            }
            item.Grid.Children.Add(new ItemLabel
            {
                Text                    = item.State,
                FontSize                = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                TextColor               = App.Config.TextColor,
                BackgroundColor         = App.Config.CellColor,
                HorizontalTextAlignment = TextAlignment.End,
                VerticalTextAlignment   = TextAlignment.Start,
                HorizontalOptions       = LayoutOptions.End,
                VerticalOptions         = LayoutOptions.End,
                TranslationY            = -10,
                Name                    = item.Name
            }, 0, 2);

            //Unit of progress bar
            item.Grid.Children.Add(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,
                Name              = item.Name
            }, 1, 2);

            Button dimmerButton = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
                StyleId           = item.Name //StyleID is not used on buttons
            };

            dimmerButton.Clicked += OnDimmerButtonClicked;
            Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Dimmer", "Button ID: " + dimmerButton.Id + " created."));
            item.Grid.Children.Add(dimmerButton, 0, 2, 0, 3);
        }
コード例 #12
0
        public static void Sensor_update(bool Create, App.TrackItem item)
        {
            Floorplan_update(item);

            if (item.Grid == null)
            {
                return;
            }

            item.Grid.Children.Clear();

            #region Header
            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"))
                    {
                        Sensor_Off(item);
                    }
                    else
                    {
                        Sensor_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, 1);
            #endregion Image

            #region Status Text
            item.Grid.Children.Add(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
            }, 0, 2);
            #endregion Status Text

            //Button must be last to be added to work
            Button dummyButton = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
            };
            item.Grid.Children.Add(dummyButton, 0, 1, 0, 2);
            dummyButton.Clicked += OnDummyButtonClicked;
        }
コード例 #13
0
ファイル: Switch.cs プロジェクト: johnjore/Kala
        public static void Switch_update(bool Create, App.TrackItem item)
        {
            string status = "N/A";

            item.Grid.Children.Clear();

            //Header
            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);

            //State
            if (item.State != null && !item.State.Equals("Uninitialized"))
            {
                try
                {
                    if (int.TryParse(item.State, out int 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, 0, 0, 1, 1, ex.ToString());
                }
            }

            //Image
            item.Grid.Children.Add(new Image
            {
                Source            = item.Icon,
                Aspect            = Aspect.AspectFill,
                BackgroundColor   = Color.Transparent,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            }, 0, 1);

            //Status
            item.Grid.Children.Add(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,
                Name              = item.Name
            }, 0, 2);

            //Button must be last to be added to work
            Button switchButton = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
                StyleId           = item.Name //StyleID is not used on buttons
            };

            item.Grid.Children.Add(switchButton, 0, 1, 0, 2);
            switchButton.Clicked += OnSwitchButtonClicked;
            Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Switch", "Button ID: " + switchButton.Id + " created."));
        }
コード例 #14
0
ファイル: Floormap.cs プロジェクト: dragonxu/Kala
        public static async void FloormapAsync(Grid grid, int px, int py, int sx, int sy, string header, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Floormap Widget");

            try
            {
                Floorplan flooritem = data.ToObject <Floorplan>();
                CrossLogger.Current.Debug("Floormap", "URL: " + flooritem.Url);

                var httpClient = new HttpClient();
                var svgString  = await httpClient.GetStringAsync(flooritem.Url);

                //Loop through SVG and find "ID" and add as Sensor
                MatchCollection matches = Regex.Matches(svgString, "(id=\")(.*)(.\\b(on|off))", RegexOptions.IgnoreCase);
                for (int j = 0; j < matches.Count; j++)
                {
                    string Itemid = matches[j].Groups[2].Value;
                    if (App.Config.Items.Find(s => s.Name == Itemid) == null)
                    {
                        CrossLogger.Current.Debug("Floormap", "Adding: " + Itemid);

                        RestService GetItemUpdate = new RestService();
                        string      state         = GetItemUpdate.GetItem(Itemid);

                        if (state != null)
                        {
                            App.TrackItem sensor = new App.TrackItem
                            {
                                Name  = Itemid,
                                State = state,
                                Type  = Itemtypes.Sensor
                            };
                            App.Config.Items.Add(sensor);
                        }
                    }
                }

                #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);
                #endregion w_grid

                #region 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);
                #endregion Header

                #region SVG
                SvgCachedImage svg = new SvgCachedImage
                {
                    DownsampleToViewSize = false,
                    CacheDuration        = TimeSpan.FromMilliseconds(1000),
                    Aspect = Aspect.AspectFit,
                    BitmapOptimizations = false,
                    Source = SvgImageSource.FromSvgString(svgString)
                };
                w_grid.Children.Add(svg, 0, 0);

                App.TrackItem svgImage = new App.TrackItem
                {
                    State    = svgString,
                    Header   = header,
                    Type     = Itemtypes.Floormap,
                    SvgImage = svg
                };
                App.Config.Items.Add(svgImage);
                #endregion SVG

                CrossLogger.Current.Debug("Floormap", "SVGBefore");
                foreach (App.TrackItem item in App.Config.Items.Where(n => n.Type == Itemtypes.Sensor))
                {
                    svgImage.State = UpdateOnOff(item, svgImage.State);
                }
                svgImage.SvgImage.Source = SvgImageSource.FromSvgString(svgImage.State);
                svgImage.SvgImage.ReloadImage();
                CrossLogger.Current.Debug("Floormap", "SVGAfter");

                //Button must be last to be added to work
                Button dummyButton = new Button
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                };
                w_grid.Children.Add(dummyButton, 0, 0);
                dummyButton.Clicked += OnDummyButtonClicked;
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Floormap", "Widgets.Floormap crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }