public static void getMatchingRecipientsFromDirectoryQueries( Context context, Map<String, RecipientEntry> recipientEntries, Set<String> addresses, Account account, Set<String> matchesNotFound, RecipientMatchCallback callback) { getMatchingRecipientsFromDirectoryQueries( context, recipientEntries, addresses, account, matchesNotFound, Queries.EMAIL, callback); }
/** * Get a HashMap of address to RecipientEntry that contains all contact information for a contact * with the provided address, if one exists. This may block the UI, so run it in an async task. * * @param context Context. * @param inAddresses Array of addresses on which to perform the lookup. * @param callback RecipientMatchCallback called when a match or matches are found. */ public static void getMatchingRecipients( Context context, BaseRecipientAdapter adapter, ArrayList<String> inAddresses, int addressType, Account account, RecipientMatchCallback callback) { Queries.Query query; if (addressType == QUERY_TYPE_EMAIL) { query = Queries.EMAIL; } else { query = Queries.PHONE; } int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size()); HashSet<String> addresses = new HashSet<String>(); StringBuilder bindString = new StringBuilder(); // Create the "?" string and set up arguments. for (int i = 0; i < addressesSize; i++) { Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase()); addresses.add(tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i)); bindString.append("?"); if (i < addressesSize - 1) { bindString.append(","); } } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Doing reverse lookup for " + addresses.toString()); } String[] addressArray = new String[addresses.size()]; addresses.toArray(addressArray); HashMap<String, RecipientEntry> recipientEntries = null; Cursor c = null; try { c = context .getContentResolver() .query( query.getContentUri(), query.getProjection(), query.getProjection()[Queries.Query.DESTINATION] + " IN (" + bindString.toString() + ")", addressArray, null); recipientEntries = processContactEntries(c, null /* directoryId */); callback.matchesFound(recipientEntries); } finally { if (c != null) { c.close(); } } // final Set<String> matchesNotFound = new HashSet<String>(); getMatchingRecipientsFromDirectoryQueries( context, recipientEntries, addresses, account, matchesNotFound, query, callback); getMatchingRecipientsFromExtensionMatcher(adapter, matchesNotFound, callback); }