Patch for the third_party chips library to fix functionality with phone numbers.

Currently the popup from touching a chip uses the Rfc822Tokenizer to extract email addresses from the destination for the SingleRecipient adapter type. This behavior doesn't work for phone numbers, as anything within parentheses (ie. area codes) get removed from the destination.

Change-Id: I333c1a55b5475aa3559bf721af402ae0db024342
diff --git a/src/com/android/ex/chips/DropdownChipLayouter.java b/src/com/android/ex/chips/DropdownChipLayouter.java
index 93e433a..6ca3d0e 100644
--- a/src/com/android/ex/chips/DropdownChipLayouter.java
+++ b/src/com/android/ex/chips/DropdownChipLayouter.java
@@ -165,7 +165,9 @@
                 }
                 break;
             case SINGLE_RECIPIENT:
-                destination = Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress();
+                if (!PhoneUtil.isPhoneNumber(entry.getDestination())) {
+                    destination = Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress();
+                }
                 destinationType = null;
         }
 
diff --git a/src/com/android/ex/chips/PhoneUtil.java b/src/com/android/ex/chips/PhoneUtil.java
new file mode 100644
index 0000000..512d275
--- /dev/null
+++ b/src/com/android/ex/chips/PhoneUtil.java
@@ -0,0 +1,52 @@
+/*
+
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ex.chips;
+
+import android.text.TextUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A utility class for chips using phone numbers.
+ */
+public class PhoneUtil {
+
+    // This pattern comes from android.util.Patterns. It has been tweaked to handle a "1" before
+    // parens, so numbers such as "1 (425) 222-2342" match.
+    private static final Pattern PHONE_PATTERN
+            = Pattern.compile(                                  // sdd = space, dot, or dash
+                    "(\\+[0-9]+[\\- \\.]*)?"                    // +<digits><sdd>*
+                    + "(1?[ ]*\\([0-9]+\\)[\\- \\.]*)?"         // 1(<digits>)<sdd>*
+                    + "([0-9][0-9\\- \\.][0-9\\- \\.]+[0-9])"); // <digit><digit|sdd>+<digit>
+
+    /**
+     * Returns true if the string is a phone number.
+     */
+    public static boolean isPhoneNumber(String number) {
+        // TODO: replace this function with libphonenumber's isPossibleNumber (see
+        // PhoneNumberUtil). One complication is that it requires the sender's region which
+        // comes from the CurrentCountryIso. For now, let's just do this simple match.
+        if (TextUtils.isEmpty(number)) {
+            return false;
+        }
+
+        Matcher match = PHONE_PATTERN.matcher(number);
+        return match.matches();
+    }
+}
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index d8d029b..d3a8e16 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -122,14 +122,6 @@
     private static final String SEPARATOR = String.valueOf(COMMIT_CHAR_COMMA)
             + String.valueOf(COMMIT_CHAR_SPACE);
 
-    // This pattern comes from android.util.Patterns. It has been tweaked to handle a "1" before
-    // parens, so numbers such as "1 (425) 222-2342" match.
-    private static final Pattern PHONE_PATTERN
-            = Pattern.compile(                                  // sdd = space, dot, or dash
-            "(\\+[0-9]+[\\- \\.]*)?"                    // +<digits><sdd>*
-                    + "(1?[ ]*\\([0-9]+\\)[\\- \\.]*)?"         // 1(<digits>)<sdd>*
-                    + "([0-9][0-9\\- \\.][0-9\\- \\.]+[0-9])"); // <digit><digit|sdd>+<digit>
-
     private static final int DISMISS = "dismiss".hashCode();
     private static final long DISMISS_DELAY = 300;
 
@@ -1286,24 +1278,12 @@
         }
     }
 
-    private static boolean isPhoneNumber(String number) {
-        // TODO: replace this function with libphonenumber's isPossibleNumber (see
-        // PhoneNumberUtil). One complication is that it requires the sender's region which
-        // comes from the CurrentCountryIso. For now, let's just do this simple match.
-        if (TextUtils.isEmpty(number)) {
-            return false;
-        }
-
-        Matcher match = PHONE_PATTERN.matcher(number);
-        return match.matches();
-    }
-
     // VisibleForTesting
     RecipientEntry createTokenizedEntry(final String token) {
         if (TextUtils.isEmpty(token)) {
             return null;
         }
-        if (isPhoneQuery() && isPhoneNumber(token)) {
+        if (isPhoneQuery() && PhoneUtil.isPhoneNumber(token)) {
             return RecipientEntry.constructFakePhoneEntry(token, true);
         }
         Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token);
@@ -1891,7 +1871,7 @@
             display = null;
         }
         String trimmedDisplayText;
-        if (isPhoneQuery() && isPhoneNumber(address)) {
+        if (isPhoneQuery() && PhoneUtil.isPhoneNumber(address)) {
             trimmedDisplayText = address.trim();
         } else {
             if (address != null) {