Made Favorites view in portrait orientation in 7" look like phone

Added two new configuration parameters in resources:
- (integer) contact_tile_column_count_in_favorites - which specifies the
  number of columns for the image thumbnails in the favorites tab
- (bool) config_use_two_panes_in_favorites - indicates whether favorites
  should be shown in two-pane mode

Bug: 6379260
Change-Id: I41100b2aee507e0b9a2a37e9149b944a4831a3e9
diff --git a/res/layout-sw580dp/people_activity.xml b/res/layout-sw580dp/people_activity.xml
index 93f7795..42c6afc 100644
--- a/res/layout-sw580dp/people_activity.xml
+++ b/res/layout-sw580dp/people_activity.xml
@@ -78,7 +78,7 @@
                 class="com.android.contacts.detail.ContactLoaderFragment"
                 android:layout_height="0dip"
                 android:layout_width="0dip"
-                android:visibility="gone"/>
+                android:visibility="gone" />
         </view>
 
         <!-- Right panel detail view for Groups tab -->
@@ -100,42 +100,21 @@
                 android:visibility="gone" />
         </view>
 
-        <!-- Two-panel view under the Favorites tab -->
-        <LinearLayout
+        <!-- Single panel view under the Favorites tab (Strequent) -->
+        <FrameLayout
             android:id="@+id/favorites_view"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:background="@drawable/list_background_holo"
-            android:baselineAligned="false">
+            android:layout_height="match_parent">
 
-            <!-- Starred -->
-            <FrameLayout
-                android:layout_width="0dip"
-                android:layout_height="match_parent"
-                android:layout_weight="10"
-                android:background="@drawable/panel_favorites_holo_light">
-
-                <fragment
-                    android:id="@+id/favorites_fragment"
-                    class="com.android.contacts.list.ContactTileListFragment"
-                    android:layout_height="match_parent"
-                    android:layout_width="match_parent"
-                    android:layout_marginRight="16dip"
-                    android:layout_marginLeft="16dip"/>
-
-            </FrameLayout>
-
-            <!-- Most Frequent -->
             <fragment
-                android:id="@+id/frequent_fragment"
-                class="com.android.contacts.list.ContactTileFrequentFragment"
-                android:layout_width="0dip"
+                android:id="@+id/favorites_fragment"
+                class="com.android.contacts.list.ContactTileListFragment"
                 android:layout_height="match_parent"
-                android:layout_weight="8"
-                android:layout_marginTop="16dip"
-                android:layout_marginRight="16dip"/>
+                android:layout_width="match_parent"
+                android:layout_marginRight="16dip"
+                android:layout_marginLeft="16dip" />
 
-        </LinearLayout>
+        </FrameLayout>
 
     </LinearLayout>
 
diff --git a/res/values-sw580dp-w940dp/donottranslate_config.xml b/res/values-sw580dp-w940dp/donottranslate_config.xml
index 92d2780..5e5be30 100644
--- a/res/values-sw580dp-w940dp/donottranslate_config.xml
+++ b/res/values-sw580dp-w940dp/donottranslate_config.xml
@@ -19,4 +19,5 @@
 
 <resources>
     <bool name="config_browse_list_show_images">true</bool>
+    <bool name="config_use_two_panes_in_favorites">true</bool>
 </resources>
diff --git a/res/values-sw580dp-w940dp/integers.xml b/res/values-sw580dp-w940dp/integers.xml
index 8ce96de..191eeb8 100644
--- a/res/values-sw580dp-w940dp/integers.xml
+++ b/res/values-sw580dp-w940dp/integers.xml
@@ -15,5 +15,6 @@
 -->
 <resources>
     <integer name="contact_tile_column_count">3</integer>
+    <integer name="contact_tile_column_count_in_favorites">3</integer>
     <integer name="updates_tab_snippet_max_lines">7</integer>
 </resources>
diff --git a/res/values-sw580dp/donottranslate_config.xml b/res/values-sw580dp/donottranslate_config.xml
index cf4286e..3d0dea0 100644
--- a/res/values-sw580dp/donottranslate_config.xml
+++ b/res/values-sw580dp/donottranslate_config.xml
@@ -19,6 +19,7 @@
 
 <resources>
     <bool name="config_use_two_panes">true</bool>
+    <bool name="config_use_two_panes_in_favorites">false</bool>
     <bool name="show_home_icon">true</bool>
     <bool name="config_show_group_action_in_action_bar">false</bool>
     <bool name="config_browse_list_show_images">false</bool>
diff --git a/res/values-sw580dp/integers.xml b/res/values-sw580dp/integers.xml
index a62fa14..cdf6e4a 100644
--- a/res/values-sw580dp/integers.xml
+++ b/res/values-sw580dp/integers.xml
@@ -15,5 +15,6 @@
 -->
 <resources>
     <integer name="contact_tile_column_count">2</integer>
+    <integer name="contact_tile_column_count_in_favorites">3</integer>
     <integer name="updates_tab_snippet_max_lines">4</integer>
 </resources>
diff --git a/res/values-sw680dp-w1000dp/donottranslate_config.xml b/res/values-sw680dp-w1000dp/donottranslate_config.xml
deleted file mode 100644
index 92d2780..0000000
--- a/res/values-sw680dp-w1000dp/donottranslate_config.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2011, 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.
-*/
--->
-
-<resources>
-    <bool name="config_browse_list_show_images">true</bool>
-</resources>
diff --git a/res/values-sw680dp-w1000dp/integers.xml b/res/values-sw680dp-w1000dp/integers.xml
index 5fda2ed..bc9b2b7 100644
--- a/res/values-sw680dp-w1000dp/integers.xml
+++ b/res/values-sw680dp-w1000dp/integers.xml
@@ -15,4 +15,5 @@
 -->
 <resources>
     <integer name="contact_tile_column_count">4</integer>
-</resources>
\ No newline at end of file
+    <integer name="contact_tile_column_count_in_favorites">4</integer>
+</resources>
diff --git a/res/values-sw680dp/donottranslate_config.xml b/res/values-sw680dp/donottranslate_config.xml
index 92d2780..5e5be30 100644
--- a/res/values-sw680dp/donottranslate_config.xml
+++ b/res/values-sw680dp/donottranslate_config.xml
@@ -19,4 +19,5 @@
 
 <resources>
     <bool name="config_browse_list_show_images">true</bool>
+    <bool name="config_use_two_panes_in_favorites">true</bool>
 </resources>
diff --git a/res/values-sw680dp/integers.xml b/res/values-sw680dp/integers.xml
index eaf5971..5b348a5 100644
--- a/res/values-sw680dp/integers.xml
+++ b/res/values-sw680dp/integers.xml
@@ -15,5 +15,6 @@
 -->
 <resources>
     <integer name="contact_tile_column_count">2</integer>
+    <integer name="contact_tile_column_count_in_favorites">2</integer>
     <integer name="updates_tab_snippet_max_lines">7</integer>
 </resources>
diff --git a/res/values-w470dp/integers.xml b/res/values-w470dp/integers.xml
index d247e46..bc9b2b7 100644
--- a/res/values-w470dp/integers.xml
+++ b/res/values-w470dp/integers.xml
@@ -15,4 +15,5 @@
 -->
 <resources>
     <integer name="contact_tile_column_count">4</integer>
+    <integer name="contact_tile_column_count_in_favorites">4</integer>
 </resources>
diff --git a/res/values/donottranslate_config.xml b/res/values/donottranslate_config.xml
index 64a1243..dd94097 100644
--- a/res/values/donottranslate_config.xml
+++ b/res/values/donottranslate_config.xml
@@ -107,6 +107,12 @@
          shown in their own screens. This flag must be in sync with the layout definitions. -->
     <bool name="config_use_two_panes">false</bool>
 
+    <!--  If true, Contacts uses two panes in the favorites view, one for starred and one for
+          frequently contacted.  If false, only one list is shown with starred on top and frequently
+          contacted listed below. Note: This should not be true if config_use_two_panes is
+          false. -->
+    <bool name="config_use_two_panes_in_favorites">false</bool>
+
     <!-- If true, the "home" icon on the action bar will be shown. -->
     <bool name="show_home_icon">false</bool>
 
diff --git a/res/values/integers.xml b/res/values/integers.xml
index e742ba0..6d5f7c9 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -18,6 +18,9 @@
     <!-- Determines the number of columns in a ContactTileRow -->
     <integer name="contact_tile_column_count">2</integer>
 
+    <!--  Determines the number of columns in a ContactTileRow in the favorites tab -->
+    <integer name="contact_tile_column_count_in_favorites">2</integer>
+
     <!-- Max lines to display of a contact's snippet in the "updates" tab of the contact card tab carousel  -->
     <integer name="updates_tab_snippet_max_lines">3</integer>
 </resources>
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 2d6e4c8..4955b1a 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -402,11 +402,13 @@
             mGroupDetailsView = getView(R.id.group_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.enableQuickContact(true);
+            // Only favorites tab with two panes has a separate frequent fragment
+            if (PhoneCapabilityTester.isUsingTwoPanesInFavorites(this)) {
+                mFrequentFragment = getFragment(R.id.frequent_fragment);
+                mFrequentFragment.setListener(mFavoritesFragmentListener);
+                mFrequentFragment.setDisplayType(DisplayType.FREQUENT_ONLY);
+                mFrequentFragment.enableQuickContact(true);
+            }
 
             mContactDetailLoaderFragment = getFragment(R.id.contact_detail_loader_fragment);
             mContactDetailLoaderFragment.setListener(mContactDetailLoaderFragmentListener);
@@ -430,7 +432,7 @@
         fragmentManager.executePendingTransactions();
 
         // Setting Properties after fragment is created
-        if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
+        if (PhoneCapabilityTester.isUsingTwoPanesInFavorites(this)) {
             mFavoritesFragment.enableQuickContact(true);
             mFavoritesFragment.setDisplayType(DisplayType.STARRED_ONLY);
         } else {
@@ -1448,7 +1450,7 @@
      * @return
      */
     private boolean hasFrequents() {
-        if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
+        if (PhoneCapabilityTester.isUsingTwoPanesInFavorites(this)) {
             return mFrequentFragment.hasFrequents();
         } else {
             return mFavoritesFragment.hasFrequents();
diff --git a/src/com/android/contacts/list/ContactTileListFragment.java b/src/com/android/contacts/list/ContactTileListFragment.java
index 9f34c54..4ee20f5 100644
--- a/src/com/android/contacts/list/ContactTileListFragment.java
+++ b/src/com/android/contacts/list/ContactTileListFragment.java
@@ -19,6 +19,7 @@
 import com.android.contacts.ContactTileLoaderFactory;
 import com.android.contacts.R;
 import com.android.contacts.list.ContactTileAdapter.DisplayType;
+import com.android.contacts.util.PhoneCapabilityTester;
 
 import android.app.Activity;
 import android.app.Fragment;
@@ -31,6 +32,7 @@
 import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -53,8 +55,6 @@
         void onCallNumberDirectly(String phoneNumber);
     }
 
-    private static int LOADER_CONTACTS = 1;
-
     private Listener mListener;
     private ContactTileAdapter mAdapter;
     private DisplayType mDisplayType;
@@ -68,7 +68,7 @@
         super.onAttach(activity);
 
         Resources res = getResources();
-        int columnCount = res.getInteger(R.integer.contact_tile_column_count);
+        int columnCount = res.getInteger(R.integer.contact_tile_column_count_in_favorites);
 
         mAdapter = new ContactTileAdapter(activity, mAdapterListener,
                 columnCount, mDisplayType);
@@ -97,7 +97,17 @@
     @Override
     public void onStart() {
         super.onStart();
-        getLoaderManager().initLoader(LOADER_CONTACTS, null, mContactTileLoaderListener);
+
+        // initialize the loader for this display type and destroy all others
+        final DisplayType[] loaderTypes = mDisplayType.values();
+        for (int i = 0; i < loaderTypes.length; i++) {
+            if (loaderTypes[i] == mDisplayType) {
+                getLoaderManager().initLoader(mDisplayType.ordinal(), null,
+                        mContactTileLoaderListener);
+            } else {
+                getLoaderManager().destroyLoader(loaderTypes[i].ordinal());
+            }
+        }
     }
 
     /**
diff --git a/src/com/android/contacts/list/PhoneFavoriteFragment.java b/src/com/android/contacts/list/PhoneFavoriteFragment.java
index a8eafdc..170790f 100644
--- a/src/com/android/contacts/list/PhoneFavoriteFragment.java
+++ b/src/com/android/contacts/list/PhoneFavoriteFragment.java
@@ -275,7 +275,7 @@
         // that will be available on onCreateView().
 
         mContactTileAdapter = new ContactTileAdapter(activity, mContactTileAdapterListener,
-                getResources().getInteger(R.integer.contact_tile_column_count),
+                getResources().getInteger(R.integer.contact_tile_column_count_in_favorites),
                 ContactTileAdapter.DisplayType.STREQUENT_PHONE_ONLY);
         mContactTileAdapter.setPhotoLoader(ContactPhotoManager.getInstance(activity));
 
diff --git a/src/com/android/contacts/util/PhoneCapabilityTester.java b/src/com/android/contacts/util/PhoneCapabilityTester.java
index d3a8060..ce248bb 100644
--- a/src/com/android/contacts/util/PhoneCapabilityTester.java
+++ b/src/com/android/contacts/util/PhoneCapabilityTester.java
@@ -89,4 +89,11 @@
     public static boolean isUsingTwoPanes(Context context) {
         return context.getResources().getBoolean(R.bool.config_use_two_panes);
     }
+
+    /**
+     * True if the favorites tab should be shown in two-pane mode.  False, otherwise.
+     */
+    public static boolean isUsingTwoPanesInFavorites(Context context) {
+        return context.getResources().getBoolean(R.bool.config_use_two_panes_in_favorites);
+    }
 }