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

Commit 24675d36 authored by Tony Wickham's avatar Tony Wickham
Browse files

Improve quick switch from home to taskbar

- Add LauncherState#isTaskbarAlignedWithHotseat() which defaults to !isTaskbarStashed(), but is always false for quick switch from home
- Replaced FLAG_TRANSITION_STATE_START_STASHED and FLAG_TRANSITION_STATE_COMMITTED_STASHED with FLAG_STATE_TRANSITION_RUNNING and a reference to mLauncherState. STATE_START is equivalent to TRANSITION_RUNNING changing to true, and STATE_COMMITTED is equivalent to TRANSITION_RUNNING changing to false. Then can get details from the state such as whether taskbar is stashed and icon alignment from mLauncherState

Test: quick switch from home, both with taskbar stashed in apps and not
Fixes: 194728611
Bug: 204657916
Change-Id: I6cf84ec73a4036e14cc7268667c6f62100884c27
parent 9566290e
Loading
Loading
Loading
Loading
+31 −31
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@ import java.util.function.Supplier;

    public static final int FLAG_RESUMED = 1 << 0;
    public static final int FLAG_RECENTS_ANIMATION_RUNNING = 1 << 1;
    public static final int FLAG_TRANSITION_STATE_START_STASHED = 1 << 2;
    public static final int FLAG_TRANSITION_STATE_COMMITTED_STASHED = 1 << 3;
    public static final int FLAG_TRANSITION_STATE_RUNNING = 1 << 2;

    /** Equivalent to an int with all 1s for binary operation purposes */
    private static final int FLAGS_ALL = ~0;
@@ -69,6 +68,7 @@ import java.util.function.Supplier;

    private Integer mPrevState;
    private int mState;
    private LauncherState mLauncherState = LauncherState.NORMAL;

    private boolean mIsAnimatingToLauncherViaGesture;
    private boolean mIsAnimatingToLauncherViaResume;
@@ -78,15 +78,20 @@ import java.util.function.Supplier;

                @Override
                public void onStateTransitionStart(LauncherState toState) {
                    updateStateForFlag(FLAG_TRANSITION_STATE_START_STASHED,
                            toState.isTaskbarStashed());
                    if (toState != mLauncherState) {
                        // Treat FLAG_TRANSITION_STATE_RUNNING as a changed flag even if a previous
                        // state transition was already running, so we update the new target.
                        mPrevState &= ~FLAG_TRANSITION_STATE_RUNNING;
                        mLauncherState = toState;
                    }
                    updateStateForFlag(FLAG_TRANSITION_STATE_RUNNING, true);
                    applyState();
                }

                @Override
                public void onStateTransitionComplete(LauncherState finalState) {
                    updateStateForFlag(FLAG_TRANSITION_STATE_COMMITTED_STASHED,
                            finalState.isTaskbarStashed());
                    mLauncherState = finalState;
                    updateStateForFlag(FLAG_TRANSITION_STATE_RUNNING, false);
                    applyState();
                }
            };
@@ -127,7 +132,7 @@ import java.util.function.Supplier;
        // Update stashed flags first to ensure goingToUnstashedLauncherState() returns correctly.
        TaskbarStashController stashController = mControllers.taskbarStashController;
        stashController.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE,
                toState.isTaskbarStashed());
                toState.isTaskbarStashed(mLauncher));
        stashController.updateStateForFlag(FLAG_IN_APP, false);

        updateStateForFlag(FLAG_RECENTS_ANIMATION_RUNNING, true);
@@ -189,8 +194,8 @@ import java.util.function.Supplier;
        if (mPrevState == null || mPrevState != mState) {
            // If this is our initial state, treat all flags as changed.
            int changedFlags = mPrevState == null ? FLAGS_ALL : mPrevState ^ mState;
            animator = onStateChangeApplied(changedFlags, duration, start);
            mPrevState = mState;
            animator = onStateChangeApplied(changedFlags, duration, start);
        }
        return animator;
    }
@@ -250,14 +255,15 @@ import java.util.function.Supplier;
                    .setDuration(duration));
        }

        if (hasAnyFlag(changedFlags, FLAG_TRANSITION_STATE_START_STASHED)) {
            playStateTransitionAnim(isTransitionStateStartStashed(), animatorSet, duration,
                    false /* committed */);
        }
        if (hasAnyFlag(changedFlags, FLAG_TRANSITION_STATE_RUNNING)) {
            boolean committed = !hasAnyFlag(FLAG_TRANSITION_STATE_RUNNING);
            playStateTransitionAnim(animatorSet, duration, committed);

        if (hasAnyFlag(changedFlags, FLAG_TRANSITION_STATE_COMMITTED_STASHED)) {
            playStateTransitionAnim(isTransitionStateCommittedStashed(), animatorSet, duration,
                    true /* committed */);
            if (committed && mLauncherState == LauncherState.QUICK_SWITCH) {
                // We're about to be paused, set immediately to ensure seamless handoff.
                updateStateForFlag(FLAG_RESUMED, false);
                applyState(0 /* duration */);
            }
        }

        if (start) {
@@ -271,17 +277,19 @@ import java.util.function.Supplier;
        return !mControllers.taskbarStashController.isInStashedLauncherState();
    }

    private void playStateTransitionAnim(boolean isTransitionStateStashed,
            AnimatorSet animatorSet, long duration, boolean committed) {
    private void playStateTransitionAnim(AnimatorSet animatorSet, long duration,
            boolean committed) {
        boolean isInStashedState = mLauncherState.isTaskbarStashed(mLauncher);
        float toAlignment = mLauncherState.isTaskbarAlignedWithHotseat(mLauncher) ? 1 : 0;

        TaskbarStashController controller = mControllers.taskbarStashController;
        controller.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE,
                isTransitionStateStashed);
        controller.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE, isInStashedState);
        Animator stashAnimator = controller.applyStateWithoutStart(duration);
        if (stashAnimator != null) {
            stashAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (isTransitionStateStashed && committed) {
                    if (isInStashedState && committed) {
                        // Reset hotseat alpha to default
                        mLauncher.getHotseat().setIconsAlpha(1);
                    }
@@ -295,10 +303,10 @@ import java.util.function.Supplier;
                }
            });
            animatorSet.play(stashAnimator);
            animatorSet.play(mIconAlignmentForLauncherState.animateToValue(
                    getCurrentIconAlignmentRatioForLauncherState(),
                    isTransitionStateStashed ? 0 : 1));
        }

        animatorSet.play(mIconAlignmentForLauncherState.animateToValue(toAlignment)
                .setDuration(duration));
    }

    private boolean isResumed() {
@@ -309,14 +317,6 @@ import java.util.function.Supplier;
        return (mState & FLAG_RECENTS_ANIMATION_RUNNING) != 0;
    }

    private boolean isTransitionStateStartStashed() {
        return (mState & FLAG_TRANSITION_STATE_START_STASHED) != 0;
    }

    private boolean isTransitionStateCommittedStashed() {
        return (mState & FLAG_TRANSITION_STATE_COMMITTED_STASHED) != 0;
    }

    private void onIconAlignmentRatioChangedForStateTransition() {
        if (!isResumed()) {
            return;
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class AllAppsState extends LauncherState {
    }

    @Override
    public boolean isTaskbarStashed() {
    public boolean isTaskbarStashed(Launcher launcher) {
        return true;
    }

+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class OverviewState extends LauncherState {
    }

    @Override
    public boolean isTaskbarStashed() {
    public boolean isTaskbarStashed(Launcher launcher) {
        return true;
    }

+15 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.uioverrides.states;

import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.util.Themes;
@@ -42,6 +43,10 @@ public class QuickSwitchState extends BackgroundAppState {

    @Override
    public int getWorkspaceScrimColor(Launcher launcher) {
        DeviceProfile dp = launcher.getDeviceProfile();
        if (dp.isTaskbarPresentInApps) {
            return launcher.getColor(R.color.taskbar_background);
        }
        return Themes.getAttrColor(launcher, R.attr.overviewScrimColor);
    }

@@ -55,4 +60,14 @@ public class QuickSwitchState extends BackgroundAppState {
    public int getVisibleElements(Launcher launcher) {
        return TASKBAR;
    }

    @Override
    public boolean isTaskbarStashed(Launcher launcher) {
        return !launcher.getDeviceProfile().isTaskbarPresentInApps;
    }

    @Override
    public boolean isTaskbarAlignedWithHotseat(Launcher launcher) {
        return false;
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -236,8 +236,10 @@ public class NoButtonQuickSwitchTouchController implements TouchController,
        //   - RecentsView fade (if it's empty)
        PendingAnimation xAnim = new PendingAnimation((long) (mXRange * 2));
        xAnim.setFloat(mRecentsView, ADJACENT_PAGE_HORIZONTAL_OFFSET, scaleAndOffset[1], LINEAR);
        // Use QuickSwitchState instead of OverviewState to determine scrim color,
        // since we need to take potential taskbar into account.
        xAnim.setViewBackgroundColor(mLauncher.getScrimView(),
                toState.getWorkspaceScrimColor(mLauncher), LINEAR);
                QUICK_SWITCH.getWorkspaceScrimColor(mLauncher), LINEAR);
        if (mRecentsView.getTaskViewCount() == 0) {
            xAnim.addFloat(mRecentsView, CONTENT_ALPHA, 0f, 1f, LINEAR);
        }
@@ -310,6 +312,11 @@ public class NoButtonQuickSwitchTouchController implements TouchController,
                }
            });
            overviewAnim.start();

            // Create an empty state transition so StateListeners get onStateTransitionStart().
            mLauncher.getStateManager().createAnimationToNewWorkspace(
                    OVERVIEW, config.duration, StateAnimationConfig.SKIP_ALL_ANIMATIONS)
                    .dispatchOnStart();
            return;
        }

@@ -384,6 +391,7 @@ public class NoButtonQuickSwitchTouchController implements TouchController,
            config.animFlags = SKIP_ALL_ANIMATIONS;
            updateNonOverviewAnim(targetState, config);
            nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
            mNonOverviewAnim.dispatchOnStart();

            new WorkspaceRevealAnim(mLauncher, false /* animateOverviewScrim */).start();
        } else {
Loading