Show contact addresses while chips load

When the "more" chip (eg +3) is expanded, we need to display the
addresses as text while we go searching for the real contacts.

Bug: 8099861
Change-Id: I5e9631f258b8d273777c65f3f5460f1aa71f10b1
diff --git a/chips/src/com/android/ex/chips/InvisibleRecipientChip.java b/chips/src/com/android/ex/chips/InvisibleRecipientChip.java
index 46fe19a..beeb499 100644
--- a/chips/src/com/android/ex/chips/InvisibleRecipientChip.java
+++ b/chips/src/com/android/ex/chips/InvisibleRecipientChip.java
@@ -42,6 +42,9 @@
 
     private CharSequence mOriginalText;
 
+    /** <code>true</code> to display the original text, <code>false</code> to display nothing */
+    private boolean mDisplayOriginalText = false;
+
     public InvisibleRecipientChip(RecipientEntry entry, int offset) {
         super();
         mDisplay = entry.getDisplayName();
@@ -112,15 +115,28 @@
         return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination();
     }
 
-    @Override
-    public void draw(Canvas arg0, CharSequence arg1, int arg2, int arg3, float arg4, int arg5,
-            int arg6, int arg7, Paint arg8) {
-        // Do nothing.
+    public void setDisplayOriginalText(final boolean displayOriginalText) {
+        mDisplayOriginalText = displayOriginalText;
     }
 
     @Override
-    public int getSize(Paint arg0, CharSequence arg1, int arg2, int arg3, FontMetricsInt arg4) {
-        return 0;
+    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y,
+            int bottom, Paint paint) {
+        if (mDisplayOriginalText) {
+            canvas.drawText(text, start, end, x, y, paint);
+        } else {
+            // Do nothing.
+        }
+    }
+
+    @Override
+    public int getSize(
+            Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
+        if (mDisplayOriginalText) {
+            return (int) paint.measureText(text, start, end);
+        } else {
+            return 0;
+        }
     }
 
     @Override
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index c051c1b..462d456 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -1865,6 +1865,13 @@
                     end = chipEnd = Math.min(editable.length(), chipStart + token.length());
                     // Only set the span if we found a matching token.
                     if (chipStart != -1) {
+                        if (chip instanceof InvisibleRecipientChip) {
+                            /*
+                             * We want the original text to be displayed until we can replace it
+                             * with a real chip
+                             */
+                            ((InvisibleRecipientChip) chip).setDisplayOriginalText(true);
+                        }
                         editable.setSpan(chip, chipStart, chipEnd,
                                 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                     }