AI 143308: am: CL 143159 am: CL 142855 Fix SHOW_OR_CREATE intent to correctly handle duplicate E-mail or IM entries for a person.
Added a new WITH_EMAIL_OR_IM_FILTER_URI to find people with a given string as either an E-mail or IM address. This cleans up the original code, and lets us handle duplicates when there are multiple ContactMethod matches for a single person. (We don't get GROUP BY through the ContentProvider interface.)
In ContactsListActivity we don't show possibly-incorrect labels when in MODE_QUERY_PICK_TO_VIEW, as any labels and values would be identical. (The people appearing in that list are there because their ContactMethod matches the query.)
Original author: jsharkey
Merged from: //branches/cupcake/...
Original author: android-build
Merged from: //branches/donutburger/...
Automated import of CL 143308
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 5bebc33..e063ef8 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -187,6 +187,11 @@
People.PRESENCE_STATUS, // 8
SORT_STRING, // 9
};
+
+ static final String[] SIMPLE_CONTACTS_PROJECTION = new String[] {
+ People._ID, // 0
+ NAME_COLUMN, // 1
+ };
static final String[] STREQUENT_PROJECTION = new String[] {
People._ID, // 0
@@ -236,7 +241,7 @@
static final int SORT_STRING_INDEX = 9;
static final int PHONES_PERSON_ID_INDEX = 6;
- static final int CONTACT_METHODS_PERSON_ID_INDEX = 6;
+ static final int SIMPLE_CONTACTS_PERSON_ID_INDEX = 0;
static final int DISPLAY_GROUP_INDEX_ALL_CONTACTS = 0;
static final int DISPLAY_GROUP_INDEX_ALL_CONTACTS_WITH_PHONES = 1;
@@ -1136,12 +1141,14 @@
case MODE_QUERY_PICK_TO_VIEW: {
if (mQueryMode == QUERY_MODE_MAILTO) {
- mQueryPersonIdIndex = CONTACT_METHODS_PERSON_ID_INDEX;
+ // Find all contacts with the given search string as either
+ // an E-mail or IM address.
+ mQueryPersonIdIndex = SIMPLE_CONTACTS_PERSON_ID_INDEX;
+ Uri uri = Uri.withAppendedPath(People.WITH_EMAIL_OR_IM_FILTER_URI,
+ Uri.encode(mQueryData));
mQueryHandler.startQuery(QUERY_TOKEN, null,
- ContactMethods.CONTENT_URI, CONTACT_METHODS_PROJECTION,
- QUERY_KIND_EMAIL_OR_IM + " AND " + ContactMethods.DATA + "=?",
- new String[] { mQueryData },
- getSortOrder(CONTACT_METHODS_PROJECTION));
+ uri, SIMPLE_CONTACTS_PROJECTION, null, null,
+ getSortOrder(CONTACTS_PROJECTION));
} else if (mQueryMode == QUERY_MODE_TEL) {
mQueryPersonIdIndex = PHONES_PERSON_ID_INDEX;
@@ -1566,6 +1573,17 @@
cache.nameView.setText(mUnknownNameText);
}
+ // Bail out early if using a specific SEARCH query mode, usually for
+ // matching a specific E-mail or phone number. Any contact details
+ // shown would be identical, and columns might not even be present
+ // in the returned cursor.
+ if (mQueryMode != QUERY_MODE_NONE) {
+ cache.numberView.setVisibility(View.GONE);
+ cache.labelView.setVisibility(View.GONE);
+ cache.presenceView.setVisibility(View.GONE);
+ return;
+ }
+
// Set the phone number
TextView numberView = cache.numberView;
TextView labelView = cache.labelView;
diff --git a/src/com/android/contacts/ShowOrCreateActivity.java b/src/com/android/contacts/ShowOrCreateActivity.java
index 8d3cf0b..0732ffe 100755
--- a/src/com/android/contacts/ShowOrCreateActivity.java
+++ b/src/com/android/contacts/ShowOrCreateActivity.java
@@ -56,20 +56,17 @@
static final boolean LOGD = false;
static final String[] PHONES_PROJECTION = new String[] {
- Phones._ID,
Phones.PERSON_ID,
};
- static final String[] CONTACT_METHODS_PROJECTION = new String[] {
- ContactMethods._ID,
- ContactMethods.PERSON_ID,
+ static final String[] PEOPLE_PROJECTION = new String[] {
+ People._ID,
};
static final String SCHEME_MAILTO = "mailto";
static final String SCHEME_TEL = "tel";
- static final int ID_INDEX = 0;
- static final int PERSON_ID_INDEX = 1;
+ static final int PERSON_ID_INDEX = 0;
/**
* Query clause to filter {@link ContactMethods#CONTENT_URI} to only search
@@ -126,11 +123,9 @@
// Handle specific query request
if (SCHEME_MAILTO.equals(scheme)) {
createExtras.putString(Intents.Insert.EMAIL, ssp);
- mQueryHandler.startQuery(QUERY_TOKEN, null,
- ContactMethods.CONTENT_URI, CONTACT_METHODS_PROJECTION,
- QUERY_KIND_EMAIL_OR_IM + " AND " + ContactMethods.DATA + "=?",
- new String[] { ssp }, null);
-
+ Uri uri = Uri.withAppendedPath(People.WITH_EMAIL_OR_IM_FILTER_URI, Uri.encode(ssp));
+ mQueryHandler.startQuery(QUERY_TOKEN, null, uri,
+ PEOPLE_PROJECTION, null, null, null);
} else if (SCHEME_TEL.equals(scheme)) {
createExtras.putString(Intents.Insert.PHONE, ssp);
mQueryHandler.startQuery(QUERY_TOKEN, null,