Adds all contacts fragment.

Change-Id: Iea03cbb82c9ca9fdff51686a722bea5d301add44
diff --git a/res/drawable-hdpi/ic_menu_all_contacts_dk.png b/res/drawable-hdpi/ic_menu_all_contacts_dk.png
new file mode 100644
index 0000000..88ba4f1
--- /dev/null
+++ b/res/drawable-hdpi/ic_menu_all_contacts_dk.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_all_contacts_dk.png b/res/drawable-mdpi/ic_menu_all_contacts_dk.png
new file mode 100644
index 0000000..03af9c4
--- /dev/null
+++ b/res/drawable-mdpi/ic_menu_all_contacts_dk.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_all_contacts_dk.png b/res/drawable-xhdpi/ic_menu_all_contacts_dk.png
new file mode 100644
index 0000000..11bd615
--- /dev/null
+++ b/res/drawable-xhdpi/ic_menu_all_contacts_dk.png
Binary files differ
diff --git a/res/layout/show_all_contact_button.xml b/res/layout/show_all_contact_button.xml
new file mode 100644
index 0000000..824d10c
--- /dev/null
+++ b/res/layout/show_all_contact_button.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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/show_all_contact_button"
+    android:orientation="horizontal"
+    android:clickable="true"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:gravity="center"
+    android:background="?android:attr/selectableItemBackground"
+    android:focusable="true">
+
+    <ImageView
+        android:layout_height="match_parent"
+        android:layout_width="wrap_content"
+        android:layout_gravity="center"
+        android:src="@drawable/ic_menu_all_contacts_dk"
+        android:layout_marginEnd="10dp"/>
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:textSize="14sp"
+        android:ellipsize="marquee"
+        android:singleLine="true"
+        android:text="@string/show_all_contacts_button_text"
+        android:textAlignment="center"
+        android:gravity="center"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/show_all_contacts_fragment.xml b/res/layout/show_all_contacts_fragment.xml
new file mode 100644
index 0000000..0a95f27
--- /dev/null
+++ b/res/layout/show_all_contacts_fragment.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_marginTop="?android:attr/actionBarSize">
+
+    <!-- Shown only when an Account filter is set.
+         - paddingTop should be here to show "shade" effect correctly. -->
+    <!-- TODO {klp} Remove the filter header. -->
+    <include
+        android:id="@+id/account_filter_header_container"
+        layout="@layout/account_filter_header" />
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="0dip"
+        android:layout_weight="1" >
+        <view
+            class="com.android.contacts.common.list.PinnedHeaderListView"
+            style="@style/NewDialtactsTheme"
+            android:id="@android:id/list"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_marginLeft="?attr/contact_browser_list_padding_left"
+            android:layout_marginRight="?attr/contact_browser_list_padding_right"
+            android:layout_marginStart="?attr/contact_browser_list_padding_left"
+            android:layout_marginEnd="?attr/contact_browser_list_padding_right"
+            android:fastScrollEnabled="true"
+            android:fadingEdge="none"/>
+    </FrameLayout>
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3845e2d..06d0a1e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -534,6 +534,10 @@
          Do not translate. -->
     <string name="call_log_activity_title_font_family">sans-serif-light</string>
 
+    <!-- String resource for the font-family to use for show all contacts' title
+         Do not translate. -->
+    <string name="show_all_contacts_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>
 
@@ -597,4 +601,9 @@
     <string name="dialpad_pound_number">#</string>
     <!--  Do not translate. -->
     <string name="dialpad_pound_letters"></string>
+
+    <!--  Title of fragment that displays all contacts -->
+    <string name="show_all_contacts_title">All contacts</string>
+    <!--  Title of show all contacts button -->
+    <string name="show_all_contacts_button_text">All contacts</string>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 86df4ae..e2d7ab4 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -92,11 +92,11 @@
         <item name="list_item_profile_photo_size">70dip</item>
         <item name="list_item_prefix_highlight_color">@color/people_app_theme_color</item>
         <item name="list_item_header_text_indent">8dip</item>
-        <item name="list_item_header_text_color">@color/people_app_theme_color</item>
-        <item name="list_item_header_text_size">14sp</item>
-        <item name="list_item_header_height">24dip</item>
-        <item name="list_item_header_underline_height">1dip</item>
-        <item name="list_item_header_underline_color">@color/people_app_theme_color</item>
+        <item name="list_item_header_text_color">@color/dialtacts_secondary_text_color</item>
+        <item name="list_item_header_text_size">20sp</item>
+        <item name="list_item_header_height">48dip</item>
+        <item name="list_item_header_underline_height">2dip</item>
+        <item name="list_item_header_underline_color">@color/favorite_contacts_separator_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">8dip</item>
diff --git a/src/com/android/dialer/NewDialtactsActivity.java b/src/com/android/dialer/NewDialtactsActivity.java
index 95d9ea7..7ac1b6e 100644
--- a/src/com/android/dialer/NewDialtactsActivity.java
+++ b/src/com/android/dialer/NewDialtactsActivity.java
@@ -39,6 +39,7 @@
 import android.provider.ContactsContract.Intents.UI;
 import android.provider.Settings;
 import android.speech.RecognizerIntent;
+import android.support.v4.app.NavUtils;
 import android.telephony.TelephonyManager;
 import android.text.Editable;
 import android.text.TextUtils;
@@ -72,6 +73,7 @@
 import com.android.dialer.interactions.PhoneNumberInteraction;
 import com.android.dialer.list.NewPhoneFavoriteFragment;
 import com.android.dialer.list.OnListFragmentScrolledListener;
+import com.android.dialer.list.ShowAllContactsFragment;
 import com.android.dialer.list.SmartDialSearchFragment;
 import com.android.internal.telephony.ITelephony;
 
@@ -96,7 +98,6 @@
     private static final String PHONE_PACKAGE = "com.android.phone";
     private static final String CALL_SETTINGS_CLASS_NAME =
             "com.android.phone.CallFeaturesSetting";
-
     /** @see #getCallOrigin() */
     private static final String CALL_ORIGIN_DIALTACTS =
             "com.android.dialer.DialtactsActivity";
@@ -105,6 +106,7 @@
     private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
     private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
     private static final String TAG_FAVORITES_FRAGMENT = "favorites";
+    private static final String TAG_SHOW_ALL_CONTACTS_FRAGMENT = "show_all_contacts";
 
     /**
      * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
@@ -137,6 +139,8 @@
      */
     private SmartDialSearchFragment mSmartDialSearchFragment;
 
+    private ShowAllContactsFragment mShowAllContactsFragment;
+
     private View mMenuButton;
     private View mCallHistoryButton;
     private View mDialpadButton;
@@ -237,20 +241,22 @@
 
         if (savedInstanceState == null) {
             mPhoneFavoriteFragment = new NewPhoneFavoriteFragment();
-            mPhoneFavoriteFragment.setRetainInstance(true);
             mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener);
 
             mRegularSearchFragment = new NewSearchFragment();
             mSmartDialSearchFragment = new SmartDialSearchFragment();
             mDialpadFragment = new NewDialpadFragment();
+            mShowAllContactsFragment = new ShowAllContactsFragment();
+            mShowAllContactsFragment.setOnPhoneNumberPickerActionListener(
+                    mPhoneNumberPickerActionListener);
 
             // TODO krelease: load fragments on demand instead of creating all of them at run time
             final FragmentTransaction ft = getFragmentManager().beginTransaction();
             ft.add(R.id.dialtacts_frame, mPhoneFavoriteFragment, TAG_FAVORITES_FRAGMENT);
             ft.add(R.id.dialtacts_frame, mRegularSearchFragment, TAG_REGULAR_SEARCH_FRAGMENT);
             ft.add(R.id.dialtacts_frame, mSmartDialSearchFragment, TAG_SMARTDIAL_SEARCH_FRAGMENT);
+            ft.add(R.id.dialtacts_frame, mShowAllContactsFragment, TAG_SHOW_ALL_CONTACTS_FRAGMENT);
             ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
-            // Fragments will be hidden as necessary in onAttachFragment
             ft.commit();
         }
 
@@ -282,12 +288,18 @@
                 TAG_SMARTDIAL_SEARCH_FRAGMENT);
         mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(
                 mPhoneNumberPickerActionListener);
+
+        mShowAllContactsFragment = (ShowAllContactsFragment) fm.findFragmentByTag(
+                TAG_SHOW_ALL_CONTACTS_FRAGMENT);
+        mShowAllContactsFragment.setOnPhoneNumberPickerActionListener(
+                mPhoneNumberPickerActionListener);
     }
 
     @Override
     public void onAttachFragment(Fragment fragment) {
         if (fragment instanceof NewDialpadFragment || fragment instanceof NewSearchFragment
-                || fragment instanceof SmartDialSearchFragment) {
+                || fragment instanceof SmartDialSearchFragment
+                || fragment instanceof ShowAllContactsFragment) {
             final FragmentTransaction transaction = getFragmentManager().beginTransaction();
             transaction.hide(fragment);
             transaction.commit();
@@ -297,6 +309,16 @@
     }
 
     @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            // Respond to the action bar's Up/Home button
+            case android.R.id.home:
+                hideAllContactsFragment();
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
     public boolean onMenuItemClick(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.menu_import_export:
@@ -314,7 +336,8 @@
                 try {
                     startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
                 } catch (ActivityNotFoundException e) {
-                    Toast toast = Toast.makeText(this, R.string.add_contact_not_available,
+                    Toast toast = Toast.makeText(this,
+                            R.string.add_contact_not_available,
                             Toast.LENGTH_SHORT);
                     toast.show();
                 }
@@ -402,6 +425,23 @@
         ft.commit();
     }
 
+    public void showAllContactsFragment() {
+        final FragmentTransaction ft = getFragmentManager().beginTransaction();
+        ft.hide(mPhoneFavoriteFragment);
+        ft.show(mShowAllContactsFragment);
+        // TODO{klp} Add animation
+        ft.commit();
+        hideSearchBar(false);
+    }
+
+    private void hideAllContactsFragment() {
+        final FragmentTransaction ft = getFragmentManager().beginTransaction();
+        ft.hide(mShowAllContactsFragment);
+        ft.show(mPhoneFavoriteFragment);
+        ft.commit();
+        showSearchBar();
+    }
+
     private void prepareSearchView() {
         mSearchViewContainer = findViewById(R.id.search_view_container);
         mSearchViewCloseButton = findViewById(R.id.search_close_button);
@@ -435,26 +475,29 @@
     };
 
     public void hideSearchBar() {
-        // If the favorites fragment hasn't been fully created before the dialpad fragment
-        // is hidden (i.e. onResume), don't bother animating
-        if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) {
-            return;
-        }
-        mSearchViewContainer.animate().cancel();
-        mSearchViewContainer.setAlpha(1);
-        mSearchViewContainer.setTranslationY(0);
-        mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight())
-                .setDuration(200).setListener(mHideListener);
+       hideSearchBar(true);
+    }
 
-        mPhoneFavoriteFragment.getView().animate().withLayer()
-                .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener(
+    public void hideSearchBar(boolean shiftView) {
+        if (shiftView) {
+            mSearchViewContainer.animate().cancel();
+            mSearchViewContainer.setAlpha(1);
+            mSearchViewContainer.setTranslationY(0);
+            mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight())
+                    .setDuration(200).setListener(mHideListener);
+
+            mPhoneFavoriteFragment.getView().animate().withLayer()
+                    .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener(
                     new AnimatorListenerAdapter() {
-                    @Override
+                        @Override
                         public void onAnimationEnd(Animator animation) {
                             mBottomPaddingView.setVisibility(View.VISIBLE);
                             mPhoneFavoriteFragment.getView().setTranslationY(0);
                         }
                     });
+        } else {
+            mSearchViewContainer.setTranslationY(-mSearchView.getHeight());
+        }
     }
 
     public void showSearchBar() {
@@ -468,20 +511,20 @@
         mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight());
         mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200)
                 .setListener(new AnimatorListenerAdapter() {
-                        @Override
-                        public void onAnimationStart(Animator animation) {
+                    @Override
+                    public void onAnimationStart(Animator animation) {
                         mSearchViewContainer.setVisibility(View.VISIBLE);
-                        }
+                    }
                 });
 
         mPhoneFavoriteFragment.getView().setTranslationY(-mSearchViewContainer.getHeight());
         mPhoneFavoriteFragment.getView().animate().withLayer().translationY(0).setDuration(200)
                 .setListener(
                         new AnimatorListenerAdapter() {
-                                @Override
-                                public void onAnimationStart(Animator animation) {
-                                    mBottomPaddingView.setVisibility(View.GONE);
-                                }
+                            @Override
+                            public void onAnimationStart(Animator animation) {
+                                mBottomPaddingView.setVisibility(View.GONE);
+                            }
                         });
     }
 
@@ -745,6 +788,8 @@
             hideDialpadFragment(true);
         } else if (mInSearchUi) {
             mSearchView.setText(null);
+        } else if (mShowAllContactsFragment.isVisible()) {
+            hideAllContactsFragment();
         } else if (isTaskRoot()) {
             // Instead of stopping, simply push this to the back of the stack.
             // This is only done when running at the top of the stack;
diff --git a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
index a181fb0..ba438cf 100644
--- a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
+++ b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java
@@ -19,16 +19,11 @@
 import android.app.Fragment;
 import android.app.LoaderManager;
 import android.content.CursorLoader;
-import android.content.Intent;
 import android.content.Loader;
 import android.database.Cursor;
 import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.provider.ContactsContract.Directory;
-import android.provider.Settings;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -44,10 +39,8 @@
 import com.android.contacts.common.ContactPhotoManager;
 import com.android.contacts.common.ContactTileLoaderFactory;
 import com.android.contacts.common.GeoUtil;
-import com.android.contacts.common.list.ContactListItemView;
 import com.android.contacts.common.list.ContactTileView;
 import com.android.contacts.common.list.PhoneNumberListAdapter;
-import com.android.contacts.common.preference.ContactsPreferences;
 import com.android.dialer.NewDialtactsActivity;
 import com.android.dialer.R;
 import com.android.dialer.calllog.ContactInfoHelper;
@@ -94,19 +87,6 @@
             if (DEBUG) Log.d(TAG, "ContactTileLoaderListener#onLoadFinished");
             mContactTileAdapter.setContactCursor(data);
 
-            if (mAllContactsForceReload) {
-                mAllContactsAdapter.onDataReload();
-                // Use restartLoader() to make LoaderManager to load the section again.
-                getLoaderManager().restartLoader(
-                        LOADER_ID_ALL_CONTACTS, null, mAllContactsLoaderListener);
-            } else if (!mAllContactsLoaderStarted) {
-                // Load "all" contacts if not loaded yet.
-                getLoaderManager().initLoader(
-                        LOADER_ID_ALL_CONTACTS, null, mAllContactsLoaderListener);
-            }
-            mAllContactsForceReload = false;
-            mAllContactsLoaderStarted = true;
-
             // Show the filter header with "loading" state.
             mAccountFilterHeader.setVisibility(View.VISIBLE);
         }
@@ -117,29 +97,6 @@
         }
     }
 
-    private class AllContactsLoaderListener implements LoaderManager.LoaderCallbacks<Cursor> {
-        @Override
-        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            if (DEBUG) Log.d(TAG, "AllContactsLoaderListener#onCreateLoader");
-            CursorLoader loader = new CursorLoader(getActivity(), null, null, null, null, null);
-            mAllContactsAdapter.configureLoader(loader, Directory.DEFAULT);
-            return loader;
-        }
-
-        @Override
-        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
-            if (DEBUG) Log.d(TAG, "AllContactsLoaderListener#onLoadFinished");
-            mAllContactsAdapter.changeCursor(0, data);
-            mHandler.removeMessages(MESSAGE_SHOW_LOADING_EFFECT);
-            mLoadingView.setVisibility(View.VISIBLE);
-        }
-
-        @Override
-        public void onLoaderReset(Loader<Cursor> loader) {
-            if (DEBUG) Log.d(TAG, "AllContactsLoaderListener#onLoaderReset. ");
-        }
-    }
-
     private class ContactTileAdapterListener implements ContactTileView.Listener {
         @Override
         public void onContactSelected(Uri contactUri, Rect targetRect) {
@@ -161,16 +118,6 @@
         }
     }
 
-    private class ContactsPreferenceChangeListener
-            implements ContactsPreferences.ChangeListener {
-        @Override
-        public void onChange() {
-            if (loadContactsPreferences()) {
-                requestReloadAllContacts();
-            }
-        }
-    }
-
     private class ScrollListener implements ListView.OnScrollListener {
         @Override
         public void onScroll(AbsListView view,
@@ -183,19 +130,6 @@
         }
     }
 
-    private static final int MESSAGE_SHOW_LOADING_EFFECT = 1;
-    private static final int LOADING_EFFECT_DELAY = 500;  // ms
-    private final Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MESSAGE_SHOW_LOADING_EFFECT:
-                    mLoadingView.setVisibility(View.VISIBLE);
-                    break;
-            }
-        }
-    };
-
     private Listener mListener;
 
     private OnListFragmentScrolledListener mActivityScrollListener;
@@ -206,21 +140,9 @@
     private NewCallLogAdapter mCallLogAdapter;
     private CallLogQueryHandler mCallLogQueryHandler;
 
-    /**
-     * true when the loader for {@link PhoneNumberListAdapter} has started already.
-     */
-    private boolean mAllContactsLoaderStarted;
-    /**
-     * true when the loader for {@link PhoneNumberListAdapter} must reload "all" contacts again.
-     * It typically happens when {@link ContactsPreferences} has changed its settings
-     * (display order and sort order)
-     */
-    private boolean mAllContactsForceReload;
-
-    private ContactsPreferences mContactsPrefs;
-
     private TextView mEmptyView;
     private ListView mListView;
+    private View mShowAllContactsButton;
     /**
      * Layout containing {@link #mAccountFilterHeader}. Used to limit area being "pressed".
      */
@@ -237,10 +159,6 @@
             new ContactTileAdapterListener();
     private final LoaderManager.LoaderCallbacks<Cursor> mContactTileLoaderListener =
             new ContactTileLoaderListener();
-    private final LoaderManager.LoaderCallbacks<Cursor> mAllContactsLoaderListener =
-            new AllContactsLoaderListener();
-    private final ContactsPreferenceChangeListener mContactsPreferenceChangeListener =
-            new ContactsPreferenceChangeListener();
     private final ScrollListener mScrollListener = new ScrollListener();
 
     private boolean mOptionsMenuHasFrequents;
@@ -250,8 +168,6 @@
         if (DEBUG) Log.d(TAG, "onAttach()");
         super.onAttach(activity);
 
-        mContactsPrefs = new ContactsPreferences(activity);
-
         // Construct two base adapters which will become part of PhoneFavoriteMergedAdapter.
         // We don't construct the resultant adapter at this moment since it requires LayoutInflater
         // that will be available on onCreateView().
@@ -260,33 +176,6 @@
                 getResources().getInteger(R.integer.contact_tile_column_count_in_favorites_new),
                 1);
         mContactTileAdapter.setPhotoLoader(ContactPhotoManager.getInstance(activity));
-
-        // Setup the "all" adapter manually. See also the setup logic in ContactEntryListFragment.
-        mAllContactsAdapter = new PhoneNumberListAdapter(activity);
-        mAllContactsAdapter.setDisplayPhotos(true);
-        mAllContactsAdapter.setQuickContactEnabled(true);
-        mAllContactsAdapter.setSearchMode(false);
-        mAllContactsAdapter.setIncludeProfile(false);
-        mAllContactsAdapter.setSelectionVisible(false);
-        mAllContactsAdapter.setDarkTheme(false);
-        mAllContactsAdapter.setPhotoLoader(ContactPhotoManager.getInstance(activity));
-        // Disable directory header.
-        mAllContactsAdapter.setHasHeader(0, false);
-        // Show A-Z section index.
-        mAllContactsAdapter.setSectionHeaderDisplayEnabled(true);
-        // Disable pinned header. It doesn't work with this fragment.
-        mAllContactsAdapter.setPinnedPartitionHeadersEnabled(false);
-        // Put photos on START (LEFT in LTR layout direction and RIGHT in RTL layout direction)
-        // for consistency with "frequent" contacts section.
-        mAllContactsAdapter.setPhotoPosition(ContactListItemView.getDefaultPhotoPosition(
-                true /* opposite */ ));
-
-        // Use Callable.CONTENT_URI which will include not only phone numbers but also SIP
-        // addresses.
-        mAllContactsAdapter.setUseCallableUri(true);
-
-        mAllContactsAdapter.setContactNameDisplayOrder(mContactsPrefs.getDisplayOrder());
-        mAllContactsAdapter.setSortOrder(mContactsPrefs.getSortOrder());
     }
 
     @Override
@@ -330,9 +219,18 @@
         mAccountFilterHeaderContainer.addView(mAccountFilterHeader);
 
         mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false);
+        mShowAllContactsButton = inflater.inflate(R.layout.show_all_contact_button, mListView,
+                false);
+        mShowAllContactsButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                showAllContacts();
+            }
+        });
 
-        mAdapter = new NewPhoneFavoriteMergedAdapter(getActivity(),
-                mContactTileAdapter, mAccountFilterHeaderContainer, mCallLogAdapter, mLoadingView);
+        mAdapter = new NewPhoneFavoriteMergedAdapter(getActivity(), mContactTileAdapter,
+                mAccountFilterHeaderContainer, mCallLogAdapter, mLoadingView,
+                mShowAllContactsButton);
 
         mListView.setAdapter(mAdapter);
 
@@ -347,6 +245,7 @@
         return listLayout;
     }
 
+
     // TODO krelease: update the options menu when displaying the popup menu instead. We could
     // possibly get rid of this method entirely.
     private boolean isOptionsMenuChanged() {
@@ -386,30 +285,11 @@
             throw new ClassCastException(activity.toString()
                     + " must implement OnListFragmentScrolledListener");
         }
-        mContactsPrefs.registerChangeListener(mContactsPreferenceChangeListener);
-
-        // If ContactsPreferences has changed, we need to reload "all" contacts with the new
-        // settings. If mAllContactsFoarceReload is already true, it should be kept.
-        if (loadContactsPreferences()) {
-            mAllContactsForceReload = true;
-        }
 
         // Use initLoader() instead of restartLoader() to refraining unnecessary reload.
         // This method call implicitly assures ContactTileLoaderListener's onLoadFinished() will
         // be called, on which we'll check if "all" contacts should be reloaded again or not.
         getLoaderManager().initLoader(LOADER_ID_CONTACT_TILE, null, mContactTileLoaderListener);
-
-        // Delay showing "loading" view until certain amount of time so that users won't see
-        // instant flash of the view when the contacts load is fast enough.
-        // This will be kept shown until both tile and all sections are loaded.
-        mLoadingView.setVisibility(View.INVISIBLE);
-        mHandler.sendEmptyMessageDelayed(MESSAGE_SHOW_LOADING_EFFECT, LOADING_EFFECT_DELAY);
-    }
-
-    @Override
-    public void onStop() {
-        super.onStop();
-        mContactsPrefs.unregisterChangeListener();
     }
 
     /**
@@ -424,58 +304,17 @@
         if (position <= contactTileAdapterCount) {
             Log.e(TAG, "onItemClick() event for unexpected position. "
                     + "The position " + position + " is before \"all\" section. Ignored.");
-        } else {
-            final int localPosition = position - mContactTileAdapter.getCount() - 1;
-            if (mListener != null) {
-                mListener.onContactSelected(mAllContactsAdapter.getDataUri(localPosition));
-            }
         }
     }
 
-    private boolean loadContactsPreferences() {
-        if (mContactsPrefs == null || mAllContactsAdapter == null) {
-            return false;
-        }
-
-        boolean changed = false;
-        final int currentDisplayOrder = mContactsPrefs.getDisplayOrder();
-        if (mAllContactsAdapter.getContactNameDisplayOrder() != currentDisplayOrder) {
-            mAllContactsAdapter.setContactNameDisplayOrder(currentDisplayOrder);
-            changed = true;
-        }
-
-        final int currentSortOrder = mContactsPrefs.getSortOrder();
-        if (mAllContactsAdapter.getSortOrder() != currentSortOrder) {
-            mAllContactsAdapter.setSortOrder(currentSortOrder);
-            changed = true;
-        }
-
-        return changed;
-    }
-
     /**
-     * Requests to reload "all" contacts. If the section is already loaded, this method will
-     * force reloading it now. If the section isn't loaded yet, the actual load may be done later
-     * (on {@link #onStart()}.
+     * Gets called when user click on the show all contacts button.
      */
-    private void requestReloadAllContacts() {
-        if (DEBUG) {
-            Log.d(TAG, "requestReloadAllContacts()"
-                    + " mAllContactsAdapter: " + mAllContactsAdapter
-                    + ", mAllContactsLoaderStarted: " + mAllContactsLoaderStarted);
+    private void showAllContacts() {
+        // TODO {klp} Use interface for the fragment to communicate with the activity
+        if (getActivity() instanceof  NewDialtactsActivity) {
+            ((NewDialtactsActivity) getActivity()).showAllContactsFragment();
         }
-
-        if (mAllContactsAdapter == null || !mAllContactsLoaderStarted) {
-            // Remember this request until next load on onStart().
-            mAllContactsForceReload = true;
-            return;
-        }
-
-        if (DEBUG) Log.d(TAG, "Reload \"all\" contacts now.");
-
-        mAllContactsAdapter.onDataReload();
-        // Use restartLoader() to make LoaderManager to load the section again.
-        getLoaderManager().restartLoader(LOADER_ID_ALL_CONTACTS, null, mAllContactsLoaderListener);
     }
 
     public void setListener(Listener listener) {
diff --git a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
index d42189e..b350f02 100644
--- a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
+++ b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java
@@ -23,11 +23,7 @@
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.SectionIndexer;
 
-import com.android.contacts.common.list.ContactEntryListAdapter;
-import com.android.contacts.common.list.ContactListItemView;
 import com.android.dialer.R;
 import com.android.dialer.calllog.NewCallLogAdapter;
 
@@ -49,6 +45,7 @@
     private final PhoneFavoritesTileAdapter mContactTileAdapter;
     private final NewCallLogAdapter mCallLogAdapter;
     private final View mLoadingView;
+    private final View mShowAllContactsButton;
 
     private final int mCallLogPadding;
 
@@ -60,7 +57,8 @@
             PhoneFavoritesTileAdapter contactTileAdapter,
             View accountFilterHeaderContainer,
             NewCallLogAdapter callLogAdapter,
-            View loadingView) {
+            View loadingView,
+            View showAllContactsButton) {
         final Resources resources = context.getResources();
         mContext = context;
         mCallLogPadding = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding);
@@ -70,6 +68,7 @@
         mObserver = new CustomDataSetObserver();
         mContactTileAdapter.registerDataSetObserver(mObserver);
         mLoadingView = loadingView;
+        mShowAllContactsButton = showAllContactsButton;
     }
 
     @Override
@@ -81,13 +80,11 @@
 
     @Override
     public int getCount() {
-        return mContactTileAdapter.getCount() + mCallLogAdapter.getCount();
+        return mContactTileAdapter.getCount() + mCallLogAdapter.getCount() + 1;
     }
 
     @Override
     public Object getItem(int position) {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-
         final int callLogAdapterCount = mCallLogAdapter.getCount();
 
         if (callLogAdapterCount > 0) {
@@ -108,7 +105,7 @@
 
     @Override
     public int getViewTypeCount() {
-        return (mContactTileAdapter.getViewTypeCount() + mCallLogAdapter.getViewTypeCount());
+        return (mContactTileAdapter.getViewTypeCount() + mCallLogAdapter.getViewTypeCount() + 1);
     }
 
     @Override
@@ -119,18 +116,24 @@
             // View type of the call log adapter is the last view type of the contact tile adapter
             // + 1
             return mContactTileAdapter.getViewTypeCount();
-        } else {
+        } else if (position < getCount() - 1) {
             return mContactTileAdapter.getItemViewType(
                     getAdjustedFavoritePosition(position, callLogAdapterCount));
+        } else {
+            // View type of the show all contact button is the last view type of the contact tile
+            // adapter + 2
+            return mContactTileAdapter.getViewTypeCount() + 1;
         }
     }
 
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
-
         final int callLogAdapterCount = mCallLogAdapter.getCount();
 
+        if (position == getCount() - 1) {
+            return mShowAllContactsButton;
+        }
+
         if (callLogAdapterCount > 0) {
             if (position == 0) {
                 final FrameLayout wrapper;
@@ -189,7 +192,6 @@
     @Override
     public boolean isEnabled(int position) {
         final int callLogAdapterCount = mCallLogAdapter.getCount();
-        final int contactTileAdapterCount = mContactTileAdapter.getCount();
         if (position < callLogAdapterCount) {
             return mCallLogAdapter.isEnabled(position);
         } else { // For favorites section
@@ -201,5 +203,4 @@
     private int getAdjustedFavoritePosition(int position, int callLogAdapterCount) {
         return position - callLogAdapterCount;
     }
-
 }
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index 2f3facf..6a4476d 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -221,7 +221,8 @@
             return 0;
         }
 
-        final int total = mNumFrequents + mNumStarred;
+        int total = mNumFrequents + mNumStarred;
+
         return total - (mMaxTiledRows * (mColumnCount - 1));
     }
 
@@ -297,7 +298,8 @@
     public View getView(int position, View convertView, ViewGroup parent) {
         int itemViewType = getItemViewType(position);
 
-        ContactTileRow contactTileRowView = (ContactTileRow) convertView;
+        ContactTileRow contactTileRowView  = (ContactTileRow) convertView;
+
         ArrayList<ContactEntry> contactList = getItem(position);
 
         if (contactTileRowView == null) {
diff --git a/src/com/android/dialer/list/ShowAllContactsFragment.java b/src/com/android/dialer/list/ShowAllContactsFragment.java
new file mode 100644
index 0000000..85806b6
--- /dev/null
+++ b/src/com/android/dialer/list/ShowAllContactsFragment.java
@@ -0,0 +1,89 @@
+/*
+
+ * Copyright (C) 2013 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.dialer.list;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.os.Bundle;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.style.TypefaceSpan;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.contacts.common.list.ContactListItemView;
+import com.android.contacts.common.list.PhoneNumberPickerFragment;
+import com.android.dialer.R;
+
+// TODO{klp}: Wrap this fragment with an activity.
+/**
+ * Fragments to show all contacts with phone numbers.
+ */
+public class ShowAllContactsFragment extends PhoneNumberPickerFragment{
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+    }
+
+    @Override
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+
+        // Customizes the listview according to the dialer specifics.
+        setQuickContactEnabled(true);
+        setDarkTheme(false);
+        setPhotoPosition(ContactListItemView.getDefaultPhotoPosition(true /* opposite */));
+        setUseCallableUri(true);
+    }
+
+    @Override
+    public void onStart() {
+        // Displays action bar for quick navigation.
+        final ActionBar actionBar = getActivity().getActionBar();
+        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+        actionBar.setDisplayShowHomeEnabled(true);
+        actionBar.setDisplayHomeAsUpEnabled(true);
+        actionBar.setDisplayShowTitleEnabled(true);
+
+        final SpannableString s = new SpannableString(getString(R.string.show_all_contacts_title));
+        s.setSpan(new TypefaceSpan(getString(R.string.show_all_contacts_title)), 0,
+                s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+        actionBar.setTitle(s);
+
+        super.onStart();
+    }
+
+    @Override
+    public void onHiddenChanged(boolean hidden) {
+        // Hides the action bar as it is hidden in the main activity
+        if (getActivity() != null) {
+            if (hidden) {
+                getActivity().getActionBar().hide();
+            } else {
+                getActivity().getActionBar().show();
+            }
+        }
+    }
+
+    @Override
+    protected View inflateView(LayoutInflater inflater, ViewGroup container) {
+        return inflater.inflate(R.layout.show_all_contacts_fragment, null);
+    }
+}