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

Commit ad3915e7 authored by Fengjiang Li's avatar Fengjiang Li Committed by Android (Google) Code Review
Browse files

Merge "Adding support for skipping animation cancel on reapply" into main

parents 07f4f9b9 98b5e1f0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class PortraitStatesTouchController extends AbstractStateChangeTouchContr
    protected StateAnimationConfig getConfigForStates(
            LauncherState fromState, LauncherState toState) {
        final StateAnimationConfig config = new StateAnimationConfig();
        config.userControlled = true;
        config.animProps |= StateAnimationConfig.USER_CONTROLLED;
        if (fromState == NORMAL && toState == ALL_APPS) {
            AllAppsSwipeController.applyNormalToAllAppsAnimConfig(mLauncher, config);
        } else if (fromState == ALL_APPS && toState == NORMAL) {
+2 −2
Original line number Diff line number Diff line
@@ -342,7 +342,7 @@ public class AllAppsTransitionController
            });
        }

        if(FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get() && config.userControlled
        if (FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get() && config.isUserControlled()
                && Utilities.ATLEAST_S) {
            if (toState == ALL_APPS) {
                builder.addOnFrameListener(
@@ -367,7 +367,7 @@ public class AllAppsTransitionController

        // need to decide depending on the release velocity
        Interpolator verticalProgressInterpolator = config.getInterpolator(ANIM_VERTICAL_PROGRESS,
                config.userControlled ? LINEAR : DECELERATE_1_7);
                config.isUserControlled() ? LINEAR : DECELERATE_1_7);
        Animator anim = createSpringAnimation(mProgress, targetProgress);
        anim.setInterpolator(verticalProgressInterpolator);
        builder.add(anim);
+15 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3.statemanager;
import static android.animation.ValueAnimator.areAnimatorsEnabled;

import static com.android.launcher3.anim.AnimatorPlaybackController.callListenerCommandRecursively;
import static com.android.launcher3.states.StateAnimationConfig.HANDLE_STATE_APPLY;
import static com.android.launcher3.states.StateAnimationConfig.SKIP_ALL_ANIMATIONS;

import android.animation.Animator;
@@ -36,6 +37,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.states.StateAnimationConfig.AnimationFlags;
import com.android.launcher3.states.StateAnimationConfig.AnimationPropertyFlags;
import com.android.launcher3.testing.shared.TestProtocol;

import java.io.PrintWriter;
@@ -189,7 +191,7 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {

    public void reapplyState(boolean cancelCurrentAnimation) {
        boolean wasInAnimation = mConfig.currentAnimation != null;
        if (cancelCurrentAnimation) {
        if (cancelCurrentAnimation && (mConfig.animProps & HANDLE_STATE_APPLY) == 0) {
            // Animation canceling can trigger a cleanup routine, causing problems when we are in a
            // launcher state that relies on member variable data. So if we are in one of those
            // states, accelerate the current animation to its end point rather than canceling it
@@ -237,7 +239,7 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {
                    listener.onAnimationEnd(null);
                }
                return;
            } else if ((!mConfig.userControlled && animated && mConfig.targetState == state)
            } else if ((!mConfig.isUserControlled() && animated && mConfig.targetState == state)
                    || mState.shouldPreserveDataStateOnReapply()) {
                // We are running the same animation as requested, and/or target state should not be
                // reset -- allow the current animation to complete instead of canceling it.
@@ -343,7 +345,7 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {

    public AnimatorPlaybackController createAnimationToNewWorkspace(STATE_TYPE state,
            StateAnimationConfig config) {
        config.userControlled = true;
        config.animProps |= StateAnimationConfig.USER_CONTROLLED;
        cancelAnimation();
        config.copyTo(mConfig);
        mConfig.playbackController = createAnimationToNewWorkspaceInternal(state)
@@ -418,7 +420,7 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {
    }

    public void moveToRestState(boolean isAnimated) {
        if (mConfig.currentAnimation != null && mConfig.userControlled) {
        if (mConfig.currentAnimation != null && mConfig.isUserControlled()) {
            // The user is doing something. Lets not mess it up
            return;
        }
@@ -450,10 +452,18 @@ public class StateManager<STATE_TYPE extends BaseState<STATE_TYPE>> {
        }
    }

    /**
     * Sets the provided controller as the current user controlled state animation
     */
    public void setCurrentUserControlledAnimation(AnimatorPlaybackController controller) {
        setCurrentAnimation(controller, StateAnimationConfig.USER_CONTROLLED);
    }

    public void setCurrentAnimation(AnimatorPlaybackController controller,
            @AnimationPropertyFlags int animationProps) {
        clearCurrentAnimation();
        setCurrentAnimation(controller.getTarget());
        mConfig.userControlled = true;
        mConfig.animProps = animationProps;
        mConfig.playbackController = controller;
    }

+1 −9
Original line number Diff line number Diff line
@@ -126,16 +126,8 @@ public abstract class StatefulActivity<STATE_TYPE extends BaseState<STATE_TYPE>>

    @Override
    public void reapplyUi() {
        reapplyUi(true /* cancelCurrentAnimation */);
    }

    /**
     * Re-applies if any state transition is not running, optionally cancelling
     * the transition if requested.
     */
    public void reapplyUi(boolean cancelCurrentAnimation) {
        getRootView().dispatchInsets();
        getStateManager().reapplyState(cancelCurrentAnimation);
        getStateManager().reapplyState(true /* cancelCurrentAnimation */);
    }

    @Override
+17 −2
Original line number Diff line number Diff line
@@ -40,8 +40,19 @@ public class StateAnimationConfig {
    public static final int SKIP_DEPTH_CONTROLLER = 1 << 2;
    public static final int SKIP_SCRIM = 1 << 3;

    @IntDef(flag = true, value = {
            USER_CONTROLLED,
            HANDLE_STATE_APPLY
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface AnimationPropertyFlags {}
    // Indicates that the animation is controlled by the user
    public static final int USER_CONTROLLED = 1 << 0;
    // Indicates that he animation can survive state UI resets due to inset or config changes
    public static final int HANDLE_STATE_APPLY = 1 << 1;

    public long duration;
    public boolean userControlled;
    public @AnimationPropertyFlags int animProps = 0;
    public @AnimationFlags int animFlags = 0;


@@ -105,12 +116,16 @@ public class StateAnimationConfig {
    public void copyTo(StateAnimationConfig target) {
        target.duration = duration;
        target.animFlags = animFlags;
        target.userControlled = userControlled;
        target.animProps = animProps;
        for (int i = 0; i < ANIM_TYPES_COUNT; i++) {
            target.mInterpolators[i] = mInterpolators[i];
        }
    }

    public boolean isUserControlled() {
        return (animProps & USER_CONTROLLED) != 0;
    }

    /**
     * Returns the interpolator set for animId or fallback if nothing is set
     *
Loading