Package eltos.simpledialogfragment.form
Class Input
java.lang.Object
eltos.simpledialogfragment.form.FormElement<Input,eltos.simpledialogfragment.form.InputViewHolder>
eltos.simpledialogfragment.form.Input
- All Implemented Interfaces:
android.os.Parcelable
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.-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final android.os.Parcelable.Creator<Input>
protected int
protected Boolean
Fields inherited from class eltos.simpledialogfragment.form.FormElement
NO_ID, required, resultKey
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
-
Method Summary
Modifier and TypeMethodDescriptionasSpinner
(boolean spinner) Make this Input field a spinner (not editable, drop down button)eltos.simpledialogfragment.form.InputViewHolder
Return your custom implementation ofFormElementViewHolder
hereint
static Input
Factory method for an email input field.Shortcut forforceSuggestion(boolean)
forceSuggestion
(boolean force) Specify whether this input may contain only one of the suggestions provided.protected String
getHint
(android.content.Context context) protected String
getPatternError
(android.content.Context context) protected String[]
getSuggestions
(android.content.Context context) protected String
getText
(android.content.Context context) hint
(int hintResourceId) Sets a hintSets a hintinputType
(int inputType) Sets the input type The default isInputType.TYPE_CLASS_TEXT
.max
(int maxLength) Sets an upper limit to the input's text length.min
(int minLength) Sets a lower limit to the input's text length.Sets the input type toInputType.TYPE_TEXT_FLAG_MULTI_LINE
.multiLine
(int maxLines) Sets the input type toInputType.TYPE_TEXT_FLAG_MULTI_LINE
and the maximum number of lines to showstatic Input
Factory method for a name input field.static Input
Factory method for a password input field.static Input
Factory method for a phone input field.static Input
Factory method for a pin input field.static Input
Factory method for a plain input field.Displays a button to toggle the password visibility.showPasswordToggle
(boolean show) Hide or show a button to toggle the password visibility.static Input
Factory method for a spinner input field.static Input
static Input
static Input
static Input
suggest
(int suggestionArrayRes) Provide an array resource with suggestions to be shown while the user is typing.suggest
(int... suggestionStringResArray) Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.Provide an array of suggestions to be shown while the user is typing This enables the auto-complete behaviour.text
(int textResourceId) Sets the initial textSets the initial textprotected String
validatePattern
(android.content.Context context, String input) validatePattern
(String pattern, int errorMsgId) Validate input using the supplied regular expression pattern and display an error message if the pattern does not match.validatePattern
(String pattern, String errorMsg) Validate input using the supplied regular expression pattern and display an error message if the pattern does not match.Validate input to consist of alpha-numeric characters only.Validate input as email address.Validate input so that only upper- and lowercase letters are contained.Validate input as password.wrap()
Enables wrapping of lines exceeding the width of the input field.wrap
(int maxLines) Enables wrapping of lines exceeding the width of the input field.Configures wrapping of lines exceeding the width of the input field.void
writeToParcel
(android.os.Parcel dest, int flags) Methods inherited from class eltos.simpledialogfragment.form.FormElement
label, label, required, required
-
Field Details
-
wrap
-
maxLines
protected int maxLines -
CREATOR
-
-
Method Details
-
plain
Factory method for a plain input field.- Parameters:
key
- the key that can be used to receive the entered text from the bundle inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
name
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 inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
password
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 inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
pin
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 inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
email
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 inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
phone
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 inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
spinner
Factory method for a spinner input field. This disables editing and only uses suggestions. Make sure to supply the items viasuggest(int)
- Parameters:
key
- the key that can be used to receive the entered text from the bundle inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Returns:
- this instance
-
spinner
-
spinner
-
spinner
-
spinner
-
hint
Sets a hint- Parameters:
hint
- the hint as string- Returns:
- this instance
-
hint
Sets a hint- Parameters:
hintResourceId
- the hint as android string resource- Returns:
- this instance
-
text
Sets the initial text- Parameters:
text
- initial text as string- Returns:
- this instance
-
text
Sets the initial text- Parameters:
textResourceId
- initial text as android string resource- Returns:
- this instance
-
inputType
Sets the input type The default isInputType.TYPE_CLASS_TEXT
.- Parameters:
inputType
- the input type. SeeInputType
- Returns:
- this instance
-
multiLine
Sets the input type toInputType.TYPE_TEXT_FLAG_MULTI_LINE
.- Returns:
- this instance
-
multiLine
Sets the input type toInputType.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
Enables wrapping of lines exceeding the width of the input field.- Returns:
- this instance
-
wrap
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
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
Displays a button to toggle the password visibility. Note that this will only work if the input type is a password. SeeshowPasswordToggle(boolean)
- Returns:
- this instance
-
showPasswordToggle
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
Sets an upper limit to the input's text length.- Parameters:
maxLength
- the maximum text length- Returns:
- this instance
-
min
Sets a lower limit to the input's text length.- Parameters:
minLength
- the minimum text length- Returns:
- this instance
-
suggest
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
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
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
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
Shortcut forforceSuggestion(boolean)
- Returns:
- this instance
-
forceSuggestion
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 thesuggest(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
Make this Input field a spinner (not editable, drop down button)- Parameters:
spinner
- whether to make this a spinner- Returns:
- this instance
-
validatePattern
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 inputerrorMsg
- the error message to display, if the pattern does not match the input- Returns:
- this instance
-
validatePattern
Validate input using the supplied regular expression pattern and display an error message if the pattern does not match. SeevalidatePattern(String, String)
- Parameters:
pattern
- a regular expression used to validate inputerrorMsgId
- the error message to display as string resource- Returns:
- this instance
-
validatePatternEmail
Validate input as email address. Shortcut forvalidatePattern(String, int)
.- Returns:
- this instance
-
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 forvalidatePattern(String, int)
.- Returns:
- this instance
-
validatePatternLetters
Validate input so that only upper- and lowercase letters are contained. Shortcut forvalidatePattern(String, int)
.- Returns:
- this instance
-
validatePatternAlphanumeric
Validate input to consist of alpha-numeric characters only. Shortcut forvalidatePattern(String, int)
.- Returns:
- this instance
-
buildViewHolder
public eltos.simpledialogfragment.form.InputViewHolder buildViewHolder()Description copied from class:FormElement
Return your custom implementation ofFormElementViewHolder
here- Specified by:
buildViewHolder
in classFormElement<Input,
eltos.simpledialogfragment.form.InputViewHolder> - Returns:
- The view holder that can represent this form element
-
validatePattern
-
getPatternError
-
getHint
-
getText
- Overrides:
getText
in classFormElement<Input,
eltos.simpledialogfragment.form.InputViewHolder>
-
getSuggestions
-
describeContents
public int describeContents()- Specified by:
describeContents
in interfaceandroid.os.Parcelable
- Overrides:
describeContents
in classFormElement<Input,
eltos.simpledialogfragment.form.InputViewHolder>
-
writeToParcel
public void writeToParcel(android.os.Parcel dest, int flags) - Specified by:
writeToParcel
in interfaceandroid.os.Parcelable
- Overrides:
writeToParcel
in classFormElement<Input,
eltos.simpledialogfragment.form.InputViewHolder>
-