Esempio n. 1
0
        public DeviceListViewHeader()
        {
            var deviceName = new StyledLabel
            {
                CssStyle = "h2left",
                Text     = "Device Name"
            };
            var lastHeard = new StyledLabel
            {
                CssStyle          = "h2",
                Text              = "Last Heard",
                HorizontalOptions = LayoutOptions.End,
            };

            ColumnDefinitions = new ColumnDefinitionCollection {
                new ColumnDefinition {
                    Width = GridLength.Star
                },
                new ColumnDefinition {
                    Width = GridLength.Auto
                }
            };

            Children.Add(deviceName, 0, 0);
            Children.Add(lastHeard, 1, 0);
            Padding = new Thickness(10, 0, 10, 0);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                formsElement = e.NewElement as StyledLabel;
                formsElement.HorizontalTextAlignment = TextAlignment.Center;
                uwpElement = Control;

                switch (formsElement.CssStyle)
                {
                case "h1":
                    SetHeading1Font();
                    break;

                case "h2":
                    SetHeading2Font();
                    break;

                case "body":
                    SetBodyFont();
                    break;

                case "widgetCount":
                    SetWidgetCountFont();
                    break;
                }
            }
        }
Esempio n. 3
0
        public DeviceCell()
        {
            deviceName = new StyledLabel {
                CssStyle = "h3", VerticalOptions = LayoutOptions.Center
            };
            lastHeard = new StyledLabel {
                CssStyle = "body", VerticalOptions = LayoutOptions.Center
            };

            Grid layout = new Grid
            {
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                },
                Padding = new Thickness(20, 0, 10, 0)
            };

            layout.Children.Add(deviceName, 0, 0);
            layout.Children.Add(lastHeard, 1, 0);

            deviceName.SetBinding(Label.TextProperty, "Name");
            lastHeard.SetBinding(Label.TextProperty, "LastHeard", BindingMode.Default, null, "{0:MM/dd H:mm}");

            View = layout;
        }
Esempio n. 4
0
        public DashboardWidget()
        {
            WidgetTitle = new StyledLabel {
                CssStyle = "widgetTitle"
            };
            WidgetCount = new StyledLabel {
                CssStyle = "widgetCount"
            };

            Func <RelativeLayout, double> getWidgetCountWidth = (p) => WidgetCount.GetSizeRequest(this.Width, this.Height).Request.Width;

            Children.Add(WidgetTitle,
                         xConstraint: Constraint.Constant(AppSettings.Margin),
                         yConstraint: Constraint.Constant(10),
                         widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
                         );
            Children.Add(WidgetCount,
                         xConstraint: Constraint.RelativeToParent(p => (p.Width - getWidgetCountWidth(p)) / 2),
                         yConstraint: Device.OnPlatform(
                             Constraint.RelativeToView(WidgetTitle, (p, v) => v.Y + 20),
                             Constraint.RelativeToView(WidgetTitle, (p, v) => v.Y + 10),
                             Constraint.RelativeToView(WidgetTitle, (p, v) => v.Y + 20)
                             )
                         );
            BackgroundColor = AppColors.LightGray;
        }
Esempio n. 5
0
        public DeviceListViewHeader()
        {
            var deviceName = new StyledLabel
            {
                CssStyle = "h2left",
                Text     = "Device Name"
            };
            var lastHeard = new StyledLabel
            {
                CssStyle        = "h2left",
                Text            = "Last Heard",
                VerticalOptions = LayoutOptions.Center,
            };

            ColumnDefinitions = new ColumnDefinitionCollection {
                new ColumnDefinition {
                    Width = new GridLength(2, GridUnitType.Star)
                },
                new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                }
            };

            Children.Add(deviceName, 0, 0);
            Children.Add(lastHeard, 1, 0);
            Padding = new Thickness(10, 0, 5, 0);
        }
Esempio n. 6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            _styledElement = _styledElement ?? (Element as StyledLabel);

            if (Control != null)
            {
                TextStyle.Style <UILabel>(Control, _styledElement.CssStyle);
            }
        }
Esempio n. 7
0
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            _styledElement = _styledElement ?? (Element as StyledLabel);

            if (Control != null)
            {
                SetStyle();
                _textStyle.Style(Control, _styledElement.CssStyle, null, _styledElement.CustomTags);
            }
        }
Esempio n. 8
0
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            _styledElement = _styledElement ?? (Element as StyledLabel);

            var cssStyle = _styledElement.CssStyle;

            var textStyle = (!string.IsNullOrEmpty(_styledElement.TextStyleInstance) && TextStyle.Instances.ContainsKey(_styledElement.TextStyleInstance))
                                        ? TextStyle.Instances[_styledElement.TextStyleInstance] : TextStyle.Main;

            if (Control != null)
            {
                textStyle.Style(Control, cssStyle, null, _styledElement.CustomTags);
            }
        }
Esempio n. 9
0
		public DashboardWidget ()
		{
			WidgetTitle = new StyledLabel { CssStyle = "widgetTitle" };
			WidgetCount = new StyledLabel { CssStyle = "widgetCount" };

			Func<RelativeLayout, double> getWidgetCountWidth = (p) => WidgetCount.GetSizeRequest (this.Width, this.Height).Request.Width;

			Children.Add (WidgetTitle,
				xConstraint: Constraint.Constant (AppSettings.Margin),
				yConstraint: Constraint.Constant (10),
				widthConstraint: Constraint.RelativeToParent (p => p.Width - AppSettings.Margin * 2)
			);
			Children.Add (WidgetCount,
				xConstraint: Constraint.RelativeToParent (p => (p.Width - getWidgetCountWidth (p)) / 2),
			    yConstraint: Device.OnPlatform (
				Constraint.RelativeToView (WidgetTitle, (p, v) => v.Y + 20),
				Constraint.RelativeToView (WidgetTitle, (p, v) => v.Y + 10),
				Constraint.RelativeToView (WidgetTitle, (p, v) => v.Y + 20)
			   )
			);
			BackgroundColor = AppColors.LightGray;
		}
Esempio n. 10
0
        public DeviceLandingPage(ParticleDevice device)
        {
            Title           = "Mission Control";
            BackgroundColor = AppColors.BackgroundColor;
            ViewModel       = new DeviceLandingPageViewModel(device);
            BindingContext  = ViewModel;

            var refreshDevice = new ToolbarItem {
                Icon = "ic_cached_white_24dp.png"
            };
            var back = new ToolbarItem {
                Icon = "ic_clear_white.png"
            };
            var layout = new RelativeLayout();

            var indicator  = new ActivityIndicator();
            var deviceName = new StyledLabel {
                CssStyle = "h1"
            };
            var deviceConnected = new Image {
                Source = "notconnected.png"
            };
            var currentAppLabel = new StyledLabel {
                CssStyle = "h2"
            };
            var variableWidget = new DashboardWidget();
            var functionWidget = new DashboardWidget();
            var appDescription = new StyledLabel {
                CssStyle = "body"
            };
            var interactButton = new StyledButton
            {
                StyleId         = "startInteractionButton",
                Text            = "START INTERACTION",
                BackgroundColor = AppColors.Green,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                IsEnabled       = false
            };
            var flashButton = new StyledButton
            {
                StyleId         = "flashBinaryButton",
                Text            = "FLASH NEW APP",
                BackgroundColor = AppColors.Purple,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                IsEnabled       = false
            };

            var boxConstraint = Constraint.RelativeToParent(p => p.Width / 2 - AppSettings.Margin - AppSettings.ItemPadding / 2);

            layout.Children.Add(deviceName,
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.Constant(Device.OnPlatform(AppSettings.Margin, 10, 10)),
                                widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
                                );
            layout.Children.Add(currentAppLabel,
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Y + v.Height + 5),
                                widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                heightConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Height)
                                );
            layout.Children.Add(variableWidget,
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.RelativeToView(currentAppLabel, (p, v) => Device.OnPlatform(
                                                                           v.Y + v.Height + 5,
                                                                           v.Y + v.Height,
                                                                           v.Y + v.Height)
                                                                       ),
                                widthConstraint: boxConstraint,
                                heightConstraint: boxConstraint
                                );
            layout.Children.Add(functionWidget,
                                xConstraint: Constraint.RelativeToParent(p => p.Width / 2 + AppSettings.ItemPadding / 2),
                                yConstraint: Constraint.RelativeToView(variableWidget, (p, v) => v.Y),
                                widthConstraint: boxConstraint,
                                heightConstraint: boxConstraint
                                );
            layout.Children.Add(new ScrollView {
                Content = appDescription
            },
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10),
                                widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20)
                                );
            layout.Children.Add(flashButton,
                                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)
                                );
            layout.Children.Add(interactButton,
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.RelativeToView(flashButton, (p, v) => v.Y - AppSettings.ButtonHeight - 10),
                                widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                heightConstraint: Constraint.Constant(AppSettings.ButtonHeight)
                                );
            layout.Children.Add(indicator,
                                xConstraint: Constraint.Constant(AppSettings.Margin),
                                yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10),
                                widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
                                heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20)
                                );

            variableWidget.WidgetTitle.Text = "Variables";
            functionWidget.WidgetTitle.Text = "Functions";

            if (Device.OS == TargetPlatform.iOS)
            {
                interactButton.TextColor = Color.FromHex("#ffffff");
                flashButton.TextColor    = Color.FromHex("#ffffff");
            }

            Content = layout;
            ToolbarItems.Add(refreshDevice);
            ToolbarItems.Add(back);

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

            deviceName.SetBinding(Label.TextProperty, "Device.Name");
            currentAppLabel.SetBinding(Label.TextProperty, "CurrentApp");
            deviceConnected.SetBinding(Image.IsVisibleProperty, "DeviceConnected");
            variableWidget.WidgetCount.SetBinding(Label.TextProperty, "VariableCount");
            functionWidget.WidgetCount.SetBinding(Label.TextProperty, "FunctionCount");
            interactButton.SetBinding(Button.IsEnabledProperty, "InteractButtonLock");
            flashButton.SetBinding(Button.IsEnabledProperty, "FlashButtonLock");
            refreshDevice.SetBinding(ToolbarItem.CommandProperty, "RefreshDeviceCommand");
            appDescription.SetBinding(Label.TextProperty, "AppDescription");

            interactButton.Clicked += async(object sender, EventArgs e) =>
            {
                if (ViewModel.CurrentApp.ToLower().Contains("rgb led picker"))
                {
                    await Navigation.PushAsync(new ChangeLEDColorPage(ViewModel.Device, ViewModel.variables));
                }
                else if (ViewModel.CurrentApp.ToLower().Contains("simonsays"))
                {
                    await Navigation.PushAsync(new SimonSaysPage(ViewModel.Device));
                }
                else
                {
                    DisplayAlert("Sorry...", "There isn't a mobile interaction with this IoT app. Try flashing either the 'Simon Says' or ' RBG LED' app.", "Ok");
                }
            };

            flashButton.Clicked += async(object sender, EventArgs e) =>
            {
                var result = await DisplayActionSheet("Pick File to Flash", "Cancel", null, "RGB LED", "Shake LED", "Simon Says", "Follow me LED");

                if (result != "Cancel")
                {
                    var success = await ViewModel.TryFlashFileAsync(result);

                    if (!success)
                    {
                        await DisplayAlert("Error", "The Device connection timed out. Please try again once the device breaths a solid cyan light", "Ok");
                    }
                }
            };

            back.Clicked += async(object sender, EventArgs e) =>
            {
                var success = await ViewModel.Device.UnclaimAsync();

                //if (success)
                Navigation.PopModalAsync(true);
            };
        }
Esempio n. 11
0
        public static void criarConteudo(StackLayout layout, List <string> listaDeConteudo)
        {
            FontAttributes atributoDaFonte = FontAttributes.None;
            double         tamanhoDaFonte  = Device.GetNamedSize(NamedSize.Medium, typeof(Label));

            foreach (string linha in listaDeConteudo)
            {
                if (linha.Equals("[botao]"))
                {
                    StyledButton button = new StyledButton
                    {
                        Text           = "Áudio Demonstrativo",
                        FontSize       = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                        Style          = (Style)Application.Current.Resources["buttonStyle1"],
                        FontAttributes = FontAttributes.Bold
                    };

                    button.Clicked += TocarAudio;
                    layout.Children.Add(button);
                }
                else if (linha.Contains("[link]"))
                {
                    string linhaLink = linha;
                    linhaLink = linhaLink.Replace("[link]", "");
                    linhaLink = linhaLink.Replace("[/link]", "");

                    var label = new Label()
                    {
                        Text           = linhaLink,
                        FontSize       = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                        FontAttributes = FontAttributes.Bold,
                        TextColor      = Color.FromHex("#2D12DB") //8E97E1
                    };

                    string enderecoSite = label.Text.Trim();

                    if (!(enderecoSite.Substring(0, 4).Equals("http")))
                    {
                        enderecoSite = enderecoSite.Insert(0, "http://");
                    }

                    var tapGestureRecognizer = new TapGestureRecognizer();
                    tapGestureRecognizer.Tapped += (s, e) => {
                        try
                        {
                            Device.OpenUri(new Uri(enderecoSite));
                        }
                        catch (Exception exc)
                        {
                            System.Diagnostics.Debug.WriteLine("ERRO: " + exc.Message);
                        }
                    };
                    label.GestureRecognizers.Add(tapGestureRecognizer);

                    layout.Children.Add(label);
                }
                else
                {
                    var label = new StyledLabel()
                    {
                        Style = (Style)Application.Current.Resources["labelStyle1"]
                    };
                    var s = new FormattedString();
                    if (linha.Contains("[b]") || linha.Contains("[i]") || linha.Contains("[small]") || linha.Contains("[large]"))
                    {
                        string linhaComAtributos = linha;
                        while (linhaComAtributos.Contains("[b]") || linhaComAtributos.Contains("[i]") || linhaComAtributos.Contains("[small]") || linhaComAtributos.Contains("[/b]") || linhaComAtributos.Contains("[/i]") || linhaComAtributos.Contains("[/small]") || linhaComAtributos.Contains("[large]") || linhaComAtributos.Contains("[/large]"))
                        {
                            string trecho = "";

                            int posicaoAtributoMaisProximo = linhaComAtributos.IndexOf('[');

                            if (posicaoAtributoMaisProximo != 0)
                            {
                                trecho            = linhaComAtributos.Substring(0, posicaoAtributoMaisProximo);
                                linhaComAtributos = linhaComAtributos.Substring(posicaoAtributoMaisProximo);
                            }
                            else
                            {
                                if (linhaComAtributos.Substring(0, 3).Equals("[b]"))
                                {
                                    atributoDaFonte   = FontAttributes.Bold;
                                    linhaComAtributos = linhaComAtributos.Substring(3);
                                }
                                else if (linhaComAtributos.Substring(0, 3).Equals("[i]"))
                                {
                                    atributoDaFonte   = FontAttributes.Italic;
                                    linhaComAtributos = linhaComAtributos.Substring(3);
                                }
                                else if (linhaComAtributos.Substring(0, 4).Equals("[/b]"))
                                {
                                    atributoDaFonte   = FontAttributes.None;
                                    linhaComAtributos = linhaComAtributos.Substring(4);
                                }
                                else if (linhaComAtributos.Substring(0, 4).Equals("[/i]"))
                                {
                                    atributoDaFonte   = FontAttributes.None;
                                    linhaComAtributos = linhaComAtributos.Substring(4);
                                }
                                else if (linhaComAtributos.Contains("[small]") || linhaComAtributos.Contains("[/small]"))
                                {
                                    if (linhaComAtributos.Substring(0, 7).Equals("[small]"))
                                    {
                                        tamanhoDaFonte    = Device.GetNamedSize(NamedSize.Small, typeof(Label));
                                        linhaComAtributos = linhaComAtributos.Substring(7);
                                    }
                                    if (linhaComAtributos.Substring(0, 8).Equals("[/small]"))
                                    {
                                        tamanhoDaFonte    = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
                                        linhaComAtributos = linhaComAtributos.Substring(8);
                                    }
                                }
                                else if (linhaComAtributos.Contains("[large]") || linhaComAtributos.Contains("[/large]"))
                                {
                                    if (linhaComAtributos.Substring(0, 7).Equals("[large]"))
                                    {
                                        tamanhoDaFonte    = Device.GetNamedSize(NamedSize.Large, typeof(Label));
                                        linhaComAtributos = linhaComAtributos.Substring(7);
                                    }
                                    if (linhaComAtributos.Substring(0, 8).Equals("[/large]"))
                                    {
                                        tamanhoDaFonte    = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
                                        linhaComAtributos = linhaComAtributos.Substring(8);
                                    }
                                }
                                else
                                {
                                    trecho            = "[";
                                    linhaComAtributos = linhaComAtributos.Substring(1);
                                }
                            }

                            s.Spans.Add(new Span {
                                Text = trecho + "", FontSize = tamanhoDaFonte, FontAttributes = atributoDaFonte
                            });
                        }
                        s.Spans.Add(new Span {
                            Text = linhaComAtributos, FontSize = tamanhoDaFonte, FontAttributes = atributoDaFonte
                        });
                    }
                    else
                    {
                        s.Spans.Add(new Span {
                            Text = linha, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
                        });
                    }
                    label.FormattedText = s;
                    layout.Children.Add(label);
                }
            }
        }
Esempio n. 12
0
		public DeviceLandingPage(ParticleDevice device)
		{
			Title = "Mission Control";
			BackgroundColor = AppColors.BackgroundColor;
			ViewModel = new DeviceLandingPageViewModel(device);
			BindingContext = ViewModel;

			var refreshDevice = new ToolbarItem { Icon = "ic_cached_white_24dp.png" };
			var back = new ToolbarItem { Icon = "ic_clear_white.png" };
			var layout = new RelativeLayout();

			var indicator = new ActivityIndicator();
			var deviceName = new StyledLabel { CssStyle = "h1" };
			var deviceConnected = new Image { Source = "notconnected.png" };
			var currentAppLabel = new StyledLabel { CssStyle = "h2" };
			var variableWidget = new DashboardWidget();
			var functionWidget = new DashboardWidget();
			var appDescription = new StyledLabel { CssStyle = "body" };
			var interactButton = new StyledButton
			{
				StyleId = "startInteractionButton",
				Text = "START INTERACTION",
				BackgroundColor = AppColors.Green,
				CssStyle = "button",
				BorderRadius = 0,
				HeightRequest = AppSettings.ButtonHeight,
				IsEnabled = false
			};
			var flashButton = new StyledButton
			{
				StyleId = "flashBinaryButton",
				Text = "FLASH NEW APP",
				BackgroundColor = AppColors.Purple,
				CssStyle = "button",
				BorderRadius = 0,
				HeightRequest = AppSettings.ButtonHeight,
				IsEnabled = false
			};

			var boxConstraint = Constraint.RelativeToParent(p => p.Width / 2 - AppSettings.Margin - AppSettings.ItemPadding / 2);

			layout.Children.Add(deviceName,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.Constant(Device.OnPlatform(AppSettings.Margin, 10, 10)),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
			);
			layout.Children.Add(currentAppLabel,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Y + v.Height + 5),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.RelativeToView(deviceName, (p, v) => v.Height)
			);
			layout.Children.Add(variableWidget,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(currentAppLabel, (p, v) => Device.OnPlatform(
																v.Y + v.Height + 5,
																v.Y + v.Height,
																v.Y + v.Height)
													  ),
				widthConstraint: boxConstraint,
				heightConstraint: boxConstraint
			);
			layout.Children.Add(functionWidget,
				xConstraint: Constraint.RelativeToParent(p => p.Width / 2 + AppSettings.ItemPadding / 2),
				yConstraint: Constraint.RelativeToView(variableWidget, (p, v) => v.Y),
				widthConstraint: boxConstraint,
				heightConstraint: boxConstraint
			);
			layout.Children.Add(new ScrollView { Content = appDescription },
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20)
			);
			layout.Children.Add(flashButton,
				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)
			);
			layout.Children.Add(interactButton,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(flashButton, (p, v) => v.Y - AppSettings.ButtonHeight - 10),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.Constant(AppSettings.ButtonHeight)
			);
			layout.Children.Add(indicator,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(functionWidget, (p, v) => v.Y + v.Height + 10),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.RelativeToView(functionWidget, (p, v) => p.Height - v.Y - v.Height - 10 - AppSettings.Margin - 2 * AppSettings.ButtonHeight - 20)
			);

			variableWidget.WidgetTitle.Text = "Variables";
			functionWidget.WidgetTitle.Text = "Functions";

			if (Device.OS == TargetPlatform.iOS)
			{
				interactButton.TextColor = Color.FromHex("#ffffff");
				flashButton.TextColor = Color.FromHex("#ffffff");
			}

			Content = layout;
			ToolbarItems.Add(refreshDevice);
			ToolbarItems.Add(back);

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

			deviceName.SetBinding(Label.TextProperty, "Device.Name");
			currentAppLabel.SetBinding(Label.TextProperty, "CurrentApp");
			deviceConnected.SetBinding(Image.IsVisibleProperty, "DeviceConnected");
			variableWidget.WidgetCount.SetBinding(Label.TextProperty, "VariableCount");
			functionWidget.WidgetCount.SetBinding(Label.TextProperty, "FunctionCount");
			interactButton.SetBinding(Button.IsEnabledProperty, "InteractButtonLock");
			flashButton.SetBinding(Button.IsEnabledProperty, "FlashButtonLock");
			refreshDevice.SetBinding(ToolbarItem.CommandProperty, "RefreshDeviceCommand");
			appDescription.SetBinding(Label.TextProperty, "AppDescription");

			interactButton.Clicked += async (object sender, EventArgs e) =>
			{
				if (ViewModel.CurrentApp.ToLower().Contains("rgb led picker"))
					await Navigation.PushAsync(new ChangeLEDColorPage(ViewModel.Device, ViewModel.variables));
				else if (ViewModel.CurrentApp.ToLower().Contains("simonsays"))
					await Navigation.PushAsync(new SimonSaysPage(ViewModel.Device));
				else
					DisplayAlert("Sorry...", "There isn't a mobile interaction with this IoT app. Try flashing either the 'Simon Says' or ' RBG LED' app.", "Ok");
			};

			flashButton.Clicked += async (object sender, EventArgs e) =>
			{
				var result = await DisplayActionSheet("Pick File to Flash", "Cancel", null, "RGB LED", "Shake LED", "Simon Says", "Follow me LED");
				if (result != "Cancel")
				{
					var success = await ViewModel.TryFlashFileAsync(result);
					if (!success)
					{
						await DisplayAlert("Error", "The Device connection timed out. Please try again once the device breaths a solid cyan light", "Ok");
					}
				}
			};

			back.Clicked += async (object sender, EventArgs e) =>
			{
				var success = await ViewModel.Device.UnclaimAsync();
				//if (success)
				Navigation.PopModalAsync(true);
			};
		}
Esempio n. 13
0
        public NewUserSignUpPage()
        {
            ViewModel.SaveFailed                += HandleSaveFailed;
            ViewModel.TakePhotoFailed           += HandleTakePhotoFailed;
            ViewModel.SaveSuccessfullyCompleted += HandleSaveSuccessfullyCompleted;

            BackgroundColor = Color.FromHex("2980b9");

            var passwordEntry = new StyledEntry(1)
            {
                Placeholder             = "Password",
                IsPassword              = true,
                HorizontalOptions       = LayoutOptions.Fill,
                HorizontalTextAlignment = TextAlignment.End,
                VerticalOptions         = LayoutOptions.Fill,
                PlaceholderColor        = Color.FromHex("749FA8"),
                ReturnType              = ReturnType.Done
            };

            passwordEntry.ReturnCommand = new Command(() => passwordEntry.Unfocus());
            passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText));

            var usernameEntry = new StyledEntry(1)
            {
                Placeholder             = "Username",
                HorizontalOptions       = LayoutOptions.Fill,
                HorizontalTextAlignment = TextAlignment.End,
                PlaceholderColor        = Color.FromHex("749FA8"),
                ReturnType    = ReturnType.Next,
                ReturnCommand = new Command(() => passwordEntry.Focus())
            };

            usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

            _saveUsernameButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Save User",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };
            _saveUsernameButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _saveUsernameButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SaveButtonCommand));

            _cancelButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Cancel",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End
            };
            _cancelButton.Clicked += HandleCancelButtonClicked;
            _cancelButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _cancelButton.SetBinding(Button.CommandProperty, nameof(ViewModel.CancelButtonCommand));

            _takePhotoButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Take Photo",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };
            _takePhotoButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _takePhotoButton.SetBinding(Button.CommandProperty, nameof(ViewModel.TakePhotoButtonCommand));

            var isFacialRecognitionCompletedDescriptionLabel = new StyledLabel
            {
                Text = "Facial Recognition Completed",
                VerticalTextAlignment = TextAlignment.Center
            };

            var isFacialRecognitionCompletedLabel = new FontAwesomeIcon
            {
                TextColor               = Color.White,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center
            };

            isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(ViewModel.FontAwesomeLabelText));

            if (Device.RuntimePlatform is Device.iOS)
            {
                isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive));
            }

            var activityIndicator = new ActivityIndicator
            {
                Color             = Color.White,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand,
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive));

            var facialRecognitionStackLayout = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center,

                Children =
                {
                    isFacialRecognitionCompletedDescriptionLabel,
                    isFacialRecognitionCompletedLabel
                }
            };

            var stackLayout = new StackLayout
            {
                Padding         = new Thickness(20, 50, 20, 20),
                VerticalOptions = LayoutOptions.FillAndExpand,

                Children =
                {
                    new Label
                    {
                        Text              = "Please enter username",
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Start
                    },

                    usernameEntry,

                    new Label
                    {
                        Text              = "Please enter password",
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Start
                    },

                    passwordEntry,
                    _takePhotoButton,
                    facialRecognitionStackLayout,
                }
            };

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                facialRecognitionStackLayout.Children.Add(activityIndicator);
                break;

            case Device.Android:
                stackLayout.Children.Add(activityIndicator);
                break;

            default:
                throw new NotSupportedException("Device Runtime Unsupported");
            }
            stackLayout.Children.Add(_saveUsernameButton);
            stackLayout.Children.Add(_cancelButton);

            Content = new Xamarin.Forms.ScrollView {
                Content = stackLayout
            };

            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public FirstPage()
        {
            const string entryTextPaceHolder = "Enter text and click 'Go'";

            var viewModel = new FirstPageViewModel();

            BindingContext = viewModel;

            _goButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go",
                AutomationId = AutomationIdConstants.GoButton,                 // This provides an ID that can be referenced in UITests
            };
            _goButton.SetBinding <FirstPageViewModel>(Button.CommandProperty, vm => vm.GoButtonTapped);

            var textEntry = new StyledEntry(1)
            {
                Placeholder      = entryTextPaceHolder,
                AutomationId     = AutomationIdConstants.TextEntry,             // This provides an ID that can be referenced in UITests
                PlaceholderColor = Color.FromHex("749FA8"),
                ReturnType       = ReturnType.Go
            };

            textEntry.Completed += (sender, e) => viewModel?.GoButtonTapped?.Execute(null);
            textEntry.SetBinding <FirstPageViewModel>(Entry.TextProperty, vm => vm.EntryText);

            var textLabel = new StyledLabel
            {
                AutomationId      = AutomationIdConstants.TextLabel,            // This provides an ID that can be referenced in UITests
                HorizontalOptions = LayoutOptions.Center
            };

            textLabel.SetBinding <FirstPageViewModel>(Label.TextProperty, vm => vm.LabelText);

            _listPageButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go to List Page",
                AutomationId = AutomationIdConstants.ListViewButton                 // This provides an ID that can be referenced in UITests
            };

            var activityIndicator = new ActivityIndicator
            {
                AutomationId = AutomationIdConstants.BusyActivityIndicator,                 // This provides an ID that can be referenced in UITests
                Color        = Color.White
            };

            activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsVisibleProperty, vm => vm.IsActiityIndicatorRunning);
            activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsRunningProperty, vm => vm.IsActiityIndicatorRunning);

            var stackLayout = new StackLayout
            {
                Children =
                {
                    textEntry,
                    _goButton,
                    activityIndicator,
                    textLabel,
                },
                VerticalOptions   = LayoutOptions.StartAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            var relativeLayout = new RelativeLayout();

            relativeLayout.Children.Add(stackLayout,
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.X);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Y);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width - 20);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height / 2);
            })
                                        );

            relativeLayout.Children.Add(_listPageButton,
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.X);
            }),
                                        Constraint.Constant(250),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width - 20);
            })
                                        );

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
            Title   = "First Page";
            Content = relativeLayout;
        }
Esempio n. 16
0
        public FirstPage() : base(PageTitleConstants.FirstPage)
        {
            const string entryTextPaceHolder = "Enter text and click 'Go'";

            _goButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go",
                AutomationId = AutomationIdConstants.GoButton, // This provides an ID that can be referenced in UITests
            };
            _goButton.SetBinding(Button.CommandProperty, nameof(ViewModel.GoButtonCommand));

            var textEntry = new StyledEntry(1)
            {
                Placeholder             = entryTextPaceHolder,
                AutomationId            = AutomationIdConstants.TextEntry, // This provides an ID that can be referenced in UITests
                PlaceholderColor        = Color.FromHex("749FA8"),
                HorizontalTextAlignment = TextAlignment.Center
            };

            CustomReturnEffect.SetReturnType(textEntry, ReturnType.Go);
            textEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.GoButtonCommand));
            textEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.EntryText));

            var textLabel = new StyledLabel
            {
                AutomationId      = AutomationIdConstants.TextLabel, // This provides an ID that can be referenced in UITests
                HorizontalOptions = LayoutOptions.Center
            };

            textLabel.SetBinding(Label.TextProperty, nameof(ViewModel.LabelText));

            _listPageButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go to List Page",
                AutomationId = AutomationIdConstants.ListViewButton // This provides an ID that can be referenced in UITests
            };

            var activityIndicator = new ActivityIndicator
            {
                AutomationId = AutomationIdConstants.BusyActivityIndicator, // This provides an ID that can be referenced in UITests
                Color        = Color.White
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsActiityIndicatorRunning));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsActiityIndicatorRunning));

            Func <RelativeLayout, double> getTextEntryWidth         = (p) => textEntry.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getGoButtonWidth          = (p) => _goButton.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getActivityIndicatorWidth = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getTextLabelWidth         = (p) => textLabel.Measure(p.Width, p.Height).Request.Width;

            var relativeLayout = new RelativeLayout();

            relativeLayout.Children.Add(textEntry,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToParent((parent) => parent.Y),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));
            relativeLayout.Children.Add(_goButton,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToView(textEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));
            relativeLayout.Children.Add(activityIndicator,
                                        Constraint.RelativeToParent((parent) => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding));
            relativeLayout.Children.Add(textLabel,
                                        Constraint.RelativeToParent((parent) => parent.Width / 2 - getTextLabelWidth(parent) / 2),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding));
            relativeLayout.Children.Add(_listPageButton,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding * 15),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));

            Padding = GetPagePadding();
            Content = relativeLayout;
        }
Esempio n. 17
0
        void CreateGlobalChildren()
        {
            logo = new Image {
                HeightRequest = 30, Aspect = Aspect.AspectFit
            };
            loginLabel = new StyledLabel
            {
                CssStyle = "h1",
                Text     = "Login with your particle username",
                Opacity  = 0
            };
            loginEntry = new LoginEntry
            {
                StyleId     = "usernameEntry",
                Placeholder = "Email",
                Keyboard    = Keyboard.Email
            };
            passwordEntry = new LoginEntry
            {
                StyleId     = "passwordEntry",
                Placeholder = "Password",
                IsPassword  = true,
            };
            loginButton = new StyledButton
            {
                StyleId         = "loginButton",
                Text            = "LOGIN",
                TextColor       = Color.White,
                BackgroundColor = AppColors.Green,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                Opacity         = 0
            };
            newUserSignUpButton = new StyledButton
            {
                StyleId         = "newUserButton",
                Text            = "SIGN-UP",
                TextColor       = Color.White,
                BackgroundColor = AppColors.Purple,
                CssStyle        = "button",
                BorderRadius    = 0,
                HeightRequest   = AppSettings.ButtonHeight,
                Opacity         = 0
            };

            loginButton.Clicked += (object sender, EventArgs e) =>
            {
                if (String.IsNullOrEmpty(loginEntry.Text) || String.IsNullOrEmpty(passwordEntry.Text))
                {
                    DisplayAlert("Error", "You must enter a username and password.", "Okay");
                    return;
                }

                Login(loginEntry.Text, passwordEntry.Text);
            };
            newUserSignUpButton.Clicked += (object sender, EventArgs e) =>
            {
                NewUserSignUp();
            };
        }
Esempio n. 18
0
        public NewUserSignUpPage()
        {
            ViewModel      = new BaseViewModel();
            BindingContext = ViewModel;

            RelativeLayout    relativeLayout = new RelativeLayout();
            ActivityIndicator indicator      = new ActivityIndicator();

            var usernameEntry = new LoginEntry(1)
            {
                StyleId                 = "newUsernameEntry",
                Placeholder             = "Email",
                Keyboard                = Keyboard.Email,
                HorizontalTextAlignment = TextAlignment.Center,
            };
            var passwordEntry = new LoginEntry(1)
            {
                StyleId                 = "newPasswordEntry",
                Placeholder             = "Password",
                IsPassword              = true,
                HorizontalTextAlignment = TextAlignment.Center
            };
            var reEnterPasswordEntry = new LoginEntry(1)
            {
                StyleId                 = "reEnterPasswordEntry",
                Placeholder             = "Re-enter password",
                IsPassword              = true,
                HorizontalTextAlignment = TextAlignment.Center,
            };
            var saveUsernameButton = new StyledButton
            {
                CssStyle          = "button",
                StyleId           = "saveUsernameButton",
                Text              = "Save Username",
                TextColor         = Color.White,
                BackgroundColor   = AppColors.Green,
                BorderRadius      = 0,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };
            var usernameLabel = new StyledLabel
            {
                CssStyle          = "h2",
                Text              = "Please enter username",
                HorizontalOptions = LayoutOptions.Start
            };
            var passwordLabel = new StyledLabel
            {
                CssStyle          = "h2",
                Text              = "Please enter password",
                HorizontalOptions = LayoutOptions.Start
            };
            var reEnterPasswordLabel = new StyledLabel
            {
                CssStyle          = "h2",
                Text              = "Please re-enter password",
                HorizontalOptions = LayoutOptions.Start
            };

            relativeLayout.Children.Add(usernameLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.Constant(AppSettings.Margin),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(usernameEntry,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(usernameLabel, (p, v) => v.Y + v.Height + AppSettings.ItemPadding),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(passwordLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(usernameEntry, (p, v) => v.Y + v.Height + AppSettings.ItemPadding),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(passwordEntry,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(passwordLabel, (p, v) => v.Y + v.Height + AppSettings.ItemPadding),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(reEnterPasswordLabel,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(passwordEntry, (p, v) => v.Y + v.Height + AppSettings.ItemPadding),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(reEnterPasswordEntry,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(reEnterPasswordLabel, (p, v) => v.Y + v.Height + AppSettings.ItemPadding),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(saveUsernameButton,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin)
                                        );
            relativeLayout.Children.Add(indicator,
                                        xConstraint: Constraint.Constant(AppSettings.Margin),
                                        yConstraint: Constraint.RelativeToView(reEnterPasswordEntry, (p, v) => v.Y + v.Height),
                                        widthConstraint: Constraint.RelativeToParent(p => p.Width - 2 * AppSettings.Margin),
                                        heightConstraint: Constraint.RelativeToView(reEnterPasswordEntry, (p, v) => p.Height - v.Y - v.Height - AppSettings.Margin - AppSettings.ButtonHeight)
                                        );

            Content = relativeLayout;

            indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");

            if (Device.OS == TargetPlatform.Windows)
            {
                indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");
            }

            saveUsernameButton.Clicked += async(object sender, EventArgs e) =>
            {
                ViewModel.IsBusy = true;

                if (String.IsNullOrEmpty(usernameEntry.Text))
                {
                    DisplayAlert("Error", "Username cannot be blank", "Ok");
                    ViewModel.IsBusy = false;
                    return;
                }
                else if (!usernameEntry.Text.Contains("@"))
                {
                    DisplayAlert("Error", "Username is invalid. Please enter a valid email address.", "Ok");
                    ViewModel.IsBusy = false;
                    return;
                }
                else if (String.IsNullOrEmpty(passwordEntry.Text))
                {
                    DisplayAlert("Error", "Password cannot be blank", "Ok");
                    ViewModel.IsBusy = false;
                    return;
                }
                else if (String.IsNullOrEmpty(reEnterPasswordEntry.Text))
                {
                    DisplayAlert("Error", "Please re-enter your password", "Ok");
                    ViewModel.IsBusy = false;
                    return;
                }
                else if (passwordEntry.Text != reEnterPasswordEntry.Text)
                {
                    DisplayAlert("Error", "Passwords don't match.", "Ok");
                    ViewModel.IsBusy = false;
                    return;
                }

                var result = await ParticleCloud.SharedInstance.SignupWithUserAsync(usernameEntry.Text, passwordEntry.Text);

                ViewModel.IsBusy = false;

                if (result == "Success")
                {
                    await DisplayAlert("Success", "Your account was successfully created. Now let's login.", "Ok");

                    await Navigation.PopAsync();
                }
                else
                {
                    DisplayAlert("Error", $"{result}", "Ok");
                }
            };
        }