From 128460ed360ee312077487d5c43b89dcc979f932 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 1 Feb 2022 20:16:13 +0000 Subject: [PATCH] Home Controls: Adjust width of menu for tablets. Menu is usually half of the width for phones. Check the dp width of the device and default to size of largest child view + padding if the dp width of the device is over some threshold. Bug: 217373193 Test: Tested on tablet device Change-Id: I567891e70607428b965c3d2c55ec8ced210300fc --- .../systemui/globalactions/GlobalActionsPopupMenu.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPopupMenu.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPopupMenu.java index d1a103e3a8fa2..de67ba8a6ded4 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPopupMenu.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsPopupMenu.java @@ -40,6 +40,7 @@ public class GlobalActionsPopupMenu extends ListPopupWindow { private boolean mIsDropDownMode; private int mMenuVerticalPadding = 0; private int mGlobalActionsSidePadding = 0; + private int mMaximumWidthThresholdDp = 800; private ListAdapter mAdapter; private AdapterView.OnItemLongClickListener mOnItemLongClickListener; @@ -92,6 +93,8 @@ public class GlobalActionsPopupMenu extends ListPopupWindow { // width should be between [.5, .9] of screen int parentWidth = res.getSystem().getDisplayMetrics().widthPixels; + float parentDensity = res.getSystem().getDisplayMetrics().density; + float parentWidthDp = parentWidth / parentDensity; int widthSpec = MeasureSpec.makeMeasureSpec( (int) (parentWidth * 0.9), MeasureSpec.AT_MOST); int maxWidth = 0; @@ -101,9 +104,12 @@ public class GlobalActionsPopupMenu extends ListPopupWindow { int w = child.getMeasuredWidth(); maxWidth = Math.max(w, maxWidth); } - int width = Math.max(maxWidth, (int) (parentWidth * 0.5)); - listView.setPadding(0, mMenuVerticalPadding, 0, mMenuVerticalPadding); + int width = maxWidth; + if (parentWidthDp < mMaximumWidthThresholdDp) { + width = Math.max(maxWidth, (int) (parentWidth * 0.5)); + } + listView.setPadding(0, mMenuVerticalPadding, 0, mMenuVerticalPadding); setWidth(width); if (getAnchorView().getLayoutDirection() == LayoutDirection.LTR) { setHorizontalOffset(getAnchorView().getWidth() - mGlobalActionsSidePadding - width);