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
This commit is contained in:
Jacqueline Bronger
2022-04-28 16:39:55 +02:00
parent 2a3d045604
commit 442ba6ca2c
2 changed files with 35 additions and 5 deletions

View File

@@ -21,10 +21,13 @@
android:layout_height="match_parent"
android:gravity="center|top">
<!-- Matches the PiP app content -->
<View
android:id="@+id/tv_pip"
android:layout_width="0dp"
android:layout_height="0dp"
android:alpha="0"
android:background="@color/tv_pip_menu_background"
android:layout_marginTop="@dimen/pip_menu_outer_space"
android:layout_marginStart="@dimen/pip_menu_outer_space"
android:layout_marginEnd="@dimen/pip_menu_outer_space"/>

View File

@@ -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;