summaryrefslogtreecommitdiffstats
path: root/chips
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-02-26 06:15:32 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2013-02-26 06:15:32 +0000
commit38c3a78aa9e4525353d65540b38c3221148f0327 (patch)
tree56fbabae9e7db8d5e7e262a7345dbfbc803c65ac /chips
parent8189b1c116661428247585c56c8b16d98509becd (diff)
parent8c3867660cd9e2ebb34e5efc62aecdad76a65c6d (diff)
downloadandroid_frameworks_ex-38c3a78aa9e4525353d65540b38c3221148f0327.tar.gz
android_frameworks_ex-38c3a78aa9e4525353d65540b38c3221148f0327.tar.bz2
android_frameworks_ex-38c3a78aa9e4525353d65540b38c3221148f0327.zip
am 8c386766: Use the best contact result for chips
* commit '8c3867660cd9e2ebb34e5efc62aecdad76a65c6d': Use the best contact result for chips
Diffstat (limited to 'chips')
-rw-r--r--chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java70
1 files changed, 68 insertions, 2 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
index 49e2d5c..1aead22 100644
--- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
+++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
@@ -23,6 +23,7 @@ import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.ContactsContract;
+import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.Log;
@@ -191,7 +192,8 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
if (c != null && c.moveToFirst()) {
do {
String address = c.getString(Queries.Query.DESTINATION);
- recipientEntries.put(address, RecipientEntry.constructTopLevelEntry(
+
+ final RecipientEntry newRecipientEntry = RecipientEntry.constructTopLevelEntry(
c.getString(Queries.Query.NAME),
c.getInt(Queries.Query.DISPLAY_NAME_SOURCE),
c.getString(Queries.Query.DESTINATION),
@@ -200,7 +202,17 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
c.getLong(Queries.Query.CONTACT_ID),
c.getLong(Queries.Query.DATA_ID),
c.getString(Queries.Query.PHOTO_THUMBNAIL_URI),
- true));
+ true);
+
+ /*
+ * In certain situations, we may have two results for one address, where one of the
+ * results is just the email address, and the other has a name and photo, so we want
+ * to use the better one.
+ */
+ final RecipientEntry recipientEntry =
+ getBetterRecipient(recipientEntries.get(address), newRecipientEntry);
+
+ recipientEntries.put(address, recipientEntry);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Received reverse look up information for " + address
+ " RESULTS: "
@@ -213,6 +225,60 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
return recipientEntries;
}
+ /**
+ * Given two {@link RecipientEntry}s for the same email address, this will return the one that
+ * contains more complete information for display purposes. Defaults to <code>entry2</code> if
+ * no significant differences are found.
+ * TODO(skennedy) Add tests
+ */
+ private static RecipientEntry getBetterRecipient(final RecipientEntry entry1,
+ final RecipientEntry entry2) {
+ // If only one has passed in, use it
+ if (entry2 == null) {
+ return entry1;
+ }
+
+ if (entry1 == null) {
+ return entry2;
+ }
+
+ // If only one has a display name, use it
+ if (!TextUtils.isEmpty(entry1.getDisplayName())
+ && TextUtils.isEmpty(entry2.getDisplayName())) {
+ return entry1;
+ }
+
+ if (!TextUtils.isEmpty(entry2.getDisplayName())
+ && TextUtils.isEmpty(entry1.getDisplayName())) {
+ return entry2;
+ }
+
+ // If only one has a display name that is not the same as the destination, use it
+ if (!TextUtils.equals(entry1.getDisplayName(), entry1.getDestination())
+ && TextUtils.equals(entry2.getDisplayName(), entry2.getDestination())) {
+ return entry1;
+ }
+
+ if (!TextUtils.equals(entry2.getDisplayName(), entry2.getDestination())
+ && TextUtils.equals(entry1.getDisplayName(), entry1.getDestination())) {
+ return entry2;
+ }
+
+ // If only one has a photo, use it
+ if ((entry1.getPhotoThumbnailUri() != null || entry1.getPhotoBytes() != null)
+ && (entry2.getPhotoThumbnailUri() == null && entry2.getPhotoBytes() == null)) {
+ return entry1;
+ }
+
+ if ((entry2.getPhotoThumbnailUri() != null || entry2.getPhotoBytes() != null)
+ && (entry1.getPhotoThumbnailUri() == null && entry1.getPhotoBytes() == null)) {
+ return entry2;
+ }
+
+ // Go with the second option as a default
+ return entry2;
+ }
+
private static Cursor doQuery(CharSequence constraint, int limit, Long directoryId,
Account account, ContentResolver resolver, Query query) {
final Uri.Builder builder = query