Class Input

java.lang.Object
eltos.simpledialogfragment.form.FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
eltos.simpledialogfragment.form.Input
All Implemented Interfaces:
android.os.Parcelable

public class Input extends FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
An input form element to be used with SimpleFormDialog This is an EditText that can be used to enter text, email-addresses, numbers, passwords etc. Optionally supports auto-complete behaviour using suggestions. This will add a String to resource bundle containing the entered text. Created by eltos on 20.02.17.
  • Field Details

    • wrap

      protected Boolean wrap
    • maxLines

      protected int maxLines
    • CREATOR

      public static final android.os.Parcelable.Creator<Input> CREATOR
  • Method Details

    • plain

      public static Input plain(String key)
      Factory method for a plain input field.
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • name

      public static Input name(String key)
      Factory method for a name input field. InputType and hint are preset.
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • password

      public static Input password(String key)
      Factory method for a password input field. InputType and hint are preset. Shows a button to toggle the passwords visibility
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • pin

      public static Input pin(String key)
      Factory method for a pin input field. InputType and hint are preset.
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • email

      public static Input email(String key)
      Factory method for an email input field. InputType and hint are preset. This field also validates, that an email matching the default pattern was entered.
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • phone

      public static Input phone(String key)
      Factory method for a phone input field. InputType and hint are preset. This field also automatically format the phone number while the user is typing.
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • spinner

      public static Input spinner(String key)
      Factory method for a spinner input field. This disables editing and only uses suggestions. Make sure to supply the items via suggest(int)
      Parameters:
      key - the key that can be used to receive the entered text from the bundle in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Returns:
      this instance
    • spinner

      public static Input spinner(String key, @ArrayRes int suggestionArrayRes)
    • spinner

      public static Input spinner(String key, @StringRes int... suggestionStringResArray)
    • spinner

      public static Input spinner(String key, String... strings)
    • spinner

      public static Input spinner(String key, ArrayList<String> strings)
    • hint

      public Input hint(String hint)
      Sets a hint
      Parameters:
      hint - the hint as string
      Returns:
      this instance
    • hint

      public Input hint(@StringRes int hintResourceId)
      Sets a hint
      Parameters:
      hintResourceId - the hint as android string resource
      Returns:
      this instance
    • text

      public Input text(String text)
      Sets the initial text
      Parameters:
      text - initial text as string
      Returns:
      this instance
    • text

      public Input text(@StringRes int textResourceId)
      Sets the initial text
      Parameters:
      textResourceId - initial text as android string resource
      Returns:
      this instance
    • inputType

      public Input inputType(int inputType)
      Sets the input type The default is InputType.TYPE_CLASS_TEXT.
      Parameters:
      inputType - the input type. See InputType
      Returns:
      this instance
    • multiLine

      public Input multiLine()
      Sets the input type to InputType.TYPE_TEXT_FLAG_MULTI_LINE.
      Returns:
      this instance
    • multiLine

      public Input multiLine(int maxLines)
      Sets the input type to InputType.TYPE_TEXT_FLAG_MULTI_LINE and the maximum number of lines to show
      Parameters:
      maxLines - the maximum number of lines to show. If the text exceeds this number of lines, the input field will scroll vertically.
      Returns:
      this instance
    • wrap

      public Input wrap()
      Enables wrapping of lines exceeding the width of the input field.
      Returns:
      this instance
    • wrap

      public Input wrap(int maxLines)
      Enables wrapping of lines exceeding the width of the input field.
      Parameters:
      maxLines - the maximum number of lines to show. If the text exceeds this number of lines, the input field will scroll vertically.
      Returns:
      this instance
    • wrap

      public Input wrap(@Nullable Boolean wrap, int maxLines)
      Configures wrapping of lines exceeding the width of the input field.
      Parameters:
      wrap - en-/disable wrapping of lines (and dis-/enable horizontal scrolling)
      maxLines - the maximum number of lines to show. If the text exceeds this number of lines, the input field will scroll vertically.
      Returns:
      this instance
    • showPasswordToggle

      public Input showPasswordToggle()
      Displays a button to toggle the password visibility. Note that this will only work if the input type is a password. See showPasswordToggle(boolean)
      Returns:
      this instance
    • showPasswordToggle

      public Input showPasswordToggle(boolean show)
      Hide or show a button to toggle the password visibility. Note that this will only work if the input type is a password.
      Parameters:
      show - whether to show the password toggle button
      Returns:
      this instance
    • max

      public Input max(@IntRange(from=1L) int maxLength)
      Sets an upper limit to the input's text length.
      Parameters:
      maxLength - the maximum text length
      Returns:
      this instance
    • min

      public Input min(@IntRange(from=1L) int minLength)
      Sets a lower limit to the input's text length.
      Parameters:
      minLength - the minimum text length
      Returns:
      this instance
    • suggest

      public Input suggest(@ArrayRes int suggestionArrayRes)
      Provide an array resource with suggestions to be shown while the user is typing. This enables the auto-complete behaviour.
      Parameters:
      suggestionArrayRes - the string array resource to suggest
      Returns:
      this instance
    • suggest

      public Input suggest(@StringRes int... suggestionStringResArray)
      Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.
      Parameters:
      suggestionStringResArray - array of string resources to suggest
      Returns:
      this instance
    • suggest

      public Input suggest(String... strings)
      Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.
      Parameters:
      strings - array of strings to suggest
      Returns:
      this instance
    • suggest

      public Input suggest(ArrayList<String> strings)
      Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.
      Parameters:
      strings - An ArrayList of strings to suggest
      Returns:
      this instance
    • forceSuggestion

      public Input forceSuggestion()
      Returns:
      this instance
    • forceSuggestion

      public Input forceSuggestion(boolean force)
      Specify whether this input may contain only one of the suggestions provided. If enabled, the EditText will show an error message if something else was entered. This will only take affect if suggestions were set by any of the suggest(int) methods If the suggestion array is small, consider using a spinner instead.
      Parameters:
      force - whether to force the input to be one of the suggestions or not
      Returns:
      this instance
    • asSpinner

      public Input asSpinner(boolean spinner)
      Make this Input field a spinner (not editable, drop down button)
      Parameters:
      spinner - whether to make this a spinner
      Returns:
      this instance
    • validatePattern

      public Input validatePattern(String pattern, @Nullable String errorMsg)
      Validate input using the supplied regular expression pattern and display an error message if the pattern does not match.
      Parameters:
      pattern - a regular expression used to validate input
      errorMsg - the error message to display, if the pattern does not match the input
      Returns:
      this instance
    • validatePattern

      public Input validatePattern(String pattern, @StringRes int errorMsgId)
      Validate input using the supplied regular expression pattern and display an error message if the pattern does not match. See validatePattern(String, String)
      Parameters:
      pattern - a regular expression used to validate input
      errorMsgId - the error message to display as string resource
      Returns:
      this instance
    • validatePatternEmail

      public Input validatePatternEmail()
      Validate input as email address. Shortcut for validatePattern(String, int).
      Returns:
      this instance
    • validatePatternStrongPassword

      public Input validatePatternStrongPassword()
      Validate input as password. The password must consists of at least 8 chars and contains at least one number, one special character, one upper and one lower case letter Shortcut for validatePattern(String, int).
      Returns:
      this instance
    • validatePatternLetters

      public Input validatePatternLetters()
      Validate input so that only upper- and lowercase letters are contained. Shortcut for validatePattern(String, int).
      Returns:
      this instance
    • validatePatternAlphanumeric

      public Input validatePatternAlphanumeric()
      Validate input to consist of alpha-numeric characters only. Shortcut for validatePattern(String, int).
      Returns:
      this instance
    • buildViewHolder

      public eltos.simpledialogfragment.form.InputViewHolder buildViewHolder()
      Description copied from class: FormElement
      Return your custom implementation of FormElementViewHolder here
      Specified by:
      buildViewHolder in class FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
      Returns:
      The view holder that can represent this form element
    • validatePattern

      protected String validatePattern(android.content.Context context, @Nullable String input)
    • getPatternError

      @Nullable protected String getPatternError(android.content.Context context)
    • getHint

      @Nullable protected String getHint(android.content.Context context)
    • getText

      @Nullable protected String getText(android.content.Context context)
      Overrides:
      getText in class FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
    • getSuggestions

      @Nullable protected String[] getSuggestions(android.content.Context context)
    • describeContents

      public int describeContents()
      Specified by:
      describeContents in interface android.os.Parcelable
      Overrides:
      describeContents in class FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
    • writeToParcel

      public void writeToParcel(android.os.Parcel dest, int flags)
      Specified by:
      writeToParcel in interface android.os.Parcelable
      Overrides:
      writeToParcel in class FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>