/// <summary> /// Returns HTML for an <input> HTML element. /// </summary> /// <param name="inputType">The type of input to produce</param> /// <param name="fieldConfiguration">The field configuration to use for attributes and format string</param> /// <returns>The HTML of the input element</returns> protected IHtmlContent GetInputHtml(TextInputType inputType, IReadonlyFieldConfiguration fieldConfiguration) { if (inputType == TextInputType.Password) { return(FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, fieldConfiguration.HtmlAttributes)); } var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes); if (!attrs.Attributes.ContainsKey("type")) { attrs = attrs.Attr(type => inputType.ToString().ToLower()); } IHtmlContent htmlContent; if (!string.IsNullOrEmpty(fieldConfiguration.FormatString)) { htmlContent = FieldGenerator.HtmlHelper.TextBoxFor( FieldGenerator.FieldProperty, fieldConfiguration.FormatString, attrs.ToDictionary() ); } else { htmlContent = FieldGenerator.HtmlHelper.TextBoxFor( FieldGenerator.FieldProperty, attrs.ToDictionary() ); } return(htmlContent); }
public EditableText(TextEditingController controller, FocusNode focusNode, TextStyle style, Color cursorColor, bool obscureText = false, bool autocorrect = false, TextAlign textAlign = TextAlign.left, TextDirection?textDirection = null, float?textScaleFactor = null, int?maxLines = 1, bool autofocus = false, Color selectionColor = null, TextSelectionControls selectionControls = null, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, SelectionChangedCallback onSelectionChanged = null, List <TextInputFormatter> inputFormatters = null, bool rendererIgnoresPointer = false, EdgeInsets scrollPadding = null, bool unityTouchKeyboard = false, Key key = null) : base(key) { D.assert(controller != null); D.assert(focusNode != null); D.assert(style != null); D.assert(cursorColor != null); D.assert(maxLines == null || maxLines > 0); this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.controller = controller; this.focusNode = focusNode; this.obscureText = obscureText; this.autocorrect = autocorrect; this.style = style; this.textAlign = textAlign; this.textDirection = textDirection; this.textScaleFactor = textScaleFactor; this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.cursorColor = cursorColor; this.maxLines = maxLines; this.autofocus = autofocus; this.selectionColor = selectionColor; this.onChanged = onChanged; this.onSubmitted = onSubmitted; this.onSelectionChanged = onSelectionChanged; this.onEditingComplete = onEditingComplete; this.rendererIgnoresPointer = rendererIgnoresPointer; this.selectionControls = selectionControls; this.unityTouchKeyboard = unityTouchKeyboard; if (maxLines == 1) { this.inputFormatters = new List <TextInputFormatter>(); this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter); if (inputFormatters != null) { this.inputFormatters.AddRange(inputFormatters); } } else { this.inputFormatters = inputFormatters; } }
public InputField( Key key = null, TextEditingController controller = null, FocusNode focusNode = null, bool obscureText = false, bool autocorrect = true, bool enabled = true, TextStyle style = null, TextAlign textAlign = TextAlign.left, int maxLines = 1, bool autofocus = false, string hintText = null, TextStyle hintStyle = null, string labelText = null, TextStyle labelStyle = null, Color cursorColor = null, float cursorWidth = 2, Radius cursorRadius = null, TextInputAction textInputAction = TextInputAction.none, TextInputType keyboardType = null, float height = 44.0f, InputFieldClearButtonMode clearButtonMode = InputFieldClearButtonMode.never, bool enableInteractiveSelection = true, Color selectionColor = null, ValueChanged <string> onChanged = null, ValueChanged <string> onSubmitted = null, EdgeInsets scrollPadding = null ) : base(key) { this.controller = controller; this.textAlign = textAlign; this.focusNode = focusNode; this.obscureText = obscureText; this.autocorrect = autocorrect; this.enabled = enabled; this.style = style; this.textAlign = textAlign; this.maxLines = maxLines; this.autofocus = autofocus; this.hintText = hintText; this.hintStyle = hintStyle; this.labelText = labelText; this.labelStyle = labelStyle; this.height = height; this.clearButtonMode = clearButtonMode; this.enableInteractiveSelection = enableInteractiveSelection; this.selectionColor = selectionColor ?? new Color(0x667FAACF); this.cursorColor = cursorColor; this.cursorWidth = cursorWidth; this.cursorRadius = cursorRadius ?? Radius.circular(1.0f); this.textInputAction = textInputAction; this.keyboardType = keyboardType; this.onChanged = onChanged; this.onSubmitted = onSubmitted; this.scrollPadding = scrollPadding; }
public SearchDelegate( string searchFieldLabel = null, TextInputType keyboardType = null, TextInputAction textInputAction = TextInputAction.search ) { this.searchFieldLabel = searchFieldLabel; this.keyboardType = keyboardType; this.textInputAction = textInputAction; }
/// <summary> /// Utwórz nowe pole edytowalne. /// </summary> /// <param name="texture">kolor tła pola</param> /// <param name="font">czcionka tekstu</param> /// <param name="showCursor"><value>true</value> oznacza pokazywanie kursowa, <value>false</value> brak</param> /// <param name="textColor">kolor czcionki</param> /// <param name="textInputType">rodzaj pola <value>Hasło</value> oznacza zamianę wpisywanych znaków na symbole "*"</param> /// <param name="buttonColor">kolor tła przycisku</param> /// <param name="maxCharacters">maksymalna ilość znaków</param> public TextInput(Texture2D texture, SpriteFont font, bool showCursor, Color textColor, TextInputType textInputType, Color buttonColor, int maxCharacters = Int32.MaxValue) { _maxCharacters = maxCharacters; TextInputType = textInputType; _font = font; _texture = texture; TextValue = String.Empty; ShowCursor = showCursor; _textColor = textColor; _button = new Button(BState.Up, texture, buttonColor, new Vector2(0, 0), new Vector2(1, 1), 0.0f, 2.0f, Color.Black); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiEditBoxBase)); Hint = DefinitionResolver.GetSharedString(Controller, Binding, file["Hint"]) ?? new SharedString(); _maxLength = DefinitionResolver.Get(Controller, Binding, file["MaxLength"], int.MaxValue); _inputType = DefinitionResolver.Get(Controller, Binding, file["InputType"], TextInputType.NormalText); _lostFocusCancels = DefinitionResolver.Get(Controller, Binding, file["CancelOnLostFocus"], false); _focusedShared = DefinitionResolver.GetShared(Controller, Binding, file["IsFocused"], false); _focusedShared.Value = false; string filter = DefinitionResolver.GetString(Controller, Binding, file["Filter"]); if (!filter.IsNullOrEmpty()) { _filter = new List <char>(filter.ToCharArray()); } _focusedShared.ValueChanged += (bool focused) => { if (focused) { CurrentlyFocused = this; } else if (CurrentlyFocused == this) { CurrentlyFocused = null; } }; if (_inputType == TextInputType.Password) { _password = new SharedString(); } RegisterDelegate("TextApply", file["TextApply"]); RegisterDelegate("TextChanged", file["TextChanged"]); RegisterDelegate("TextCancel", file["TextCancel"]); RegisterDelegate("LostFocus", file["LostFocus"]); RegisterDelegate("Return", file["Return"]); return(true); }
/// <summary> /// Inflates the views in the layout. /// </summary> /// <param name="context">the current context for the view.</param> private void Init(Context context, IAttributeSet attrs) { LayoutInflater inflater = context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater; inflater.Inflate(Resource.Layout.MyEditTextView, this); #region Finding Views TitleTextView = FindViewById <TextView>(Resource.Id.myedittext_tv_title); ErrorTextView = FindViewById <TextView>(Resource.Id.myedittext_tv_error); InputEditText = FindViewById <EditText>(Resource.Id.myedittext_et_input); #endregion // Default values Error = ""; InputType = TextInputType.Text; if (attrs != null) { TypedArray typedArray = Context.ObtainStyledAttributes(attrs, Resource.Styleable.MyEditText); if (typedArray.HasValue(Resource.Styleable.MyEditText_title)) { Title = typedArray.GetString(Resource.Styleable.MyEditText_title); } if (typedArray.HasValue(Resource.Styleable.MyEditText_input)) { Input = typedArray.GetString(Resource.Styleable.MyEditText_input); } if (typedArray.HasValue(Resource.Styleable.MyEditText_inputHint)) { InputHint = typedArray.GetString(Resource.Styleable.MyEditText_inputHint); } if (typedArray.HasValue(Resource.Styleable.MyEditText_error)) { Error = typedArray.GetString(Resource.Styleable.MyEditText_error); } if (typedArray.HasValue(Resource.Styleable.MyEditText_inputType)) { InputType = (TextInputType)typedArray.GetInt(Resource.Styleable.MyEditText_inputType, (int)TextInputType.Text); } typedArray.Recycle(); } }
UIKeyboardType TypeFromContext(TextInputType context) { switch (context & TextInputType.TypeFilter) { case TextInputType.Email: return(UIKeyboardType.EmailAddress); case TextInputType.Digits: return(UIKeyboardType.NumberPad); case TextInputType.Numeric: return(UIKeyboardType.NumbersAndPunctuation); } return(UIKeyboardType.Default); }
protected Nancy.ViewEngines.Razor.IHtmlString GetInputHtml(TextInputType inputType) { ///TODO: GB fix this so it renders the password with the correct attributes: if (inputType == TextInputType.Password) { return(new NonEncodedHtmlString(string.Format(@"<input type=""password"" id="""" name="""" class="""" />"))); } //return FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, FieldConfiguration.HtmlAttributes); var attrs = new HtmlAttributes(FieldConfiguration.HtmlAttributes); attrs.Attr(type => inputType.ToString().ToLower()); return(!string.IsNullOrEmpty(FieldConfiguration.FormatString) ? FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, FieldConfiguration.FormatString, attrs.ToDictionary()) : FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, attrs.ToDictionary())); }
UITextAutocapitalizationType AutoCapitalizationFromContext(TextInputType context) { switch (context & TextInputType.TypeFilter) { case TextInputType.FirstLetterUppercase: return(UITextAutocapitalizationType.Words); case TextInputType.Uppercase: return(UITextAutocapitalizationType.AllCharacters); case TextInputType.MultilineText: return(UITextAutocapitalizationType.Sentences); } return(UITextAutocapitalizationType.None); }
InputTypes TypeFromContext(TextInputType context) { InputTypes value = Android.Text.InputTypes.TextFlagNoSuggestions | Android.Text.InputTypes.ClassText; switch (context & TextInputType.TypeFilter) { case TextInputType.Email: value = InputTypes.TextVariationEmailAddress | Android.Text.InputTypes.ClassText; break; case TextInputType.FirstLetterUppercase: value = InputTypes.TextFlagCapWords | Android.Text.InputTypes.ClassText; break; case TextInputType.Digits: value = InputTypes.ClassNumber | InputTypes.NumberFlagSigned; break; case TextInputType.Numeric: value = InputTypes.NumberFlagDecimal | InputTypes.ClassNumber; break; case TextInputType.NormalText: value = InputTypes.TextVariationNormal | Android.Text.InputTypes.ClassText; break; case TextInputType.Uppercase: value = InputTypes.TextFlagCapCharacters | InputTypes.ClassText; break; case TextInputType.PasswordClass: value = InputTypes.TextVariationPassword | Android.Text.InputTypes.ClassText; break; case TextInputType.MultilineText: value = InputTypes.TextFlagMultiLine | Android.Text.InputTypes.TextFlagImeMultiLine; break; } if (context.HasFlag(TextInputType.NoSuggestions)) { value |= InputTypes.TextFlagNoSuggestions | InputTypes.TextVariationVisiblePassword; } return(value); }
InputScopeName NameFromContext(TextInputType context) { switch (context & TextInputType.TypeFilter) { case TextInputType.FirstLetterUppercase: return(_inputScopeName); case TextInputType.Numeric: return(_inputScopeNumber); case TextInputType.Uppercase: return(_inputScopeUpper); case TextInputType.Email: return(_inputScopeEmail); case TextInputType.Digits: return(_inputScopeDigits); } return(_inputScopeText); }
public TextFormField( Key key = null, TextEditingController controller = null, string initialValue = null, FocusNode focusNode = null, InputDecoration decoration = null, TextInputType keyboardType = null, TextCapitalization textCapitalization = TextCapitalization.none, TextInputAction?textInputAction = null, TextStyle style = null, TextDirection?textDirection = null, TextAlign textAlign = TextAlign.left, bool autofocus = false, bool obscureText = false, bool autocorrect = true, bool autovalidate = false, bool maxLengthEnforced = true, int maxLines = 1, int?maxLength = null, VoidCallback onEditingComplete = null, ValueChanged <string> onFieldSubmitted = null, FormFieldSetter <string> onSaved = null, FormFieldValidator <string> validator = null, List <TextInputFormatter> inputFormatters = null, bool enabled = true, float cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, bool enableInteractiveSelection = true, InputCounterWidgetBuilder buildCounter = null ) : base( key: key, initialValue: controller != null ? controller.text : (initialValue ?? ""), onSaved: onSaved, validator: validator, autovalidate: autovalidate, enabled: enabled, builder: (FormFieldState <string> field) => { _TextFormFieldState state = (_TextFormFieldState)field; InputDecoration effectiveDecoration = (decoration ?? new InputDecoration()) .applyDefaults(Theme.of(field.context).inputDecorationTheme); return(new TextField( controller: state._effectiveController, focusNode: focusNode, decoration: effectiveDecoration.copyWith(errorText: field.errorText), keyboardType: keyboardType, textInputAction: textInputAction, style: style, textAlign: textAlign, textDirection: textDirection ?? TextDirection.ltr, textCapitalization: textCapitalization, autofocus: autofocus, obscureText: obscureText, autocorrect: autocorrect, maxLengthEnforced: maxLengthEnforced, maxLines: maxLines, maxLength: maxLength, onChanged: field.didChange, onEditingComplete: onEditingComplete, onSubmitted: onFieldSubmitted, inputFormatters: inputFormatters, enabled: enabled, cursorWidth: cursorWidth, cursorRadius: cursorRadius, cursorColor: cursorColor, scrollPadding: scrollPadding ?? EdgeInsets.all(20.0f), keyboardAppearance: keyboardAppearance, enableInteractiveSelection: enableInteractiveSelection, buildCounter: buildCounter )); } ) { D.assert(initialValue == null || controller == null); D.assert(maxLines > 0); D.assert(maxLength == null || maxLength > 0); this.controller = controller; }
public TextField(Key key = null, TextEditingController controller = null, FocusNode focusNode = null, InputDecoration decoration = null, bool noDecoration = false, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null, StrutStyle strutStyle = null, TextAlign textAlign = TextAlign.left, TextDirection textDirection = TextDirection.ltr, bool autofocus = false, bool obscureText = false, bool autocorrect = false, int?maxLines = 1, int?minLines = null, bool expands = false, int?maxLength = null, bool maxLengthEnforced = true, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, List <TextInputFormatter> inputFormatters = null, bool?enabled = null, float?cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool?enableInteractiveSelection = null, GestureTapCallback onTap = null, InputCounterWidgetBuilder buildCounter = null, ScrollPhysics scrollPhysics = null ) : base(key: key) { D.assert(maxLines == null || maxLines > 0); D.assert(minLines == null || minLines > 0); D.assert((maxLines == null) || (minLines == null) || (maxLines >= minLines), () => "minLines can't be greater than maxLines"); D.assert(!expands || (maxLines == null && minLines == null), () => "minLines and maxLines must be null when expands is true."); D.assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0); this.controller = controller; this.focusNode = focusNode; this.decoration = noDecoration ? null : (decoration ?? new InputDecoration()); this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.style = style; this.strutStyle = strutStyle; this.textAlign = textAlign; this.textDirection = textDirection; this.autofocus = autofocus; this.obscureText = obscureText; this.autocorrect = autocorrect; this.maxLines = maxLines; this.minLines = minLines; this.expands = expands; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.onChanged = onChanged; this.onEditingComplete = onEditingComplete; this.onSubmitted = onSubmitted; this.inputFormatters = inputFormatters; this.enabled = enabled; this.cursorWidth = cursorWidth; this.cursorColor = cursorColor; this.cursorRadius = cursorRadius; this.onSubmitted = onSubmitted; this.keyboardAppearance = keyboardAppearance; this.enableInteractiveSelection = enableInteractiveSelection; this.onTap = onTap; this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.dragStartBehavior = dragStartBehavior; this.buildCounter = buildCounter; this.scrollPhysics = scrollPhysics; }
public TextInput(string label, string value, bool isRequired, TextInputType type) : this(label, value, isRequired) { Type = type; }
public TextField(Key key = null, TextEditingController controller = null, FocusNode focusNode = null, InputDecoration decoration = null, bool noDecoration = false, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null, StrutStyle strutStyle = null, TextAlign textAlign = TextAlign.left, TextAlignVertical textAlignVertical = null, TextDirection textDirection = TextDirection.ltr, bool readOnly = false, ToolbarOptions toolbarOptions = null, bool?showCursor = null, bool autofocus = false, bool obscureText = false, bool autocorrect = false, SmartDashesType?smartDashesType = null, SmartQuotesType?smartQuotesType = null, bool enableSuggestions = true, int?maxLines = 1, int?minLines = null, bool expands = false, int?maxLength = null, bool maxLengthEnforced = true, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, List <TextInputFormatter> inputFormatters = null, bool?enabled = null, float?cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight, BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool enableInteractiveSelection = true, GestureTapCallback onTap = null, InputCounterWidgetBuilder buildCounter = null, ScrollController scrollController = null, ScrollPhysics scrollPhysics = null ) : base(key: key) { D.assert(maxLines == null || maxLines > 0); D.assert(minLines == null || minLines > 0); D.assert((maxLines == null) || (minLines == null) || (maxLines >= minLines), () => "minLines can't be greater than maxLines"); D.assert(!expands || (maxLines == null && minLines == null), () => "minLines and maxLines must be null when expands is true."); D.assert(maxLength == null || maxLength == noMaxLength || maxLength > 0); D.assert(!obscureText || maxLines == 1, () => "Obscured fields cannot be multiline."); this.smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled); this.smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled); this.controller = controller; this.focusNode = focusNode; this.decoration = noDecoration ? null : (decoration ?? new InputDecoration()); this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.style = style; this.strutStyle = strutStyle; this.textAlign = textAlign; this.textAlignVertical = textAlignVertical; this.textDirection = textDirection; this.readOnly = readOnly; this.showCursor = showCursor; this.autofocus = autofocus; this.obscureText = obscureText; this.autocorrect = autocorrect; this.enableSuggestions = enableSuggestions; this.maxLines = maxLines; this.minLines = minLines; this.expands = expands; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.onChanged = onChanged; this.onEditingComplete = onEditingComplete; this.onSubmitted = onSubmitted; this.inputFormatters = inputFormatters; this.enabled = enabled; this.cursorWidth = cursorWidth; this.cursorColor = cursorColor; this.selectionHeightStyle = selectionHeightStyle; this.selectionWidthStyle = selectionWidthStyle; this.cursorRadius = cursorRadius; this.onSubmitted = onSubmitted; this.keyboardAppearance = keyboardAppearance; this.enableInteractiveSelection = enableInteractiveSelection; this.onTap = onTap; this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.toolbarOptions = toolbarOptions ?? (obscureText ? new ToolbarOptions( selectAll: true, paste: true ) : new ToolbarOptions( copy: true, cut: true, selectAll: true, paste: true )); this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.dragStartBehavior = dragStartBehavior; this.enableInteractiveSelection = enableInteractiveSelection; this.buildCounter = buildCounter; this.scrollPhysics = scrollPhysics; this.scrollController = scrollController; }
public static void SetInputTextType(DependencyObject d, TextInputType value) { d.SetValue(InputTextTypeProperty, value); }
public NativeInput(Rectangle position, TextInputType keyboardContext, string text, int textSize, Align align, ITextEdit controller) { if (CurrentFocus != null) { CurrentFocus.Unfocus(); } _inputType = keyboardContext; _controller = controller; CurrentFocus = this; text = text.Replace('\n', '\r'); var info = DisplayInformation.GetForCurrentView(); double scale = info.RawPixelsPerViewPixel; double fontSize = textSize; if (keyboardContext == TextInputType.Password) { _usePasswordBox = true; _passwordBox.PasswordChanged += HandleEditingChangedPassword; _passwordBox.LostFocus += HandleEditingDidEnd; _passwordBox.KeyUp += HandleKeyUp; Canvas.SetLeft(_passwordBox, (position.X + 2) / scale); _passwordBox.Width = (position.Width - 4) / scale; _passwordBox.Height = _passwordBox.MinHeight; Canvas.SetTop(_passwordBox, (position.Center.Y / scale - _passwordBox.Height / 2)); _passwordBox.FontSize = fontSize; _passwordBox.Visibility = Visibility.Visible; _passwordBox.Focus(FocusState.Programmatic); SetText(text); } else { _usePasswordBox = false; _textBox.TextChanged += HandleEditingChanged; _textBox.LostFocus += HandleEditingDidEnd; _textBox.KeyUp += HandleKeyUp; Canvas.SetLeft(_textBox, (position.X + 2) / scale); _textBox.Width = (position.Width - 2) / scale; switch (align & Align.Horz) { case Align.Left: _textBox.TextAlignment = TextAlignment.Left; break; case Align.Right: _textBox.TextAlignment = TextAlignment.Right; break; case Align.Center: _textBox.TextAlignment = TextAlignment.Center; break; } _inputScope.Names.Clear(); _inputScope.Names.Add(NameFromContext(keyboardContext)); _textBox.InputScope = _inputScope; _textBox.IsTextPredictionEnabled = !keyboardContext.HasFlag(TextInputType.NoSuggestions); _uppercase = keyboardContext.HasFlag(TextInputType.Uppercase); if (keyboardContext == TextInputType.MultilineText) { _textBox.VerticalContentAlignment = VerticalAlignment.Top; _textBox.AcceptsReturn = true; _textBox.TextWrapping = TextWrapping.Wrap; _multiline = true; Canvas.SetTop(_textBox, (position.Y + 2) / scale); _textBox.Height = (position.Height - 4) / scale; } else { _textBox.VerticalContentAlignment = VerticalAlignment.Center; _textBox.AcceptsReturn = false; _textBox.TextWrapping = keyboardContext.HasFlag(TextInputType.Wrap) ? TextWrapping.Wrap : TextWrapping.NoWrap; _multiline = false; _textBox.Height = _textBox.MinHeight; Canvas.SetTop(_textBox, (position.Center.Y / scale - _textBox.Height / 2)); } SetText(text); CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; _textBox.FontSize = fontSize; _textBox.Visibility = Visibility.Visible; _textBox.Focus(FocusState.Programmatic); } }
public NativeInput(Rectangle position, TextInputType keyboardContext, string text, int textSize, Align align, ITextEdit controller) { if (CurrentFocus != null) { CurrentFocus.Unfocus(); } _controller = controller; CurrentFocus = this; if (_textField == null) { InitTextField(); } text = text.Replace('\n', '\r'); Bottom = position.Bottom + (int)Platform.PointsToPixels(10); position.Y += AppMain.Current.SetFocus(this); float x = Platform.PixelsToPoints(position.X) + 1; float y = Platform.PixelsToPoints(position.Y) + 2; float width = Platform.PixelsToPoints(position.Width) - 2; float height = Platform.PixelsToPoints(position.Height) - 4; if (keyboardContext.HasFlag(TextInputType.PasswordClass)) { keyboardContext &= ~(TextInputType.NoSuggestions); } if (keyboardContext.HasFlag(TextInputType.MultilineText)) { _useTextView = true; _textView.Frame = new System.Drawing.RectangleF(x, y, width, height); _textView.BackgroundColor = new UIColor(255, 255, 255, 255); _textView.TextColor = new UIColor(0, 0, 0, 255); _textView.Opaque = true; _textView.KeyboardType = TypeFromContext(keyboardContext); _textView.AutocapitalizationType = AutoCapitalizationFromContext(keyboardContext); _textView.KeyboardType = UIKeyboardType.Default; _textView.AutocorrectionType = keyboardContext.HasFlag(TextInputType.NoSuggestions) ? UITextAutocorrectionType.No : UITextAutocorrectionType.Default; _textView.SecureTextEntry = keyboardContext.HasFlag(TextInputType.PasswordClass); _textView.Font = UIFont.FromName("Helvetica", textSize); SetText(text); _textView.Ended += HandleEnded; _textView.BecomeFirstResponder(); } else { _textField.Frame = new System.Drawing.RectangleF(x, y, width, height); _textField.BackgroundColor = new UIColor(255, 255, 255, 255); _textField.TextColor = new UIColor(0, 0, 0, 255); _textField.Opaque = true; _textField.KeyboardType = TypeFromContext(keyboardContext); _textField.AutocapitalizationType = AutoCapitalizationFromContext(keyboardContext); _textField.ResignFirstResponder(); _textField.AutocorrectionType = keyboardContext.HasFlag(TextInputType.NoSuggestions) ? UITextAutocorrectionType.No : UITextAutocorrectionType.Default; _textField.SecureTextEntry = keyboardContext.HasFlag(TextInputType.PasswordClass); _textField.ClearsOnBeginEditing = false; _textField.Font = UIFont.FromName("Helvetica", textSize); switch (align & Align.Horz) { case Align.Center: _textField.TextAlignment = UITextAlignment.Center; break; case Align.Left: _textField.TextAlignment = UITextAlignment.Left; break; case Align.Right: _textField.TextAlignment = UITextAlignment.Right; break; } SetText(text); _textField.EditingChanged += HandleEditingChanged; _textField.EditingDidEnd += HandleEditingDidEnd; _textField.ShouldReturn = delegate { if ((keyboardContext & TextInputType.TypeFilter) != TextInputType.MultilineText) { _controller.Return(); return(true); } return(false); }; _textField.BecomeFirstResponder(); } }
public InputField( Key key = null, TextEditingController controller = null, FocusNode focusNode = null, bool obscureText = false, bool autocorrect = true, bool enabled = true, Decoration decoration = null, TextStyle style = null, TextAlign textAlign = TextAlign.left, Alignment alignment = null, int?maxLines = 1, int?minLines = null, int?maxLength = null, bool maxLengthEnforced = true, bool autofocus = false, List <TextInputFormatter> inputFormatters = null, Widget prefix = null, Widget suffix = null, string hintText = null, float?hintTextWidth = null, TextStyle hintStyle = null, string labelText = null, TextStyle labelStyle = null, Color cursorColor = null, float cursorWidth = 2, Radius cursorRadius = null, TextInputAction textInputAction = TextInputAction.none, TextInputType keyboardType = null, float?height = 44.0f, InputFieldClearButtonMode clearButtonMode = InputFieldClearButtonMode.never, bool enableInteractiveSelection = true, Color selectionColor = null, ValueChanged <string> onChanged = null, ValueChanged <string> onSubmitted = null, EdgeInsets scrollPadding = null ) : base(key: key) { D.assert(maxLines == null || minLines == null || maxLines >= minLines); this.controller = controller; this.textAlign = textAlign; this.focusNode = focusNode; this.obscureText = obscureText; this.autocorrect = autocorrect; this.enabled = enabled; this.decoration = decoration; this.style = style; this.textAlign = textAlign; this.alignment = alignment ?? Alignment.center; this.maxLines = maxLines; this.minLines = minLines; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.autofocus = autofocus; this.inputFormatters = inputFormatters; this.prefix = prefix; this.suffix = suffix; this.hintText = hintText; this.hintTextWidth = hintTextWidth; this.hintStyle = hintStyle; this.labelText = labelText; this.labelStyle = labelStyle; this.height = height; this.clearButtonMode = clearButtonMode; this.enableInteractiveSelection = enableInteractiveSelection; this.selectionColor = selectionColor ?? new Color(0x667FAACF); this.cursorColor = cursorColor; this.cursorWidth = cursorWidth; this.cursorRadius = cursorRadius ?? Radius.circular(1.0f); this.textInputAction = textInputAction; this.keyboardType = keyboardType; this.onChanged = onChanged; this.onSubmitted = onSubmitted; this.scrollPadding = scrollPadding; }
public CupertinoTextField( Key key = null, TextEditingController controller = null, FocusNode focusNode = null, BoxDecoration decoration = null, EdgeInsets padding = null, string placeholder = null, TextStyle placeholderStyle = null, Widget prefix = null, OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always, Widget suffix = null, OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always, OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null, StrutStyle strutStyle = null, TextAlign textAlign = TextAlign.left, bool autofocus = false, bool obscureText = false, bool autocorrect = true, int?maxLines = 1, int?minLines = null, bool expands = false, int?maxLength = null, bool maxLengthEnforced = true, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, List <TextInputFormatter> inputFormatters = null, bool?enabled = null, float cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start, ScrollPhysics scrollPhysics = null) : base(key: key) { D.assert(maxLines == null || maxLines > 0); D.assert(minLines == null || minLines > 0); D.assert(maxLines == null || minLines == null || maxLines >= minLines, () => "minLines can't be greater than maxLines"); D.assert(!expands || (maxLines == null && minLines == null), () => "minLines and maxLines must be null when expands is true."); D.assert(maxLength == null || maxLength > 0); this.controller = controller; this.focusNode = focusNode; this.decoration = decoration ?? CupertinoTextFieldUtils._kDefaultRoundedBorderDecoration; this.padding = padding ?? EdgeInsets.all(6.0f); this.placeholder = placeholder; this.placeholderStyle = placeholderStyle ?? new TextStyle( fontWeight: FontWeight.w300, color: CupertinoTextFieldUtils._kInactiveTextColor ); this.prefix = prefix; this.prefixMode = prefixMode; this.suffix = suffix; this.suffixMode = suffixMode; this.clearButtonMode = clearButtonMode; this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.style = style; this.strutStyle = strutStyle; this.textAlign = textAlign; this.autofocus = autofocus; this.obscureText = obscureText; this.autocorrect = autocorrect; this.maxLines = maxLines; this.minLines = minLines; this.expands = expands; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.onChanged = onChanged; this.onEditingComplete = onEditingComplete; this.onSubmitted = onSubmitted; this.inputFormatters = inputFormatters; this.enabled = enabled; this.cursorWidth = cursorWidth; this.cursorRadius = cursorRadius ?? Radius.circular(2.0f); this.cursorColor = cursorColor; this.keyboardAppearance = keyboardAppearance; this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.dragStartBehavior = dragStartBehavior; this.scrollPhysics = scrollPhysics; this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); }
public TextFormField( Key key = null, TextEditingController controller = null, string initialValue = null, FocusNode focusNode = null, InputDecoration decoration = null, TextInputType keyboardType = null, TextCapitalization textCapitalization = TextCapitalization.none, TextInputAction?textInputAction = null, TextStyle style = null, StrutStyle strutStyle = null, TextDirection?textDirection = null, TextAlign textAlign = TextAlign.left, TextAlignVertical textAlignVertical = null, bool autofocus = false, bool readOnly = false, ToolbarOptions toolbarOptions = null, bool?showCursor = null, bool obscureText = false, bool autocorrect = true, SmartDashesType?smartDashesType = null, SmartQuotesType?smartQuotesType = null, bool enableSuggestions = true, bool autovalidate = false, bool maxLengthEnforced = true, int?maxLines = 1, int?minLines = null, bool expands = false, int?maxLength = null, ValueChanged <string> onChanged = null, GestureTapCallback onTap = null, VoidCallback onEditingComplete = null, ValueChanged <string> onFieldSubmitted = null, FormFieldSetter <string> onSaved = null, FormFieldValidator <string> validator = null, List <TextInputFormatter> inputFormatters = null, bool enabled = true, float cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, bool enableInteractiveSelection = true, InputCounterWidgetBuilder buildCounter = null, ScrollPhysics scrollPhysics = null ) : base( key: key, initialValue: controller != null ? controller.text : (initialValue ?? ""), onSaved: onSaved, validator: validator, autovalidate: autovalidate, enabled: enabled, builder: (FormFieldState <string> field) => { _TextFormFieldState state = (_TextFormFieldState)field; InputDecoration effectiveDecoration = (decoration ?? new InputDecoration()) .applyDefaults(Theme.of(field.context).inputDecorationTheme); void onChangedHandler(string value) { if (onChanged != null) { onChanged(value); } field.didChange(value); } return(new TextField( controller: state._effectiveController, focusNode: focusNode, decoration: effectiveDecoration.copyWith(errorText: field.errorText), keyboardType: keyboardType, textInputAction: textInputAction, style: style, strutStyle: strutStyle, textAlign: textAlign, textAlignVertical: textAlignVertical, textDirection: textDirection ?? TextDirection.ltr, textCapitalization: textCapitalization, autofocus: autofocus, toolbarOptions: toolbarOptions, readOnly: readOnly, showCursor: showCursor, obscureText: obscureText, autocorrect: autocorrect, smartDashesType: smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartQuotesType: smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), enableSuggestions: enableSuggestions, maxLengthEnforced: maxLengthEnforced, maxLines: maxLines, minLines: minLines, expands: expands, maxLength: maxLength, onChanged: onChangedHandler, onTap: onTap, onEditingComplete: onEditingComplete, onSubmitted: onFieldSubmitted, inputFormatters: inputFormatters, enabled: enabled, cursorWidth: cursorWidth, cursorRadius: cursorRadius, cursorColor: cursorColor, scrollPadding: scrollPadding ?? EdgeInsets.all(20.0f), scrollPhysics: scrollPhysics, keyboardAppearance: keyboardAppearance, enableInteractiveSelection: enableInteractiveSelection, buildCounter: buildCounter )); } ) { D.assert(initialValue == null || controller == null); D.assert(maxLines > 0); D.assert(maxLines == null || maxLines > 0); D.assert(minLines == null || minLines > 0); D.assert((maxLines == null) || (minLines == null) || (maxLines >= minLines), () => "minLines can't be greater than maxLines"); D.assert(!expands || (maxLines == null && minLines == null), () => "minLines and maxLines must be null when expands is true."); D.assert(!obscureText || maxLines == 1, () => "Obscured fields cannot be multiline."); D.assert(maxLength == null || maxLength > 0); this.controller = controller; }
public TextField(Key key = null, TextEditingController controller = null, FocusNode focusNode = null, InputDecoration decoration = null, bool noDecoration = false, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null, TextAlign textAlign = TextAlign.left, TextDirection textDirection = TextDirection.ltr, bool autofocus = false, bool obscureText = false, bool autocorrect = false, int?maxLines = 1, int?maxLength = null, bool maxLengthEnforced = true, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, List <TextInputFormatter> inputFormatters = null, bool?enabled = null, float?cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, bool enableInteractiveSelection = true, GestureTapCallback onTap = null ) : base(key: key) { D.assert(maxLines == null || maxLines > 0); D.assert(maxLength == null || maxLength > 0); this.controller = controller; this.focusNode = focusNode; this.decoration = noDecoration ? null : (decoration ?? new InputDecoration()); this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.style = style; this.textAlign = textAlign; this.textDirection = textDirection; this.autofocus = autofocus; this.obscureText = obscureText; this.autocorrect = autocorrect; this.maxLines = maxLines; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.onChanged = onChanged; this.onEditingComplete = onEditingComplete; this.onSubmitted = onSubmitted; this.inputFormatters = inputFormatters; this.enabled = enabled; this.cursorWidth = cursorWidth; this.cursorColor = cursorColor; this.cursorRadius = cursorRadius; this.onSubmitted = onSubmitted; this.keyboardAppearance = keyboardAppearance; this.enableInteractiveSelection = enableInteractiveSelection; this.onTap = onTap; this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); }
public static bool ValidTextInput(this TextBox textField, ErrorProvider errors, TextInputType textInputType = TextInputType.Letters) { if (errors == null) { return(false); } if (string.IsNullOrWhiteSpace(textField.Text)) { errors.SetError(textField, Resources.RequiredField); return(false); } if ((textInputType == TextInputType.Digits && textField.Text.Any(char.IsLetter)) || (textInputType == TextInputType.Letters && textField.Text.Any(char.IsDigit))) { errors.SetError(textField, Resources.InvalidFormat); return(false); } return(true); }
public CupertinoTextField( Key key = null, TextEditingController controller = null, FocusNode focusNode = null, BoxDecoration decoration = null, EdgeInsets padding = null, string placeholder = null, TextStyle placeholderStyle = null, Widget prefix = null, OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always, Widget suffix = null, OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always, OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null, StrutStyle strutStyle = null, TextAlign textAlign = TextAlign.left, TextAlignVertical textAlignVertical = null, bool readOnly = false, ToolbarOptions toolbarOptions = null, bool?showCursor = null, bool autofocus = false, bool obscureText = false, bool autocorrect = true, SmartDashesType?smartDashesType = null, SmartQuotesType?smartQuotesType = null, bool enableSuggestions = true, int?maxLines = 1, int?minLines = null, bool expands = false, int?maxLength = null, bool maxLengthEnforced = true, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, List <TextInputFormatter> inputFormatters = null, bool?enabled = null, float cursorWidth = 2.0f, Radius cursorRadius = null, Color cursorColor = null, ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight, ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight, Brightness?keyboardAppearance = null, EdgeInsets scrollPadding = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool enableInteractiveSelection = true, GestureTapCallback onTap = null, ScrollController scrollController = null, ScrollPhysics scrollPhysics = null ) : base(key: key) { this.smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled); this.smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled); D.assert(maxLines == null || maxLines > 0); D.assert(minLines == null || minLines > 0); D.assert(maxLines == null || minLines == null || maxLines >= minLines, () => "minLines can't be greater than maxLines"); D.assert(!expands || (maxLines == null && minLines == null), () => "minLines and maxLines must be null when expands is true."); D.assert(maxLength == null || maxLength > 0); this.controller = controller; this.focusNode = focusNode; this.decoration = decoration ?? CupertinoTextFieldUtils._kDefaultRoundedBorderDecoration; this.padding = padding ?? EdgeInsets.all(6.0f); this.placeholder = placeholder; this.placeholderStyle = placeholderStyle ?? new TextStyle( fontWeight: FontWeight.w400, color: CupertinoColors.placeholderText ); this.prefix = prefix; this.prefixMode = prefixMode; this.suffix = suffix; this.suffixMode = suffixMode; this.clearButtonMode = clearButtonMode; this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.style = style; this.strutStyle = strutStyle; this.textAlign = textAlign; this.textAlignVertical = textAlignVertical; this.readOnly = readOnly; this.showCursor = showCursor; this.autofocus = autofocus; this.obscureText = obscureText; this.autocorrect = autocorrect; this.enableSuggestions = enableSuggestions; this.maxLines = maxLines; this.minLines = minLines; this.expands = expands; this.maxLength = maxLength; this.maxLengthEnforced = maxLengthEnforced; this.onChanged = onChanged; this.onEditingComplete = onEditingComplete; this.onSubmitted = onSubmitted; this.inputFormatters = inputFormatters; this.enabled = enabled; this.cursorWidth = cursorWidth; this.cursorRadius = cursorRadius ?? Radius.circular(2.0f); this.cursorColor = cursorColor; this.selectionHeightStyle = selectionHeightStyle; this.selectionWidthStyle = selectionWidthStyle; this.keyboardAppearance = keyboardAppearance; this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.dragStartBehavior = dragStartBehavior; this.enableInteractiveSelection = enableInteractiveSelection; this.scrollPhysics = scrollPhysics; this.onTap = onTap; this.scrollController = scrollController; this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.toolbarOptions = toolbarOptions ?? (obscureText ? new ToolbarOptions( selectAll: true, paste: true ) : new ToolbarOptions( copy: true, cut: true, selectAll: true, paste: true )); }
//透明度从高到低 #endregion #region 检查文本控件输入类型是否有效 /// <summary> /// 功能描述:检查文本控件输入类型是否有效 /// 作 者:HZH /// 创建日期:2019-02-28 10:23:34 /// 任务编号:POS /// </summary> /// <param name="strValue">值</param> /// <param name="inputType">控制类型</param> /// <param name="decMaxValue">最大值</param> /// <param name="decMinValue">最小值</param> /// <param name="intLength">小数位长度</param> /// <param name="strRegexPattern">正则</param> /// <returns>返回值</returns> public static bool CheckInputType( string strValue, TextInputType inputType, decimal decMaxValue = default(decimal), decimal decMinValue = default(decimal), int intLength = 2, string strRegexPattern = null) { bool result; switch (inputType) { case TextInputType.NotControl: result = true; return(result); case TextInputType.UnsignNumber: if (string.IsNullOrEmpty(strValue)) { result = true; return(result); } else { if (strValue.IndexOf("-") >= 0) { result = false; return(result); } } break; case TextInputType.Number: if (string.IsNullOrEmpty(strValue)) { result = true; return(result); } else { if (!Regex.IsMatch(strValue, "^-?\\d*(\\.?\\d*)?$")) { result = false; return(result); } } break; case TextInputType.Integer: if (string.IsNullOrEmpty(strValue)) { result = true; return(result); } else { if (!Regex.IsMatch(strValue, "^-?\\d*$")) { result = false; return(result); } } break; case TextInputType.PositiveInteger: if (string.IsNullOrEmpty(strValue)) { result = true; return(result); } else { if (!Regex.IsMatch(strValue, "^\\d+$")) { result = false; return(result); } } break; case TextInputType.Regex: result = (string.IsNullOrEmpty(strRegexPattern) || Regex.IsMatch(strValue, strRegexPattern)); return(result); } if (strValue == "-") { return(true); } decimal d; if (!decimal.TryParse(strValue, out d)) { result = false; } else if (d < decMinValue || d > decMaxValue) { result = false; } else { if (inputType == TextInputType.Number || inputType == TextInputType.UnsignNumber || inputType == TextInputType.PositiveNumber) { if (strValue.IndexOf(".") >= 0) { string text = strValue.Substring(strValue.IndexOf(".")); if (text.Length > intLength + 1) { result = false; return(result); } } } result = true; } return(result); }
public NativeInput(Rectangle position, TextInputType textInputType, string text, int textSize, Align textAlign, ITextEdit controller) { if (CurrentFocus != null) { CurrentFocus.Unfocus(); } _controller = controller; CurrentFocus = this; if (_textField != null) { EditTextEx field = _textField; field.OnBackPressed -= UnfocusByBack; _textField = null; DelayedActionInvoker.Instance.AddAction(10, (s) => { AppMain.Current.RootView.RemoveView(field); }); } { InitTextField(); } DisplayMetrics metrics = AppMain.Activity.Resources.DisplayMetrics; int padding = 0; if (textInputType == TextInputType.MultilineText) { padding = 0; } _textField.SetTextSize(Android.Util.ComplexUnitType.Px, (float)(UiUnit.FontUnit * textSize)); _textField.SetHeight(position.Height); _textField.SetPadding(0, padding, _textField.PaddingRight, padding); _textField.InputType = TypeFromContext(textInputType); if (textInputType.HasFlag(TextInputType.Uppercase)) { _textField.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(controller.MaxLength), new InputFilterAllCaps() }); } else { _textField.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(controller.MaxLength) }); } switch (textAlign & Align.Horz) { case Align.Left: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.Left; break; case Align.Center: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.CenterHorizontal; break; case Align.Right: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.Right; break; } if ((textInputType & TextInputType.TypeFilter) == TextInputType.MultilineText) { _textField.SetMaxLines(controller.MaxLines); _textField.EditorAction -= HandleEditorAction; _textField.Gravity = GravityFlags.Left | GravityFlags.Top; _textField.SetSingleLine(false); _textField.ImeOptions = ImeAction.ImeNull | (ImeAction)ImeFlags.NoExtractUi; } else { _textField.SetMaxLines(1); _textField.EditorAction += HandleEditorAction; _textField.SetSingleLine(true); _textField.ImeOptions = (controller.WaitsForReturn ? ImeAction.Next : ImeAction.Done) | (ImeAction)ImeFlags.NoExtractUi; } if (textInputType.HasFlag(TextInputType.NoSuggestions)) { _textField.ImeOptions |= (ImeAction)InputTypes.TextFlagNoSuggestions; } _textField.SetAllCaps((textInputType & TextInputType.TypeFilter) == TextInputType.Uppercase); _textField.TransformationMethod = textInputType == TextInputType.Password ? new PasswordTransformationMethod(): null; _layoutParams.SetMargins(position.X, position.Y + 4, 0, 0); _layoutParams.Width = position.Width; _layoutParams.Height = position.Height - 4; _textField.Text = text; _textField.SetSelection(_textField.Text.Length, _textField.Text.Length); _textField.TextChanged += HandleEditingChanged; _textField.FocusChange += HandleFocusChange; _textField.RequestLayout(); _textField.Visibility = Android.Views.ViewStates.Visible; _textField.SetCursorVisible(true); _textField.RequestFocus(); _textField.RequestFocusFromTouch(); ShowKeyboard(_textField); }
public TextInput(ITextConsumer consumer, TextInputType inputType) { _consumer = consumer; _inputType = inputType; }
/// <summary> /// Sets the type of keyboard that should be displayed to the user. /// </summary> /// <param name="textInputType">The keybord type</param> public void SetTextInputType(TextInputType textInputType) { switch (textInputType) { case TextInputType.Number: ContentType = "number"; break; case TextInputType.PhoneNumber: ContentType = "phonenumber"; break; case TextInputType.Url: ContentType = "url"; break; case TextInputType.Email: ContentType = "number"; break; default: ContentType = "email"; break; } }