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

Commit 51d1d7c1 authored by Ben Lin's avatar Ben Lin
Browse files

PiP: Implement expand transition.

Video: http://recall/-/gu5DjQFZPMFpwgaXdl4cV3/hJhcmBJWGG3IHgn6Vw9Xoa
Bug: 165793917
Test: Exit PiP with ENABLE_SHELL_TRANSITIONS flag on
Change-Id: I669919d44df2b1954ce3cbce9328faf10c24171f
parent fba001d9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -423,6 +423,11 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        // Set the exiting state first so if there is fixed rotation later, the running animation
        // won't be interrupted by alpha animation for existing PiP.
        mState = State.EXITING_PIP;

        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            mPipTransitionController.startTransition(destinationBounds, wct);
            return;
        }
        mSyncTransactionQueue.queue(wct);
        mSyncTransactionQueue.runInSync(t -> {
            // Make sure to grab the latest source hint rect as it could have been
+33 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTI
import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_TO_PIP;
import static com.android.wm.shell.pip.PipAnimationController.isInPipDirection;
import static com.android.wm.shell.pip.PipAnimationController.isOutPipDirection;
import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;

import android.app.TaskInfo;
import android.content.Context;
@@ -53,6 +54,7 @@ public class PipTransition extends PipTransitionController {
    private final int mEnterExitAnimationDuration;
    private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
    private Transitions.TransitionFinishCallback mFinishCallback;
    private Rect mExitDestinationBounds = new Rect();

    public PipTransition(Context context,
            PipBoundsState pipBoundsState, PipMenuController pipMenuController,
@@ -66,12 +68,28 @@ public class PipTransition extends PipTransitionController {
                .getInteger(R.integer.config_pipResizeAnimationDuration);
    }

    @Override
    public void startTransition(Rect destinationBounds, WindowContainerTransaction out) {
        mExitDestinationBounds.set(destinationBounds);
        mTransitions.startTransition(TRANSIT_EXIT_PIP, out, this);
    }

    @Override
    public boolean startAnimation(@android.annotation.NonNull IBinder transition,
            @android.annotation.NonNull TransitionInfo info,
            @android.annotation.NonNull SurfaceControl.Transaction startTransaction,
            @android.annotation.NonNull SurfaceControl.Transaction finishTransaction,
            @android.annotation.NonNull Transitions.TransitionFinishCallback finishCallback) {

        if (info.getType() == TRANSIT_EXIT_PIP && info.getChanges().size() == 1) {
            final TransitionInfo.Change change = info.getChanges().get(0);
            mFinishCallback = finishCallback;
            boolean success = startExpandAnimation(change.getTaskInfo(), change.getLeash(),
                    new Rect(mExitDestinationBounds));
            mExitDestinationBounds.setEmpty();
            return success;
        }

        for (int i = info.getChanges().size() - 1; i >= 0; --i) {
            final TransitionInfo.Change change = info.getChanges().get(i);
            if (change.getTaskInfo() != null
@@ -109,6 +127,21 @@ public class PipTransition extends PipTransitionController {
        finishResizeForMenu(destinationBounds);
    }

    private boolean startExpandAnimation(final TaskInfo taskInfo, final SurfaceControl leash,
            final Rect destinationBounds) {
        PipAnimationController.PipTransitionAnimator animator =
                mPipAnimationController.getAnimator(taskInfo, leash, mPipBoundsState.getBounds(),
                        mPipBoundsState.getBounds(), destinationBounds, null,
                        TRANSITION_DIRECTION_LEAVE_PIP, 0 /* startingAngle */, Surface.ROTATION_0);

        animator.setTransitionDirection(TRANSITION_DIRECTION_LEAVE_PIP)
                .setPipAnimationCallback(mPipAnimationCallback)
                .setDuration(mEnterExitAnimationDuration)
                .start();

        return true;
    }

    private boolean startEnterAnimation(final TaskInfo taskInfo, final SurfaceControl leash,
            final SurfaceControl.Transaction startTransaction,
            final SurfaceControl.Transaction finishTransaction) {
+10 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.view.SurfaceControl;
import android.window.WindowContainerTransaction;

import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.transition.Transitions;
@@ -46,6 +47,7 @@ public abstract class PipTransitionController implements Transitions.TransitionH
    protected final PipBoundsState mPipBoundsState;
    protected final ShellTaskOrganizer mShellTaskOrganizer;
    protected final PipMenuController mPipMenuController;
    protected final Transitions mTransitions;
    private final Handler mMainHandler;
    private final List<PipTransitionCallback> mPipTransitionCallbacks = new ArrayList<>();

@@ -98,6 +100,13 @@ public abstract class PipTransitionController implements Transitions.TransitionH
            SurfaceControl.Transaction tx) {
    }

    /**
     * Called when the Shell wants to starts a transition/animation.
     */
    public void startTransition(Rect destinationBounds, WindowContainerTransaction out) {
        // Default implementation does nothing.
    }

    public PipTransitionController(PipBoundsState pipBoundsState,
            PipMenuController pipMenuController, PipBoundsAlgorithm pipBoundsAlgorithm,
            PipAnimationController pipAnimationController, Transitions transitions,
@@ -107,6 +116,7 @@ public abstract class PipTransitionController implements Transitions.TransitionH
        mShellTaskOrganizer = shellTaskOrganizer;
        mPipBoundsAlgorithm = pipBoundsAlgorithm;
        mPipAnimationController = pipAnimationController;
        mTransitions = transitions;
        mMainHandler = new Handler(Looper.getMainLooper());
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            transitions.addHandler(this);
+3 −0
Original line number Diff line number Diff line
@@ -77,6 +77,9 @@ public class Transitions implements RemoteCallable<Transitions> {
    /** Transition type for launching 2 tasks simultaneously. */
    public static final int TRANSIT_SPLIT_SCREEN_PAIR_OPEN = TRANSIT_FIRST_CUSTOM + 2;

    /** Transition type for exiting PIP via the Shell, either via Expand or Dismiss. */
    public static final int TRANSIT_EXIT_PIP = TRANSIT_FIRST_CUSTOM + 3;

    private final WindowOrganizer mOrganizer;
    private final Context mContext;
    private final ShellExecutor mMainExecutor;