From 442ba6ca2c88fa49a0a13eea400ef256f565869c Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Thu, 28 Apr 2022 16:39:55 +0200 Subject: [PATCH] TV:Fade out PiP content during aspect ratio change This avoids stretching the content - the content will only be shown again once it has been redrawn by the app for the new ratio. Content should stay visible during the enter and move animation, i.e. whenever the ratio stays the same. Bug: 230741005 Test: manual - enter PiP, change aspect ratio, expand, move Change-Id: Ie95f4a480a622c7403f342e0ac25660fd2af197f --- .../Shell/res/layout/tv_pip_menu.xml | 3 ++ .../wm/shell/pip/tv/TvPipMenuView.java | 37 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml index 90c923ae5c832..7a3ee23d8cdce 100644 --- a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml +++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml @@ -21,10 +21,13 @@ android:layout_height="match_parent" android:gravity="center|top"> + diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java index f3b3145c9103a..868e45655ba3c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java @@ -217,6 +217,21 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { } void onPipTransitionStarted(Rect finishBounds) { + // Fade out content by fading in view on top. + if (mCurrentPipBounds != null && finishBounds != null) { + boolean ratioChanged = PipUtils.aspectRatioChanged( + mCurrentPipBounds.width() / (float) mCurrentPipBounds.height(), + finishBounds.width() / (float) finishBounds.height()); + if (ratioChanged) { + mPipView.animate() + .alpha(1f) + .setInterpolator(TvPipInterpolators.EXIT) + .setDuration(mResizeAnimationDuration / 2) + .start(); + } + } + + // Update buttons. final boolean vertical = finishBounds.height() > finishBounds.width(); final boolean orientationChanged = vertical != (mActionButtonsContainer.getOrientation() == LinearLayout.VERTICAL); @@ -235,10 +250,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { .withEndAction(() -> { changeButtonScrollOrientation(finishBounds); updateButtonGravity(finishBounds); - mActionButtonsContainer.animate() - .alpha(1) - .setInterpolator(TvPipInterpolators.ENTER) - .setDuration(mResizeAnimationDuration / 2); + // Only make buttons visible again in onPipTransitionFinished to keep in + // sync with PiP content alpha animation. }); } else { changeButtonScrollOrientation(finishBounds); @@ -249,7 +262,21 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { void onPipTransitionFinished() { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: onPipTransitionFinished()", TAG); - if (!mSwitchingOrientation) { + + // Fade in content by fading out view on top. + mPipView.animate() + .alpha(0f) + .setDuration(mResizeAnimationDuration / 2) + .setInterpolator(TvPipInterpolators.ENTER) + .start(); + + // Update buttons. + if (mSwitchingOrientation) { + mActionButtonsContainer.animate() + .alpha(1) + .setInterpolator(TvPipInterpolators.ENTER) + .setDuration(mResizeAnimationDuration / 2); + } else { refocusPreviousButton(); } mSwitchingOrientation = false;