Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7b0e00f authored by Tingting Wang's avatar Tingting Wang Committed by Android (Google) Code Review
Browse files

Merge "Show hamburger promo after users start using the App." into ub-contactsdialer-f-dev

parents 967cffda ac9596e8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import com.android.contacts.group.GroupsFragment.GroupsListener;
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 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i
    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 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!mMenuClickedBefore) {
                SharedPreferenceUtil.setHamburgerMenuClickedBefore(ContactsDrawerActivity.this);
                mMenuClickedBefore = true;
            }
            invalidateOptionsMenu();
        }

+2 −18
Original line number Diff line number Diff line
@@ -85,9 +85,6 @@ public class ActionBarAdapter implements OnCloseListener {

    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 @@ public class ActionBarAdapter implements OnCloseListener {
            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 @@ public class ActionBarAdapter implements OnCloseListener {
        if (mSearchMode && !TextUtils.isEmpty(mQueryString)) {
            setQueryString(mQueryString);
        }
        addHamburgerFeatureHighlight();
    }

    public void setListener(Listener listener) {
@@ -434,7 +431,7 @@ public class ActionBarAdapter implements OnCloseListener {
        }
    }

    private void addHamburgerHighlight() {
    private void addHamburgerFeatureHighlight() {
        if (mHamburgerFeatureHighlight == null) {
            mHamburgerFeatureHighlight = FeatureHighlight.Builder
                    .forView(new ToolbarNavigationIconFinder())
@@ -452,19 +449,6 @@ public class ActionBarAdapter implements OnCloseListener {
        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();

+11 −2
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ import com.android.contacts.list.OnContactBrowserActionListener;
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 @@ public class PeopleActivity extends ContactsDrawerActivity implements
            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 @@ public class PeopleActivity extends ContactsDrawerActivity implements
        // Current tab may have changed since the last onSaveInstanceState().  Make sure
        // the actual contents match the tab.
        updateFragmentsVisibility();
        maybeShowHamburgerFeatureHighlight();
    }

    @Override
@@ -575,6 +580,7 @@ public class PeopleActivity extends ContactsDrawerActivity implements
            case ActionBarAdapter.Listener.Action.STOP_SEARCH_AND_SELECTION_MODE:
                setQueryTextToFragment("");
                updateFragmentsVisibility();
                maybeShowHamburgerFeatureHighlight();
                invalidateOptionsMenu();
                showFabWithAnimation(shouldShowFabForAccount());
                break;
@@ -594,6 +600,9 @@ public class PeopleActivity extends ContactsDrawerActivity implements
        updateFragmentsVisibility();
        invalidateOptionsMenu();
        showFabWithAnimation(/* showFab */ false);
        if (!SharedPreferenceUtil.getHamburgerPromoTriggerActionHappenedBefore(this)) {
            SharedPreferenceUtil.setHamburgerPromoTriggerActionHappenedBefore(this);
        }
    }

    @Override
+8 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ import com.android.contacts.quickcontact.WebAddress.ParseException;
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 @@ public class QuickContactActivity extends ContactsActivity

    @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();
+84 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}