Merge "Checking number existence before dedupe"
diff --git a/res/layout-land/quickcontact_activity.xml b/res/layout-w500dp-land/quickcontact_activity.xml
similarity index 92%
rename from res/layout-land/quickcontact_activity.xml
rename to res/layout-w500dp-land/quickcontact_activity.xml
index af622dc..63cab3c 100644
--- a/res/layout-land/quickcontact_activity.xml
+++ b/res/layout-w500dp-land/quickcontact_activity.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2016 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.
diff --git a/res/layout/create_group_dialog.xml b/res/layout/create_group_dialog.xml
new file mode 100644
index 0000000..3fefd3d
--- /dev/null
+++ b/res/layout/create_group_dialog.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:paddingBottom="24dp"
+    android:paddingStart="24dp"
+    android:paddingEnd="24dp">
+
+    <EditText android:id="@android:id/text1"
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="4dp"
+        android:layout_marginLeft="4dp"
+        android:layout_marginRight="4dp"
+        android:layout_marginTop="16dp"
+        android:inputType="textCapWords"
+        android:maxLength="40"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/expanding_entry_card_item.xml b/res/layout/expanding_entry_card_item.xml
index 7c7337e..99f9174 100644
--- a/res/layout/expanding_entry_card_item.xml
+++ b/res/layout/expanding_entry_card_item.xml
@@ -43,7 +43,7 @@
         android:layout_alignParentTop="true"
         android:paddingTop="5dp"
         android:layout_toEndOf="@+id/icon"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textColor="@color/quickcontact_entry_header_text_color"
         android:textAlignment="viewStart"
         android:layout_marginBottom="@dimen/expanding_entry_card_header_margin_bottom" />
@@ -54,7 +54,7 @@
         android:layout_height="wrap_content"
         android:layout_below="@+id/header"
         android:layout_toEndOf="@+id/icon_sub_header"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textAlignment="viewStart"
         android:textColor="@color/quickcontact_entry_sub_header_text_color" />
 
@@ -73,7 +73,7 @@
         android:id="@+id/text"
         android:layout_below="@+id/sub_header"
         android:layout_toEndOf="@+id/icon_text"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textAlignment="viewStart"
         android:textColor="@color/quickcontact_entry_sub_header_text_color" />
 
diff --git a/res/layout/user_profile_header.xml b/res/layout/user_profile_header.xml
deleted file mode 100644
index 828f08c..0000000
--- a/res/layout/user_profile_header.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?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.
--->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/user_profile_header"
-    android:orientation="horizontal"
-    android:layout_width="match_parent"
-    android:layout_height="?attr/list_item_header_height"
-    android:paddingLeft="?attr/list_item_padding_left"
-    android:paddingRight="?attr/list_item_padding_right"
-    android:paddingStart="?attr/list_item_padding_left"
-    android:paddingEnd="?attr/list_item_padding_right"
-    android:paddingTop="4dp"
-    android:paddingBottom="8dp" >
-
-    <TextView android:id="@+id/profile_title"
-        android:layout_width="@dimen/contact_list_section_header_width"
-        android:layout_height="?android:attr/listPreferredItemHeight"
-        android:singleLine="true"
-        android:text="@string/user_profile_contacts_list_header"
-        android:ellipsize="end"
-        android:textAppearance="@style/SectionHeaderStyle"
-        android:gravity="start|center_vertical" />
-
-    <Button android:id="@+id/user_profile_button"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="?android:attr/listPreferredItemHeight"
-        android:paddingStart="?attr/list_item_padding_left"
-        android:paddingEnd="?attr/list_item_padding_right"
-        android:background="?android:attr/selectableItemBackground"
-        android:singleLine="true"
-        android:text="@string/profile_display_name"
-        android:ellipsize="end"
-        android:gravity="start|center_vertical"
-        android:textAppearance="?android:attr/textAppearanceMedium" />
-
-</LinearLayout>
diff --git a/res/menu/activity_main_drawer.xml b/res/menu/activity_main_drawer.xml
index 75277af..4e58f44 100644
--- a/res/menu/activity_main_drawer.xml
+++ b/res/menu/activity_main_drawer.xml
@@ -41,14 +41,6 @@
         </item>
     </group>
 
-    <group android:id="@+id/create_groups">
-        <item
-            android:id="@+id/nav_create_groups"
-            android:icon="@drawable/ic_menu_group_add"
-            android:title="@string/menu_new_group_action_bar"
-            android:visible="false"/>
-    </group>
-
     <group android:id="@+id/filters">
         <item
             android:id="@+id/nav_filters"
diff --git a/res/values-land/bools.xml b/res/values-land/bools.xml
index bd0650f..beaa960 100644
--- a/res/values-land/bools.xml
+++ b/res/values-land/bools.xml
@@ -15,6 +15,7 @@
 -->
 <resources>
 
-    <bool name="quickcontact_two_panel">true</bool>
+    <bool name="quickcontact_two_panel">false</bool>
+    <bool name="contacteditor_two_panel">true</bool>
 
 </resources>
diff --git a/res/layout-land/quickcontact_activity.xml b/res/values-w500dp-land/bools.xml
similarity index 81%
copy from res/layout-land/quickcontact_activity.xml
copy to res/values-w500dp-land/bools.xml
index af622dc..65174ba 100644
--- a/res/layout-land/quickcontact_activity.xml
+++ b/res/values-w500dp-land/bools.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2016 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.
@@ -13,6 +13,8 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<merge>
-    <include layout="@layout/quickcontact_activity_landscape" />
-</merge>
\ No newline at end of file
+<resources>
+
+    <bool name="quickcontact_two_panel">true</bool>
+
+</resources>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index b94cc85..eef3808 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -17,5 +17,6 @@
 
     <bool name="quickcontact_two_panel">false</bool>
     <bool name="contact_all_list_show_card_frame">false</bool>
+    <bool name="contacteditor_two_panel">false</bool>
 
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 85b8898..37e276f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -399,7 +399,13 @@
     <string name="share_via">Share contact via</string>
 
     <!-- Title for the disambiguation dialog that requests the user choose an account for the new label to be created under [CHAR LIMIT=NONE] -->
-    <string name="dialog_new_group_account">Create label under account</string>
+    <string name="dialog_new_group_account">Choose account</string>
+
+    <!-- Title for the create new label dialog. CHAR LIMIT=40] -->
+    <string name="create_group_dialog_title">Create label</string>
+
+    <!-- Button label to create a new label on the create new label dialog. [CHAR LIMIT=20] -->
+    <string name="create_group_dialog_button">Create</string>
 
     <!-- Generic action string for starting an audio chat. Used by AccessibilityService to announce the purpose of the view. [CHAR LIMIT=NONE] -->
     <string name="audio_chat">Voice chat</string>
@@ -618,9 +624,8 @@
         <xliff:g id="call_type" example="Friends">%1$s</xliff:g>  <xliff:g id="call_short_date" example="Friends">%2$s</xliff:g>
     </string>
 
-    <!-- Text displayed in place of the display name for the contact that represents the user's
-      personal profile entry [CHAR LIMIT=64] -->
-    <string name="profile_display_name">Set up my profile</string>
+    <!-- Label to instruct the user to type in a contact's name to add the contact as a member of the current group. [CHAR LIMIT=64] -->
+    <string name="enter_contact_name">Type person\'s name</string>
 
     <!-- Hint text in the label name box in the edit label view. [CHAR LIMIT=20]-->
     <string name="group_name_hint">Label\'s name</string>
@@ -874,8 +879,8 @@
     <!-- The menu item to open blocked numbers activity [CHAR LIMIT=60]-->
     <string name="menu_blocked_numbers">Blocked numbers</string>
 
-    <!-- The menu item to open the link/merge duplicates activity. [CHAR LIMIT=80]-->
-    <string name="menu_duplicates">Find duplicates</string>
+    <!-- The menu item to open the link/merge duplicates activity. [CHAR LIMIT=20]-->
+    <string name="menu_duplicates">Duplicates</string>
 
     <!-- Open drawer content descriptions [CHAR LIMIT=40] -->
     <string name="navigation_drawer_open">Open navigation drawer</string>
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index c2951d8..50f50dd 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -290,7 +290,6 @@
             case ContactsRequest.ACTION_DEFAULT:
             case ContactsRequest.ACTION_PICK_CONTACT: {
                 ContactPickerFragment fragment = new ContactPickerFragment();
-                fragment.setIncludeProfile(mRequest.shouldIncludeProfile());
                 fragment.setIncludeFavorites(mRequest.shouldIncludeFavorites());
                 mListFragment = fragment;
                 break;
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index b692bde..eea55da 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -398,7 +398,7 @@
         mAllFragment.setOnContactListActionListener(new ContactBrowserActionListener());
         mAllFragment.setCheckBoxListListener(new CheckBoxListListener());
 
-        if (areGroupWritableAccountsAvailable()) {
+        if (areGroupWritableAccountsAvailable() && mGroupsFragment != null) {
             mGroupsFragment.setListener(this);
         }
 
@@ -925,7 +925,11 @@
             }
         }
 
-        makeMenuItemVisible(menu, R.id.nav_create_groups, areGroupWritableAccountsAvailable());
+        // Create a menu item in the sub menu to add new groups
+        final MenuItem menuItem = subMenu.add(R.id.nav_groups_items, Menu.NONE, Menu.NONE,
+                getString(R.string.menu_new_group_action_bar));
+        menuItem.setIntent(GroupUtil.createAddGroupIntent(this));
+        menuItem.setIcon(R.drawable.ic_menu_group_add);
     }
 
     @Override
@@ -1247,8 +1251,6 @@
         } else if (id == R.id.nav_find_duplicates) {
             ImplicitIntentsUtil.startActivityInAppIfPossible(this,
                     Assistants.getDuplicatesActivityIntent(this));
-        } else if (id == R.id.nav_create_groups) {
-            ImplicitIntentsUtil.startActivityInApp(this, GroupUtil.createAddGroupIntent(this));
         } else if (item.getIntent() != null) {
             ImplicitIntentsUtil.startActivityInApp(this, item.getIntent());
         } else {
diff --git a/src/com/android/contacts/editor/CompactPhotoEditorView.java b/src/com/android/contacts/editor/CompactPhotoEditorView.java
index 1696a12..899e22a 100644
--- a/src/com/android/contacts/editor/CompactPhotoEditorView.java
+++ b/src/com/android/contacts/editor/CompactPhotoEditorView.java
@@ -78,7 +78,7 @@
 
         mLandscapePhotoRatio = getTypedFloat(R.dimen.quickcontact_landscape_photo_ratio);
         mPortraitPhotoRatio = getTypedFloat(R.dimen.editor_portrait_photo_ratio);
-        mIsTwoPanel = getResources().getBoolean(R.bool.quickcontact_two_panel);
+        mIsTwoPanel = getResources().getBoolean(R.bool.contacteditor_two_panel);
 
         final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
                 new int[] { android.R.attr.actionBarSize });
diff --git a/src/com/android/contacts/group/CreateGroupDialogFragment.java b/src/com/android/contacts/group/CreateGroupDialogFragment.java
new file mode 100644
index 0000000..777fd44
--- /dev/null
+++ b/src/com/android/contacts/group/CreateGroupDialogFragment.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2016 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, softwareateCre
+ * 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.group;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.android.contacts.R;
+
+/**
+ * Prompts the user for the name of the new group.
+ */
+public final class CreateGroupDialogFragment extends DialogFragment {
+
+    private static final String TAG_CREATE_GROUP_DIALOG = "createGroup";
+
+    /** Callbacks for hosts of the {@link CreateGroupDialogFragment}. */
+    public interface Listener {
+        void onCreateGroup(String groupName);
+        void onCreateGroupCancelled();
+    }
+
+    private EditText mGroupNameEditText;
+
+    public static <F extends Fragment & Listener> void show(
+            FragmentManager fragmentManager, F targetFragment) {
+        final CreateGroupDialogFragment dialog = new CreateGroupDialogFragment();
+        dialog.setTargetFragment(targetFragment, /* requestCode */ 0);
+        dialog.show(fragmentManager, TAG_CREATE_GROUP_DIALOG);
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        // Build a dialog with two buttons and a view of a single EditText input field
+        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.create_group_dialog_title)
+                .setView(R.layout.create_group_dialog)
+                .setNegativeButton(android.R.string.cancel, new OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        onCreateGroupCancelled();
+                        dismiss();
+                    }
+                })
+                .setPositiveButton(R.string.create_group_dialog_button, new OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        onCreateGroup();
+                    }
+                });
+
+        // Disable the create button when the name is empty
+        final AlertDialog alertDialog = builder.create();
+        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
+            @Override
+            public void onShow(DialogInterface dialog) {
+                mGroupNameEditText = (EditText) alertDialog.findViewById(android.R.id.text1);
+
+                final Button createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+                createButton.setEnabled(!TextUtils.isEmpty(getGroupName()));
+                mGroupNameEditText.addTextChangedListener(new TextWatcher() {
+                    @Override
+                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                    }
+
+                    @Override
+                    public void onTextChanged(CharSequence s, int start, int before, int count) {
+                    }
+
+                    @Override
+                    public void afterTextChanged(Editable s) {
+                        createButton.setEnabled(!TextUtils.isEmpty(s));
+                    }
+                });
+            }
+        });
+        return alertDialog;
+    }
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        super.onCancel(dialog);
+        onCreateGroupCancelled();
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle b) {
+        setTargetFragment(null, /* requestCode */ -1);
+        super.onSaveInstanceState(b);
+    }
+
+    private void onCreateGroupCancelled() {
+        final Fragment targetFragment = getTargetFragment();
+        if (targetFragment != null && targetFragment instanceof Listener) {
+            ((Listener) targetFragment).onCreateGroupCancelled();
+        }
+    }
+
+    private void onCreateGroup() {
+        final Fragment targetFragment = getTargetFragment();
+        if (targetFragment != null && targetFragment instanceof Listener) {
+            ((Listener) targetFragment).onCreateGroup(getGroupName());
+        }
+    }
+
+    private String getGroupName() {
+        return mGroupNameEditText == null || mGroupNameEditText.getText() == null
+                ? null : mGroupNameEditText.getText().toString();
+    }
+}
diff --git a/src/com/android/contacts/list/ContactBrowseListFragment.java b/src/com/android/contacts/list/ContactBrowseListFragment.java
index afd2543..4b4b326 100644
--- a/src/com/android/contacts/list/ContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/ContactBrowseListFragment.java
@@ -401,11 +401,8 @@
             }
         }
 
-        // Display the user's profile if not in search mode
-        adapter.setIncludeProfile(!searchMode);
-
-        // Display favorites if not in search mode
-        adapter.setIncludeFavorites(!searchMode);
+        adapter.setIncludeFavorites(!searchMode
+                && mFilter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS);
     }
 
     @Override
diff --git a/src/com/android/contacts/list/ContactsRequest.java b/src/com/android/contacts/list/ContactsRequest.java
index f867549..a1428be 100644
--- a/src/com/android/contacts/list/ContactsRequest.java
+++ b/src/com/android/contacts/list/ContactsRequest.java
@@ -85,7 +85,6 @@
     private CharSequence mTitle;
     private boolean mSearchMode;
     private String mQueryString;
-    private boolean mIncludeProfile;
     private boolean mIncludeFavorites;
     private boolean mLegacyCompatibilityMode;
     private boolean mDirectorySearchEnabled = true;
@@ -98,7 +97,6 @@
                 + " mTitle=" + mTitle
                 + " mSearchMode=" + mSearchMode
                 + " mQueryString=" + mQueryString
-                + " mIncludeProfile=" + mIncludeProfile
                 + " mIncludeFavorites=" + mIncludeFavorites
                 + " mLegacyCompatibilityMode=" + mLegacyCompatibilityMode
                 + " mDirectorySearchEnabled=" + mDirectorySearchEnabled
@@ -146,14 +144,6 @@
         mQueryString = string;
     }
 
-    public boolean shouldIncludeProfile() {
-        return mIncludeProfile;
-    }
-
-    public void setIncludeProfile(boolean includeProfile) {
-        mIncludeProfile = includeProfile;
-    }
-
     public boolean shouldIncludeFavorites() {
         return mIncludeFavorites;
     }
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 2ce22c0..672e63e 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -17,29 +17,22 @@
 
 import android.content.Context;
 import android.content.CursorLoader;
-import android.content.Intent;
 import android.net.Uri;
 import android.provider.ContactsContract.Contacts;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
-import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.ListView;
 import android.widget.TextView;
 
 import com.android.contacts.R;
 import com.android.contacts.common.list.ContactListAdapter;
-import com.android.contacts.common.list.ContactListFilter;
 import com.android.contacts.common.list.ContactListItemView;
 import com.android.contacts.common.list.DefaultContactListAdapter;
-import com.android.contacts.common.list.ProfileAndContactsLoader;
-import com.android.contacts.common.util.ImplicitIntentsUtil;
-import com.android.contacts.editor.ContactEditorFragment;
-import com.android.contacts.common.util.AccountFilterUtil;
+import com.android.contacts.common.list.FavoritesAndContactsLoader;
 
 /**
  * Fragment containing a contact list used for browsing (as compared to
@@ -49,11 +42,6 @@
     private static final String TAG = DefaultContactBrowseListFragment.class.getSimpleName();
 
     private View mSearchHeaderView;
-    private View mAccountFilterHeader;
-    private FrameLayout mProfileHeaderContainer;
-    private View mProfileHeader;
-    private Button mProfileMessage;
-    private TextView mProfileTitle;
     private View mSearchProgress;
     private TextView mSearchProgressText;
 
@@ -68,7 +56,7 @@
 
     @Override
     public CursorLoader createCursorLoader(Context context) {
-        return new ProfileAndContactsLoader(context);
+        return new FavoritesAndContactsLoader(context);
     }
 
     @Override
@@ -99,11 +87,6 @@
     protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
         super.onCreateView(inflater, container);
 
-        // Create an empty user profile header and hide it for now (it will be visible if the
-        // contacts list will have no user profile).
-        addEmptyUserProfileHeader(inflater);
-        showEmptyUserProfile(false);
-
         // Putting the header view inside a container will allow us to make
         // it invisible later. See checkHeaderViewVisibility()
         FrameLayout headerContainer = new FrameLayout(inflater.getContext());
@@ -138,70 +121,30 @@
     }
 
     @Override
-    protected void setProfileHeader() {
-        mUserProfileExists = getAdapter().hasProfile();
-        showEmptyUserProfile(!mUserProfileExists && !isSearchMode());
-
-        if (isSearchMode()) {
-            ContactListAdapter adapter = getAdapter();
-            if (adapter == null) {
-                return;
-            }
-
-            // In search mode we only display the header if there is nothing found
-            if (TextUtils.isEmpty(getQueryString()) || !adapter.areAllPartitionsEmpty()) {
-                mSearchHeaderView.setVisibility(View.GONE);
-                showSearchProgress(false);
-            } else {
-                mSearchHeaderView.setVisibility(View.VISIBLE);
-                if (adapter.isLoading()) {
-                    mSearchProgressText.setText(R.string.search_results_searching);
-                    showSearchProgress(true);
-                } else {
-                    mSearchProgressText.setText(R.string.listFoundAllContactsZero);
-                    mSearchProgressText.sendAccessibilityEvent(
-                            AccessibilityEvent.TYPE_VIEW_SELECTED);
-                    showSearchProgress(false);
-                }
-            }
-            showEmptyUserProfile(false);
+    protected void setListHeader() {
+        if (!isSearchMode()) {
+            return;
         }
-    }
+        ContactListAdapter adapter = getAdapter();
+        if (adapter == null) {
+            return;
+        }
 
-    private void showEmptyUserProfile(boolean show) {
-        // Changing visibility of just the mProfileHeader doesn't do anything unless
-        // you change visibility of its children, hence the call to mCounterHeaderView
-        // and mProfileTitle
-        mProfileHeaderContainer.setVisibility(show ? View.VISIBLE : View.GONE);
-        mProfileHeader.setVisibility(show ? View.VISIBLE : View.GONE);
-        mProfileTitle.setVisibility(show ? View.VISIBLE : View.GONE);
-        mProfileMessage.setVisibility(show ? View.VISIBLE : View.GONE);
-    }
-
-    /**
-     * This method creates a pseudo user profile contact. When the returned query doesn't have
-     * a profile, this methods creates 2 views that are inserted as headers to the listview:
-     * 1. A header view with the "ME" title and the contacts count.
-     * 2. A button that prompts the user to create a local profile
-     */
-    private void addEmptyUserProfileHeader(LayoutInflater inflater) {
-        ListView list = getListView();
-        // Add a header with the "ME" name. The view is embedded in a frame view since you cannot
-        // change the visibility of a view in a ListView without having a parent view.
-        mProfileHeader = inflater.inflate(R.layout.user_profile_header, null, false);
-        mProfileTitle = (TextView) mProfileHeader.findViewById(R.id.profile_title);
-        mProfileHeaderContainer = new FrameLayout(inflater.getContext());
-        mProfileHeaderContainer.addView(mProfileHeader);
-        list.addHeaderView(mProfileHeaderContainer, null, false);
-
-        // Add a button with a message inviting the user to create a local profile
-        mProfileMessage = (Button) mProfileHeader.findViewById(R.id.user_profile_button);
-        mProfileMessage.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View v) {
-                Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
-                intent.putExtra(ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE, true);
-                ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
+        // In search mode we only display the header if there is nothing found
+        if (TextUtils.isEmpty(getQueryString()) || !adapter.areAllPartitionsEmpty()) {
+            mSearchHeaderView.setVisibility(View.GONE);
+            showSearchProgress(false);
+        } else {
+            mSearchHeaderView.setVisibility(View.VISIBLE);
+            if (adapter.isLoading()) {
+                mSearchProgressText.setText(R.string.search_results_searching);
+                showSearchProgress(true);
+            } else {
+                mSearchProgressText.setText(R.string.listFoundAllContactsZero);
+                mSearchProgressText.sendAccessibilityEvent(
+                        AccessibilityEvent.TYPE_VIEW_SELECTED);
+                showSearchProgress(false);
             }
-        });
+        }
     }
 }
diff --git a/src/com/android/contacts/list/MultiSelectContactsListFragment.java b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
index 76dd3f3..8dd18c1 100644
--- a/src/com/android/contacts/list/MultiSelectContactsListFragment.java
+++ b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
@@ -144,8 +144,7 @@
         final int previouslySelectedCount = getAdapter().getSelectedContactIds().size();
         final Uri uri = getAdapter().getContactUri(position);
         final int partition = getAdapter().getPartitionForPosition(position);
-        if (uri != null && (partition == ContactsContract.Directory.DEFAULT
-                && (position > 0 || !getAdapter().hasProfile()))) {
+        if (uri != null && partition == ContactsContract.Directory.DEFAULT) {
             final String contactId = uri.getLastPathSegment();
             if (!TextUtils.isEmpty(contactId)) {
                 if (mCheckBoxListListener != null) {
diff --git a/src/com/android/contacts/list/MultiSelectEntryContactListAdapter.java b/src/com/android/contacts/list/MultiSelectEntryContactListAdapter.java
index b080657..5a54c51 100644
--- a/src/com/android/contacts/list/MultiSelectEntryContactListAdapter.java
+++ b/src/com/android/contacts/list/MultiSelectEntryContactListAdapter.java
@@ -115,13 +115,12 @@
 
     private void bindCheckBox(ContactListItemView view, Cursor cursor, int position,
             boolean isLocalDirectory) {
-        // Disable clicking on the ME profile and all contacts from remote directories
-        // when showing check boxes. We do this by telling the view to handle clicking itself.
-        view.setClickable((position == 0 && hasProfile() || !isLocalDirectory)
-                && mDisplayCheckBoxes);
+        // Disable clicking on all contacts from remote directories when showing check boxes. We do
+        // this by telling the view to handle clicking itself.
+        view.setClickable(!isLocalDirectory && mDisplayCheckBoxes);
         // Only show checkboxes if mDisplayCheckBoxes is enabled. Also, never show the
-        // checkbox for the Me profile entry and other directory contacts except local directory.
-        if (position == 0 && hasProfile() || !mDisplayCheckBoxes || !isLocalDirectory) {
+        // checkbox for other directory contacts except local directory.
+        if (!mDisplayCheckBoxes || !isLocalDirectory) {
             view.hideCheckBox();
             return;
         }
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index c9a4d32..7942eec 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -32,6 +32,7 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.ColorStateList;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -113,6 +114,7 @@
 import com.android.contacts.common.activity.RequestPermissionsActivity;
 import com.android.contacts.common.compat.CompatUtils;
 import com.android.contacts.common.compat.EventCompat;
+import com.android.contacts.common.compat.MultiWindowCompat;
 import com.android.contacts.common.dialog.CallSubjectDialog;
 import com.android.contacts.common.editor.SelectAccountDialogFragment;
 import com.android.contacts.common.interactions.TouchPointManager;
@@ -1043,7 +1045,9 @@
         mWindowScrim.setAlpha(0);
         getWindow().setBackgroundDrawable(mWindowScrim);
 
-        mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED);
+        mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED,
+                /* maximumHeaderTextSize */ -1,
+                /* shouldUpdateNameViewHeight */ true);
         // mScroller needs to perform asynchronous measurements after initalize(), therefore
         // we can't mark this as GONE.
         mScroller.setVisibility(View.INVISIBLE);
@@ -1156,7 +1160,11 @@
                     ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
         }
         mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE);
-        mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE);
+        if (isMultiWindowOnPhone()) {
+            mExtraMode = QuickContact.MODE_LARGE;
+        }
+        mExtraPrioritizedMimeType =
+                getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE);
         final Uri oldLookupUri = mLookupUri;
 
         if (lookupUri == null) {
@@ -1193,7 +1201,12 @@
             return;
         }
         mHasAlreadyBeenOpened = true;
-        mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED);
+        mScroller.scrollUpForEntranceAnimation(/* scrollToCurrentPosition */ !isMultiWindowOnPhone()
+                && (mExtraMode != MODE_FULLY_EXPANDED));
+    }
+
+    private boolean isMultiWindowOnPhone() {
+        return MultiWindowCompat.isInMultiWindowMode(this) && PhoneCapabilityTester.isPhone(this);
     }
 
     /** Assign this string to the view if it is not empty. */
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index eb3283f..b1deb90 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -66,7 +66,7 @@
 public class MultiShrinkScroller extends FrameLayout {
 
     /**
-     * 1000 pixels per millisecond. Ie, 1 pixel per second.
+     * 1000 pixels per second. Ie, 1 pixel per millisecond.
      */
     private static final int PIXELS_PER_SECOND = 1000;
 
@@ -135,6 +135,8 @@
      */
     private boolean mIsOpenContactSquare;
     private int mMaximumHeaderTextSize;
+    private int mMaximumPhoneticNameViewHeight;
+    private int mMaximumFullNameViewHeight;
     private int mCollapsedTitleBottomMargin;
     private int mCollapsedTitleStartMargin;
     private int mMinimumPortraitHeaderHeight;
@@ -287,7 +289,8 @@
     /**
      * This method must be called inside the Activity's OnCreate.
      */
-    public void initialize(MultiShrinkScrollerListener listener, boolean isOpenContactSquare) {
+    public void initialize(MultiShrinkScrollerListener listener, boolean isOpenContactSquare,
+                final int maximumHeaderTextSize, final boolean shouldUpdateNameViewHeight) {
         mScrollView = (ScrollView) findViewById(R.id.content_scroller);
         mScrollViewChild = findViewById(R.id.card_container);
         mToolbar = findViewById(R.id.toolbar_parent);
@@ -346,7 +349,20 @@
                 mMaximumPortraitHeaderHeight = mIsTwoPanel ? getHeight()
                         : mPhotoViewContainer.getWidth();
                 setHeaderHeight(getMaximumScrollableHeaderHeight());
-                mMaximumHeaderTextSize = mTitleAndPhoneticNameView.getHeight();
+                if (shouldUpdateNameViewHeight) {
+                    mMaximumHeaderTextSize = mTitleAndPhoneticNameView.getHeight();
+                    mMaximumFullNameViewHeight = mLargeTextView.getHeight();
+                    // We cannot rely on mPhoneticNameView.getHeight() since it could be 0
+                    final int phoneticNameSize = getResources().getDimensionPixelSize(
+                            R.dimen.quickcontact_maximum_phonetic_name_size);
+                    final int fullNameSize = getResources().getDimensionPixelSize(
+                            R.dimen.quickcontact_maximum_title_size);
+                    mMaximumPhoneticNameViewHeight =
+                            mMaximumFullNameViewHeight * phoneticNameSize / fullNameSize;
+                }
+                if (maximumHeaderTextSize > 0) {
+                    mMaximumHeaderTextSize = maximumHeaderTextSize;
+                }
                 if (mIsTwoPanel) {
                     mMaximumHeaderHeight = getHeight();
                     mMinimumHeaderHeight = mMaximumHeaderHeight;
@@ -393,7 +409,7 @@
         final float TITLE_GRADIENT_SIZE_COEFFICIENT = 1.25f;
         final FrameLayout.LayoutParams largeTextLayoutParms
                 = (FrameLayout.LayoutParams) mTitleAndPhoneticNameView.getLayoutParams();
-        titleGradientLayoutParams.height = (int) ((mTitleAndPhoneticNameView.getHeight()
+        titleGradientLayoutParams.height = (int) ((mMaximumHeaderTextSize
                 + largeTextLayoutParms.bottomMargin) * TITLE_GRADIENT_SIZE_COEFFICIENT);
         mTitleGradientView.setLayoutParams(titleGradientLayoutParams);
     }
@@ -418,7 +434,9 @@
         // in case it just changed from Visibility=GONE.
         mPhoneticNameView.setVisibility(View.VISIBLE);
         // TODO try not using initialize() to refresh phonetic name view: b/27410518
-        initialize(mListener, mIsOpenContactSquare);
+        initialize(mListener, mIsOpenContactSquare, /* maximumHeaderTextSize */
+                (mMaximumFullNameViewHeight + mMaximumPhoneticNameViewHeight),
+                /* shouldUpdateNameViewHeight */ false);
     }
 
     public void setPhoneticNameGone() {
@@ -429,7 +447,9 @@
         mPhoneticNameView.setVisibility(View.GONE);
         // Initialize to make Visibility work.
         // TODO try not using initialize() to refresh phonetic name view: b/27410518
-        initialize(mListener, mIsOpenContactSquare);
+        initialize(mListener, mIsOpenContactSquare,
+                /* maximumHeaderTextSize */ mMaximumFullNameViewHeight,
+                /* shouldUpdateNameViewHeight */ false);
     }
 
     @Override
@@ -1039,7 +1059,7 @@
         } else {
             mTitleAndPhoneticNameView.setPivotX(0);
         }
-        mTitleAndPhoneticNameView.setPivotY(mTitleAndPhoneticNameView.getHeight() / 2);
+        mTitleAndPhoneticNameView.setPivotY(mMaximumHeaderTextSize / 2);
 
         final int toolbarHeight = mToolbar.getLayoutParams().height;
         mPhotoTouchInterceptOverlay.setClickable(toolbarHeight != mMaximumHeaderHeight);
@@ -1085,7 +1105,7 @@
         // Padding needed on the mTitleAndPhoneticNameView so that it has the same amount of
         // padding as the target rectangle.
         mCollapsedTitleBottomMargin =
-                desiredTopToCenter - mTitleAndPhoneticNameView.getHeight() / 2;
+                desiredTopToCenter - mMaximumHeaderTextSize / 2;
     }
 
     /**