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(); }; }
public ScanDevicePage() { NavigationPage.SetHasNavigationBar(this, false); Title = "EvolveApp"; BackgroundColor = AppColors.BackgroundColor; var viewModel = new ScanDeviceViewModel(); BindingContext = viewModel; var layout = new RelativeLayout(); var titleLabel = new StyledLabel { Text = "Particle Internet Button", CssStyle = "h1", }; var subtitleLabel = new StyledLabel { Text = "Take Control!", CssStyle = "h2" }; var descriptionLabel = new StyledLabel { Text = "Just scan the QR barcode of any device to take control.", CssStyle = "body" }; var indicator = new ActivityIndicator(); var scanBarcodeButton = new StyledButton { Text = "START SCANNING", CssStyle = "button", BackgroundColor = AppColors.Blue, BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight }; layout.Children.Add(titleLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.Constant(AppSettings.Margin * 3), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(100) ); layout.Children.Add(subtitleLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(titleLabel, (p, v) => v.Height + v.Y + AppSettings.ItemPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); layout.Children.Add(descriptionLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(subtitleLabel, (p, v) => v.Height + v.Y + AppSettings.Margin), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); layout.Children.Add(indicator, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => v.Y + v.Height), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => p.Height - v.Y - v.Height - AppSettings.Margin - AppSettings.ButtonHeight) ); layout.Children.Add(scanBarcodeButton, 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(50) ); Content = layout; #if __IOS__ scanBarcodeButton.TextColor = Color.FromHex("#ffffff"); #endif scanBarcodeButton.Clicked += async (object sender, EventArgs e) => { viewModel.SetLock(); var scanPage = new ZXingScannerPage(); scanPage.OnScanResult += (result) => { scanPage.IsScanning = false; Device.BeginInvokeOnMainThread(async () => { await Navigation.PopModalAsync(); System.Diagnostics.Debug.WriteLine($"Result: {result.Text}"); var isValidDevice = InternetButtonHelper.CheckDeviceId(result.Text); System.Diagnostics.Debug.WriteLine($"{isValidDevice}"); if (isValidDevice) { var success = await viewModel.GetDevice(result.Text); if (!success) { viewModel.ClearLock(); return; } var navPage = new NavigationPage(new DeviceLandingPage(viewModel.Device)); #if __IOS__ navPage.BarBackgroundColor = AppColors.Blue; navPage.BarTextColor = Color.White; #endif await Navigation.PushModalAsync(navPage); } else DisplayAlert("Error", "The barcode scanner had an error. Please try scanning the barcode again", "Ok"); viewModel.ClearLock(); }); }; await Navigation.PushModalAsync(scanPage); }; indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android) indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); #if __IOS__ scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock"); #endif #if __ANDROID__ scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock"); #endif }
//LoginEntry usernameEntry, passwordEntry, reEnterPasswordEntry; 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"); } }; }
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); }
public ScanDevicePage() { NavigationPage.SetHasNavigationBar(this, false); Title = "EvolveApp"; BackgroundColor = AppColors.BackgroundColor; var viewModel = new ScanDeviceViewModel(); BindingContext = viewModel; var layout = new RelativeLayout(); var titleLabel = new StyledLabel { Text = "Particle Internet Button", CssStyle = "h1", }; var subtitleLabel = new StyledLabel { Text = "Take Control!", CssStyle = "h2" }; var descriptionLabel = new StyledLabel { Text = "Just scan the QR barcode of any device to take control.", CssStyle = "body" }; var indicator = new ActivityIndicator(); var scanBarcodeButton = new StyledButton { Text = "START SCANNING", CssStyle = "button", BackgroundColor = AppColors.Blue, BorderRadius = 0, HeightRequest = AppSettings.ButtonHeight }; layout.Children.Add(titleLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.Constant(AppSettings.Margin * 3), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.Constant(100) ); layout.Children.Add(subtitleLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(titleLabel, (p, v) => v.Height + v.Y + AppSettings.ItemPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); layout.Children.Add(descriptionLabel, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(subtitleLabel, (p, v) => v.Height + v.Y + AppSettings.Margin), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2) ); layout.Children.Add(indicator, xConstraint: Constraint.Constant(AppSettings.Margin), yConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => v.Y + v.Height), widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2), heightConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => p.Height - v.Y - v.Height - AppSettings.Margin - AppSettings.ButtonHeight) ); layout.Children.Add(scanBarcodeButton, 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(50) ); Content = layout; #if __IOS__ scanBarcodeButton.TextColor = Color.FromHex("#ffffff"); #endif scanBarcodeButton.Clicked += async(object sender, EventArgs e) => { viewModel.SetLock(); var scanPage = new ZXingScannerPage(); scanPage.OnScanResult += (result) => { scanPage.IsScanning = false; Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); System.Diagnostics.Debug.WriteLine($"Result: {result.Text}"); var isValidDevice = InternetButtonHelper.CheckDeviceId(result.Text); System.Diagnostics.Debug.WriteLine($"{isValidDevice}"); if (isValidDevice) { var success = await viewModel.GetDevice(result.Text); if (!success) { viewModel.ClearLock(); return; } var navPage = new NavigationPage(new DeviceLandingPage(viewModel.Device)); #if __IOS__ navPage.BarBackgroundColor = AppColors.Blue; navPage.BarTextColor = Color.White; #endif await Navigation.PushModalAsync(navPage); } else { DisplayAlert("Error", "The barcode scanner had an error. Please try scanning the barcode again", "Ok"); } viewModel.ClearLock(); }); }; await Navigation.PushModalAsync(scanPage); }; indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android) { indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); } #if __IOS__ scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock"); #endif #if __ANDROID__ scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock"); #endif }
//LoginEntry usernameEntry, passwordEntry, reEnterPasswordEntry; 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"); } }; }
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); }