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" +} 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..7578b4c25f 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) { @@ -114,6 +117,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/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..db155425b6 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) @@ -132,18 +138,19 @@ open class PhoneLandscapeNavLayoutter( } if (a11yButton != null) { startContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { 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..3eb25a2a58 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,15 +114,19 @@ 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() } 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..899aab4201 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,15 +61,19 @@ 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() } 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..f31443cb21 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) { @@ -72,6 +75,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..69e524e113 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) { @@ -107,6 +110,7 @@ class TaskbarNavLayoutter( } if (a11yButton != null) { endContextualContainer.addView(a11yButton) + a11yButton.layoutParams = getParamsToCenterView() } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 0991fce04b..32d10b04ef 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/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( 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/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" /> 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/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 @@ + 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/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); 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/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/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/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; } } 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/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); 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); + } } /** 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 + ); + } +}