/// <summary> /// Gets the image. /// </summary> /// <param name="enhancedEntry">The enhanced entry.</param> /// <param name="color">The color.</param> /// <returns></returns> private UIImageView getImage(EnhancedEntry enhancedEntry, Color color) { return(new UIImageView(new UIImage(enhancedEntry.LeftIcon)) { BackgroundColor = color.ToUIColor(), ContentMode = UIViewContentMode.Center, }); }
protected override VisualElement Create(XNode node) { var enhancedActivityIndicatorLabel = new Label { Text = "This is a Geocortex Mobile enhanced activity indicator.", Margin = new Thickness(10, 0) }; var enhancedActivityIndicator = new EnhancedActivityIndicator() { IsRunning = true, HeightRequest = 75, WidthRequest = 75, Margin = new Thickness(10, 0, 10, 10) }; var enhancedButton = new EnhancedButton() { Text = "Geocortex Mobile button", Margin = 10 }; var enhancedEntry = new EnhancedEntry() { Placeholder = "This is a Geocortex Mobile enhanced entry.", Margin = 10 }; var enhancedSwitchLabel = new Label { Text = "This is a Geocortex Mobile enhanced switch.", Margin = new Thickness(10, 0) }; var enhancedSwitch = new EnhancedSwitch() { Margin = new Thickness(10, 0, 10, 10) }; var view = new StackLayout { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Children = { enhancedActivityIndicatorLabel, enhancedActivityIndicator, enhancedButton, enhancedEntry, enhancedSwitchLabel, enhancedSwitch, } }; return(view); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { EnhancedEntry baseEntry = (EnhancedEntry)this.Element; base.OnElementChanged(e); if (!((this.Control != null) & (e.NewElement != null))) { return; } this.Control.LeftView = new UIView(new CGRect(0, 0, baseEntry.LeftPadding, this.Control.Frame.Height + baseEntry.TopBottomPadding)); this.Control.RightView = new UIView(new CGRect(0, 0, baseEntry.RightPadding, this.Control.Frame.Height + baseEntry.TopBottomPadding)); this.Control.LeftViewMode = UITextFieldViewMode.Always; this.Control.RightViewMode = UITextFieldViewMode.Always; this.Element.HeightRequest = 30; if (e.NewElement is EnhancedEntry customEntry) { switch (customEntry.UITextBorderStyle) { case TextBorderStyle.None: this.Control.BorderStyle = UITextBorderStyle.None; break; case TextBorderStyle.Line: this.Control.BorderStyle = UITextBorderStyle.Line; break; case TextBorderStyle.Bezel: this.Control.BorderStyle = UITextBorderStyle.Bezel; break; case TextBorderStyle.RoundedRect: this.Control.BorderStyle = UITextBorderStyle.RoundedRect; break; } e.NewElement.Focused += (sender, evt) => { this.Control.Layer.BorderColor = baseEntry.FocusBorderColor.ToCGColor(); }; e.NewElement.Unfocused += (sender, evt) => { this.Control.Layer.BorderColor = baseEntry.BorderColor.ToCGColor(); }; this.Control.Layer.CornerRadius = new nfloat(customEntry.CornerRadius); this.Control.Layer.BorderWidth = new nfloat(customEntry.BorderWidth); this.Control.Layer.BackgroundColor = baseEntry.BackgroundColor.ToCGColor(); this.Control.Layer.BorderColor = baseEntry.BorderColor.ToCGColor(); this.Control.ReturnKeyType = GetValueFromDescription <UIReturnKeyType>(customEntry.ReturnKeyType.ToString()); if (!string.IsNullOrEmpty(customEntry.LeftIcon)) { UIImage leftImage = new UIImage(customEntry.LeftIcon); { UIImageView viewImage = new UIImageView(leftImage); viewImage.Frame = new CGRect( 0.0, 0.0, viewImage.Image.Size.Width + customEntry.PaddingLeftIcon, viewImage.Image.Size.Height + customEntry.PaddingLeftIcon); viewImage.ContentMode = UIViewContentMode.Center; this.Control.LeftView = viewImage; } } this.Control.ShouldReturn += field => { if (baseEntry.NextEntry == null) { UIApplication.SharedApplication.KeyWindow.EndEditing(true); } baseEntry.EntryActionFired(); return(true); }; } }
public Page1() { InitializeComponent(); EnhancedEntry entry3 = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, FontSize = 11, ReturnKeyType = ReturnKeyTypes.Done, Placeholder = "Show dialog on tap", KeyBoardAction = new Command(() => DisplayAlert("Passwords match!", "Both passwords match", "OK")) }; EnhancedEntry entryPasswordConfirm = new EnhancedEntry { BorderColor = Color.Red, LeftIcon = "password", Effects = { new ShowHiddenEntryEffect() }, BorderWidth = 1, CornerRadius = 2, Placeholder = "Password confirm", IsPassword = true, NextEntry = entry3, ReturnKeyType = ReturnKeyTypes.Next }; EnhancedEntry passwordEntry = new EnhancedEntry { BorderColor = Color.Red, LeftIcon = "password", BorderWidth = 1, CornerRadius = 2, Placeholder = "Password", Effects = { new ShowHiddenEntryEffect() }, IsPassword = true, Behaviors = { new PasswordCompareValidationBehavior(new List <Entry> { entryPasswordConfirm }) { ValidColor = Color.Green, InValidColor = Color.Red } }, NextEntry = entryPasswordConfirm, ReturnKeyType = ReturnKeyTypes.Done }; EnhancedEntry advancedEntry = new EnhancedEntry { BorderColor = Color.Red, LeftIcon = "account", Placeholder = "Type email", FocusBorderColor = Color.Green, BackgroundColor = Color.Yellow, BorderWidth = 3, CornerRadius = 10, Behaviors = { new EmailValidatorBehavior { InValidColor = Color.Red, ValidColor = Color.Green } }, NextEntry = passwordEntry, Keyboard = Keyboard.Email, ReturnKeyType = ReturnKeyTypes.Next }; entryPasswordConfirm.Behaviors.Add(new PasswordCompareValidationBehavior(new List <Entry> { passwordEntry }) { ValidColor = Color.Green, InValidColor = Color.Red }); EnhancedEntry jumpToEntry3 = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, ReturnKeyType = ReturnKeyTypes.Done, Keyboard = Keyboard.Numeric, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center }; EnhancedEntry jumpToEntry2 = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, NextEntry = entry3, ReturnKeyType = ReturnKeyTypes.Next, Keyboard = Keyboard.Numeric, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center, Behaviors = { new MaxLengthValidator { MaxLength = 2 }, new GoToNextEntryOnLengthBehaviour(jumpToEntry3) { CharacterLength = 2 } } }; EnhancedEntry jumpToEntry1 = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, NextEntry = entry3, ReturnKeyType = ReturnKeyTypes.Next, Keyboard = Keyboard.Numeric, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center, Behaviors = { new MaxLengthValidator { MaxLength = 2 }, new GoToNextEntryOnLengthBehaviour(jumpToEntry2) { CharacterLength = 2 } } }; StackLayout stackNextEntries = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(20, 0), Children = { jumpToEntry1, jumpToEntry2, jumpToEntry3 } }; if (((PasswordCompareValidationBehavior)passwordEntry.Behaviors .FirstOrDefault(behavior => behavior.GetType() == typeof(PasswordCompareValidationBehavior))).IsValid && ((PasswordCompareValidationBehavior)entryPasswordConfirm.Behaviors .FirstOrDefault(behavior => behavior.GetType() == typeof(PasswordCompareValidationBehavior))).IsValid) { this.DisplayAlert("Passwords match!", "Both passwords match", "OK"); } StackLayout stack = new StackLayout { VerticalOptions = LayoutOptions.Center, Spacing = 10, Margin = 20, Children = { new ContentView { VerticalOptions = LayoutOptions.Fill, Content = advancedEntry }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = passwordEntry }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entryPasswordConfirm }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entry3 }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = stackNextEntries } } }; CV.Content = stack; }
/// <summary> /// Raises the <see cref="E:ElementChanged" /> event. /// </summary> /// <param name="e">The <see cref="ElementChangedEventArgs{Entry}"/> instance containing the event data.</param> protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { EnhancedEntry baseEntry = (EnhancedEntry)Element; base.OnElementChanged(e); if (!((Control != null) & (e.NewElement != null))) { return; } Control.LeftView = new UIView(new CGRect(0, 0, baseEntry.LeftPadding, Control.Frame.Height + baseEntry.TopBottomPadding)); Control.RightView = new UIView(new CGRect(0, 0, baseEntry.RightPadding, Control.Frame.Height + baseEntry.TopBottomPadding)); Control.LeftViewMode = UITextFieldViewMode.Always; Control.RightViewMode = UITextFieldViewMode.Always; if (baseEntry.EntryHeight != -1) { Element.HeightRequest = baseEntry.EntryHeight; } if (e.NewElement is EnhancedEntry enhancedEntry) { switch (enhancedEntry.UITextBorderStyle) { case TextBorderStyle.None: Control.BorderStyle = UITextBorderStyle.None; break; case TextBorderStyle.Line: Control.BorderStyle = UITextBorderStyle.Line; break; case TextBorderStyle.Bezel: Control.BorderStyle = UITextBorderStyle.Bezel; break; case TextBorderStyle.RoundedRect: Control.BorderStyle = UITextBorderStyle.RoundedRect; break; } e.NewElement.Focused += (sender, evt) => Control.Layer.BorderColor = baseEntry.FocusBorderColor.ToCGColor(); e.NewElement.Unfocused += (sender, evt) => Control.Layer.BorderColor = baseEntry.BorderColor.ToCGColor(); Control.Layer.CornerRadius = new nfloat(enhancedEntry.CornerRadius); Control.Layer.BorderWidth = new nfloat(enhancedEntry.BorderWidth); Control.Layer.BackgroundColor = baseEntry.BackgroundColor.ToCGColor(); Control.Layer.BorderColor = baseEntry.BorderColor.ToCGColor(); Control.ReturnKeyType = getValueFromDescription <UIReturnKeyType>(enhancedEntry.ReturnKeyType.ToString()); if (!string.IsNullOrEmpty(enhancedEntry.LeftIcon)) { Control.LeftView = getImage(enhancedEntry, Color.Transparent); enhancedEntry.IconDrawableColorChanged += (sender, args) => { Control.LeftView = getImage(enhancedEntry, args.Color); }; } Control.ShouldReturn += _ => { if (baseEntry.NextEntry == null) { UIApplication.SharedApplication.KeyWindow.EndEditing(true); } baseEntry.EntryActionFired(); return(true); }; } }
public Page1() { EnhancedEntry advancedEntry = new EnhancedEntry { BorderColor = Color.Red, Placeholder = "Type an email in me...", FocusBorderColor = Color.Green, BackgroundColor = Color.Yellow, BorderWidth = 1, CornerRadius = 10, EmailValidatorBehavior = new EmailValidatorBehavior(), Keyboard = Keyboard.Email, ReturnKeyType = ReturnKeyTypes.Done }; EnhancedEntry entryPasswordConfirm = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, Placeholder = "Password confirm" }; EnhancedEntry passwordEntry = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, Placeholder = "Password", PasswordCompareValidation = new PasswordCompareValidationBehavior(new List <Entry>() { entryPasswordConfirm }) { ValidColor = Color.Orange, InValidColor = Color.Red }, }; entryPasswordConfirm.PasswordCompareValidation = new PasswordCompareValidationBehavior(new List <Entry>() { passwordEntry }) { ValidColor = Color.Orange, InValidColor = Color.Red }; EnhancedEntry entry3 = new EnhancedEntry { BorderColor = Color.Red, BorderWidth = 1, CornerRadius = 2, Placeholder = "Tap done in keyboard to execute some code in keyboardaction...", KeyBoardAction = new Command( () => { DisplayAlert("Tapped", "Action executed", "OK"); }), }; EnhancedEntry entry1 = new EnhancedEntry { BorderColor = Color.Red, Placeholder = "Jump to next entry on Next", BorderWidth = 1, CornerRadius = 2, NextEntry = entry3, ReturnKeyType = ReturnKeyTypes.Next }; EnhancedEntry entry4 = new EnhancedEntry { BorderColor = Color.Red, Placeholder = "Focus next entry when text length is 2", BorderWidth = 1, CornerRadius = 2, NextEntry = entry3, ReturnKeyType = ReturnKeyTypes.Done, GoToNextEntryOnLengthBehaviour = new GoToNextEntryOnLengthBehaviour(advancedEntry) { CharacterLength = 2 }, }; if (entryPasswordConfirm.PasswordCompareValidation.IsValid && entryPasswordConfirm.PasswordCompareValidation.IsValid) { this.DisplayAlert("Passwords match!", "Both passwords match", "OK"); } StackLayout stack = new StackLayout { VerticalOptions = LayoutOptions.Center, Spacing = 10, Margin = 20, Children = { new ContentView { VerticalOptions = LayoutOptions.Fill, Content = advancedEntry }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = passwordEntry }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entryPasswordConfirm }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entry1 }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entry4 }, new ContentView { VerticalOptions = LayoutOptions.Fill, Content = entry3 } } }; Content = stack; InitializeComponent(); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); // EnhancedEntry baseEntry = (EnhancedEntry)this.Element; if (!((this.Control != null) & (e.NewElement != null))) { return; } EnhancedEntry entryExt = e.NewElement as EnhancedEntry; if (entryExt == null) { return; } // LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] // { // this.gradietDrawable // }); // GradientDrawable strokeDrawable = (GradientDrawable)layerDrawable.findDrawableByLayerId(R.id.item_bottom_stroke); // strokeDrawable.setColor(strokeColor[0]); // GradientDrawable backgroundColor = (GradientDrawable)layerDrawable.findDrawableByLayerId(R.id.item_navbar_background); // backgroundColor.setColors(bgColor); if (entryExt != null) { this.Control.ImeOptions = GetValueFromDescription(entryExt.ReturnKeyType); this.Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), this.Control.ImeOptions); this.gradietDrawable = new GradientDrawable(); this.gradietDrawable.SetShape(ShapeType.Rectangle); this.gradietDrawable.SetColor(entryExt.BackgroundColor.ToAndroid()); this.gradietDrawable.SetCornerRadius(entryExt.CornerRadius); this.gradietDrawable.SetStroke((int)entryExt.BorderWidth, entryExt.BorderColor.ToAndroid()); Rect padding = new Rect { Left = entryExt.LeftPadding, Right = entryExt.RightPadding, Top = entryExt.TopBottomPadding / 2, Bottom = entryExt.TopBottomPadding / 2 }; this.gradietDrawable.GetPadding(padding); e.NewElement.Focused += (sender, evt) => { this.gradietDrawable.SetStroke( (int)entryExt.BorderWidth, entryExt.FocusBorderColor.ToAndroid()); }; e.NewElement.Unfocused += (sender, evt) => { this.gradietDrawable.SetStroke((int)entryExt.BorderWidth, entryExt.BorderColor.ToAndroid()); }; this.Control.SetBackground(this.gradietDrawable); if (this.Control != null && !string.IsNullOrEmpty(PackageName)) { if (!string.IsNullOrEmpty(entryExt.LeftIcon)) { int identifier = this.Context.Resources.GetIdentifier( entryExt.LeftIcon, "drawable", PackageName); if (identifier != 0) { Drawable drawable = this.Context.Resources.GetDrawable(identifier); if (drawable != null) { this.Control.SetCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); this.Control.CompoundDrawablePadding = entryExt.PaddingLeftIcon; } } } } this.Control.EditorAction += (sender, args) => { if (entryExt.NextEntry == null) { if (this.context.GetSystemService(Context.InputMethodService) is InputMethodManager inputMethodManager && this.context is Activity) { Activity activity = (Activity)this.context; IBinder token = activity.CurrentFocus?.WindowToken; inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None); activity.Window.DecorView.ClearFocus(); } } entryExt.EntryActionFired(); }; } // gradietDrawable.SetColorFilter(Color.Black, PorterDuff.Mode.SrcIn); }