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

Commit e884c2c7 authored by Fengjiang Li's avatar Fengjiang Li
Browse files

Support predictive back from all apps to home

bug: b/238475505
Test: manual

Change-Id: Ibf4f7f41a26b044a538e2cd566d2297ed88f1b99
parent bf69ef03
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -69,9 +69,13 @@ import android.view.HapticFeedbackConstants;
import android.view.RemoteAnimationTarget;
import android.view.View;
import android.view.WindowManagerGlobal;
import android.window.BackEvent;
import android.window.OnBackAnimationCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.SplashScreen;

import androidx.annotation.BinderThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.app.viewcapture.ViewCapture;
@@ -105,6 +109,8 @@ import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory;
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.taskbar.TaskbarManager;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.uioverrides.QuickstepWidgetHolder.QuickstepHolderFactory;
import com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationFactory;
import com.android.launcher3.uioverrides.touchcontrollers.NavBarToHomeTouchController;
@@ -623,6 +629,29 @@ public class QuickstepLauncher extends Launcher {
        }
    }

    @Override
    protected void registerBackDispatcher() {
        getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
                OnBackInvokedDispatcher.PRIORITY_DEFAULT,
                new OnBackAnimationCallback() {
                    @Override
                    public void onBackInvoked() {
                        onBackPressed();
                        TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
                    }

                    @Override
                    public void onBackProgressed(@NonNull BackEvent backEvent) {
                        QuickstepLauncher.this.onBackProgressed(backEvent.getProgress());
                    }

                    @Override
                    public void onBackCancelled() {
                        QuickstepLauncher.this.onBackCancelled();
                    }
                });
    }

    private void onTaskbarInAppDisplayProgressUpdate(float progress, int flag) {
        if (mTaskbarManager == null
                || mTaskbarManager.getCurrentActivityContext() == null
+12 −8
Original line number Diff line number Diff line
@@ -176,14 +176,7 @@ public abstract class BaseActivity extends Activity implements ActivityContext {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Utilities.ATLEAST_T) {
            getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
                    OnBackInvokedDispatcher.PRIORITY_DEFAULT,
                    () -> {
                        onBackPressed();
                        TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
                    });
        }
        registerBackDispatcher();
    }

    @Override
@@ -246,6 +239,17 @@ public abstract class BaseActivity extends Activity implements ActivityContext {

    }

    protected void registerBackDispatcher() {
        if (Utilities.ATLEAST_T) {
            getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
                    OnBackInvokedDispatcher.PRIORITY_DEFAULT,
                    () -> {
                        onBackPressed();
                        TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
                    });
        }
    }

    public boolean isStarted() {
        return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0;
    }
+9 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.CallSuper;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@@ -2065,6 +2066,14 @@ public class Launcher extends StatefulActivity<LauncherState>
        mStateManager.getState().onBackPressed(this);
    }

    protected void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float backProgress) {
        mStateManager.getState().onBackProgressed(this, backProgress);
    }

    protected void onBackCancelled() {
        mStateManager.getState().onBackCancelled(this);
    }

    protected void onScreenOff() {
        // Reset AllApps to its initial state only if we are not in the middle of
        // processing a multi-step drop
+23 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import android.content.Context;
import android.graphics.Color;
import android.view.animation.Interpolator;

import androidx.annotation.FloatRange;

import com.android.launcher3.statemanager.BaseState;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.states.HintState;
@@ -342,6 +344,27 @@ public abstract class LauncherState implements BaseState<LauncherState> {
        }
    }

    /**
     * Find {@link StateManager} and target {@link LauncherState} to handle back progress in
     * predictive back gesture.
     */
    public void onBackProgressed(
            Launcher launcher, @FloatRange(from = 0.0, to = 1.0) float backProgress) {
        StateManager<LauncherState> lsm = launcher.getStateManager();
        LauncherState toState = lsm.getLastState();
        lsm.onBackProgressed(toState, backProgress);
    }

    /**
     * Find {@link StateManager} and target {@link LauncherState} to handle backProgress in
     * predictive back gesture.
     */
    public void onBackCancelled(Launcher launcher) {
        StateManager<LauncherState> lsm = launcher.getStateManager();
        LauncherState toState = lsm.getLastState();
        lsm.onBackCancelled(toState);
    }

    public static abstract class PageAlphaProvider {

        public final Interpolator interpolator;
+56 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.allapps;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.ALL_APPS_CONTENT;
@@ -33,11 +34,15 @@ import android.view.HapticFeedbackConstants;
import android.view.View;
import android.view.animation.Interpolator;

import androidx.annotation.FloatRange;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.AnimatorListeners;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PropertySetter;
import com.android.launcher3.statemanager.StateManager.StateHandler;
@@ -61,6 +66,8 @@ public class AllAppsTransitionController
        implements StateHandler<LauncherState>, OnDeviceProfileChangeListener {
    // This constant should match the second derivative of the animator interpolator.
    public static final float INTERP_COEFF = 1.7f;
    private static final float SWIPE_ALL_APPS_TO_HOME_MIN_SCALE = 0.9f;
    private static final int REVERT_SWIPE_ALL_APPS_TO_HOME_ANIMATION_DURATION_MS = 200;

    public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS =
            new FloatProperty<AllAppsTransitionController>("allAppsProgress") {
@@ -139,6 +146,7 @@ public class AllAppsTransitionController
    private ActivityAllAppsContainerView<Launcher> mAppsView;

    private final Launcher mLauncher;
    private final AnimatedFloat mAllAppScale = new AnimatedFloat(this::onScaleProgressChanged);
    private boolean mIsVerticalLayout;

    // Whether this class should take care of closing the keyboard.
@@ -232,6 +240,52 @@ public class AllAppsTransitionController
        onProgressAnimationEnd();
    }

    @Override
    public void onBackProgressed(
            LauncherState toState, @FloatRange(from = 0.0, to = 1.0) float backProgress) {
        if (!mLauncher.isInState(ALL_APPS) || !NORMAL.equals(toState)) {
            return;
        }

        float deceleratedProgress =
                Interpolators.PREDICTIVE_BACK_DECELERATED_EASE.getInterpolation(backProgress);
        float scaleProgress = SWIPE_ALL_APPS_TO_HOME_MIN_SCALE
                + (1 - SWIPE_ALL_APPS_TO_HOME_MIN_SCALE) * (1 - deceleratedProgress);

        mAllAppScale.updateValue(scaleProgress);
    }

    @Override
    public void onBackCancelled(LauncherState toState) {
        if (!mLauncher.isInState(ALL_APPS) || !NORMAL.equals(toState)) {
            return;
        }

        // TODO: once ag/20649618 is picked into tm-qpr, we don't need to animate back on cancel
        // swipe because framework will do that for us in {@link #onBackProgressed}.
        animateAllAppsToNoScale();
    }

    private void onScaleProgressChanged() {
        final float scaleProgress = mAllAppScale.value;
        SCALE_PROPERTY.set(mLauncher.getAppsView(), scaleProgress);
        mLauncher.getScrimView().setScrimHeaderScale(scaleProgress);

        AllAppsRecyclerView rv = mLauncher.getAppsView().getActiveRecyclerView();
        if (rv != null && rv.getScrollbar() != null) {
            rv.getScrollbar().setVisibility(scaleProgress < 1f ? View.INVISIBLE : View.VISIBLE);
        }

        // TODO(b/264906511): We need to disable view clipping on all apps' parent views so
        //  that the extra roll of app icons are displayed.
    }

    private void animateAllAppsToNoScale() {
        mAllAppScale.animateToValue(1f)
                .setDuration(REVERT_SWIPE_ALL_APPS_TO_HOME_ANIMATION_DURATION_MS)
                .start();
    }

    /**
     * Creates an animation which updates the vertical transition progress and updates all the
     * dependent UI using various animation events
@@ -258,6 +312,8 @@ public class AllAppsTransitionController
                if (config.userControlled && success && mShouldControlKeyboard) {
                    mLauncher.getAppsView().getSearchUiManager().getEditText().hideKeyboard();
                }

                mAllAppScale.updateValue(1f);
            });
        }

Loading