Merge "Use AT_MOST for label when photo is on right" into ics-mr1
diff --git a/res/layout-sw580dp-w1000dp/people_activity.xml b/res/layout-sw580dp-w1000dp/people_activity.xml
index 9d066df..a288ff0 100644
--- a/res/layout-sw580dp-w1000dp/people_activity.xml
+++ b/res/layout-sw580dp-w1000dp/people_activity.xml
@@ -137,7 +137,7 @@
                 <!-- Most Frequent -->
                 <fragment
                     android:id="@+id/frequent_fragment"
-                    class="com.android.contacts.list.ContactTileListFragment"
+                    class="com.android.contacts.list.ContactTileFrequentFragment"
                     android:layout_width="0dip"
                     android:layout_height="match_parent"
                     android:layout_weight="3"
diff --git a/res/layout-sw580dp/people_activity.xml b/res/layout-sw580dp/people_activity.xml
index c32893e..59a218d 100644
--- a/res/layout-sw580dp/people_activity.xml
+++ b/res/layout-sw580dp/people_activity.xml
@@ -133,7 +133,7 @@
                 <!-- Most Frequent -->
                 <fragment
                     android:id="@+id/frequent_fragment"
-                    class="com.android.contacts.list.ContactTileListFragment"
+                    class="com.android.contacts.list.ContactTileFrequentFragment"
                     android:layout_width="0dip"
                     android:layout_height="match_parent"
                     android:layout_weight="8"
diff --git a/res/layout/account_filter_header.xml b/res/layout/account_filter_header.xml
index 26207f0..ef0a9c2 100644
--- a/res/layout/account_filter_header.xml
+++ b/res/layout/account_filter_header.xml
@@ -23,7 +23,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
-    android:paddingTop="@dimen/contact_browser_list_top_margin"
+    android:paddingTop="@dimen/account_filter_header_top_padding"
     android:layout_marginLeft="@dimen/contact_browser_list_header_left_margin"
     android:layout_marginRight="@dimen/contact_browser_list_header_right_margin"
     android:background="?android:attr/selectableItemBackground"
diff --git a/res/layout/account_filter_header_for_phone_favorite.xml b/res/layout/account_filter_header_for_phone_favorite.xml
new file mode 100644
index 0000000..6f1d23d
--- /dev/null
+++ b/res/layout/account_filter_header_for_phone_favorite.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 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.
+-->
+
+<!-- Layout showing the type of account filter for phone favorite screen
+     (or, new phone "all" screen).
+     This is very similar to account_filter_header.xml but different in its
+     top padding. -->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/account_filter_header_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:paddingTop="8dip"
+    android:layout_marginLeft="@dimen/contact_browser_list_header_left_margin"
+    android:layout_marginRight="@dimen/contact_browser_list_header_right_margin"
+    android:background="?android:attr/selectableItemBackground"
+    android:visibility="gone">
+    <TextView
+        android:id="@+id/account_filter_header"
+        style="@style/ContactListSeparatorTextViewStyle"
+        android:paddingLeft="@dimen/contact_browser_list_item_text_indent" />
+</LinearLayout>
diff --git a/res/layout/contact_tile_list_frequent.xml b/res/layout/contact_tile_list_frequent.xml
new file mode 100644
index 0000000..3707f11
--- /dev/null
+++ b/res/layout/contact_tile_list_frequent.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 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.
+-->
+
+<!--
+  This is very similar to contact_tile_list.xml (there needs to be a ListView called
+  contact_tile_list and an empty view called contact_tile_list_empty). However, this layout also
+  contains a container view for the title of the frequently contacted list.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingBottom="?attr/favorites_padding_bottom"
+    android:orientation="vertical">
+
+    <FrameLayout
+        android:id="@+id/header_container"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"/>
+
+    <ListView
+        android:id="@+id/contact_tile_list"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:fadingEdge="none"
+        android:divider="@null" />
+
+    <TextView
+        android:id="@+id/contact_tile_list_empty"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:gravity="center_horizontal"
+        android:layout_marginTop="@dimen/empty_message_top_margin"
+        android:textColor="?android:attr/textColorSecondary"
+        android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+</LinearLayout>
diff --git a/res/values-sw580dp/dimens.xml b/res/values-sw580dp/dimens.xml
index 8621afd..cb2d173 100644
--- a/res/values-sw580dp/dimens.xml
+++ b/res/values-sw580dp/dimens.xml
@@ -38,6 +38,7 @@
     <dimen name="contact_browser_list_header_left_margin">@dimen/list_visible_scrollbar_padding</dimen>
     <dimen name="contact_browser_list_header_right_margin">24dip</dimen>
     <dimen name="list_visible_scrollbar_padding">48dip</dimen>
+    <dimen name="account_filter_header_top_padding">@dimen/contact_browser_list_top_margin</dimen>
 
     <!-- Margins and padding for text in widget -->
     <dimen name="widget_snippet_top_margin">5dip</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a5843c6..fa66877 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -167,6 +167,8 @@
     <dimen name="contact_browser_list_item_text_indent">8dip</dimen>
     <dimen name="contact_browser_list_top_margin">8dip</dimen>
 
+    <dimen name="account_filter_header_top_padding">0dip</dimen>
+
     <!-- ContactTile Layouts -->
     <!--
       Use sp instead of dip so that the shadowbox heights can all scale uniformly
diff --git a/src/com/android/contacts/ContactsUtils.java b/src/com/android/contacts/ContactsUtils.java
index b0c0508..64dfaef 100644
--- a/src/com/android/contacts/ContactsUtils.java
+++ b/src/com/android/contacts/ContactsUtils.java
@@ -31,6 +31,8 @@
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
+import android.view.View;
+import android.widget.TextView;
 
 import java.util.List;
 
@@ -208,4 +210,15 @@
         intent.setData(lookupUri);
         return intent;
     }
+
+    /**
+     * Returns a header view based on the R.layout.list_separator, where the
+     * containing {@link TextView} is set using the given textResourceId.
+     */
+    public static View createHeaderView(Context context, int textResourceId) {
+        View view = View.inflate(context, R.layout.list_separator, null);
+        TextView textView = (TextView) view.findViewById(R.id.title);
+        textView.setText(context.getString(textResourceId));
+        return view;
+    }
 }
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 772fa54..b4ad78a 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -38,6 +38,7 @@
 import com.android.contacts.list.ContactListFilter;
 import com.android.contacts.list.ContactListFilterController;
 import com.android.contacts.list.ContactTileAdapter.DisplayType;
+import com.android.contacts.list.ContactTileFrequentFragment;
 import com.android.contacts.list.ContactTileListFragment;
 import com.android.contacts.list.ContactsIntentResolver;
 import com.android.contacts.list.ContactsRequest;
@@ -145,7 +146,7 @@
      */
     private DefaultContactBrowseListFragment mAllFragment;
     private ContactTileListFragment mFavoritesFragment;
-    private ContactTileListFragment mFrequentFragment;
+    private ContactTileFrequentFragment mFrequentFragment;
     private GroupBrowseListFragment mGroupsFragment;
 
     private View mFavoritesView;
diff --git a/src/com/android/contacts/list/ContactTileAdapter.java b/src/com/android/contacts/list/ContactTileAdapter.java
index 782d7c1..48bc5c3 100644
--- a/src/com/android/contacts/list/ContactTileAdapter.java
+++ b/src/com/android/contacts/list/ContactTileAdapter.java
@@ -19,6 +19,7 @@
 import com.android.contacts.ContactPresenceIconUtil;
 import com.android.contacts.ContactStatusUtil;
 import com.android.contacts.ContactTileLoaderFactory;
+import com.android.contacts.ContactsUtils;
 import com.android.contacts.GroupMemberLoader;
 import com.android.contacts.R;
 
@@ -298,8 +299,8 @@
                 // Return the number of starred plus frequent rows
                 return starredRowCount + frequentRowCount;
             case FREQUENT_ONLY:
-                // Number of frequent contacts plus one for the header
-                return mContactCursor.getCount() + 1;
+                // Number of frequent contacts
+                return mContactCursor.getCount();
             default:
                 throw new IllegalArgumentException("Unrecognized DisplayType " + mDisplayType);
         }
@@ -324,8 +325,7 @@
 
         switch (mDisplayType) {
             case FREQUENT_ONLY:
-                // Taking the current position and subtracting one because of the header
-                resultList.add(createContactEntryFromCursor(mContactCursor, position - 1));
+                resultList.add(createContactEntryFromCursor(mContactCursor, position));
                 break;
             case STARRED_ONLY:
             case GROUP_MEMBERS:
@@ -403,14 +403,10 @@
      * Divider uses a list_seperator.xml along with text to denote
      * the most frequently contacted contacts.
      */
-    private View getDivider() {
-        View dividerView = View.inflate(mContext, R.layout.list_separator, null);
-        TextView text = (TextView) dividerView.findViewById(R.id.title);
-
-        text.setText(mDisplayType == DisplayType.STREQUENT_PHONE_ONLY ?
-                mContext.getString(R.string.favoritesFrequentCalled) :
-                mContext.getString(R.string.favoritesFrequentContacted));
-        return dividerView;
+    public View getDivider() {
+        return ContactsUtils.createHeaderView(mContext,
+                mDisplayType == DisplayType.STREQUENT_PHONE_ONLY ?
+                R.string.favoritesFrequentCalled : R.string.favoritesFrequentContacted);
     }
 
     private int getLayoutResourceId(int viewType) {
@@ -463,7 +459,7 @@
             case GROUP_MEMBERS:
                 return ViewTypes.STARRED;
             case FREQUENT_ONLY:
-                return position == 0 ? ViewTypes.DIVIDER : ViewTypes.FREQUENT;
+                return ViewTypes.FREQUENT;
             default:
                 throw new IllegalStateException("Unrecognized DisplayType " + mDisplayType);
         }
diff --git a/src/com/android/contacts/list/ContactTileFrequentFragment.java b/src/com/android/contacts/list/ContactTileFrequentFragment.java
new file mode 100644
index 0000000..d958c95
--- /dev/null
+++ b/src/com/android/contacts/list/ContactTileFrequentFragment.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 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.
+ */
+package com.android.contacts.list;
+
+import com.android.contacts.ContactPhotoManager;
+import com.android.contacts.ContactTileLoaderFactory;
+import com.android.contacts.ContactsUtils;
+import com.android.contacts.R;
+import com.android.contacts.list.ContactTileAdapter.DisplayType;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.LoaderManager;
+import android.app.LoaderManager.LoaderCallbacks;
+import android.content.CursorLoader;
+import android.content.Loader;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+import android.widget.TextView;
+
+/**
+ * Fragment containing a list of frequently contacted people.
+ */
+public class ContactTileFrequentFragment extends ContactTileListFragment {
+    private static final String TAG = ContactTileFrequentFragment.class.getSimpleName();
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        View listLayout = inflateAndSetupView(inflater, container, savedInstanceState,
+                R.layout.contact_tile_list_frequent);
+        View headerView = ContactsUtils.createHeaderView(getActivity(),
+                R.string.favoritesFrequentContacted);
+        ViewGroup headerContainer = (ViewGroup) listLayout.findViewById(R.id.header_container);
+        headerContainer.addView(headerView);
+        return listLayout;
+    }
+}
diff --git a/src/com/android/contacts/list/ContactTileListFragment.java b/src/com/android/contacts/list/ContactTileListFragment.java
index 875d5d2..f28c2b5 100644
--- a/src/com/android/contacts/list/ContactTileListFragment.java
+++ b/src/com/android/contacts/list/ContactTileListFragment.java
@@ -38,6 +38,11 @@
 
 /**
  * Fragment containing a list of starred contacts followed by a list of frequently contacted.
+ *
+ * TODO: Make this an abstract class so that the favorites, frequent, and group list functionality
+ * can be separated out. This will make it easier to customize any of those lists if necessary
+ * (i.e. adding header views to the ListViews in the fragment). This work was started
+ * by creating {@link ContactTileFrequentFragment}.
  */
 public class ContactTileListFragment extends Fragment {
     private static final String TAG = ContactTileListFragment.class.getSimpleName();
@@ -69,14 +74,19 @@
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
-        View listLayout = inflater.inflate(R.layout.contact_tile_list, container, false);
+        return inflateAndSetupView(inflater, container, savedInstanceState,
+                R.layout.contact_tile_list);
+    }
+
+    protected View inflateAndSetupView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState, int layoutResourceId) {
+        View listLayout = inflater.inflate(layoutResourceId, container, false);
 
         mEmptyView = (TextView) listLayout.findViewById(R.id.contact_tile_list_empty);
         mListView = (ListView) listLayout.findViewById(R.id.contact_tile_list);
 
         mListView.setItemsCanFocus(true);
         mListView.setAdapter(mAdapter);
-
         return listLayout;
     }
 
diff --git a/src/com/android/contacts/list/PhoneFavoriteFragment.java b/src/com/android/contacts/list/PhoneFavoriteFragment.java
index 9ee2d3c..6876789 100644
--- a/src/com/android/contacts/list/PhoneFavoriteFragment.java
+++ b/src/com/android/contacts/list/PhoneFavoriteFragment.java
@@ -304,7 +304,8 @@
 
         // Create the account filter header but keep it hidden until "all" contacts are loaded.
         mAccountFilterHeaderContainer = new FrameLayout(context, null);
-        mAccountFilterHeader = inflater.inflate(R.layout.account_filter_header, mListView, false);
+        mAccountFilterHeader = inflater.inflate(R.layout.account_filter_header_for_phone_favorite,
+                mListView, false);
         mAccountFilterHeader.setOnClickListener(mFilterHeaderClickListener);
         mAccountFilterHeaderContainer.addView(mAccountFilterHeader);
         mAccountFilterHeaderContainer.setVisibility(View.GONE);