From aff4a412a08f841a750615b272f2a31013fb98a5 Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Thu, 30 Mar 2023 21:49:38 +0000 Subject: [PATCH] Fix tv edu text drawer not closing completely The edu text drawer closes by doing a slide animation - it looks like it slides behind the pip content (even thought it is actually drawn on top of the pip surface). We do the slide animation by having a ValueAnimator animate from the current height of the drawer to 0. On each animation update, we update the LayoutParams.height of the TvPipEduTextDrawer until eventually the height converges to 0 and at that point the edu text drawer is gone. The pip menu surface size is updated on each frame of the animation. To determine the necesary size for the pip menu surface, the TvPipMenuController asks the TvPipMenuView to calculate that, taking into account the current height of the edu text drawer. It does so by using the View.getHeight() method. However, even though we set LayoutParams.height to 0, the height of the edu text drawer remains 1, which causes the pip menu surface to stay 1px bigger in height than desired. In this CL, we mitigate that by making the edu text GONE at the end of the animation and returning 0 for the edu drawer height. This also ensures a safe recovery in error states by making the final size of the pip menu surface correct. Bug: 275693800 Test: m SystemUI && verify white pip focus border touches the pip content without any grey line below the pip content Change-Id: I4f3aec560ca7e2170e163852ce741fec349dfae4 --- .../shell/pip/tv/TvPipMenuEduTextDrawer.java | 39 +++++++++++++++---- .../wm/shell/pip/tv/TvPipMenuView.java | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuEduTextDrawer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuEduTextDrawer.java index 6eef22562caa6..dca246b566ffe 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuEduTextDrawer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuEduTextDrawer.java @@ -23,6 +23,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE; +import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.drawable.Drawable; @@ -115,6 +116,10 @@ class TvPipMenuEduTextDrawer extends FrameLayout { scheduleLifecycleEvents(); } + int getEduTextDrawerHeight() { + return getVisibility() == GONE ? 0 : getHeight(); + } + private void scheduleLifecycleEvents() { final int startScrollDelay = mContext.getResources().getInteger( R.integer.pip_edu_text_start_scroll_delay); @@ -226,22 +231,42 @@ class TvPipMenuEduTextDrawer extends FrameLayout { .start(); // Start animation to close the drawer by animating its height to 0 - final ValueAnimator heightAnimation = ValueAnimator.ofInt(getHeight(), 0); - heightAnimation.setDuration(eduTextSlideExitAnimationDuration); - heightAnimation.setInterpolator(TvPipInterpolators.BROWSE); - heightAnimation.addUpdateListener(animator -> { + final ValueAnimator heightAnimator = ValueAnimator.ofInt(getHeight(), 0); + heightAnimator.setDuration(eduTextSlideExitAnimationDuration); + heightAnimator.setInterpolator(TvPipInterpolators.BROWSE); + heightAnimator.addUpdateListener(animator -> { final ViewGroup.LayoutParams params = getLayoutParams(); params.height = (int) animator.getAnimatedValue(); setLayoutParams(params); - if (params.height == 0) { - setVisibility(GONE); + }); + heightAnimator.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(@NonNull Animator animator) { + } + + @Override + public void onAnimationEnd(@NonNull Animator animator) { + onCloseEduTextAnimationEnd(); + } + + @Override + public void onAnimationCancel(@NonNull Animator animator) { + onCloseEduTextAnimationEnd(); + } + + @Override + public void onAnimationRepeat(@NonNull Animator animator) { } }); - heightAnimation.start(); + heightAnimator.start(); mListener.onCloseEduText(); } + public void onCloseEduTextAnimationEnd() { + setVisibility(GONE); + } + /** * Creates the educational text that will be displayed to the user. Here we replace the * HOME annotation in the String with an icon 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 6eb719ba60a36..235d07b56b7ff 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 @@ -262,7 +262,7 @@ public class TvPipMenuView extends FrameLayout implements TvPipActionsProvider.L Rect getPipMenuContainerBounds(Rect pipBounds) { final Rect menuUiBounds = new Rect(pipBounds); menuUiBounds.inset(-mPipMenuOuterSpace, -mPipMenuOuterSpace); - menuUiBounds.bottom += mEduTextDrawer.getHeight(); + menuUiBounds.bottom += mEduTextDrawer.getEduTextDrawerHeight(); return menuUiBounds; }