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

Commit 02e9f1e1 authored by Tony Wickham's avatar Tony Wickham
Browse files

Slightly improve Taskbar animations to launcher

- Move Taskbar scale to LauncherState
- Rename TaskbarVisibilityController to TaskbarAnimationController and
  add mTaskbarScaleForLauncherState to TaskbarAnimationController
- Set OverviewState#getTaskbarScale() = 1f so Taskbar doesn't scale
  up when going from an app to Overview
- Increase home animation duration so Taskbar animation aligns better

Test: Taskbar scales up when going home, doesn't scale up when going
to overview
Bug: 182512211

Change-Id: I6f448e76de98d7ff337ae93234d4bb7ce6254d50
parent 11bc3118
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -335,6 +335,14 @@ public abstract class BaseQuickstepLauncher extends Launcher
                ? new float[] {1, 1} : new float[] {1.1f, 0};
    }

    @Override
    public float getNormalTaskbarScale() {
        if (mTaskbarController != null) {
            return mTaskbarController.getTaskbarScaleOnHome();
        }
        return super.getNormalTaskbarScale();
    }

    @Override
    public void onDragLayerHierarchyChanged() {
        onLauncherStateOrFocusChanged();
+25 −6
Original line number Diff line number Diff line
@@ -20,20 +20,21 @@ import static com.android.launcher3.LauncherState.TASKBAR;
import android.animation.Animator;

import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.Utilities;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.SystemUiProxy;
import com.android.systemui.shared.system.QuickStepContract;

/**
 * Works with TaskbarController to update the TaskbarView's alpha based on LauncherState, whether
 * Launcher is in the foreground, etc.
 * Works with TaskbarController to update the TaskbarView's visual properties based on factors such
 * as LauncherState, whether Launcher is in the foreground, etc.
 */
public class TaskbarVisibilityController {
public class TaskbarAnimationController {

    private static final long IME_VISIBILITY_ALPHA_DURATION = 120;

    private final BaseQuickstepLauncher mLauncher;
    private final TaskbarController.TaskbarVisibilityControllerCallbacks mTaskbarCallbacks;
    private final TaskbarController.TaskbarAnimationControllerCallbacks mTaskbarCallbacks;

    // Background alpha.
    private final AnimatedFloat mTaskbarBackgroundAlpha = new AnimatedFloat(
@@ -45,8 +46,12 @@ public class TaskbarVisibilityController {
    private final AnimatedFloat mTaskbarVisibilityAlphaForIme = new AnimatedFloat(
            this::updateVisibilityAlpha);

    public TaskbarVisibilityController(BaseQuickstepLauncher launcher,
            TaskbarController.TaskbarVisibilityControllerCallbacks taskbarCallbacks) {
    // Scale.
    private final AnimatedFloat mTaskbarScaleForLauncherState = new AnimatedFloat(
            this::updateScale);

    public TaskbarAnimationController(BaseQuickstepLauncher launcher,
            TaskbarController.TaskbarAnimationControllerCallbacks taskbarCallbacks) {
        mLauncher = launcher;
        mTaskbarCallbacks = taskbarCallbacks;
    }
@@ -72,6 +77,10 @@ public class TaskbarVisibilityController {
        return mTaskbarVisibilityAlphaForLauncherState;
    }

    protected AnimatedFloat getTaskbarScaleForLauncherState() {
        return mTaskbarScaleForLauncherState;
    }

    protected Animator createAnimToBackgroundAlpha(float toAlpha, long duration) {
        return mTaskbarBackgroundAlpha.animateToValue(mTaskbarBackgroundAlpha.value, toAlpha)
                .setDuration(duration);
@@ -85,6 +94,7 @@ public class TaskbarVisibilityController {
    private void onTaskbarBackgroundAlphaChanged() {
        mTaskbarCallbacks.updateTaskbarBackgroundAlpha(mTaskbarBackgroundAlpha.value);
        updateVisibilityAlpha();
        updateScale();
    }

    private void updateVisibilityAlpha() {
@@ -101,6 +111,15 @@ public class TaskbarVisibilityController {
        setNavBarButtonAlpha(1f - taskbarAlpha);
    }

    private void updateScale() {
        // We use mTaskbarBackgroundAlpha as a proxy for whether Launcher is resumed/paused, the
        // assumption being that Taskbar should always be at scale 1f regardless of the current
        // LauncherState if Launcher is paused.
        float scale = mTaskbarScaleForLauncherState.value;
        scale = Utilities.mapRange(mTaskbarBackgroundAlpha.value, scale, 1f);
        mTaskbarCallbacks.updateTaskbarScale(scale);
    }

    private void setNavBarButtonAlpha(float navBarAlpha) {
        SystemUiProxy.INSTANCE.get(mLauncher).setNavBarButtonAlpha(navBarAlpha, false);
    }
+26 −20
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;

@@ -75,7 +73,7 @@ public class TaskbarController {
    // Layout width and height of the Taskbar in the default state.
    private final Point mTaskbarSize;
    private final TaskbarStateHandler mTaskbarStateHandler;
    private final TaskbarVisibilityController mTaskbarVisibilityController;
    private final TaskbarAnimationController mTaskbarAnimationController;
    private final TaskbarHotseatController mHotseatController;
    private final TaskbarRecentsController mRecentsController;
    private final TaskbarDragController mDragController;
@@ -104,8 +102,8 @@ public class TaskbarController {
        mWindowManager = mLauncher.getWindowManager();
        mTaskbarSize = new Point(MATCH_PARENT, mLauncher.getDeviceProfile().taskbarSize);
        mTaskbarStateHandler = mLauncher.getTaskbarStateHandler();
        mTaskbarVisibilityController = new TaskbarVisibilityController(mLauncher,
                createTaskbarVisibilityControllerCallbacks());
        mTaskbarAnimationController = new TaskbarAnimationController(mLauncher,
                createTaskbarAnimationControllerCallbacks());
        mHotseatController = new TaskbarHotseatController(mLauncher,
                createTaskbarHotseatControllerCallbacks());
        mRecentsController = new TaskbarRecentsController(mLauncher,
@@ -113,8 +111,8 @@ public class TaskbarController {
        mDragController = new TaskbarDragController(mLauncher);
    }

    private TaskbarVisibilityControllerCallbacks createTaskbarVisibilityControllerCallbacks() {
        return new TaskbarVisibilityControllerCallbacks() {
    private TaskbarAnimationControllerCallbacks createTaskbarAnimationControllerCallbacks() {
        return new TaskbarAnimationControllerCallbacks() {
            @Override
            public void updateTaskbarBackgroundAlpha(float alpha) {
                mTaskbarViewInApp.setBackgroundAlpha(alpha);
@@ -125,6 +123,12 @@ public class TaskbarController {
                mTaskbarContainerView.setAlpha(alpha);
                mTaskbarViewOnHome.setAlpha(alpha);
            }

            @Override
            public void updateTaskbarScale(float scale) {
                mTaskbarViewInApp.setScaleX(scale);
                mTaskbarViewInApp.setScaleY(scale);
            }
        };
    }

@@ -242,12 +246,10 @@ public class TaskbarController {
        mTaskbarContainerView.init(mTaskbarViewInApp);
        addToWindowManager();
        mTaskbarStateHandler.setTaskbarCallbacks(createTaskbarStateHandlerCallbacks());
        mTaskbarVisibilityController.init();
        mTaskbarAnimationController.init();
        mHotseatController.init();
        mRecentsController.init();

        SCALE_PROPERTY.set(mTaskbarViewInApp, mLauncher.hasBeenResumed()
                ? getTaskbarScaleOnHome() : 1f);
        updateWhichTaskbarViewIsVisible();
    }

@@ -255,7 +257,12 @@ public class TaskbarController {
        return new TaskbarStateHandlerCallbacks() {
            @Override
            public AnimatedFloat getAlphaTarget() {
                return mTaskbarVisibilityController.getTaskbarVisibilityForLauncherState();
                return mTaskbarAnimationController.getTaskbarVisibilityForLauncherState();
            }

            @Override
            public AnimatedFloat getScaleTarget() {
                return mTaskbarAnimationController.getTaskbarScaleForLauncherState();
            }
        };
    }
@@ -274,7 +281,7 @@ public class TaskbarController {
        mTaskbarContainerView.cleanup();
        removeFromWindowManager();
        mTaskbarStateHandler.setTaskbarCallbacks(null);
        mTaskbarVisibilityController.cleanup();
        mTaskbarAnimationController.cleanup();
        mHotseatController.cleanup();
        mRecentsController.cleanup();
    }
@@ -342,12 +349,10 @@ public class TaskbarController {
     */
    public Animator createAnimToLauncher(@Nullable LauncherState toState, long duration) {
        PendingAnimation anim = new PendingAnimation(duration);
        anim.add(mTaskbarVisibilityController.createAnimToBackgroundAlpha(0, duration));
        anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(0, duration));
        if (toState != null) {
            mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
        }
        anim.addFloat(mTaskbarViewInApp, SCALE_PROPERTY, mTaskbarViewInApp.getScaleX(),
                getTaskbarScaleOnHome(), LINEAR);

        anim.addListener(new AnimatorListenerAdapter() {
            @Override
@@ -368,8 +373,7 @@ public class TaskbarController {

    private Animator createAnimToApp(long duration) {
        PendingAnimation anim = new PendingAnimation(duration);
        anim.add(mTaskbarVisibilityController.createAnimToBackgroundAlpha(1, duration));
        anim.addFloat(mTaskbarViewInApp, SCALE_PROPERTY, mTaskbarViewInApp.getScaleX(), 1f, LINEAR);
        anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(1, duration));
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
@@ -390,7 +394,7 @@ public class TaskbarController {
     * Should be called when the IME visibility changes, so we can hide/show Taskbar accordingly.
     */
    public void setIsImeVisible(boolean isImeVisible) {
        mTaskbarVisibilityController.animateToVisibilityForIme(isImeVisible ? 0 : 1);
        mTaskbarAnimationController.animateToVisibilityForIme(isImeVisible ? 0 : 1);
    }

    /**
@@ -527,15 +531,17 @@ public class TaskbarController {
     */
    protected interface TaskbarStateHandlerCallbacks {
        AnimatedFloat getAlphaTarget();
        AnimatedFloat getScaleTarget();
    }

    /**
     * Contains methods that TaskbarVisibilityController can call to interface with
     * Contains methods that TaskbarAnimationController can call to interface with
     * TaskbarController.
     */
    protected interface TaskbarVisibilityControllerCallbacks {
    protected interface TaskbarAnimationControllerCallbacks {
        void updateTaskbarBackgroundAlpha(float alpha);
        void updateTaskbarVisibilityAlpha(float alpha);
        void updateTaskbarScale(float scale);
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -53,8 +53,10 @@ public class TaskbarStateHandler implements StateManager.StateHandler<LauncherSt
        }

        AnimatedFloat alphaTarget = mTaskbarCallbacks.getAlphaTarget();
        AnimatedFloat scaleTarget = mTaskbarCallbacks.getScaleTarget();
        boolean isTaskbarVisible = (state.getVisibleElements(mLauncher) & TASKBAR) != 0;
        alphaTarget.updateValue(isTaskbarVisible ? 1f : 0f);
        scaleTarget.updateValue(state.getTaskbarScale(mLauncher));
    }

    @Override
@@ -65,7 +67,10 @@ public class TaskbarStateHandler implements StateManager.StateHandler<LauncherSt
        }

        AnimatedFloat alphaTarget = mTaskbarCallbacks.getAlphaTarget();
        AnimatedFloat scaleTarget = mTaskbarCallbacks.getScaleTarget();
        boolean isTaskbarVisible = (toState.getVisibleElements(mLauncher) & TASKBAR) != 0;
        animation.setFloat(alphaTarget, AnimatedFloat.VALUE, isTaskbarVisible ? 1f : 0f, LINEAR);
        animation.setFloat(scaleTarget, AnimatedFloat.VALUE, toState.getTaskbarScale(mLauncher),
                LINEAR);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -82,6 +82,11 @@ public class OverviewState extends LauncherState {
        return new float[] {NO_SCALE, NO_OFFSET};
    }

    @Override
    public float getTaskbarScale(Launcher launcher) {
        return 1f;
    }

    @Override
    public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
        return new PageAlphaProvider(DEACCEL_2) {
Loading