public static void ChainEntries(params VisualElement[] entries) { if (entries.Length == 0) { return; } for (int i = 0; i < entries.Length - 1; i++) { var current = entries[i]; var next = entries[i + 1]; CustomReturnEffect.SetReturnType(current, ReturnType.Next); CustomReturnEffect.SetReturnCommand(current, new Command(x => next.Focus())); if (current is Picker picker) { picker.SelectedIndexChanged += (sender, args) => next.Focus(); } } var lastEntry = entries.Last(); CustomReturnEffect.SetReturnType(lastEntry, ReturnType.Done); }
public MainPage() { InitializeComponent(); CustomReturnEntry.ReturnCommand = ReturnCommand; CustomReturnEffect.SetReturnCommand(EffectsEntry, ReturnCommand); }
void ConfigureCustomReturnEffect() { CustomReturnEffect.SetReturnType(Player1Entry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(Player1Entry, new Command(() => Player2Entry.Focus())); CustomReturnEffect.SetReturnType(Player2Entry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(Player2Entry, new Command(() => HandleStartGameButtonClicked(StartGameButton, EventArgs.Empty))); }
void ConstructUI() { _layout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, }; _usernameEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewUserNameEntry, Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8"), }; CustomReturnEffect.SetReturnType(_usernameEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(_usernameEntry, new Command(() => _passwordEntry.Focus())); _passwordEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewPasswordEntry, Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8") }; CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(_passwordEntry, new Command(() => HandleSaveUsernameButtonClicked(_saveUsernameButton, EventArgs.Empty))); _saveUsernameButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.SaveUsernameButton, Text = "Save Username", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.Clicked += HandleSaveUsernameButtonClicked; _cancelButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.CancelButton, Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; }
public MultipleEffectsEntryPage() { InitializeComponent(); CustomReturnEffect.SetReturnCommand(DefaultReturnTypeEntry, new Command(() => NextReturnTypeEntry.Focus())); CustomReturnEffect.SetReturnCommand(NextReturnTypeEntry, new Command(() => DoneReturnTypeEntry.Focus())); CustomReturnEffect.SetReturnCommand(DoneReturnTypeEntry, new Command(() => SendReturnTypeEntry.Focus())); CustomReturnEffect.SetReturnCommand(SendReturnTypeEntry, new Command(() => SearchReturnTypeEntry.Focus())); CustomReturnEffect.SetReturnCommand(SearchReturnTypeEntry, new Command(() => GoReturnTypeEntry.Focus())); }
public EffectsPage() { var effectsEntry = new Entry { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Placeholder = EffectsPageConstants.EffectsEntryPlaceholderText, AutomationId = AutomationIdConstants.EffectsEntry }; CustomReturnEffect.SetReturnType(effectsEntry, EntryCustomReturn.Forms.Plugin.Abstractions.ReturnType.Go); CustomReturnEffect.SetReturnCommand(effectsEntry, BaseEntryReturnCommand); CustomReturnEffect.SetReturnCommandParameter(effectsEntry, EntryConstants.CommandParameterString); var canExecuteLabel = new Label { Text = "Can Execute", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; var canExecuteSwitch = new Switch { AutomationId = AutomationIdConstants.CanExecuteSwitch }; canExecuteSwitch.Toggled += (sender, e) => BaseEntryReturnCommandCanExecute = e.Value; var baseCanExecuteStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Children = { canExecuteLabel, canExecuteSwitch } }; Title = PageTitles.Effects; Content = new StackLayout { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Children = { effectsEntry, baseCanExecuteStackLayout } }; }
public EffectsPage() { var effectsEntry = new Entry { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Placeholder = "Effects Entry", }; CustomReturnEffect.SetReturnType(effectsEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(effectsEntry, new Command(async() => await Navigation.PopAsync())); Title = "Effects"; Content = effectsEntry; }
void CreateGlobalChildren() { logo = new Image(); logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.UsernameEntry, Placeholder = "Username", }; CustomReturnEffect.SetReturnType(loginEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(loginEntry, new Command(() => passwordEntry.Focus())); passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.PasswordEntry, Placeholder = "Password", IsPassword = true, }; CustomReturnEffect.SetReturnType(passwordEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(passwordEntry, new Command(() => HandleLoginButtonClicked(passwordEntry, EventArgs.Empty))); loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginButton, Text = "Login", }; newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.NewUserButton, Text = "Sign-up", }; forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.ForgotPasswordButton, Text = "Forgot Password?", }; loginButton.Clicked += HandleLoginButtonClicked; newUserSignUpButton.Clicked += (object sender, EventArgs e) => NewUserSignUp(); forgotPasswordButton.Clicked += (object sender, EventArgs e) => ForgotPassword(); }
static void ConfigureEntryReturnCommand(bool shouldUseEffects, Entry entry, Action action) { var command = new Command(action); switch (shouldUseEffects) { case true: CustomReturnEffect.SetReturnCommand(entry, command); break; case false: ((CustomReturnEntry)entry).ReturnCommand = command; break; default: throw new Exception("Invalid Type"); } }
public EffectsPage() { var effectsEntry = new Entry { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Placeholder = EffectsPageConstants.EffectsEntryPlaceholderText, AutomationId = AutomationIdConstants.EffectsEntry }; CustomReturnEffect.SetReturnType(effectsEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(effectsEntry, new Command <string>(async title => await ExecuteEntryCommand(title))); CustomReturnEffect.SetReturnCommandParameter(effectsEntry, EntryConstants.CommandParameterString); Title = PageTitles.Effects; Content = effectsEntry; }
static void ConfigureEntryReturnCommand(Entry entry, Action action) { var command = new Command(action); switch (entry) { case CustomReturnEntry customReturnEntry: customReturnEntry.ReturnCommand = command; break; case Entry baseEntry: CustomReturnEffect.SetReturnCommand(baseEntry, command); break; default: throw new NotSupportedException("Invalid Type"); } }
void CreateGlobalChildren() { _logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; _loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_UsernameEntry, Placeholder = "Username", }; CustomReturnEffect.SetReturnType(_loginEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(_loginEntry, new Command(() => _passwordEntry.Focus())); _passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_PasswordEntry, Placeholder = "Password", IsPassword = true, }; CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(_passwordEntry, new Command(() => HandleLoginButtonClicked(_passwordEntry, EventArgs.Empty))); _loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginPage_LoginButton, Text = "Login", }; _newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_NewUserSignUpButton, Text = "Sign-up", }; _forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_ForgotPasswordButton, Text = "Forgot Password?", }; }
public NewUserSignUpPage() { BackgroundColor = Color.FromHex("2980b9"); _usernameEntry = new StyledEntry(1) { Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8"), }; _usernameEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.UsernameEntryText)); CustomReturnEffect.SetReturnType(_usernameEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(_usernameEntry, new Command(() => _passwordEntry.Focus())); _passwordEntry = new StyledEntry(1) { Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8") }; _passwordEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.PasswordEntryText)); CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Done); CustomReturnEffect.SetReturnCommand(_passwordEntry, new Command(Unfocus)); _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.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" }; var isFacialRecognitionCompletedLabel = new FontAwesomeIcon { TextColor = Color.White, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(ViewModel.FontAwesomeLabelText)); switch (Device.RuntimePlatform) { case Device.iOS: isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive)); break; } 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 Exception("Device Runtime Unsupported"); } stackLayout.Children.Add(_saveUsernameButton); stackLayout.Children.Add(_cancelButton); Content = new ScrollView { Content = stackLayout }; }
public EffectsPage() { InitializeComponent(); CustomReturnEffect.SetReturnCommand(EffectsEntry, BaseEntryReturnCommand); }
public AddPersonPage() { var saveButtonToolBar = new ToolbarItem { Text = _saveButtonToolBarItemText, Priority = 0, AutomationId = AutomationIdConstants.AddPersonPage_SaveButton }; saveButtonToolBar.SetBinding(ToolbarItem.CommandProperty, nameof(ViewModel.SaveButtonCommand)); ToolbarItems.Add(saveButtonToolBar); _cancelButtonToolbarItem = new ToolbarItem { Text = _cancelButtonToolBarItemText, Priority = 1, AutomationId = AutomationIdConstants.AddPersonPage_CancelButton }; ToolbarItems.Add(_cancelButtonToolbarItem); var ageLabel = new Label { Text = "Age" }; var ageEntry = new AddPersonPageEntry { Placeholder = "Age", Keyboard = Keyboard.Numeric, AutomationId = AutomationIdConstants.AddPersonPage_AgeEntry }; ageEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.AgeEntryText)); ageEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.SaveButtonCommand)); ageEntry.SetBinding(IsEnabledProperty, new Binding(nameof(ViewModel.IsActivityIndicatorActive), BindingMode.Default, new InverseBooleanConverter(), ViewModel.IsActivityIndicatorActive)); CustomReturnEffect.SetReturnType(ageEntry, ReturnType.Go); var nameLabel = new Label { Text = "Name" }; _nameEntry = new AddPersonPageEntry { Placeholder = "Name", AutomationId = AutomationIdConstants.AddPersonPage_NameEntry }; _nameEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.NameEntryText)); _nameEntry.SetBinding(IsEnabledProperty, new Binding(nameof(ViewModel.IsActivityIndicatorActive), BindingMode.Default, new InverseBooleanConverter(), ViewModel.IsActivityIndicatorActive)); CustomReturnEffect.SetReturnCommand(_nameEntry, new Command(() => ageEntry.Focus())); CustomReturnEffect.SetReturnType(_nameEntry, ReturnType.Next); _activityIndicator = new ActivityIndicator { AutomationId = AutomationIdConstants.AddPersonPage_ActivityIndicator }; _activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsActivityIndicatorActive)); _activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsActivityIndicatorActive)); Padding = GetPageThickness(); var stackLayout = new StackLayout { Children = { nameLabel, _nameEntry, ageLabel, ageEntry, _activityIndicator } }; Title = PageTitles.AddPersonPage; Content = new ScrollView { Content = stackLayout }; }
public LoginPage() { BackgroundColor = Color.FromHex("#3498db"); Padding = GetPagePadding(); _logo = new Image { Source = "xamarin_logo" }; _logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; _usernameEntry = new StyledEntry { Placeholder = "Username" }; _usernameEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.UsernameEntryText)); CustomReturnEffect.SetReturnType(_usernameEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(_usernameEntry, new Command(() => _passwordEntry.Focus())); _passwordEntry = new StyledEntry { Placeholder = "Password", IsPassword = true, }; _passwordEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.PasswordEntryText)); _passwordEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.LoginButtonTappedCommand)); CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Done); _loginButton = new StyledButton(Borders.Thin) { Text = "Login" }; _loginButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _loginButton.SetBinding(Button.CommandProperty, nameof(ViewModel.LoginButtonTappedCommand)); _newUserSignUpButton = new StyledButton(Borders.None) { Text = "Sign-up" }; _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); var activityIndicator = new ActivityIndicator { Color = Color.White }; activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive)); Func <RelativeLayout, double> getNewUserButtonWidth = (p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getLogoSloganWidth = (p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getActivityIndicatorHeight = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Height; Func <RelativeLayout, double> getActivityIndicatorWidth = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width; _relativeLayout = new RelativeLayout(); _relativeLayout.Children.Add( _logo, xConstraint: Constraint.Constant(100), yConstraint: Constraint.Constant(250), widthConstraint: Constraint.RelativeToParent(p => p.Width - 200) ); _relativeLayout.Children.Add( _logoSlogan, xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)), yConstraint: Constraint.Constant(125) ); _relativeLayout.Children.Add( _usernameEntry, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _passwordEntry, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_usernameEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _loginButton, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _newUserSignUpButton, xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)), yConstraint: Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15) ); _relativeLayout.Children.Add(activityIndicator, xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2), yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2)); Content = new ScrollView { Content = _relativeLayout }; }
public EffectsPage() { InitializeComponent(); CustomReturnEffect.SetReturnCommand(EffectsEntry, new Command <string>(async title => await ExecuteEntryCommand(title))); }