Merge "Prevents cropping of shortcuts in the app popup menu by limiting rows to available screen space." into udc-dev am: 39fbf0e1a7

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22382551

Change-Id: I2e889e8f4c780ca06e047064abe024e77b5ec680
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Charlie Anderson
2023-04-06 23:23:08 +00:00
committed by Automerger Merge Worker
4 changed files with 25 additions and 28 deletions
+1 -4
View File
@@ -22,15 +22,12 @@
android:id="@+id/bubble_text" android:id="@+id/bubble_text"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="start|center_vertical" 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:minHeight="@dimen/bg_popup_item_height"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:paddingStart="@dimen/deep_shortcuts_text_padding_start" android:paddingStart="@dimen/deep_shortcuts_text_padding_start"
android:paddingEnd="@dimen/popup_padding_end" android:paddingEnd="@dimen/popup_padding_end"
android:textSize="14sp" android:textSize="14sp"
android:minLines="1" android:lines="1"
android:maxLines="2"
android:ellipsize="end" android:ellipsize="end"
android:hyphenationFrequency="full" android:hyphenationFrequency="full"
android:textColor="@color/system_shortcut_text" android:textColor="@color/system_shortcut_text"
@@ -109,7 +109,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
protected final int mArrowPointRadius; protected final int mArrowPointRadius;
protected final View mArrow; protected final View mArrow;
private final int mMargin; protected final int mChildContainerMargin;
protected boolean mIsLeftAligned; protected boolean mIsLeftAligned;
protected boolean mIsAboveIcon; protected boolean mIsAboveIcon;
@@ -145,7 +145,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
// Initialize arrow view // Initialize arrow view
final Resources resources = getResources(); final Resources resources = getResources();
mArrowColor = getColorStateList(getContext(), R.color.popup_shade_first).getDefaultColor(); 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); mArrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width);
mArrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); mArrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height);
mArrow = new View(context); mArrow = new View(context);
@@ -249,7 +249,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
if (view.getVisibility() == VISIBLE) { if (view.getVisibility() == VISIBLE) {
if (lastView != null) { if (lastView != null) {
MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
mlp.bottomMargin = mMargin; mlp.bottomMargin = mChildContainerMargin;
} }
lastView = view; lastView = view;
MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
@@ -441,7 +441,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
numVisibleChildren++; numVisibleChildren++;
} }
} }
int childMargins = (numVisibleChildren - 1) * mMargin; int childMargins = (numVisibleChildren - 1) * mChildContainerMargin;
int height = getMeasuredHeight() + extraVerticalSpace + childMargins; int height = getMeasuredHeight() + extraVerticalSpace + childMargins;
int width = getMeasuredWidth() + getPaddingLeft() + getPaddingRight(); int width = getMeasuredWidth() + getPaddingLeft() + getPaddingRight();
@@ -95,6 +95,8 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
private static final int SHORTCUT_COLLAPSE_THRESHOLD = 6; private static final int SHORTCUT_COLLAPSE_THRESHOLD = 6;
private final float mShortcutHeight;
private BubbleTextView mOriginalIcon; private BubbleTextView mOriginalIcon;
private int mNumNotifications; private int mNumNotifications;
private NotificationContainer mNotificationContainer; private NotificationContainer mNotificationContainer;
@@ -112,6 +114,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
mStartDragThreshold = getResources().getDimensionPixelSize( mStartDragThreshold = getResources().getDimensionPixelSize(
R.dimen.deep_shortcuts_start_drag_threshold); R.dimen.deep_shortcuts_start_drag_threshold);
mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width);
mShortcutHeight = getResources().getDimension(R.dimen.system_shortcut_header_height);
} }
public PopupContainerWithArrow(Context context, AttributeSet attrs) { public PopupContainerWithArrow(Context context, AttributeSet attrs) {
@@ -387,16 +390,18 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
*/ */
private void addAllShortcutsMaterialU(int deepShortcutCount, private void addAllShortcutsMaterialU(int deepShortcutCount,
List<SystemShortcut> systemShortcuts) { List<SystemShortcut> systemShortcuts) {
if (deepShortcutCount + systemShortcuts.size() <= SHORTCUT_COLLAPSE_THRESHOLD) { if (deepShortcutCount + systemShortcuts.size() <= SHORTCUT_COLLAPSE_THRESHOLD) {
// add all system shortcuts including widgets shortcut to same container // add all system shortcuts including widgets shortcut to same container
addSystemShortcutsMaterialU(systemShortcuts, addSystemShortcutsMaterialU(systemShortcuts,
R.layout.system_shortcut_rows_container_material_u, R.layout.system_shortcut_rows_container_material_u,
R.layout.system_shortcut); R.layout.system_shortcut);
addDeepShortcutsMaterialU(deepShortcutCount); float currentHeight = (mShortcutHeight * systemShortcuts.size())
+ mChildContainerMargin;
addDeepShortcutsMaterialU(deepShortcutCount, currentHeight);
return; return;
} }
float currentHeight = mShortcutHeight + mChildContainerMargin;
List<SystemShortcut> nonWidgetSystemShortcuts = List<SystemShortcut> nonWidgetSystemShortcuts =
getNonWidgetSystemShortcuts(systemShortcuts); getNonWidgetSystemShortcuts(systemShortcuts);
// If total shortcuts over threshold, collapse system shortcuts to single row // If total shortcuts over threshold, collapse system shortcuts to single row
@@ -411,8 +416,9 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container_material_u, mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container_material_u,
this); this);
initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get()); initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get());
currentHeight += mShortcutHeight + mChildContainerMargin;
} }
addDeepShortcutsMaterialU(deepShortcutCount); addDeepShortcutsMaterialU(deepShortcutCount, currentHeight);
} }
/** /**
@@ -497,10 +503,14 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
/** /**
* Inflates and adds [deepShortcutCount] number of DeepShortcutView for the to a new container * Inflates and adds [deepShortcutCount] number of DeepShortcutView for the to a new container
* @param deepShortcutCount number of DeepShortcutView instances to add * @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); mDeepShortcutContainer = inflateAndAdd(R.layout.deep_shortcut_container, this);
for (int i = deepShortcutCount; i > 0; i--) { 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, DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut_material_u,
mDeepShortcutContainer); mDeepShortcutContainer);
v.getLayoutParams().width = mContainerWidth; v.getLayoutParams().width = mContainerWidth;
@@ -51,7 +51,6 @@ import com.android.launcher3.tapl.Folder;
import com.android.launcher3.tapl.FolderIcon; import com.android.launcher3.tapl.FolderIcon;
import com.android.launcher3.tapl.HomeAllApps; import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.tapl.HomeAppIcon; import com.android.launcher3.tapl.HomeAppIcon;
import com.android.launcher3.tapl.HomeAppIconMenu;
import com.android.launcher3.tapl.HomeAppIconMenuItem; import com.android.launcher3.tapl.HomeAppIconMenuItem;
import com.android.launcher3.tapl.Widgets; import com.android.launcher3.tapl.Widgets;
import com.android.launcher3.tapl.Workspace; import com.android.launcher3.tapl.Workspace;
@@ -391,23 +390,14 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
.switchToAllApps(); .switchToAllApps();
allApps.freeze(); allApps.freeze();
try { try {
final HomeAppIconMenu menu = allApps final HomeAppIconMenuItem menuItem = allApps
.getAppIcon(APP_NAME) .getAppIcon(APP_NAME)
.openDeepShortcutMenu(); .openDeepShortcutMenu()
final HomeAppIconMenuItem menuItem0 = menu.getMenuItem(0); .getMenuItem(0);
final HomeAppIconMenuItem menuItem2 = menu.getMenuItem(2); final String actualShortcutName = menuItem.getText();
final String expectedShortcutName = "Shortcut 1";
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;
}
assertEquals(expectedShortcutName, actualShortcutName);
menuItem.dragToWorkspace(false, false); menuItem.dragToWorkspace(false, false);
mLauncher.getWorkspace().getWorkspaceAppIcon(expectedShortcutName) mLauncher.getWorkspace().getWorkspaceAppIcon(expectedShortcutName)
.launch(getAppPackageName()); .launch(getAppPackageName());