From 7bf296f1d3a7e0bc4d1f47241a5de66454a13403 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Tue, 29 Sep 2009 21:01:25 -0700 Subject: [PATCH] [Issue 2097049] Adding a collapsed "Show all contacts" item to the join suggestion list Change-Id: I7cf12800b942720d00229d6c61ba6180f4cd87d4 --- res/layout-finger/contacts_list_show_all_item.xml | 39 +++++++++++++ res/values/strings.xml | 5 +- src/com/android/contacts/ContactsListActivity.java | 64 +++++++++++++++++++--- 3 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 res/layout-finger/contacts_list_show_all_item.xml diff --git a/res/layout-finger/contacts_list_show_all_item.xml b/res/layout-finger/contacts_list_show_all_item.xml new file mode 100644 index 0000000..5937b9f --- /dev/null +++ b/res/layout-finger/contacts_list_show_all_item.xml @@ -0,0 +1,39 @@ + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index da7bb88..1ea5409 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -144,8 +144,11 @@ Select the contact you want to join with %s. + + Show all contacts + - Suggestions + Suggested contacts All contacts diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java index aa6654d..f164289 100644 --- a/src/com/android/contacts/ContactsListActivity.java +++ b/src/com/android/contacts/ContactsListActivity.java @@ -40,6 +40,7 @@ import android.content.UriMatcher; import android.content.res.Resources; import android.database.CharArrayBuffer; import android.database.Cursor; +import android.database.MatrixCursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -359,9 +360,21 @@ public class ContactsListActivity extends ListActivity implements private static final String CLAUSE_ONLY_VISIBLE = Contacts.IN_VISIBLE_GROUP + "=1"; private static final String CLAUSE_ONLY_PHONES = Contacts.HAS_PHONE_NUMBER + "=1"; + /** + * In the {@link #MODE_JOIN} determines whether we display a list item with the label + * "Show all contacts" or actually show all contacts + */ + private boolean mJoinModeShowAllContacts; + + /** + * The ID of the special item described above. + */ + private static final long JOIN_MODE_SHOW_ALL_CONTACTS_ID = -2; + // Uri matcher for contact id private static final int CONTACTS_ID = 1001; private static final UriMatcher sContactsIdMatcher; + static { sContactsIdMatcher = new UriMatcher(UriMatcher.NO_MATCH); sContactsIdMatcher.addURI(ContactsContract.AUTHORITY, "contacts/#", CONTACTS_ID); @@ -566,7 +579,7 @@ public class ContactsListActivity extends ListActivity implements String blurb = getString(R.string.blurbJoinContactDataWith, contactName); blurbView.setText(blurb); - + mJoinModeShowAllContacts = true; } else { setContentView(R.layout.contacts_list_content); } @@ -1132,7 +1145,12 @@ public class ContactsListActivity extends ListActivity implements final Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivityForResult(intent, SUBACTIVITY_VIEW_CONTACT); } else if (mMode == MODE_JOIN_CONTACT) { - returnPickerResult(null, null, uri, id); + if (id == JOIN_MODE_SHOW_ALL_CONTACTS_ID) { + mJoinModeShowAllContacts = false; + startQuery(); + } else { + returnPickerResult(null, null, uri, id); + } } else if (mMode == MODE_QUERY_PICK_TO_VIEW) { // Started with query that should launch to view contact final Intent intent = new Intent(Intent.ACTION_VIEW, uri); @@ -1701,6 +1719,7 @@ public class ContactsListActivity extends ListActivity implements Cursor cursor = resolver.query(getJoinSuggestionsUri(filter), projection, null, null, null); mAdapter.setSuggestionsCursor(cursor); + mJoinModeShowAllContacts = false; return resolver.query(getContactFilterUri(filter), projection, Contacts._ID + " != " + mQueryAggregateId + " AND " + CLAUSE_ONLY_VISIBLE, null, getSortOrder(projection)); @@ -1709,6 +1728,15 @@ public class ContactsListActivity extends ListActivity implements throw new UnsupportedOperationException("filtering not allowed in mode " + mMode); } + private Cursor getShowAllContactsLabelCursor(String[] projection) { + MatrixCursor matrixCursor = new MatrixCursor(projection); + Object[] row = new Object[projection.length]; + // The only columns we care about is the id + row[SUMMARY_ID_COLUMN_INDEX] = JOIN_MODE_SHOW_ALL_CONTACTS_ID; + matrixCursor.addRow(row); + return matrixCursor; + } + /** * Calls the currently selected list item. * @return true if the call was initiated, false otherwise @@ -1838,15 +1866,21 @@ public class ContactsListActivity extends ListActivity implements if (cursor.getCount() > 0) { activity.mAdapter.setSuggestionsCursor(cursor); } else { + cursor.close(); activity.mAdapter.setSuggestionsCursor(null); } - startQuery(QUERY_TOKEN, null, activity.getContactFilterUri(activity.mQuery), - CONTACTS_SUMMARY_PROJECTION, - Contacts._ID + " != " + activity.mQueryAggregateId - + " AND " + CLAUSE_ONLY_VISIBLE, null, - getSortOrder(CONTACTS_SUMMARY_PROJECTION)); - return; + if (activity.mAdapter.mSuggestionsCursorCount == 0 + || !activity.mJoinModeShowAllContacts) { + startQuery(QUERY_TOKEN, null, activity.getContactFilterUri(activity.mQuery), + CONTACTS_SUMMARY_PROJECTION, + Contacts._ID + " != " + activity.mQueryAggregateId + + " AND " + CLAUSE_ONLY_VISIBLE, null, + getSortOrder(CONTACTS_SUMMARY_PROJECTION)); + return; + } + + cursor = activity.getShowAllContactsLabelCursor(CONTACTS_SUMMARY_PROJECTION); } activity.mAdapter.setLoading(false); @@ -2077,6 +2111,9 @@ public class ContactsListActivity extends ListActivity implements if (position == 0 && (mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) { return IGNORE_ITEM_VIEW_TYPE; } + if (isShowAllContactsItemPosition(position)) { + return IGNORE_ITEM_VIEW_TYPE; + } if (getSeparatorId(position) != 0) { // We don't want the separator view to be recycled. return IGNORE_ITEM_VIEW_TYPE; @@ -2102,6 +2139,12 @@ public class ContactsListActivity extends ListActivity implements return totalContacts; } + if (isShowAllContactsItemPosition(position)) { + LayoutInflater inflater = + (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + return inflater.inflate(R.layout.contacts_list_show_all_item, parent, false); + } + // Handle the separator specially int separatorId = getSeparatorId(position); if (separatorId != 0) { @@ -2138,6 +2181,11 @@ public class ContactsListActivity extends ListActivity implements return v; } + private boolean isShowAllContactsItemPosition(int position) { + return mMode == MODE_JOIN_CONTACT && mJoinModeShowAllContacts + && mSuggestionsCursorCount != 0 && position == mSuggestionsCursorCount + 2; + } + private int getSeparatorId(int position) { int separatorId = 0; if (position == mFrequentSeparatorPos) { -- 2.11.0