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

Commit d9b48356 authored by Tony Wickham's avatar Tony Wickham Committed by android-build-merger
Browse files

Merge "Adjust recents onboarding logic" into pi-dev am: 2cb0244a

am: 5e828f57

Change-Id: I1026bb850649fdeeeafb5604f223b5a2f1d1661a
parents 66499b45 5e828f57
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -65,6 +66,8 @@ public class RecentsOnboarding {
    private static final long SHOW_HIDE_DURATION_MS = 300;
    // Don't show the onboarding until the user has launched this number of apps.
    private static final int SHOW_ON_APP_LAUNCH = 2;
    // After explicitly dismissing, show again after launching this number of apps.
    private static final int SHOW_ON_APP_LAUNCH_AFTER_DISMISS = 5;

    private final Context mContext;
    private final WindowManager mWindowManager;
@@ -84,6 +87,9 @@ public class RecentsOnboarding {
    private boolean mTaskListenerRegistered;
    private boolean mLayoutAttachedToWindow;
    private boolean mBackgroundIsLight;
    private int mLastTaskId;
    private boolean mHasDismissed;
    private int mNumAppsLaunchedSinceDismiss;

    private final SysUiTaskStackChangeListener mTaskListener = new SysUiTaskStackChangeListener() {
        @Override
@@ -94,15 +100,27 @@ public class RecentsOnboarding {
                hide(true);
                return;
            }
            if (info.id == mLastTaskId) {
                // We only count launches that go to a new task.
                return;
            }
            int activityType = info.configuration.windowConfiguration.getActivityType();
            int numAppsLaunched = Prefs.getInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, 0);
            if (activityType == ACTIVITY_TYPE_STANDARD) {
                mLastTaskId = info.id;
                int numAppsLaunched = mHasDismissed ? mNumAppsLaunchedSinceDismiss
                        : Prefs.getInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, 0);
                int showOnAppLaunch = mHasDismissed ? SHOW_ON_APP_LAUNCH_AFTER_DISMISS
                        : SHOW_ON_APP_LAUNCH;
                numAppsLaunched++;
                if (numAppsLaunched >= SHOW_ON_APP_LAUNCH) {
                if (numAppsLaunched >= showOnAppLaunch) {
                    show();
                } else {
                    if (mHasDismissed) {
                        mNumAppsLaunchedSinceDismiss = numAppsLaunched;
                    } else {
                        Prefs.putInt(mContext, Prefs.Key.NUM_APPS_LAUNCHED, numAppsLaunched);
                    }
                }
            } else {
                hide(false);
            }
@@ -115,6 +133,7 @@ public class RecentsOnboarding {
        public void onViewAttachedToWindow(View view) {
            if (view == mLayout) {
                mLayoutAttachedToWindow = true;
                mHasDismissed = false;
            }
        }

@@ -149,7 +168,11 @@ public class RecentsOnboarding {

        mLayout.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
        mLayout.setBackground(mBackgroundDrawable);
        mDismissView.setOnClickListener(v -> hide(true));
        mDismissView.setOnClickListener(v -> {
            hide(true);
            mHasDismissed = true;
            mNumAppsLaunchedSinceDismiss = 0;
        });

        if (RESET_PREFS_FOR_DEBUG) {
            Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_RECENTS_ONBOARDING, false);
@@ -180,6 +203,8 @@ public class RecentsOnboarding {
            ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskListener);
            mTaskListenerRegistered = false;
        }
        mHasDismissed = false;
        mNumAppsLaunchedSinceDismiss = 0;
        hide(false);
    }