Merge "Add all intents accpeted by PeopleActivity to AllIntentsActivity" into ub-contactsdialer-f-dev
diff --git a/src/com/android/contacts/ContactsDrawerActivity.java b/src/com/android/contacts/ContactsDrawerActivity.java
index 6ae6a59..e4eef51 100644
--- a/src/com/android/contacts/ContactsDrawerActivity.java
+++ b/src/com/android/contacts/ContactsDrawerActivity.java
@@ -71,6 +71,7 @@
 import com.android.contacts.interactions.AccountFiltersFragment;
 import com.android.contacts.interactions.AccountFiltersFragment.AccountFiltersListener;
 import com.android.contacts.quickcontact.QuickContactActivity;
+import com.android.contacts.util.SharedPreferenceUtil;
 import com.android.contactsbind.Assistants;
 import com.android.contactsbind.HelpUtils;
 
@@ -111,6 +112,8 @@
     private class ContactsActionBarDrawerToggle extends ActionBarDrawerToggle {
 
         private Runnable mRunnable;
+        private boolean mMenuClickedBefore = SharedPreferenceUtil.getHamburgerMenuClickedBefore(
+                ContactsDrawerActivity.this);
 
         public ContactsActionBarDrawerToggle(AppCompatActivity activity, DrawerLayout drawerLayout,
                 Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) {
@@ -121,6 +124,10 @@
         @Override
         public void onDrawerOpened(View drawerView) {
             super.onDrawerOpened(drawerView);
+            if (!mMenuClickedBefore) {
+                SharedPreferenceUtil.setHamburgerMenuClickedBefore(ContactsDrawerActivity.this);
+                mMenuClickedBefore = true;
+            }
             invalidateOptionsMenu();
         }
 
@@ -217,7 +224,7 @@
             clearCheckedMenus();
             mIdMenuMap.get(R.id.nav_find_duplicates).setCheckable(true);
             mIdMenuMap.get(R.id.nav_find_duplicates).setChecked(true);
-            updateScrollPosition(DUPLICATES_POSITION);
+            maybeUpdateScrollPosition(DUPLICATES_POSITION);
         }
 
         if (savedState != null && savedState.containsKey(KEY_NEW_GROUP_ACCOUNT)) {
@@ -226,7 +233,11 @@
         }
     }
 
-    private void updateScrollPosition(int position) {
+    private void maybeUpdateScrollPosition(int position) {
+        if (mDrawer.isDrawerOpen(GravityCompat.START)) {
+            if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Don't scroll menu when drawer open");
+            return;
+        }
         final RecyclerView recyclerView = (RecyclerView) mNavigationView.getChildAt(0);
         final LinearLayoutManager layoutManager =
                 (LinearLayoutManager) recyclerView.getLayoutManager();
@@ -409,7 +420,7 @@
                 && mGroupMenuMap.get(groupMetadata.groupId) != null) {
             mGroupMenuMap.get(groupMetadata.groupId).setCheckable(true);
             mGroupMenuMap.get(groupMetadata.groupId).setChecked(true);
-            updateScrollPosition(mGroupMenuMap.get(groupMetadata.groupId).getOrder());
+            maybeUpdateScrollPosition(mGroupMenuMap.get(groupMetadata.groupId).getOrder());
         }
     }
 
@@ -513,13 +524,13 @@
             if (mIdMenuMap != null && mIdMenuMap.get(R.id.nav_all_contacts) != null) {
                 mIdMenuMap.get(R.id.nav_all_contacts).setCheckable(true);
                 mIdMenuMap.get(R.id.nav_all_contacts).setChecked(true);
-                updateScrollPosition(ALL_CONTACTS_POSITION);
+                maybeUpdateScrollPosition(ALL_CONTACTS_POSITION);
             }
         } else {
             if (mFilterMenuMap != null && mFilterMenuMap.get(filter) != null) {
                 mFilterMenuMap.get(filter).setCheckable(true);
                 mFilterMenuMap.get(filter).setChecked(true);
-                updateScrollPosition(mFilterMenuMap.get(filter).getOrder());
+                maybeUpdateScrollPosition(mFilterMenuMap.get(filter).getOrder());
             }
         }
     }
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 0ee83df..cc2428e 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -85,9 +85,6 @@
 
     private static final String PERSISTENT_LAST_TAB = "actionBarAdapter.lastTab";
 
-    private static final String PREFERENCE_KEY_SHOULD_SHOW_HAMBURGER_FEATURE_HIGHLIGHT =
-            "shouldShowHamburgerFeatureHighlight";
-
     private boolean mSelectionMode;
     private boolean mSearchMode;
     private String mQueryString;
@@ -239,7 +236,6 @@
             mQueryString = request.getQueryString();
             mCurrentTab = loadLastTabPreference();
             mSelectionMode = false;
-            addHamburgerHighlight();
         } else {
             mSearchMode = savedState.getBoolean(EXTRA_KEY_SEARCH_MODE);
             mSelectionMode = savedState.getBoolean(EXTRA_KEY_SELECTED_MODE);
@@ -260,6 +256,7 @@
         if (mSearchMode && !TextUtils.isEmpty(mQueryString)) {
             setQueryString(mQueryString);
         }
+        addHamburgerFeatureHighlight();
     }
 
     public void setListener(Listener listener) {
@@ -434,7 +431,7 @@
         }
     }
 
-    private void addHamburgerHighlight() {
+    private void addHamburgerFeatureHighlight() {
         if (mHamburgerFeatureHighlight == null) {
             mHamburgerFeatureHighlight = FeatureHighlight.Builder
                     .forView(new ToolbarNavigationIconFinder())
@@ -452,19 +449,6 @@
         return mHamburgerFeatureHighlight;
     }
 
-    public boolean shouldShowHamburgerFeatureHighlight(Context context) {
-        final SharedPreferences prefs = context.getSharedPreferences(
-                context.getPackageName(), Context.MODE_PRIVATE);
-        return prefs.getBoolean(PREFERENCE_KEY_SHOULD_SHOW_HAMBURGER_FEATURE_HIGHLIGHT, true);
-    }
-
-    public void setHamburgerFeatureHighlightShown(Context context) {
-        final SharedPreferences prefs = context.getSharedPreferences(
-                context.getPackageName(), Context.MODE_PRIVATE);
-        prefs.edit().putBoolean(PREFERENCE_KEY_SHOULD_SHOW_HAMBURGER_FEATURE_HIGHLIGHT, false)
-                .apply();
-    }
-
     private void update(boolean skipAnimation) {
         updateStatusBarColor();
 
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index f1392f8..2e32e11 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -87,6 +87,7 @@
 import com.android.contacts.list.OnContactsUnavailableActionListener;
 import com.android.contacts.quickcontact.QuickContactActivity;
 import com.android.contacts.util.DialogManager;
+import com.android.contacts.util.SharedPreferenceUtil;
 import com.google.android.libraries.material.featurehighlight.FeatureHighlight;
 
 import java.util.List;
@@ -237,13 +238,16 @@
             Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate finish");
         }
         getWindow().setBackgroundDrawable(null);
+    }
 
-        if (mActionBarAdapter.shouldShowHamburgerFeatureHighlight(this)) {
+    private void maybeShowHamburgerFeatureHighlight() {
+        if (!mActionBarAdapter.isSearchMode() && !mActionBarAdapter.isSelectionMode()
+                && SharedPreferenceUtil.getShouldShowHamburgerPromo(this)) {
             final FeatureHighlight hamburgerFeatureHighlight =
                     mActionBarAdapter.getHamburgerFeatureHighlight();
             if (hamburgerFeatureHighlight != null) {
                 hamburgerFeatureHighlight.show(this);
-                mActionBarAdapter.setHamburgerFeatureHighlightShown(this);
+                SharedPreferenceUtil.setHamburgerPromoDisplayedBefore(this);
             }
         }
     }
@@ -427,6 +431,7 @@
         // Current tab may have changed since the last onSaveInstanceState().  Make sure
         // the actual contents match the tab.
         updateFragmentsVisibility();
+        maybeShowHamburgerFeatureHighlight();
     }
 
     @Override
@@ -575,6 +580,7 @@
             case ActionBarAdapter.Listener.Action.STOP_SEARCH_AND_SELECTION_MODE:
                 setQueryTextToFragment("");
                 updateFragmentsVisibility();
+                maybeShowHamburgerFeatureHighlight();
                 invalidateOptionsMenu();
                 showFabWithAnimation(shouldShowFabForAccount());
                 break;
@@ -594,6 +600,9 @@
         updateFragmentsVisibility();
         invalidateOptionsMenu();
         showFabWithAnimation(/* showFab */ false);
+        if (!SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) {
+            SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this);
+        }
     }
 
     @Override
diff --git a/src/com/android/contacts/group/GroupListItem.java b/src/com/android/contacts/group/GroupListItem.java
index 3bfcdd3..f2359b6 100644
--- a/src/com/android/contacts/group/GroupListItem.java
+++ b/src/com/android/contacts/group/GroupListItem.java
@@ -15,8 +15,6 @@
  */
 package com.android.contacts.group;
 
-import java.util.Objects;
-
 /**
  * Meta-data for a contact group.  We load all groups associated with the contact's
  * constituent accounts.
@@ -85,36 +83,4 @@
     public String getSystemId() {
         return mSystemId;
     }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(mAccountName, mAccountType, mDataSet, mGroupId, mTitle,
-                mIsFirstGroupInAccount, mMemberCount, mIsReadOnly, mSystemId);
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (this == other) {
-            return true;
-        }
-
-        if (!(other instanceof GroupListItem)) {
-            return false;
-        }
-
-        final GroupListItem otherGroup = (GroupListItem) other;
-        if (!Objects.equals(mAccountName, otherGroup.getAccountName())
-                || !Objects.equals(mAccountType, otherGroup.getAccountType())
-                || !Objects.equals(mDataSet, otherGroup.getDataSet())
-                || !(mGroupId == otherGroup.getGroupId())
-                || !Objects.equals(mTitle, otherGroup.getTitle())
-                || !(mIsFirstGroupInAccount == otherGroup.isFirstGroupInAccount())
-                || !(mMemberCount == otherGroup.getMemberCount())
-                || !(mIsReadOnly == otherGroup.isReadOnly())
-                || !Objects.equals(mSystemId, otherGroup.getSystemId())) {
-            return false;
-        }
-
-        return true;
-    }
 }
\ No newline at end of file
diff --git a/src/com/android/contacts/group/GroupsFragment.java b/src/com/android/contacts/group/GroupsFragment.java
index 4c9e251..be1b44a 100644
--- a/src/com/android/contacts/group/GroupsFragment.java
+++ b/src/com/android/contacts/group/GroupsFragment.java
@@ -18,11 +18,11 @@
 
 import android.app.Fragment;
 import android.app.LoaderManager;
+import android.content.Context;
 import android.content.CursorLoader;
 import android.content.Loader;
 import android.database.Cursor;
 import android.os.Bundle;
-import android.util.Log;
 
 import com.android.contacts.GroupListLoader;
 
@@ -34,8 +34,6 @@
  */
 public final class GroupsFragment extends Fragment {
 
-    private static final String TAG = GroupsFragment.class.getSimpleName();
-
     private static final int LOADER_GROUPS = 1;
 
     /**
@@ -59,26 +57,12 @@
 
                 @Override
                 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
-                    final List<GroupListItem> newGroupListItems = new ArrayList<>();
+                    mGroupListItems.clear();
                     for (int i = 0; i < data.getCount(); i++) {
                         if (data.moveToNext()) {
-                            newGroupListItems.add(GroupUtil.getGroupListItem(data, i));
+                            mGroupListItems.add(GroupUtil.getGroupListItem(data, i));
                         }
                     }
-
-                    if (mGroupListItems.equals(newGroupListItems)) {
-                        if (Log.isLoggable(TAG, Log.VERBOSE)) {
-                            Log.v(TAG, "The same groups loaded, returning.");
-                        }
-                        return;
-                    }
-
-                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
-                        Log.v(TAG, "New group(s) loaded.");
-                    }
-
-                    mGroupListItems.clear();
-                    mGroupListItems.addAll(newGroupListItems);
                     if (mListener != null) {
                         mListener.onGroupsLoaded(mGroupListItems);
                     }
diff --git a/src/com/android/contacts/list/MultiSelectContactsListFragment.java b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
index 8b55047..f5c6d34 100644
--- a/src/com/android/contacts/list/MultiSelectContactsListFragment.java
+++ b/src/com/android/contacts/list/MultiSelectContactsListFragment.java
@@ -330,7 +330,13 @@
         if (accountFilterContainer == null) {
             return;
         }
-        if (firstVisibleItem == 0) {
+
+        int firstCompletelyVisibleItem = firstVisibleItem;
+        if (view != null && view.getChildAt(0) != null && view.getChildAt(0).getTop() < 0) {
+            firstCompletelyVisibleItem++;
+        }
+
+        if (firstCompletelyVisibleItem == 0) {
             ViewCompat.setElevation(accountFilterContainer, 0);
         } else {
             ViewCompat.setElevation(accountFilterContainer,
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 16f137e..e918233 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -171,6 +171,7 @@
 import com.android.contacts.util.ImageViewDrawableSetter;
 import com.android.contacts.util.PhoneCapabilityTester;
 import com.android.contacts.util.SchedulingUtils;
+import com.android.contacts.util.SharedPreferenceUtil;
 import com.android.contacts.util.StructuredPostalUtils;
 import com.android.contacts.widget.MultiShrinkScroller;
 import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener;
@@ -2546,6 +2547,13 @@
 
     @Override
     public void onBackPressed() {
+        final int previousScreenType = getIntent().getIntExtra
+                (EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN);
+        if ((previousScreenType == ScreenType.ALL_CONTACTS
+                || previousScreenType == ScreenType.FAVORITES)
+                && !SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) {
+            SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this);
+        }
         if (mScroller != null) {
             if (!mIsExitAnimationInProgress) {
                 mScroller.scrollOffBottom();
diff --git a/src/com/android/contacts/util/SharedPreferenceUtil.java b/src/com/android/contacts/util/SharedPreferenceUtil.java
new file mode 100644
index 0000000..e33c7aa
--- /dev/null
+++ b/src/com/android/contacts/util/SharedPreferenceUtil.java
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+package com.android.contacts.util;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+public class SharedPreferenceUtil {
+
+    private static final String PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED_BEFORE =
+            "hamburgerPromoDisplayedBefore";
+
+    private static final String PREFERENCE_KEY_HAMBURGER_MENU_CLICKED_BEFORE =
+            "hamburgerMenuClickedBefore";
+
+    private static final String PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED_BEFORE =
+            "hamburgerPromoTriggerActionHappenedBefore";
+
+    public static boolean getHamburgerPromoDisplayedBefore(Context context) {
+        return getSharedPreferences(context)
+                .getBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED_BEFORE, false);
+    }
+
+    public static void setHamburgerPromoDisplayedBefore(Context context) {
+        getSharedPreferences(context).edit()
+                .putBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED_BEFORE, true)
+                .apply();
+    }
+
+    public static boolean getHamburgerMenuClickedBefore(Context context) {
+        return getSharedPreferences(context)
+                .getBoolean(PREFERENCE_KEY_HAMBURGER_MENU_CLICKED_BEFORE, false);
+    }
+
+    public static void setHamburgerMenuClickedBefore(Context context) {
+        getSharedPreferences(context).edit()
+                .putBoolean(PREFERENCE_KEY_HAMBURGER_MENU_CLICKED_BEFORE, true)
+                .apply();
+    }
+
+    public static boolean getHamburgerPromoTriggerActionHappenedBefore(Context context) {
+        return getSharedPreferences(context)
+                .getBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED_BEFORE, false);
+    }
+
+    public static void setHamburgerPromoTriggerActionHappenedBefore(Context context) {
+        getSharedPreferences(context).edit()
+                .putBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED_BEFORE, true)
+                .apply();
+    }
+
+    /**
+     * Show hamburger promo if:
+     * 1) Hamburger menu is never clicked before
+     * 2) Hamburger menu promo is never displayed before
+     * 3) There is at least one available user action
+     *      (for now, available user actions to trigger to displayed hamburger promo are:
+     *       a: QuickContact UI back to PeopleActivity
+     *       b: Search action back to PeopleActivity)
+     */
+    public static boolean getShouldShowHamburgerPromo(Context context) {
+        return !getHamburgerMenuClickedBefore(context)
+                && getHamburgerPromoTriggerActionHappenedBefore(context)
+                && !getHamburgerPromoDisplayedBefore(context);
+    }
+
+    private static SharedPreferences getSharedPreferences(Context context) {
+        return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
+    }
+}