From 1eeea7c0c533090c7c72c39c89949ed37205a964 Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Tue, 28 Sep 2021 10:02:51 +0000 Subject: [PATCH] Tv pip menu design update (1) PiP window stays where it is instead of moving to the center and the menu buttons are shown on centered on the pip instead of below the window. Additionally disabled menu items are removed to avoid cluttering. Bug: 201270615 Test: manual Change-Id: I9af5dc04dd0999d61add88a3475c697b376034d0 --- core/res/res/values-television/config.xml | 4 +- .../Shell/res/color/tv_pip_menu_icon.xml | 23 +++++ .../Shell/res/color/tv_pip_menu_icon_bg.xml | 21 ++++ ...utton_focused.xml => tv_pip_button_bg.xml} | 7 +- .../Shell/res/drawable/tv_pip_menu_border.xml | 22 +++++ .../Shell/res/layout/tv_pip_menu.xml | 69 +++++++++----- .../res/layout/tv_pip_menu_action_button.xml | 48 ++++------ .../tv_pip_menu_additional_action_button.xml | 21 ---- .../Shell/res/values-tvdpi/dimen.xml | 9 +- .../Shell/res/values/colors_tv.xml | 24 +++++ .../wm/shell/pip/tv/TvPipController.java | 8 -- .../shell/pip/tv/TvPipMenuActionButton.java | 95 ++----------------- .../wm/shell/pip/tv/TvPipMenuController.java | 27 ++++-- .../wm/shell/pip/tv/TvPipMenuView.java | 28 ++---- 14 files changed, 201 insertions(+), 205 deletions(-) create mode 100644 libs/WindowManager/Shell/res/color/tv_pip_menu_icon.xml create mode 100644 libs/WindowManager/Shell/res/color/tv_pip_menu_icon_bg.xml rename libs/WindowManager/Shell/res/drawable/{tv_pip_button_focused.xml => tv_pip_button_bg.xml} (74%) create mode 100644 libs/WindowManager/Shell/res/drawable/tv_pip_menu_border.xml delete mode 100644 libs/WindowManager/Shell/res/layout/tv_pip_menu_additional_action_button.xml create mode 100644 libs/WindowManager/Shell/res/values/colors_tv.xml diff --git a/core/res/res/values-television/config.xml b/core/res/res/values-television/config.xml index 606d0f25d490b..92bea34d55242 100644 --- a/core/res/res/values-television/config.xml +++ b/core/res/res/values-television/config.xml @@ -27,11 +27,11 @@ - 0.14 + 0.2 - 56x27 + 24x24 diff --git a/libs/WindowManager/Shell/res/color/tv_pip_menu_icon.xml b/libs/WindowManager/Shell/res/color/tv_pip_menu_icon.xml new file mode 100644 index 0000000000000..2758704504938 --- /dev/null +++ b/libs/WindowManager/Shell/res/color/tv_pip_menu_icon.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/libs/WindowManager/Shell/res/color/tv_pip_menu_icon_bg.xml b/libs/WindowManager/Shell/res/color/tv_pip_menu_icon_bg.xml new file mode 100644 index 0000000000000..4f5e63dac5c08 --- /dev/null +++ b/libs/WindowManager/Shell/res/color/tv_pip_menu_icon_bg.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml b/libs/WindowManager/Shell/res/drawable/tv_pip_button_bg.xml similarity index 74% rename from libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml rename to libs/WindowManager/Shell/res/drawable/tv_pip_button_bg.xml index cce13035dba77..1938f4562e97b 100644 --- a/libs/WindowManager/Shell/res/drawable/tv_pip_button_focused.xml +++ b/libs/WindowManager/Shell/res/drawable/tv_pip_button_bg.xml @@ -14,5 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + + \ No newline at end of file diff --git a/libs/WindowManager/Shell/res/drawable/tv_pip_menu_border.xml b/libs/WindowManager/Shell/res/drawable/tv_pip_menu_border.xml new file mode 100644 index 0000000000000..9bc03112b1186 --- /dev/null +++ b/libs/WindowManager/Shell/res/drawable/tv_pip_menu_border.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml index 49e2379589a45..5b90c99c22e0f 100644 --- a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml +++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml @@ -18,35 +18,54 @@ + android:layout_height="match_parent"> - + - + - + - + - + + + + + + + + diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu_action_button.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu_action_button.xml index 5925008e0d084..f9d0968a16df8 100644 --- a/libs/WindowManager/Shell/res/layout/tv_pip_menu_action_button.xml +++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu_action_button.xml @@ -15,36 +15,20 @@ limitations under the License. --> - + - - - - - - + + \ No newline at end of file diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu_additional_action_button.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu_additional_action_button.xml deleted file mode 100644 index bf4eb2691ff05..0000000000000 --- a/libs/WindowManager/Shell/res/layout/tv_pip_menu_additional_action_button.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml index 7920fd237a08b..e41ebc4fb2454 100644 --- a/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml +++ b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml @@ -16,7 +16,12 @@ --> - 100dp - -50dp + 40dp + 20dp + 20dp + 4dp + 26dp + 2dp + 0dp diff --git a/libs/WindowManager/Shell/res/values/colors_tv.xml b/libs/WindowManager/Shell/res/values/colors_tv.xml new file mode 100644 index 0000000000000..17387fa1636f0 --- /dev/null +++ b/libs/WindowManager/Shell/res/values/colors_tv.xml @@ -0,0 +1,24 @@ + + + + #0E0E0F + #E8EAED + #80868B + #E8EAED + #777777 + #CCE8EAED + \ No newline at end of file diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java index 83390a5390435..b165706bc0380 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java @@ -253,9 +253,6 @@ public class TvPipController implements PipTransitionController.PipTransitionCal final Rect newBounds; switch (mState) { case STATE_PIP_MENU: - newBounds = mPipBoundsState.getExpandedBounds(); - break; - case STATE_PIP: // Let PipBoundsAlgorithm figure out what the correct bounds are at the moment. // Internally, it will get the "default" bounds from PipBoundsState and adjust them @@ -336,11 +333,6 @@ public class TvPipController implements PipTransitionController.PipTransitionCal private void loadConfigurations() { final Resources res = mContext.getResources(); mResizeAnimationDuration = res.getInteger(R.integer.config_pipResizeAnimationDuration); - // "Cache" bounds for the Pip menu as "expanded" bounds in PipBoundsState. We'll refer back - // to this value in resizePinnedStack(), when we are adjusting Pip task/window position for - // the menu. - mPipBoundsState.setExpandedBounds( - Rect.unflattenFromString(res.getString(R.string.pip_menu_bounds))); } private DisplayInfo getDisplayInfo() { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuActionButton.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuActionButton.java index 6f7cd82f8da01..bda685e99a12a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuActionButton.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuActionButton.java @@ -16,8 +16,6 @@ package com.android.wm.shell.pip.tv; -import android.animation.Animator; -import android.animation.AnimatorInflater; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; @@ -26,7 +24,6 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; -import android.widget.TextView; import com.android.wm.shell.R; @@ -36,12 +33,7 @@ import com.android.wm.shell.R; */ public class TvPipMenuActionButton extends RelativeLayout implements View.OnClickListener { private final ImageView mIconImageView; - private final ImageView mButtonImageView; - private final TextView mDescriptionTextView; - private Animator mTextFocusGainAnimator; - private Animator mButtonFocusGainAnimator; - private Animator mTextFocusLossAnimator; - private Animator mButtonFocusLossAnimator; + private final View mButtonView; private OnClickListener mOnClickListener; public TvPipMenuActionButton(Context context) { @@ -64,8 +56,7 @@ public class TvPipMenuActionButton extends RelativeLayout implements View.OnClic inflater.inflate(R.layout.tv_pip_menu_action_button, this); mIconImageView = findViewById(R.id.icon); - mButtonImageView = findViewById(R.id.button); - mDescriptionTextView = findViewById(R.id.desc); + mButtonView = findViewById(R.id.button); final int[] values = new int[]{android.R.attr.src, android.R.attr.text}; final TypedArray typedArray = context.obtainStyledAttributes(attrs, values, defStyleAttr, @@ -76,43 +67,16 @@ public class TvPipMenuActionButton extends RelativeLayout implements View.OnClic if (textResId != 0) { setTextAndDescription(getContext().getString(textResId)); } - typedArray.recycle(); } - @Override - public void onFinishInflate() { - super.onFinishInflate(); - mButtonImageView.setOnFocusChangeListener((v, hasFocus) -> { - if (hasFocus) { - startFocusGainAnimation(); - } else { - startFocusLossAnimation(); - } - }); - - mTextFocusGainAnimator = AnimatorInflater.loadAnimator(getContext(), - R.anim.tv_pip_controls_focus_gain_animation); - mTextFocusGainAnimator.setTarget(mDescriptionTextView); - mButtonFocusGainAnimator = AnimatorInflater.loadAnimator(getContext(), - R.anim.tv_pip_controls_focus_gain_animation); - mButtonFocusGainAnimator.setTarget(mButtonImageView); - - mTextFocusLossAnimator = AnimatorInflater.loadAnimator(getContext(), - R.anim.tv_pip_controls_focus_loss_animation); - mTextFocusLossAnimator.setTarget(mDescriptionTextView); - mButtonFocusLossAnimator = AnimatorInflater.loadAnimator(getContext(), - R.anim.tv_pip_controls_focus_loss_animation); - mButtonFocusLossAnimator.setTarget(mButtonImageView); - } - @Override public void setOnClickListener(OnClickListener listener) { // We do not want to set an OnClickListener to the TvPipMenuActionButton itself, but only to // the ImageView. So let's "cash" the listener we've been passed here and set a "proxy" // listener to the ImageView. mOnClickListener = listener; - mButtonImageView.setOnClickListener(listener != null ? this : null); + mButtonView.setOnClickListener(listener != null ? this : null); } @Override @@ -143,55 +107,16 @@ public class TvPipMenuActionButton extends RelativeLayout implements View.OnClic * Sets the text for description the with the given string. */ public void setTextAndDescription(CharSequence text) { - mButtonImageView.setContentDescription(text); - mDescriptionTextView.setText(text); + mButtonView.setContentDescription(text); } - private static void cancelAnimator(Animator animator) { - if (animator.isStarted()) { - animator.cancel(); - } + @Override + public void setEnabled(boolean enabled) { + mButtonView.setEnabled(enabled); } - /** - * Starts the focus gain animation. - */ - public void startFocusGainAnimation() { - cancelAnimator(mButtonFocusLossAnimator); - cancelAnimator(mTextFocusLossAnimator); - mTextFocusGainAnimator.start(); - if (mButtonImageView.getAlpha() < 1f) { - // If we had faded out the ripple drawable, run our manual focus change animation. - // See the comment at {@link #startFocusLossAnimation()} for the reason of manual - // animator. - mButtonFocusGainAnimator.start(); - } - } - - /** - * Starts the focus loss animation. - */ - public void startFocusLossAnimation() { - cancelAnimator(mButtonFocusGainAnimator); - cancelAnimator(mTextFocusGainAnimator); - mTextFocusLossAnimator.start(); - if (mButtonImageView.hasFocus()) { - // Button uses ripple that has the default animation for the focus changes. - // However, it doesn't expose the API to fade out while it is focused, so we should - // manually run the fade out animation when PIP controls row loses focus. - mButtonFocusLossAnimator.start(); - } - } - - /** - * Resets to initial state. - */ - public void reset() { - cancelAnimator(mButtonFocusGainAnimator); - cancelAnimator(mTextFocusGainAnimator); - cancelAnimator(mButtonFocusLossAnimator); - cancelAnimator(mTextFocusLossAnimator); - mButtonImageView.setAlpha(1f); - mDescriptionTextView.setAlpha(mButtonImageView.hasFocus() ? 1f : 0f); + @Override + public boolean isEnabled() { + return mButtonView.isEnabled(); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java index ee41b41a743d0..77bfa07a425fc 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ParceledListSlice; +import android.graphics.Rect; import android.os.Handler; import android.util.Log; import android.view.SurfaceControl; @@ -122,19 +123,19 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis if (DEBUG) Log.d(TAG, "showMenu()"); if (mMenuView != null) { - mSystemWindows.updateViewLayout(mMenuView, getPipMenuLayoutParams(MENU_WINDOW_TITLE, - mPipBoundsState.getDisplayBounds().width(), - mPipBoundsState.getDisplayBounds().height())); + Rect pipBounds = mPipBoundsState.getBounds(); + mSystemWindows.updateViewLayout(mMenuView, getPipMenuLayoutParams( + MENU_WINDOW_TITLE, pipBounds.width(), pipBounds.height())); maybeUpdateMenuViewActions(); - mMenuView.show(); - // By default, SystemWindows views are above everything else. - // Set the relative z-order so the menu is below PiP. - if (mMenuView.getWindowSurfaceControl() != null && mLeash != null) { + SurfaceControl menuSurfaceControl = mSystemWindows.getViewSurface(mMenuView); + if (menuSurfaceControl != null) { SurfaceControl.Transaction t = new SurfaceControl.Transaction(); - t.setRelativeLayer(mMenuView.getWindowSurfaceControl(), mLeash, -1); + t.setRelativeLayer(mMenuView.getWindowSurfaceControl(), mLeash, 1); + t.setPosition(menuSurfaceControl, pipBounds.left, pipBounds.top); t.apply(); } + mMenuView.show(); } } @@ -181,7 +182,15 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis private void onMediaActionsChanged(List actions) { if (DEBUG) Log.d(TAG, "onMediaActionsChanged()"); - updateAdditionalActionsList(mMediaActions, actions); + + // Hide disabled actions. + List enabledActions = new ArrayList<>(); + for (RemoteAction remoteAction : actions) { + if (remoteAction.isEnabled()) { + enabledActions.add(remoteAction); + } + } + updateAdditionalActionsList(mMediaActions, enabledActions); } private void updateAdditionalActionsList( 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 d6cd9ea13ca1e..4327f1590f534 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 @@ -24,9 +24,7 @@ import android.animation.Animator; import android.app.PendingIntent; import android.app.RemoteAction; import android.content.Context; -import android.graphics.Color; import android.os.Handler; -import android.os.Looper; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -55,13 +53,13 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { private static final String TAG = "TvPipMenuView"; private static final boolean DEBUG = TvPipController.DEBUG; - private static final float DISABLED_ACTION_ALPHA = 0.54f; - private final Animator mFadeInAnimation; private final Animator mFadeOutAnimation; - @Nullable private Listener mListener; + @Nullable + private Listener mListener; private final LinearLayout mActionButtonsContainer; + private final View mMenuFrameView; private final List mAdditionalButtons = new ArrayList<>(); public TvPipMenuView(@NonNull Context context) { @@ -88,11 +86,12 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { mActionButtonsContainer.findViewById(R.id.tv_pip_menu_close_button) .setOnClickListener(this); + mMenuFrameView = findViewById(R.id.tv_pip_menu_frame); mFadeInAnimation = loadAnimator(mContext, R.anim.tv_pip_menu_fade_in_animation); - mFadeInAnimation.setTarget(mActionButtonsContainer); + mFadeInAnimation.setTarget(mMenuFrameView); mFadeOutAnimation = loadAnimator(mContext, R.anim.tv_pip_menu_fade_out_animation); - mFadeOutAnimation.setTarget(mActionButtonsContainer); + mFadeOutAnimation.setTarget(mMenuFrameView); } void setListener(@Nullable Listener listener) { @@ -103,7 +102,6 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { if (DEBUG) Log.d(TAG, "show()"); mFadeInAnimation.start(); - setAlpha(1.0f); grantWindowFocus(true); } @@ -111,12 +109,11 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { if (DEBUG) Log.d(TAG, "hide()"); mFadeOutAnimation.start(); - setAlpha(0.0f); grantWindowFocus(false); } boolean isVisible() { - return getAlpha() == 1.0f; + return mMenuFrameView != null && mMenuFrameView.getAlpha() != 0.0f; } private void grantWindowFocus(boolean grantFocus) { @@ -140,9 +137,7 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { final LayoutInflater layoutInflater = LayoutInflater.from(mContext); // Add buttons until we have enough to display all of the actions. while (actionsNumber > buttonsNumber) { - final TvPipMenuActionButton button = (TvPipMenuActionButton) layoutInflater.inflate( - R.layout.tv_pip_menu_additional_action_button, mActionButtonsContainer, - false); + TvPipMenuActionButton button = new TvPipMenuActionButton(mContext); button.setOnClickListener(this); mActionButtonsContainer.addView(button); @@ -168,13 +163,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { button.setVisibility(View.VISIBLE); // Ensure the button is visible. button.setTextAndDescription(action.getContentDescription()); button.setEnabled(action.isEnabled()); - button.setAlpha(action.isEnabled() ? 1f : DISABLED_ACTION_ALPHA); button.setTag(action); - - action.getIcon().loadDrawableAsync(mContext, drawable -> { - drawable.setTint(Color.WHITE); - button.setImageDrawable(drawable); - }, mainHandler); + action.getIcon().loadDrawableAsync(mContext, button::setImageDrawable, mainHandler); } }