public class SpanChipTokenizer<C extends Chip> extends java.lang.Object implements ChipTokenizer
ChipTokenizer.
This implementation does the following:
ChipSpan containing the same text, once the token terminatesapplyConfiguration(Editable, ChipConfiguration) to configure any ChipSpans that get createdterminateToken(CharSequence, Object)):
----------------------------------------------------------- | SpannableString | | ---------------------------------------------------- | | | ChipSpan | | | | | | | | space separator text separator space | | | | | | | ---------------------------------------------------- | -----------------------------------------------------------
ChipSpan| Modifier and Type | Field and Description |
|---|---|
static char |
AUTOCORRECT_SEPARATOR |
static char |
CHIP_SPAN_SEPARATOR
The character used to separate chips internally is the US (Unit Separator) ASCII control character.
|
| Constructor and Description |
|---|
SpanChipTokenizer(android.content.Context context,
ChipCreator<C> chipCreator,
java.lang.Class<C> chipClass) |
| Modifier and Type | Method and Description |
|---|---|
void |
applyConfiguration(android.text.Editable text,
ChipConfiguration chipConfiguration)
Configures this ChipTokenizer to produce chips with the provided attributes.
|
void |
deleteChip(Chip chip,
android.text.Editable text)
Removes a chip and any text it encompasses from
text. |
void |
deleteChipAndPadding(Chip chip,
android.text.Editable text)
Removes a chip, any text it encompasses AND any padding text (such as spaces) that may have been inserted when the chip was created in
ChipTokenizer.terminateToken(CharSequence, Object) or after. |
C[] |
findAllChips(int start,
int end,
android.text.Spanned text)
Searches through
text for any chips |
java.util.List<android.util.Pair<java.lang.Integer,java.lang.Integer>> |
findAllTokens(java.lang.CharSequence text)
Searches through
text for any tokens. |
int |
findChipEnd(Chip chip,
android.text.Spanned text)
Finds the index of the character after the last character in
text that is a part of chip |
int |
findChipStart(Chip chip,
android.text.Spanned text)
Finds the index of the first character in
text that is a part of chip |
int |
findTokenEnd(java.lang.CharSequence text,
int cursor)
Returns the end of the token (minus trailing punctuation)
that begins at offset
cursor within text. |
int |
findTokenStart(java.lang.CharSequence text,
int cursor)
Returns the start of the token that ends at offset
cursor within text. |
void |
revertChipToToken(Chip chip,
android.text.Editable text)
Effectively does the opposite of
ChipTokenizer.terminateToken(CharSequence, Object) by reverting the provided chip back into a token. |
void |
terminateAllTokens(android.text.Editable text)
Terminates (converts from token into chip) all unterminated tokens in the provided text.
|
java.lang.CharSequence |
terminateToken(java.lang.CharSequence text,
java.lang.Object data)
Returns
text, modified, if necessary, to ensure that
it ends with a token terminator (for example a space or comma). |
public static final char CHIP_SPAN_SEPARATOR
public static final char AUTOCORRECT_SEPARATOR
public SpanChipTokenizer(android.content.Context context,
ChipCreator<C> chipCreator,
java.lang.Class<C> chipClass)
public void applyConfiguration(android.text.Editable text,
ChipConfiguration chipConfiguration)
ChipTokenizer-1 or null may be
passed to indicate that the attribute may be ignored.
This will also apply the provided ChipConfiguration to any existing chips in the provided text.
applyConfiguration in interface ChipTokenizertext - the text in which to search for existing chips to apply the configuration tochipConfiguration - a ChipConfiguration containing customizations for the chips produced by this classpublic int findTokenStart(java.lang.CharSequence text,
int cursor)
ChipTokenizercursor within text.findTokenStart in interface ChipTokenizerpublic int findTokenEnd(java.lang.CharSequence text,
int cursor)
ChipTokenizercursor within text.findTokenEnd in interface ChipTokenizerpublic java.util.List<android.util.Pair<java.lang.Integer,java.lang.Integer>> findAllTokens(java.lang.CharSequence text)
ChipTokenizertext for any tokens.findAllTokens in interface ChipTokenizertext - the text in which to search for un-terminated tokensPairs of the form (startIndex, endIndex) containing the locations of all
unterminated tokenspublic java.lang.CharSequence terminateToken(java.lang.CharSequence text,
java.lang.Object data)
ChipTokenizertext, modified, if necessary, to ensure that
it ends with a token terminator (for example a space or comma).terminateToken in interface ChipTokenizerpublic void terminateAllTokens(android.text.Editable text)
ChipTokenizerterminateAllTokens in interface ChipTokenizertext - the text in which to terminate all tokenspublic int findChipStart(Chip chip, android.text.Spanned text)
ChipTokenizertext that is a part of chipfindChipStart in interface ChipTokenizerchip - the chip whose start should be foundtext - the text in which to search for the start of chippublic int findChipEnd(Chip chip, android.text.Spanned text)
ChipTokenizertext that is a part of chipfindChipEnd in interface ChipTokenizerchip - the chip whose end should be foundtext - the text in which to search for the end of chippublic C[] findAllChips(int start, int end, android.text.Spanned text)
ChipTokenizertext for any chipsfindAllChips in interface ChipTokenizerstart - index to start looking for terminated tokens (inclusive)end - index to end looking for terminated tokens (exclusive)text - the text in which to search for terminated tokensChip interface to represent the terminated tokenspublic void revertChipToToken(Chip chip, android.text.Editable text)
ChipTokenizerChipTokenizer.terminateToken(CharSequence, Object) by reverting the provided chip back into a token.
This method CAN alter the provided text.revertChipToToken in interface ChipTokenizerchip - the chip to revert into a tokentext - the text in which the chip residespublic void deleteChip(Chip chip, android.text.Editable text)
ChipTokenizertext. This method CAN alter the provided text.deleteChip in interface ChipTokenizerchip - the chip to removetext - the text to remove the chip frompublic void deleteChipAndPadding(Chip chip, android.text.Editable text)
ChipTokenizerChipTokenizer.terminateToken(CharSequence, Object) or after. This method CAN alter the provided text.deleteChipAndPadding in interface ChipTokenizerchip - the chip to removetext - the text to remove the chip and padding from