From de109167a25169e6fea3ddf2ebdfb86ef5e3fad4 Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Mon, 22 Jan 2024 17:12:57 +0000 Subject: [PATCH 01/10] Update dependency on Shell utils. Fix: 321724947 Flag: NA Test: both soong and gradle builds work Change-Id: Ifc29aa62f19b16da668ed8129cd2a408c65e52f0 --- .../com/android/quickstep/util/FadeOutRemoteTransition.kt | 5 ++--- .../com/android/quickstep/util/SlideInRemoteTransition.kt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/FadeOutRemoteTransition.kt b/quickstep/src/com/android/quickstep/util/FadeOutRemoteTransition.kt index 5cce728ebf..32a15a2875 100644 --- a/quickstep/src/com/android/quickstep/util/FadeOutRemoteTransition.kt +++ b/quickstep/src/com/android/quickstep/util/FadeOutRemoteTransition.kt @@ -25,7 +25,7 @@ import android.window.IRemoteTransitionFinishedCallback import android.window.TransitionInfo import com.android.launcher3.anim.AnimatorListeners.forEndCallback import com.android.launcher3.util.Executors -import com.android.wm.shell.util.TransitionUtil +import com.android.wm.shell.shared.TransitionUtil /** Remote animation which fades out the closing targets */ class FadeOutRemoteTransition : IRemoteTransition.Stub() { @@ -84,6 +84,5 @@ class FadeOutRemoteTransition : IRemoteTransition.Stub() { Executors.MAIN_EXECUTOR.execute { anim.start() } } - override fun onTransitionConsumed(transition: IBinder?, aborted: Boolean) { - } + override fun onTransitionConsumed(transition: IBinder?, aborted: Boolean) {} } diff --git a/quickstep/src/com/android/quickstep/util/SlideInRemoteTransition.kt b/quickstep/src/com/android/quickstep/util/SlideInRemoteTransition.kt index 6544ba75ca..9f7b46d90f 100644 --- a/quickstep/src/com/android/quickstep/util/SlideInRemoteTransition.kt +++ b/quickstep/src/com/android/quickstep/util/SlideInRemoteTransition.kt @@ -28,7 +28,7 @@ import android.window.IRemoteTransitionFinishedCallback import android.window.TransitionInfo import com.android.launcher3.anim.AnimatorListeners.forEndCallback import com.android.launcher3.util.Executors -import com.android.wm.shell.util.TransitionUtil +import com.android.wm.shell.shared.TransitionUtil /** Remote animation which slides the opening targets in and the closing targets out */ class SlideInRemoteTransition( From 997d385778138e0c48d53469324dd4231d46bc37 Mon Sep 17 00:00:00 2001 From: Holly Sun Date: Thu, 25 Jan 2024 16:04:08 -0800 Subject: [PATCH 02/10] [PS] Update icon background for PS, Widget and web. PS: https://screenshot.googleplex.com/3xVtx5bPD296pUd https://screenshot.googleplex.com/B3MkSoyfkBJPRsA https://screenshot.googleplex.com/8pqs2ZsNatEvcBF https://screenshot.googleplex.com/9CK9hqHSGfc6jin Widget: https://screenshot.googleplex.com/AdcmB7ScDnxK2Hv https://screenshot.googleplex.com/9XkaghiVrx3YBLq https://screenshot.googleplex.com/7hh3xU4JTUXG4X5 https://screenshot.googleplex.com/Ao2wWAAGVF4kHpe Bug: 320562455 Test: manual Flag: aconfig com.google.android.apps.nexuslauncher.enable_inject_private_space_tile teamfood Change-Id: I46d9ae92cc21a4ba6e66be2271c584ee0e3514cd --- res/drawable/ic_encrypted_with_background.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/drawable/ic_encrypted_with_background.xml b/res/drawable/ic_encrypted_with_background.xml index 155e2be1c6..c439b5580d 100644 --- a/res/drawable/ic_encrypted_with_background.xml +++ b/res/drawable/ic_encrypted_with_background.xml @@ -19,7 +19,7 @@ android:height="48dp"> + android:fillColor="?attr/materialColorOutlineVariant" /> From c48c660bb5cfaef4fa074a94d2e68e8166b76d27 Mon Sep 17 00:00:00 2001 From: Shamali P Date: Thu, 25 Jan 2024 14:35:32 +0000 Subject: [PATCH 03/10] Add a feature flag for displaying categorized widget recommendations. Bug: 318410881 Test: NONE Flag: ACONFIG com.android.launcher3.enable_categorized_widget_suggestions DEVELOPMENT Change-Id: I6f8a0cc8f74823f1a29cef1b5f8ac0a3e9411609 --- aconfig/launcher.aconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index defb0e66cb..7032d5f7e7 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -140,3 +140,10 @@ flag { description: "Tie unfold animation with state animation" bug: "297057373" } + +flag { + name: "enable_categorized_widget_suggestions" + namespace: "launcher" + description: "Enables widget suggestions in widget picker to be displayed in categories" + bug: "318410881" +} From 2f609d09f6cc6221b8261564292e50728462f6a0 Mon Sep 17 00:00:00 2001 From: Jakob Schneider Date: Wed, 10 Jan 2024 18:03:35 +0000 Subject: [PATCH 04/10] Initialize the archiving compat options during launcher3 startup. This just sets an OP_CODE (cheap operation). It disables a help-dialog for launchers who have not implemented archiving. Test: PackageInstallerArchiveTest and also manually Bug: 302114748 Flag: ACONFIG com.android.launcher3.enable_support_for_archiving DEVELOPMENT Change-Id: Ifa9335d7ad250218eec3863dcdd986118bba007c --- src/com/android/launcher3/LauncherAppState.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index e015021136..1b2cebd34e 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -89,6 +89,7 @@ public class LauncherAppState implements SafeCloseable { return mContext; } + @SuppressWarnings("NewApi") public LauncherAppState(Context context) { this(context, LauncherFiles.APP_ICONS_DB); Log.v(Launcher.TAG, "LauncherAppState initiated"); @@ -103,9 +104,14 @@ public class LauncherAppState implements SafeCloseable { }); ModelLauncherCallbacks callbacks = mModel.newModelCallbacks(); - mContext.getSystemService(LauncherApps.class).registerCallback(callbacks); + LauncherApps launcherApps = mContext.getSystemService(LauncherApps.class); + launcherApps.registerCallback(callbacks); mOnTerminateCallback.add(() -> mContext.getSystemService(LauncherApps.class).unregisterCallback(callbacks)); + if (Flags.enableSupportForArchiving()) { + launcherApps.setArchiveCompatibilityOptions(/* enableIconOverlay= */ true, + /* enableUnarchivalConfirmation= */ false); + } SimpleBroadcastReceiver modelChangeReceiver = new SimpleBroadcastReceiver(mModel::onBroadcastIntent); From 419140aede56733c75c1e4fe22f49a3e6dc0d13a Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 30 Jan 2024 11:16:13 -0800 Subject: [PATCH 05/10] Make sure touch only goes to the nearest button when it makes sense - In NearestTouchFrame, we can't use view bounds alone since the buttons do not have the same root (3 buttons are in the main container, while the contextual buttons are in the contextual button container). This currently caused the issue that contextual button region, when the contextual buttons are invisible, triggers overview - Need to add an empty space in the left / top area of the button nav to prevent view clicks from going into back (that's how it works in navigationbar/) Bug: 25768138 Test: left and right of 3 buttons don't trigger back or overview Change-Id: Idc26c0c8ac0ecc000300a6db2e3e6251f678dada --- .../taskbar/NavbarButtonsViewController.java | 10 +++++++- .../taskbar/TaskbarNavButtonController.java | 7 ++++++ .../navbutton/AbstractNavButtonLayoutter.kt | 4 +++- .../taskbar/navbutton/KidsNavLayoutter.kt | 7 ++++-- .../navbutton/NavButtonLayoutFactory.kt | 23 +++++++++++++------ .../taskbar/navbutton/NearestTouchFrame.java | 18 +++++++++++---- .../navbutton/PhoneGestureLayoutter.kt | 7 ++++-- .../navbutton/PhoneLandscapeNavLayoutter.kt | 14 +++++++---- .../navbutton/PhonePortraitNavLayoutter.kt | 9 +++++++- .../navbutton/PhoneSeascapeNavLayoutter.kt | 11 +++++++-- .../taskbar/navbutton/SetupNavLayoutter.kt | 7 ++++-- .../taskbar/navbutton/TaskbarNavLayoutter.kt | 7 ++++-- .../navbutton/NavButtonLayoutFactoryTest.kt | 5 +++- res/values/id.xml | 1 + 14 files changed, 101 insertions(+), 29 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java index 1a1c64dd7d..9b8ab33a91 100644 --- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java @@ -30,6 +30,7 @@ import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BA import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME; import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_IME_SWITCH; import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_RECENTS; +import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_SPACE; import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_KEYGUARD; import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_SMALL_SCREEN; import static com.android.launcher3.util.FlagDebugUtils.appendFlag; @@ -79,6 +80,7 @@ import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.Space; import androidx.annotation.Nullable; @@ -207,6 +209,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT this::onComputeInsetsForSeparateWindow; private final RecentsHitboxExtender mHitboxExtender = new RecentsHitboxExtender(); private ImageView mRecentsButton; + private Space mSpace; public NavbarButtonsViewController(TaskbarActivityContext context, @Nullable Context navigationBarPanelContext, NearestTouchFrame navButtonsView) { @@ -432,6 +435,11 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT mPropertyHolders.add(new StatePropertyHolder(mA11yButton, flags -> (flags & FLAG_A11Y_VISIBLE) != 0 && (flags & FLAG_ROTATION_BUTTON_VISIBLE) == 0)); + + mSpace = new Space(mNavButtonsView.getContext()); + mSpace.setOnClickListener(view -> navButtonController.onButtonClick(BUTTON_SPACE, view)); + mSpace.setOnLongClickListener(view -> + navButtonController.onButtonLongClick(BUTTON_SPACE, view)); } private void parseSystemUiFlags(int sysUiStateFlags) { @@ -760,7 +768,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT NavButtonLayoutFactory.Companion.getUiLayoutter( dp, mNavButtonsView, mImeSwitcherButton, mControllers.rotationButtonController.getRotationButton(), - mA11yButton, res, isInKidsMode, isInSetup, isThreeButtonNav, + mA11yButton, mSpace, res, isInKidsMode, isInSetup, isThreeButtonNav, mContext.isPhoneMode(), mWindowManagerProxy.getRotation(mContext)); navButtonLayoutter.layoutButtons(mContext, isA11yButtonPersistent()); updateButtonsBackground(); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java index 3f72e5d9d3..19293b59ee 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarNavButtonController.java @@ -102,6 +102,7 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa static final int BUTTON_A11Y = BUTTON_IME_SWITCH << 1; static final int BUTTON_QUICK_SETTINGS = BUTTON_A11Y << 1; static final int BUTTON_NOTIFICATIONS = BUTTON_QUICK_SETTINGS << 1; + static final int BUTTON_SPACE = BUTTON_NOTIFICATIONS << 1; private static final int SCREEN_UNPIN_COMBO = BUTTON_BACK | BUTTON_RECENTS; private int mLongPressedButtons = 0; @@ -123,6 +124,9 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa } public void onButtonClick(@TaskbarButton int buttonType, View view) { + if (buttonType == BUTTON_SPACE) { + return; + } // Provide the same haptic feedback that the system offers for virtual keys. view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (buttonType) { @@ -156,6 +160,9 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa } public boolean onButtonLongClick(@TaskbarButton int buttonType, View view) { + if (buttonType == BUTTON_SPACE) { + return false; + } // Provide the same haptic feedback that the system offers for virtual keys. view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (buttonType) { diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt index 23e3310e70..ac47c60283 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.Utilities import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter @@ -46,7 +47,8 @@ abstract class AbstractNavButtonLayoutter( protected val startContextualContainer: ViewGroup, protected val imeSwitcher: ImageView?, protected val rotationButton: RotationButton?, - protected val a11yButton: ImageView? + protected val a11yButton: ImageView?, + protected val space: Space ) : NavButtonLayoutter { protected val homeButton: ImageView? = navButtonContainer.findViewById(R.id.home) protected val recentsButton: ImageView? = navButtonContainer.findViewById(R.id.recent_apps) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt index f31af09ab7..26344b8c37 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt @@ -25,6 +25,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.* @@ -37,7 +38,8 @@ class KidsNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView? + a11yButton: ImageView?, + space: Space, ) : AbstractNavButtonLayoutter( resources, @@ -46,7 +48,8 @@ class KidsNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt index 672bc0d597..1d4ae7b15a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.DeviceProfile import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.* @@ -60,6 +61,7 @@ class NavButtonLayoutFactory { imeSwitcher: ImageView?, rotationButton: RotationButton?, a11yButton: ImageView?, + space: Space, resources: Resources, isKidsMode: Boolean, isInSetup: Boolean, @@ -86,7 +88,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } else if (surfaceRotation == ROTATION_90) { navButtonsView.setIsVertical(true) @@ -97,7 +100,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } else { navButtonsView.setIsVertical(true) @@ -108,7 +112,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } } @@ -120,7 +125,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } deviceProfile.isTaskbarPresent -> { @@ -133,7 +139,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } isKidsMode -> { @@ -144,7 +151,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } else -> @@ -155,7 +163,8 @@ class NavButtonLayoutFactory { startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) } } diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/NearestTouchFrame.java b/quickstep/src/com/android/launcher3/taskbar/navbutton/NearestTouchFrame.java index a477303c25..bbf08bf903 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/NearestTouchFrame.java +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/NearestTouchFrame.java @@ -27,6 +27,7 @@ import android.widget.FrameLayout; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -42,7 +43,10 @@ public class NearestTouchFrame extends FrameLayout { private final List mClickableChildren = new ArrayList<>(); private final List mAttachedChildren = new ArrayList<>(); private final boolean mIsActive; + private final int[] mTmpInt = new int[2]; + // Offset (as the base) to translate window cords to view cords. + private final int[] mWindowOffset = new int[2]; private boolean mIsVertical; private View mTouchingChild; private final Map mTouchableRegions = new HashMap<>(); @@ -52,8 +56,11 @@ public class NearestTouchFrame extends FrameLayout { */ private final Comparator mChildRegionComparator = (view1, view2) -> { - int startingCoordView1 = mIsVertical ? view1.getTop() : view1.getLeft(); - int startingCoordView2 = mIsVertical ? view2.getTop() : view2.getLeft(); + int leftTopIndex = mIsVertical ? 1 : 0; + view1.getLocationInWindow(mTmpInt); + int startingCoordView1 = mTmpInt[leftTopIndex] - mWindowOffset[leftTopIndex]; + view2.getLocationInWindow(mTmpInt); + int startingCoordView2 = mTmpInt[leftTopIndex] - mWindowOffset[leftTopIndex]; return startingCoordView1 - startingCoordView2; }; @@ -74,6 +81,7 @@ public class NearestTouchFrame extends FrameLayout { mAttachedChildren.clear(); mTouchableRegions.clear(); addClickableChildren(this); + getLocationInWindow(mWindowOffset); cacheClosestChildLocations(); } @@ -147,8 +155,9 @@ public class NearestTouchFrame extends FrameLayout { } private Rect getChildsBounds(View child) { - int left = child.getLeft(); - int top = child.getTop(); + child.getLocationInWindow(mTmpInt); + int left = mTmpInt[0] - mWindowOffset[0]; + int top = mTmpInt[1] - mWindowOffset[1]; int right = left + child.getWidth(); int bottom = top + child.getHeight(); return new Rect(left, top, right, bottom); @@ -194,6 +203,7 @@ public class NearestTouchFrame extends FrameLayout { public void dumpLogs(String prefix, PrintWriter pw) { pw.println(prefix + "NearestTouchFrame:"); + pw.println(String.format("%s\tmWindowOffset=%s", prefix, Arrays.toString(mWindowOffset))); pw.println(String.format("%s\tmIsVertical=%s", prefix, mIsVertical)); pw.println(String.format("%s\tmTouchingChild=%s", prefix, mTouchingChild)); pw.println(String.format("%s\tmTouchableRegions=%s", prefix, diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt index 3817f91ec1..6d86f1b63b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt @@ -20,6 +20,7 @@ import android.content.res.Resources import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.systemui.shared.rotation.RotationButton @@ -31,7 +32,8 @@ class PhoneGestureLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView? + a11yButton: ImageView?, + space: Space, ) : AbstractNavButtonLayoutter( resources, @@ -40,7 +42,8 @@ class PhoneGestureLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt index b1b50d6d7f..9314f81ac4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt @@ -19,9 +19,11 @@ package com.android.launcher3.taskbar.navbutton import android.content.res.Resources import android.view.Gravity import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.systemui.shared.rotation.RotationButton @@ -34,6 +36,7 @@ open class PhoneLandscapeNavLayoutter( imeSwitcher: ImageView?, rotationButton: RotationButton?, a11yButton: ImageView?, + space: Space, ) : AbstractNavButtonLayoutter( resources, @@ -42,7 +45,8 @@ open class PhoneLandscapeNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { @@ -60,7 +64,7 @@ open class PhoneLandscapeNavLayoutter( val navButtonContainerHeight = contentWidth - contextualButtonHeight * 2 val navContainerParams = FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, navButtonContainerHeight.toInt()) + MATCH_PARENT, navButtonContainerHeight.toInt()) navContainerParams.apply { topMargin = (contextualButtonHeight + contentPadding + roundedCornerContentMargin).toInt() @@ -125,6 +129,8 @@ open class PhoneLandscapeNavLayoutter( val contentPadding = resources.getDimensionPixelSize(R.dimen.taskbar_phone_content_padding) repositionContextualContainer(startContextualContainer, buttonSize, roundedCornerContentMargin + contentPadding, 0, Gravity.TOP) + repositionContextualContainer(endContextualContainer, buttonSize, + 0, roundedCornerContentMargin + contentPadding, Gravity.BOTTOM) if (imeSwitcher != null) { startContextualContainer.addView(imeSwitcher) @@ -137,13 +143,13 @@ open class PhoneLandscapeNavLayoutter( startContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() } + endContextualContainer.addView(space, MATCH_PARENT, MATCH_PARENT) } override fun repositionContextualContainer(contextualContainer: ViewGroup, buttonSize: Int, barAxisMarginTop: Int, barAxisMarginBottom: Int, gravity: Int) { - val contextualContainerParams = FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, buttonSize) + val contextualContainerParams = FrameLayout.LayoutParams(MATCH_PARENT, buttonSize) contextualContainerParams.apply { marginStart = 0 marginEnd = 0 diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt index 05183b8411..13e085a887 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt @@ -19,9 +19,11 @@ package com.android.launcher3.taskbar.navbutton import android.content.res.Resources import android.view.Gravity import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.systemui.shared.rotation.RotationButton @@ -34,6 +36,7 @@ class PhonePortraitNavLayoutter( imeSwitcher: ImageView?, rotationButton: RotationButton?, a11yButton: ImageView?, + space: Space ) : AbstractNavButtonLayoutter( resources, @@ -42,7 +45,8 @@ class PhonePortraitNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { @@ -110,9 +114,12 @@ class PhonePortraitNavLayoutter( endContextualContainer.removeAllViews() startContextualContainer.removeAllViews() + repositionContextualContainer(startContextualContainer, contextualButtonWidth.toInt(), + roundedCornerContentMargin + contentPadding, 0, Gravity.START) repositionContextualContainer(endContextualContainer, contextualButtonWidth.toInt(), 0, roundedCornerContentMargin + contentPadding, Gravity.END) + startContextualContainer.addView(space, MATCH_PARENT, MATCH_PARENT) if (imeSwitcher != null) { endContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt index 0f52552c8b..a21f5ce4b3 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt @@ -19,8 +19,10 @@ package com.android.launcher3.taskbar.navbutton import android.content.res.Resources import android.view.Gravity import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.systemui.shared.rotation.RotationButton @@ -31,7 +33,8 @@ class PhoneSeascapeNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView? + a11yButton: ImageView?, + space: Space, ) : PhoneLandscapeNavLayoutter( resources, @@ -40,7 +43,8 @@ class PhoneSeascapeNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun addThreeButtons() { @@ -57,9 +61,12 @@ class PhoneSeascapeNavLayoutter( val roundedCornerContentMargin = resources.getDimensionPixelSize( R.dimen.taskbar_phone_rounded_corner_content_margin) val contentPadding = resources.getDimensionPixelSize(R.dimen.taskbar_phone_content_padding) + repositionContextualContainer(startContextualContainer, buttonSize, + roundedCornerContentMargin + contentPadding, 0, Gravity.TOP) repositionContextualContainer(endContextualContainer, buttonSize, 0, roundedCornerContentMargin + contentPadding, Gravity.BOTTOM) + startContextualContainer.addView(space, MATCH_PARENT, MATCH_PARENT) if (imeSwitcher != null) { endContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt index 5111bba53d..6eb7b93dc4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.systemui.shared.rotation.RotationButton @@ -34,7 +35,8 @@ class SetupNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView? + a11yButton: ImageView?, + space: Space, ) : AbstractNavButtonLayoutter( resources, @@ -43,7 +45,8 @@ class SetupNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt index 45dbebbbdb..89c67b9947 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import com.android.launcher3.R import com.android.launcher3.taskbar.TaskbarActivityContext import com.android.systemui.shared.rotation.RotationButton @@ -37,7 +38,8 @@ class TaskbarNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView? + a11yButton: ImageView?, + space: Space ) : AbstractNavButtonLayoutter( resources, @@ -46,7 +48,8 @@ class TaskbarNavLayoutter( startContextualContainer, imeSwitcher, rotationButton, - a11yButton + a11yButton, + space ) { override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { diff --git a/quickstep/tests/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactoryTest.kt b/quickstep/tests/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactoryTest.kt index 9c7fdc6707..87cbdd1b94 100644 --- a/quickstep/tests/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactoryTest.kt +++ b/quickstep/tests/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactoryTest.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout +import android.widget.Space import androidx.test.runner.AndroidJUnit4 import com.android.launcher3.DeviceProfile import com.android.launcher3.R @@ -38,6 +39,7 @@ class NavButtonLayoutFactoryTest { private val mockImeSwitcher: ImageView = mock() private val mockRotationButton: RotationButton = mock() private val mockA11yButton: ImageView = mock() + private val mockSpace: Space = mock() private var surfaceRotation = Surface.ROTATION_0 @@ -201,7 +203,8 @@ class NavButtonLayoutFactoryTest { surfaceRotation = surfaceRotation, imeSwitcher = mockImeSwitcher, rotationButton = mockRotationButton, - a11yButton = mockA11yButton + a11yButton = mockA11yButton, + space = mockSpace, ) } } diff --git a/res/values/id.xml b/res/values/id.xml index 6156c91888..198496f741 100644 --- a/res/values/id.xml +++ b/res/values/id.xml @@ -32,6 +32,7 @@ + From c5fbb42dcbc200b808846a0edb1fdb6418623e9e Mon Sep 17 00:00:00 2001 From: Shamali P Date: Wed, 24 Jan 2024 16:09:34 +0000 Subject: [PATCH 06/10] Add a default widget category provider that uses application category. The category provider can be customized by any launcher via resource override. For instance, one can override it to provide custom categories using an allowlist or use a different mechanism such as query play services. We still need to get proper strings for categories from UX writer. Bug: 318410881 Test: WidgetRecommendationCategoryProviderTest Flag: ACONFIG com.android.launcher3.enable_categorized_widget_recommendations DEVELOPMENT Change-Id: I5c4e0d22eaffc8254ddd54356f8c62f00e22a3c4 --- res/values/config.xml | 8 + res/values/strings.xml | 6 + .../picker/WidgetRecommendationCategory.java | 62 +++++++ .../WidgetRecommendationCategoryProvider.java | 126 ++++++++++++++ ...getRecommendationCategoryProviderTest.java | 156 ++++++++++++++++++ 5 files changed, 358 insertions(+) create mode 100644 src/com/android/launcher3/widget/picker/WidgetRecommendationCategory.java create mode 100644 src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java create mode 100644 tests/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProviderTest.java diff --git a/res/values/config.xml b/res/values/config.xml index 5bdd7ebb36..29c4e663fb 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -194,6 +194,11 @@ + + + + + @@ -252,6 +257,9 @@ + + + 0.5 720 diff --git a/res/values/strings.xml b/res/values/strings.xml index b9fb0242c7..5cc4616db9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -71,6 +71,12 @@ Suggestions + Boost your day + News For You + Your Chill Zone + Reach Your Fitness Goals + Stay Ahead of the Weather + You Might Also Like diff --git a/src/com/android/launcher3/widget/picker/WidgetRecommendationCategory.java b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategory.java new file mode 100644 index 0000000000..072d1d5948 --- /dev/null +++ b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategory.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.widget.picker; + +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; + +import java.util.Objects; + +/** + * A category of widget recommendations displayed in the widget picker (launched from "Widgets" + * option in the pop-up opened on long press of launcher workspace). + */ +public class WidgetRecommendationCategory implements Comparable { + /** Resource id that holds the user friendly label for the category. */ + @StringRes + public final int categoryTitleRes; + /** + * Relative order of this category with respect to other categories. + * + *

Category with lowest order is displayed first in the recommendations section.

+ */ + public final int order; + + public WidgetRecommendationCategory(@StringRes int categoryTitleRes, int order) { + this.categoryTitleRes = categoryTitleRes; + this.order = order; + } + + @Override + public int hashCode() { + return Objects.hash(categoryTitleRes, order); + } + + @Override + public boolean equals(@Nullable Object obj) { + if (!(obj instanceof WidgetRecommendationCategory category)) { + return false; + } + return categoryTitleRes == category.categoryTitleRes + && order == category.order; + } + + @Override + public int compareTo(WidgetRecommendationCategory widgetRecommendationCategory) { + return order - widgetRecommendationCategory.order; + } +} diff --git a/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java new file mode 100644 index 0000000000..d99c5d1e6d --- /dev/null +++ b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.widget.picker; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.util.Log; + +import androidx.annotation.WorkerThread; + +import com.android.launcher3.R; +import com.android.launcher3.model.WidgetItem; +import com.android.launcher3.util.Preconditions; +import com.android.launcher3.util.ResourceBasedOverride; + +/** + * A {@link ResourceBasedOverride} that categorizes widget recommendations. + * + *

Override the {@code widget_recommendation_category_provider_class} resource to provide your + * own implementation. Method {@code getWidgetRecommendationCategory} is called per widget to get + * the category.

+ */ +public class WidgetRecommendationCategoryProvider implements ResourceBasedOverride { + private static final String TAG = "WidgetRecommendationCategoryProvider"; + + /** + * Retrieve instance of this object that can be overridden in runtime based on the build + * variant of the application. + */ + public static WidgetRecommendationCategoryProvider newInstance(Context context) { + Preconditions.assertWorkerThread(); + return Overrides.getObject( + WidgetRecommendationCategoryProvider.class, context.getApplicationContext(), + R.string.widget_recommendation_category_provider_class); + } + + /** + * Returns a {@link WidgetRecommendationCategory} for the provided widget item that can be used + * to display the recommendation grouped by categories. + */ + @WorkerThread + public WidgetRecommendationCategory getWidgetRecommendationCategory(Context context, + WidgetItem item) { + // This is a default implementation that uses application category to derive the category to + // be displayed. The implementation can be overridden in individual launcher customization + // via the overridden WidgetRecommendationCategoryProvider resource. + + Preconditions.assertWorkerThread(); + PackageManager pm = context.getPackageManager(); + if (item.widgetInfo != null && item.widgetInfo.getComponent() != null) { + String widgetComponentName = item.widgetInfo.getComponent().getClassName(); + try { + int predictionCategory = pm.getApplicationInfo( + item.widgetInfo.getComponent().getPackageName(), 0 /* flags */).category; + return getCategoryFromApplicationCategory(context, predictionCategory, + widgetComponentName); + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Failed to retrieve application category when determining the " + + "widget category for " + widgetComponentName, e); + } + } + return null; + } + + /** Maps application category to an appropriate displayable category. */ + private static WidgetRecommendationCategory getCategoryFromApplicationCategory( + Context context, int applicationCategory, String componentName) { + if (applicationCategory == ApplicationInfo.CATEGORY_PRODUCTIVITY) { + return new WidgetRecommendationCategory( + R.string.productivity_widget_recommendation_category_label, /*order=*/0); + } + + if (applicationCategory == ApplicationInfo.CATEGORY_NEWS) { + return new WidgetRecommendationCategory( + R.string.news_widget_recommendation_category_label, /*order=*/1); + } + + if (applicationCategory == ApplicationInfo.CATEGORY_SOCIAL + || applicationCategory == ApplicationInfo.CATEGORY_AUDIO + || applicationCategory == ApplicationInfo.CATEGORY_VIDEO + || applicationCategory == ApplicationInfo.CATEGORY_IMAGE) { + return new WidgetRecommendationCategory( + R.string.social_and_entertainment_widget_recommendation_category_label, + /*order=*/4); + } + + // Fitness & weather categories don't map to a specific application category, so, we + // maintain an allowlist. + String[] weatherRecommendationAllowlist = + context.getResources().getStringArray(R.array.weather_recommendations); + for (String allowedWeatherComponentName : weatherRecommendationAllowlist) { + if (componentName.equalsIgnoreCase(allowedWeatherComponentName)) { + return new WidgetRecommendationCategory( + R.string.weather_widget_recommendation_category_label, /*order=*/2); + } + } + + String[] fitnessRecommendationAllowlist = + context.getResources().getStringArray(R.array.fitness_recommendations); + for (String allowedFitnessComponentName : fitnessRecommendationAllowlist) { + if (componentName.equalsIgnoreCase(allowedFitnessComponentName)) { + return new WidgetRecommendationCategory( + R.string.fitness_widget_recommendation_category_label, /*order=*/3); + } + } + + return new WidgetRecommendationCategory( + R.string.others_widget_recommendation_category_label, /*order=*/5); + } + +} diff --git a/tests/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProviderTest.java b/tests/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProviderTest.java new file mode 100644 index 0000000000..c807771c59 --- /dev/null +++ b/tests/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProviderTest.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.widget.picker; + +import static android.content.pm.ApplicationInfo.CATEGORY_AUDIO; +import static android.content.pm.ApplicationInfo.CATEGORY_IMAGE; +import static android.content.pm.ApplicationInfo.CATEGORY_NEWS; +import static android.content.pm.ApplicationInfo.CATEGORY_PRODUCTIVITY; +import static android.content.pm.ApplicationInfo.CATEGORY_SOCIAL; +import static android.content.pm.ApplicationInfo.CATEGORY_UNDEFINED; +import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO; + +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; + +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProviderInfo; +import android.content.ComponentName; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Process; + +import androidx.test.core.content.pm.ApplicationInfoBuilder; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.SmallTest; + +import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.R; +import com.android.launcher3.icons.IconCache; +import com.android.launcher3.model.WidgetItem; +import com.android.launcher3.util.Executors; +import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; + +import com.google.common.collect.ImmutableMap; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.Map; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class WidgetRecommendationCategoryProviderTest { + private static final String TEST_PACKAGE = "com.foo.test"; + private static final String TEST_APP_NAME = "foo"; + public static final WidgetRecommendationCategory SOCIAL_AND_ENTERTAINMENT_CATEGORY = + new WidgetRecommendationCategory( + R.string.social_and_entertainment_widget_recommendation_category_label, + /*order=*/4); + private final ApplicationInfo mTestAppInfo = ApplicationInfoBuilder.newBuilder().setPackageName( + TEST_PACKAGE).setName(TEST_APP_NAME).build(); + private Context mContext; + @Mock + private IconCache mIconCache; + + private WidgetItem mTestWidgetItem; + @Mock + private PackageManager mPackageManager; + private InvariantDeviceProfile mTestProfile; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = new ContextWrapper(getInstrumentation().getTargetContext()) { + @Override + public PackageManager getPackageManager() { + return mPackageManager; + } + }; + mTestProfile = new InvariantDeviceProfile(); + mTestProfile.numRows = 5; + mTestProfile.numColumns = 5; + createTestWidgetItem(); + } + + @Test + public void getWidgetRecommendationCategory_returnsMappedCategory() throws Exception { + ImmutableMap testCategories = ImmutableMap.of( + CATEGORY_PRODUCTIVITY, new WidgetRecommendationCategory( + R.string.productivity_widget_recommendation_category_label, + /*order=*/ + 0), + CATEGORY_NEWS, new WidgetRecommendationCategory( + R.string.news_widget_recommendation_category_label, /*order=*/1), + CATEGORY_SOCIAL, SOCIAL_AND_ENTERTAINMENT_CATEGORY, + CATEGORY_AUDIO, SOCIAL_AND_ENTERTAINMENT_CATEGORY, + CATEGORY_IMAGE, SOCIAL_AND_ENTERTAINMENT_CATEGORY, + CATEGORY_VIDEO, SOCIAL_AND_ENTERTAINMENT_CATEGORY, + CATEGORY_UNDEFINED, new WidgetRecommendationCategory( + R.string.others_widget_recommendation_category_label, /*order=*/5)); + + for (Map.Entry testCategory : + testCategories.entrySet()) { + + mTestAppInfo.category = testCategory.getKey(); + when(mPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( + mTestAppInfo); + + WidgetRecommendationCategory category = Executors.MODEL_EXECUTOR.submit(() -> + new WidgetRecommendationCategoryProvider().getWidgetRecommendationCategory( + mContext, + mTestWidgetItem)).get(); + + assertThat(category).isEqualTo(testCategory.getValue()); + } + } + + private void createTestWidgetItem() { + String widgetLabel = "Foo Widget"; + String widgetClassName = ".mWidget"; + + doAnswer(invocation -> widgetLabel).when(mIconCache).getTitleNoCache(any()); + + AppWidgetProviderInfo providerInfo = AppWidgetManager.getInstance(getApplicationContext()) + .getInstalledProvidersForPackage( + getInstrumentation().getContext().getPackageName(), Process.myUserHandle()) + .get(0); + providerInfo.provider = ComponentName.createRelative(TEST_PACKAGE, widgetClassName); + + LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo = + LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, providerInfo); + launcherAppWidgetProviderInfo.spanX = 2; + launcherAppWidgetProviderInfo.spanY = 2; + launcherAppWidgetProviderInfo.label = widgetLabel; + mTestWidgetItem = new WidgetItem(launcherAppWidgetProviderInfo, mTestProfile, mIconCache, + mContext + ); + } +} From 45ef544ae5a3aa2b8c81151b5e8257f9f17ec302 Mon Sep 17 00:00:00 2001 From: Anushree Ganjam Date: Fri, 26 Jan 2024 14:08:07 -0800 Subject: [PATCH 07/10] [PS] Show "Uninstall" in Long Press menu for Private Space apps. Video : https://b.corp.google.com/issues/319250810#comment18 - Add SecondaryDropTarget.performUninstall() - Make SecondaryDropTarget.getUninstallTarget() public static. Test: Manual Flag: aconfig com.android.launcher3.enable_private_space TEAMFOOD Bug: 319250810 Change-Id: If6488033a976914fdc0a50658fc0561dc1a6586a --- .../uioverrides/QuickstepLauncher.java | 4 ++ .../launcher3/SecondaryDropTarget.java | 44 ++++++++----- .../launcher3/logging/StatsLogManager.java | 5 +- .../launcher3/popup/SystemShortcut.java | 63 ++++++++++++++++--- 4 files changed, 92 insertions(+), 24 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 9b73bb10a3..4f2275218c 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -43,6 +43,7 @@ import static com.android.launcher3.popup.SystemShortcut.APP_INFO; import static com.android.launcher3.popup.SystemShortcut.DONT_SUGGEST_APP; import static com.android.launcher3.popup.SystemShortcut.INSTALL; import static com.android.launcher3.popup.SystemShortcut.PRIVATE_PROFILE_INSTALL; +import static com.android.launcher3.popup.SystemShortcut.UNINSTALL_APP; import static com.android.launcher3.popup.SystemShortcut.WIDGETS; import static com.android.launcher3.taskbar.LauncherTaskbarUIController.ALL_APPS_PAGE_PROGRESS_INDEX; import static com.android.launcher3.taskbar.LauncherTaskbarUIController.MINUS_ONE_PAGE_PROGRESS_INDEX; @@ -437,6 +438,9 @@ public class QuickstepLauncher extends Launcher { if (Flags.enableShortcutDontSuggestApp()) { shortcuts.add(DONT_SUGGEST_APP); } + if (Flags.enablePrivateSpace()) { + shortcuts.add(UNINSTALL_APP); + } return shortcuts.stream(); } diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java index 0b92c285fb..1362586c9e 100644 --- a/src/com/android/launcher3/SecondaryDropTarget.java +++ b/src/com/android/launcher3/SecondaryDropTarget.java @@ -34,6 +34,8 @@ import android.util.Log; import android.view.View; import android.widget.Toast; +import androidx.annotation.Nullable; + import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.logging.FileLog; @@ -43,6 +45,7 @@ import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.logging.StatsLogManager.StatsLogger; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; +import com.android.launcher3.pm.UserCache; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; @@ -176,6 +179,10 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList if (uninstallDisabled) { return INVALID; } + if (Flags.enablePrivateSpace() && UserCache.getInstance(getContext()).getUserInfo( + info.user).isPrivate()) { + return INVALID; + } if (info instanceof ItemInfoWithIcon) { ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info; @@ -184,7 +191,7 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList return INVALID; } } - if (getUninstallTarget(info) == null) { + if (getUninstallTarget(getContext(), info) == null) { return INVALID; } return UNINSTALL; @@ -193,7 +200,7 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList /** * @return the component name that should be uninstalled or null. */ - private ComponentName getUninstallTarget(ItemInfo item) { + public static ComponentName getUninstallTarget(Context context, ItemInfo item) { Intent intent = null; UserHandle user = null; if (item != null && @@ -202,7 +209,7 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList user = item.user; } if (intent != null) { - LauncherActivityInfo info = getContext().getSystemService(LauncherApps.class) + LauncherActivityInfo info = context.getSystemService(LauncherApps.class) .resolveActivity(intent, user); if (info != null && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) { @@ -280,32 +287,41 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList if (FeatureFlags.ENABLE_DISMISS_PREDICTION_UNDO.get()) { CharSequence announcement = getContext().getString(R.string.item_removed); mDropTargetHandler - .dismissPrediction(announcement, () -> {}, () -> { - mStatsLogManager.logger() - .withInstanceId(instanceId) - .withItemInfo(info) - .log(LAUNCHER_DISMISS_PREDICTION_UNDO); - }); + .dismissPrediction(announcement, () -> { + }, () -> { + mStatsLogManager.logger() + .withInstanceId(instanceId) + .withItemInfo(info) + .log(LAUNCHER_DISMISS_PREDICTION_UNDO); + }); } return null; } - ComponentName cn = getUninstallTarget(info); + return performUninstall(getContext(), getUninstallTarget(getContext(), info), info); + } + + /** + * Performs uninstall and returns the target component for the {@link ItemInfo} or null if + * the uninstall was not performed. + */ + public static ComponentName performUninstall(Context context, @Nullable ComponentName cn, + ItemInfo info) { if (cn == null) { // System applications cannot be installed. For now, show a toast explaining that. // We may give them the option of disabling apps this way. Toast.makeText( - getContext(), + context, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT - ).show(); + ).show(); return null; } try { - Intent i = Intent.parseUri(getContext().getString(R.string.delete_package_intent), 0) + Intent i = Intent.parseUri(context.getString(R.string.delete_package_intent), 0) .setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName())) .putExtra(Intent.EXTRA_USER, info.user); - getContext().startActivity(i); + context.startActivity(i); FileLog.d(TAG, "start uninstall activity " + cn.getPackageName()); return cn; } catch (URISyntaxException e) { diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java index f9b7495ece..2a0f0302e4 100644 --- a/src/com/android/launcher3/logging/StatsLogManager.java +++ b/src/com/android/launcher3/logging/StatsLogManager.java @@ -717,7 +717,10 @@ public class StatsLogManager implements ResourceBasedOverride { LAUNCHER_PRIVATE_SPACE_INSTALL_APP_BUTTON_TAP(1605), @UiEvent(doc = "User attempted to create split screen with a widget") - LAUNCHER_SPLIT_WIDGET_ATTEMPT(1604) + LAUNCHER_SPLIT_WIDGET_ATTEMPT(1604), + + @UiEvent(doc = "User tapped on private space uninstall system shortcut.") + LAUNCHER_PRIVATE_SPACE_UNINSTALL_SYSTEM_SHORTCUT_TAP(1608), // ADD MORE ; diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index 3030ed4634..fbbfea97f8 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -1,6 +1,7 @@ package com.android.launcher3.popup; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_INSTALL_SYSTEM_SHORTCUT_TAP; +import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_UNINSTALL_SYSTEM_SHORTCUT_TAP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_APP_INFO_TAP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_DONT_SUGGEST_APP_TAP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_WIDGETS_TAP; @@ -17,17 +18,21 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.R; +import com.android.launcher3.SecondaryDropTarget; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.PrivateProfileManager; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; +import com.android.launcher3.pm.UserCache; import com.android.launcher3.uioverrides.ApiWrapper; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.InstantAppResolver; @@ -301,16 +306,11 @@ public abstract class SystemShortcut extend } } - public static final Factory DONT_SUGGEST_APP = new Factory() { - @Nullable - @Override - public SystemShortcut getShortcut(Launcher activity, ItemInfo itemInfo, - View originalView) { - if (!itemInfo.isPredictedItem()) { - return null; - } - return new DontSuggestApp(activity, itemInfo, originalView); + public static final Factory DONT_SUGGEST_APP = (activity, itemInfo, originalView) -> { + if (!itemInfo.isPredictedItem()) { + return null; } + return new DontSuggestApp(activity, itemInfo, originalView); }; private static class DontSuggestApp extends SystemShortcut { @@ -329,6 +329,51 @@ public abstract class SystemShortcut extend } } + public static final Factory UNINSTALL_APP = (activity, itemInfo, originalView) -> { + if (!Flags.enablePrivateSpace()) { + return null; + } + if (!UserCache.getInstance(activity.getApplicationContext()).getUserInfo( + itemInfo.user).isPrivate()) { + // If app is not Private Space app. + return null; + } + ComponentName cn = SecondaryDropTarget.getUninstallTarget(activity.getApplicationContext(), + itemInfo); + if (cn == null) { + // If component name is null, don't show uninstall shortcut. + // System apps will have component name as null. + return null; + } + return new UninstallApp(activity, itemInfo, originalView, cn); + }; + + private static class UninstallApp extends SystemShortcut { + private static final String TAG = "UninstallApp"; + Context mContext; + @NonNull + ComponentName mComponentName; + + UninstallApp(Launcher target, ItemInfo itemInfo, View originalView, + @NonNull ComponentName cn) { + super(R.drawable.ic_uninstall_no_shadow, R.string.uninstall_drop_target_label, target, + itemInfo, originalView); + mContext = target.getApplicationContext(); + mComponentName = cn; + + } + + @Override + public void onClick(View view) { + dismissTaskMenuView(mTarget); + SecondaryDropTarget.performUninstall(mContext, mComponentName, mItemInfo); + mTarget.getStatsLogManager() + .logger() + .withItemInfo(mItemInfo) + .log(LAUNCHER_PRIVATE_SPACE_UNINSTALL_SYSTEM_SHORTCUT_TAP); + } + } + public static void dismissTaskMenuView(T activity) { AbstractFloatingView.closeOpenViews(activity, true, AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE); From 1a92257520fb6883434ed974fe08e525ee24de5b Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 30 Jan 2024 16:54:10 -0800 Subject: [PATCH 08/10] Center a11y button Bug: 25768138 Test: a11y button is centered when visible Change-Id: If9099575c12b51a90bc9e15e712cb629811d36e3 --- .../com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt | 1 + .../launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt | 1 + .../launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt | 1 + .../launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt | 1 + .../com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt | 1 + .../android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt | 1 + 6 files changed, 6 insertions(+) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt index f31af09ab7..38612ef8bb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt @@ -114,6 +114,7 @@ class KidsNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt index b1b50d6d7f..4f5695ecda 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt @@ -132,6 +132,7 @@ open class PhoneLandscapeNavLayoutter( } if (a11yButton != null) { startContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { startContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt index 05183b8411..8448d0e946 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt @@ -119,6 +119,7 @@ class PhonePortraitNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt index 0f52552c8b..26e8987d2c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt @@ -66,6 +66,7 @@ class PhoneSeascapeNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt index 5111bba53d..d3410faa91 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt @@ -72,6 +72,7 @@ class SetupNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt index 45dbebbbdb..387844bd01 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt @@ -107,6 +107,7 @@ class TaskbarNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) From 9ab4550ac31894f8f990b9746e70af430ea030f5 Mon Sep 17 00:00:00 2001 From: Rohit Goyal Date: Fri, 26 Jan 2024 02:20:56 +0530 Subject: [PATCH 09/10] UI Improvement: Fix unexpected progress bar around app icon added to Workspace after unarchival. * In case app icon is added to workspace after unarchival completes for archived app, it shows a completely filled progress bar around the icon. * This behaviour exists because the 'FLAG_ARCHIVED' flag is copied from `AppInfo` item. * This cl updates the 'FLAG_ARCHIVED' flag for 'AllApps' item once unarchival completes. Test: verified bugfix locally. Bug: 319213296 Flag: ACONFIG com.android.launcher3.enable_support_for_archiving DEVELOPMENT Change-Id: I739225707a11bc9a6aa23e81775b4e036ce81a7e --- src/com/android/launcher3/model/AllAppsList.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java index ccb89004e3..b41f01118f 100644 --- a/src/com/android/launcher3/model/AllAppsList.java +++ b/src/com/android/launcher3/model/AllAppsList.java @@ -330,12 +330,15 @@ public class AllAppsList { PackageManagerHelper.getLoadingProgress(info), PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING); applicationInfo.intent = launchIntent; - if (enableSupportForArchiving() && info.getActivityInfo().isArchived) { + if (enableSupportForArchiving()) { // In case an app is archived, the respective item flag corresponding to // archiving should also be applied during package updates - applicationInfo.runtimeStatusFlags |= FLAG_ARCHIVED; + if (info.getActivityInfo().isArchived) { + applicationInfo.runtimeStatusFlags |= FLAG_ARCHIVED; + } else { + applicationInfo.runtimeStatusFlags &= (~FLAG_ARCHIVED); + } } - mDataChanged = true; } } From e96d30bddb783f712770122b75f9d7f288d4831c Mon Sep 17 00:00:00 2001 From: Jeremy Sim Date: Wed, 31 Jan 2024 18:13:09 +0800 Subject: [PATCH 10/10] Make app pairs respond properly to disabled state 1) App pair member icons are now always redrawn when app pair icon is redrawn, allowing greyed out icons to be updated immediately when an app is disabled. 2) App pairs now check for disabled status when clicked. If one or both of the apps is disabled, app pair will not be launched, and the appropriate error message or affordance will be displayed. Fixes: 323088270 Test: Manual Flag: ACONFIG com.android.wm.shell.enable_app_pairs TEAMFOOD Change-Id: I7f2af75db0d8579d5d04583c0d3ead32714768e4 --- .../launcher3/apppairs/AppPairIconGraphic.kt | 12 ++---------- .../android/launcher3/model/data/FolderInfo.java | 9 +++++++++ .../android/launcher3/touch/ItemClickHandler.java | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt index b2497a3050..ce354b681a 100644 --- a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt +++ b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt @@ -112,7 +112,6 @@ class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: Attr appIcon2?.setBounds(0, 0, memberIconSize.toInt(), memberIconSize.toInt()) } - /** Gets this icon graphic's bounds, with respect to the parent icon's coordinate system. */ fun getIconBounds(outBounds: Rect) { outBounds.set(0, 0, backgroundSize.toInt(), backgroundSize.toInt()) @@ -138,15 +137,8 @@ class AppPairIconGraphic @JvmOverloads constructor(context: Context, attrs: Attr // Draw background appPairBackground.draw(canvas) - // Make sure icons are loaded - if ( - appIcon1 == null || - appIcon2 == null || - appIcon1 is PlaceHolderIconDrawable || - appIcon2 is PlaceHolderIconDrawable - ) { - applyIcons(parentIcon.info.contents) - } + // Make sure icons are loaded and fresh + applyIcons(parentIcon.info.contents) // Draw first icon canvas.save() diff --git a/src/com/android/launcher3/model/data/FolderInfo.java b/src/com/android/launcher3/model/data/FolderInfo.java index 5b541d045b..83ba2b3a9f 100644 --- a/src/com/android/launcher3/model/data/FolderInfo.java +++ b/src/com/android/launcher3/model/data/FolderInfo.java @@ -371,4 +371,13 @@ public class FolderInfo extends ItemInfo { } return LauncherAtom.ToState.TO_STATE_UNSPECIFIED; } + + @Override + public boolean isDisabled() { + if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR) { + return contents.stream().anyMatch((WorkspaceItemInfo::isDisabled)); + } + + return super.isDisabled(); + } } diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java index 9d50e6ac9c..f47ab90822 100644 --- a/src/com/android/launcher3/touch/ItemClickHandler.java +++ b/src/com/android/launcher3/touch/ItemClickHandler.java @@ -149,7 +149,20 @@ public class ItemClickHandler { private static void onClickAppPairIcon(View v) { Launcher launcher = Launcher.getLauncher(v.getContext()); AppPairIcon appPairIcon = (AppPairIcon) v; - launcher.launchAppPair(appPairIcon); + if (appPairIcon.getInfo().isDisabled()) { + WorkspaceItemInfo app1 = appPairIcon.getInfo().contents.get(0); + WorkspaceItemInfo app2 = appPairIcon.getInfo().contents.get(1); + // Show the user why the app pair is disabled. + if (app1.isDisabled() && !handleDisabledItemClicked(app1, launcher)) { + // If handleDisabledItemClicked() did not handle the error message, we initiate an + // app launch so Framework can tell the user why the app is suspended. + onClickAppShortcut(v, app1, launcher); + } else if (app2.isDisabled() && !handleDisabledItemClicked(app2, launcher)) { + onClickAppShortcut(v, app2, launcher); + } + } else { + launcher.launchAppPair(appPairIcon); + } } /**