Reduce time until first revision of a chip is drawn.
Means less time showing plain text.
replace call is expensive.
Change-Id: I1be571af78497c2dfff724b612d60ededc98ff36
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index b460a4d..4568b2c 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -897,8 +897,6 @@
RecipientEntry entry = createTokenizedEntry(token);
if (entry != null) {
String destText = createAddressText(entry);
- // Always leave a blank space at the end of a chip.
- int textLength = destText.length() - 1;
SpannableString chipText = new SpannableString(destText);
int end = getSelectionEnd();
int start = mTokenizer != null ? mTokenizer.findTokenStart(getText(), end) : 0;
@@ -913,12 +911,11 @@
TextUtils.isEmpty(entry.getDisplayName())
|| TextUtils.equals(entry.getDisplayName(),
entry.getDestination()));
- chipText.setSpan(chip, 0, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
}
- editable.replace(tokenStart, tokenEnd, chipText);
+ editable.setSpan(chip, tokenStart, tokenEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Add this chip to the list of entries "to replace"
if (chip != null) {
if (mTemporaryRecipients == null) {
@@ -2391,11 +2388,11 @@
end = oldText.getSpanEnd(chip);
oldText.removeSpan(chip);
RecipientChip replacement = replacements.get(i);
- // Trim any whitespace, as we will already have
- // it added if these are replacement chips.
+ // Make sure we always have just 1 space at the
+ // end to separate this chip from the next chip.
SpannableString displayText = new SpannableString(
- createAddressText(replacement.getEntry()).trim());
- displayText.setSpan(replacement, 0, displayText.length(),
+ createAddressText(replacement.getEntry()).trim() + " ");
+ displayText.setSpan(replacement, 0, displayText.length()-1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// Replace the old text we found with with the new display text,
// which now may also contain the display name of the recipient.