First pass on assistants left nav

Create new assistant and remove duplicates menu item for
Google Contacts. Duplicates will live in the new assistants
fragment.

Test: manual
  - Open left nav to see new Assistant
  - Click on assistant to view new section

Bug:31822010
Change-Id: I0b9d77dd73e45c12fa3853864d09f555563def9a
diff --git a/res/drawable/ic_assistant.xml b/res/drawable/ic_assistant.xml
new file mode 100644
index 0000000..3391beb
--- /dev/null
+++ b/res/drawable/ic_assistant.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M19,2L5,2c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h4l3,3 3,-3h4c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM13.88,12.88L12,17l-1.88,-4.12L6,11l4.12,-1.88L12,5l1.88,4.12L18,11l-4.12,1.88z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_group_add.xml b/res/drawable/ic_group_add.xml
new file mode 100644
index 0000000..6d8776e
--- /dev/null
+++ b/res/drawable/ic_group_add.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M8,10L5,10L5,7L3,7v3L0,10v2h3v3h2v-3h3v-2zM18,11c1.66,0 2.99,-1.34 2.99,-3S19.66,5 18,5c-0.32,0 -0.63,0.05 -0.91,0.14 0.57,0.81 0.9,1.79 0.9,2.86s-0.34,2.04 -0.9,2.86c0.28,0.09 0.59,0.14 0.91,0.14zM13,11c1.66,0 2.99,-1.34 2.99,-3S14.66,5 13,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM19.62,13.16c0.83,0.73 1.38,1.66 1.38,2.84v2h3v-2c0,-1.54 -2.37,-2.49 -4.38,-2.84zM13,13c-2,0 -6,1 -6,3v2h12v-2c0,-2 -4,-3 -6,-3z"/>
+</vector>
\ No newline at end of file
diff --git a/res/menu/activity_main_drawer.xml b/res/menu/activity_main_drawer.xml
index a006761..4082f5f 100644
--- a/res/menu/activity_main_drawer.xml
+++ b/res/menu/activity_main_drawer.xml
@@ -24,9 +24,9 @@
             android:icon="@drawable/ic_menu_filter"
             android:title="@string/contactsList" />
         <item
-            android:id="@+id/nav_find_duplicates"
-            android:icon="@drawable/ic_menu_duplicates"
-            android:title="@string/menu_duplicates"/>
+            android:id="@+id/nav_assistant"
+            android:icon="@drawable/ic_assistant"
+            android:title="@string/menu_assistant"/>
     </group>
 
     <group android:id="@+id/groups">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 454777e..d76f53d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -899,8 +899,8 @@
     <!-- Text shown in the contacts app while the background process updates contacts after a locale change [CHAR LIMIT=150]-->
     <string name="locale_change_in_progress">Contact list is being updated to reflect the change of language.\n\nPlease wait&#8230;</string>
 
-    <!-- The menu item to open the link/merge duplicates activity. [CHAR LIMIT=20]-->
-    <string name="menu_duplicates">Duplicates</string>
+    <!-- The menu item to open the Google contacts assistant. [CHAR LIMIT=20]-->
+    <string name="menu_assistant">Assistant</string>
 
     <!-- Open drawer content descriptions [CHAR LIMIT=40] -->
     <string name="navigation_drawer_open">Open navigation drawer</string>
diff --git a/src-bind/com/android/contactsbind/ObjectFactory.java b/src-bind/com/android/contactsbind/ObjectFactory.java
index 83b8f4d..e336e4f 100644
--- a/src-bind/com/android/contactsbind/ObjectFactory.java
+++ b/src-bind/com/android/contactsbind/ObjectFactory.java
@@ -42,11 +42,7 @@
         return new DeviceLocalAccountTypeFactory.Default(context);
     }
 
-    public static Fragment getDuplicatesFragment() {
-        return null;
-    }
-
-    public static Fragment getDuplicatesUtilFragment() {
+    public static Fragment getAssistantFragment() {
         return null;
     }
 
diff --git a/src/com/android/contacts/ContactsDrawerActivity.java b/src/com/android/contacts/ContactsDrawerActivity.java
index 3fc3c9d..68b9884 100644
--- a/src/com/android/contacts/ContactsDrawerActivity.java
+++ b/src/com/android/contacts/ContactsDrawerActivity.java
@@ -20,13 +20,13 @@
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.graphics.Color;
 import android.graphics.PorterDuff;
 import android.os.Bundle;
 import android.provider.ContactsContract.Intents;
 import android.support.annotation.LayoutRes;
 import android.support.design.widget.NavigationView;
-import android.support.v4.content.ContextCompat;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBarDrawerToggle;
@@ -49,6 +49,8 @@
 import com.android.contacts.common.list.ContactListFilter;
 import com.android.contacts.common.list.ContactListFilterController;
 import com.android.contacts.common.model.AccountTypeManager;
+import com.android.contacts.common.model.account.AccountDisplayInfo;
+import com.android.contacts.common.model.account.AccountDisplayInfoFactory;
 import com.android.contacts.common.model.account.AccountWithDataSet;
 import com.android.contacts.common.preference.ContactsPreferenceActivity;
 import com.android.contacts.common.util.AccountFilterUtil;
@@ -69,8 +71,6 @@
 import com.android.contacts.interactions.AccountFiltersFragment.AccountFiltersListener;
 import com.android.contacts.list.DefaultContactBrowseListFragment;
 import com.android.contacts.list.MultiSelectContactsListFragment;
-import com.android.contacts.common.model.account.AccountDisplayInfo;
-import com.android.contacts.common.model.account.AccountDisplayInfoFactory;
 import com.android.contacts.util.SharedPreferenceUtil;
 import com.android.contactsbind.HelpUtils;
 import com.android.contactsbind.ObjectFactory;
@@ -94,7 +94,7 @@
     public enum ContactsView {
         NONE,
         ALL_CONTACTS,
-        DUPLICATES,
+        ASSISTANT,
         GROUP_VIEW,
         ACCOUNT_VIEW,
     }
@@ -223,8 +223,15 @@
         mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
         mToggle = new ContactsActionBarDrawerToggle(this, mDrawer, mToolbar,
                 R.string.navigation_drawer_open, R.string.navigation_drawer_close);
+
         mDrawer.setDrawerListener(mToggle);
-        mToggle.syncState();
+        // Set fallback handler for when drawer is disabled.
+        mToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                onBackPressed();
+            }
+        });
 
         // Set up navigation mode.
         if (savedState != null) {
@@ -246,16 +253,32 @@
         }
     }
 
+    public void setDrawerLockMode(boolean enabled) {
+        // Prevent drawer from being opened by sliding from the start of screen.
+        mDrawer.setDrawerLockMode(enabled ? DrawerLayout.LOCK_MODE_UNLOCKED
+                : DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+
+        // Order of these statements matter.
+        // Display back button and disable drawer indicator.
+        if (enabled) {
+            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
+            mToggle.setDrawerIndicatorEnabled(true);
+        } else {
+            mToggle.setDrawerIndicatorEnabled(false);
+            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+        }
+    }
+
     private void setUpMenu() {
         final Menu menu = mNavigationView.getMenu();
 
-        if (ObjectFactory.getDuplicatesFragment() == null) {
-            menu.removeItem(R.id.nav_find_duplicates);
+        if (ObjectFactory.getAssistantFragment() == null) {
+            menu.removeItem(R.id.nav_assistant);
         } else {
-            final MenuItem findDupMenu = menu.findItem(R.id.nav_find_duplicates);
-            mIdMenuMap.put(R.id.nav_find_duplicates, findDupMenu);
-            if (isDuplicatesView()) {
-                updateMenuSelection(findDupMenu);
+            final MenuItem assistantMenu = menu.findItem(R.id.nav_assistant);
+            mIdMenuMap.put(R.id.nav_assistant, assistantMenu);
+            if (isAssistantView()) {
+                updateMenuSelection(assistantMenu);
             }
         }
 
@@ -306,6 +329,18 @@
         getWindow().setStatusBarColor(Color.TRANSPARENT);
     }
 
+    @Override
+    protected void onPostCreate(Bundle savedInstanceState) {
+        super.onPostCreate(savedInstanceState);
+        mToggle.syncState();
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        mToggle.onConfigurationChanged(newConfig);
+    }
+
     // Set up fragment manager to load groups and filters.
     protected void loadGroupsAndFilters() {
         final FragmentManager fragmentManager = getFragmentManager();
@@ -429,8 +464,8 @@
         return mCurrentView == ContactsView.GROUP_VIEW;
     }
 
-    protected boolean isDuplicatesView() {
-        return mCurrentView == ContactsView.DUPLICATES;
+    protected boolean isAssistantView() {
+        return mCurrentView == ContactsView.ASSISTANT;
     }
 
     protected boolean isAllContactsView() {
@@ -442,7 +477,7 @@
     }
 
     public boolean isInSecondLevel() {
-        return isGroupView() || isDuplicatesView();
+        return isGroupView() || isAssistantView();
     }
 
     protected abstract void onGroupMenuItemClicked(long groupId, String title);
@@ -556,9 +591,9 @@
                     HelpUtils.launchHelpAndFeedbackForMainScreen(ContactsDrawerActivity.this);
                 } else if (id == R.id.nav_all_contacts) {
                     switchToAllContacts();
-                } else if (id == R.id.nav_find_duplicates) {
-                    if (!isDuplicatesView()) {
-                        launchFindDuplicates();
+                } else if (id == R.id.nav_assistant) {
+                    if (!isAssistantView()) {
+                        launchAssistant();
                         updateMenuSelection(item);
                     }
                 } else if (item.getIntent() != null) {
@@ -599,7 +634,7 @@
                 mContactListFilterController, AppCompatActivity.RESULT_OK, intent);
     }
 
-    protected abstract void launchFindDuplicates();
+    protected abstract void launchAssistant();
 
     protected abstract DefaultContactBrowseListFragment getAllFragment();
 
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index b2a0a07..1950eb2 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -20,15 +20,13 @@
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
-import android.content.ContentResolver;
 import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
 import android.content.ContentUris;
 import android.content.Context;
 import android.content.Intent;
-import android.content.SyncStatusObserver;
 import android.content.IntentFilter;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
+import android.content.SyncStatusObserver;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -40,7 +38,6 @@
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.SwipeRefreshLayout;
-import android.text.TextUtils;
 import android.util.Log;
 import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
@@ -65,8 +62,6 @@
 import com.android.contacts.common.logging.Logger;
 import com.android.contacts.common.logging.ScreenEvent.ScreenType;
 import com.android.contacts.common.model.AccountTypeManager;
-import com.android.contacts.common.model.account.AccountDisplayInfo;
-import com.android.contacts.common.model.account.AccountDisplayInfoFactory;
 import com.android.contacts.common.model.account.AccountWithDataSet;
 import com.android.contacts.common.util.AccountFilterUtil;
 import com.android.contacts.common.util.Constants;
@@ -96,9 +91,11 @@
     private static final String TAG_ALL = "contacts-all";
     private static final String TAG_UNAVAILABLE = "contacts-unavailable";
     private static final String TAG_GROUP_VIEW = "contacts-groups";
-    private static final String TAG_DUPLICATES = "contacts-duplicates";
-    private static final String TAG_SECOND_LEVEL = "second-level";
-    // Tag for DuplicatesUtilFragment.java
+    public static final String TAG_ASSISTANT = "contacts-assistant";
+    public static final String TAG_SECOND_LEVEL = "second-level";
+    public static final String TAG_THIRD_LEVEL = "third-level";
+
+    public static final String TAG_DUPLICATES = "DuplicatesFragment";
     public static final String TAG_DUPLICATES_UTIL = "DuplicatesUtilFragment";
 
     private static final String KEY_GROUP_URI = "groupUri";
@@ -631,8 +628,8 @@
             return;
         }
 
-        if (isDuplicatesView()) {
-            switchToAllContacts();
+        if (isAssistantView()) {
+            onBackPressedAssistantView();
             return;
         }
 
@@ -662,6 +659,14 @@
         }
     }
 
+    private void onBackPressedAssistantView() {
+        if (!popThirdLevel()) {
+            switchToAllContacts();
+        } else {
+            setDrawerLockMode(/* enabled */ true);
+        }
+    }
+
     // Returns true if back event is handled in this method.
     private boolean maybeHandleInAllFragment() {
         if (isAllFragmentInSelectionMode()) {
@@ -769,8 +774,8 @@
     }
 
     @Override
-    protected void launchFindDuplicates() {
-        switchView(ContactsView.DUPLICATES);
+    protected void launchAssistant() {
+        switchView(ContactsView.ASSISTANT);
     }
 
     private void switchView(ContactsView contactsView) {
@@ -784,20 +789,14 @@
             }
             transaction.replace(
                     R.id.contacts_list_container, mMembersFragment, TAG_GROUP_VIEW);
-        } else if (isDuplicatesView()) {
-            Fragment duplicatesFragment = fragmentManager.findFragmentByTag(TAG_DUPLICATES);
-            Fragment duplicatesUtilFragment =
-                    fragmentManager.findFragmentByTag(TAG_DUPLICATES_UTIL);
-            if (duplicatesFragment == null || duplicatesUtilFragment == null) {
-                duplicatesFragment = ObjectFactory.getDuplicatesFragment();
-                duplicatesUtilFragment = ObjectFactory.getDuplicatesUtilFragment();
-                duplicatesUtilFragment.setTargetFragment(duplicatesFragment, /* requestCode */ 0);
+        } else if(isAssistantView()) {
+            Fragment assistantFragment = fragmentManager.findFragmentByTag(TAG_ASSISTANT);
+            if (assistantFragment == null) {
+                assistantFragment = ObjectFactory.getAssistantFragment();
             }
-            transaction.replace(
-                    R.id.contacts_list_container, duplicatesFragment, TAG_DUPLICATES);
-            if (!duplicatesUtilFragment.isAdded()) {
-                transaction.add(duplicatesUtilFragment, TAG_DUPLICATES_UTIL);
-                resetToolBarStatusBarColor();
+            if (assistantFragment != null) {
+                transaction.replace(
+                        R.id.contacts_list_container, assistantFragment, TAG_ASSISTANT);
             }
             resetToolBarStatusBarColor();
         }
@@ -821,6 +820,11 @@
         super.switchToAllContacts();
     }
 
+    private boolean popThirdLevel() {
+        return getFragmentManager().popBackStackImmediate(
+                TAG_THIRD_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+    }
+
     private void popSecondLevel() {
         getFragmentManager().popBackStackImmediate(
                 TAG_SECOND_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE);