OSDN Git Service

Make total contacts header more like a separator.
authorNeel Parekh <neel@google.com>
Tue, 29 Sep 2009 19:33:19 +0000 (12:33 -0700)
committerNeel Parekh <neel@google.com>
Tue, 29 Sep 2009 21:09:12 +0000 (14:09 -0700)
res/layout-finger/total_contacts.xml
src/com/android/contacts/ContactsListActivity.java

index 1221ef3..ab15ce1 100644 (file)
@@ -24,6 +24,5 @@
     android:textStyle="normal"
     android:background="@drawable/section_dark"
     android:paddingLeft="7dp"
-    android:gravity="left|center_vertical"
-    android:visibility="gone"
+    android:gravity="center|center_vertical"
 />
\ No newline at end of file
index 6d2ea57..1b7dd07 100644 (file)
@@ -566,14 +566,9 @@ public class ContactsListActivity extends ListActivity implements
             list.setTextFilterEnabled(true);
         }
 
-        final LayoutInflater inflater = getLayoutInflater();
-        if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
-            View totalContacts = inflater.inflate(R.layout.total_contacts, list, false);
-            list.addHeaderView(totalContacts);
-        }
-
         if ((mMode & MODE_MASK_CREATE_NEW) != 0) {
             // Add the header for creating a new contact
+            final LayoutInflater inflater = getLayoutInflater();
             View header = inflater.inflate(R.layout.create_new_contact, list, false);
             list.addHeaderView(header);
         }
@@ -585,11 +580,6 @@ public class ContactsListActivity extends ListActivity implements
         setListAdapter(mAdapter);
         getListView().setOnScrollListener(mAdapter);
 
-        if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
-            TextView totalContacts = (TextView) findViewById(R.id.totalContactsText);
-            totalContacts.setVisibility(View.VISIBLE);
-        }
-
         // We manually save/restore the listview state
         list.setSaveEnabled(false);
 
@@ -1094,13 +1084,6 @@ public class ContactsListActivity extends ListActivity implements
                 getSystemService(Context.INPUT_METHOD_SERVICE);
         inputMethodManager.hideSoftInputFromWindow(mList.getWindowToken(), 0);
 
-        if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
-            if (position == 0) {
-                return;
-            }
-            position--;
-        }
-
         if (mMode == MODE_INSERT_OR_EDIT_CONTACT) {
             Intent intent;
             if (position == 0) {
@@ -2071,6 +2054,9 @@ public class ContactsListActivity extends ListActivity implements
 
         @Override
         public int getItemViewType(int position) {
+            if (position == 0 && (mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
+                return IGNORE_ITEM_VIEW_TYPE;
+            }
             if (getSeparatorId(position) != 0) {
                 // We don't want the separator view to be recycled.
                 return IGNORE_ITEM_VIEW_TYPE;
@@ -2085,6 +2071,17 @@ public class ContactsListActivity extends ListActivity implements
                         "this should only be called when the cursor is valid");
             }
 
+            // handle the total contacts item
+            if (position == 0 && (mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
+                final LayoutInflater inflater = getLayoutInflater();
+                TextView totalContacts = (TextView) inflater.inflate(R.layout.total_contacts,
+                        parent, false);
+                int stringId = mDisplayOnlyPhones ? R.string.listTotalPhoneContacts
+                        : R.string.listTotalAllContacts;
+                totalContacts.setText(getString(stringId, getCount()));
+                return totalContacts;
+            }
+
             // Handle the separator specially
             int separatorId = getSeparatorId(position);
             if (separatorId != 0) {
@@ -2380,12 +2377,6 @@ public class ContactsListActivity extends ListActivity implements
             }
 
             super.changeCursor(cursor);
-            if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
-                TextView totalContacts = (TextView) findViewById(R.id.totalContactsText);
-                int stringId = mDisplayOnlyPhones
-                    ? R.string.listTotalPhoneContacts : R.string.listTotalAllContacts;
-                totalContacts.setText(getString(stringId, cursorCount));
-            }
             // Update the indexer for the fast scroll widget
             updateIndexer(cursor);
         }
@@ -2497,6 +2488,12 @@ public class ContactsListActivity extends ListActivity implements
 
         @Override
         public boolean isEnabled(int position) {
+            if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
+                if (position == 0) {
+                    return false;
+                }
+                position--;
+            }
             if (mSuggestionsCursorCount > 0) {
                 return position != 0 && position != mSuggestionsCursorCount + 1;
             }
@@ -2519,6 +2516,9 @@ public class ContactsListActivity extends ListActivity implements
         }
 
         private int getRealPosition(int pos) {
+            if ((mMode & MODE_MASK_SHOW_NUMBER_OF_CONTACTS) != 0) {
+                pos--;
+            }
             if (mSuggestionsCursorCount != 0) {
                 // When showing suggestions, we have 2 additional list items: the "Suggestions"
                 // and "All contacts" separators.