From 471b88269ff6fbab91ad0ef3acb51191767b096c Mon Sep 17 00:00:00 2001 From: Charlie Anderson Date: Fri, 31 Mar 2023 14:02:58 -0400 Subject: [PATCH] Prevents cropping of shortcuts in the app popup menu by limiting rows to available screen space. - Limit the number of shortcut rows shown to what will fit the screen. - Fix drag testDragShortcut so that it works for all screen sizes. - Prevent cropping and misalignment of shortcut text. Bug: 247880037 Fixes: 275115239 Test: locally on different devices, and with Display Size set to different sizes Change-Id: I18b27ec302c34d1d801171ab18c64169a9f252ee --- res/layout/system_shortcut_content.xml | 5 +---- .../android/launcher3/popup/ArrowPopup.java | 8 +++---- .../popup/PopupContainerWithArrow.java | 18 +++++++++++---- .../launcher3/ui/TaplTestsLauncher3.java | 22 +++++-------------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/res/layout/system_shortcut_content.xml b/res/layout/system_shortcut_content.xml index ddcef096e0..3008339653 100644 --- a/res/layout/system_shortcut_content.xml +++ b/res/layout/system_shortcut_content.xml @@ -22,15 +22,12 @@ android:id="@+id/bubble_text" android:background="?android:attr/selectableItemBackground" android:gravity="start|center_vertical" - android:paddingTop="@dimen/bg_popup_item_vertical_padding" - android:paddingBottom="@dimen/bg_popup_item_vertical_padding" android:minHeight="@dimen/bg_popup_item_height" android:textAlignment="viewStart" android:paddingStart="@dimen/deep_shortcuts_text_padding_start" android:paddingEnd="@dimen/popup_padding_end" android:textSize="14sp" - android:minLines="1" - android:maxLines="2" + android:lines="1" android:ellipsize="end" android:hyphenationFrequency="full" android:textColor="@color/system_shortcut_text" diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index 0edf2921ae..5b493c2a65 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -109,7 +109,7 @@ public abstract class ArrowPopup protected final int mArrowPointRadius; protected final View mArrow; - private final int mMargin; + protected final int mChildContainerMargin; protected boolean mIsLeftAligned; protected boolean mIsAboveIcon; @@ -145,7 +145,7 @@ public abstract class ArrowPopup // Initialize arrow view final Resources resources = getResources(); mArrowColor = getColorStateList(getContext(), R.color.popup_shade_first).getDefaultColor(); - mMargin = resources.getDimensionPixelSize(R.dimen.popup_margin); + mChildContainerMargin = resources.getDimensionPixelSize(R.dimen.popup_margin); mArrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width); mArrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); mArrow = new View(context); @@ -249,7 +249,7 @@ public abstract class ArrowPopup if (view.getVisibility() == VISIBLE) { if (lastView != null) { MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); - mlp.bottomMargin = mMargin; + mlp.bottomMargin = mChildContainerMargin; } lastView = view; MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); @@ -441,7 +441,7 @@ public abstract class ArrowPopup numVisibleChildren++; } } - int childMargins = (numVisibleChildren - 1) * mMargin; + int childMargins = (numVisibleChildren - 1) * mChildContainerMargin; int height = getMeasuredHeight() + extraVerticalSpace + childMargins; int width = getMeasuredWidth() + getPaddingLeft() + getPaddingRight(); diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 3f75eccea0..9cca29a6d0 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -95,6 +95,8 @@ public class PopupContainerWithArrow private static final int SHORTCUT_COLLAPSE_THRESHOLD = 6; + private final float mShortcutHeight; + private BubbleTextView mOriginalIcon; private int mNumNotifications; private NotificationContainer mNotificationContainer; @@ -112,6 +114,7 @@ public class PopupContainerWithArrow mStartDragThreshold = getResources().getDimensionPixelSize( R.dimen.deep_shortcuts_start_drag_threshold); mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); + mShortcutHeight = getResources().getDimension(R.dimen.system_shortcut_header_height); } public PopupContainerWithArrow(Context context, AttributeSet attrs) { @@ -387,16 +390,18 @@ public class PopupContainerWithArrow */ private void addAllShortcutsMaterialU(int deepShortcutCount, List systemShortcuts) { - if (deepShortcutCount + systemShortcuts.size() <= SHORTCUT_COLLAPSE_THRESHOLD) { // add all system shortcuts including widgets shortcut to same container addSystemShortcutsMaterialU(systemShortcuts, R.layout.system_shortcut_rows_container_material_u, R.layout.system_shortcut); - addDeepShortcutsMaterialU(deepShortcutCount); + float currentHeight = (mShortcutHeight * systemShortcuts.size()) + + mChildContainerMargin; + addDeepShortcutsMaterialU(deepShortcutCount, currentHeight); return; } + float currentHeight = mShortcutHeight + mChildContainerMargin; List nonWidgetSystemShortcuts = getNonWidgetSystemShortcuts(systemShortcuts); // If total shortcuts over threshold, collapse system shortcuts to single row @@ -411,8 +416,9 @@ public class PopupContainerWithArrow mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container_material_u, this); initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get()); + currentHeight += mShortcutHeight + mChildContainerMargin; } - addDeepShortcutsMaterialU(deepShortcutCount); + addDeepShortcutsMaterialU(deepShortcutCount, currentHeight); } /** @@ -497,10 +503,14 @@ public class PopupContainerWithArrow /** * Inflates and adds [deepShortcutCount] number of DeepShortcutView for the to a new container * @param deepShortcutCount number of DeepShortcutView instances to add + * @param currentHeight height of popup before adding deep shortcuts */ - private void addDeepShortcutsMaterialU(int deepShortcutCount) { + private void addDeepShortcutsMaterialU(int deepShortcutCount, float currentHeight) { mDeepShortcutContainer = inflateAndAdd(R.layout.deep_shortcut_container, this); for (int i = deepShortcutCount; i > 0; i--) { + currentHeight += mShortcutHeight; + // when there is limited vertical screen space, limit total popup rows to fit + if (currentHeight >= mActivityContext.getDeviceProfile().availableHeightPx) break; DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut_material_u, mDeepShortcutContainer); v.getLayoutParams().width = mContainerWidth; diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index f30538d408..217bec3aa1 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -51,7 +51,6 @@ import com.android.launcher3.tapl.Folder; import com.android.launcher3.tapl.FolderIcon; import com.android.launcher3.tapl.HomeAllApps; import com.android.launcher3.tapl.HomeAppIcon; -import com.android.launcher3.tapl.HomeAppIconMenu; import com.android.launcher3.tapl.HomeAppIconMenuItem; import com.android.launcher3.tapl.Widgets; import com.android.launcher3.tapl.Workspace; @@ -391,23 +390,14 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { .switchToAllApps(); allApps.freeze(); try { - final HomeAppIconMenu menu = allApps + final HomeAppIconMenuItem menuItem = allApps .getAppIcon(APP_NAME) - .openDeepShortcutMenu(); - final HomeAppIconMenuItem menuItem0 = menu.getMenuItem(0); - final HomeAppIconMenuItem menuItem2 = menu.getMenuItem(2); - - final HomeAppIconMenuItem menuItem; - - final String expectedShortcutName = "Shortcut 3"; - if (menuItem0.getText().equals(expectedShortcutName)) { - menuItem = menuItem0; - } else { - final String shortcutName2 = menuItem2.getText(); - assertEquals("Wrong menu item", expectedShortcutName, shortcutName2); - menuItem = menuItem2; - } + .openDeepShortcutMenu() + .getMenuItem(0); + final String actualShortcutName = menuItem.getText(); + final String expectedShortcutName = "Shortcut 1"; + assertEquals(expectedShortcutName, actualShortcutName); menuItem.dragToWorkspace(false, false); mLauncher.getWorkspace().getWorkspaceAppIcon(expectedShortcutName) .launch(getAppPackageName());