From 4edea3a6a6515da6c5809a341a12f6f19300684a Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Tue, 29 Jun 2021 16:14:48 +0100 Subject: [PATCH] Set the widgets pickers' width to at most 80% of screen width on large screen devices Test: Phone: Open the full widgets picker and observe the width of the widgets picker fills the device screen width. Large screen devices: Open the bottom widgets picker and observe the width of the widgets picker only takes at most 80% of the devices' screen width. Same behavior is observed for bottom widgets picker. Bug: 186425352 Change-Id: I801b73ea031a290fb6a7295dca826ac91841877e --- .../android/launcher3/widget/BaseWidgetSheet.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index 9f0b9d9b1f..a5c142db66 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -51,6 +51,11 @@ import com.android.launcher3.views.ArrowTipView; public abstract class BaseWidgetSheet extends AbstractSlideInView implements OnClickListener, OnLongClickListener, DragSource, PopupDataProvider.PopupDataChangeListener, Insettable { + /** + * The maximum scale, [0, 1], of the device screen width that the widgets picker can consume + * on large screen devices. + */ + protected static final float MAX_WIDTH_SCALE_FOR_LARGER_SCREEN = 0.8f; protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN = "launcher.widgets_education_tip_seen"; @@ -131,6 +136,15 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView 2 * (mInsets.left + mInsets.right)); } + if (deviceProfile.isTablet || deviceProfile.isTwoPanels) { + // In large screen devices, we restrict the width of the widgets picker to show part of + // the home screen. Let's ensure the minimum width used is at least the minimum width + // that isn't taken by the widgets picker. + int minUsedWidth = (int) (deviceProfile.availableWidthPx + * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN)); + widthUsed = Math.max(widthUsed, minUsedWidth); + } + int heightUsed = mInsets.top + deviceProfile.edgeMarginPx; measureChildWithMargins(mContent, widthMeasureSpec, widthUsed, heightMeasureSpec, heightUsed);