public static class Autocomplete.SimplePolicy extends java.lang.Object implements AutocompletePolicy
AutocompletePolicy implementation.
Popup is shown when text length is bigger than 0, and hidden when text is empty.
The query string is the whole text.| Constructor and Description |
|---|
SimplePolicy() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.CharSequence |
getQuery(android.text.Spannable text)
Called to understand which query should be passed to
AutocompletePresenter
for a showing popup. |
void |
onDismiss(android.text.Spannable text)
Called when popup is dismissed.
|
boolean |
shouldDismissPopup(android.text.Spannable text,
int cursorPos)
Called to understand whether a currently shown popup should be closed, maybe
because text is invalid.
|
boolean |
shouldShowPopup(android.text.Spannable text,
int cursorPos)
Called to understand whether the popup should be shown.
|
public boolean shouldShowPopup(android.text.Spannable text,
int cursorPos)
AutocompletePolicyreturn text.length() > 0
- Show when last char is @: return text.getCharAt(text.length()-1) == '@'shouldShowPopup in interface AutocompletePolicytext - current text, along with its SpanscursorPos - the position of the cursorpublic boolean shouldDismissPopup(android.text.Spannable text,
int cursorPos)
AutocompletePolicyreturn !shouldShowPopup(text, cursorPos).
However this is defined so you can add or clear spans.shouldDismissPopup in interface AutocompletePolicytext - current text, along with its SpanscursorPos - the position of the cursorpublic java.lang.CharSequence getQuery(android.text.Spannable text)
AutocompletePolicyAutocompletePresenter
for a showing popup. If this is called, AutocompletePolicy.shouldShowPopup(Spannable, int) just returned
true, or AutocompletePolicy.shouldDismissPopup(Spannable, int) just returned false.
This is useful to understand which part of the text should be passed to presenters.
For example, user might have typed '@john' to select a username, but you just want to
search for 'john'.
For more complex cases, you can add inclusive Spans in AutocompletePolicy.shouldShowPopup(Spannable, int),
and get the span position here.getQuery in interface AutocompletePolicytext - current text, along with its Spanspublic void onDismiss(android.text.Spannable text)
AutocompletePolicyonDismiss in interface AutocompletePolicytext - text at the moment of dismissing