Applying the Holo style to contact picker

Change-Id: Ic57c56359b813d65c89cb0f42efdd1a5f7320894
diff --git a/res/layout-xlarge/contact_picker_content.xml b/res/layout-xlarge/contact_picker_content.xml
new file mode 100644
index 0000000..9112073
--- /dev/null
+++ b/res/layout-xlarge/contact_picker_content.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<LinearLayout 
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal"
+    >
+
+    <view
+        class="com.android.contacts.list.ContactListAizyView"
+        android:id="@+id/contacts_list_aizy"
+        android:layout_width="40dip"
+        android:layout_height="match_parent"
+    />
+
+    <LinearLayout
+        android:layout_width="0px"
+        android:layout_height="match_parent"
+        android:orientation="vertical"
+        android:layout_weight="1"
+        >
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="2dip"
+            android:layout_marginTop="1dip"
+            android:layout_marginBottom="1dip"
+            android:background="#7e7e87"
+        />
+
+        <view
+            class="com.android.contacts.list.ContactEntryListView"
+            android:id="@android:id/list"
+            android:layout_width="match_parent"
+            android:layout_height="0dip"
+            android:fastScrollEnabled="true"
+            android:layout_weight="1"
+            android:scrollingCache="false"
+        />
+
+        <include layout="@layout/contacts_list_empty"/>
+
+        <ViewStub android:id="@+id/footer_stub"
+            android:layout="@layout/footer_panel"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+        />
+    </LinearLayout>
+</LinearLayout>
diff --git a/res/layout/contact_picker.xml b/res/layout/contact_picker.xml
new file mode 100644
index 0000000..4fa8c8e
--- /dev/null
+++ b/res/layout/contact_picker.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/ContactPickerLayout"
+    android:id="@+id/list_container"
+    >
+</FrameLayout>
diff --git a/res/layout/contact_picker_content.xml b/res/layout/contact_picker_content.xml
new file mode 100644
index 0000000..56e8340
--- /dev/null
+++ b/res/layout/contact_picker_content.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     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="horizontal"
+        >
+
+    <LinearLayout
+            android:layout_width="0px"
+            android:layout_height="match_parent"
+            android:orientation="vertical"
+            android:layout_weight="1"
+            >
+
+        <view
+            class="com.android.contacts.list.ContactEntryListView"
+            android:id="@android:id/list"
+            android:layout_width="match_parent"
+            android:layout_height="0dip"
+            android:fastScrollEnabled="true"
+            android:layout_weight="1"
+        />
+
+        <include layout="@layout/contacts_list_empty"/>
+
+        <ViewStub android:id="@+id/footer_stub"
+            android:layout="@layout/footer_panel"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+        />
+    </LinearLayout>
+    <view
+        class="com.android.contacts.list.ContactListAizyView"
+        android:id="@+id/contacts_list_aizy"
+        android:layout_width="30dip"
+        android:layout_height="match_parent"
+    />
+</LinearLayout>
diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml
index f462536..67d52f5 100644
--- a/res/values-xlarge/styles.xml
+++ b/res/values-xlarge/styles.xml
@@ -37,7 +37,7 @@
         <item name="contact_filter_popup_width">320dip</item>
     </style>
 
-    <style name="ContactPickerTheme" parent="@android:Theme.Dialog">
+    <style name="ContactPickerTheme" parent="@android:Theme.Holo.Light.Dialog">
         <item name="section_header_background">@drawable/section_header_holo</item>
         <item name="list_item_divider">@drawable/list_item_divider_holo</item>
         <item name="list_item_padding_top">0dip</item>
@@ -67,6 +67,11 @@
         <item name="android:layout_height">600dip</item>
     </style>
 
+    <style name="ContactPickerLayout" parent="ContactPickerTheme">
+        <item name="android:layout_width">480dip</item>
+        <item name="android:layout_height">650dip</item>
+    </style>
+
     <style name="CallDetailActivityTheme" parent="@android:Theme.Dialog">
         <item name="android:windowContentOverlay">@null</item>
     </style>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9b43a31..960df1e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -47,6 +47,9 @@
     <!-- Activity title when the user is selecting a contact for a direct message shortcut. -->
     <string name="messageShortcutActivityTitle">Choose a number to message</string>
 
+    <!-- Activity title when the user is selecting a contact.  [CHAR LIMIT=128] -->
+    <string name="contactPickerActivityTitle">Select a contact</string>
+
     <!-- Title for the activity that shows only starred contacts -->
     <string name="starredList">Starred</string>
 
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e2a73ea..55cd698 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -179,6 +179,11 @@
     <style name="CustomContactListFilterTheme" parent="@android:Theme">
     </style>
 
+    <style name="ContactPickerLayout" parent="ContactPickerTheme">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">match_parent</item>
+    </style>
+    
     <style name="CustomContactListFilterView" parent="CustomContactListFilterTheme">
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">match_parent</item>
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 938bf0a..06e5bf3 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -33,7 +33,7 @@
 import com.android.contacts.widget.SearchEditText.OnFilterTextListener;
 
 import android.app.Activity;
-import android.app.FragmentTransaction;
+import android.app.Fragment;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
@@ -51,10 +51,12 @@
 public class ContactSelectionActivity extends Activity implements View.OnCreateContextMenuListener {
     private static final String TAG = "ContactSelectionActivity";
 
+    private static final String KEY_ACTION_CODE = "actionCode";
+
     private ContactsIntentResolver mIntentResolver;
     protected ContactEntryListFragment<?> mListFragment;
 
-    private int mActionCode;
+    private int mActionCode = -1;
 
     private boolean mSearchInitiated;
 
@@ -66,8 +68,20 @@
     }
 
     @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
+    public void onAttachFragment(Fragment fragment) {
+        if (fragment instanceof ContactEntryListFragment<?>) {
+            mListFragment = (ContactEntryListFragment<?>) fragment;
+            setupActionListener();
+        }
+    }
+
+    @Override
+    protected void onCreate(Bundle savedState) {
+        super.onCreate(savedState);
+
+        if (savedState != null) {
+            mActionCode = savedState.getInt(KEY_ACTION_CODE);
+        }
 
         // Extract relevant information from the intent
         mRequest = mIntentResolver.resolveIntent(getIntent());
@@ -85,22 +99,20 @@
             return;
         }
 
-        setTitle(mRequest.getActivityTitle());
-
-        onCreateFragment();
-
-        int listFragmentContainerId;
+        configureActivityTitle();
         if (mRequest.isSearchMode()) {
             setContentView(R.layout.contacts_search_content);
-            listFragmentContainerId = R.id.list_container;
             setupSearchUI();
         } else {
-            listFragmentContainerId = android.R.id.content;
+            setContentView(R.layout.contact_picker);
         }
+        configureListFragment();
+    }
 
-        FragmentTransaction transaction = getFragmentManager().openTransaction();
-        transaction.add(listFragmentContainerId, mListFragment);
-        transaction.commit();
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putInt(KEY_ACTION_CODE, mActionCode);
     }
 
     private void setupSearchUI() {
@@ -127,15 +139,68 @@
         }
     }
 
+    private void configureActivityTitle() {
+        if (mRequest.getActivityTitle() != null) {
+            setTitle(mRequest.getActivityTitle());
+            return;
+        }
+
+        int actionCode = mRequest.getActionCode();
+        switch (actionCode) {
+            case ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT: {
+                setTitle(R.string.contactPickerActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_PICK_CONTACT: {
+                setTitle(R.string.contactPickerActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT: {
+                setTitle(R.string.contactPickerActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT: {
+                setTitle(R.string.shortcutActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_PICK_PHONE: {
+                setTitle(R.string.contactPickerActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_CREATE_SHORTCUT_CALL: {
+                setTitle(R.string.callShortcutActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_CREATE_SHORTCUT_SMS: {
+                setTitle(R.string.messageShortcutActivityTitle);
+                break;
+            }
+
+            case ContactsRequest.ACTION_PICK_POSTAL: {
+                setTitle(R.string.contactPickerActivityTitle);
+                break;
+            }
+        }
+    }
+
     /**
      * Creates the fragment based on the current request.
      */
-    private void onCreateFragment() {
+    public void configureListFragment() {
+        if (mActionCode == mRequest.getActionCode()) {
+            return;
+        }
+
         mActionCode = mRequest.getActionCode();
         switch (mActionCode) {
             case ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT: {
                 DefaultContactBrowseListFragment fragment = new DefaultContactBrowseListFragment();
-                fragment.setOnContactListActionListener(new ContactBrowserActionListener());
                 fragment.setEditMode(true);
                 fragment.setCreateContactEnabled(true);
                 fragment.setSearchMode(mRequest.isSearchMode());
@@ -147,8 +212,6 @@
 
             case ContactsRequest.ACTION_PICK_CONTACT: {
                 ContactPickerFragment fragment = new ContactPickerFragment();
-                fragment.setOnContactPickerActionListener(new ContactPickerActionListener());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 fragment.setSearchMode(mRequest.isSearchMode());
                 mListFragment = fragment;
                 break;
@@ -156,18 +219,14 @@
 
             case ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT: {
                 ContactPickerFragment fragment = new ContactPickerFragment();
-                fragment.setOnContactPickerActionListener(new ContactPickerActionListener());
                 fragment.setCreateContactEnabled(!mRequest.isSearchMode());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 mListFragment = fragment;
                 break;
             }
 
             case ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT: {
                 ContactPickerFragment fragment = new ContactPickerFragment();
-                fragment.setOnContactPickerActionListener(new ContactPickerActionListener());
                 fragment.setCreateContactEnabled(!mRequest.isSearchMode());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 fragment.setSearchMode(mRequest.isSearchMode());
                 fragment.setQueryString(mRequest.getQueryString());
                 fragment.setDirectorySearchEnabled(mRequest.isDirectorySearchEnabled());
@@ -178,18 +237,12 @@
 
             case ContactsRequest.ACTION_PICK_PHONE: {
                 PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
-                fragment.setOnPhoneNumberPickerActionListener(
-                        new PhoneNumberPickerActionListener());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 mListFragment = fragment;
                 break;
             }
 
             case ContactsRequest.ACTION_CREATE_SHORTCUT_CALL: {
                 PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
-                fragment.setOnPhoneNumberPickerActionListener(
-                        new PhoneNumberPickerActionListener());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 fragment.setShortcutAction(Intent.ACTION_CALL);
                 fragment.setSearchMode(mRequest.isSearchMode());
 
@@ -199,9 +252,6 @@
 
             case ContactsRequest.ACTION_CREATE_SHORTCUT_SMS: {
                 PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
-                fragment.setOnPhoneNumberPickerActionListener(
-                        new PhoneNumberPickerActionListener());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 fragment.setShortcutAction(Intent.ACTION_SENDTO);
                 fragment.setSearchMode(mRequest.isSearchMode());
 
@@ -211,9 +261,6 @@
 
             case ContactsRequest.ACTION_PICK_POSTAL: {
                 PostalAddressPickerFragment fragment = new PostalAddressPickerFragment();
-                fragment.setOnPostalAddressPickerActionListener(
-                        new PostalAddressPickerActionListener());
-                fragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
                 mListFragment = fragment;
                 break;
             }
@@ -221,7 +268,30 @@
             default:
                 throw new IllegalStateException("Invalid action code: " + mActionCode);
         }
+
+        mListFragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
         mListFragment.setContactsRequest(mRequest);
+        getFragmentManager().openTransaction()
+                .replace(R.id.list_container, mListFragment)
+                .commit();
+    }
+
+    public void setupActionListener() {
+        if (mListFragment instanceof DefaultContactBrowseListFragment) {
+            ((DefaultContactBrowseListFragment) mListFragment).setOnContactListActionListener(
+                    new ContactBrowserActionListener());
+        } else if (mListFragment instanceof ContactPickerFragment) {
+            ((ContactPickerFragment) mListFragment).setOnContactPickerActionListener(
+                    new ContactPickerActionListener());
+        } else if (mListFragment instanceof PhoneNumberPickerFragment) {
+            ((PhoneNumberPickerFragment) mListFragment).setOnPhoneNumberPickerActionListener(
+                    new PhoneNumberPickerActionListener());
+        } else if (mListFragment instanceof PostalAddressPickerFragment) {
+            ((PostalAddressPickerFragment) mListFragment).setOnPostalAddressPickerActionListener(
+                    new PostalAddressPickerActionListener());
+        } else {
+            throw new IllegalStateException("Unsupported list fragment type: " + mListFragment);
+        }
     }
 
     private final class ContactBrowserActionListener implements OnContactBrowserActionListener {
diff --git a/src/com/android/contacts/list/ContactPickerFragment.java b/src/com/android/contacts/list/ContactPickerFragment.java
index 9bc4d8d..64d1dce 100644
--- a/src/com/android/contacts/list/ContactPickerFragment.java
+++ b/src/com/android/contacts/list/ContactPickerFragment.java
@@ -41,6 +41,7 @@
         setPhotoLoaderEnabled(true);
         setSectionHeaderDisplayEnabled(true);
         setAizyEnabled(true);
+        setQuickContactEnabled(false);
     }
 
     public void setOnContactPickerActionListener(OnContactPickerActionListener listener) {
@@ -124,7 +125,7 @@
 
     @Override
     protected View inflateView(LayoutInflater inflater, ViewGroup container) {
-        return inflater.inflate(R.layout.contacts_list_content, null);
+        return inflater.inflate(R.layout.contact_picker_content, null);
     }
 
     @Override
diff --git a/src/com/android/contacts/list/ContactsIntentResolver.java b/src/com/android/contacts/list/ContactsIntentResolver.java
index 3b34cb5..c0917dd 100644
--- a/src/com/android/contacts/list/ContactsIntentResolver.java
+++ b/src/com/android/contacts/list/ContactsIntentResolver.java
@@ -101,13 +101,10 @@
             String component = intent.getComponent().getClassName();
             if (component.equals("alias.DialShortcut")) {
                 request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CALL);
-                request.setActivityTitle(mContext.getString(R.string.callShortcutActivityTitle));
             } else if (component.equals("alias.MessageShortcut")) {
                 request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_SMS);
-                request.setActivityTitle(mContext.getString(R.string.messageShortcutActivityTitle));
             } else {
                 request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT);
-                request.setActivityTitle(mContext.getString(R.string.shortcutActivityTitle));
             }
         } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
             String type = intent.getType();