Merge "Details for multiple calls."
diff --git a/src/com/android/contacts/ContactsActivity.java b/src/com/android/contacts/ContactsActivity.java
index b78fad2..1414f80 100644
--- a/src/com/android/contacts/ContactsActivity.java
+++ b/src/com/android/contacts/ContactsActivity.java
@@ -19,10 +19,13 @@
 import com.android.contacts.test.InjectedServices;
 
 import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
 import android.content.ContentResolver;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.view.View;
 
 /**
  * A common superclass for Contacts activities that handles application-wide services.
@@ -86,4 +89,32 @@
     public void onServiceCompleted(Intent callbackIntent) {
         onNewIntent(callbackIntent);
     }
+
+    /**
+     * Convenient version of {@link FragmentManager#findFragmentById(int)}, which throws
+     * an exception if the fragment doesn't exist.
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends Fragment> T getFragment(int id) {
+        T result = (T)getFragmentManager().findFragmentById(id);
+        if (result == null) {
+            throw new IllegalArgumentException("fragment 0x" + Integer.toHexString(id)
+                    + " doesn't exist");
+        }
+        return result;
+    }
+
+    /**
+     * Convenient version of {@link #findViewById(int)}, which throws
+     * an exception if the view doesn't exist.
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends View> T getView(int id) {
+        T result = (T)findViewById(id);
+        if (result == null) {
+            throw new IllegalArgumentException("view 0x" + Integer.toHexString(id)
+                    + " doesn't exist");
+        }
+        return result;
+    }
 }
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 12a17f2..2445a1f 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -90,7 +90,6 @@
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ListPopupWindow;
-import android.widget.SearchView;
 import android.widget.Toast;
 
 import java.util.ArrayList;
@@ -208,19 +207,22 @@
         return mProviderStatus == ProviderStatus.STATUS_NORMAL;
     }
 
+    /**
+     * Initialize fragments that are (or may not be) in the layout.
+     *
+     * For the fragments that are in the layout, we initialize them in
+     * {@link #configureContentView(boolean, Bundle)} after inflating the layout.
+     *
+     * However, there are special fragments which may not be in the layout, so we have to do the
+     * initialization here.
+     * The target fragments are:
+     * - {@link ContactDetailFragment} and {@link ContactDetailUpdatesFragment}:  They may not be
+     *   in the layout depending on the configuration.  (i.e. portrait)
+     * - {@link ContactsUnavailableFragment}: We always create it at runtime.
+     */
     @Override
     public void onAttachFragment(Fragment fragment) {
-        if (fragment instanceof DefaultContactBrowseListFragment) {
-            mAllFragment = (DefaultContactBrowseListFragment)fragment;
-            mAllFragment.setOnContactListActionListener(new ContactBrowserActionListener());
-            if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
-                mAllFragment.setContextMenuAdapter(
-                        new ContactBrowseListContextMenuAdapter(mAllFragment));
-            }
-        } else if (fragment instanceof GroupBrowseListFragment) {
-            mGroupsFragment = (GroupBrowseListFragment) fragment;
-            mGroupsFragment.setListener(new GroupBrowserActionListener());
-        } else if (fragment instanceof ContactDetailFragment) {
+        if (fragment instanceof ContactDetailFragment) {
             mContactDetailFragment = (ContactDetailFragment) fragment;
             mContactDetailFragment.setListener(mContactDetailFragmentListener);
         } else if (fragment instanceof ContactDetailUpdatesFragment) {
@@ -230,18 +232,6 @@
             mContactsUnavailableFragment.setProviderStatusLoader(mProviderStatusLoader);
             mContactsUnavailableFragment.setOnContactsUnavailableActionListener(
                     new ContactsUnavailableFragmentListener());
-        } else if (fragment instanceof ContactLoaderFragment) {
-            mContactDetailLoaderFragment = (ContactLoaderFragment) fragment;
-            mContactDetailLoaderFragment.setListener(mContactDetailLoaderFragmentListener);
-        } else if (fragment instanceof GroupDetailFragment) {
-            mGroupDetailFragment = (GroupDetailFragment) fragment;
-            mGroupDetailFragment.setListener(mGroupDetailFragmentListener);
-            mGroupDetailFragment.setQuickContact(PhoneCapabilityTester.isUsingTwoPanes(this));
-        } else if (fragment instanceof StrequentContactListFragment) {
-            mFavoritesFragment = (StrequentContactListFragment) fragment;
-            mFavoritesFragment.setListener(mFavoritesFragmentListener);
-            mFavoritesFragment.setDisplayType(DisplayType.STARRED_ONLY);
-            mFavoritesFragment.setQuickContact(PhoneCapabilityTester.isUsingTwoPanes(this));
         }
     }
 
@@ -275,39 +265,6 @@
             return;
         }
 
-        if (createContentView) {
-            setContentView(R.layout.people_activity);
-
-            mFavoritesView = findViewById(R.id.favorites_view);
-            mDetailsView = findViewById(R.id.details_view);
-            mBrowserView = findViewById(R.id.browse_view);
-
-            final FragmentManager fragmentManager = getFragmentManager();
-            mFavoritesFragment = (StrequentContactListFragment) fragmentManager
-                    .findFragmentById(R.id.favorites_fragment);
-            mFrequentFragment = (StrequentContactListFragment) fragmentManager
-                    .findFragmentById(R.id.frequent_fragment);
-            mAllFragment = (DefaultContactBrowseListFragment) fragmentManager
-                    .findFragmentById(R.id.all_fragment);
-            mGroupsFragment = (GroupBrowseListFragment) fragmentManager
-                    .findFragmentById(R.id.groups_fragment);
-            // Hide all tabs (the current tab will later be reshown once a tab is selected)
-            final FragmentTransaction transaction = fragmentManager.beginTransaction();
-            transaction.hide(mAllFragment);
-            transaction.hide(mGroupsFragment);
-
-            if (mFrequentFragment != null) {
-                mFrequentFragment.setDisplayType(DisplayType.FREQUENT_ONLY);
-            }
-            if (mContactDetailFragment != null) {
-                transaction.hide(mContactDetailFragment);
-            }
-            if (mGroupDetailFragment != null) {
-                transaction.hide(mGroupDetailFragment);
-            }
-            transaction.commit();
-        }
-
         if (mRequest.getActionCode() == ContactsRequest.ACTION_VIEW_CONTACT
                 && !PhoneCapabilityTester.isUsingTwoPanes(this)) {
             redirect = new Intent(this, ContactDetailActivity.class);
@@ -318,6 +275,60 @@
             return;
         }
 
+        if (createContentView) {
+            setContentView(R.layout.people_activity);
+
+            final FragmentManager fragmentManager = getFragmentManager();
+
+            // Hide all tabs (the current tab will later be reshown once a tab is selected)
+            final FragmentTransaction transaction = fragmentManager.beginTransaction();
+
+            // Common fragments that exist on both 1 and 2 panes.
+            mFavoritesFragment = getFragment(R.id.favorites_fragment);
+            mFavoritesFragment.setListener(mFavoritesFragmentListener);
+            mFavoritesFragment.setDisplayType(DisplayType.STARRED_ONLY);
+
+            mAllFragment = getFragment(R.id.all_fragment);
+            mAllFragment.setOnContactListActionListener(new ContactBrowserActionListener());
+            if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
+                mAllFragment.setContextMenuAdapter(
+                        new ContactBrowseListContextMenuAdapter(mAllFragment));
+            }
+
+            mGroupsFragment = getFragment(R.id.groups_fragment);
+            mGroupsFragment.setListener(new GroupBrowserActionListener());
+
+            transaction.hide(mAllFragment);
+            transaction.hide(mGroupsFragment);
+
+            if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
+                mFavoritesFragment.setQuickContact(true);
+
+                // Container views for fragments
+                mFavoritesView = getView(R.id.favorites_view);
+                mDetailsView = getView(R.id.details_view);
+                mBrowserView = getView(R.id.browse_view);
+
+                // 2-pane only fragments
+                mFrequentFragment = getFragment(R.id.frequent_fragment);
+                mFrequentFragment.setListener(mFavoritesFragmentListener);
+                mFrequentFragment.setDisplayType(DisplayType.FREQUENT_ONLY);
+                mFrequentFragment.setQuickContact(true);
+
+                mContactDetailLoaderFragment = getFragment(R.id.contact_detail_loader_fragment);
+                mContactDetailLoaderFragment.setListener(mContactDetailLoaderFragmentListener);
+
+                mGroupDetailFragment = getFragment(R.id.group_detail_fragment);
+                mGroupDetailFragment.setListener(mGroupDetailFragmentListener);
+                mGroupDetailFragment.setQuickContact(true);
+
+                transaction.hide(mContactDetailFragment);
+                transaction.hide(mGroupDetailFragment);
+            }
+            transaction.commit();
+            fragmentManager.executePendingTransactions();
+        }
+
         setTitle(mRequest.getActivityTitle());
         ActionBar actionBar = getActionBar();
         mActionBarAdapter = new ActionBarAdapter(this, this);
diff --git a/src/com/android/contacts/list/ContactTileView.java b/src/com/android/contacts/list/ContactTileView.java
index 279dc93..7981bd1 100644
--- a/src/com/android/contacts/list/ContactTileView.java
+++ b/src/com/android/contacts/list/ContactTileView.java
@@ -43,6 +43,7 @@
 
     public ContactTileView(Context context, AttributeSet attrs) {
         super(context, attrs);
+        setLayerType(View.LAYER_TYPE_HARDWARE, null);
     }
 
     @Override