From 229c4c3235b6ba162ed71ba442686d17e2160e9e Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 15 Jun 2021 12:17:13 -0700 Subject: [PATCH] App Shortcut menu bug fixes and polish. - Widget is its own item. - Change order of icon order. - Update grab handle colors Bug: 188095695 Test: long press on apps with/without widgets, long press apps on workspace/ all apps/search Change-Id: Iabb9b4b3f3a928103b9d62601f22e74ef2325d7c --- .../launcher3/BaseQuickstepLauncher.java | 4 +- .../uioverrides/QuickstepLauncher.java | 2 +- res/drawable/ic_drag_handle.xml | 2 +- res/layout/system_shortcut.xml | 2 +- res/layout/widget_shortcut_container.xml | 27 +++++++++ .../popup/PopupContainerWithArrow.java | 59 ++++++++++++++----- .../launcher3/ui/TaplTestsLauncher3.java | 4 +- .../com/android/launcher3/tapl/AppIcon.java | 10 ++++ 8 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 res/layout/widget_shortcut_container.xml diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java index 1bf36278ca..33dc6cf5bd 100644 --- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java @@ -422,8 +422,8 @@ public abstract class BaseQuickstepLauncher extends Launcher @Override public Stream getSupportedShortcuts() { - return Stream.concat(super.getSupportedShortcuts(), - Stream.of(WellbeingModel.SHORTCUT_FACTORY)); + return Stream.concat(Stream.of(WellbeingModel.SHORTCUT_FACTORY), + super.getSupportedShortcuts()); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index f0b02b3c47..ec9893c84f 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -192,7 +192,7 @@ public class QuickstepLauncher extends BaseQuickstepLauncher { @Override public Stream getSupportedShortcuts() { return Stream.concat( - super.getSupportedShortcuts(), Stream.of(mHotseatPredictionController)); + Stream.of(mHotseatPredictionController), super.getSupportedShortcuts()); } /** diff --git a/res/drawable/ic_drag_handle.xml b/res/drawable/ic_drag_handle.xml index 0181ff15d7..9db75f4a04 100644 --- a/res/drawable/ic_drag_handle.xml +++ b/res/drawable/ic_drag_handle.xml @@ -19,7 +19,7 @@ android:height="@dimen/deep_shortcut_drag_handle_size" android:viewportWidth="24.0" android:viewportHeight="24.0" - android:tint="?android:attr/textColorHint" > + android:tint="?android:attr/textColorPrimary" > + android:backgroundTint="?android:attr/textColorPrimary"/> diff --git a/res/layout/widget_shortcut_container.xml b/res/layout/widget_shortcut_container.xml new file mode 100644 index 0000000000..a4d8eb4be0 --- /dev/null +++ b/res/layout/widget_shortcut_container.xml @@ -0,0 +1,27 @@ + + + + + diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 332390d8e2..2ae12ac71f 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -96,6 +96,8 @@ public class PopupContainerWithArrow> private int mNumNotifications; private ViewGroup mNotificationContainer; + private ViewGroup mWidgetContainer; + private ViewGroup mDeepShortcutContainer; private ViewGroup mSystemShortcutContainer; @@ -234,7 +236,7 @@ public class PopupContainerWithArrow> @Override protected List getChildrenForColorExtraction() { - return Arrays.asList(mSystemShortcutContainer, mDeepShortcutContainer, + return Arrays.asList(mSystemShortcutContainer, mWidgetContainer, mDeepShortcutContainer, mNotificationContainer); } @@ -298,10 +300,24 @@ public class PopupContainerWithArrow> updateHiddenShortcuts(); if (!systemShortcuts.isEmpty()) { - mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this); for (SystemShortcut shortcut : systemShortcuts) { - initializeSystemShortcut( - R.layout.system_shortcut_icon_only, mSystemShortcutContainer, shortcut); + if (shortcut instanceof SystemShortcut.Widgets) { + if (mWidgetContainer == null) { + mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, + this); + } + initializeSystemShortcut(R.layout.system_shortcut, mWidgetContainer, + shortcut); + } + } + mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this); + + for (SystemShortcut shortcut : systemShortcuts) { + if (!(shortcut instanceof SystemShortcut.Widgets)) { + initializeSystemShortcut( + R.layout.system_shortcut_icon_only, mSystemShortcutContainer, + shortcut); + } } } } else { @@ -524,25 +540,34 @@ public class PopupContainerWithArrow> mLauncher.getPopupDataProvider().setChangeListener(null); } + private View getWidgetsView(ViewGroup container) { + for (int i = container.getChildCount() - 1; i >= 0; --i) { + View systemShortcutView = container.getChildAt(i); + if (systemShortcutView.getTag() instanceof SystemShortcut.Widgets) { + return systemShortcutView; + } + } + return null; + } + @Override public void onWidgetsBound() { ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag(); SystemShortcut widgetInfo = SystemShortcut.WIDGETS.getShortcut(mLauncher, itemInfo); - View widgetsView = null; - int count = mSystemShortcutContainer.getChildCount(); - for (int i = 0; i < count; i++) { - View systemShortcutView = mSystemShortcutContainer.getChildAt(i); - if (systemShortcutView.getTag() instanceof SystemShortcut.Widgets) { - widgetsView = systemShortcutView; - break; - } + View widgetsView = getWidgetsView(PopupContainerWithArrow.this); + if (widgetsView == null && mWidgetContainer != null) { + widgetsView = getWidgetsView(mWidgetContainer); } if (widgetInfo != null && widgetsView == null) { // We didn't have any widgets cached but now there are some, so enable the shortcut. if (mSystemShortcutContainer != PopupContainerWithArrow.this) { - initializeSystemShortcut(R.layout.system_shortcut_icon_only, - mSystemShortcutContainer, widgetInfo); + if (mWidgetContainer == null) { + mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, + PopupContainerWithArrow.this); + } + initializeSystemShortcut(R.layout.system_shortcut, mWidgetContainer, + widgetInfo); } else { // If using the expanded system shortcut (as opposed to just the icon), we need // to reopen the container to ensure measurements etc. all work out. While this @@ -554,8 +579,10 @@ public class PopupContainerWithArrow> } } else if (widgetInfo == null && widgetsView != null) { // No widgets exist, but we previously added the shortcut so remove it. - if (mSystemShortcutContainer != PopupContainerWithArrow.this) { - mSystemShortcutContainer.removeView(widgetsView); + if (mSystemShortcutContainer + != PopupContainerWithArrow.this + && mWidgetContainer != null) { + mWidgetContainer.removeView(widgetsView); } else { close(false); PopupContainerWithArrow.showForIcon(mOriginalIcon); diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 6f47df06a6..06bc26a2a2 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -293,7 +293,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { try { final AppIconMenu menu = allApps. getAppIcon(APP_NAME). - openMenu(); + openDeepShortcutMenu(); executeOnLauncher( launcher -> assertTrue("Launcher internal state didn't switch to Showing Menu", @@ -341,7 +341,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { try { final AppIconMenu menu = allApps .getAppIcon(APP_NAME) - .openMenu(); + .openDeepShortcutMenu(); final AppIconMenuItem menuItem0 = menu.getMenuItem(0); final AppIconMenuItem menuItem2 = menu.getMenuItem(2); diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 56723b18d2..57fd08ae2c 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -51,6 +51,16 @@ public final class AppIcon extends Launchable { } } + /** + * Long-clicks the icon to open its menu, and looks at the deep shortcuts container only. + */ + public AppIconMenu openDeepShortcutMenu() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + return new AppIconMenu(mLauncher, mLauncher.clickAndGet( + mObject, "deep_shortcuts_container", LONG_CLICK_EVENT)); + } + } + @Override protected void addExpectedEventsForLongClick() { mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT);