Null check; back behavior

Since its possible there was no chip formed for an address, it is
possible there is no address in some part of the inAddresses array, so
build it up as an arraylist so we don't have null spots.

Fixes b/6555471 NPE in com.android.ex.chips.RecipientAlternatesAdapter.getMatchingRecipients

Fixes b/6556107 when contact chip is selected back button should dismiss the popup and unselct the chip
Change-Id: If74b13ccc5f51aafc3638817b5fbef54cd57548c
diff --git a/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/src/com/android/ex/chips/RecipientAlternatesAdapter.java
index e3ef6cd..553890e 100644
--- a/src/com/android/ex/chips/RecipientAlternatesAdapter.java
+++ b/src/com/android/ex/chips/RecipientAlternatesAdapter.java
@@ -31,6 +31,7 @@
 
 import com.android.ex.chips.Queries.Query;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 
@@ -55,7 +56,7 @@
     private Query mQuery;
 
     public static HashMap<String, RecipientEntry> getMatchingRecipients(Context context,
-            String[] inAddresses) {
+            ArrayList<String> inAddresses) {
         return getMatchingRecipients(context, inAddresses, QUERY_TYPE_EMAIL);
     }
 
@@ -69,20 +70,20 @@
      * @return HashMap<String,RecipientEntry>
      */
     public static HashMap<String, RecipientEntry> getMatchingRecipients(Context context,
-            String[] inAddresses, int addressType) {
+            ArrayList<String> inAddresses, int addressType) {
         Queries.Query query;
         if (addressType == QUERY_TYPE_EMAIL) {
             query = Queries.EMAIL;
         } else {
             query = Queries.PHONE;
         }
-        int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.length);
+        int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
         String[] addresses = new String[addressesSize];
         StringBuilder bindString = new StringBuilder();
         // Create the "?" string and set up arguments.
         for (int i = 0; i < addressesSize; i++) {
-            Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses[i].toLowerCase());
-            addresses[i] = (tokens.length > 0 ? tokens[0].getAddress() : inAddresses[i]);
+            Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
+            addresses[i] = (tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
             bindString.append("?");
             if (i < addressesSize - 1) {
                 bindString.append(",");