diff options
author | Alon Albert <aalbert@google.com> | 2013-07-14 15:32:49 +0300 |
---|---|---|
committer | Alon Albert <aalbert@google.com> | 2013-07-21 11:25:43 +0300 |
commit | dc660babb68131f3fd9c62c1c1e640869d21bd92 (patch) | |
tree | 4daac3a0be156827f772fc9a5c8ad91e41f1059b | |
parent | aac694088bdbb11416d2ee1d1e9091cab272592f (diff) | |
download | android_frameworks_ex-dc660babb68131f3fd9c62c1c1e640869d21bd92.tar.gz android_frameworks_ex-dc660babb68131f3fd9c62c1c1e640869d21bd92.tar.bz2 android_frameworks_ex-dc660babb68131f3fd9c62c1c1e640869d21bd92.zip |
Support an External Dictionary of Contacts
Allow support for an external custom source of contacts. By making
some classes & methods protected rather than private, it's possible
to allow for a derived class to extend the Chips behavior to load
contacts from an arbitrary source.
Most of the changes here are just access modifier changes but there's
one more substantial change:
Intruduced BaseRecipientAdapter#getMatchingRecipients() which matches
generated recipients with proper chips recipients from the external
sources.
Ideally RecipientAlternatesAdapter#getMatchingRecipients() should reside
in the adaper too but the goal of this CL was to do this minimal
modifications.
There's also a small change that beileve was a bug in IndividualReplacementTask:
The matchesFound() callback gets a list of matches found. It then iterates all
the original recipients and looks for those that have matches and replaces them.
So far so good but, if the original recipient doesn't have a match and is not a
phone number, the old code still replaces it with itself when it can simply skip
it I think.
Change-Id: I24e89f93ec15154ed8912664cd061fa2b5b18bd8
3 files changed, 74 insertions, 33 deletions
diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java index 71b610e..8af8d2c 100644 --- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java +++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java @@ -140,7 +140,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter } /** Used to temporarily hold results in Cursor objects. */ - private static class TemporaryEntry { + protected static class TemporaryEntry { public final String displayName; public final String destination; public final int destinationType; @@ -150,6 +150,25 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter public final String thumbnailUriString; public final int displayNameSource; + public TemporaryEntry( + String displayName, + String destination, + int destinationType, + String destinationLabel, + long contactId, + long dataId, + String thumbnailUriString, + int displayNameSource) { + this.displayName = displayName; + this.destination = destination; + this.destinationType = destinationType; + this.destinationLabel = destinationLabel; + this.contactId = contactId; + this.dataId = dataId; + this.thumbnailUriString = thumbnailUriString; + this.displayNameSource = displayNameSource; + } + public TemporaryEntry(Cursor cursor) { this.displayName = cursor.getString(Queries.Query.NAME); this.destination = cursor.getString(Queries.Query.DESTINATION); @@ -322,7 +341,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter /** * An asynchronous filter that performs search in a particular directory. */ - private final class DirectoryFilter extends Filter { + protected class DirectoryFilter extends Filter { private final DirectorySearchParams mParams; private int mLimit; @@ -536,6 +555,10 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter } } + public Context getContext() { + return mContext; + } + public int getQueryType() { return mQueryType; } @@ -554,6 +577,16 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter return new DefaultFilter(); } + /** + * An extesion to {@link RecipientAlternatesAdapter#getMatchingRecipients} that allows + * additional sources of contacts to be considered as matching recipients. + * @param addresses A set of addresses to be matched + * @return A list of matches or null if none found + */ + public Map<String, RecipientEntry> getMatchingRecipients(Set<String> addresses) { + return null; + } + public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account) { final PackageManager packageManager = context.getPackageManager(); @@ -612,7 +645,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter * Starts search in other directories using {@link Filter}. Results will be handled in * {@link DirectoryFilter}. */ - private void startSearchOtherDirectories( + protected void startSearchOtherDirectories( CharSequence constraint, List<DirectorySearchParams> paramsList, int limit) { final int count = paramsList.size(); // Note: skipping the default partition (index 0), which has already been loaded @@ -729,7 +762,7 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter mTempEntries = null; } - private List<RecipientEntry> getEntries() { + protected List<RecipientEntry> getEntries() { return mTempEntries != null ? mTempEntries : mEntries; } diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java index ef34379..f64c166 100644 --- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java +++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java @@ -73,9 +73,9 @@ public class RecipientAlternatesAdapter extends CursorAdapter { public void matchesNotFound(Set<String> unfoundAddresses); } - public static void getMatchingRecipients(Context context, ArrayList<String> inAddresses, - Account account, RecipientMatchCallback callback) { - getMatchingRecipients(context, inAddresses, QUERY_TYPE_EMAIL, account, callback); + public static void getMatchingRecipients(Context context, BaseRecipientAdapter adapter, + ArrayList<String> inAddresses, Account account, RecipientMatchCallback callback) { + getMatchingRecipients(context, adapter, inAddresses, QUERY_TYPE_EMAIL, account, callback); } /** @@ -88,8 +88,9 @@ public class RecipientAlternatesAdapter extends CursorAdapter { * @param callback RecipientMatchCallback called when a match or matches are found. * @return HashMap<String,RecipientEntry> */ - public static void getMatchingRecipients(Context context, ArrayList<String> inAddresses, - int addressType, Account account, RecipientMatchCallback callback) { + 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; @@ -197,6 +198,19 @@ public class RecipientAlternatesAdapter extends CursorAdapter { } } + // If no matches found in contact provider or the directories, try the extension + // matcher. + // todo (aalbert): This whole method needs to be in the adapter? + if (adapter != null) { + final Map<String, RecipientEntry> entries = + adapter.getMatchingRecipients(matchesNotFound); + if (entries != null && entries.size() > 0) { + callback.matchesFound(entries); + for (final String address : entries.keySet()) { + matchesNotFound.remove(address); + } + } + } callback.matchesNotFound(matchesNotFound); } diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index aaf4a05..9721ed6 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -17,18 +17,6 @@ package com.android.ex.chips; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import android.app.Dialog; import android.content.ClipData; import android.content.ClipDescription; @@ -99,6 +87,18 @@ import com.android.ex.chips.recipientchip.DrawableRecipientChip; import com.android.ex.chips.recipientchip.InvisibleRecipientChip; import com.android.ex.chips.recipientchip.VisibleRecipientChip; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * RecipientEditTextView is an auto complete text view for use with applications * that use the new Chips UI for addressing a message to recipients. @@ -2497,7 +2497,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements Log.wtf(TAG, "My assumption that this was fixed is wrong."); return null; } - RecipientAlternatesAdapter.getMatchingRecipients(getContext(), addresses, + RecipientAlternatesAdapter.getMatchingRecipients(getContext(), adapter, addresses, adapter.getAccount(), new RecipientMatchCallback() { @Override public void matchesFound(Map<String, RecipientEntry> entries) { @@ -2624,7 +2624,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements addresses.add(createAddressText(chip.getEntry())); } } - RecipientAlternatesAdapter.getMatchingRecipients(getContext(), addresses, + final BaseRecipientAdapter adapter = (BaseRecipientAdapter) getAdapter(); + RecipientAlternatesAdapter.getMatchingRecipients(getContext(), adapter, addresses, ((BaseRecipientAdapter) getAdapter()).getAccount(), new RecipientMatchCallback() { @@ -2635,21 +2636,14 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements .getContactId()) && getSpannable().getSpanStart(temp) != -1) { // Replace this. - RecipientEntry entry = createValidatedEntry(entries + final RecipientEntry entry = createValidatedEntry(entries .get(tokenizeAddress(temp.getEntry().getDestination()) .toLowerCase())); - // If we don't have a validated contact - // match, just use the - // entry as it existed before. - if (entry == null && !isPhoneQuery()) { - entry = temp.getEntry(); - } - final RecipientEntry tempEntry = entry; - if (tempEntry != null) { + if (entry != null) { mHandler.post(new Runnable() { @Override public void run() { - replaceChip(temp, tempEntry); + replaceChip(temp, entry); } }); } |