From bf1818439f5c0e509a1e5b4ac87c0b4d091a2a5a Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 11 Apr 2023 18:44:54 +0800 Subject: [PATCH] Re-show faded PiP when fixed rotation is finished PiP will be faded out if there is orientation change when switching app (onFixedRotationStarted), and then fade in with display transition from startAnimation -> fadeExistingPip. But if there is no app switch, such as entering recent and then return to current app, the signal to re-show the PiP was missed in shell transition. So still listen to onFixedRotationFinished and restore the visibility of PiP when the transition is idle. Bug: 262835608 Test: Enter PiP in portrait. Launch a rotatable app. Rotate screen to landscape. Either: - Swipe up and down to cancel. - Swipe up to enter recent. Click the current app to return. Though the PiP will be fade out during swipe-up gesture. After return to current app, the PiP should be still visible. Change-Id: Ieb47eceaa5e8e7ff710a0fd6ab8319d1a3463985 --- .../wm/shell/pip/PipTaskOrganizer.java | 1 + .../android/wm/shell/pip/PipTransition.java | 24 ++++++++++++++++++- .../wm/shell/pip/PipTransitionController.java | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index 5670fe6eaebaf..43ab76713c38b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -1002,6 +1002,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, return; } if (Transitions.ENABLE_SHELL_TRANSITIONS) { + mPipTransitionController.onFixedRotationFinished(); clearWaitForFixedRotation(); return; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index 91bb1abbd8c67..46969d6dba529 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -412,9 +412,31 @@ public class PipTransition extends PipTransitionController { @Override public void onFixedRotationStarted() { + fadeEnteredPipIfNeed(false /* show */); + } + + @Override + public void onFixedRotationFinished() { + fadeEnteredPipIfNeed(true /* show */); + } + + private void fadeEnteredPipIfNeed(boolean show) { // The transition with this fixed rotation may be handled by other handler before reaching // PipTransition, so we cannot do this in #startAnimation. - if (mPipTransitionState.getTransitionState() == ENTERED_PIP && !mHasFadeOut) { + if (!mPipTransitionState.hasEnteredPip()) { + return; + } + if (show && mHasFadeOut) { + // If there is a pending transition, then let startAnimation handle it. And if it is + // handled, mHasFadeOut will be set to false and this runnable will be no-op. Otherwise + // make sure the PiP will reshow, e.g. swipe-up with fixed rotation (fade-out) but + // return to the current app (only finish the recent transition). + mTransitions.runOnIdle(() -> { + if (mHasFadeOut && mPipTransitionState.hasEnteredPip()) { + fadeExistingPip(true /* show */); + } + }); + } else if (!show && !mHasFadeOut) { // Fade out the existing PiP to avoid jump cut during seamless rotation. fadeExistingPip(false /* show */); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java index 7979ce7a80c18..97f14686010fb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransitionController.java @@ -123,6 +123,10 @@ public abstract class PipTransitionController implements Transitions.TransitionH public void onFixedRotationStarted() { } + /** Called when the fixed rotation finished. */ + public void onFixedRotationFinished() { + } + public PipTransitionController( @NonNull ShellInit shellInit, @NonNull ShellTaskOrganizer shellTaskOrganizer,