When recipients are appended, take them as is without ANY parsing of tokens.
Change-Id: I7ecc16cc032e7a6f4809ba1a323f7e445b8f74fd
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index a65ac57..e11d419 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -100,6 +100,8 @@
private ArrayList<RecipientChip> mRemovedSpans;
+ private ArrayList<String> mPendingChips = new ArrayList<String>();
+
private float mChipHeight;
private float mChipFontSize;
@@ -223,6 +225,7 @@
if (seperatorPos != 0 && !TextUtils.isEmpty(displayString)
&& TextUtils.getTrimmedLength(displayString) > 0) {
mPendingChipsCount++;
+ mPendingChips.add((String)text);
}
}
}
@@ -234,6 +237,7 @@
// Reset any pending chips as they would have been handled
// when the field lost focus.
mPendingChipsCount = 0;
+ mPendingChips.clear();
mHandler.post(mAddTextWatcher);
} else {
expand();
@@ -305,7 +309,7 @@
* Get the background drawable for a RecipientChip.
*/
public Drawable getChipBackground(RecipientEntry contact) {
- return mValidator != null && mValidator.isValid(contact.getDestination()) ?
+ return (mValidator != null && mValidator.isValid(contact.getDestination())) ?
mChipBackground : mInvalidChipBackground;
}
@@ -461,30 +465,24 @@
if (mPendingChipsCount > 0) {
Editable editable = getText();
// Tokenize!
- int startingPos = 0;
- while (startingPos < editable.length() && mPendingChipsCount > 0) {
- int tokenEnd = mTokenizer.findTokenEnd(editable, startingPos);
- int tokenStart = mTokenizer.findTokenStart(editable, tokenEnd);
- if (findChip(tokenStart) == null) {
- // Always include seperators with the token to the
- // left.
- if (tokenEnd < editable.length() - 1
- && editable.charAt(tokenEnd) == COMMIT_CHAR_COMMA) {
- tokenEnd++;
- }
- startingPos = tokenEnd;
- String token = editable.toString().substring(tokenStart, tokenEnd);
- int seperatorPos = token.indexOf(COMMIT_CHAR_COMMA);
- if (seperatorPos != -1) {
- token = token.substring(0, seperatorPos);
- }
- editable.replace(tokenStart, tokenEnd, createChip(RecipientEntry
- .constructFakeEntry(token), false));
+ for (int i = 0; i < mPendingChips.size(); i++) {
+ String current = mPendingChips.get(i);
+ int tokenStart = editable.toString().indexOf(current);
+ int tokenEnd = tokenStart + current.length();
+ // Always include seperators with the token to the
+ // left.
+ if (tokenEnd < editable.length() - 1
+ && editable.charAt(tokenEnd) == COMMIT_CHAR_COMMA) {
+ tokenEnd++;
}
- mPendingChipsCount--;
+ String token = editable.toString().substring(tokenStart, tokenEnd);
+ editable.replace(tokenStart, tokenEnd, createChip(RecipientEntry
+ .constructFakeEntry(token), false));
}
+ mPendingChipsCount--;
}
mPendingChipsCount = 0;
+ mPendingChips.clear();
mHandler.post(mAddTextWatcher);
}
}