private SingleClick OnFakeGateway() => new SingleClick((o, args) => { RunOnUiThread(() => { EditText input = new EditText(this); InputFilterLengthFilter inputFilterLengthFilter = new InputFilterLengthFilter(2); input.SetFilters(new IInputFilter[] { inputFilterLengthFilter }); input.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); new AlertDialog.Builder(this) .SetMessage("Enter region code (2 chars country code)") .SetTitle("Fake Gateway") .SetView(input) .SetPositiveButton("OK", async(sender, eventArgs) => { ApiResponse response = await _viewModel.FakeGateway(input.Text); if (response != null) { UpdateText($"Pushed keys to region: {input.Text}\n" + $"isSuccessful: {response.IsSuccessfull}\n" + $"StatusCode: {response.StatusCode}\n" + $"Error Message: {response.ErrorLogMessage}\n\n"); } else { UpdateText($"Pushing of keys failed with unknown error"); } }) .SetNegativeButton("Cancel", (sender, eventArgs) => { /* ignore */ }) .Show(); }); });
public override bool OnOptionsItemSelected(IMenuItem item) { // Handle presses on the action bar items try { switch (item.ItemId) { case Resource.Id.action_settings: Intent i = new Intent(this, typeof(SettingsActivity)); StartActivityForResult(i, SETTINGS_ACTIVITY_CODE); return(true); case Resource.Id.action_goto: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Go To ... %"); EditText inputGoTo = new EditText(this); inputGoTo.InputType = InputTypes.ClassNumber; IInputFilter[] fa = new IInputFilter[1]; fa[0] = new InputFilterLengthFilter(2); inputGoTo.SetFilters(fa); inputGoTo.Text = Convert.ToString((int)(Math.Min(linesRecyclerView.progress * 100, 99))); inputGoTo.Gravity = GravityFlags.Center; inputGoTo.SetSelection(inputGoTo.Text.Length); builder.SetView(inputGoTo); builder.SetPositiveButton("Go", (sender, e) => { int newPercent = 0; try { newPercent = Math.Max(0, Math.Min(int.Parse(inputGoTo.Text.ToString()), 100)); int newPos = (int)Math.Round((double)textLen * newPercent / 100); Annotate(newPos); ((AlertDialog)sender).Dismiss(); } catch (System.FormatException) { Toast.MakeText(this, "Invalid percent number", ToastLength.Long).Show(); } }); builder.SetNegativeButton("Cancel", (sender, e) => { ((AlertDialog)sender).Cancel(); }); AlertDialog dialog = builder.Create(); dialog.Window.SetSoftInputMode(SoftInput.StateVisible); dialog.Show(); break; } } catch (Exception e) { Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show(); } return(false); }
protected override void OnAttachedToWindow() { base.OnAttachedToWindow (); if (Control != null) { Control.Background = Resources.GetDrawable(Resource.Drawable.roundedBorder); Control.SetHint (Resource.String.description); InputFilterLengthFilter filter = new InputFilterLengthFilter (255); Control.SetFilters (new IInputFilter[]{filter}); } }
protected override void OnAttachedToWindow() { base.OnAttachedToWindow(); if (Control != null) { Control.Background = Resources.GetDrawable(Resource.Drawable.EditorBorder); Control.SetHint(Resource.String.description); InputFilterLengthFilter filter = new InputFilterLengthFilter(255); Control.SetFilters(new IInputFilter[] { filter }); } }
private void SetDefaultAttributes() { SetSingleLine(true); InputType = InputTypes.ClassNumber; var filters = GetFilters(); var newFilters = new IInputFilter[filters.Length + 1]; filters.CopyTo(newFilters, 0); var lengthFilter = new InputFilterLengthFilter(MaxCharLengthWithSpaces); newFilters[newFilters.Length - 1] = lengthFilter; SetFilters(newFilters); }
private void ApplyInputFilters(int maxLength) { IInputFilter[] filterArray; if (maxLength > 0) { filterArray = new IInputFilter[1]; filterArray[0] = new InputFilterLengthFilter(maxLength); } else { filterArray = new IInputFilter[0]; } ((NativeEditText)this.NativeUIElement).SetFilters(filterArray); }
void IniEditText(EditText editText, TextView txtDescription, string descricao, int minCaract, int maxCaract) { editText.SetTextColor(ContextCompat.GetColorStateList(context, Resource.Color.black)); editText.SetHintTextColor(ContextCompat.GetColorStateList(context, Resource.Color.black)); editText.BackgroundTintList = ContextCompat.GetColorStateList(context, Resource.Color.black); editText.ImeOptions = ImeAction.Next; editText.SetTextSize(ComplexUnitType.Sp, 20); editText.SetEms(10); txtDescription.Text = descricao; if (maxCaract > 0) { IInputFilter[] filterArray = new IInputFilter[1]; filterArray[0] = new InputFilterLengthFilter(maxCaract); editText.SetFilters(filterArray); } if (minCaract > 0) { txtDescription.Text += " *"; editText.OnFocusChangeListener = new OnFocusChange(() => { if (minCaract > editText.Text.Length && editText.Text.Length > 0) { editText.SetTextColor(ContextCompat.GetColorStateList(context, Resource.Color.red)); editText.SetHintTextColor(ContextCompat.GetColorStateList(context, Resource.Color.red)); } else { editText.SetTextColor(ContextCompat.GetColorStateList(context, Resource.Color.black)); editText.SetHintTextColor(ContextCompat.GetColorStateList(context, Resource.Color.black)); } }); } }
private void ApplyInputFilters(bool isReadOnly, int maxLength) { IInputFilter[] filterArray; if (maxLength > 0) { if (isReadOnly) { filterArray = new IInputFilter[2]; filterArray[1] = this.readOnlyFilter; } else { filterArray = new IInputFilter[1]; } filterArray[0] = new InputFilterLengthFilter(maxLength); } else { if (isReadOnly) { filterArray = new IInputFilter[1]; filterArray[0] = this.readOnlyFilter; // It is unclear, what to with the background in readonly mode // Android.Graphics.Drawables.StateListDrawable draw = (Android.Graphics.Drawables.StateListDrawable)Resources.System.GetDrawable(Android.Resource.Drawable.EditBoxBackground); // draw.SetState(new int[1] { Android.Resource.Attribute.DisabledAlpha }); // Android.Graphics.Drawables.Drawable draw2 = draw.Current; // ((NativeEditText)this.NativeUIElement).SetBackgroundDrawable(draw2); } else { filterArray = new IInputFilter[0]; // It is unclear, what to with the background in readonly mode // ((NativeEditText)this.NativeUIElement).SetBackgroundResource(Android.Resource.Drawable.EditBoxBackground); } } ((NativeEditText)this.NativeUIElement).SetFilters(filterArray); }
protected override void OnElementChanged(ElementChangedEventArgs <RoundedEntry> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } var editText = new EditText(this.Context); // will remove cursor and not scrollable for tablet //editText.MovementMethod = null; editText.Ellipsize = TextUtils.TruncateAt.End; editText.SetCursorVisible(Element.ShowCursor); if (!Element.AllowCutCopyPaste) { editText.LongClickable = false; } if (Element.MaxCharacter.HasValue) { var filter = new InputFilterLengthFilter(Element.MaxCharacter.Value); editText.SetFilters(new IInputFilter[] { filter }); } SetNativeControl(editText); CreateShapeDrawable(); this.Background = new ColorDrawable(Color.Transparent.ToAndroid()); //if (Element.IsPassword) // Control.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword; if (Element.IsReadOnly) { Control.KeyListener = null; } if (Element.IsSingleLine) { editText.SetMaxLines(1); editText.SetSingleLine(true); if (Element.NextElement != null) { Control.ImeOptions = ImeAction.Next; } if (Element.NextElement == null && Element.Command != null) { Control.ImeOptions = ImeAction.Done; } if (Element.NextElement != null || (Element.NextElement == null && Element.Command != null)) { Control.SetOnEditorActionListener(this); } else { Control.ImeOptions = ImeAction.Done; } } //int selectionStart = -1; //string previousText = ""; editText.AfterTextChanged += (s, ev) => { //if (editText.Text.Length > previousText.Length) // selectionStart = editText.CursorPosition + 1; //else // selectionStart = editText.CursorPosition - 1; ////if (!editText.Text.ToString().Replace(Environment.NewLine, "").Equals(editText.Text.ToString())) ////editText.Text = editText.Text.ToString().Replace(Environment.NewLine, ""); //if (selectionStart > editText.Text.Length || selectionStart < 0) // selectionStart = editText.Text.Length; //editText.SetSelection(selectionStart); ((IElementController)Element).SetValueFromRenderer(Xamarin.Forms.Entry.TextProperty, editText.Text); //previousText = editText.Text; }; Control.SetPadding(BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Left), BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Top), BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Right), BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Bottom)); SetText(); SetTextColor(); SetTextAlignment(); SetHint(); SetTextInputTypes(); ShowKeyboard(); //CheckEnabled(); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Entry> e) { bool hasSet = false; if (e.OldElement == null && this.Element != null) { //SetNativeControl(new EditTextCustom(Context)); //SetNativeControl(new EditTextCustom()); hasSet = true; } if (inputMethodManager == null) { inputMethodManager = base.Context.GetSystemService(Context.InputMethodService) as InputMethodManager; } base.OnElementChanged(e); if (!hasSet) { return; } var entryControl = (MvvmAspire.Controls.Entry)Element; DefaultKeyListener = Control.KeyListener; entryControl.PropertyChanged += (s, ev) => { var element = (MvvmAspire.Controls.Entry)s; switch (ev.PropertyName) { case "TextPadding": case "ImageLeft": case "ImageRight": case "ImageTop": case "ImageBottom": SetImages(element); break; case "ClearFocusTrigger": HideSoftKeyBoardOnTextChanged(element); break; case "IsFocused": element.ClearFocus = !element.IsFocused; break; case "BackgroundImage": SetBackground(element); break; case "FontFamily": SetTypeface(element); break; case "FontSize": SetTextSize(element); break; case "SuppressKeyboard": SetShowSoftInputOnFocus(element); break; case "Text": if (element.ClearFocus) { HideSoftKeyBoardOnTextChanged(element); } break; case "ClearFocus": //if (!EntryControl.IsNumeric) break; if (element.ClearFocus) { //inputMethodManager.HideSoftInputFromWindow(base.Control.WindowToken, HideSoftInputFlags.None); //Control.Focusable = false; //Control.ClearFocus(); HideSoftKeyBoardOnTextChanged(element); } break; case "NextFocus": inputMethodManager.ShowSoftInput(Control, ShowFlags.Implicit); //inputMethodManager.ToggleSoftInput(ShowFlags.Forced, InputMethodManager.ShowImplicit); break; case "IsEnabled": if (base.Control == null) { return; } if (!element.IsEnabled) { base.Control.KeyListener = null; } else { base.Control.KeyListener = DefaultKeyListener; } break; case "IsReadOnly": SetIsReadOnly(element); break; //case "Padding": SetPadding(element); break; } }; //if (EntryControl.IsNumeric) // Control.Touch += Control_Touch; SetBackground(entryControl); SetImages(entryControl); SetTypeface(entryControl); SetTextSize(entryControl); SetShowSoftInputOnFocus(entryControl); SetHintColor(entryControl); SetIsReadOnly(entryControl); SetTextAlignment(); //SetPadding(entryControl); SetGravity(entryControl); if (BaseElement.NextElement != null) { Control.ImeOptions = ImeAction.Next; } if (BaseElement.NextElement == null && BaseElement.Command != null) { Control.ImeOptions = ImeAction.Done; } if (BaseElement.MaxCharacter.HasValue) { var filter = new InputFilterLengthFilter(BaseElement.MaxCharacter.Value); Control.SetFilters(new IInputFilter[] { filter }); } Control.ViewAttachedToWindow += Control_ViewAttachedToWindow; Control.SetPadding(BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Left), BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Top), BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Right), BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Bottom)); if (BaseElement.NextElement != null || BaseElement.Command != null) { Control.SetOnEditorActionListener(this); } SetTextInputTypes(entryControl); if (!entryControl.IsEnabled) { base.Control.KeyListener = null; } base.Control.Focusable = !BaseElement.IsReadOnly; //Control.Touch += Control_Touch; //Control.FocusChange += Control_FocusChange; if (BaseElement.IsSingleLine) { Control.SetMaxLines(1); Control.SetSingleLine(true); Control.Ellipsize = TextUtils.TruncateAt.End; } //Control.Gravity = GravityFlags.CenterVertical; Control.Background.SetColorFilter(Android.Graphics.Color.Transparent, PorterDuff.Mode.SrcIn); }