Merge "New plus/minus buttons in Editor"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9c034c1..a3eba3b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -267,7 +267,8 @@
         </activity>
 
         <!-- An activity for selecting multiple phone numbers -->
-        <activity android:name="MultiplePhonePickerActivity">
+        <activity android:name="MultiplePhonePickerActivity"
+            android:enabled="false">
             <intent-filter>
                 <action android:name="com.android.contacts.action.GET_MULTIPLE_PHONES" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/drawable-hdpi/group_membership_edit_background.9.png b/res/drawable-hdpi/group_membership_edit_background.9.png
new file mode 100644
index 0000000..1292ebf
--- /dev/null
+++ b/res/drawable-hdpi/group_membership_edit_background.9.png
Binary files differ
diff --git a/res/drawable-mdpi/group_membership_edit_background.9.png b/res/drawable-mdpi/group_membership_edit_background.9.png
new file mode 100644
index 0000000..36003cf
--- /dev/null
+++ b/res/drawable-mdpi/group_membership_edit_background.9.png
Binary files differ
diff --git a/res/layout-xlarge/item_group_membership.xml b/res/layout-xlarge/item_group_membership.xml
index 8ac514d..2c773ce 100644
--- a/res/layout-xlarge/item_group_membership.xml
+++ b/res/layout-xlarge/item_group_membership.xml
@@ -31,12 +31,13 @@
         android:singleLine="true"
         android:ellipsize="marquee" />
 
-    <Button
+    <TextView
         android:id="@+id/group_list"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:textAppearance="?android:attr/textAppearanceMedium"
+        android:background="@drawable/group_membership_edit_background"
         android:gravity="left"
         android:ellipsize="end"
     />
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 8e82ba7..90d92a1 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -26,6 +26,8 @@
 import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.preference.PreferenceManager;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
@@ -55,6 +57,15 @@
 
     private static final int REQUEST_CODE_CUSTOMIZE_FILTER = 3;
 
+    private static final int MESSAGE_REFRESH_FILTERS = 0;
+
+    /**
+     * The delay before the contact filter list is refreshed. This is needed because
+     * during contact sync we will get lots of notifications in rapid succession. This
+     * delay will prevent the slowly changing list of filters from reloading too often.
+     */
+    private static final int FILTER_SPINNER_REFRESH_DELAY_MILLIS = 5000;
+
     private boolean mEditMode;
     private boolean mCreateContactEnabled;
     private int mDisplayWithPhonesOnlyOption = ContactsRequest.DISPLAY_ONLY_WITH_PHONES_DISABLED;
@@ -66,9 +77,19 @@
     private ArrayList<ContactListFilter> mFilterList;
     private int mNextFilterId = 1;
     private NotifyingSpinner mFilterSpinner;
+    private FilterSpinnerAdapter mFilterSpinnerAdapter;
     private ContactListFilter mFilter;
     private boolean mFiltersLoaded;
     private SharedPreferences mPrefs;
+    private final Handler mHandler = new Handler() {
+
+        @Override
+        public void handleMessage(Message msg) {
+            if (msg.what == MESSAGE_REFRESH_FILTERS) {
+                loadFilters();
+            }
+        }
+    };
 
     private LoaderCallbacks<List<ContactListFilter>> mGroupFilterLoaderCallbacks =
             new LoaderCallbacks<List<ContactListFilter>>() {
@@ -292,13 +313,17 @@
     protected void startLoading() {
         // We need to load filters before we can load the list contents
         if (mFilterEnabled && !mFiltersLoaded) {
-            getLoaderManager().restartLoader(
-                    R.id.contact_list_filter_loader, null, mGroupFilterLoaderCallbacks);
+            loadFilters();
         } else {
             super.startLoading();
         }
     }
 
+    private void loadFilters() {
+        getLoaderManager().restartLoader(
+                R.id.contact_list_filter_loader, null, mGroupFilterLoaderCallbacks);
+    }
+
     protected void onGroupFilterLoadFinished(List<ContactListFilter> filters) {
         if (mFilters == null) {
             mFilters = new SparseArray<ContactListFilter>(filters.size());
@@ -349,20 +374,36 @@
         }
 
         boolean filterChanged = false;
-        mFiltersLoaded = true;
         if (mFilter == null  || !filterValid) {
             filterChanged = mFilter != null;
             mFilter = getDefaultFilter();
         }
 
-        mFilterSpinner.setAdapter(new FilterSpinnerAdapter());
-        updateFilterView();
+        if (mFilterSpinnerAdapter == null) {
+            mFilterSpinnerAdapter = new FilterSpinnerAdapter();
+            mFilterSpinner.setAdapter(mFilterSpinnerAdapter);
+        } else {
+            mFilterSpinnerAdapter.notifyDataSetChanged();
+        }
 
         if (filterChanged) {
+            mFiltersLoaded = true;
             reloadData();
-        } else {
+        } else if (!mFiltersLoaded) {
+            mFiltersLoaded = true;
             startLoading();
         }
+
+        updateFilterView();
+    }
+
+    @Override
+    protected void onPartitionLoaded(int partitionIndex, Cursor data) {
+        super.onPartitionLoaded(partitionIndex, data);
+        if (!mHandler.hasMessages(MESSAGE_REFRESH_FILTERS)) {
+            mHandler.sendEmptyMessageDelayed(
+                    MESSAGE_REFRESH_FILTERS, FILTER_SPINNER_REFRESH_DELAY_MILLIS);
+        }
     }
 
     protected void setContactListFilter(int filterId) {
diff --git a/src/com/android/contacts/ui/widget/GroupMembershipView.java b/src/com/android/contacts/ui/widget/GroupMembershipView.java
index 572b204..543820d 100644
--- a/src/com/android/contacts/ui/widget/GroupMembershipView.java
+++ b/src/com/android/contacts/ui/widget/GroupMembershipView.java
@@ -143,7 +143,9 @@
                 }
 
                 // Exclude favorites from the list - they are handled with special UI (star)
-                if (groupId != mFavoritesGroupId && hasMembership(groupId)) {
+                // Also exclude the default group.
+                if (groupId != mFavoritesGroupId && groupId != mDefaultGroupId
+                        && hasMembership(groupId)) {
                     String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
                     if (sb.length() != 0) {
                         sb.append(", ");
@@ -153,8 +155,6 @@
             }
         }
 
-        // Only show the default group for existing contacts (not for inserts)
-        accountHasGroups |= (!mState.isContactInsert() && mDefaultGroupId != 0);
         if (!accountHasGroups) {
             setVisibility(GONE);
             return;
@@ -185,15 +185,7 @@
             String accountType = mGroupMetaData.getString(GroupMetaDataLoader.ACCOUNT_TYPE);
             if (accountName.equals(mAccountName) && accountType.equals(mAccountType)) {
                 long groupId = mGroupMetaData.getLong(GroupMetaDataLoader.GROUP_ID);
-                boolean showGroup;
-                if (groupId == mFavoritesGroupId) {
-                    showGroup = false;
-                } else if (groupId == mDefaultGroupId) {
-                    showGroup = !mState.isContactInsert();
-                } else {
-                    showGroup = true;
-                }
-                if (showGroup) {
+                if (groupId != mFavoritesGroupId && groupId != mDefaultGroupId) {
                     String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
                     boolean checked = hasMembership(groupId);
                     mAdapter.add(new GroupSelectionItem(groupId, title, checked));
@@ -201,9 +193,10 @@
             }
         }
 
-        mPopup = new ListPopupWindow(getContext());
+        mPopup = new ListPopupWindow(getContext(), null);
         mPopup.setAnchorView(mGroupList);
         mPopup.setAdapter(mAdapter);
+        mPopup.setModal(true);
         mPopup.show();
 
         ListView listView = mPopup.getListView();