예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
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);
            };
        }
예제 #4
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);
			};
		}
예제 #5
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;
        }