コード例 #1
0
        public ChangeLEDColorPage(ParticleDevice device, Dictionary <string, string> variables)
        {
            var labelStyle = new Style(typeof(Label))
            {
                Setters =
                {
                    new Setter {
                        Property = Label.TextColorProperty, Value = Color.White
                    },
                    new Setter {
                        Property = Label.FontFamilyProperty, Value = Device.OnPlatform("AppleSDGothicNeo-Light", "Droid Sans Mono", "Comic Sans MS")
                    },
                }
            };

            var buttonStyle = new Style(typeof(Button))
            {
                Setters =
                {
                    new Setter {
                        Property = Button.TextColorProperty, Value = Color.White
                    },
                    new Setter {
                        Property = Button.FontFamilyProperty, Value = Device.OnPlatform("AppleSDGothicNeo-Light", "Droid Sans Mono", "Comic Sans MS")
                    },
                }
            };

            Resources = new ResourceDictionary();
            Resources.Add(labelStyle);
            Resources.Add(buttonStyle);

            ViewModel      = new ChangeLEDColorViewModel(variables);
            BindingContext = ViewModel;

            redSlider = new Slider {
                Minimum = 0,
                Maximum = 255,
                Value   = 0,
            };
            greenSlider = new Slider {
                Minimum = 0,
                Maximum = 255,
                Value   = 0,
            };
            blueSlider = new Slider {
                Minimum = 0,
                Maximum = 255,
                Value   = 0,
            };
            push = new Button {
                Text = "Push To Photon"
            };
            lightShow = new Button {
                Text = "Start a light show!"
            };

            off = new ToolbarItem {
                Text = "Off"
            };
            refresh = new ToolbarItem {
                Text = "Refresh"
            };

            StackLayout layout = new StackLayout
            {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Padding         = new Thickness(20, 0, 20, 0)
            };

            layout.Children.Add(new Label {
                Text = "R Value", HorizontalOptions = LayoutOptions.Start
            });
            layout.Children.Add(redSlider);
            layout.Children.Add(new Label {
                Text = "G Value", HorizontalOptions = LayoutOptions.Start
            });
            layout.Children.Add(greenSlider);
            layout.Children.Add(new Label {
                Text = "B Value", HorizontalOptions = LayoutOptions.Start
            });
            layout.Children.Add(blueSlider);
            layout.Children.Add(push);
            layout.Children.Add(lightShow);

            Content = layout;
            Padding = new Thickness(10, 0, 10, 0);

            push.Clicked      += PushColorToPhoton;
            lightShow.Clicked += StartLightShow;
            off.Clicked       += TurnOffLeds;
            refresh.Clicked   += RefreshFile;

            redSlider.SetBinding(Slider.ValueProperty, "R", BindingMode.TwoWay);
            greenSlider.SetBinding(Slider.ValueProperty, "G", BindingMode.TwoWay);
            blueSlider.SetBinding(Slider.ValueProperty, "B", BindingMode.TwoWay);
            this.SetBinding(ContentPage.BackgroundColorProperty, "ColorBoxColor");

            ToolbarItems.Add(off);
            ToolbarItems.Add(refresh);

            particleDevice = device;
        }
コード例 #2
0
        public ChangeLEDColorPage(ParticleDevice device, Dictionary <string, string> variables)
        {
            Title           = "RBG LED";
            BackgroundColor = AppColors.BackgroundColor;
            ViewModel       = new ChangeLEDColorViewModel(device, variables);
            BindingContext  = ViewModel;

            var indicator = new ActivityIndicator {
                HeightRequest = Device.OnPlatform(50, 30, 50)
            };
            var colorPreview = new BoxView {
                HeightRequest = 100
            };
            var redSlider = new Slider {
                StyleId = "redSlider", Minimum = 0, Maximum = 255, Value = 0
            };
            var greenSlider = new Slider {
                StyleId = "greenSlider", Minimum = 0, Maximum = 255, Value = 0
            };
            var blueSlider = new Slider {
                StyleId = "blueSlider", Minimum = 0, Maximum = 255, Value = 0
            };
            var push = new StyledButton
            {
                StyleId         = "pushRGBvalueButton",
                Text            = "PUSH TO PHOTON",
                BackgroundColor = AppColors.Blue,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                VerticalOptions = LayoutOptions.Fill
            };
            var lightShow = new StyledButton
            {
                StyleId         = "startLightShowButton",
                Text            = "START A LIGHT SHOW",
                BackgroundColor = AppColors.Green,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                VerticalOptions = LayoutOptions.End
            };
            var previewLabel = new StyledLabel {
                CssStyle = "body", Text = "Color Preview:", HorizontalOptions = LayoutOptions.Start
            };
            var rLabel = new StyledLabel {
                CssStyle = "body", Text = "R Value", HorizontalOptions = LayoutOptions.Start
            };
            var gLabel = new StyledLabel {
                CssStyle = "body", Text = "G Value", HorizontalOptions = LayoutOptions.Start
            };
            var bLabel = new StyledLabel {
                CssStyle = "body", Text = "B Value", HorizontalOptions = LayoutOptions.Start
            };

            Func <RelativeLayout, View, double> layoutAfterPrevious = (p, v) => Device.OnPlatform(
                v.Y + v.Height + 5,
                v.Y + v.Height + 5,
                v.Y + v.Height + 2);

            RelativeLayout relativeLayout = new RelativeLayout();

            relativeLayout.Children.Add(previewLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.Constant(10)
                                        );
            relativeLayout.Children.Add(colorPreview,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(previewLabel, layoutAfterPrevious),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                        heightConstraint: Constraint.Constant(AppSettings.ButtonHeight * 2)
                                        );
            relativeLayout.Children.Add(rLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(colorPreview, layoutAfterPrevious)
                                        );
            relativeLayout.Children.Add(redSlider,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(rLabel, layoutAfterPrevious),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
                                        );
            relativeLayout.Children.Add(gLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(redSlider, layoutAfterPrevious)
                                        );
            relativeLayout.Children.Add(greenSlider,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(gLabel, layoutAfterPrevious),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
                                        );
            relativeLayout.Children.Add(bLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(greenSlider, layoutAfterPrevious)
                                        );
            relativeLayout.Children.Add(blueSlider,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(bLabel, layoutAfterPrevious),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
                                        );
            relativeLayout.Children.Add(indicator,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(blueSlider, layoutAfterPrevious),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                        heightConstraint: Constraint.Constant(Device.OnPlatform(50, 50, 25))
                                        );
            relativeLayout.Children.Add(lightShow,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                        heightConstraint: Constraint.Constant(AppSettings.ButtonHeight)
                                        );
            relativeLayout.Children.Add(push,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(lightShow, (p, v) => v.Y - AppSettings.ButtonHeight - 10),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                        heightConstraint: Constraint.Constant(AppSettings.ButtonHeight)
                                        );



            //         StackLayout layout = new StackLayout
            //{
            //	VerticalOptions = LayoutOptions.CenterAndExpand,
            //	Padding = new Thickness(AppSettings.Margin, 10, AppSettings.Margin, AppSettings.Margin),
            //	Spacing = 10,
            //	Children = {
            //		new StyledLabel { CssStyle = "body", Text = "Color Preview:", HorizontalOptions = LayoutOptions.Start },
            //		colorPreview,
            //		new StyledLabel { CssStyle = "body", Text = "R Value", HorizontalOptions = LayoutOptions.Start },
            //		redSlider,
            //		new StyledLabel { CssStyle = "body", Text = "G Value", HorizontalOptions = LayoutOptions.Start },
            //		greenSlider,
            //		new StyledLabel { CssStyle = "body", Text = "B Value", HorizontalOptions = LayoutOptions.Start },
            //		blueSlider,
            //		indicator,
            //		push,
            //		lightShow
            //	}
            //};

            if (Device.OS == TargetPlatform.iOS)
            {
                push.FontFamily = "SegoeUI-Light";
                push.FontSize   = 16;
                push.TextColor  = Color.FromHex("#ffffff");

                lightShow.FontFamily = "SegoeUI-Light";
                lightShow.FontSize   = 16;
                lightShow.TextColor  = Color.FromHex("#ffffff");
            }

            var off = new ToolbarItem {
                Text = "LEDs Off"
            };

            Content = relativeLayout;


            indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android)
            {
                indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");
            }

            redSlider.SetBinding(Slider.ValueProperty, "R", BindingMode.TwoWay);
            greenSlider.SetBinding(Slider.ValueProperty, "G", BindingMode.TwoWay);
            blueSlider.SetBinding(Slider.ValueProperty, "B", BindingMode.TwoWay);
            colorPreview.SetBinding(BoxView.BackgroundColorProperty, "ColorBoxColor");
            push.SetBinding(Button.CommandProperty, "PushColorCommand");
            lightShow.SetBinding(Button.CommandProperty, "LightShowCommand");
            off.SetBinding(ToolbarItem.CommandProperty, "LedsOffCommand");

            ToolbarItems.Add(off);
        }