Merge "Implement dialpad in XML"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c576cd7..8c97265 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -183,6 +183,14 @@
                   android:theme="@style/NewDialtactsTheme"
                   android:screenOrientation="portrait"
                   android:icon="@mipmap/ic_launcher_phone">
+                <!--
+                <intent-filter>
+                    <action android:name="android.intent.action.VIEW" />
+                    <category android:name="android.intent.category.DEFAULT" />
+                    <category android:name="android.intent.category.BROWSABLE" />
+                    <data android:mimeType="vnd.android.cursor.dir/calls" />
+                </intent-filter>
+                 -->
         </activity>
 
         <activity android:name="com.android.dialer.CallDetailActivity"
diff --git a/res/layout/new_dialpad_fragment.xml b/res/layout/new_dialpad_fragment.xml
index 6a27216..c357d47 100644
--- a/res/layout/new_dialpad_fragment.xml
+++ b/res/layout/new_dialpad_fragment.xml
@@ -73,26 +73,40 @@
 
         <View style="@style/DialpadHorizontalSeparator"/>
 
-        <!-- left and right paddings will be modified by the code. See DialpadFragment. -->
-        <FrameLayout
+        <LinearLayout
             android:id="@+id/dialButtonContainer"
             android:layout_width="match_parent"
             android:layout_height="0px"
             android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"
             android:layout_gravity="center_horizontal"
             android:background="@color/dialpad_primary_text_color">
-
+            <ImageButton
+                android:id="@+id/call_history_on_dialpad_button"
+                android:layout_height="@dimen/fake_action_bar_height"
+                android:layout_width="@dimen/fake_menu_button_min_width"
+                android:layout_gravity="bottom|start"
+                android:background="?android:attr/selectableItemBackground"
+                android:contentDescription="@string/action_menu_call_history_description"
+                android:src="@drawable/ic_dialer_menu_history_dk"/>
             <ImageButton
                 android:id="@+id/dialButton"
-                android:layout_width="match_parent"
+                android:layout_width="0dp"
+                android:layout_weight="1"
                 android:layout_height="match_parent"
                 android:layout_gravity="center"
                 android:state_enabled="false"
                 android:background="@drawable/btn_call"
                 android:contentDescription="@string/description_dial_button"
                 android:src="@drawable/ic_dial_action_call" />
-
-        </FrameLayout>
+            <ImageButton
+                android:id="@+id/overflow_menu_on_dialpad"
+                android:layout_height="@dimen/fake_action_bar_height"
+                android:layout_width="@dimen/fake_menu_button_min_width"
+                android:layout_gravity="bottom|end"
+                android:background="?android:attr/selectableItemBackground"
+                android:src="@drawable/ic_menu_overflow_dark"
+                android:contentDescription="@string/action_menu_overflow_description" />
+        </LinearLayout>
 
         <!-- "Dialpad chooser" UI, shown only when the user brings up the
              Dialer while a call is already in progress.
@@ -105,4 +119,4 @@
         />
 
     </LinearLayout>
-</view>
\ No newline at end of file
+</view>
diff --git a/res/layout/new_phone_favorites_fragment.xml b/res/layout/new_phone_favorites_fragment.xml
index 90d0aac..cc11ea1 100644
--- a/res/layout/new_phone_favorites_fragment.xml
+++ b/res/layout/new_phone_favorites_fragment.xml
@@ -22,7 +22,8 @@
     android:orientation="vertical"
     android:divider="?android:attr/dividerHorizontal"
     android:showDividers="end"
-    android:clipChildren="false">
+    android:clipChildren="false"
+    android:background="@color/background_dialer_light">
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
@@ -46,7 +47,7 @@
             android:textAppearance="?android:attr/textAppearanceLarge"/>
     </FrameLayout>
     <FrameLayout
-        android:layout_height="48dp"
+        android:layout_height="@dimen/fake_action_bar_height"
         android:layout_width="match_parent"
         android:id="@+id/fake_action_bar"
         android:background="@color/actionbar_background_color">
@@ -56,7 +57,7 @@
             android:layout_height="match_parent"
             android:layout_gravity="bottom|start"
             android:background="?android:attr/selectableItemBackground"
-            android:contentDescription="@string/description_search_button"
+            android:contentDescription="@string/action_menu_call_history_description"
             android:src="@drawable/ic_dialer_menu_history_dk"/>
         <ImageButton
             android:id="@+id/dialpad_button"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 0ab27c3..452bb31 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -34,7 +34,7 @@
     <dimen name="call_log_call_action_width">48dip</dimen>
     <dimen name="call_log_icon_margin">4dip</dimen>
     <dimen name="call_log_inner_margin">8dip</dimen>
-    <dimen name="call_log_outer_margin">16dip</dimen>
+    <dimen name="call_log_outer_margin">8dip</dimen>
     <dimen name="call_log_indent_margin">24dip</dimen>
     <dimen name="call_log_list_item_height">56dip</dimen>
     <dimen name="call_log_list_contact_photo_size">64dip</dimen>
@@ -49,8 +49,9 @@
     <integer name="dialpad_layout_weight_dialpad">65</integer>
     <integer name="dialpad_layout_weight_additional_buttons">15</integer>
 
+    <dimen name="fake_action_bar_height">48dp</dimen>
     <!-- Min with of fake menu buttons, which should be same as ActionBar's one -->
-    <dimen name="fake_menu_button_min_width">56dip</dimen>
+    <dimen name="fake_menu_button_min_width">56dp</dimen>
 
     <!--  Smart Dial -->
     <dimen name="smartdial_suggestions_padding">4dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e1f1b0d..7d4a4d9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -302,6 +302,10 @@
     -->
     <string name="description_digits_edittext">number to dial</string>
 
+    <!-- Content description for the fake action menu button that brings up the call history
+         activity -->
+    <string name="action_menu_call_history_description">Call History</string>
+
     <!-- Content description for the fake action menu overflow button.
          This should be same as the description for the real action menu
          overflow button available in ActionBar.
@@ -523,6 +527,10 @@
          [CHAR LIMIT=15] -->
     <string name="call_log_missed_title">Missed</string>
 
+    <!-- String resource for the font-family to use for the call log activity's title
+         Do not translate. -->
+    <string name="call_log_activity_title_font_family">sans-serif-light</string>
+
     <!-- Text displayed when the list of missed calls is empty -->
     <string name="recentMissed_empty">No recent missed calls.</string>
 
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0cdf223..86df4ae 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -73,7 +73,6 @@
         <item name="android:actionBarStyle">@style/DialtactsActionBarStyleNew</item>
         <item name="android:actionBarTabStyle">@style/DialtactsActionBarTabStyle</item>
         <item name="android:windowContentOverlay">@null</item>
-        <item name="android:windowBackground">@color/background_dialer_light</item>
         <!--  Searchbox Style -->
         <item name="android:editTextStyle">@style/DialtactsSearchboxStyle</item>
         <item name="android:listViewStyle">@style/ListViewStyle</item>
@@ -81,9 +80,9 @@
         <item name="section_header_background">@drawable/list_title_holo</item>
         <item name="list_section_header_height">32dip</item>
         <item name="list_item_divider">?android:attr/listDivider</item>
-        <item name="list_item_padding_top">0dip</item>
+        <item name="list_item_padding_top">8dip</item>
         <item name="list_item_padding_right">0dip</item>
-        <item name="list_item_padding_bottom">0dip</item>
+        <item name="list_item_padding_bottom">8dip</item>
         <item name="list_item_padding_left">0dip</item>
         <item name="list_item_gap_between_image_and_text">8dip</item>
         <item name="list_item_gap_between_label_and_data">5dip</item>
@@ -100,7 +99,7 @@
         <item name="list_item_header_underline_color">@color/people_app_theme_color</item>
         <item name="list_item_data_width_weight">5</item>
         <item name="list_item_label_width_weight">3</item>
-        <item name="contact_browser_list_padding_left">16dip</item>
+        <item name="contact_browser_list_padding_left">8dip</item>
         <item name="contact_browser_list_padding_right">0dip</item>
         <item name="contact_browser_background">@android:color/transparent</item>
         <item name="list_item_text_indent">@dimen/contact_browser_list_item_text_indent</item>
diff --git a/src/com/android/dialer/NewDialtactsActivity.java b/src/com/android/dialer/NewDialtactsActivity.java
index 54e7df2..0229c6b 100644
--- a/src/com/android/dialer/NewDialtactsActivity.java
+++ b/src/com/android/dialer/NewDialtactsActivity.java
@@ -38,6 +38,7 @@
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Intents.UI;
 import android.provider.Settings;
+import android.telephony.TelephonyManager;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
@@ -82,7 +83,8 @@
 public class NewDialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
         NewDialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener,
         OnListFragmentScrolledListener,
-        NewPhoneFavoriteFragment.OnPhoneFavoriteFragmentStartedListener {
+        NewPhoneFavoriteFragment.OnPhoneFavoriteFragmentStartedListener,
+        NewDialpadFragment.OnDialpadFragmentStartedListener {
     private static final String TAG = "DialtactsActivity";
 
     public static final boolean DEBUG = false;
@@ -106,14 +108,6 @@
      */
     private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
 
-    private SharedPreferences mPrefs;
-
-    public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
-
-    /** Last manually selected tab index */
-    private static final String PREF_LAST_MANUALLY_SELECTED_TAB =
-            "DialtactsActivity_last_manually_selected_tab";
-
     private static final int SUBACTIVITY_ACCOUNT_FILTER = 1;
 
     private String mFilterText;
@@ -155,12 +149,6 @@
     private EditText mSearchView;
 
     /**
-     * The index of the Fragment (or, the tab) that has last been manually selected.
-     * This value does not keep track of programmatically set Tabs (e.g. Call Log after a Call)
-     */
-    private int mLastManuallySelectedFragment;
-
-    /**
      * Listener used when one of phone numbers in search UI is selected. This will initiate a
      * phone call using the phone number.
      */
@@ -256,16 +244,7 @@
         mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding);
         prepareSearchView();
 
-        // Load the last manually loaded tab
-        mPrefs = this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
-
-        /*
-         * TODO krelease : Remember which fragment was last displayed, and then redisplay it as
-         * necessary. mLastManuallySelectedFragment = mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB,
-         * PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT); if (mLastManuallySelectedFragment >=
-         * TAB_INDEX_COUNT) { // Stored value may have exceeded the number of current tabs. Reset
-         * it. mLastManuallySelectedFragment = PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT; }
-         */
+        displayFragment(intent);
 
         if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction())
                 && savedInstanceState == null) {
@@ -335,6 +314,7 @@
     @Override
     public void onClick(View view) {
         switch (view.getId()) {
+            case R.id.overflow_menu_on_dialpad:
             case R.id.overflow_menu: {
                 final PopupMenu popupMenu = new PopupMenu(NewDialtactsActivity.this, view);
                 final Menu menu = popupMenu.getMenu();
@@ -344,9 +324,13 @@
                 break;
             }
             case R.id.dialpad_button:
-                showDialpadFragment();
+                showDialpadFragment(true);
                 break;
+            case R.id.call_history_on_dialpad_button:
             case R.id.call_history_button:
+                // TODO krelease: This should start an intent with content type
+                // CallLog.Calls.CONTENT_TYPE, once the intent filters for the call log activity
+                // is enabled
                 final Intent intent = new Intent(this, NewCallLogActivity.class);
                 startActivity(intent);
                 break;
@@ -363,16 +347,20 @@
         }
     }
 
-    private void showDialpadFragment() {
+    private void showDialpadFragment(boolean animate) {
         final FragmentTransaction ft = getFragmentManager().beginTransaction();
-        ft.setCustomAnimations(R.anim.slide_in, 0);
+        if (animate) {
+            ft.setCustomAnimations(R.anim.slide_in, 0);
+        }
         ft.show(mDialpadFragment);
         ft.commit();
     }
 
-    private void hideDialpadFragment() {
+    private void hideDialpadFragment(boolean animate) {
         final FragmentTransaction ft = getFragmentManager().beginTransaction();
-        ft.setCustomAnimations(0, R.anim.slide_out);
+        if (animate) {
+            ft.setCustomAnimations(0, R.anim.slide_out);
+        }
         ft.hide(mDialpadFragment);
         ft.commit();
     }
@@ -397,7 +385,7 @@
 
     private void hideDialpadFragmentIfNecessary() {
         if (mDialpadFragment.isVisible()) {
-            hideDialpadFragment();
+            hideDialpadFragment(true);
         }
     }
 
@@ -450,7 +438,7 @@
     }
 
 
-    public void setupFakeActionBarItems() {
+    public void setupFakeActionBarItemsForFavoritesFragment() {
         mMenuButton = findViewById(R.id.overflow_menu);
         if (mMenuButton != null) {
             // mMenuButton.setMinimumWidth(fakeMenuItemWidth);
@@ -471,17 +459,11 @@
         mDialpadButton.setOnClickListener(this);
     }
 
-    @Override
-    protected void onPause() {
-        super.onPause();
-        mPrefs.edit().putInt(PREF_LAST_MANUALLY_SELECTED_TAB, mLastManuallySelectedFragment)
-                .apply();
-        requestBackup();
-    }
-
-    private void requestBackup() {
-        final BackupManager bm = new BackupManager(this);
-        bm.dataChanged();
+    public void setupFakeActionBarItemsForDialpadFragment() {
+        final View overflowButton = findViewById(R.id.overflow_menu_on_dialpad);
+        overflowButton.setOnClickListener(this);
+        final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button);
+        callhistoryButton.setOnClickListener(this);
     }
 
     private void fixIntent(Intent intent) {
@@ -537,6 +519,14 @@
             finish();
             return;
         }
+
+        if ((mDialpadFragment != null && phoneIsInUse())
+                || isDialIntent(intent)) {
+            mDialpadFragment.setStartedFromNewIntent(true);
+            // TODO krelease: This should use showDialpadFragment(false) to avoid animating
+            // the dialpad in. Need to fix the onPreDrawListener in NewDialpadFragment first.
+            showDialpadFragment(true);
+        }
     }
 
     @Override
@@ -545,9 +535,7 @@
         fixIntent(newIntent);
         displayFragment(newIntent);
         final String action = newIntent.getAction();
-        if (UI.FILTER_CONTACTS_ACTION.equals(action)) {
-            setupFilterText(newIntent);
-        }
+
         if (mInSearchUi || (mRegularSearchFragment != null && mRegularSearchFragment.isVisible())) {
             exitSearchUi();
         }
@@ -714,7 +702,7 @@
     @Override
     public void onBackPressed() {
         if (mDialpadFragment.isVisible()) {
-            hideDialpadFragment();
+            hideDialpadFragment(true);
         } else if (mInSearchUi) {
             mSearchView.setText(null);
         } else if (isTaskRoot()) {
@@ -747,6 +735,17 @@
 
     @Override
     public void onPhoneFavoriteFragmentStarted() {
-        setupFakeActionBarItems();
+        setupFakeActionBarItemsForFavoritesFragment();
+    }
+
+    @Override
+    public void onDialpadFragmentStarted() {
+        setupFakeActionBarItemsForDialpadFragment();
+    }
+
+    private boolean phoneIsInUse() {
+        final TelephonyManager tm = (TelephonyManager) getSystemService(
+                Context.TELEPHONY_SERVICE);
+        return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE;
     }
 }
diff --git a/src/com/android/dialer/NewSearchFragment.java b/src/com/android/dialer/NewSearchFragment.java
index c428db2..0ddee42 100644
--- a/src/com/android/dialer/NewSearchFragment.java
+++ b/src/com/android/dialer/NewSearchFragment.java
@@ -16,16 +16,12 @@
 package com.android.dialer;
 
 import android.app.Activity;
-import android.os.Bundle;
 import android.view.LayoutInflater;
-import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AbsListView;
 import android.widget.AbsListView.OnScrollListener;
-import android.widget.ListView;
 
 import com.android.contacts.common.list.ContactListItemView;
-import com.android.contacts.common.list.PhoneNumberListAdapter;
 import com.android.contacts.common.list.PhoneNumberPickerFragment;
 import com.android.dialer.list.OnListFragmentScrolledListener;
 
diff --git a/src/com/android/dialer/calllog/NewCallLogActivity.java b/src/com/android/dialer/calllog/NewCallLogActivity.java
index a25729a..d8724cf 100644
--- a/src/com/android/dialer/calllog/NewCallLogActivity.java
+++ b/src/com/android/dialer/calllog/NewCallLogActivity.java
@@ -29,6 +29,9 @@
 import android.support.v4.view.PagerTabStrip;
 import android.support.v4.view.ViewPager;
 import android.support.v4.view.ViewPager.OnPageChangeListener;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.style.TypefaceSpan;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -119,6 +122,11 @@
         actionBar.setDisplayHomeAsUpEnabled(true);
         actionBar.setDisplayShowTitleEnabled(true);
 
+        final SpannableString s = new SpannableString(getString(R.string.call_log_activity_title));
+        s.setSpan(new TypefaceSpan(getString(R.string.call_log_activity_title_font_family)), 0,
+                s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+        actionBar.setTitle(s);
+
         final Tab allTab = actionBar.newTab();
         final String allTitle = getString(R.string.call_log_all_title);
         allTab.setContentDescription(allTitle);
diff --git a/src/com/android/dialer/dialpad/NewDialpadFragment.java b/src/com/android/dialer/dialpad/NewDialpadFragment.java
index b1b25a7..659c608 100644
--- a/src/com/android/dialer/dialpad/NewDialpadFragment.java
+++ b/src/com/android/dialer/dialpad/NewDialpadFragment.java
@@ -102,6 +102,10 @@
         DialpadKeyButton.OnPressedListener {
     private static final String TAG = NewDialpadFragment.class.getSimpleName();
 
+    public interface OnDialpadFragmentStartedListener {
+        public void onDialpadFragmentStarted();
+    }
+
     /**
      * LinearLayout with getter and setter methods for the translationY property using floats,
      * for animation purposes.
@@ -155,8 +159,6 @@
 
     private OnDialpadQueryChangedListener mDialpadQueryListener;
 
-    private View mFragmentView;
-
     /**
      * View (usually FrameLayout) containing mDigits field. This can be null, in which mDigits
      * isn't enclosed by the container.
@@ -340,22 +342,22 @@
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
-        View fragmentView = inflater.inflate(R.layout.new_dialpad_fragment, container, false);
-        mFragmentView = fragmentView;
-        mFragmentView.buildLayer();
+        final View fragmentView = inflater.inflate(R.layout.new_dialpad_fragment, container,
+                false);
+        fragmentView.buildLayer();
 
         // TODO krelease: Get rid of this ugly hack which is to prevent the first frame of the
         // animation from drawing the fragment at translationY = 0
-        final ViewTreeObserver vto = mFragmentView.getViewTreeObserver();
+        final ViewTreeObserver vto = fragmentView.getViewTreeObserver();
         final OnPreDrawListener preDrawListener = new OnPreDrawListener() {
 
             @Override
             public boolean onPreDraw() {
                 if (isHidden()) return true;
-                if (mFragmentView.getTranslationY() == 0) {
-                    ((DialpadSlidingLinearLayout) mFragmentView).setYFraction(0.67f);
+                if (fragmentView.getTranslationY() == 0) {
+                    ((DialpadSlidingLinearLayout) fragmentView).setYFraction(0.67f);
                 }
-                final ViewTreeObserver vto = mFragmentView.getViewTreeObserver();
+                final ViewTreeObserver vto = fragmentView.getViewTreeObserver();
                 vto.removeOnPreDrawListener(this);
                 return true;
             }
@@ -381,18 +383,6 @@
             setupKeypad(fragmentView);
         }
 
-        DisplayMetrics dm = getResources().getDisplayMetrics();
-        int minCellSize = (int) (56 * dm.density); // 56dip == minimum size of menu buttons
-        int cellCount = dm.widthPixels / minCellSize;
-        int fakeMenuItemWidth = dm.widthPixels / cellCount;
-        mDialButtonContainer = fragmentView.findViewById(R.id.dialButtonContainer);
-        // If in portrait, add padding to the dial button since we need space for the
-        // search and menu/overflow buttons.
-        if (mDialButtonContainer != null && !OrientationUtil.isLandscape(this.getActivity())) {
-            mDialButtonContainer.setPadding(
-                    fakeMenuItemWidth, mDialButtonContainer.getPaddingTop(),
-                    fakeMenuItemWidth, mDialButtonContainer.getPaddingBottom());
-        }
         mDialButton = fragmentView.findViewById(R.id.dialButton);
         if (r.getBoolean(R.bool.config_show_onscreen_dial_button)) {
             mDialButton.setOnClickListener(this);
@@ -424,6 +414,20 @@
         return fragmentView;
     }
 
+    @Override
+    public void onStart() {
+        super.onStart();
+
+        final Activity activity = getActivity();
+
+        try {
+            ((OnDialpadFragmentStartedListener) activity).onDialpadFragmentStarted();
+        } catch (ClassCastException e) {
+            throw new ClassCastException(activity.toString()
+                    + " must implement OnDialpadFragmentStartedListener");
+        }
+    }
+
     private boolean isLayoutReady() {
         return mDigits != null;
     }
@@ -505,11 +509,10 @@
      */
     private void configureScreenFromIntent(Activity parent) {
         // If we were not invoked with a DIAL intent,
-        if (!(parent instanceof DialtactsActivity)) {
+        if (!(parent instanceof NewDialtactsActivity)) {
             setStartedFromNewIntent(false);
             return;
         }
-
         // See if we were invoked with a DIAL intent. If we were, fill in the appropriate
         // digits in the dialer field.
         Intent intent = parent.getIntent();
diff --git a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
index db2999c..a181fb0 100644
--- a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
+++ b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
@@ -172,20 +172,9 @@
     }
 
     private class ScrollListener implements ListView.OnScrollListener {
-        private boolean mShouldShowFastScroller;
         @Override
         public void onScroll(AbsListView view,
                 int firstVisibleItem, int visibleItemCount, int totalItemCount) {
-            // FastScroller should be visible only when the user is seeing "all" contacts section.
-            final boolean shouldShow = mAdapter.shouldShowFirstScroller(firstVisibleItem);
-            if (shouldShow != mShouldShowFastScroller) {
-                mListView.setVerticalScrollBarEnabled(shouldShow);
-                mListView.setFastScrollEnabled(shouldShow);
-                mListView.setFastScrollAlwaysVisible(shouldShow);
-                mShouldShowFastScroller = shouldShow;
-            }
-
-
         }
 
         @Override
@@ -343,8 +332,7 @@
         mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false);
 
         mAdapter = new NewPhoneFavoriteMergedAdapter(getActivity(),
-                mContactTileAdapter, mAccountFilterHeaderContainer, mAllContactsAdapter,
-                mCallLogAdapter, mLoadingView);
+                mContactTileAdapter, mAccountFilterHeaderContainer, mCallLogAdapter, mLoadingView);
 
         mListView.setAdapter(mAdapter);
 
diff --git a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
index 742892b..d42189e 100644
--- a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
+++ b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
@@ -32,13 +32,10 @@
 import com.android.dialer.calllog.NewCallLogAdapter;
 
 /**
- * An adapter that combines items from {@link com.android.contacts.common.list.ContactTileAdapter} and
- * {@link com.android.contacts.common.list.ContactEntryListAdapter} into a single list.
- * In between those two results, an account filter header will be inserted.
- *
- * Has one extra view at the top: The most recent call/voicemail/missed call.
+ * An adapter that combines items from {@link com.android.contacts.common.list.ContactTileAdapter}
+ * and {@link com.android.dialer.calllog.NewCallLogAdapter} into a single list.
  */
-public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements SectionIndexer {
+public class NewPhoneFavoriteMergedAdapter extends BaseAdapter {
 
     private class CustomDataSetObserver extends DataSetObserver {
         @Override
@@ -50,17 +47,9 @@
     private static final String TAG = NewPhoneFavoriteMergedAdapter.class.getSimpleName();
 
     private final PhoneFavoritesTileAdapter mContactTileAdapter;
-    private final ContactEntryListAdapter mContactEntryListAdapter;
     private final NewCallLogAdapter mCallLogAdapter;
-    private final View mAccountFilterHeaderContainer;
     private final View mLoadingView;
 
-    // TODO krelease: Add a setting to toggle mShowAllContacts, and really handle it
-    // properly below.
-    private boolean mShowAllContacts = false;
-
-    private final int mItemPaddingLeft;
-    private final int mItemPaddingRight;
     private final int mCallLogPadding;
 
     private final Context mContext;
@@ -70,23 +59,16 @@
     public NewPhoneFavoriteMergedAdapter(Context context,
             PhoneFavoritesTileAdapter contactTileAdapter,
             View accountFilterHeaderContainer,
-            ContactEntryListAdapter contactEntryListAdapter,
             NewCallLogAdapter callLogAdapter,
             View loadingView) {
         final Resources resources = context.getResources();
         mContext = context;
-        mItemPaddingLeft = resources.getDimensionPixelSize(R.dimen.detail_item_side_margin);
-        mItemPaddingRight = resources.getDimensionPixelSize(R.dimen.list_visible_scrollbar_padding);
         mCallLogPadding = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding);
         mContactTileAdapter = contactTileAdapter;
-        mContactEntryListAdapter = contactEntryListAdapter;
         mCallLogAdapter = callLogAdapter;
 
-        mAccountFilterHeaderContainer = accountFilterHeaderContainer;
-
         mObserver = new CustomDataSetObserver();
         mContactTileAdapter.registerDataSetObserver(mObserver);
-        mContactEntryListAdapter.registerDataSetObserver(mObserver);
         mLoadingView = loadingView;
     }
 
@@ -94,59 +76,29 @@
     public boolean isEmpty() {
         // Cannot use the super's method here because we add extra rows in getCount() to account
         // for headers
-        return mCallLogAdapter.getCount() + mContactTileAdapter.getCount() +
-                mContactEntryListAdapter.getCount() == 0;
+        return mCallLogAdapter.getCount() + mContactTileAdapter.getCount() == 0;
     }
 
     @Override
     public int getCount() {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        final int contactEntryListAdapterCount = mShowAllContacts ?
-                mContactEntryListAdapter.getCount() : 0;
-
-        final int callLogAdapterCount = mCallLogAdapter.getCount();
-
-        if (mShowAllContacts && mContactEntryListAdapter.isLoading()) {
-            // Hide "all" contacts during its being loaded. Instead show "loading" view.
-            //
-            // "+2" for mAccountFilterHeaderContainer and mLoadingView
-            return contactTileAdapterCount + 1 + (mShowAllContacts ? 1 : 0) +
-                    callLogAdapterCount;
-        } else {
-            // "+1" for mAccountFilterHeaderContainer
-            return contactTileAdapterCount + contactEntryListAdapterCount +
-                    (mShowAllContacts ? 1 : 0) + callLogAdapterCount;
-        }
+        return mContactTileAdapter.getCount() + mCallLogAdapter.getCount();
     }
 
     @Override
     public Object getItem(int position) {
         final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        final int contactEntryListAdapterCount = mShowAllContacts ?
-                mContactEntryListAdapter.getCount() : 0;
 
         final int callLogAdapterCount = mCallLogAdapter.getCount();
 
-        // TODO krelease: Calculate the position properly.
         if (callLogAdapterCount > 0) {
             if (position < callLogAdapterCount) {
                 return mCallLogAdapter.getItem(position);
             }
-            position -= callLogAdapterCount;
+            // Set position to the position of the actual favorite contact in the favorites adapter
+            position = getAdjustedFavoritePosition(position, callLogAdapterCount);
         }
 
-        if (position < contactTileAdapterCount) {  // For "tile" and "frequent" sections
-            return mContactTileAdapter.getItem(position);
-        } else {  // For "all" section
-            if (mShowAllContacts && mContactEntryListAdapter.isLoading()) {
-                // "All" section is being loaded.
-                return mLoadingView;
-            } else {
-                // "-1" for mAccountFilterHeaderContainer
-                final int localPosition = position - contactTileAdapterCount - 1;
-                return mContactTileAdapter.getItem(localPosition);
-            }
-        }
+        return mContactTileAdapter.getItem(position);
     }
 
     @Override
@@ -156,78 +108,20 @@
 
     @Override
     public int getViewTypeCount() {
-        // "+1" for mLoadingView
-        return (mContactTileAdapter.getViewTypeCount()
-                + mContactEntryListAdapter.getViewTypeCount()
-                + 1
-                + mCallLogAdapter.getViewTypeCount());
+        return (mContactTileAdapter.getViewTypeCount() + mCallLogAdapter.getViewTypeCount());
     }
 
     @Override
     public int getItemViewType(int position) {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-
-        final int contactEntryListAdapterCount = mShowAllContacts ?
-                mContactEntryListAdapter.getCount() : 0;
-
         final int callLogAdapterCount = mCallLogAdapter.getCount();
 
-        if (callLogAdapterCount > 0) {
-            if (position == 0) {
-                return mContactTileAdapter.getViewTypeCount() +
-                        mContactEntryListAdapter.getViewTypeCount() + 2;
-            }
-            // Ignore the first position when calculating view types of all other items
-            position -= callLogAdapterCount;
-        }
-
-        // There should be four kinds of types that are usually used, and one more exceptional
-        // type (IGNORE_ITEM_VIEW_TYPE), which sometimes comes from mContactTileAdapter.
-        //
-        // The four ordinary view types have the index equal to or more than 0, and less than
-        // mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount() + 2.
-        // (See also this class's getViewTypeCount())
-        //
-        // We have those values for:
-        // - The view types mContactTileAdapter originally has
-        // - The view types mContactEntryListAdapter originally has
-        // - mAccountFilterHeaderContainer ("all" section's account header), and
-        // - mLoadingView
-        //
-        // Those types should not be mixed, so we have a different range for each kinds of types:
-        // - Types for mContactTileAdapter ("tile" and "frequent" sections)
-        //   They should have the index, >=0 and <mContactTileAdapter.getViewTypeCount()
-        //
-        // - Types for mContactEntryListAdapter ("all" sections)
-        //   They should have the index, >=mContactTileAdapter.getViewTypeCount() and
-        //   <(mContactTileAdapter.getViewTypeCount() + mContactEntryListAdapter.getViewTypeCount())
-        //
-        // - Type for "all" section's account header
-        //   It should have the exact index
-        //   mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount()
-        //
-        // - Type for "loading" view used during "all" section is being loaded.
-        //   It should have the exact index
-        //   mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount() + 1
-        //
-        // As an exception, IGNORE_ITEM_VIEW_TYPE (-1) will be remained as is, which will be used
-        // by framework's Adapter implementation and thus should be left as is.
-        if (position < contactTileAdapterCount) {  // For "tile" and "frequent" sections
-            return mContactTileAdapter.getItemViewType(position);
-        } else if (position == contactTileAdapterCount) {  // For "all" section's account header
-            return mContactTileAdapter.getViewTypeCount()
-                    + mContactEntryListAdapter.getViewTypeCount();
-        } else {  // For "all" section
-            if (mContactEntryListAdapter.isLoading()) {  // "All" section is being loaded.
-                return mContactTileAdapter.getViewTypeCount()
-                        + mContactEntryListAdapter.getViewTypeCount() + 1;
-            } else {
-                // "-1" for mAccountFilterHeaderContainer
-                final int localPosition = position - contactTileAdapterCount - 1;
-                final int type = mContactEntryListAdapter.getItemViewType(localPosition);
-                // IGNORE_ITEM_VIEW_TYPE must be handled differently.
-                return (type < 0) ? type : type + mContactTileAdapter.getViewTypeCount();
-            }
+        if (position < callLogAdapterCount) {
+            // View type of the call log adapter is the last view type of the contact tile adapter
+            // + 1
+            return mContactTileAdapter.getViewTypeCount();
+        } else {
+            return mContactTileAdapter.getItemViewType(
+                    getAdjustedFavoritePosition(position, callLogAdapterCount));
         }
     }
 
@@ -235,12 +129,8 @@
     public View getView(int position, View convertView, ViewGroup parent) {
         final int contactTileAdapterCount = mContactTileAdapter.getCount();
 
-        final int contactEntryListAdapterCount = mShowAllContacts ?
-                mContactEntryListAdapter.getCount() : 0;
-
         final int callLogAdapterCount = mCallLogAdapter.getCount();
 
-        // TODO krelease: Handle the new callLogAdapterCount and position offsets properly
         if (callLogAdapterCount > 0) {
             if (position == 0) {
                 final FrameLayout wrapper;
@@ -270,42 +160,22 @@
 
                 return wrapper;
             }
-            position -= callLogAdapterCount;
+            // Set position to the position of the actual favorite contact in the
+            // favorites adapter
+            position = getAdjustedFavoritePosition(position, callLogAdapterCount);
         }
 
-        // Obtain a View relevant for that position, and adjust its horizontal padding. Each
-        // View has different implementation, so we use different way to control those padding.
-        if (position < contactTileAdapterCount) {  // For "tile" and "frequent" sections
-            final View view = mContactTileAdapter.getView(position, convertView, parent);
-            final int frequentHeaderPosition = mContactTileAdapter.getFrequentHeaderPosition();
-            // TODO krelease: Get rid of frequent header position, we don't need it anymore
-            if (position >= frequentHeaderPosition) {
-                final FrameLayout frameLayout = (FrameLayout) view;
-                final View child = frameLayout.getChildAt(0);
-                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
-                        FrameLayout.LayoutParams.WRAP_CONTENT,
-                        FrameLayout.LayoutParams.WRAP_CONTENT);
-                child.setLayoutParams(params);
-            }
-            return view;
-        } else {  // For "all" section
-            if (mShowAllContacts && mContactEntryListAdapter.isLoading()) {
-                // "All" section is being loaded.
-                mLoadingView.setPadding(mItemPaddingLeft,
-                        mLoadingView.getPaddingTop(),
-                        mItemPaddingRight,
-                        mLoadingView.getPaddingBottom());
-                return mLoadingView;
-            } else {
-                final int localPosition = position - contactTileAdapterCount;
-                final ContactListItemView itemView = (ContactListItemView)
-                        mContactEntryListAdapter.getView(localPosition, convertView, null);
-                itemView.setPadding(mItemPaddingLeft, itemView.getPaddingTop(),
-                        mItemPaddingRight, itemView.getPaddingBottom());
-                itemView.setSelectionBoundsHorizontalMargin(mItemPaddingLeft, mItemPaddingRight);
-                return itemView;
-            }
+        // Favorites section
+        final View view = mContactTileAdapter.getView(position, convertView, parent);
+        if (position >= mContactTileAdapter.getMaxTiledRows()) {
+            final FrameLayout frameLayout = (FrameLayout) view;
+            final View child = frameLayout.getChildAt(0);
+            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
+                    FrameLayout.LayoutParams.WRAP_CONTENT,
+                    FrameLayout.LayoutParams.WRAP_CONTENT);
+            child.setLayoutParams(params);
         }
+        return view;
     }
 
     @Override
@@ -313,58 +183,23 @@
         // If "all" section is being loaded we'll show mLoadingView, which is not enabled.
         // Otherwise check the all the other components in the ListView and return appropriate
         // result.
-        return !mContactEntryListAdapter.isLoading()
-                && (mContactTileAdapter.areAllItemsEnabled()
-                && mAccountFilterHeaderContainer.isEnabled()
-                && mContactEntryListAdapter.areAllItemsEnabled());
+        return mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled();
     }
 
     @Override
     public boolean isEnabled(int position) {
+        final int callLogAdapterCount = mCallLogAdapter.getCount();
         final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        final int contactEntryListAdapterCount = mContactEntryListAdapter.getCount();
-        if (position < contactTileAdapterCount) {  // For "tile" and "frequent" sections
-            return mContactTileAdapter.isEnabled(position);
-        } else if (position == contactTileAdapterCount) {  // For "all" section's account header
-            // This will be handled by View's onClick event instead of ListView's onItemClick event.
-            return false;
-        } else {  // For "all" section
-            if (mContactEntryListAdapter.isLoading()) {  // "All" section is being loaded.
-                return false;
-            } else {
-                // "-1" for mAccountFilterHeaderContainer
-                final int localPosition = position - contactTileAdapterCount - 1;
-                return mContactEntryListAdapter.isEnabled(localPosition);
-            }
+        if (position < callLogAdapterCount) {
+            return mCallLogAdapter.isEnabled(position);
+        } else { // For favorites section
+            return mContactTileAdapter.isEnabled(
+                    getAdjustedFavoritePosition(position, callLogAdapterCount));
         }
     }
 
-    @Override
-    public int getPositionForSection(int sectionIndex) {
-        // frequent header view.
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        final int localPosition = mContactEntryListAdapter.getPositionForSection(sectionIndex);
-        return contactTileAdapterCount + localPosition;
+    private int getAdjustedFavoritePosition(int position, int callLogAdapterCount) {
+        return position - callLogAdapterCount;
     }
 
-    @Override
-    public int getSectionForPosition(int position) {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        if (position <= contactTileAdapterCount) {
-            return 0;
-        } else {
-            final int localPosition = position - contactTileAdapterCount;
-            return mContactEntryListAdapter.getSectionForPosition(localPosition);
-        }
-    }
-
-    @Override
-    public Object[] getSections() {
-        return mContactEntryListAdapter.getSections();
-    }
-
-    public boolean shouldShowFirstScroller(int firstVisibleItem) {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-        return firstVisibleItem > contactTileAdapterCount;
-    }
 }
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index f859e85..3657906 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -225,6 +225,10 @@
         return total - (mMaxTiledRows * (mColumnCount - 1));
     }
 
+    public int getMaxTiledRows() {
+        return mMaxTiledRows;
+    }
+
     /**
      * Returns the number of rows required to show the provided number of entries
      * with the current number of columns.