From 0dc09244e5894edf65d13248bc43d1a2fed0e2f0 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Mon, 1 Feb 2021 14:37:52 -0800 Subject: [PATCH] Adjust the estimated minimum size of PiP menu Use the similar measurement from PipMenuView#updateActionViews Video: http://rcll/aaaaaabFQoRHlzixHdtY/g1YgomInywOHbZcKdsegcf Bug: 175055101 Test: See video Change-Id: I2a52f46c2208b9e164f0898fff0e43cbb3eb8b96 --- .../pip/phone/PhonePipMenuController.java | 4 ++-- .../wm/shell/pip/phone/PipMenuView.java | 18 ++++++++++-------- .../wm/shell/pip/phone/PipTouchHandler.java | 9 ++++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index 4b118f1217672..a57eee83ef59a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -212,8 +212,8 @@ public class PhonePipMenuController implements PipMenuController { } @Nullable - Size getEstimatedMenuSize() { - return mPipMenuView == null ? null : mPipMenuView.getEstimatedMenuSize(); + Size getEstimatedMinMenuSize() { + return mPipMenuView == null ? null : mPipMenuView.getEstimatedMinMenuSize(); } /** diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java index 48942b604a8d4..2df3e2ec1f811 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java @@ -367,15 +367,17 @@ public class PipMenuView extends FrameLayout { } /** - * @return estimated {@link Size} for which the width is based on number of actions and - * height based on the height of expand button + top and bottom action bar. + * @return Estimated minimum {@link Size} to hold the actions. + * See also {@link #updateActionViews(Rect)} */ - Size getEstimatedMenuSize() { - final int pipActionSize = mContext.getResources().getDimensionPixelSize( - R.dimen.pip_action_size); - final int width = mActions.size() * pipActionSize; - final int height = pipActionSize * 2 + mContext.getResources().getDimensionPixelSize( - R.dimen.pip_expand_action_size); + Size getEstimatedMinMenuSize() { + final int pipActionSize = getResources().getDimensionPixelSize(R.dimen.pip_action_size); + // the minimum width would be (2 * pipActionSize) since we have settings and dismiss button + // on the top action container. + final int width = Math.max(2, mActions.size()) * pipActionSize; + final int height = getResources().getDimensionPixelSize(R.dimen.pip_expand_action_size) + + getResources().getDimensionPixelSize(R.dimen.pip_action_padding) + + getResources().getDimensionPixelSize(R.dimen.pip_expand_container_edge_margin); return new Size(width, height); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index 128d13c2ce2e5..03861d1715d96 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -30,7 +30,6 @@ import android.content.res.Resources; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; -import android.os.Handler; import android.provider.DeviceConfig; import android.util.Log; import android.util.Size; @@ -932,14 +931,14 @@ public class PipTouchHandler { if (!mEnableResize) { return false; } - final Size estimatedMenuSize = mMenuController.getEstimatedMenuSize(); - if (estimatedMenuSize == null) { + final Size estimatedMinMenuSize = mMenuController.getEstimatedMinMenuSize(); + if (estimatedMinMenuSize == null) { Log.wtf(TAG, "Failed to get estimated menu size"); return false; } final Rect currentBounds = mPipBoundsState.getBounds(); - return currentBounds.width() < estimatedMenuSize.getWidth() - || currentBounds.height() < estimatedMenuSize.getHeight(); + return currentBounds.width() < estimatedMinMenuSize.getWidth() + || currentBounds.height() < estimatedMinMenuSize.getHeight(); } /**