Merge "Reduce a column for People contacts query" into ics-mr1
diff --git a/src/com/android/contacts/list/ContactListAdapter.java b/src/com/android/contacts/list/ContactListAdapter.java
index 1074423..a8caf3b 100644
--- a/src/com/android/contacts/list/ContactListAdapter.java
+++ b/src/com/android/contacts/list/ContactListAdapter.java
@@ -39,45 +39,64 @@
public abstract class ContactListAdapter extends ContactEntryListAdapter {
protected static class ContactQuery {
- public static final String[] PROJECTION_CONTACT = new String[] {
+ private static final String[] CONTACT_PROJECTION_PRIMARY = new String[] {
Contacts._ID, // 0
Contacts.DISPLAY_NAME_PRIMARY, // 1
- Contacts.DISPLAY_NAME_ALTERNATIVE, // 2
- Contacts.CONTACT_PRESENCE, // 3
- Contacts.CONTACT_STATUS, // 4
- Contacts.PHOTO_ID, // 5
- Contacts.PHOTO_THUMBNAIL_URI, // 6
- Contacts.LOOKUP_KEY, // 7
- Contacts.IS_USER_PROFILE, // 8
+ Contacts.CONTACT_PRESENCE, // 2
+ Contacts.CONTACT_STATUS, // 3
+ Contacts.PHOTO_ID, // 4
+ Contacts.PHOTO_THUMBNAIL_URI, // 5
+ Contacts.LOOKUP_KEY, // 6
+ Contacts.IS_USER_PROFILE, // 7
};
- public static final String[] FILTER_PROJECTION = new String[] {
+ private static final String[] CONTACT_PROJECTION_ALTERNATIVE = new String[] {
+ Contacts._ID, // 0
+ Contacts.DISPLAY_NAME_ALTERNATIVE, // 1
+ Contacts.CONTACT_PRESENCE, // 2
+ Contacts.CONTACT_STATUS, // 3
+ Contacts.PHOTO_ID, // 4
+ Contacts.PHOTO_THUMBNAIL_URI, // 5
+ Contacts.LOOKUP_KEY, // 6
+ Contacts.IS_USER_PROFILE, // 7
+ };
+
+ private static final String[] FILTER_PROJECTION_PRIMARY = new String[] {
Contacts._ID, // 0
Contacts.DISPLAY_NAME_PRIMARY, // 1
- Contacts.DISPLAY_NAME_ALTERNATIVE, // 2
- Contacts.CONTACT_PRESENCE, // 3
- Contacts.CONTACT_STATUS, // 4
- Contacts.PHOTO_ID, // 5
- Contacts.PHOTO_THUMBNAIL_URI, // 6
- Contacts.LOOKUP_KEY, // 7
- Contacts.IS_USER_PROFILE, // 8
- SearchSnippetColumns.SNIPPET, // 9
+ Contacts.CONTACT_PRESENCE, // 2
+ Contacts.CONTACT_STATUS, // 3
+ Contacts.PHOTO_ID, // 4
+ Contacts.PHOTO_THUMBNAIL_URI, // 5
+ Contacts.LOOKUP_KEY, // 6
+ Contacts.IS_USER_PROFILE, // 7
+ SearchSnippetColumns.SNIPPET, // 8
};
- public static final int CONTACT_ID = 0;
- public static final int CONTACT_DISPLAY_NAME_PRIMARY = 1;
- public static final int CONTACT_DISPLAY_NAME_ALTERNATIVE = 2;
- public static final int CONTACT_PRESENCE_STATUS = 3;
- public static final int CONTACT_CONTACT_STATUS = 4;
- public static final int CONTACT_PHOTO_ID = 5;
- public static final int CONTACT_PHOTO_URI = 6;
- public static final int CONTACT_LOOKUP_KEY = 7;
- public static final int CONTACT_IS_USER_PROFILE = 8;
- public static final int CONTACT_SNIPPET = 9;
+ private static final String[] FILTER_PROJECTION_ALTERNATIVE = new String[] {
+ Contacts._ID, // 0
+ Contacts.DISPLAY_NAME_ALTERNATIVE, // 1
+ Contacts.CONTACT_PRESENCE, // 2
+ Contacts.CONTACT_STATUS, // 3
+ Contacts.PHOTO_ID, // 4
+ Contacts.PHOTO_THUMBNAIL_URI, // 5
+ Contacts.LOOKUP_KEY, // 6
+ Contacts.IS_USER_PROFILE, // 7
+ SearchSnippetColumns.SNIPPET, // 8
+ };
+
+ public static final int CONTACT_ID = 0;
+ public static final int CONTACT_DISPLAY_NAME = 1;
+ public static final int CONTACT_PRESENCE_STATUS = 2;
+ public static final int CONTACT_CONTACT_STATUS = 3;
+ public static final int CONTACT_PHOTO_ID = 4;
+ public static final int CONTACT_PHOTO_URI = 5;
+ public static final int CONTACT_LOOKUP_KEY = 6;
+ public static final int CONTACT_IS_USER_PROFILE = 7;
+ public static final int CONTACT_SNIPPET = 8;
}
private CharSequence mUnknownNameText;
- private int mDisplayNameColumnIndex;
private long mSelectedContactDirectoryId;
private String mSelectedContactLookupKey;
@@ -118,17 +137,7 @@
@Override
public String getContactDisplayName(int position) {
- return ((Cursor)getItem(position)).getString(mDisplayNameColumnIndex);
- }
-
- @Override
- public void setContactNameDisplayOrder(int displayOrder) {
- super.setContactNameDisplayOrder(displayOrder);
- if (getContactNameDisplayOrder() == ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY) {
- mDisplayNameColumnIndex = ContactQuery.CONTACT_DISPLAY_NAME_PRIMARY;
- } else {
- mDisplayNameColumnIndex = ContactQuery.CONTACT_DISPLAY_NAME_ALTERNATIVE;
- }
+ return ((Cursor) getItem(position)).getString(ContactQuery.CONTACT_DISPLAY_NAME);
}
/**
@@ -226,7 +235,8 @@
}
protected void bindName(final ContactListItemView view, Cursor cursor) {
- view.showDisplayName(cursor, mDisplayNameColumnIndex, getContactNameDisplayOrder());
+ view.showDisplayName(
+ cursor, ContactQuery.CONTACT_DISPLAY_NAME, getContactNameDisplayOrder());
// Note: we don't show phonetic any more (See issue 5265330)
}
@@ -330,4 +340,24 @@
setProfileExists(cursor.getInt(ContactQuery.CONTACT_IS_USER_PROFILE) == 1);
}
}
+
+ /**
+ * @return Projection useful for children.
+ */
+ protected final String[] getProjection(boolean forSearch) {
+ final int sortOrder = getContactNameDisplayOrder();
+ if (forSearch) {
+ if (sortOrder == ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY) {
+ return ContactQuery.FILTER_PROJECTION_PRIMARY;
+ } else {
+ return ContactQuery.FILTER_PROJECTION_ALTERNATIVE;
+ }
+ } else {
+ if (sortOrder == ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY) {
+ return ContactQuery.CONTACT_PROJECTION_PRIMARY;
+ } else {
+ return ContactQuery.CONTACT_PROJECTION_ALTERNATIVE;
+ }
+ }
+ }
}
diff --git a/src/com/android/contacts/list/DefaultContactListAdapter.java b/src/com/android/contacts/list/DefaultContactListAdapter.java
index 401320a..348abb9 100644
--- a/src/com/android/contacts/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/list/DefaultContactListAdapter.java
@@ -72,7 +72,7 @@
// Regardless of the directory, we don't want anything returned,
// so let's just send a "nothing" query to the local directory.
loader.setUri(Contacts.CONTENT_URI);
- loader.setProjection(ContactQuery.PROJECTION_CONTACT);
+ loader.setProjection(getProjection(false));
loader.setSelection("0");
} else {
Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
@@ -87,11 +87,11 @@
SNIPPET_ARGS);
builder.appendQueryParameter(SearchSnippetColumns.DEFERRED_SNIPPETING_KEY,"1");
loader.setUri(builder.build());
- loader.setProjection(ContactQuery.FILTER_PROJECTION);
+ loader.setProjection(getProjection(true));
}
} else {
configureUri(loader, directoryId, filter);
- configureProjection(loader, directoryId, filter);
+ loader.setProjection(getProjection(false));
configureSelection(loader, directoryId, filter);
}
@@ -132,11 +132,6 @@
loader.setUri(uri);
}
- protected void configureProjection(
- CursorLoader loader, long directoryId, ContactListFilter filter) {
- loader.setProjection(ContactQuery.PROJECTION_CONTACT);
- }
-
private void configureSelection(
CursorLoader loader, long directoryId, ContactListFilter filter) {
if (filter == null) {
diff --git a/src/com/android/contacts/list/JoinContactListAdapter.java b/src/com/android/contacts/list/JoinContactListAdapter.java
index b81dd3b..bfe8c53 100644
--- a/src/com/android/contacts/list/JoinContactListAdapter.java
+++ b/src/com/android/contacts/list/JoinContactListAdapter.java
@@ -67,7 +67,7 @@
@Override
public void configureLoader(CursorLoader cursorLoader, long directoryId) {
- JoinContactLoader loader = (JoinContactLoader)cursorLoader;
+ JoinContactLoader loader = (JoinContactLoader) cursorLoader;
Builder builder = Contacts.CONTENT_URI.buildUpon();
builder.appendEncodedPath(String.valueOf(mTargetContactId));
@@ -83,7 +83,7 @@
loader.setSuggestionUri(builder.build());
// TODO simplify projection
- loader.setProjection(ContactQuery.PROJECTION_CONTACT);
+ loader.setProjection(getProjection(false));
Uri allContactsUri = buildSectionIndexerUri(Contacts.CONTENT_URI).buildUpon()
.appendQueryParameter(
ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT))
@@ -189,13 +189,6 @@
}
}
- public Cursor getShowAllContactsLabelCursor() {
- MatrixCursor matrixCursor = new MatrixCursor(ContactQuery.PROJECTION_CONTACT);
- Object[] row = new Object[ContactQuery.PROJECTION_CONTACT.length];
- matrixCursor.addRow(row);
- return matrixCursor;
- }
-
@Override
public Uri getContactUri(int partitionIndex, Cursor cursor) {
long contactId = cursor.getLong(ContactQuery.CONTACT_ID);