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

Commit 68becd05 authored by Ats Jenk's avatar Ats Jenk
Browse files

Adjust size change animation timings

Per motion POR, window size change animation should be 400ms and use an
emphasized interpolator.
Together with the emphasized interpolator, the scale duration of 0.7x
does not work well. Adjust the scale factor to 1x in these cases.
Update the existing animation for converting a task to bubble and
converting bubble to fullscreen.

Bug: 403659671
Test: manual, use menu and drag to convert a task to bubble and back
Flag: com.android.wm.shell.enable_bubble_to_fullscreen

Change-Id: I2b24c355a04fd3a886768dbddbb22696c473e329
parent 310deb44
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class SizeChangeAnimation {
     * The maximum of stretching applied to any surface during interpolation (since the animation
     * is a combination of stretching/cropping/fading).
     */
    private static final float SCALE_FACTOR = 0.7f;
    private static final float DEFAULT_SCALE_FACTOR = 0.7f;

    /**
     * Since this animation is made of several sub-animations, we want to pre-arrange the
@@ -82,13 +82,27 @@ public class SizeChangeAnimation {
     */
    private static final int ANIMATION_RESOLUTION = 1000;

    /**
     * Initialize a size-change animation from start to end bounds
     */
    public SizeChangeAnimation(Rect startBounds, Rect endBounds) {
        this(startBounds, endBounds, 1f);
        this(startBounds, endBounds, 1f, DEFAULT_SCALE_FACTOR);
    }

    public SizeChangeAnimation(Rect startBounds, Rect endBounds, float initialScale) {
        mAnimation = buildContainerAnimation(startBounds, endBounds, initialScale);
        mSnapshotAnim = buildSnapshotAnimation(startBounds, endBounds);
    /**
     * Initialize a size-change animation from start to end bounds.
     * <p>
     * Allows specifying the initial scale factor, {@code initialScale}, that is applied to the
     * start bounds. This can be useful for example when a task is scaled down when the size change
     * animation starts.
     * <p>
     * By default the max scale applied to any surface is {@link #DEFAULT_SCALE_FACTOR}. Use
     * {@code scaleFactor} to override it.
     */
    public SizeChangeAnimation(Rect startBounds, Rect endBounds, float initialScale,
            float scaleFactor) {
        mAnimation = buildContainerAnimation(startBounds, endBounds, initialScale, scaleFactor);
        mSnapshotAnim = buildSnapshotAnimation(startBounds, endBounds, scaleFactor);
    }

    /**
@@ -172,15 +186,15 @@ public class SizeChangeAnimation {

    /** Animation for the whole container (snapshot is inside this container). */
    private static AnimationSet buildContainerAnimation(Rect startBounds, Rect endBounds,
            float initialScale) {
            float initialScale, float scaleFactor) {
        final long duration = ANIMATION_RESOLUTION;
        boolean growing = endBounds.width() - startBounds.width()
                + endBounds.height() - startBounds.height() >= 0;
        long scalePeriod = (long) (duration * SCALE_FACTOR);
        float startScaleX = SCALE_FACTOR * ((float) startBounds.width()) / endBounds.width()
                + (1.f - SCALE_FACTOR);
        float startScaleY = SCALE_FACTOR * ((float) startBounds.height()) / endBounds.height()
                + (1.f - SCALE_FACTOR);
        long scalePeriod = (long) (duration * scaleFactor);
        float startScaleX = scaleFactor * ((float) startBounds.width()) / endBounds.width()
                + (1.f - scaleFactor);
        float startScaleY = scaleFactor * ((float) startBounds.height()) / endBounds.height()
                + (1.f - scaleFactor);
        final AnimationSet animSet = new AnimationSet(true);

        final Animation scaleAnim = new ScaleAnimation(startScaleX, 1, startScaleY, 1);
@@ -218,15 +232,16 @@ public class SizeChangeAnimation {
    }

    /** The snapshot surface is assumed to be a child of the container surface. */
    private static AnimationSet buildSnapshotAnimation(Rect startBounds, Rect endBounds) {
    private static AnimationSet buildSnapshotAnimation(Rect startBounds, Rect endBounds,
            float scaleFactor) {
        final long duration = ANIMATION_RESOLUTION;
        boolean growing = endBounds.width() - startBounds.width()
                + endBounds.height() - startBounds.height() >= 0;
        long scalePeriod = (long) (duration * SCALE_FACTOR);
        float endScaleX = 1.f / (SCALE_FACTOR * ((float) startBounds.width()) / endBounds.width()
                + (1.f - SCALE_FACTOR));
        float endScaleY = 1.f / (SCALE_FACTOR * ((float) startBounds.height()) / endBounds.height()
                + (1.f - SCALE_FACTOR));
        long scalePeriod = (long) (duration * scaleFactor);
        float endScaleX = 1.f / (scaleFactor * ((float) startBounds.width()) / endBounds.width()
                + (1.f - scaleFactor));
        float endScaleY = 1.f / (scaleFactor * ((float) startBounds.height()) / endBounds.height()
                + (1.f - scaleFactor));

        AnimationSet snapAnimSet = new AnimationSet(true);
        // Animation for the "old-state" snapshot that is atop the task.
+5 −5
Original line number Diff line number Diff line
@@ -596,11 +596,11 @@ public class BubbleBarAnimationHelper {
        final Size size = getExpandedViewSize();
        Point position = getExpandedViewRestPosition(size);

        final SizeChangeAnimation sca =
                new SizeChangeAnimation(
                        new Rect(origBounds.left - position.x, origBounds.top - position.y,
                                origBounds.right - position.x, origBounds.bottom - position.y),
                        new Rect(0, 0, size.getWidth(), size.getHeight()), origScale);
        Rect startBounds = new Rect(origBounds.left - position.x, origBounds.top - position.y,
                origBounds.right - position.x, origBounds.bottom - position.y);
        Rect endBounds = new Rect(0, 0, size.getWidth(), size.getHeight());
        final SizeChangeAnimation sca = new SizeChangeAnimation(startBounds, endBounds,
                origScale, /* scaleFactor= */ 1f);
        sca.initialize(bbev, taskLeash, snapshot, startT);

        Animator a = sca.buildViewAnimator(bbev, tvSf, snapshot, /* onFinish */ (va) -> {
+6 −4
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPI
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;

import static com.android.internal.jank.Cuj.CUJ_DEFAULT_TASK_TO_TASK_ANIMATION;
import static com.android.internal.policy.TransitionAnimation.DEFAULT_APP_TRANSITION_DURATION;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_CHANGE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_CLOSE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_INTRA_CLOSE;
@@ -116,6 +115,7 @@ import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.TransactionPool;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.shared.animation.Interpolators;
import com.android.wm.shell.sysui.ShellInit;

import java.util.ArrayList;
@@ -125,6 +125,7 @@ import java.util.function.Consumer;
/** The default handler that handles anything not already handled. */
public class DefaultTransitionHandler implements Transitions.TransitionHandler {
    private static final int MAX_ANIMATION_DURATION = 3000;
    private static final int SIZE_CHANGE_ANIMATION_DURATION = 400;

    private final TransactionPool mTransactionPool;
    private final DisplayController mDisplayController;
@@ -779,15 +780,16 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
    private void startBoundsChangeAnimation(@NonNull SurfaceControl.Transaction startT,
            @NonNull ArrayList<Animator> animations, @NonNull TransitionInfo.Change change,
            @NonNull Runnable finishCb, @NonNull ShellExecutor mainExecutor) {
        final SizeChangeAnimation sca =
                new SizeChangeAnimation(change.getStartAbsBounds(), change.getEndAbsBounds());
        final SizeChangeAnimation sca = new SizeChangeAnimation(change.getStartAbsBounds(),
                change.getEndAbsBounds(), /* initialScale= */ 1f, /* scaleFactor= */ 1f);
        sca.initialize(change.getLeash(), change.getSnapshot(), startT);
        final ValueAnimator va = sca.buildAnimator(change.getLeash(), change.getSnapshot(),
                (animator) -> mainExecutor.execute(() -> {
                    animations.remove(animator);
                    finishCb.run();
                }));
        va.setDuration(DEFAULT_APP_TRANSITION_DURATION);
        va.setDuration(SIZE_CHANGE_ANIMATION_DURATION);
        va.setInterpolator(Interpolators.EMPHASIZED);
        animations.add(va);
    }