Merge "Destroy mAggregationSuggestionEngine only on destroy"
diff --git a/res/layout/contact_picker_content.xml b/res/layout/contact_picker_content.xml
index 613af69..0a3fa1d 100644
--- a/res/layout/contact_picker_content.xml
+++ b/res/layout/contact_picker_content.xml
@@ -14,26 +14,25 @@
      limitations under the License.
 -->
 
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/pinned_header_list_layout"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             android:layout_width="match_parent"
+             android:layout_height="match_parent">
 
     <view
         class="com.android.contacts.common.list.PinnedHeaderListView"
         android:id="@android:id/list"
         android:layout_width="match_parent"
-        android:layout_height="0dip"
+        android:layout_height="match_parent"
         android:layout_marginLeft="?attr/contact_browser_list_padding_left"
         android:layout_marginRight="?attr/contact_browser_list_padding_right"
-        android:fastScrollEnabled="true"
-        android:layout_weight="1" />
+        android:fastScrollEnabled="true"/>
 
-    <ViewStub
-        android:id="@+id/footer_stub"
-        android:layout="@layout/footer_panel"
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content" />
-</LinearLayout>
+    <TextView android:id="@android:id/empty"
+              android:layout_width="wrap_content"
+              android:layout_height="wrap_content"
+              android:layout_gravity="center"
+              android:textSize="20sp"
+              android:textColor="?android:attr/textColorSecondary"
+              android:text="@string/listFoundAllContactsZero"/>
+
+</FrameLayout>
diff --git a/res/xml/preference_display_options.xml b/res/xml/preference_display_options.xml
index a65010d..4ec31b2 100644
--- a/res/xml/preference_display_options.xml
+++ b/res/xml/preference_display_options.xml
@@ -15,16 +15,13 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
-    <PreferenceCategory
-        android:title="@string/preference_displayOptions">
-        <com.android.contacts.preference.SortOrderPreference
-            android:key="sortOrder"
-            android:title="@string/display_options_sort_list_by"
-            android:dialogTitle="@string/display_options_sort_list_by" />
+    <com.android.contacts.preference.SortOrderPreference
+        android:key="sortOrder"
+        android:title="@string/display_options_sort_list_by"
+        android:dialogTitle="@string/display_options_sort_list_by" />
 
-        <com.android.contacts.preference.DisplayOrderPreference
-            android:key="displayOrder"
-            android:title="@string/display_options_view_names_as"
-            android:dialogTitle="@string/display_options_view_names_as" />
-    </PreferenceCategory>
+    <com.android.contacts.preference.DisplayOrderPreference
+        android:key="displayOrder"
+        android:title="@string/display_options_view_names_as"
+        android:dialogTitle="@string/display_options_view_names_as" />
 </PreferenceScreen>
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index c79ba2f..d069c8d 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -18,6 +18,8 @@
 
 import android.content.Context;
 import android.database.Cursor;
+import android.os.Bundle;
+import android.os.Parcelable;
 import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
 import android.provider.ContactsContract.CommonDataKinds.Organization;
 import android.provider.ContactsContract.CommonDataKinds.Photo;
@@ -60,12 +62,19 @@
  * {@link RawContactModifier} to ensure that {@link AccountType} are enforced.
  */
 public class RawContactEditorView extends BaseRawContactEditorView {
+    private static final String KEY_ORGANIZATION_VIEW_EXPANDED = "organizationViewExpanded";
+    private static final String KEY_SUPER_INSTANCE_STATE = "superInstanceState";
+
     private LayoutInflater mInflater;
 
     private StructuredNameEditorView mName;
     private PhoneticNameEditorView mPhoneticName;
     private GroupMembershipView mGroupMembershipView;
 
+    private ViewGroup mOrganizationSectionViewContainer;
+    private View mAddOrganizationButton;
+    private boolean mOrganizationViewExpanded = false;
+
     private ViewGroup mFields;
 
     private ImageView mAccountIcon;
@@ -148,6 +157,35 @@
         });
     }
 
+    @Override
+    protected Parcelable onSaveInstanceState() {
+        Bundle bundle = new Bundle();
+        bundle.putBoolean(KEY_ORGANIZATION_VIEW_EXPANDED, mOrganizationViewExpanded);
+        // super implementation of onSaveInstanceState returns null
+        bundle.putParcelable(KEY_SUPER_INSTANCE_STATE, super.onSaveInstanceState());
+        return bundle;
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Parcelable state) {
+        if (state instanceof Bundle) {
+            Bundle bundle = (Bundle) state;
+            mOrganizationViewExpanded = bundle.getBoolean(KEY_ORGANIZATION_VIEW_EXPANDED);
+            if (mOrganizationViewExpanded) {
+                // we have to manually perform the expansion here because
+                // onRestoreInstanceState is called after setState. So at the point
+                // of the creation of the organization view, mOrganizationViewExpanded
+                // does not have the correct value yet.
+                mOrganizationSectionViewContainer.setVisibility(VISIBLE);
+                mAddOrganizationButton.setVisibility(GONE);
+            }
+            super.onRestoreInstanceState(bundle.getParcelable(KEY_SUPER_INSTANCE_STATE));
+            return;
+        }
+        super.onRestoreInstanceState(state);
+        return;
+    }
+
     /**
      * Set the internal state for this view, given a current
      * {@link RawContactDelta} state and the {@link AccountType} that
@@ -264,21 +302,21 @@
                     // EditText fields only when clicked
                     final View organizationView = mInflater.inflate(
                             R.layout.organization_editor_view_switcher, mFields, false);
-                    final View addOrganizationButton = organizationView.findViewById(
+                    mAddOrganizationButton = organizationView.findViewById(
                             R.id.add_organization_button);
-                    final ViewGroup organizationSectionViewContainer =
+                    mOrganizationSectionViewContainer =
                             (ViewGroup) organizationView.findViewById(R.id.container);
-
-                    organizationSectionViewContainer.addView(section);
+                    mOrganizationSectionViewContainer.addView(section);
 
                     // Setup the click listener for the "add organization" button
-                    addOrganizationButton.setOnClickListener(new OnClickListener() {
+                    mAddOrganizationButton.setOnClickListener(new OnClickListener() {
                         @Override
                         public void onClick(View v) {
                             // Once the user expands the organization field, the user cannot
                             // collapse them again.
-                            EditorAnimator.getInstance().expandOrganization(addOrganizationButton,
-                                    organizationSectionViewContainer);
+                            EditorAnimator.getInstance().expandOrganization(mAddOrganizationButton,
+                                    mOrganizationSectionViewContainer);
+                            mOrganizationViewExpanded = true;
                         }
                     });
 
diff --git a/src/com/android/contacts/group/GroupBrowseListAdapter.java b/src/com/android/contacts/group/GroupBrowseListAdapter.java
index 32296c2..f1c3aba 100644
--- a/src/com/android/contacts/group/GroupBrowseListAdapter.java
+++ b/src/com/android/contacts/group/GroupBrowseListAdapter.java
@@ -60,7 +60,7 @@
         // first group
         if (mSelectedGroupUri == null && cursor != null && cursor.getCount() > 0) {
             GroupListItem firstItem = getItem(0);
-            long groupId = (firstItem == null) ? null : firstItem.getGroupId();
+            long groupId = (firstItem == null) ? 0 : firstItem.getGroupId();
             mSelectedGroupUri = getGroupUriFromId(groupId);
         }