summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chips/src/com/android/ex/chips/BaseRecipientAdapter.java41
-rw-r--r--chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java24
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java42
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);
}
});
}