Merge "Show hamburger promo after users start using the App." into ub-contactsdialer-f-dev
diff --git a/src/com/android/contacts/ContactsDrawerActivity.java b/src/com/android/contacts/ContactsDrawerActivity.java
index 6ae6a59..5f70b14 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();
}
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/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);
+ }
+}