public abstract class TokenCompleteTextView<T> extends AppCompatAutoCompleteTextView implements android.widget.TextView.OnEditorActionListener, ViewSpan.Layout
| Modifier and Type | Class and Description |
|---|---|
static class |
TokenCompleteTextView.TokenClickStyle |
protected class |
TokenCompleteTextView.TokenImageSpan |
static interface |
TokenCompleteTextView.TokenListener<T> |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
TAG |
| Constructor and Description |
|---|
TokenCompleteTextView(android.content.Context context) |
TokenCompleteTextView(android.content.Context context,
android.util.AttributeSet attrs) |
TokenCompleteTextView(android.content.Context context,
android.util.AttributeSet attrs,
int defStyle) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addListeners()
Add the TextChangedListeners
|
void |
addObjectAsync(T object)
Append a token object to the object list.
|
void |
addObjectSync(T object)
Append a token object to the object list.
|
void |
allowCollapse(boolean allowCollapse)
Set whether the view should collapse to a single line when it loses focus.
|
protected TokenCompleteTextView.TokenImageSpan |
buildSpanForObject(T obj) |
boolean |
canDeleteSelection(int beforeLength)
Checks if selection can be deleted.
|
void |
clearAsync()
Remove all objects from the token list.
|
void |
clearCompletionText()
Clear the completion text only.
|
protected java.lang.CharSequence |
convertSelectionToString(java.lang.Object object) |
protected java.util.List<T> |
convertSerializableObjectsToTypedObjects(java.util.List s) |
protected java.lang.String |
currentCompletionText() |
protected abstract T |
defaultObject(java.lang.String completionText)
Provides a default completion when the user hits , and there is no item in the completion
list
|
boolean |
enoughToFilter() |
boolean |
extractText(android.view.inputmethod.ExtractedTextRequest request,
android.view.inputmethod.ExtractedText outText) |
java.lang.CharSequence |
getContentText()
Get the content entered in the text field, including hidden text when ellipsized
|
int |
getMaxViewSpanWidth() |
java.util.List<T> |
getObjects()
Get the list of Tokens
|
protected java.util.List<java.io.Serializable> |
getSerializableObjects() |
java.lang.CharSequence |
getTextForAccessibility()
Correctly build accessibility string for token contents
This seems to be a hidden API, but there doesn't seem to be another reasonable way
|
protected abstract android.view.View |
getViewForObject(T object)
A token view for the object
|
void |
invalidate() |
boolean |
isTokenRemovable(T token)
Override if you want to prevent a token from being removed.
|
protected float |
maxTextWidth() |
android.view.inputmethod.InputConnection |
onCreateInputConnection(android.view.inputmethod.EditorInfo outAttrs) |
boolean |
onEditorAction(android.widget.TextView view,
int action,
android.view.KeyEvent keyEvent) |
void |
onFocusChanged(boolean hasFocus,
int direction,
android.graphics.Rect previous) |
void |
onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event) |
boolean |
onKeyDown(int keyCode,
android.view.KeyEvent event) |
boolean |
onKeyUp(int keyCode,
android.view.KeyEvent event) |
protected void |
onLayout(boolean changed,
int left,
int top,
int right,
int bottom) |
void |
onRestoreInstanceState(android.os.Parcelable state) |
android.os.Parcelable |
onSaveInstanceState() |
protected void |
onSelectionChanged(int selStart,
int selEnd) |
protected void |
onTextChanged(java.lang.CharSequence text,
int start,
int lengthBefore,
int lengthAfter) |
boolean |
onTouchEvent(android.view.MotionEvent event) |
void |
performBestGuess(boolean guess)
Set whether we try to guess an entry from the autocomplete spinner or just use the
defaultObject implementation for inline token completion.
|
void |
performCollapse(boolean hasFocus)
Collapse the view by removing all the tokens not on the first line.
|
void |
performCompletion() |
protected void |
performFiltering(java.lang.CharSequence text,
int keyCode) |
void |
preventFreeFormText(boolean prevent)
If set to true, the only content in this view will be the tokens and the current completion
text.
|
protected void |
removeListeners()
Remove the TextChangedListeners
|
void |
removeObjectAsync(T object)
Remove an object from the token list.
|
void |
removeObjectSync(T object)
Remove an object from the token list.
|
protected void |
replaceText(java.lang.CharSequence ignore) |
void |
setPrefix(java.lang.CharSequence p)
A String of text that is shown before all the tokens inside the EditText
(Think "To: " in an email address field.
|
void |
setPrefix(java.lang.CharSequence prefix,
int color)
You can get a color integer either using
androidx.core.content.ContextCompat#getColor(android.content.Context, int)
or with Color.parseColor(String). |
void |
setTokenClickStyle(TokenCompleteTextView.TokenClickStyle cStyle)
Set the action to be taken when a Token is clicked
|
void |
setTokenizer(Tokenizer t) |
void |
setTokenLimit(int tokenLimit)
Set a number of tokens limit.
|
void |
setTokenListener(TokenCompleteTextView.TokenListener<T> l)
Set the listener that will be notified of changes in the Token list
|
boolean |
shouldIgnoreToken(T token)
Override if you want to prevent a token from being added.
|
protected java.lang.CharSequence |
tokenToString(T token)
Override if you need custom logic to provide a sting representation of a token
|
public static final java.lang.String TAG
public TokenCompleteTextView(android.content.Context context)
public TokenCompleteTextView(android.content.Context context,
android.util.AttributeSet attrs)
public TokenCompleteTextView(android.content.Context context,
android.util.AttributeSet attrs,
int defStyle)
protected void addListeners()
protected void removeListeners()
protected void performFiltering(java.lang.CharSequence text,
int keyCode)
public void setTokenizer(Tokenizer t)
public void setTokenClickStyle(TokenCompleteTextView.TokenClickStyle cStyle)
cStyle - The TokenClickStylepublic void setTokenListener(TokenCompleteTextView.TokenListener<T> l)
l - The TokenListenerpublic boolean shouldIgnoreToken(T token)
token - the token to checkpublic boolean isTokenRemovable(T token)
token - the token to checkpublic void setPrefix(java.lang.CharSequence p)
p - String with the hintpublic void setPrefix(java.lang.CharSequence prefix,
int color)
You can get a color integer either using
androidx.core.content.ContextCompat#getColor(android.content.Context, int)
or with Color.parseColor(String).
Color.parseColor(String)
accepts these formats (copied from android.graphics.Color):
You can use: '#RRGGBB', '#AARRGGBB'
or one of the following names: 'red', 'blue', 'green', 'black', 'white',
'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey',
'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy',
'olive', 'purple', 'silver', 'teal'.
prefix - prefixcolor - A single color value in the form 0xAARRGGBB.public java.util.List<T> getObjects()
public java.lang.CharSequence getContentText()
public void performBestGuess(boolean guess)
guess - true to enable guessingpublic void preventFreeFormText(boolean prevent)
prevent - true to prevent non-token text. Defaults to true.public void allowCollapse(boolean allowCollapse)
allowCollapse - true if it should collapsepublic void setTokenLimit(int tokenLimit)
tokenLimit - The number of tokens permitted. -1 value disables limit.protected abstract android.view.View getViewForObject(T object)
object - the object selected by the user from the listprotected abstract T defaultObject(java.lang.String completionText)
completionText - the current text we are completing againstpublic java.lang.CharSequence getTextForAccessibility()
public void clearCompletionText()
public void onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
protected java.lang.CharSequence tokenToString(T token)
token - the token to convertObject.toString()protected java.lang.String currentCompletionText()
protected float maxTextWidth()
public int getMaxViewSpanWidth()
getMaxViewSpanWidth in interface ViewSpan.Layoutpublic void invalidate()
public boolean enoughToFilter()
public void performCompletion()
public android.view.inputmethod.InputConnection onCreateInputConnection(@NonNull
android.view.inputmethod.EditorInfo outAttrs)
public boolean onKeyUp(int keyCode,
@NonNull
android.view.KeyEvent event)
public boolean onKeyDown(int keyCode,
@NonNull
android.view.KeyEvent event)
public boolean onEditorAction(android.widget.TextView view,
int action,
android.view.KeyEvent keyEvent)
onEditorAction in interface android.widget.TextView.OnEditorActionListenerpublic boolean onTouchEvent(@NonNull
android.view.MotionEvent event)
protected void onSelectionChanged(int selStart,
int selEnd)
protected void onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
public void performCollapse(boolean hasFocus)
hasFocus - boolean indicating whether we have the focus or not.public void onFocusChanged(boolean hasFocus,
int direction,
android.graphics.Rect previous)
protected java.lang.CharSequence convertSelectionToString(java.lang.Object object)
protected TokenCompleteTextView.TokenImageSpan buildSpanForObject(T obj)
protected void replaceText(java.lang.CharSequence ignore)
public boolean extractText(@NonNull
android.view.inputmethod.ExtractedTextRequest request,
@NonNull
android.view.inputmethod.ExtractedText outText)
@UiThread public void addObjectSync(T object)
object - the object to add to the displayed tokenspublic void addObjectAsync(T object)
object - the object to add to the displayed tokens@UiThread public void removeObjectSync(T object)
Object.equals(Object) to find objects. May only
be called from the main threadobject - object to remove, may be null or not in the viewpublic void removeObjectAsync(T object)
Object.equals(Object) to find objects. Object
will be added on the main threadobject - object to remove, may be null or not in the viewpublic void clearAsync()
protected java.util.List<java.io.Serializable> getSerializableObjects()
protected java.util.List<T> convertSerializableObjectsToTypedObjects(java.util.List s)
public android.os.Parcelable onSaveInstanceState()
public void onRestoreInstanceState(android.os.Parcelable state)
public boolean canDeleteSelection(int beforeLength)
beforeLength - the number of characters before the current selection end to checkprotected void onTextChanged(java.lang.CharSequence text,
int start,
int lengthBefore,
int lengthAfter)