From dfa88d55f505d3f1f44dc2e4045c05ea097ea7eb Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Tue, 5 Apr 2022 12:01:46 -0700 Subject: [PATCH] Make the widget option on the PopupContainer full width The width of the PopupContainer grows if there are multiple SystemShortcuts and we where not updating the width of all the options. Fix: 227538975 Test: Long press an app like Google Maps on the HomeScreen to see the menu. All the options should have the same width. Change-Id: I25310d74aa1af17be37b53c27d2334f86bef325a --- .../popup/LauncherPopupLiveUpdateHandler.java | 3 +-- .../popup/PopupContainerWithArrow.java | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java b/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java index 3e3f633567..72956b01c8 100644 --- a/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java +++ b/src/com/android/launcher3/popup/LauncherPopupLiveUpdateHandler.java @@ -62,8 +62,7 @@ public class LauncherPopupLiveUpdateHandler extends PopupLiveUpdateHandler private BubbleTextView mOriginalIcon; private int mNumNotifications; private NotificationContainer mNotificationContainer; + private int mContainerWidth; private ViewGroup mWidgetContainer; @@ -104,6 +105,7 @@ public class PopupContainerWithArrow super(context, attrs, defStyleAttr); mStartDragThreshold = getResources().getDimensionPixelSize( R.dimen.deep_shortcuts_start_drag_threshold); + mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); } public PopupContainerWithArrow(Context context, AttributeSet attrs) { @@ -246,14 +248,15 @@ public class PopupContainerWithArrow mOriginalIcon = originalIcon; boolean hasDeepShortcuts = shortcutCount > 0; - int containerWidth = (int) getResources().getDimension(R.dimen.bg_popup_item_width); + mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); // if there are deep shortcuts, we might want to increase the width of shortcuts to fit // horizontally laid out system shortcuts. if (hasDeepShortcuts) { - containerWidth = (int) Math.max(containerWidth, - systemShortcuts.size() * getResources().getDimension( - R.dimen.system_shortcut_header_icon_touch_size)); + mContainerWidth = Math.max(mContainerWidth, + systemShortcuts.size() * getResources() + .getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size) + ); } // Add views if (mNumNotifications > 0) { @@ -277,7 +280,7 @@ public class PopupContainerWithArrow for (int i = shortcutCount; i > 0; i--) { DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, mDeepShortcutContainer); - v.getLayoutParams().width = containerWidth; + v.getLayoutParams().width = mContainerWidth; mShortcuts.add(v); } updateHiddenShortcuts(); @@ -289,8 +292,7 @@ public class PopupContainerWithArrow mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, this); } - initializeSystemShortcut(R.layout.system_shortcut, mWidgetContainer, - shortcut); + initializeWidgetShortcut(mWidgetContainer, shortcut); } } mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this); @@ -384,7 +386,12 @@ public class PopupContainerWithArrow } } - protected void initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) { + protected void initializeWidgetShortcut(ViewGroup container, SystemShortcut info) { + View view = initializeSystemShortcut(R.layout.system_shortcut, container, info); + view.getLayoutParams().width = mContainerWidth; + } + + protected View initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) { View view = inflateAndAdd( resId, container, getInsertIndexForSystemShortcut(container, info)); if (view instanceof DeepShortcutView) { @@ -398,6 +405,7 @@ public class PopupContainerWithArrow } view.setTag(info); view.setOnClickListener(info); + return view; } /**