From 741dfe06833980406b4589a7ed619f26e33218a1 Mon Sep 17 00:00:00 2001 From: mpodolian Date: Tue, 27 May 2025 18:57:53 -0700 Subject: [PATCH 01/20] Moved DragZoneChangeListener logic to the shared package. Extracted logic that could be reused in the shell and Launcher to DragToBubbleController Bug: 411505605 Test: DragToBubbleControllerTest Flag: com.android.wm.shell.enable_create_any_bubble Change-Id: Ie97367f9a53acd606c8a09665a5d14e4b6bebba7 --- .../taskbar/bubbles/DragToBubbleController.kt | 87 +++++-------------- 1 file changed, 22 insertions(+), 65 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt index 2263ecfb53..c1c82584cf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt @@ -28,7 +28,9 @@ import com.android.launcher3.model.data.WorkspaceItemInfo import com.android.launcher3.taskbar.bubbles.BubbleBarLocationDropTarget.BubbleBarDropTargetController import com.android.quickstep.SystemUiProxy import com.android.wm.shell.shared.bubbles.BubbleBarLocation +import com.android.wm.shell.shared.bubbles.ContextUtils.isRtl import com.android.wm.shell.shared.bubbles.DeviceConfig +import com.android.wm.shell.shared.bubbles.DragToBubblesZoneChangeListener import com.android.wm.shell.shared.bubbles.DragZone import com.android.wm.shell.shared.bubbles.DragZoneFactory import com.android.wm.shell.shared.bubbles.DragZoneFactory.BubbleBarPropertiesProvider @@ -41,10 +43,8 @@ import com.android.wm.shell.shared.bubbles.DropTargetManager import com.android.wm.shell.shared.bubbles.DropTargetManager.DragZoneChangedListener import com.google.common.annotations.VisibleForTesting -class DragToBubbleController( - private val context: Context, - private val bubbleBarContainer: FrameLayout, -) : DragController.DragListener { +class DragToBubbleController(private val context: Context, bubbleBarContainer: FrameLayout) : + DragController.DragListener { @VisibleForTesting val dropTargetManager: DropTargetManager @@ -53,8 +53,6 @@ class DragToBubbleController( @VisibleForTesting lateinit var dragZoneFactory: DragZoneFactory private lateinit var systemUiProxy: SystemUiProxy private lateinit var bubbleBarViewController: BubbleBarViewController - private val isRtl: Boolean - get() = bubbleBarContainer.isLayoutRtl init { dropTargetManager = createDropTargetManager(bubbleBarContainer) @@ -108,79 +106,38 @@ class DragToBubbleController( private fun createDropTargetManager(bubbleBarContainer: FrameLayout): DropTargetManager { val listener: DragZoneChangedListener = - object : DragZoneChangedListener { + DragToBubblesZoneChangeListener( + context.isRtl, + object : DragToBubblesZoneChangeListener.Callback { - private var lastUpdateLocation: BubbleBarLocation? = null - private val isLocationChangedFromOriginal: Boolean - get() = - lastUpdateLocation != null && - isDifferentSides( - lastUpdateLocation, - bubbleBarViewController.bubbleBarLocation, - ) - - override fun onInitialDragZoneSet(dragZone: DragZone?) {} - - override fun onDragZoneChanged( - draggedObject: DraggedObject, - from: DragZone?, - to: DragZone?, - ) { - if (!bubbleBarViewController.hasBubbles()) { - return + override fun onDragEnteredLocation(bubbleBarLocation: BubbleBarLocation?) { + bubbleBarViewController.isShowingDropTarget = bubbleBarLocation != null } - bubbleBarViewController.isShowingDropTarget = true - val updateLocation = getBarLocation(to) - updateBubbleBarLocation(updateLocation) - lastUpdateLocation = updateLocation - } - override fun onDragEnded(zone: DragZone?) { - if (isLocationChangedFromOriginal) { - bubbleBarViewController.animateBubbleBarLocation( - bubbleBarViewController.bubbleBarLocation - ) + override fun getStartingBubbleBarLocation(): BubbleBarLocation { + return bubbleBarViewController.bubbleBarLocation + ?: BubbleBarLocation.DEFAULT } - bubbleBarViewController.isShowingDropTarget = false - } - fun updateBubbleBarLocation(updateLocation: BubbleBarLocation?) { - val updatedBefore = lastUpdateLocation != null - val originalLocation = bubbleBarViewController.bubbleBarLocation - if (updateLocation == null && isLocationChangedFromOriginal) { - bubbleBarViewController.animateBubbleBarLocation(originalLocation) - return - } - if (updatedBefore && isDifferentSides(lastUpdateLocation, updateLocation)) { - // updated before and location changed - update to new location - bubbleBarViewController.animateBubbleBarLocation(updateLocation) - return - } - if (!updatedBefore && isDifferentSides(originalLocation, updateLocation)) { - // not updated before and location changed from original - bubbleBarViewController.animateBubbleBarLocation(updateLocation) - } - } + override fun hasBubbles(): Boolean = bubbleBarViewController.hasBubbles() - fun getBarLocation(dragZone: DragZone?): BubbleBarLocation? { - return when (dragZone) { - is DragZone.Bubble.Left -> BubbleBarLocation.LEFT - is DragZone.Bubble.Right -> BubbleBarLocation.RIGHT - else -> null + override fun animateBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) { + bubbleBarViewController.animateBubbleBarLocation(bubbleBarLocation) } - } - fun isDifferentSides(f: BubbleBarLocation?, s: BubbleBarLocation?): Boolean { - return f != null && s != null && f.isOnLeft(isRtl) != s.isOnLeft(isRtl) - } - } + override fun bubbleBarPillowShownAtLocation( + bubbleBarLocation: BubbleBarLocation? + ) { + // TODO(b/411506181) adjust taskbar + } + }, + ) return DropTargetManager(context, bubbleBarContainer, listener) } private fun createDragZoneFactory( bubbleBarPropertiesProvider: BubbleBarPropertiesProvider ): DragZoneFactory { - // TODO(b/411506181) remove IPC call to display drop target in shell val splitScreenModeChecker = SplitScreenModeChecker { SplitScreenMode.NONE } val desktopWindowModeChecker = DesktopWindowModeChecker { false } val windowManager: WindowManager = context.getSystemService(WindowManager::class.java)!! From 807d4c0268deea6cf1e870808fd9a12e92f5ee39 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Mon, 26 May 2025 20:53:55 -0700 Subject: [PATCH 02/20] Open widget picker activity instead of full sheet when refactor flag is on Bug: 408283627 Flag: EXEMPT independent module Test: Manual Change-Id: I6dbd1614ae1e49e3c781d6e08199c8c17221eed7 --- src/com/android/launcher3/Launcher.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index abc18f4061..57cc6b10b5 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -165,6 +165,7 @@ import com.android.launcher3.celllayout.CellPosMapper; import com.android.launcher3.celllayout.CellPosMapper.CellPos; import com.android.launcher3.celllayout.CellPosMapper.TwoPanelCellPosMapper; import com.android.launcher3.compat.AccessibilityManagerCompat; +import com.android.launcher3.compose.ComposeFacade; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.dagger.LauncherComponentProvider; import com.android.launcher3.debug.TestEventEmitter; @@ -2872,14 +2873,19 @@ public class Launcher extends StatefulActivity // Overridden } - /** - * Opens the widget picker UI. Returns true if opened. - */ + /** Opens the widget picker UI. Returns true if opened. */ public boolean openWidgetPicker() { if (getPackageManager().isSafeMode()) { Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); return false; } else { + if (com.android.launcher3.Flags.enableWidgetPickerRefactor() && + ComposeFacade.INSTANCE.isComposeAvailable()) { + Intent intent = new Intent(Intent.ACTION_PICK); + intent.setPackage(asContext().getPackageName()); + asContext().startActivity(intent); + return true; + } openWidgetsFullSheet(); return true; } From 5293a8c9ffc6f42b8fe445525c2fe42803e79e7d Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Wed, 28 May 2025 06:14:19 -0700 Subject: [PATCH 03/20] Add widget picker module dependency to launcher when compose is enabled Bug: 408283627 Flag: EXEMPT independent module Test: Not applicable. Change-Id: I1b83fca74fefd0a43291515b7197af650236ed44 --- Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android.bp b/Android.bp index 28936b41bc..4462568e13 100644 --- a/Android.bp +++ b/Android.bp @@ -225,6 +225,7 @@ launcher_compose_java_defaults { // Compose dependencies static_libs: [ + "widget_picker_component", "androidx.compose.runtime_runtime", "androidx.compose.material3_material3", "androidx.compose.ui_ui-tooling-preview", From 8e1ac2de4410f9713be35d555d67e93f6fda2c00 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Wed, 28 May 2025 06:48:34 -0700 Subject: [PATCH 04/20] Repository and datasource implementations backing the widget picker. Bug: 408283627 Flag: EXEMPT independent module Test: Existing tests Change-Id: I0f0b68c25f416c8494f363ecc93a388570f8dfa6 --- Android.bp | 10 +- ...ConfigResourceFeaturedWidgetsDataSource.kt | 89 ++++++++ .../datasource/FeaturedWidgetsDataSource.kt | 40 ++++ .../InMemoryWidgetsSearchAlgorithm.kt | 168 +++++++++++++++ .../datasource/WidgetsSearchAlgorithm.kt | 39 ++++ .../WidgetAppIconsRepositoryImpl.kt | 79 +++++++ .../repository/WidgetUsersRepositoryImpl.kt | 125 +++++++++++ .../repository/WidgetsRepositoryImpl.kt | 198 ++++++++++++++++++ .../shared/model/PickableWidget.kt | 4 + .../ui/components/WidgetsGridTestSamples.kt | 8 + .../launcher3/widgetpicker/TestUtils.kt | 2 + res/values/config.xml | 9 + .../picker/util/WidgetPreviewContainerSize.kt | 10 + .../util/WidgetPreviewContainerSizes.kt | 60 ++++++ 14 files changed, 836 insertions(+), 5 deletions(-) create mode 100644 compose/features/com/android/launcher3/widgetpicker/datasource/ConfigResourceFeaturedWidgetsDataSource.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/datasource/FeaturedWidgetsDataSource.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/datasource/InMemoryWidgetsSearchAlgorithm.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/datasource/WidgetsSearchAlgorithm.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/repository/WidgetUsersRepositoryImpl.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/repository/WidgetsRepositoryImpl.kt diff --git a/Android.bp b/Android.bp index 4462568e13..daf87eb914 100644 --- a/Android.bp +++ b/Android.bp @@ -223,9 +223,9 @@ launcher_compose_java_defaults { ":launcher-compose-enabled-src", ], - // Compose dependencies static_libs: [ "widget_picker_component", + // Compose dependencies "androidx.compose.runtime_runtime", "androidx.compose.material3_material3", "androidx.compose.ui_ui-tooling-preview", @@ -393,9 +393,6 @@ java_library { // Library with all the dependencies for building Launcher3 android_library { name: "Launcher3ResLib", - defaults: [ - "launcher_compose_defaults", - ], srcs: [], resource_dirs: ["res"], static_libs: [ @@ -449,7 +446,10 @@ android_library { // android_app { name: "Launcher3", - defaults: ["launcher-non-platform-apis-defaults"], + defaults: [ + "launcher-non-platform-apis-defaults", + "launcher_compose_defaults", + ], static_libs: [ "Launcher3ResLib", diff --git a/compose/features/com/android/launcher3/widgetpicker/datasource/ConfigResourceFeaturedWidgetsDataSource.kt b/compose/features/com/android/launcher3/widgetpicker/datasource/ConfigResourceFeaturedWidgetsDataSource.kt new file mode 100644 index 0000000000..d361452286 --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/datasource/ConfigResourceFeaturedWidgetsDataSource.kt @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2025 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.widgetpicker.datasource + +import android.content.Context +import com.android.launcher3.InvariantDeviceProfile +import com.android.launcher3.R +import com.android.launcher3.dagger.ApplicationContext +import com.android.launcher3.dagger.LauncherAppSingleton +import com.android.launcher3.widget.picker.util.WidgetPreviewContainerSize +import com.android.launcher3.widgetpicker.shared.model.PickableWidget +import com.android.launcher3.widgetpicker.shared.model.WidgetApp +import java.util.Arrays +import java.util.stream.Collectors +import javax.inject.Inject + +/** + * An implementation of [FeaturedWidgetsDataSource] that provides featured widgets based on a static + * configuration from resources and pre-defined size templates. + */ +@LauncherAppSingleton +class ConfigResourceFeaturedWidgetsDataSource @Inject constructor( + @ApplicationContext private val appContext: Context, + private val idp: InvariantDeviceProfile +) : FeaturedWidgetsDataSource { + // the package part in component name e.g. "com.example" in {com.example/widget.Provider} + private var eligiblePackages: Set = emptySet() + + override suspend fun initialize() { + if (eligiblePackages.isEmpty()) { + eligiblePackages = Arrays.stream( + appContext.resources.getStringArray(R.array.default_featured_widget_apps) + ).collect(Collectors.toSet()) + } + } + + override suspend fun getFeaturedWidgets(widgetApps: List): List { + val widgetsByContainerSize = widgetApps + .shuffled() + // pick only one of user profiles + .distinctBy { Pair(it.id.packageName, it.id.category) } + .flatMap { it.widgets } + .filter { eligiblePackages.contains(it.id.componentName.packageName) } + .groupBy { + WidgetPreviewContainerSize( + it.sizeInfo.containerSpanX, + it.sizeInfo.containerSpanY + ) + } + + val selected: MutableList = mutableListOf() + val usedAppIds: MutableSet = mutableSetOf() + + val sizesToPick = WidgetPreviewContainerSize.pickTemplateForFeaturedWidgets( + idp.getDeviceProfile(appContext) + ) + for (sizeToPick in sizesToPick) { + widgetsByContainerSize[sizeToPick]?.shuffled()?.let { items -> + for (item in items) { + if (!usedAppIds.contains(item.appId.packageName)) { + selected.add(item) + usedAppIds.add(item.appId.packageName) + break + } + } + } + } + + return selected + } + + override fun cleanup() { + eligiblePackages = emptySet() + } +} diff --git a/compose/features/com/android/launcher3/widgetpicker/datasource/FeaturedWidgetsDataSource.kt b/compose/features/com/android/launcher3/widgetpicker/datasource/FeaturedWidgetsDataSource.kt new file mode 100644 index 0000000000..2438d9fcc7 --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/datasource/FeaturedWidgetsDataSource.kt @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 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.widgetpicker.datasource + +import com.android.launcher3.widgetpicker.shared.model.PickableWidget +import com.android.launcher3.widgetpicker.shared.model.WidgetApp + +/** + * An interface representing a datasource that provides featured widgets. + */ +interface FeaturedWidgetsDataSource { + /** + * Perform any initializations here. + */ + suspend fun initialize() + + /** + * Provides widgets from the given list that can be featured in widget picker. + */ + suspend fun getFeaturedWidgets(widgetApps: List): List + + /** + * Clear any service bindings or state here. + */ + fun cleanup() +} diff --git a/compose/features/com/android/launcher3/widgetpicker/datasource/InMemoryWidgetsSearchAlgorithm.kt b/compose/features/com/android/launcher3/widgetpicker/datasource/InMemoryWidgetsSearchAlgorithm.kt new file mode 100644 index 0000000000..16e8ca48cd --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/datasource/InMemoryWidgetsSearchAlgorithm.kt @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2025 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.widgetpicker.datasource + +import com.android.launcher3.concurrent.annotations.BackgroundContext +import com.android.launcher3.dagger.LauncherAppSingleton +import com.android.launcher3.widgetpicker.shared.model.WidgetApp +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import javax.inject.Inject +import kotlin.coroutines.CoroutineContext + +/** + * A simple in-memory implementation of [WidgetsSearchAlgorithm] that matches input query against + * the app labels, widget title and description. + * + * More weight is given to app names than widget title; and description has lowest weight in scoring + * the results. + */ +@LauncherAppSingleton +class InMemoryWidgetSearchAlgorithm @Inject constructor( + @BackgroundContext + private val backgroundContext: CoroutineContext, +) : WidgetsSearchAlgorithm { + override suspend fun initialize() {} + + override suspend fun searchWidgets( + query: String, + corpus: List + ): List = coroutineScope { + // Ideally, uses search only one word, but supporting multiple words. + val queryWords = query.trim().lowercase().split("\\s+".toRegex()) + .filter { it.isNotBlank() } + + if (queryWords.isEmpty()) { + return@coroutineScope emptyList() + } + + val results = corpus.map { widgetApp -> + async(backgroundContext) { + matchAndScoreWidgetApp(widgetApp, queryWords) + } + } + + results.awaitAll() + .filter { it.first.widgets.isNotEmpty() && it.second > 0 } + .sortedByDescending { it.second } + .map { it.first } // Return just the WidgetApp + } + + private fun matchAndScoreWidgetApp( + widgetApp: WidgetApp, + queryWords: List + ): Pair { + val appTitleScore = widgetApp.title?.let { + matchAndCalculateScore( + queryWords = queryWords, + targetText = widgetApp.title.toString(), + matchType = MatchType.APP_TITLE + ) + } ?: 0 + + val scoredWidgets = widgetApp.widgets.map { widget -> + val labelScore = + matchAndCalculateScore( + queryWords = queryWords, + targetText = widget.label, + matchType = MatchType.WIDGET_LABEL + ) + val descriptionScore = widget.description?.let { + matchAndCalculateScore( + queryWords = queryWords, + targetText = it.toString(), + matchType = MatchType.WIDGET_DESCRIPTION + ) + } ?: 0 + + val totalWidgetScore = labelScore + descriptionScore + widget to totalWidgetScore + } + .filter { it.second > 0 } + .sortedByDescending { it.second } + + val totalAppScore = appTitleScore + scoredWidgets.sumOf { it.second } + + return if (appTitleScore > 0) { + widgetApp to appTitleScore + totalAppScore + } else { + widgetApp.copy( + widgets = scoredWidgets.map { it.first } + ) to totalAppScore + } + } + + private fun matchAndCalculateScore( + queryWords: List, + targetText: String, + matchType: MatchType + ): Int { + var totalScore = 0 + val wordsInTarget = targetText + .lowercase() + .split("\\s+".toRegex()).filter { it.isNotBlank() } + + for (queryWord in queryWords) { + var wordScore = 0 + + for (targetWord in wordsInTarget) { + wordScore = wordScore.coerceAtLeast( + calculateSingleWordScore( + queryWord, + targetWord, + matchType + ) + ) + } + totalScore += wordScore + } + return totalScore + } + + private fun calculateSingleWordScore( + queryWord: String, + targetWord: String, + matchType: MatchType + ): Int { + val baseScore = when { + // exact matches are score higher. + targetWord == queryWord -> 2 + // Then the matches that begin with given input as prefix + targetWord.startsWith(queryWord) -> 1 + else -> 0 + } + + return baseScore * matchType.weightFactor + } + + private enum class MatchType(val weightFactor: Int) { + // Highest weight to app title matches; users are likely to search for apps + APP_TITLE(12), + + // Medium weight to widget labels (lower than app title as some widgets might have app title + // in name and based on number of items, might add unnecessary weight). + WIDGET_LABEL(3), + + // Lowest weight to description; description might might not be as impactful as the labels + // or app title; but, it might still help in cases where alternate words for the widgets + // functionality are used (e.g. stocks vs watchlist). + WIDGET_DESCRIPTION(1) + } + + override fun cleanup() {} +} diff --git a/compose/features/com/android/launcher3/widgetpicker/datasource/WidgetsSearchAlgorithm.kt b/compose/features/com/android/launcher3/widgetpicker/datasource/WidgetsSearchAlgorithm.kt new file mode 100644 index 0000000000..e4a98bb362 --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/datasource/WidgetsSearchAlgorithm.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 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.widgetpicker.datasource + +import com.android.launcher3.widgetpicker.shared.model.WidgetApp + +/** + * An interface representing algorithm used to search widgets for widget picker. + */ +interface WidgetsSearchAlgorithm { + /** + * Perform any initializations here + */ + suspend fun initialize() + + /** + * Returns apps and its widgets that match the given input string. + */ + suspend fun searchWidgets(query: String, corpus: List): List + + /** + * Clear any service bindings or state here. + */ + fun cleanup() +} diff --git a/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt new file mode 100644 index 0000000000..c6d013750b --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2025 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.widgetpicker.repository + +import com.android.launcher3.icons.IconCache +import com.android.launcher3.icons.cache.CacheLookupFlag +import com.android.launcher3.model.data.PackageItemInfo +import com.android.launcher3.widgetpicker.data.repository.WidgetAppIconsRepository +import com.android.launcher3.widgetpicker.shared.model.AppIcon +import com.android.launcher3.widgetpicker.shared.model.AppIconBadge +import com.android.launcher3.widgetpicker.shared.model.WidgetAppIcon +import com.android.launcher3.widgetpicker.shared.model.WidgetAppId +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.callbackFlow +import javax.inject.Inject + +/** + * An implementation of [WidgetAppIconsRepository] that provides the app icons for the widget picker + * using the [IconCache]. + */ +class WidgetAppIconsRepositoryImpl @Inject constructor( + private val iconCache: IconCache +) : WidgetAppIconsRepository { + override fun initialize() {} // nothing to do here. + + override fun getAppIcon(widgetAppId: WidgetAppId) = callbackFlow { + trySend(WidgetAppIcon(AppIcon.PlaceHolderAppIcon, AppIconBadge.NoBadge)) + + val category = widgetAppId.category + val packageItemInfo = if (category != null) { + PackageItemInfo(widgetAppId.packageName, category, widgetAppId.userHandle) + } else { + PackageItemInfo(widgetAppId.packageName, widgetAppId.userHandle) + } + + iconCache.updateIconInBackground({ itemInfoWithIcon -> + itemInfoWithIcon?.let { + if (itemInfoWithIcon.bitmap.isLowRes) { + trySend( + WidgetAppIcon( + icon = AppIcon.LowResColorIcon(itemInfoWithIcon.bitmap.color), + badge = AppIconBadge.NoBadge + ) + ) + } else { + trySend( + WidgetAppIcon( + icon = AppIcon.HighResBitmapIcon(itemInfoWithIcon.bitmap.icon), + badge = itemInfoWithIcon.bitmap.badgeDrawableInfo?.let { + AppIconBadge.DrawableBadge( + it.drawableRes, + it.colorRes + ) + } ?: AppIconBadge.NoBadge + ) + ) + } + } + }, packageItemInfo, CacheLookupFlag.DEFAULT_LOOKUP_FLAG) + + awaitClose() + } + + override fun cleanUp() {} // nothing to do here. +} diff --git a/compose/features/com/android/launcher3/widgetpicker/repository/WidgetUsersRepositoryImpl.kt b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetUsersRepositoryImpl.kt new file mode 100644 index 0000000000..e8c7c82d5a --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetUsersRepositoryImpl.kt @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2025 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.widgetpicker.repository + +import android.content.Context +import android.os.UserHandle +import android.os.UserManager +import com.android.launcher3.concurrent.annotations.BackgroundContext +import com.android.launcher3.dagger.ApplicationContext +import com.android.launcher3.model.StringCache +import com.android.launcher3.pm.UserCache +import com.android.launcher3.util.SafeCloseable +import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository +import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile +import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfileType +import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles +import kotlinx.coroutines.CoroutineName +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch +import javax.inject.Inject +import kotlin.coroutines.CoroutineContext + +/** + * An implementation of [WidgetUsersRepository] that provides user profile info to widget picker + * by looking up the [UserCache]. + */ +class WidgetUsersRepositoryImpl @Inject constructor( + @ApplicationContext private val appContext: Context, + private val userCache: UserCache, + @BackgroundContext + private val backgroundContext: CoroutineContext +) : WidgetUsersRepository { + private val userManagerService = appContext.getSystemService(UserManager::class.java) + private var stringCache: StringCache = StringCache() + private var closableUseChangeListener: SafeCloseable? = null + private val _userProfiles = MutableStateFlow(null) + private var workProfileUser: UserHandle? = null + private var backgroundScope = CoroutineScope( + SupervisorJob() + + backgroundContext + + CoroutineName("widgetUsersRepositoryBackgroundWork") + ) + + override fun initialize() { + backgroundScope.launch { + stringCache.loadStrings(appContext) + maybeUpdate(changedUser = null) + + closableUseChangeListener?.close() + closableUseChangeListener = userCache.addUserEventListener { userHandle, _ -> + maybeUpdate(userHandle) + } + } + } + + override fun observeUserProfiles(): Flow = _userProfiles.asStateFlow() + + override fun getWorkProfileUser(): UserHandle? = workProfileUser + + override fun cleanUp() { + closableUseChangeListener?.close() + backgroundScope.apply { + if (isActive) { + cancel() + } + } + } + + private fun maybeUpdate(changedUser: UserHandle?) { + check(userManagerService != null) + + workProfileUser = + userCache.userProfiles.firstOrNull { userCache.getUserInfo(it).isWork } + val needsUpdate = changedUser == null || changedUser == workProfileUser + + if (needsUpdate) { + val isUserQuiet = + workProfileUser?.let { + userManagerService.isQuietModeEnabled( + workProfileUser + ) + } ?: false + + _userProfiles.update { + WidgetUserProfiles( + personal = WidgetUserProfile( + type = WidgetUserProfileType.PERSONAL, + label = stringCache.widgetsPersonalTab, + paused = false, + pausedProfileMessage = null, + ), + work = workProfileUser?.let { + WidgetUserProfile( + type = WidgetUserProfileType.WORK, + label = stringCache.widgetsWorkTab, + paused = isUserQuiet, + pausedProfileMessage = stringCache.workProfilePausedTitle, + ) + } + ) + } + } + } +} diff --git a/compose/features/com/android/launcher3/widgetpicker/repository/WidgetsRepositoryImpl.kt b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetsRepositoryImpl.kt new file mode 100644 index 0000000000..a49fbc44df --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetsRepositoryImpl.kt @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2025 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.widgetpicker.repository + +import android.content.Context +import com.android.launcher3.DeviceProfile +import com.android.launcher3.InvariantDeviceProfile +import com.android.launcher3.concurrent.annotations.BackgroundContext +import com.android.launcher3.dagger.ApplicationContext +import com.android.launcher3.model.WidgetItem +import com.android.launcher3.model.WidgetsModel +import com.android.launcher3.model.data.PackageItemInfo +import com.android.launcher3.util.ComponentKey +import com.android.launcher3.util.Executors.MODEL_EXECUTOR +import com.android.launcher3.widget.DatabaseWidgetPreviewLoader +import com.android.launcher3.widget.picker.util.WidgetPreviewContainerSize +import com.android.launcher3.widget.util.WidgetSizes +import com.android.launcher3.widgetpicker.data.repository.WidgetsRepository +import com.android.launcher3.widgetpicker.datasource.FeaturedWidgetsDataSource +import com.android.launcher3.widgetpicker.datasource.WidgetsSearchAlgorithm +import com.android.launcher3.widgetpicker.shared.model.PickableWidget +import com.android.launcher3.widgetpicker.shared.model.WidgetApp +import com.android.launcher3.widgetpicker.shared.model.WidgetAppId +import com.android.launcher3.widgetpicker.shared.model.WidgetId +import com.android.launcher3.widgetpicker.shared.model.WidgetPreview +import com.android.launcher3.widgetpicker.shared.model.WidgetSizeInfo +import kotlinx.coroutines.CoroutineName +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import javax.inject.Inject +import kotlin.coroutines.CoroutineContext + +/** + * An implementation of the [WidgetsRepository] that provides widgets for widget picker using the + * [WidgetsModel], [FeaturedWidgetsDataSource] & enables search using the provided + * [WidgetsSearchAlgorithm]. + */ +class WidgetsRepositoryImpl @Inject constructor( + @ApplicationContext private val appContext: Context, + idp: InvariantDeviceProfile, + private val widgetsModel: WidgetsModel, + private val featuredWidgetsDataSource: FeaturedWidgetsDataSource, + private val searchAlgorithm: WidgetsSearchAlgorithm, + @BackgroundContext + private val backgroundContext: CoroutineContext, +) : WidgetsRepository { + private val deviceProfile = idp.getDeviceProfile(appContext) + private val backgroundScope = CoroutineScope( + SupervisorJob() + backgroundContext + CoroutineName("WidgetsRepository") + ) + + private val _widgetItemsByPackage = + MutableStateFlow>(emptyList()) + private val databaseWidgetPreviewLoader = DatabaseWidgetPreviewLoader(appContext, deviceProfile) + + override fun initialize() { + // TODO(b/419495339): Remove the model executor requirement from widgets model and replace + // with scope.launch + MODEL_EXECUTOR.execute { + widgetsModel.update(/*packageUser=*/ null) + _widgetItemsByPackage.update { + widgetsModel.widgetsByPackageItemForPicker.toPickableWidgets(deviceProfile) + } + } + + backgroundScope.launch { + featuredWidgetsDataSource.initialize() + } + } + + override fun observeWidgets(): Flow> = _widgetItemsByPackage.asStateFlow() + + override suspend fun getWidgetPreview(id: WidgetId): WidgetPreview { + val componentKey = ComponentKey(id.componentName, id.userHandle) + val widgetItem = widgetsModel.widgetsByComponentKey[componentKey] + ?: return WidgetPreview.PlaceholderWidgetPreview + + val previewSizePx = + WidgetSizes.getWidgetSizePx(deviceProfile, widgetItem.spanX, widgetItem.spanY) + val preview = withContext(backgroundContext) { + val result = + databaseWidgetPreviewLoader.generatePreviewInfoBg( + widgetItem, + previewSizePx.width, + previewSizePx.height + ) + when { + result.remoteViews != null -> + WidgetPreview.RemoteViewsWidgetPreview(result.remoteViews) + + result.providerInfo != null -> + WidgetPreview.ProviderInfoWidgetPreview(result.providerInfo) + + result.previewBitmap != null -> + WidgetPreview.BitmapWidgetPreview(result.previewBitmap) + + else -> WidgetPreview.PlaceholderWidgetPreview + } + } + + return preview + } + + override suspend fun searchWidgets(query: String): List = + searchAlgorithm.searchWidgets(query, _widgetItemsByPackage.value) + + override fun cleanUp() { + _widgetItemsByPackage.update { emptyList() } + backgroundScope.apply { + if (isActive) { + cancel() + } + } + } + + override fun getFeaturedWidgets(): Flow> { + return _widgetItemsByPackage.map { widgets -> + featuredWidgetsDataSource.getFeaturedWidgets(widgets) + }.flowOn(backgroundContext) + } + + companion object { + private fun Map>.toPickableWidgets(deviceProfile: DeviceProfile) = + map { (packageItemInfo, widgetItems) -> + val widgetAppId = WidgetAppId( + packageName = packageItemInfo.packageName, + userHandle = packageItemInfo.user, + category = packageItemInfo.widgetCategory + ) + + WidgetApp( + id = widgetAppId, + title = packageItemInfo.title, + widgets = widgetItems.filter { it.widgetInfo != null }.map { widgetItem -> + val previewSize = + WidgetSizes.getWidgetSizePx( + deviceProfile, + widgetItem.spanX, + widgetItem.spanY + ) + val containerSpan = + WidgetPreviewContainerSize.forItem(widgetItem, deviceProfile) + val containerSize = + WidgetSizes.getWidgetSizePx( + deviceProfile, + containerSpan.spanX, + containerSpan.spanY + ) + + PickableWidget( + id = WidgetId( + componentName = widgetItem.componentName, + userHandle = widgetItem.user + ), + appId = widgetAppId, + label = widgetItem.label, + description = widgetItem.description, + appWidgetProviderInfo = widgetItem.widgetInfo.clone(), + sizeInfo = WidgetSizeInfo( + spanX = widgetItem.widgetInfo.spanX, + spanY = widgetItem.widgetInfo.spanY, + widthPx = previewSize.width, + heightPx = previewSize.height, + containerSpanX = containerSpan.spanX, + containerSpanY = containerSpan.spanY, + containerWidthPx = containerSize.width, + containerHeightPx = containerSize.height + ) + ) + } + ) + } + } +} diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/shared/model/PickableWidget.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/shared/model/PickableWidget.kt index d37154a4b4..75cee6a722 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/shared/model/PickableWidget.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/shared/model/PickableWidget.kt @@ -55,6 +55,8 @@ data class PickableWidget( * grid * @param heightPx the height in pixels that the widget should ideally be sized at based on host's * grid + * @param spanX the number of horizontal cells that the container for the widget will use. + * @param spanY the number of vertical cells that the container for the widget will use. * @param containerWidthPx the width of container in which the widget may need to be fit to; For * instance, for visual coherence, widgets of sizes like 3x2 are shown in 2x2 container based on a * predefined mapping logic. This allows us to show them in a single row when space permits. @@ -66,6 +68,8 @@ data class WidgetSizeInfo( val spanY: Int, val widthPx: Int, val heightPx: Int, + val containerSpanX: Int, + val containerSpanY: Int, val containerWidthPx: Int, val containerHeightPx: Int, ) diff --git a/modules/widgetpicker/tests/multivalentScreenshotTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGridTestSamples.kt b/modules/widgetpicker/tests/multivalentScreenshotTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGridTestSamples.kt index 53fe5d4ea5..f86e0ab4f4 100644 --- a/modules/widgetpicker/tests/multivalentScreenshotTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGridTestSamples.kt +++ b/modules/widgetpicker/tests/multivalentScreenshotTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGridTestSamples.kt @@ -248,6 +248,8 @@ object WidgetsGridTestSamples { spanY = 1, widthPx = cellWidth, heightPx = cellHeight, + containerSpanX = 1, + containerSpanY = 1, containerWidthPx = cellWidth, containerHeightPx = cellHeight, ), @@ -267,6 +269,8 @@ object WidgetsGridTestSamples { spanY = 2, widthPx = cellWidth * 2, heightPx = cellHeight * 2, + containerSpanX = 2, + containerSpanY = 2, // container same as size containerWidthPx = cellWidth * 2, containerHeightPx = cellHeight * 2, @@ -286,6 +290,8 @@ object WidgetsGridTestSamples { spanY = 2, widthPx = cellWidth * 3, heightPx = cellHeight * 2, + containerSpanX = 2, + containerSpanY = 2, // 3x2s are bucketed to 2x2 container containerWidthPx = cellWidth * 2, containerHeightPx = cellHeight * 2, @@ -305,6 +311,8 @@ object WidgetsGridTestSamples { spanY = 2, widthPx = cellWidth * 4, heightPx = cellHeight * 2, + containerSpanX = 4, + containerSpanY = 2, // container same as size containerWidthPx = cellWidth * 4, containerHeightPx = cellHeight * 2, diff --git a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/TestUtils.kt b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/TestUtils.kt index a4ec82c24d..3f1c435398 100644 --- a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/TestUtils.kt +++ b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/TestUtils.kt @@ -121,6 +121,8 @@ object TestUtils { spanY = 2, widthPx = 200, heightPx = 200, + containerSpanX = 2, + containerSpanY = 2, containerWidthPx = 200, containerHeightPx = 200, ), diff --git a/res/values/config.xml b/res/values/config.xml index e7b2100997..7b14e50611 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -142,6 +142,15 @@ + + com.google.android.calendar + com.google.android.deskclock + com.google.android.apps.maps + com.google.android.contacts + com.google.android.apps.chromecast.app + com.google.android.gm + com.google.android.videos + 10dp diff --git a/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSize.kt b/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSize.kt index 66d8b7c21d..ae933bc173 100644 --- a/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSize.kt +++ b/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSize.kt @@ -23,6 +23,16 @@ import kotlin.math.abs /** Size of a preview container in terms of the grid spans. */ data class WidgetPreviewContainerSize(@JvmField val spanX: Int, @JvmField val spanY: Int) { companion object { + /** + * Returns a template that can be used for presenting featured widgets in widget picker. + **/ + fun pickTemplateForFeaturedWidgets(dp: DeviceProfile): List = + if (dp.deviceProperties.isTablet && !dp.deviceProperties.isTwoPanels) { + TABLET_FEATURED_CONTAINER_SIZES.random() + } else { + HANDHELD_FEATURED_CONTAINER_SIZES.random() + } + /** * Returns the size of the preview container in which the given widget's preview should be * displayed (by scaling it if necessary). diff --git a/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSizes.kt b/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSizes.kt index 1ab8f8bb54..65b0b6fc69 100644 --- a/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSizes.kt +++ b/src/com/android/launcher3/widget/picker/util/WidgetPreviewContainerSizes.kt @@ -33,6 +33,36 @@ val HANDHELD_WIDGET_PREVIEW_SIZES: List = WidgetPreviewContainerSize(spanX = 1, spanY = 1), ) +/** + * List of templates that can be used for selecting container sizes to show for featured widgets in + * the widget picker for the handheld. + */ +val HANDHELD_FEATURED_CONTAINER_SIZES: List> = + listOf( + listOf( + WidgetPreviewContainerSize(1, 1), + WidgetPreviewContainerSize(1, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(4, 1), + WidgetPreviewContainerSize(4, 2), + ), listOf( + WidgetPreviewContainerSize(2, 1), + WidgetPreviewContainerSize(2, 1), + WidgetPreviewContainerSize(4, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(4, 2), + ), + listOf( + WidgetPreviewContainerSize(4, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(4, 1), + WidgetPreviewContainerSize(4, 3), + ) + ) + /** * An ordered list of recommended sizes for the preview containers in tablet devices (with larger * grids). @@ -51,3 +81,33 @@ val TABLET_WIDGET_PREVIEW_SIZES: List = WidgetPreviewContainerSize(spanX = 2, spanY = 1), WidgetPreviewContainerSize(spanX = 1, spanY = 1), ) + +/** + * List of templates that can be used for selecting container sizes to show for featured widgets in + * the widget picker for tablets. + */ +val TABLET_FEATURED_CONTAINER_SIZES: List> = + listOf( + listOf( + WidgetPreviewContainerSize(1, 1), + WidgetPreviewContainerSize(1, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(3, 1), + WidgetPreviewContainerSize(3, 2), + ), listOf( + WidgetPreviewContainerSize(2, 1), + WidgetPreviewContainerSize(2, 1), + WidgetPreviewContainerSize(3, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(3, 2), + ), + listOf( + WidgetPreviewContainerSize(3, 1), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(2, 2), + WidgetPreviewContainerSize(3, 1), + WidgetPreviewContainerSize(3, 3), + ) + ) From 14b76f78673b331adeb9e4cc46e9a5593ffa46d1 Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Thu, 29 May 2025 12:50:54 +0100 Subject: [PATCH 05/20] Do not reflow dismissed grid task is already in split select. When the task is not found in top or bottom set, return current page. This fixes rotation in overview while split select is already active. Fix: 420546041 Test: TaskGridNavHelperTest Flag: com.android.launcher3.enable_expressive_dismiss_task_motion Change-Id: I4f654b017a0c051bd373e78ebd3d3f02f7bdf3cf --- .../com/android/quickstep/util/TaskGridNavHelper.kt | 4 ++++ .../android/quickstep/util/TaskGridNavHelperTest.kt | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/quickstep/src/com/android/quickstep/util/TaskGridNavHelper.kt b/quickstep/src/com/android/quickstep/util/TaskGridNavHelper.kt index 0e788015cd..bf60b87b89 100644 --- a/quickstep/src/com/android/quickstep/util/TaskGridNavHelper.kt +++ b/quickstep/src/com/android/quickstep/util/TaskGridNavHelper.kt @@ -59,6 +59,10 @@ class TaskGridNavHelper( cycle: Boolean, ): Int { val inTop = topRowIds.contains(currentPageTaskViewId) + val inBottom = bottomRowIds.contains(currentPageTaskViewId) + if (!inTop && !inBottom) { + return currentPageTaskViewId + } val index = if (inTop) topRowIds.indexOf(currentPageTaskViewId) else bottomRowIds.indexOf(currentPageTaskViewId) diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskGridNavHelperTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskGridNavHelperTest.kt index cb088fda56..f776b94cd0 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskGridNavHelperTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskGridNavHelperTest.kt @@ -786,6 +786,17 @@ class TaskGridNavHelperTest { .isEqualTo(ADD_DESK_PLACEHOLDER_ID) } + /* + 5 3 1 | + CLEAR_ALL | Invalid ID: + 6 4 2 | [25] --> [25] + */ + @Test + fun nextGridPage_invalidId_pressTab_noCycle_returnsCurrentPage() { + assertThat(getNextGridPage(currentPageTaskViewId = 25, TAB, delta = -1, cycle = false)) + .isEqualTo(25) + } + // Col offset: 0 1 2 // ----------- // ID grid: 4 2 0 start From 4be13eb3112100b09f1ded51dc8f241d52b38e8a Mon Sep 17 00:00:00 2001 From: Ajinkya Chalke Date: Thu, 29 May 2025 08:01:51 -0700 Subject: [PATCH 06/20] Remove obsolete TODO - From b/399089118#comment2 "On external dispalys, RecentsViewContainer is always RecentsWindowManager, so onOverviewTargetChanged will never be called on external displays". So we we only need to track OverviewTargetChange for default display. Fix: 399089118 Test: m Flag: EXEMPT comment only change Change-Id: Ica0527e45da6f0079bae5b69e9100b9f74d7f7ad --- .../src/com/android/quickstep/TouchInteractionService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 4033ebe3ba..b3ce9414cd 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -908,8 +908,6 @@ public class TouchInteractionService extends Service { private void onOverviewTargetChanged(boolean isHomeAndOverviewSame) { mAllAppsActionManager.setHomeAndOverviewSame(isHomeAndOverviewSame); - // TODO (b/399089118): how will this work with per-display Taskbars? Is using the - // default-display container ok? RecentsViewContainer newOverviewContainer = mOverviewComponentObserver.getContainerInterface( DEFAULT_DISPLAY).getCreatedContainer(); From ab50c3ab25b59bd7453e5f6cc0167077a03c8f8c Mon Sep 17 00:00:00 2001 From: Anushree Ganjam Date: Thu, 29 May 2025 11:00:18 -0700 Subject: [PATCH 07/20] Remove the debug tracing. Bug: 399112039 Test: Presubmit Flag: TEST_ONLY Change-Id: I8e542a73cfb440d82e6cd02d531721d0fa35d3d1 --- .../src/com/android/launcher3/testing/shared/TestProtocol.java | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java index 390edd2200..b02695c137 100644 --- a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java +++ b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java @@ -175,7 +175,6 @@ public final class TestProtocol { public static final String PERMANENT_DIAG_TAG = "TaplTarget"; public static final String ICON_MISSING = "b/282963545"; - public static final String SEARCH_CONTEXT_NULL = "b/399112039"; public static final String REQUEST_FLAG_ENABLE_GRID_ONLY_OVERVIEW = "enable-grid-only-overview"; public static final String REQUEST_IS_RECENTS_WINDOW_ENABLED = "recents-window-enabled"; From 8244449a9fbc7d47d77791d8898dc182d5ff8eb0 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Tue, 27 May 2025 13:18:47 -0700 Subject: [PATCH 08/20] Moving taskbar variables in DeviceProfile to their own class Bug: 419264653 Flag: EXEMPT refactor Test: DeviceProfileDumpTest Test: All Image tests Change-Id: I05ec9e15ef02096326596af4835adb706473a736 --- .../KeyboardQuickSwitchViewController.java | 5 +- .../taskbar/NavbarButtonsViewController.java | 2 +- .../taskbar/StashedHandleViewController.java | 4 +- .../taskbar/TaskbarActivityContext.java | 10 +- .../taskbar/TaskbarBackgroundRenderer.kt | 14 +-- .../taskbar/TaskbarDividerPopupView.kt | 4 +- .../taskbar/TaskbarDragLayerController.java | 13 ++- .../launcher3/taskbar/TaskbarEduTooltip.kt | 2 +- .../taskbar/TaskbarEduTooltipController.kt | 6 +- .../TaskbarLauncherStateController.java | 7 +- .../taskbar/TaskbarPopupController.java | 5 +- .../taskbar/TaskbarStashController.java | 13 ++- .../taskbar/TaskbarStashViaTouchController.kt | 3 +- .../launcher3/taskbar/TaskbarView.java | 10 +- .../taskbar/TaskbarViewController.java | 44 +++++---- .../bubbles/BubbleBarViewController.java | 10 +- .../BubbleStashedHandleViewController.java | 2 +- .../DeviceProfileDimensionsProviderAdapter.kt | 4 +- .../launcher3/taskbar/growth/NudgeView.kt | 2 +- .../quickstep/BaseContainerInterface.java | 5 +- .../TaskbarUnstashInputConsumer.java | 3 +- .../orientation/PortraitPagedViewHandler.kt | 6 +- .../quickstep/views/OverviewActionsView.java | 2 +- .../taskbar/TaskbarStashControllerTest.kt | 10 +- .../taskbar/rules/TaskbarModeRuleTest.kt | 6 +- src/com/android/launcher3/BubbleTextView.java | 2 +- src/com/android/launcher3/DeviceProfile.java | 77 ++++++--------- .../launcher3/allapps/WorkUtilityView.java | 2 +- .../launcher3/deviceprofile/TaskbarProfile.kt | 93 +++++++++++++++++++ .../android/launcher3/util/DimensionUtils.kt | 2 +- src/com/android/launcher3/views/Snackbar.java | 2 +- 31 files changed, 239 insertions(+), 131 deletions(-) create mode 100644 src/com/android/launcher3/deviceprofile/TaskbarProfile.kt diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java index 85db194d46..5dc4fd142a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java @@ -172,8 +172,9 @@ public class KeyboardQuickSwitchViewController { // Calculate the additional margin space that the KQS should move up for the transient // taskbar. The value of spaceForTaskbar is the distance between the bottom of the KQS // view with 0 bottom margin to the top of the transient taskbar view. - final int spaceForTaskbar = isTransientTaskbar ? dp.taskbarHeight + dp.taskbarBottomMargin - - dp.stashedTaskbarHeight : 0; + final int spaceForTaskbar = isTransientTaskbar ? dp.getTaskbarProfile().getHeight() + + dp.getTaskbarProfile().getBottomMargin() + - dp.getTaskbarProfile().getStashedTaskbarHeight() : 0; final int marginBottom = spaceForTaskbar + resources.getDimensionPixelSize( R.dimen.keyboard_quick_switch_margin_bottom); diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java index 4120a90020..e70e59d655 100644 --- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java @@ -366,7 +366,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT flags -> (flags & flagsToRemoveTranslation) != 0, AnimatedFloat.VALUE, 1, 0)); // Center nav buttons in new height for IME. - float transForIme = (mContext.getDeviceProfile().taskbarHeight + float transForIme = (mContext.getDeviceProfile().getTaskbarProfile().getHeight() - mControllers.taskbarInsetsController.getTaskbarHeightForIme()) / 2f; // For gesture nav, nav buttons only show for IME anyway so keep them translated down. float defaultButtonTransY = alwaysShowButtons ? 0 : transForIme; diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java index 20a049313a..c19d883e96 100644 --- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java @@ -130,11 +130,11 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT mStashedHandleWidth = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_small_screen); } else { - mTaskbarSize = deviceProfile.taskbarHeight; + mTaskbarSize = deviceProfile.getTaskbarProfile().getHeight(); mStashedHandleWidth = resources .getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width); } - int taskbarBottomMargin = deviceProfile.taskbarBottomMargin; + int taskbarBottomMargin = deviceProfile.getTaskbarProfile().getBottomMargin(); mStashedHandleView.getLayoutParams().height = mTaskbarSize + taskbarBottomMargin; mTaskbarStashedHandleAlpha.get(ALPHA_INDEX_STASHED).setValue( diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 9ce3fe83c7..0fe3eefd89 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -472,7 +472,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { deviceProfile.hotseatQsbWidth = originDeviceProfile.hotseatQsbWidth; // Update icon size - deviceProfile.iconSizePx = deviceProfile.taskbarIconSize; + deviceProfile.iconSizePx = deviceProfile.getTaskbarProfile().getIconSize(); deviceProfile.updateIconSize(1f, this); }; mDeviceProfile = originDeviceProfile.toBuilder(this) @@ -816,7 +816,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { /** Returns whether taskbar should start align. */ public boolean shouldStartAlignTaskbar() { - return isThreeButtonNav() && mDeviceProfile.startAlignTaskbar; + return isThreeButtonNav() && mDeviceProfile.getTaskbarProfile().isStartAlignTaskbar(); } public boolean isGestureNav() { @@ -1382,15 +1382,15 @@ public class TaskbarActivityContext extends BaseTaskbarContext { DeviceProfile transientTaskbarDp = mDeviceProfile.toBuilder(this) .setIsTransientTaskbar(true).build(); - taskbarWindowSize = transientTaskbarDp.taskbarHeight - + (2 * transientTaskbarDp.taskbarBottomMargin) + taskbarWindowSize = transientTaskbarDp.getTaskbarProfile().getHeight() + + (2 * transientTaskbarDp.getTaskbarProfile().getBottomMargin()) + Math.max(extraHeightForTaskbarTooltips, resources.getDimensionPixelSize( R.dimen.transient_taskbar_shadow_blur)); return Math.max(taskbarWindowSize, bubbleBarTop); } - taskbarWindowSize = mDeviceProfile.taskbarHeight + taskbarWindowSize = mDeviceProfile.getTaskbarProfile().getHeight() + getCornerRadius() + extraHeightForTaskbarTooltips; return Math.max(taskbarWindowSize, bubbleBarTop); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt index 70a303ca8e..bd33177bfa 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt @@ -40,9 +40,9 @@ class TaskbarBackgroundRenderer(private val context: TaskbarActivityContext) { private val isInSetup: Boolean = !context.isUserSetupComplete private val maxTransientTaskbarHeight = - context.transientTaskbarDeviceProfile.taskbarHeight.toFloat() + context.transientTaskbarDeviceProfile.taskbarProfile.height.toFloat() private val maxPersistentTaskbarHeight = - context.persistentTaskbarDeviceProfile.taskbarHeight.toFloat() + context.persistentTaskbarDeviceProfile.taskbarProfile.height.toFloat() var backgroundProgress = if (context.isTransientTaskbar) { PINNING_TRANSIENT @@ -57,7 +57,7 @@ class TaskbarBackgroundRenderer(private val context: TaskbarActivityContext) { val paint = Paint() private val strokePaint = Paint() val lastDrawnTransientRect = RectF() - var backgroundHeight = context.deviceProfile.taskbarHeight.toFloat() + var backgroundHeight = context.deviceProfile.taskbarProfile.height.toFloat() var translationYForSwipe = 0f var translationYForStash = 0f var translationXForBubbleBar = 0f @@ -195,10 +195,10 @@ class TaskbarBackgroundRenderer(private val context: TaskbarActivityContext) { scale = Math.round(scale * 100f) / 100f bottomMargin = mapRange( - scale, - 0f, - res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin).toFloat(), - ) + scale, + 0f, + res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin).toFloat(), + ) .toInt() shadowBlur = mapRange(scale, 0f, res.getDimension(R.dimen.transient_taskbar_shadow_blur)) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt index 7f6185dab3..3ae06abea4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt @@ -267,8 +267,8 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 } override fun getExtraVerticalOffset(): Int { - return (mActivityContext.deviceProfile.taskbarHeight - - mActivityContext.deviceProfile.taskbarIconSize) / 2 + verticalOffsetForPopupView + return (mActivityContext.deviceProfile.taskbarProfile.height - + mActivityContext.deviceProfile.taskbarProfile.iconSize) / 2 + verticalOffsetForPopupView } override fun onCreateCloseAnimation(anim: AnimatorSet?) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java index 174a02b4ea..8bd685b3d6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java @@ -163,9 +163,14 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa * @return Bounds (in TaskbarDragLayer coordinates) where an opened Folder can display. */ public Rect getFolderBoundingBox() { - Rect boundingBox = new Rect(0, 0, mTaskbarDragLayer.getWidth(), - mTaskbarDragLayer.getHeight() - mActivity.getDeviceProfile().taskbarHeight - - mActivity.getDeviceProfile().taskbarBottomMargin); + Rect boundingBox = new Rect( + 0, + 0, + mTaskbarDragLayer.getWidth(), + mTaskbarDragLayer.getHeight() + - mActivity.getDeviceProfile().getTaskbarProfile().getHeight() + - mActivity.getDeviceProfile().getTaskbarProfile().getBottomMargin() + ); boundingBox.inset(mFolderMargin, mFolderMargin); return boundingBox; } @@ -352,7 +357,7 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa deviceProfile.getDisplayInfo().currentSize.y : taskbarDimensions.y; } else { - return deviceProfile.taskbarHeight; + return deviceProfile.getTaskbarProfile().getHeight(); } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt index f3ea655866..f8ac8cdd36 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt @@ -85,7 +85,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 // constraint to reduce the number of lines of text and hopefully free up some height. activityContext.dragLayer.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) if ( - measuredHeight + activityContext.deviceProfile.taskbarHeight >= + measuredHeight + activityContext.deviceProfile.taskbarProfile.height >= activityContext.deviceProfile.deviceProperties.availableHeightPx ) { updateLayoutParams { width = MATCH_PARENT } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt index 990c575119..9a120f5611 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt @@ -245,7 +245,7 @@ open class TaskbarEduTooltipController(context: Context) : else R.dimen.taskbar_edu_features_tooltip_width_with_two_features ) - bottomMargin += activityContext.deviceProfile.taskbarHeight + bottomMargin += activityContext.deviceProfile.taskbarProfile.height } else { width = resources.getDimensionPixelSize( @@ -299,7 +299,7 @@ open class TaskbarEduTooltipController(context: Context) : handleEduAnimations(listOf(pinningAnim)) updateLayoutParams { if (activityContext.isTransientTaskbar) { - bottomMargin += activityContext.deviceProfile.taskbarHeight + bottomMargin += activityContext.deviceProfile.taskbarProfile.height } // Unlike other tooltips, we want to align with taskbar divider rather than center. gravity = Gravity.BOTTOM @@ -356,7 +356,7 @@ open class TaskbarEduTooltipController(context: Context) : showDisclosureText(eduSubtitle) updateLayoutParams { if (activityContext.isTransientTaskbar) { - bottomMargin += activityContext.deviceProfile.taskbarHeight + bottomMargin += activityContext.deviceProfile.taskbarProfile.height } // Unlike other tooltips, we want to align with the all apps button rather than // center. diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java index 6865bd6423..abbfc95255 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java @@ -804,8 +804,11 @@ public class TaskbarLauncherStateController { taskbarBgOffsetStart, taskbarBgOffsetEnd); ObjectAnimator taskbarIconsYTranslation = null; - float taskbarHeight = - mControllers.taskbarActivityContext.getDeviceProfile().taskbarHeight; + float taskbarHeight = mControllers + .taskbarActivityContext + .getDeviceProfile() + .getTaskbarProfile() + .getHeight(); if (showTaskbar) { taskbarIconsYTranslation = taskbarIconTranslationYForHome.animateToValue( taskbarHeight, 0); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java index 2b774e9733..44832b52db 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java @@ -292,7 +292,10 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba // Move the icon to align with the center-top of the touch point Point iconShift = new Point(); iconShift.x = mIconLastTouchPos.x - sv.getIconCenter().x; - iconShift.y = mIconLastTouchPos.y - mContext.getDeviceProfile().taskbarIconSize; + iconShift.y = mIconLastTouchPos.y + - mContext.getDeviceProfile() + .getTaskbarProfile() + .getIconSize(); ((TaskbarDragController) ActivityContext.lookupContext( v.getContext()).getDragController()).startDragOnLongClick(sv, iconShift); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 94d348b0b3..22ff3bedbb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -322,8 +322,11 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba mStashedHeight = mActivity.getResources().getDimensionPixelSize( R.dimen.taskbar_stashed_size); } else { - mUnstashedHeight = mActivity.getDeviceProfile().taskbarHeight; - mStashedHeight = mActivity.getDeviceProfile().stashedTaskbarHeight; + mUnstashedHeight = mActivity.getDeviceProfile().getTaskbarProfile().getHeight(); + mStashedHeight = mActivity + .getDeviceProfile() + .getTaskbarProfile() + .getStashedTaskbarHeight(); } } @@ -512,7 +515,11 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba public int getTouchableHeight() { return mIsStashed ? mStashedHeight - : (mUnstashedHeight + mActivity.getDeviceProfile().taskbarBottomMargin); + : (mUnstashedHeight + + mActivity.getDeviceProfile() + .getTaskbarProfile() + .getBottomMargin() + ); } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashViaTouchController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashViaTouchController.kt index 7793642eda..fd259223d2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashViaTouchController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashViaTouchController.kt @@ -47,7 +47,8 @@ class TaskbarStashViaTouchController(val controllers: TaskbarControllers) : Touc private val maxVisualDisplacement = activity.resources.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin).toFloat() /** How far the swipe could go, if user swiped from the very top of TaskbarView. */ - private val maxTouchDisplacement = maxVisualDisplacement + activity.deviceProfile.taskbarHeight + private val maxTouchDisplacement = + maxVisualDisplacement + activity.deviceProfile.taskbarProfile.height private val touchDisplacementToStash = activity.resources.getDimensionPixelSize(R.dimen.taskbar_to_nav_threshold).toFloat() diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index d59002c5cf..48686ee40e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -162,10 +162,11 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar onDeviceProfileChanged(mActivityContext.getDeviceProfile()); int actualMargin = resources.getDimensionPixelSize(R.dimen.taskbar_icon_spacing); - int actualIconSize = mActivityContext.getDeviceProfile().taskbarIconSize; + int actualIconSize = + mActivityContext.getDeviceProfile().getTaskbarProfile().getIconSize(); if (enableTaskbarPinning() && canTransitionToTransientTaskbar()) { DeviceProfile deviceProfile = mActivityContext.getTransientTaskbarDeviceProfile(); - actualIconSize = deviceProfile.taskbarIconSize; + actualIconSize = deviceProfile.getTaskbarProfile().getIconSize(); } int visualIconSize = (int) (actualIconSize * ICON_VISIBLE_AREA_FACTOR); @@ -178,7 +179,10 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar // We always layout taskbar as a transient taskbar when we have taskbar pinning feature on, // then we scale and translate the icons to match persistent taskbar designs, so we use // taskbar icon size from current device profile to calculate correct item padding. - mItemPadding = (mIconTouchSize - mActivityContext.getDeviceProfile().taskbarIconSize) / 2; + mItemPadding = (mIconTouchSize - mActivityContext + .getDeviceProfile() + .getTaskbarProfile() + .getIconSize()) / 2; mFolderLeaveBehindColor = Themes.getAttrColor(mActivityContext, android.R.attr.textColorTertiary); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java index e42c11ad5a..f5e6f14da7 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java @@ -231,14 +231,14 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar mActivity = activity; mTransientTaskbarDp = mActivity.getTransientTaskbarDeviceProfile(); mPersistentTaskbarDp = mActivity.getPersistentTaskbarDeviceProfile(); - mTransientIconSize = mTransientTaskbarDp.taskbarIconSize; - mPersistentIconSize = mPersistentTaskbarDp.taskbarIconSize; + mTransientIconSize = mTransientTaskbarDp.getTaskbarProfile().getIconSize(); + mPersistentIconSize = mPersistentTaskbarDp.getTaskbarProfile().getIconSize(); mTaskbarView = taskbarView; mTaskbarIconAlpha = new MultiValueAlpha(mTaskbarView, NUM_ALPHA_CHANNELS); mTaskbarIconAlpha.setUpdateVisibility(true); mModelCallbacks = TaskbarModelCallbacksFactory.newInstance(mActivity) .create(mActivity, mTaskbarView); - mTaskbarBottomMargin = activity.getDeviceProfile().taskbarBottomMargin; + mTaskbarBottomMargin = activity.getDeviceProfile().getTaskbarProfile().getBottomMargin(); mStashedHandleHeight = activity.getResources() .getDimensionPixelSize(R.dimen.taskbar_stashed_handle_height); @@ -271,7 +271,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar mControllers.runAfterInit(mTaskbarView::updatePinningPopupEventHandlers); mTaskbarView.getLayoutParams().height = mActivity.isPhoneMode() ? mActivity.getResources().getDimensionPixelSize(R.dimen.taskbar_phone_size) - : mActivity.getDeviceProfile().taskbarHeight; + : mActivity.getDeviceProfile().getTaskbarProfile().getHeight(); mTaskbarIconScaleForStash.updateValue(1f); float pinningValue = @@ -687,17 +687,19 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar // finally placing the icon in the middle of new taskbar background height. if (mControllers.getSharedState().startTaskbarVariantIsTransient) { float transY = - mTransientTaskbarDp.taskbarBottomMargin + (mTransientTaskbarDp.taskbarHeight + mTransientTaskbarDp.getTaskbarProfile().getBottomMargin() + ( + mTransientTaskbarDp.getTaskbarProfile().getHeight() - mTaskbarView.getTransientTaskbarIconLayoutBounds().bottom) - - (mPersistentTaskbarDp.taskbarHeight - - mTransientTaskbarDp.taskbarIconSize) / 2f; + - (mPersistentTaskbarDp.getTaskbarProfile().getHeight() + - mTransientTaskbarDp.getTaskbarProfile().getIconSize()) / 2f; taskbarIconTranslationYForPinningValue = mapRange(scale, 0f, transY); } else { float transY = - -mTransientTaskbarDp.taskbarBottomMargin + (mPersistentTaskbarDp.taskbarHeight + -mTransientTaskbarDp.getTaskbarProfile().getBottomMargin() + ( + mPersistentTaskbarDp.getTaskbarProfile().getHeight() - mTaskbarView.getTransientTaskbarIconLayoutBounds().bottom) - - (mTransientTaskbarDp.taskbarHeight - - mTransientTaskbarDp.taskbarIconSize) / 2f; + - (mTransientTaskbarDp.getTaskbarProfile().getHeight() + - mTransientTaskbarDp.getTaskbarProfile().getIconSize()) / 2f; taskbarIconTranslationYForPinningValue = mapRange(scale, transY, 0f); } return taskbarIconTranslationYForPinningValue; @@ -982,12 +984,16 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar Rect hotseatPadding = launcherDp.getHotseatLayoutPadding(mActivity); boolean isTransientTaskbar = mActivity.isTransientTaskbar(); - float scaleUp = ((float) launcherDp.iconSizePx) / taskbarDp.taskbarIconSize; + float scaleUp = ((float) launcherDp.iconSizePx) + / taskbarDp.getTaskbarProfile().getIconSize(); int borderSpacing = launcherDp.hotseatBorderSpace; int hotseatCellSize = DeviceProfile.calculateCellWidth( - launcherDp.getDeviceProperties().getAvailableWidthPx() - hotseatPadding.left - hotseatPadding.right, + launcherDp.getDeviceProperties().getAvailableWidthPx() + - hotseatPadding.left + - hotseatPadding.right, borderSpacing, - launcherDp.numShownHotseatIcons); + launcherDp.numShownHotseatIcons + ); boolean isToHome = mControllers.uiController.isIconAlignedWithHotseat(); boolean isDeviceLocked = mControllers.taskbarStashController.isDeviceLocked(); @@ -1012,13 +1018,14 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar } } int collapsedHeight = mActivity.getDefaultTaskbarWindowSize(); - int expandedHeight = Math.max(collapsedHeight, taskbarDp.taskbarHeight + offsetY); + int expandedHeight = Math.max(collapsedHeight, + taskbarDp.getTaskbarProfile().getHeight() + offsetY); setter.addOnFrameListener(anim -> mActivity.setTaskbarWindowSize( anim.getAnimatedFraction() > 0 ? expandedHeight : collapsedHeight)); mTaskbarBottomMargin = isTransientTaskbar - ? mTransientTaskbarDp.taskbarBottomMargin - : mPersistentTaskbarDp.taskbarBottomMargin; + ? mTransientTaskbarDp.getTaskbarProfile().getBottomMargin() + : mPersistentTaskbarDp.getTaskbarProfile().getBottomMargin(); int firstRecentTaskIndex = -1; int hotseatNavBarTranslationX = 0; @@ -1078,8 +1085,9 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar INDEX_TASKBAR_PINNING_ANIM).getValue(); } float halfQsbIconWidthDiff = - (launcherDp.hotseatQsbWidth - taskbarDp.taskbarIconSize) / 2f; - float scale = ((float) taskbarDp.taskbarIconSize) + (launcherDp.hotseatQsbWidth - taskbarDp.getTaskbarProfile().getIconSize()) + / 2f; + float scale = ((float) taskbarDp.getTaskbarProfile().getIconSize()) / launcherDp.getHotseatProfile().getQsbVisualHeight(); setter.addFloat(child, SCALE_PROPERTY, scale, 1f, interpolator); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 94e39d63bd..29c34a07bc 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -859,7 +859,7 @@ public class BubbleBarViewController { float mediumIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, APP_ICON_MEDIUM_DP, dm); float smallMediumThreshold = (smallIconSize + mediumIconSize) / 2f; - int taskbarIconSize = deviceProfile.taskbarIconSize; + int taskbarIconSize = deviceProfile.getTaskbarProfile().getIconSize(); return taskbarIconSize <= smallMediumThreshold ? res.getDimensionPixelSize(R.dimen.bubblebar_icon_size_small) : res.getDimensionPixelSize(R.dimen.bubblebar_icon_size); @@ -877,7 +877,7 @@ public class BubbleBarViewController { float largeIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, APP_ICON_LARGE_DP, dm); float mediumLargeThreshold = (mediumIconSize + largeIconSize) / 2f; - return deviceProfile.taskbarIconSize >= mediumLargeThreshold + return deviceProfile.getTaskbarProfile().getIconSize() >= mediumLargeThreshold ? res.getDimensionPixelSize(R.dimen.bubblebar_icon_spacing_large) : res.getDimensionPixelSize(R.dimen.bubblebar_icon_spacing); } @@ -954,9 +954,11 @@ public class BubbleBarViewController { int persistentSpacingSize = res .getDimensionPixelSize(R.dimen.bubblebar_icon_spacing_persistent_taskbar); int persistentBubbleBarSize = persistentBubbleSize + persistentSpacingSize * 2; - int persistentTaskbarHeight = activity.getPersistentTaskbarDeviceProfile().taskbarHeight; + int persistentTaskbarHeight = + activity.getPersistentTaskbarDeviceProfile().getTaskbarProfile().getHeight(); int persistentBubbleBarY = (persistentTaskbarHeight - persistentBubbleBarSize) / 2; - int transientBubbleBarY = activity.getTransientTaskbarDeviceProfile().taskbarBottomMargin; + int transientBubbleBarY = + activity.getTransientTaskbarDeviceProfile().getTaskbarProfile().getBottomMargin(); return transientBubbleBarY - persistentBubbleBarY; } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashedHandleViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashedHandleViewController.java index 079f33ef5a..7e2b139f2b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashedHandleViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleStashedHandleViewController.java @@ -104,7 +104,7 @@ public class BubbleStashedHandleViewController { // Use values directly from device profile to avoid referencing other bubble controllers // during init flow. int maxTy = Math.max(deviceProfile.hotseatBarBottomSpacePx, - deviceProfile.taskbarBottomMargin); + deviceProfile.getTaskbarProfile().getBottomMargin()); // Adjust handle view size to accommodate the handle morphing into the bubble bar mStashedHandleView.getLayoutParams().height = barSize + maxTy; diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt index 886b9f02c2..2408274c9f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt @@ -27,9 +27,9 @@ import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Task class DeviceProfileDimensionsProviderAdapter( private val taskbarActivityContext: TaskbarActivityContext ) : TaskbarHotseatDimensionsProvider { - override fun getTaskbarBottomSpace(): Int = taskbarDp().taskbarBottomMargin + override fun getTaskbarBottomSpace(): Int = taskbarDp().taskbarProfile.bottomMargin - override fun getTaskbarHeight(): Int = taskbarDp().taskbarHeight + override fun getTaskbarHeight(): Int = taskbarDp().taskbarProfile.height private fun taskbarDp(): DeviceProfile = taskbarActivityContext.deviceProfile } diff --git a/quickstep/src/com/android/launcher3/taskbar/growth/NudgeView.kt b/quickstep/src/com/android/launcher3/taskbar/growth/NudgeView.kt index 2290192ae7..5a832b1423 100644 --- a/quickstep/src/com/android/launcher3/taskbar/growth/NudgeView.kt +++ b/quickstep/src/com/android/launcher3/taskbar/growth/NudgeView.kt @@ -68,7 +68,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 // constraint to reduce the number of lines of text and hopefully free up some height. activityContext.dragLayer.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) if ( - measuredHeight + activityContext.deviceProfile.taskbarHeight >= + measuredHeight + activityContext.deviceProfile.taskbarProfile.height >= activityContext.deviceProfile.deviceProperties.availableHeightPx ) { updateLayoutParams { width = LayoutParams.MATCH_PARENT } diff --git a/quickstep/src/com/android/quickstep/BaseContainerInterface.java b/quickstep/src/com/android/quickstep/BaseContainerInterface.java index 6e75b79429..95c1aaf3a1 100644 --- a/quickstep/src/com/android/quickstep/BaseContainerInterface.java +++ b/quickstep/src/com/android/quickstep/BaseContainerInterface.java @@ -367,7 +367,7 @@ public abstract class BaseContainerInterface extends FrameLayo } if (mDp.getDeviceProperties().isTablet() && enableGridOnlyOverview()) { - return mDp.stashedTaskbarHeight; + return mDp.getTaskbarProfile().getStashedTaskbarHeight(); } // Align to bottom of task Rect. diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt index 22e0923fe2..77ac257dd7 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt @@ -325,7 +325,7 @@ class TaskbarStashControllerTest { } val expectedHeight = - activityContext.deviceProfile.run { taskbarHeight + taskbarBottomMargin } + activityContext.deviceProfile.taskbarProfile.run { height + bottomMargin } assertThat(stashController.touchableHeight).isEqualTo(expectedHeight) } @@ -333,7 +333,7 @@ class TaskbarStashControllerTest { @TaskbarMode(PINNED) fun testGetTouchableHeight_pinnedMode_taskbarHeight() { assertThat(stashController.touchableHeight) - .isEqualTo(activityContext.deviceProfile.taskbarHeight) + .isEqualTo(activityContext.deviceProfile.taskbarProfile.height) } @Test @@ -347,14 +347,14 @@ class TaskbarStashControllerTest { @TaskbarMode(THREE_BUTTONS) fun testGetContentHeightToReportToApps_threeButtonsMode_taskbarHeight() { assertThat(stashController.contentHeightToReportToApps) - .isEqualTo(activityContext.deviceProfile.taskbarHeight) + .isEqualTo(activityContext.deviceProfile.taskbarProfile.height) } @Test @TaskbarMode(PINNED) fun testGetContentHeightToReportToApps_pinnedMode_taskbarHeight() { assertThat(stashController.contentHeightToReportToApps) - .isEqualTo(activityContext.deviceProfile.taskbarHeight) + .isEqualTo(activityContext.deviceProfile.taskbarProfile.height) } @Test @@ -406,7 +406,7 @@ class TaskbarStashControllerTest { @TaskbarMode(PINNED) fun testGetTappableHeightToReportToApps_pinnedMode_taskbarHeight() { assertThat(stashController.tappableHeightToReportToApps) - .isEqualTo(activityContext.deviceProfile.taskbarHeight) + .isEqualTo(activityContext.deviceProfile.taskbarProfile.height) } @Test diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarModeRuleTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarModeRuleTest.kt index 6b41475dd6..d4a3fa62e6 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarModeRuleTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarModeRuleTest.kt @@ -49,7 +49,7 @@ class TaskbarModeRuleTest { @TaskbarMode(TRANSIENT) fun testTaskbarMode_transient_overridesDeviceProfile() { val dp = InvariantDeviceProfile.INSTANCE.get(context).getDeviceProfile(context) - assertThat(dp.isTransientTaskbar).isTrue() + assertThat(dp.taskbarProfile.isTransientTaskbar).isTrue() assertThat(dp.deviceProperties.isGestureMode).isTrue() } @@ -65,7 +65,7 @@ class TaskbarModeRuleTest { @TaskbarMode(PINNED) fun testTaskbarMode_pinned_overridesDeviceProfile() { val dp = InvariantDeviceProfile.INSTANCE.get(context).getDeviceProfile(context) - assertThat(dp.isTransientTaskbar).isFalse() + assertThat(dp.taskbarProfile.isTransientTaskbar).isFalse() assertThat(dp.deviceProperties.isGestureMode).isTrue() } @@ -82,7 +82,7 @@ class TaskbarModeRuleTest { @TaskbarMode(THREE_BUTTONS) fun testTaskbarMode_threeButtons_overridesDeviceProfile() { val dp = InvariantDeviceProfile.INSTANCE.get(context).getDeviceProfile(context) - assertThat(dp.isTransientTaskbar).isFalse() + assertThat(dp.taskbarProfile.isTransientTaskbar).isFalse() assertThat(dp.deviceProperties.isGestureMode).isFalse() } } diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 0639695979..c56f50e193 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -287,7 +287,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, defaultIconSize = getResources().getDimensionPixelSize( R.dimen.search_row_small_icon_size); } else if (mDisplay == DISPLAY_TASKBAR) { - defaultIconSize = mDeviceProfile.taskbarIconSize; + defaultIconSize = mDeviceProfile.getTaskbarProfile().getIconSize(); } else { // widget_selection or shortcut_popup defaultIconSize = mDeviceProfile.iconSizePx; diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index d23372c907..84c6c73889 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -48,7 +48,6 @@ import android.view.Surface; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import androidx.core.content.res.ResourcesCompat; import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.DevicePaddings.DevicePadding; @@ -58,6 +57,7 @@ import com.android.launcher3.deviceprofile.DeviceProperties; import com.android.launcher3.deviceprofile.DropTargetProfile; import com.android.launcher3.deviceprofile.HotseatProfile; import com.android.launcher3.deviceprofile.OverviewProfile; +import com.android.launcher3.deviceprofile.TaskbarProfile; import com.android.launcher3.graphics.ThemeManager; import com.android.launcher3.icons.DotRenderer; import com.android.launcher3.model.data.ItemInfo; @@ -254,17 +254,10 @@ public class DeviceProfile { public final DotRenderer mDotRendererAllApps; // Taskbar + private final TaskbarProfile mTaskbarProfile; public boolean isTaskbarPresent; // Whether Taskbar will inset the bottom of apps by taskbarSize. public boolean isTaskbarPresentInApps; - public final int taskbarHeight; - public final int stashedTaskbarHeight; - public final int taskbarBottomMargin; - public final int taskbarIconSize; - private final int mTransientTaskbarClaimedSpace; - // If true, used to layout taskbar in 3 button navigation mode. - public final boolean startAlignTaskbar; - public final boolean isTransientTaskbar; // DragController public int flingToDeleteThresholdVelocity; @@ -300,6 +293,7 @@ public class DeviceProfile { 0 ); hotseatProfile = new HotseatProfile(false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + mTaskbarProfile = new TaskbarProfile(0, 0, 0, 0, 0, false, false); inv = null; mDisplayOptionSpec = null; mInfo = null; @@ -329,13 +323,6 @@ public class DeviceProfile { mViewScaleProvider = null; mDotRendererWorkSpace = null; mDotRendererAllApps = null; - taskbarHeight = 0; - stashedTaskbarHeight = 0; - taskbarBottomMargin = 0; - taskbarIconSize = 0; - mTransientTaskbarClaimedSpace = 0; - startAlignTaskbar = false; - isTransientTaskbar = false; } /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */ @@ -399,33 +386,15 @@ public class DeviceProfile { mTypeIndex = displayOptionSpec.typeIndex; - this.isTransientTaskbar = isTransientTaskbar; - int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics); - int transientTaskbarBottomMargin = - res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin); - int transientTaskbarHeight = - Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR) - + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding))); - mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin; - - if (!isTaskbarPresent) { - taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0; - startAlignTaskbar = false; - } else if (isTransientTaskbar) { - taskbarIconSize = transientTaskbarIconSize; - taskbarHeight = transientTaskbarHeight; - stashedTaskbarHeight = - res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height); - taskbarBottomMargin = transientTaskbarBottomMargin; - startAlignTaskbar = false; - } else { - taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size), - mMetrics); - taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size); - stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size); - taskbarBottomMargin = 0; - startAlignTaskbar = displayOptionSpec.startAlignTaskbar; - } + mTaskbarProfile = TaskbarProfile.Factory.createTaskbarProfile( + res, + isTransientTaskbar, + isTaskbarPresent, + mMetrics, + displayOptionSpec, + mTypeIndex, + inv + ); edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale); @@ -2026,7 +1995,7 @@ public class DeviceProfile { * Returns the number of pixels the taskbar is translated from the bottom of the screen. */ public int getTaskbarOffsetY() { - int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2; + int taskbarIconBottomSpace = (getTaskbarProfile().getHeight() - iconSizePx) / 2; int launcherIconBottomSpace = Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY); return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace; @@ -2034,7 +2003,9 @@ public class DeviceProfile { /** Returns the number of pixels required below OverviewActions. */ public int getOverviewActionsClaimedSpaceBelow() { - return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom; + return isTaskbarPresent + ? getTaskbarProfile().getTransientTaskbarClaimedSpace() + : mInsets.bottom; } /** Gets the space that the overview actions will take, including bottom margin. */ @@ -2071,7 +2042,7 @@ public class DeviceProfile { mInsets.top + mDeviceProperties.getAvailableHeightPx()); } else { // Folders should only appear below the drop target bar and above the hotseat - int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx; + int hotseatTop = isTaskbarPresent ? getTaskbarProfile().getHeight() : hotseatBarSizePx; return new Rect(mInsets.left + edgeMarginPx, mInsets.top + getDropTargetProfile().getBarSizePx() + edgeMarginPx, mInsets.left + mDeviceProperties.getAvailableWidthPx() - edgeMarginPx, @@ -2272,10 +2243,12 @@ public class DeviceProfile { writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent); writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps); - writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight)); - writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight)); - writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin)); - writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize)); + writer.println(prefix + pxToDpStr("taskbarHeight", getTaskbarProfile().getHeight())); + writer.println(prefix + pxToDpStr("stashedTaskbarHeight", + getTaskbarProfile().getStashedTaskbarHeight())); + writer.println(prefix + pxToDpStr("taskbarBottomMargin", + getTaskbarProfile().getBottomMargin())); + writer.println(prefix + pxToDpStr("taskbarIconSize", getTaskbarProfile().getIconSize())); writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx", desiredWorkspaceHorizontalMarginPx)); @@ -2392,6 +2365,10 @@ public class DeviceProfile { } } + public TaskbarProfile getTaskbarProfile() { + return mTaskbarProfile; + } + public DropTargetProfile getDropTargetProfile() { return mDropTargetProfile; } diff --git a/src/com/android/launcher3/allapps/WorkUtilityView.java b/src/com/android/launcher3/allapps/WorkUtilityView.java index 9fcf3721a7..97f2e86dfa 100644 --- a/src/com/android/launcher3/allapps/WorkUtilityView.java +++ b/src/com/android/launcher3/allapps/WorkUtilityView.java @@ -166,7 +166,7 @@ public class WorkUtilityView extends LinearLayout implements Insettable, } if (!dp.getDeviceProperties().isGestureMode() && dp.isTaskbarPresent) { - bottomMargin += dp.taskbarHeight; + bottomMargin += dp.getTaskbarProfile().getHeight(); } lp.bottomMargin = bottomMargin; diff --git a/src/com/android/launcher3/deviceprofile/TaskbarProfile.kt b/src/com/android/launcher3/deviceprofile/TaskbarProfile.kt new file mode 100644 index 0000000000..301b79efde --- /dev/null +++ b/src/com/android/launcher3/deviceprofile/TaskbarProfile.kt @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2025 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.deviceprofile + +import android.content.res.Resources +import android.util.DisplayMetrics +import androidx.core.content.res.ResourcesCompat +import com.android.launcher3.InvariantDeviceProfile +import com.android.launcher3.R +import com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR +import com.android.launcher3.testing.shared.ResourceUtils.pxFromDp + +data class TaskbarProfile( + val height: Int, + val stashedTaskbarHeight: Int, + val bottomMargin: Int, + val iconSize: Int, + val transientTaskbarClaimedSpace: Int, + // If true, used to layout taskbar in 3 button navigation mode. + val isStartAlignTaskbar: Boolean, + val isTransientTaskbar: Boolean, +) { + companion object Factory { + fun createTaskbarProfile( + res: Resources, + isTransientTaskbar: Boolean, + isTaskbarPresent: Boolean, + metrics: DisplayMetrics, + displayOptionSpec: InvariantDeviceProfile.DisplayOptionSpec, + typeIndex: Int, + inv: InvariantDeviceProfile, + ): TaskbarProfile { + val transientTaskbarIconSize = + pxFromDp(inv.transientTaskbarIconSize.get(typeIndex), metrics) + val transientTaskbarBottomMargin: Int = + res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin) + val transientTaskbarHeight = + Math.round( + (transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR) + + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)) + ) + val transientTaskbarClaimedSpace = + transientTaskbarHeight + 2 * transientTaskbarBottomMargin + + return when { + !isTaskbarPresent -> TaskbarProfile( + bottomMargin = 0, + stashedTaskbarHeight = 0, + height = 0, + iconSize = 0, + isStartAlignTaskbar = false, + transientTaskbarClaimedSpace = transientTaskbarClaimedSpace, + isTransientTaskbar = isTransientTaskbar, + ) + isTransientTaskbar -> TaskbarProfile( + iconSize = transientTaskbarIconSize, + height = transientTaskbarHeight, + stashedTaskbarHeight = + res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height), + bottomMargin = transientTaskbarBottomMargin, + isStartAlignTaskbar = false, + transientTaskbarClaimedSpace = transientTaskbarClaimedSpace, + isTransientTaskbar = isTransientTaskbar, + ) + else -> TaskbarProfile( + iconSize = + pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size), metrics), + height = res.getDimensionPixelSize(R.dimen.taskbar_size), + stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size), + bottomMargin = 0, + isStartAlignTaskbar = displayOptionSpec.startAlignTaskbar, + isTransientTaskbar = isTransientTaskbar, + transientTaskbarClaimedSpace = transientTaskbarClaimedSpace, + ) + } + + } + } +} diff --git a/src/com/android/launcher3/util/DimensionUtils.kt b/src/com/android/launcher3/util/DimensionUtils.kt index 9941b66618..76df206127 100644 --- a/src/com/android/launcher3/util/DimensionUtils.kt +++ b/src/com/android/launcher3/util/DimensionUtils.kt @@ -38,7 +38,7 @@ object DimensionUtils { // Taskbar for large screen if (!isPhoneMode) { p.x = ViewGroup.LayoutParams.MATCH_PARENT - p.y = deviceProfile.taskbarHeight + p.y = deviceProfile.taskbarProfile.height return p } diff --git a/src/com/android/launcher3/views/Snackbar.java b/src/com/android/launcher3/views/Snackbar.java index 54aa6e429f..9edc7b2772 100644 --- a/src/com/android/launcher3/views/Snackbar.java +++ b/src/com/android/launcher3/views/Snackbar.java @@ -118,7 +118,7 @@ public class Snackbar extends AbstractFloatingView { DeviceProfile deviceProfile = activity.getDeviceProfile(); params.setMargins(0, 0, 0, marginBottom + (deviceProfile.isTaskbarPresent - ? deviceProfile.taskbarHeight + deviceProfile.getTaskbarOffsetY() + ? deviceProfile.getTaskbarProfile().getHeight() + deviceProfile.getTaskbarOffsetY() : insets.bottom)); TextView labelView = snackbar.findViewById(R.id.label); From 4bbf978043c043ae381c46812c1bcc127f45a900 Mon Sep 17 00:00:00 2001 From: Catherine Liang Date: Wed, 28 May 2025 19:11:15 +0000 Subject: [PATCH 09/20] Move custom Launcher theme flag to shared SysUI package (1/3) This allows the flag to be shared with Customization Picker. Flag: com.android.systemui.shared.extendible_theme_manager Test: manually verified by building w/ soong and gradle Test: manually verified by flipping flag Bug: 397782741 Change-Id: I131f54602e33dd2b92ce0068f5fc43da3e150a01 --- aconfig/launcher.aconfig | 7 ------- .../launcher3/graphics/LauncherPreviewRenderer.java | 2 +- .../launcher3/graphics/PreviewSurfaceRenderer.java | 2 +- tests/Android.bp | 3 +++ .../src/com/android/launcher3/icons/IconCacheTest.java | 8 ++++---- .../android/launcher3/icons/cache/CacheLookupFlagTest.kt | 6 +++--- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index 062e5ed687..7c8e5fdbd2 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -517,13 +517,6 @@ flag { bug: "394651876" } -flag { - name: "extendible_theme_manager" - namespace: "launcher" - description: "Enables custom theme manager in Launcher" - bug: "381897614" -} - flag { name: "enable_alt_tab_kqs_flatenning" namespace: "lse_desktop_experience" diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 74749f02a6..d2852c6d90 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -20,7 +20,6 @@ import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.makeMeasureSpec; import static android.view.View.VISIBLE; -import static com.android.launcher3.Flags.extendibleThemeManager; import static com.android.launcher3.Hotseat.ALPHA_CHANNEL_PREVIEW_RENDERER; import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE; import static com.android.launcher3.LauncherPrefs.GRID_NAME; @@ -29,6 +28,7 @@ import static com.android.launcher3.graphics.ThemeManager.PREF_ICON_SHAPE; import static com.android.launcher3.graphics.ThemeManager.THEMED_ICONS; import static com.android.launcher3.model.ModelUtils.currentScreenContentFilter; import static com.android.launcher3.widget.LauncherWidgetHolder.APPWIDGET_HOST_ID; +import static com.android.systemui.shared.Flags.extendibleThemeManager; import static java.util.Comparator.comparingDouble; diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index 0d2dfad2d5..d1cafb1385 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -20,7 +20,6 @@ import static android.content.res.Configuration.UI_MODE_NIGHT_NO; import static android.content.res.Configuration.UI_MODE_NIGHT_YES; import static android.view.Display.DEFAULT_DISPLAY; -import static com.android.launcher3.Flags.extendibleThemeManager; import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.LauncherPrefs.NON_FIXED_LANDSCAPE_GRID_NAME; import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID; @@ -30,6 +29,7 @@ import static com.android.launcher3.provider.LauncherDbUtils.selectionForWorkspa import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import static com.android.launcher3.widget.LauncherWidgetHolder.APPWIDGET_HOST_ID; +import static com.android.systemui.shared.Flags.extendibleThemeManager; import android.app.WallpaperColors; import android.appwidget.AppWidgetHost; diff --git a/tests/Android.bp b/tests/Android.bp index 09bc9f3b13..2570f59f4f 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -90,6 +90,7 @@ android_library { "testables", "com_android_launcher3_flags_lib", "com_android_wm_shell_flags_lib", + "com_android_systemui_shared_flags_lib", "android.appwidget.flags-aconfig-java", "platform-parametric-runner-lib", "kotlin-reflect", @@ -124,6 +125,7 @@ android_test { static_libs: [ "Launcher3TestLib", "com_android_launcher3_flags_lib", + "com_android_systemui_shared_flags_lib", ], libs: [ "android.test.base.stubs.system", @@ -197,6 +199,7 @@ android_robolectric_test { "flag-junit", "com_android_launcher3_flags_lib", "com_android_wm_shell_flags_lib", + "com_android_systemui_shared_flags_lib", "androidx.test.uiautomator_uiautomator", "androidx.core_core-animation-testing", "androidx.test.ext.junit", diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java index 86ea9fd5f1..b5e8b31f6c 100644 --- a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java @@ -28,6 +28,7 @@ import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY; import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY2; import static com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE; import static com.android.launcher3.util.TestUtil.runOnExecutorSync; +import static com.android.systemui.shared.Flags.FLAG_EXTENDIBLE_THEME_MANAGER; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -59,7 +60,6 @@ import androidx.annotation.Nullable; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; -import com.android.launcher3.Flags; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.icons.cache.IconCacheUpdateHandler; @@ -284,7 +284,7 @@ public class IconCacheTest { } @Test - @EnableFlags(Flags.FLAG_EXTENDIBLE_THEME_MANAGER) + @EnableFlags(FLAG_EXTENDIBLE_THEME_MANAGER) public void theme_icon_not_returned_if_not_requested() { ComponentName cn = new ComponentName(TEST_PACKAGE, TEST_ACTIVITY); UserHandle user = myUserHandle(); @@ -302,7 +302,7 @@ public class IconCacheTest { } @Test - @EnableFlags(Flags.FLAG_EXTENDIBLE_THEME_MANAGER) + @EnableFlags(FLAG_EXTENDIBLE_THEME_MANAGER) public void theme_icon_returned_if_requested() { ComponentName cn = new ComponentName(TEST_PACKAGE, TEST_ACTIVITY); UserHandle user = myUserHandle(); @@ -320,7 +320,7 @@ public class IconCacheTest { } @Test - @DisableFlags(Flags.FLAG_EXTENDIBLE_THEME_MANAGER) + @DisableFlags(FLAG_EXTENDIBLE_THEME_MANAGER) public void theme_icon_returned_if_not_requested_with_flag_off() { ComponentName cn = new ComponentName(TEST_PACKAGE, TEST_ACTIVITY); UserHandle user = myUserHandle(); diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt b/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt index 1794c775dc..cb26385c33 100644 --- a/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt @@ -21,8 +21,8 @@ import android.platform.test.annotations.EnableFlags import android.platform.test.flag.junit.SetFlagsRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest -import com.android.launcher3.Flags import com.android.launcher3.icons.cache.CacheLookupFlag.Companion.DEFAULT_LOOKUP_FLAG +import com.android.systemui.shared.Flags.FLAG_EXTENDIBLE_THEME_MANAGER import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Rule @@ -107,14 +107,14 @@ class CacheLookupFlagTest { ) } - @DisableFlags(Flags.FLAG_EXTENDIBLE_THEME_MANAGER) + @DisableFlags(FLAG_EXTENDIBLE_THEME_MANAGER) @Test fun `isVisuallyLessThan does not depend on theme with flag off`() { assertFalse(DEFAULT_LOOKUP_FLAG.withThemeIcon().isVisuallyLessThan(DEFAULT_LOOKUP_FLAG)) assertFalse(DEFAULT_LOOKUP_FLAG.isVisuallyLessThan(DEFAULT_LOOKUP_FLAG.withThemeIcon())) } - @EnableFlags(Flags.FLAG_EXTENDIBLE_THEME_MANAGER) + @EnableFlags(FLAG_EXTENDIBLE_THEME_MANAGER) @Test fun `isVisuallyLessThan depends on theme with flag on`() { assertFalse(DEFAULT_LOOKUP_FLAG.withThemeIcon().isVisuallyLessThan(DEFAULT_LOOKUP_FLAG)) From 05fa101519d03f279175f358a0d7e0cadabbae99 Mon Sep 17 00:00:00 2001 From: "Xiaoqian (Daisy) Dai" Date: Wed, 28 May 2025 10:28:00 -0700 Subject: [PATCH 10/20] desktop-exploded-view: Expand touch area for the task header close button According to the spec, the hit rect of the close button should be 32dp. Flag: com.android.launcher3.enable_desktop_exploded_view Test: Manual Bug: 420930786 Change-Id: I2a066c03ba728780520ce95648c20103376c73c7 --- quickstep/res/values/dimens.xml | 1 + .../android/quickstep/views/TaskHeaderView.kt | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 61c5f40dc2..81b5d9873e 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -91,6 +91,7 @@ 12dp 8dp 18dp + 32dp 16dp 24dp diff --git a/quickstep/src/com/android/quickstep/views/TaskHeaderView.kt b/quickstep/src/com/android/quickstep/views/TaskHeaderView.kt index 1fda5a3ace..bb0044161d 100644 --- a/quickstep/src/com/android/quickstep/views/TaskHeaderView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskHeaderView.kt @@ -17,7 +17,9 @@ package com.android.quickstep.views import android.content.Context +import android.graphics.Rect import android.util.AttributeSet +import android.view.TouchDelegate import android.widget.ImageButton import android.widget.ImageView import android.widget.TextView @@ -33,6 +35,29 @@ class TaskHeaderView @JvmOverloads constructor(context: Context, attrs: Attribut private val headerIconView: ImageView by lazy { findViewById(R.id.header_app_icon) } private val headerCloseButton: ImageButton by lazy { findViewById(R.id.header_close_button) } + override fun onFinishInflate() { + super.onFinishInflate() + // Post to ensure the button has been laid out and has its dimensions. + headerCloseButton.post { + val delegateArea = Rect() + headerCloseButton.getHitRect(delegateArea) + + // Calculate the desired touch area size in pixels. + val touchTargetSize = + resources.getDimensionPixelSize( + R.dimen.task_thumbnail_header_close_button_hit_rect_size + ) + + // Expand the hit rect to the desired touch target size, centered on the button. + val sizeDifferenceX = (touchTargetSize - delegateArea.width()) / 2 + val sizeDifferenceY = (touchTargetSize - delegateArea.height()) / 2 + delegateArea.inset(-sizeDifferenceX, -sizeDifferenceY) + + // The TouchDelegate is set on the parent `TaskHeaderView`. + touchDelegate = TouchDelegate(delegateArea, headerCloseButton) + } + } + fun setState(taskHeaderState: TaskHeaderUiState) { when (taskHeaderState) { is TaskHeaderUiState.ShowHeader -> { From 45101ddfb51e7b89d87a5ec4b2e7466ff64cbf1f Mon Sep 17 00:00:00 2001 From: Matthew Mourgos Date: Wed, 28 May 2025 23:16:59 -0700 Subject: [PATCH 11/20] Navigate Home to hide tasks on WidgetPicker show When the widget picker is shown while the show_home_behind_desktop feature is enabled, it becomes possible for the widget picker to be opened while freeform tasks are occluding the home screen. To fix this case, navigate Home to move it in front of occluding tasks, and then open the widget picker. Navigating home is an asynchronous action, and widget picker will already be opening once the intent executes, so exlude closing the widget picker when closing all AbstractFloatingViews in this case. This change is intended for the desktop form factor. Bug: 416057590 Flag: com.android.window.flags.show_home_behind_desktop Test: Open freeform tasks, open WidgetPicker via menu, make sure that tasks are hidden and WidgetPicker shows. Change-Id: I19ebeeb706ae7374df8038d956d453708bc96f7e --- src/com/android/launcher3/Launcher.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index abc18f4061..70ddeb90b3 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -293,6 +293,9 @@ public class Launcher extends StatefulActivity public static final String INTENT_ACTION_ALL_APPS_TOGGLE = "launcher.intent_action_all_apps_toggle"; + private static final String EXCLUDE_CLOSE_WIDGET_PICKER = + "launcher.extra.EXCLUDE_CLOSE_WIDGET_PICKER"; + private StateManager mStateManager; private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; @@ -403,7 +406,6 @@ public class Launcher extends StatefulActivity protected WallpaperThemeManager mWallpaperThemeManager; - private boolean mIsTopResumedActivity; public static Launcher getLauncher(Context context) { @@ -1527,8 +1529,12 @@ public class Launcher extends StatefulActivity if (isActionMain) { if (!internalStateHandled) { // In all these cases, only animate if we're already on home - AbstractFloatingView.closeAllOpenViewsExcept( - this, isStarted(), AbstractFloatingView.TYPE_LISTENER); + int excludedViews = AbstractFloatingView.TYPE_LISTENER; + if (intent.getBooleanExtra(EXCLUDE_CLOSE_WIDGET_PICKER, false)) { + excludedViews |= TYPE_WIDGETS_FULL_SHEET; + } + AbstractFloatingView.closeAllOpenViewsExcept(this, isStarted(), excludedViews); + if (!isInState(NORMAL)) { // Only change state, if not already the same. This prevents cancelling any @@ -2893,6 +2899,13 @@ public class Launcher extends StatefulActivity if (floatingView != null) { return (WidgetsFullSheet) floatingView; } + if (shouldShowHomeBehindDesktop() && !mIsTopResumedActivity) { + Intent intent = new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_HOME) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .putExtra(EXCLUDE_CLOSE_WIDGET_PICKER, true); + startActivity(intent); + } return WidgetsFullSheet.show(this, true /* animated */); } From e61df48651a04c8c7c33d26086cf28c6f7362eb8 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Thu, 29 May 2025 13:26:00 -0700 Subject: [PATCH 12/20] Wire the compose based widget picker in widget picker activity - Uses new picker behind a flag. - Includes appropriate implementation of picker module based on whether compose is enabled. Bug: 408283627 Flag: EXEMPT independent module Test: Upcoming in follow up cls Change-Id: I13e69379bc89c6d2e6909f9d11937997affc6a58 --- Android.bp | 8 +- .../widgetpicker/NoOpWidgetPickerModule.kt | 30 +++++ .../WidgetPickerComposeWrapper.kt | 38 ++++++ .../LauncherWidgetPickerModule.kt | 26 ++++ .../LauncherWidgetPickerModule.kt | 63 ++++++++++ .../WidgetPickerComposeWrapperImpl.kt | 119 ++++++++++++++++++ .../launcher3/dagger/LauncherAppModule.java | 2 + .../dagger/LauncherBaseAppComponent.java | 5 +- .../graphics/LauncherPreviewRenderer.java | 2 + .../widgetpicker/WidgetPickerActivity.kt | 2 +- 10 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 compose/facade/core/widgetpicker/NoOpWidgetPickerModule.kt create mode 100644 compose/facade/core/widgetpicker/WidgetPickerComposeWrapper.kt create mode 100644 compose/facade/disabled/widgetpicker/LauncherWidgetPickerModule.kt create mode 100644 compose/facade/enabled/widgetpicker/LauncherWidgetPickerModule.kt create mode 100644 compose/features/com/android/launcher3/widgetpicker/WidgetPickerComposeWrapperImpl.kt diff --git a/Android.bp b/Android.bp index daf87eb914..e8a4606e29 100644 --- a/Android.bp +++ b/Android.bp @@ -47,8 +47,8 @@ filegroup { filegroup { name: "launcher-compose-enabled-src", srcs: [ - "compose/facade/enabled/*.kt", - "compose/facade/core/*.kt", + "compose/facade/enabled/**/*.kt", + "compose/facade/core/**/*.kt", "compose/features/**/*.kt", ], } @@ -56,8 +56,8 @@ filegroup { filegroup { name: "launcher-compose-disabled-src", srcs: [ - "compose/facade/core/*.kt", - "compose/facade/disabled/*.kt", + "compose/facade/core/**/*.kt", + "compose/facade/disabled/**/*.kt", ], } diff --git a/compose/facade/core/widgetpicker/NoOpWidgetPickerModule.kt b/compose/facade/core/widgetpicker/NoOpWidgetPickerModule.kt new file mode 100644 index 0000000000..3cba82d54e --- /dev/null +++ b/compose/facade/core/widgetpicker/NoOpWidgetPickerModule.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2025 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.compose.core.widgetpicker + +import dagger.Binds +import dagger.Module + +/** + * A module that provides a no-op [WidgetPickerComposeWrapper] for dagger graph that doesn't + * involve widget picker e.g. launcher preview OR when compose is disabled via build flag. + */ +@Module +interface NoOpWidgetPickerModule { + @Binds + fun bindWidgetPickerWrapper(noOp: NoOpWidgetPickerComposeWrapper): WidgetPickerComposeWrapper +} \ No newline at end of file diff --git a/compose/facade/core/widgetpicker/WidgetPickerComposeWrapper.kt b/compose/facade/core/widgetpicker/WidgetPickerComposeWrapper.kt new file mode 100644 index 0000000000..452d8881e5 --- /dev/null +++ b/compose/facade/core/widgetpicker/WidgetPickerComposeWrapper.kt @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 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.compose.core.widgetpicker + +import com.android.launcher3.widgetpicker.WidgetPickerActivity +import javax.inject.Inject + +/** + * A wrapper for widget picker activity that is responsible for displaying the compose based + * widget picker in [WidgetPickerActivity] when compose is enabled via build flag. + */ +interface WidgetPickerComposeWrapper { + fun showAllWidgets(activity: WidgetPickerActivity) +} + +/** + * A No-op [WidgetPickerComposeWrapper] that doesn't include widget picker in dagger graph that + * don't involve widget picker e.g. launcher preview OR when compose is disabled via build flag. + */ +class NoOpWidgetPickerComposeWrapper @Inject constructor() : WidgetPickerComposeWrapper { + override fun showAllWidgets(activity: WidgetPickerActivity) { + error("Widget picker with compose is not supported") + } +} diff --git a/compose/facade/disabled/widgetpicker/LauncherWidgetPickerModule.kt b/compose/facade/disabled/widgetpicker/LauncherWidgetPickerModule.kt new file mode 100644 index 0000000000..65635817e0 --- /dev/null +++ b/compose/facade/disabled/widgetpicker/LauncherWidgetPickerModule.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2025 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.compose.widgetpicker + +import com.android.launcher3.compose.core.widgetpicker.NoOpWidgetPickerModule +import dagger.Module + +/** + * A no-op module that is used when compose is disabled in launcher. + */ +@Module(includes = [NoOpWidgetPickerModule::class]) +class LauncherWidgetPickerModule diff --git a/compose/facade/enabled/widgetpicker/LauncherWidgetPickerModule.kt b/compose/facade/enabled/widgetpicker/LauncherWidgetPickerModule.kt new file mode 100644 index 0000000000..7694077760 --- /dev/null +++ b/compose/facade/enabled/widgetpicker/LauncherWidgetPickerModule.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2025 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.compose.widgetpicker + +import com.android.launcher3.compose.core.widgetpicker.WidgetPickerComposeWrapper +import com.android.launcher3.widgetpicker.WidgetPickerComponent +import com.android.launcher3.widgetpicker.WidgetPickerComposeWrapperImpl +import com.android.launcher3.widgetpicker.data.repository.WidgetAppIconsRepository +import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository +import com.android.launcher3.widgetpicker.data.repository.WidgetsRepository +import com.android.launcher3.widgetpicker.datasource.ConfigResourceFeaturedWidgetsDataSource +import com.android.launcher3.widgetpicker.datasource.FeaturedWidgetsDataSource +import com.android.launcher3.widgetpicker.datasource.InMemoryWidgetSearchAlgorithm +import com.android.launcher3.widgetpicker.datasource.WidgetsSearchAlgorithm +import com.android.launcher3.widgetpicker.repository.WidgetsRepositoryImpl +import com.android.launcher3.widgetpicker.repository.WidgetAppIconsRepositoryImpl +import com.android.launcher3.widgetpicker.repository.WidgetUsersRepositoryImpl +import dagger.Binds +import dagger.Module + +/** + * A module that installs widget picker for launcher. + */ +@Module(subcomponents = [WidgetPickerComponent::class]) +interface LauncherWidgetPickerModule { + @Binds + fun bindWidgetPickerComposeWrapper( + impl: WidgetPickerComposeWrapperImpl + ): WidgetPickerComposeWrapper + + @Binds + fun bindWidgetUsersRepository(impl: WidgetUsersRepositoryImpl): WidgetUsersRepository + + @Binds + fun bindWidgetsRepository(impl: WidgetsRepositoryImpl): WidgetsRepository + + @Binds + fun bindWidgetAppIconsRepository(impl: WidgetAppIconsRepositoryImpl): WidgetAppIconsRepository + + @Binds + fun bindFeaturedWidgetsDataSource( + impl: ConfigResourceFeaturedWidgetsDataSource + ): FeaturedWidgetsDataSource + + @Binds + fun bindWidgetsSearchAlgorithm( + impl: InMemoryWidgetSearchAlgorithm + ): WidgetsSearchAlgorithm +} diff --git a/compose/features/com/android/launcher3/widgetpicker/WidgetPickerComposeWrapperImpl.kt b/compose/features/com/android/launcher3/widgetpicker/WidgetPickerComposeWrapperImpl.kt new file mode 100644 index 0000000000..d4d67edb55 --- /dev/null +++ b/compose/features/com/android/launcher3/widgetpicker/WidgetPickerComposeWrapperImpl.kt @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2025 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.widgetpicker + +import android.content.Context +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.LocalView +import com.android.launcher3.R +import com.android.launcher3.widgetpicker.WidgetPickerActivity +import com.android.launcher3.compose.ComposeFacade +import com.android.launcher3.compose.core.widgetpicker.WidgetPickerComposeWrapper +import com.android.launcher3.concurrent.annotations.BackgroundContext +import com.android.launcher3.dagger.ApplicationContext +import com.android.launcher3.widgetpicker.WidgetPickerComponent +import com.android.launcher3.widgetpicker.WidgetPickerEventListeners +import com.android.launcher3.widgetpicker.data.repository.WidgetAppIconsRepository +import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository +import com.android.launcher3.widgetpicker.data.repository.WidgetsRepository +import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo +import kotlinx.coroutines.launch +import javax.inject.Inject +import javax.inject.Provider +import kotlin.coroutines.CoroutineContext + +/** + * An helper that bootstraps widget picker UI (from [WidgetPickerComponent]) in to + * [WidgetPickerActivity]. + * + * Sets up the bindings necessary for widget picker component. + */ +class WidgetPickerComposeWrapperImpl @Inject constructor( + private val widgetPickerComponentProvider: Provider, + private val widgetsRepository: WidgetsRepository, + private val widgetUsersRepository: WidgetUsersRepository, + private val widgetAppIconsRepository: WidgetAppIconsRepository, + @BackgroundContext + private val backgroundContext: CoroutineContext, + @ApplicationContext + private val appContext: Context, +) : WidgetPickerComposeWrapper { + override fun showAllWidgets( + activity: WidgetPickerActivity, + ) { + val widgetPickerComponent = newWidgetPickerComponent() + val callbacks = object : WidgetPickerEventListeners { + override fun onClose() { + activity.finish() + } + } + + val fullWidgetsCatalog = widgetPickerComponent.getFullWidgetsCatalog() + val composeView = ComposeFacade.initComposeView(activity.asContext()) as ComposeView + composeView.apply { + setContent { + val scope = rememberCoroutineScope() + val view = LocalView.current + + MaterialTheme { // TODO(b/408283627): Use launcher theme. + val eventListeners = remember { callbacks } + fullWidgetsCatalog.Content(eventListeners) + } + + DisposableEffect(view) { + scope.launch { + initializeRepositories() + } + + onDispose { + cleanUpRepositories() + } + } + } + } + + activity.dragLayer?.addView(composeView) + } + + private fun newWidgetPickerComponent(): WidgetPickerComponent = + widgetPickerComponentProvider.get() + .build( + widgetsRepository = widgetsRepository, + widgetUsersRepository = widgetUsersRepository, + widgetAppIconsRepository = widgetAppIconsRepository, + widgetHostInfo = WidgetHostInfo( + appContext.resources.getString(R.string.widget_button_text) + ), + backgroundContext = backgroundContext + ) + + private fun initializeRepositories() { + widgetsRepository.initialize() + widgetUsersRepository.initialize() + widgetAppIconsRepository.initialize() + } + + private fun cleanUpRepositories() { + widgetsRepository.cleanUp() + widgetUsersRepository.cleanUp() + widgetAppIconsRepository.cleanUp() + } +} diff --git a/src/com/android/launcher3/dagger/LauncherAppModule.java b/src/com/android/launcher3/dagger/LauncherAppModule.java index de798fd9f7..54e532758b 100644 --- a/src/com/android/launcher3/dagger/LauncherAppModule.java +++ b/src/com/android/launcher3/dagger/LauncherAppModule.java @@ -16,6 +16,7 @@ package com.android.launcher3.dagger; +import com.android.launcher3.compose.widgetpicker.LauncherWidgetPickerModule; import com.android.launcher3.concurrent.ExecutorsModule; import com.android.launcher3.util.dagger.LauncherExecutorsModule; @@ -33,6 +34,7 @@ import dagger.Module; LauncherConcurrencyModule.class, ExecutorsModule.class, LauncherExecutorsModule.class, + LauncherWidgetPickerModule.class }, subcomponents = ActivityContextComponent.class) public class LauncherAppModule { } diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java index 10806f6083..ce3082c4ac 100644 --- a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java +++ b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java @@ -25,6 +25,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherPrefs; import com.android.launcher3.RemoveAnimationSettingsTracker; import com.android.launcher3.backuprestore.LauncherRestoreEventLogger; +import com.android.launcher3.compose.core.widgetpicker.WidgetPickerComposeWrapper; import com.android.launcher3.folder.FolderNameSuggestionLoader; import com.android.launcher3.graphics.GridCustomizationsProxy; import com.android.launcher3.graphics.ThemeManager; @@ -100,7 +101,9 @@ public interface LauncherBaseAppComponent { InstantAppResolver getInstantAppResolver(); DumpManager getDumpManager(); StatsLogManager.StatsLogManagerFactory getStatsLogManagerFactory(); - ActivityContextComponent.Builder getActivityContextComponentBuilder(); + ActivityContextComponent.Builder getActivityContextComponentBuilder(); + WidgetPickerComposeWrapper getWidgetPickerComposeWrapper(); + /** Builder for LauncherBaseAppComponent. */ interface Builder { diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index ca404ea451..60861b0c26 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -71,6 +71,7 @@ import com.android.launcher3.R; import com.android.launcher3.WorkspaceLayoutManager; import com.android.launcher3.celllayout.CellLayoutLayoutParams; import com.android.launcher3.celllayout.CellPosMapper; +import com.android.launcher3.compose.core.widgetpicker.NoOpWidgetPickerModule; import com.android.launcher3.concurrent.ExecutorsModule; import com.android.launcher3.dagger.ApiWrapperModule; import com.android.launcher3.dagger.AppModule; @@ -546,6 +547,7 @@ public class LauncherPreviewRenderer extends BaseContext LauncherConcurrencyModule.class, ExecutorsModule.class, LauncherExecutorsModule.class, + NoOpWidgetPickerModule.class }) public interface PreviewAppComponent extends LauncherAppComponent { diff --git a/src/com/android/launcher3/widgetpicker/WidgetPickerActivity.kt b/src/com/android/launcher3/widgetpicker/WidgetPickerActivity.kt index 36c6d10b86..cc67fcd257 100644 --- a/src/com/android/launcher3/widgetpicker/WidgetPickerActivity.kt +++ b/src/com/android/launcher3/widgetpicker/WidgetPickerActivity.kt @@ -50,7 +50,7 @@ open class WidgetPickerActivity : BaseActivity() { checkNotNull(_dragLayer).recreateControllers() if (Flags.enableWidgetPickerRefactor() && isComposeAvailable()) { - // TODO(b/408283627): add compose picker here. + component.widgetPickerComposeWrapper.showAllWidgets(this) } } From 9d946aa755a327ab767a547f9924cfcbf410afd3 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Wed, 28 May 2025 07:02:17 -0700 Subject: [PATCH 13/20] Add no-op widget picker module to some test modules / graphs. Bug: 408283627 Flag: EXEMPT not applicable Test: dagger build Change-Id: I77b2f9f32037303ddfd7f2950c7b235f9aff8f2c --- .../android/launcher3/taskbar/rules/TaskbarSandboxComponent.kt | 2 ++ .../src/com/android/launcher3/util/DaggerGraphs.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarSandboxComponent.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarSandboxComponent.kt index 6371f9ad28..441e571523 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarSandboxComponent.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarSandboxComponent.kt @@ -22,6 +22,7 @@ import com.android.launcher3.Flags import com.android.launcher3.LauncherPrefChangeListener import com.android.launcher3.LauncherPrefs import com.android.launcher3.LauncherPrefs.Companion.TASKBAR_PINNING +import com.android.launcher3.compose.core.widgetpicker.NoOpWidgetPickerModule import com.android.launcher3.concurrent.ExecutorsModule import com.android.launcher3.dagger.ApiWrapperModule import com.android.launcher3.dagger.AppModule @@ -86,6 +87,7 @@ interface TaskbarSandboxComponent : LauncherAppComponent { TaskbarSandboxWmProxyModule::class, TaskbarPerDisplayReposModule::class, DesktopVisibilityControllerModule::class, + NoOpWidgetPickerModule::class, ] ) interface AllTaskbarSandboxModules diff --git a/tests/multivalentTests/src/com/android/launcher3/util/DaggerGraphs.kt b/tests/multivalentTests/src/com/android/launcher3/util/DaggerGraphs.kt index f268b08887..148f0a178d 100644 --- a/tests/multivalentTests/src/com/android/launcher3/util/DaggerGraphs.kt +++ b/tests/multivalentTests/src/com/android/launcher3/util/DaggerGraphs.kt @@ -18,6 +18,7 @@ package com.android.launcher3.util import com.android.launcher3.FakeLauncherPrefs import com.android.launcher3.LauncherPrefs +import com.android.launcher3.compose.core.widgetpicker.NoOpWidgetPickerModule import com.android.launcher3.concurrent.ExecutorsModule import com.android.launcher3.util.dagger.LauncherExecutorsModule import com.android.launcher3.dagger.ApiWrapperModule @@ -47,6 +48,7 @@ abstract class FakePrefsModule { LauncherConcurrencyModule::class, ExecutorsModule::class, LauncherExecutorsModule::class, + NoOpWidgetPickerModule::class ] ) class CommonModulesForTest From 97cbe1c1320fb4d86f3017f3dc351cc0bf93fd3d Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Wed, 28 May 2025 11:48:33 -0700 Subject: [PATCH 14/20] Add dagger2-compiler to some of picker module targets. Also mark factories with widget picker annotation. Bug: 408283627 Flag: EXEMPT independent module Test: dagger compilation Change-Id: I716e6cd2eefe44db9a597a80329631484089e84b --- Android.bp | 1 + modules/widgetpicker/Android.bp | 2 ++ .../widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt | 2 ++ .../ui/fullcatalog/screens/landing/LandingScreenViewModel.kt | 2 ++ .../ui/fullcatalog/screens/search/SearchScreenViewModel.kt | 2 ++ 5 files changed, 9 insertions(+) diff --git a/Android.bp b/Android.bp index e8a4606e29..250744ae8a 100644 --- a/Android.bp +++ b/Android.bp @@ -264,6 +264,7 @@ launcher_compose_tests_java_defaults { ], // Compose dependencies static_libs: [ + "widget_picker_component", "androidx.compose.runtime_runtime", "androidx.compose.ui_ui-test-junit4", "androidx.compose.ui_ui-test-manifest", diff --git a/modules/widgetpicker/Android.bp b/modules/widgetpicker/Android.bp index 379cb1de38..0342ea6e14 100644 --- a/modules/widgetpicker/Android.bp +++ b/modules/widgetpicker/Android.bp @@ -124,6 +124,7 @@ android_library { name: "widget_picker_ui_components", sdk_version: "current", min_sdk_version: min_launcher3_sdk_version, + plugins: ["dagger2-compiler"], srcs: [ "src/com/android/launcher3/widgetpicker/ui/components/ScrollableFloatingToolbar.kt", "src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt", @@ -164,6 +165,7 @@ android_library { android_library { name: "widget_picker_ui", sdk_version: "current", + plugins: ["dagger2-compiler"], min_sdk_version: min_launcher3_sdk_version, srcs: [ "src/com/android/launcher3/widgetpicker/ui/ViewModel.kt", diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt index 26d57f9d43..0851a0d599 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt @@ -20,6 +20,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.android.launcher3.widgetpicker.WidgetPickerHostInfo +import com.android.launcher3.widgetpicker.WidgetPickerSingleton import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo import com.android.launcher3.widgetpicker.ui.ViewModel import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenViewModel @@ -61,6 +62,7 @@ class FullWidgetsCatalogViewModel @AssistedInject constructor( } @AssistedFactory + @WidgetPickerSingleton interface Factory { fun create(): FullWidgetsCatalogViewModel } diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenViewModel.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenViewModel.kt index 22356dd21c..7d6fa25f9a 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenViewModel.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenViewModel.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow +import com.android.launcher3.widgetpicker.WidgetPickerSingleton import com.android.launcher3.widgetpicker.domain.interactor.WidgetAppIconsInteractor import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor import com.android.launcher3.widgetpicker.shared.model.WidgetAppIcon @@ -233,6 +234,7 @@ class LandingScreenViewModel @AssistedInject constructor( /** A factory that should be injected whenever [LandingScreenViewModel] is required. */ @AssistedFactory + @WidgetPickerSingleton interface Factory { fun create(): LandingScreenViewModel } diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreenViewModel.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreenViewModel.kt index f2b18bdb29..ab7a8fcd39 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreenViewModel.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreenViewModel.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow +import com.android.launcher3.widgetpicker.WidgetPickerSingleton import com.android.launcher3.widgetpicker.domain.interactor.WidgetAppIconsInteractor import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor import com.android.launcher3.widgetpicker.shared.model.WidgetAppId @@ -142,6 +143,7 @@ class SearchScreenViewModel @AssistedInject constructor( /** A factory that should be injected whenever [SearchScreenViewModel] is required. */ @AssistedFactory + @WidgetPickerSingleton interface Factory { fun create(): SearchScreenViewModel } From 931021258274ca8f444cf49ab59ba9ce06267efe Mon Sep 17 00:00:00 2001 From: mpodolian Date: Thu, 29 May 2025 11:18:55 -0700 Subject: [PATCH 15/20] Notify Taskbar and Navigation bar of the bubble bar location updates. Added logic to notify the BubbleBarLocationListeners (Taskbar and Navigation bar) of bubble bar location animated. Fixes: 420929193 Test: Manual. Use unfolded foldable device. Set 3 buttons navigation mode. Go to the launcher overview screen. Create any application bubble. Drag bubble to the opposite side of the screen - observe navigation buttons bar updates its location with the bubble bar. Add one more application bubble. Drag bubble from the expanded bubble bar. Observe navigation bar position is updated with the bubble bar. Flag: EXEMPT - bugfix Change-Id: I2bbdcdd702141b19695480e87d6cdd456e834e11 --- .../launcher3/taskbar/bubbles/BubbleControllers.java | 2 +- .../taskbar/bubbles/BubbleDragController.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java index 0a68478fc0..b7df9a6f33 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java @@ -118,7 +118,7 @@ public class BubbleControllers { .get(ALPHA_INDEX_BUBBLE_BAR); } }); - bubbleDragController.init(/* bubbleControllers = */ this); + bubbleDragController.init(/* bubbleControllers = */ this, bubbleBarLocationListeners); bubbleDismissController.init(/* bubbleControllers = */ this); bubbleBarPinController.init(this, bubbleBarLocationListeners); bubblePinController.init(this); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java index 41686deeee..7535d366cc 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java @@ -30,6 +30,7 @@ import androidx.annotation.Nullable; import androidx.dynamicanimation.animation.FloatPropertyCompat; import com.android.launcher3.taskbar.TaskbarActivityContext; +import com.android.launcher3.taskbar.bubbles.BubbleBarController.BubbleBarLocationListener; import com.android.wm.shell.shared.bubbles.BaseBubblePinController.LocationChangeListener; import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; @@ -89,6 +90,7 @@ public class BubbleDragController { private BubbleDismissController mBubbleDismissController; private BubbleBarPinController mBubbleBarPinController; private BubblePinController mBubblePinController; + private BubbleBarLocationListener mBubbleBarLocationListener; private final DropTargetManager mDropTargetManager; private final DragZoneFactory mDragZoneFactory; private final BubbleDragZoneChangedListener mBubbleDragZoneChangedListener; @@ -143,12 +145,14 @@ public class BubbleDragController { * Should be careful to only access things that were created in constructors for now, as some * controllers may still be waiting for init(). */ - public void init(@NonNull BubbleControllers bubbleControllers) { + public void init(@NonNull BubbleControllers bubbleControllers, + BubbleBarLocationListener bubbleBarLocationListener) { mBubbleBarController = bubbleControllers.bubbleBarController; mBubbleBarViewController = bubbleControllers.bubbleBarViewController; mBubbleDismissController = bubbleControllers.bubbleDismissController; mBubbleBarPinController = bubbleControllers.bubbleBarPinController; mBubblePinController = bubbleControllers.bubblePinController; + mBubbleBarLocationListener = bubbleBarLocationListener; mBubbleDismissController.setListener( stuck -> { if (stuck) { @@ -690,13 +694,19 @@ public class BubbleDragController { if (to instanceof DragZone.Bubble.Left && mBubbleBarLocation != BubbleBarLocation.LEFT) { if (draggedObject instanceof DraggedObject.Bubble) { + // listener will be notified by BubbleBarController mBubbleBarController.animateBubbleBarLocation(BubbleBarLocation.LEFT); + } else { + // otherwise notify listener manually + mBubbleBarLocationListener.onBubbleBarLocationAnimated(BubbleBarLocation.LEFT); } mBubbleBarLocation = BubbleBarLocation.LEFT; } else if (to instanceof DragZone.Bubble.Right && mBubbleBarLocation != BubbleBarLocation.RIGHT) { if (draggedObject instanceof DraggedObject.Bubble) { mBubbleBarController.animateBubbleBarLocation(BubbleBarLocation.RIGHT); + } else { + mBubbleBarLocationListener.onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT); } mBubbleBarLocation = BubbleBarLocation.RIGHT; } From 6f8224805320306a1dbe15816a5a2228fc61b222 Mon Sep 17 00:00:00 2001 From: mpodolian Date: Wed, 28 May 2025 14:05:16 -0700 Subject: [PATCH 16/20] Notify taskbar and nav bar of bubble bar location updates. Added logic to notify the BubbleBarLocationListener implementors on bubble bar location updated. Bug: 411506181 Test: DragToBubbleControllerTest Flag: com.android.wm.shell.enable_create_any_bubble Change-Id: I51290bb6c2b35ff913a43c04db35be65b377ea03 --- .../bubbles/BubbleBarViewController.java | 1 + .../taskbar/bubbles/BubbleControllers.java | 1 + .../taskbar/bubbles/DragToBubbleController.kt | 51 ++++-- .../bubbles/DragToBubbleControllerTest.kt | 164 +++++++++++++++++- 4 files changed, 198 insertions(+), 19 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 91eec3db52..5ffff26f02 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -560,6 +560,7 @@ public class BubbleBarViewController { mBarView.showDropTarget(showingDropTarget); } + //TODO(b/411505605) remove unused IPC calls and code /** * Notifies the controller that a drag event is over the Bubble Bar drop zone. The controller * will display the appropriate drop target and enter drop target mode. The controller will also diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java index 0a68478fc0..796644d4d1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleControllers.java @@ -140,6 +140,7 @@ public class BubbleControllers { return -(int) bubbleStashController.getBubbleBarTranslationY(); } }, + bubbleBarLocationListeners, SystemUiProxy.INSTANCE.get(taskbarControllers.taskbarActivityContext)); mPostInitRunnables.executeAllAndDestroy(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt index c1c82584cf..0c879b82c4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/DragToBubbleController.kt @@ -25,6 +25,7 @@ import com.android.launcher3.dragndrop.DragController import com.android.launcher3.dragndrop.DragOptions import com.android.launcher3.model.data.ItemInfo import com.android.launcher3.model.data.WorkspaceItemInfo +import com.android.launcher3.taskbar.bubbles.BubbleBarController.BubbleBarLocationListener import com.android.launcher3.taskbar.bubbles.BubbleBarLocationDropTarget.BubbleBarDropTargetController import com.android.quickstep.SystemUiProxy import com.android.wm.shell.shared.bubbles.BubbleBarLocation @@ -47,10 +48,12 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F DragController.DragListener { @VisibleForTesting val dropTargetManager: DropTargetManager - @VisibleForTesting lateinit var bubbleBarLeftDropTarget: BubbleBarLocationDropTarget @VisibleForTesting lateinit var bubbleBarRightDropTarget: BubbleBarLocationDropTarget @VisibleForTesting lateinit var dragZoneFactory: DragZoneFactory + // If item drop is handled the next sysui update will set the bubble bar location + @VisibleForTesting var isItemDropHandled = false + private lateinit var bubbleBarLocationListener: BubbleBarLocationListener private lateinit var systemUiProxy: SystemUiProxy private lateinit var bubbleBarViewController: BubbleBarViewController @@ -61,10 +64,12 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F fun init( bubbleBarViewController: BubbleBarViewController, bubbleBarPropertiesProvider: BubbleBarPropertiesProvider, + bubbleBarLocationListener: BubbleBarLocationListener, systemUiProxy: SystemUiProxy, ) { this.bubbleBarViewController = bubbleBarViewController this.systemUiProxy = systemUiProxy + this.bubbleBarLocationListener = bubbleBarLocationListener val dropController: BubbleBarDropTargetController = createDropController() dragZoneFactory = createDragZoneFactory(bubbleBarPropertiesProvider) bubbleBarLeftDropTarget = createDropTarget(dropController, isLeftDropTarget = true) @@ -95,6 +100,7 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F } override fun onDragStart(dragObject: DragObject, options: DragOptions) { + isItemDropHandled = false val launcherIcon: DraggedObject = LauncherIcon(bubbleBarViewController.hasBubbles()) {} val dragZones: List = dragZoneFactory.createSortedDragZones(launcherIcon) dropTargetManager.onDragStarted(launcherIcon, dragZones) @@ -110,8 +116,17 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F context.isRtl, object : DragToBubblesZoneChangeListener.Callback { + private var currentBarLocation: BubbleBarLocation? = null + override fun onDragEnteredLocation(bubbleBarLocation: BubbleBarLocation?) { bubbleBarViewController.isShowingDropTarget = bubbleBarLocation != null + if (isItemDropHandled) return + val updatedLocation = bubbleBarLocation ?: getStartingBubbleBarLocation() + currentBarLocation = currentBarLocation ?: getStartingBubbleBarLocation() + if (updatedLocation != currentBarLocation) { + currentBarLocation = updatedLocation + bubbleBarLocationListener.onBubbleBarLocationAnimated(updatedLocation) + } } override fun getStartingBubbleBarLocation(): BubbleBarLocation { @@ -122,14 +137,9 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F override fun hasBubbles(): Boolean = bubbleBarViewController.hasBubbles() override fun animateBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) { + if (isItemDropHandled) return bubbleBarViewController.animateBubbleBarLocation(bubbleBarLocation) } - - override fun bubbleBarPillowShownAtLocation( - bubbleBarLocation: BubbleBarLocation? - ) { - // TODO(b/411506181) adjust taskbar - } }, ) return DropTargetManager(context, bubbleBarContainer, listener) @@ -154,6 +164,18 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F private fun createDropController(): BubbleBarDropTargetController { return object : BubbleBarDropTargetController { override fun onDrop(itemInfo: ItemInfo, isLeftDropTarget: Boolean) { + isItemDropHandled = handleDrop(itemInfo, isLeftDropTarget) + } + + override fun acceptDrop(itemInfo: ItemInfo): Boolean { + return hasShortcutInfo(itemInfo) || itemInfo.intent?.component != null + } + + fun hasShortcutInfo(itemInfo: ItemInfo): Boolean { + return itemInfo is WorkspaceItemInfo && itemInfo.deepShortcutInfo != null + } + + private fun handleDrop(itemInfo: ItemInfo, isLeftDropTarget: Boolean): Boolean { val location = if (isLeftDropTarget) { BubbleBarLocation.LEFT @@ -163,20 +185,13 @@ class DragToBubbleController(private val context: Context, bubbleBarContainer: F if (hasShortcutInfo(itemInfo)) { val si = (itemInfo as WorkspaceItemInfo).deepShortcutInfo systemUiProxy.showShortcutBubble(si, location) - return + return true } - val itemIntent: Intent = itemInfo.intent ?: return - val packageName = itemIntent.component?.packageName ?: return + val itemIntent: Intent = itemInfo.intent ?: return false + val packageName = itemIntent.component?.packageName ?: return false itemIntent.setPackage(packageName) systemUiProxy.showAppBubble(itemIntent, itemInfo.user, location) - } - - override fun acceptDrop(itemInfo: ItemInfo): Boolean { - return hasShortcutInfo(itemInfo) || itemInfo.intent?.component != null - } - - fun hasShortcutInfo(itemInfo: ItemInfo): Boolean { - return itemInfo is WorkspaceItemInfo && itemInfo.deepShortcutInfo != null + return true } } } diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt index f8534fbe84..17283c37ee 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/DragToBubbleControllerTest.kt @@ -31,6 +31,7 @@ import com.android.launcher3.DropTarget import com.android.launcher3.DropTarget.DragObject import com.android.launcher3.dragndrop.DragOptions import com.android.launcher3.model.data.AppInfo +import com.android.launcher3.taskbar.bubbles.BubbleBarController.BubbleBarLocationListener import com.android.quickstep.SystemUiProxy import com.android.wm.shell.shared.bubbles.BubbleBarLocation import com.android.wm.shell.shared.bubbles.DeviceConfig @@ -44,7 +45,9 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.any +import org.mockito.kotlin.clearInvocations import org.mockito.kotlin.doReturn +import org.mockito.kotlin.inOrder import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.stub @@ -61,6 +64,7 @@ class DragToBubbleControllerTest { private val container = FrameLayout(context) private val bubbleBarViewController: BubbleBarViewController = mock() private val systemUiProxy: SystemUiProxy = mock() + private val bubbleBarLocationListener: BubbleBarLocationListener = mock() private val bubbleBarPropertiesProvider = FakeBubbleBarPropertiesProvider() private val testDragZonesFactory = createTestDragZoneFactory() private val dragObject = DragObject(context) @@ -86,10 +90,12 @@ class DragToBubbleControllerTest { @Before fun setUp() { + prepareBubbleBarViewController() dragToBubbleController = DragToBubbleController(context, container) dragToBubbleController.init( bubbleBarViewController, bubbleBarPropertiesProvider, + bubbleBarLocationListener, systemUiProxy, ) dragToBubbleController.dragZoneFactory = testDragZonesFactory @@ -104,6 +110,7 @@ class DragToBubbleControllerTest { assertThat(secondDropTargetView!!.parent).isEqualTo(container) assertThat(dropTargetView.alpha).isEqualTo(0f) assertThat(secondDropTargetView!!.alpha).isEqualTo(0f) + assertThat(dragToBubbleController.isItemDropHandled).isFalse() } @Test @@ -235,13 +242,168 @@ class DragToBubbleControllerTest { InstrumentationRegistry.getInstrumentation().runOnMainSync { dragObject.updateXYToCenterOf(leftDropTargetRect) bubbleBarLeftDropTarget.onDragEnter(dragObject) - bubbleBarLeftDropTarget.onDragExit(dragObject) bubbleBarLeftDropTarget.onDrop(dragObject, DragOptions()) + assertThat(dragToBubbleController.isItemDropHandled).isTrue() + bubbleBarLeftDropTarget.onDragExit(dragObject) } verify(systemUiProxy).showAppBubble(itemIntent, appInfo.user, BubbleBarLocation.LEFT) } + @Test + fun dragExitRightZone_noBubbles_listenerNotNotified() { + // Scenario: No bubbles. Drag enters RIGHT, then exits to no particular zone. + // This is distinct as it starts on the default side. + prepareBubbleBarViewController( + hasBubbles = false, + bubbleBarLocation = BubbleBarLocation.RIGHT, + ) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) // Location is the same + } + verify(bubbleBarLocationListener, never()) + .onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXY(0, 0) // Move out of all zones + bubbleBarRightDropTarget.onDragExit(dragObject) + } + + // Exiting the RIGHT zone (which is the default) should not re-notify of RIGHT + verify(bubbleBarLocationListener, never()) + .onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + } + + @Test + fun onDragEnd_noBubbles_wasDraggingLeft_listenerNotifiedWithDefaultRightLocationAnimated() { + val startingLocation = BubbleBarLocation.RIGHT + // Scenario: No bubbles. Drag was over LEFT zone. Drag ends. + prepareBubbleBarViewController(hasBubbles = false, bubbleBarLocation = startingLocation) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + } + // Notifies onBubbleBarLocationAnimated(LEFT) + verify(bubbleBarLocationListener).onBubbleBarLocationAnimated(BubbleBarLocation.LEFT) + clearInvocations(bubbleBarLocationListener) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragToBubbleController.onDragEnd() + } + assertThat(dragToBubbleController.isItemDropHandled).isFalse() + + // After drag ends (and no bubbles), the listener should be notified of the default location + verify(bubbleBarLocationListener).onBubbleBarLocationAnimated(startingLocation) + } + + @Test + fun onDragEnd_noBubbles_wasDraggingRight_listenerNotifiedWithDefaultRightLocationAnimated() { + // Scenario: No bubbles. Drag was over RIGHT zone (default side). Drag ends. + prepareBubbleBarViewController(hasBubbles = false) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + } + verify(bubbleBarLocationListener, never()) + .onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + clearInvocations(bubbleBarLocationListener) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXY(0, 0) + bubbleBarLeftDropTarget.onDragExit(dragObject) + dragToBubbleController.onDragEnd() + } + + // After drag ends (and no bubbles), listener should not be notified of the default + // location. + verify(bubbleBarLocationListener, never()) + .onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + } + + @Test + fun dragEnterLeftZone_bubblesOnLeft_listenerNotNotified() { + // Scenario: Bubbles on LEFT. Drag enters LEFT zone. + prepareBubbleBarViewController( + hasBubbles = true, + bubbleBarLocation = BubbleBarLocation.LEFT, + ) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + } + + // Bubbles are already on the LEFT, and drag enters LEFT. + // No new animation to LEFT should be triggered by the zone entry itself. + verify(bubbleBarLocationListener, never()) + .onBubbleBarLocationAnimated(BubbleBarLocation.LEFT) + } + + @Test + fun onDragEnd_bubblesOnLeft_defaultIsLeft_wasDraggingRight_listenerNotifiedLeftAnimated() { + // Scenario: Bubbles on LEFT. Drag was over RIGHT zone. Drag ends. + prepareBubbleBarViewController( + hasBubbles = true, + bubbleBarLocation = BubbleBarLocation.LEFT, + ) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) // Notifies Animated(RIGHT) + } + verify(bubbleBarLocationListener).onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + clearInvocations(bubbleBarLocationListener) // Clear the Animated(RIGHT) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + dragObject.updateXY(0, 0) + bubbleBarLeftDropTarget.onDragExit(dragObject) + dragToBubbleController.onDragEnd() + } + + // Bubble bar's final animated location should be LEFT. + verify(bubbleBarLocationListener).onBubbleBarLocationAnimated(BubbleBarLocation.LEFT) + } + + @Test + fun dragEnterLeftThenExitToNoZoneThenEnterRight_noBubbles_listenerSequenceCorrectAnimated() { + // Scenario: No bubbles. Complex drag path: Left -> None -> Right + prepareBubbleBarViewController(hasBubbles = false) + dragToBubbleController.onDragStart(dragObject, DragOptions()) + clearInvocations(bubbleBarLocationListener) + + val inOrder = inOrder(bubbleBarLocationListener) + + InstrumentationRegistry.getInstrumentation().runOnMainSync { + // 1. Enter Left + dragObject.updateXYToCenterOf(leftDropTargetRect) + bubbleBarLeftDropTarget.onDragEnter(dragObject) + + // 2. Exit Left to no zone + dragObject.updateXY(0, 0) + bubbleBarLeftDropTarget.onDragExit(dragObject) + + // 3. Enter Right + dragObject.updateXYToCenterOf(rightDropTargetRect) + bubbleBarRightDropTarget.onDragEnter(dragObject) + } + + inOrder + .verify(bubbleBarLocationListener) + .onBubbleBarLocationAnimated(BubbleBarLocation.LEFT) + // Revert to default, following enter of the same zone should not trigger updated + inOrder + .verify(bubbleBarLocationListener) + .onBubbleBarLocationAnimated(BubbleBarLocation.RIGHT) + } + private fun prepareBubbleBarViewController( hasBubbles: Boolean = false, bubbleBarLocation: BubbleBarLocation = BubbleBarLocation.RIGHT, From 4589acb53dc661a00ea8c691a50898ab857fa973 Mon Sep 17 00:00:00 2001 From: Will Osborn Date: Thu, 29 May 2025 10:20:49 +0000 Subject: [PATCH 17/20] Make RecentTasksRepository dispayId aware Bug: 402365283 Flag: com.android.launcher3.enable_overview_on_connected_displays Test: unit tests + local test on tablet + foldable Change-Id: I379547e41029baedb95c67b4440f23adfb29b1ba --- .../recents/data/RecentTasksRepository.kt | 4 +- .../quickstep/recents/data/TasksRepository.kt | 23 +- .../recents/viewmodel/RecentsViewModel.kt | 5 +- .../android/quickstep/views/RecentsView.java | 3 +- .../recents/data/FakeTaskIconDataSource.kt | 5 +- .../data/FakeTaskThumbnailDataSource.kt | 9 +- .../recents/data/FakeTasksRepository.kt | 23 +- .../recents/data/TasksRepositoryTest.kt | 216 ++++++++++++++---- .../domain/usecase/GetTaskUseCaseTest.kt | 7 +- .../recents/viewmodel/RecentsViewModelTest.kt | 6 +- 10 files changed, 230 insertions(+), 71 deletions(-) diff --git a/quickstep/src/com/android/quickstep/recents/data/RecentTasksRepository.kt b/quickstep/src/com/android/quickstep/recents/data/RecentTasksRepository.kt index 53969c5219..f7b1674443 100644 --- a/quickstep/src/com/android/quickstep/recents/data/RecentTasksRepository.kt +++ b/quickstep/src/com/android/quickstep/recents/data/RecentTasksRepository.kt @@ -22,7 +22,7 @@ import kotlinx.coroutines.flow.Flow interface RecentTasksRepository { /** Gets all the recent tasks, refreshing from data sources if [forceRefresh] is true. */ - fun getAllTaskData(forceRefresh: Boolean = false): Flow> + fun getAllTaskData(displayId: Int, forceRefresh: Boolean = false): Flow> /** * Gets the data associated with a task that has id [taskId]. Flow will settle on null if the @@ -46,5 +46,5 @@ interface RecentTasksRepository { * Sets the tasks that are visible, indicating that properties relating to visuals need to be * populated e.g. icons/thumbnails etc. */ - fun setVisibleTasks(visibleTaskIdList: Set) + fun setVisibleTasks(displayId: Int, visibleTaskIdList: Set) } diff --git a/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt b/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt index 754707390b..74aaeff09b 100644 --- a/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt +++ b/quickstep/src/com/android/quickstep/recents/data/TasksRepository.kt @@ -18,6 +18,8 @@ package com.android.quickstep.recents.data import android.graphics.drawable.Drawable import android.util.Log +import android.util.SparseArray +import androidx.core.util.valueIterator import com.android.launcher3.util.coroutines.DispatcherProvider import com.android.quickstep.recents.data.TaskVisualsChangedDelegate.TaskIconChangedCallback import com.android.quickstep.recents.data.TaskVisualsChangedDelegate.TaskThumbnailChangedCallback @@ -46,10 +48,13 @@ class TasksRepository( private val dispatcherProvider: DispatcherProvider, ) : RecentTasksRepository { private val tasks = MutableStateFlow(MapForStateFlow(emptyMap())) - private var visibleTaskIds = emptySet() + private var visibleTaskIdsPerDisplay = SparseArray>() private val taskRequests = HashMap>() - override fun getAllTaskData(forceRefresh: Boolean): Flow> { + override fun getAllTaskData(displayId: Int, forceRefresh: Boolean): Flow> { + if (!visibleTaskIdsPerDisplay.contains(displayId)) { + visibleTaskIdsPerDisplay.put(displayId, emptySet()) + } if (forceRefresh) { recentsModel.getTasks { newTaskList -> val recentTasks = @@ -72,7 +77,7 @@ class TasksRepository( updateTaskRequests() } } - return tasks.map { it.values.toList() } + return tasks.map { it.values.filter { it.key.displayId == displayId }.toList() } } override fun getTaskDataById(taskId: Int) = tasks.map { it[taskId] } @@ -82,14 +87,20 @@ class TasksRepository( override fun getCurrentThumbnailById(taskId: Int) = tasks.value[taskId]?.thumbnail - override fun setVisibleTasks(visibleTaskIdList: Set) { - visibleTaskIds = visibleTaskIdList + override fun setVisibleTasks(displayId: Int, visibleTaskIdList: Set) { + if (visibleTaskIdList.isEmpty()) { + visibleTaskIdsPerDisplay.remove(displayId) + } else { + visibleTaskIdsPerDisplay.put(displayId, visibleTaskIdList) + } updateTaskRequests() } @Synchronized private fun updateTaskRequests() { - val requestsNeeded = visibleTaskIds.intersect(tasks.value.keys) + val allVisibleTaskIds = + visibleTaskIdsPerDisplay.valueIterator().asSequence().flatMap { it }.toSet() + val requestsNeeded = allVisibleTaskIds.intersect(tasks.value.keys) val taskRequestIds = taskRequests.keys val requestsNoLongerNeeded = taskRequestIds.subtract(requestsNeeded) diff --git a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt index a875ab0fcc..ec8736a6ef 100644 --- a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt +++ b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt @@ -25,16 +25,17 @@ import kotlinx.coroutines.flow.first class RecentsViewModel( private val recentsTasksRepository: RecentTasksRepository, private val recentsViewData: RecentsViewData, + private val displayId: Int, ) { private var visibleTaskIds = emptySet() fun refreshAllTaskData() { - recentsTasksRepository.getAllTaskData(true) + recentsTasksRepository.getAllTaskData(displayId, true) } fun updateVisibleTasks(visibleTaskIdList: List) { visibleTaskIds = visibleTaskIdList.toSet() - recentsTasksRepository.setVisibleTasks(visibleTaskIds) + recentsTasksRepository.setVisibleTasks(displayId, visibleTaskIds) } fun updateTasksFullyVisible(taskIds: Set) { diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index a7d6e2b1db..e0a5655bdc 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -910,7 +910,8 @@ public abstract class RecentsView< String scopeId = recentsDependencies.createRecentsViewScope(context); mRecentsViewModel = new RecentsViewModel( recentsDependencies.inject(RecentTasksRepository.class, scopeId), - recentsDependencies.inject(RecentsViewData.class, scopeId) + recentsDependencies.inject(RecentsViewData.class, scopeId), + mContainer.getDisplayId() ); mHelper = new RecentsViewModelHelper( mRecentsViewModel, diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskIconDataSource.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskIconDataSource.kt index f6f158f546..ce36715ad9 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskIconDataSource.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskIconDataSource.kt @@ -21,7 +21,7 @@ import com.android.quickstep.TaskIconCache.TaskCacheEntry import com.android.quickstep.task.thumbnail.data.TaskIconDataSource import com.android.systemui.shared.recents.model.Task import com.google.common.truth.Truth.assertThat -import kotlinx.coroutines.yield +import kotlinx.coroutines.delay import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -34,7 +34,8 @@ class FakeTaskIconDataSource : TaskIconDataSource { /** Retrieves and sets an icon on [task] from [taskIdToDrawable]. */ override suspend fun getIcon(task: Task): TaskCacheEntry { while (task.key.id in completionPrevented) { - yield() + // yield doesn't work here with an UnconfinedTestDispatcher + delay(1L) } return TaskCacheEntry( taskIdToDrawable.getValue(task.key.id), diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskThumbnailDataSource.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskThumbnailDataSource.kt index 40d5e0264c..71996c7835 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskThumbnailDataSource.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTaskThumbnailDataSource.kt @@ -20,7 +20,7 @@ import android.graphics.Bitmap import com.android.quickstep.task.thumbnail.data.TaskThumbnailDataSource import com.android.systemui.shared.recents.model.Task import com.android.systemui.shared.recents.model.ThumbnailData -import kotlinx.coroutines.yield +import kotlinx.coroutines.delay import org.mockito.kotlin.mock class FakeTaskThumbnailDataSource : TaskThumbnailDataSource { @@ -37,7 +37,8 @@ class FakeTaskThumbnailDataSource : TaskThumbnailDataSource { getThumbnailCalls[task.key.id] = (getThumbnailCalls[task.key.id] ?: 0) + 1 while (task.key.id in completionPrevented) { - yield() + // yield doesn't work here with an UnconfinedTestDispatcher + delay(1L) } return ThumbnailData( thumbnail = taskIdToBitmap[task.key.id], @@ -54,4 +55,8 @@ class FakeTaskThumbnailDataSource : TaskThumbnailDataSource { fun completeLoadingForTask(taskId: Int) { completionPrevented.remove(taskId) } + + fun completeLoading() { + completionPrevented.clear() + } } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTasksRepository.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTasksRepository.kt index 35af29f2c6..c00ff15ced 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTasksRepository.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/FakeTasksRepository.kt @@ -17,24 +17,30 @@ package com.android.quickstep.recents.data import android.graphics.drawable.Drawable +import androidx.core.util.forEach +import androidx.core.util.putAll import com.android.systemui.shared.recents.model.Task import com.android.systemui.shared.recents.model.ThumbnailData import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.update class FakeTasksRepository : RecentTasksRepository { private var thumbnailDataMap: Map = emptyMap() private var taskIconDataMap: Map = emptyMap() private var tasks: MutableStateFlow> = MutableStateFlow(emptyList()) - private var visibleTasks: MutableStateFlow> = MutableStateFlow(emptySet()) + private var visibleTasks: MutableStateFlow>> = MutableStateFlow(mapOf()) - override fun getAllTaskData(forceRefresh: Boolean): Flow> = tasks + override fun getAllTaskData(displayId: Int, forceRefresh: Boolean): Flow> = + tasks.map { it.filter { it.key.displayId == displayId }.toList() } override fun getTaskDataById(taskId: Int): Flow = - combine(getAllTaskData(), visibleTasks) { taskList, visibleTasks -> - taskList.filter { visibleTasks.contains(it.key.id) } + combine(tasks, visibleTasks) { taskList, visibleTasks -> + val allVisibleTasks = mutableSetOf() + visibleTasks.forEach { _, value -> allVisibleTasks.addAll(value) } + taskList.filter { allVisibleTasks.contains(it.key.id) } } .map { taskList -> val task = taskList.firstOrNull { it.key.id == taskId } ?: return@map null @@ -52,8 +58,13 @@ class FakeTasksRepository : RecentTasksRepository { override fun getCurrentThumbnailById(taskId: Int): ThumbnailData? = tasks.value.firstOrNull { it.key.id == taskId }?.thumbnail - override fun setVisibleTasks(visibleTaskIdList: Set) { - visibleTasks.value = visibleTaskIdList + override fun setVisibleTasks(displayId: Int, visibleTaskIdList: Set) { + visibleTasks.update { + val newVisibleTasks = mutableMapOf>() + newVisibleTasks.putAll(it) + newVisibleTasks[displayId] = visibleTaskIdList + newVisibleTasks + } tasks.value = tasks.value.map { it.apply { diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt index 677477ffa0..e7f1d18e85 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt @@ -39,7 +39,9 @@ import kotlinx.coroutines.flow.toList import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.spy @@ -51,6 +53,7 @@ import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) class TasksRepositoryTest { private val tasks = (0..5).map(::createTaskWithId) + private val secondaryTasks = (6..11).map(::createTaskWithIdForSecondaryDisplay) private val defaultTaskList = listOf( SingleTask(tasks[0]), @@ -67,6 +70,22 @@ class TasksRepositoryTest { ), DesktopTask(deskId = 0, DEFAULT_DISPLAY, tasks.subList(3, 6)), ) + private val secondaryTaskList = + listOf( + SingleTask(secondaryTasks[0]), + SplitTask( + secondaryTasks[1], + secondaryTasks[2], + SplitBounds( + /* leftTopBounds = */ Rect(), + /* rightBottomBounds = */ Rect(), + /* leftTopTaskId = */ 7, + /* rightBottomTaskId = */ 8, + /* snapPosition = */ SNAP_TO_2_50_50, + ), + ), + DesktopTask(deskId = 1, SECONDARY_DISPLAY, secondaryTasks.subList(3, 6)), + ) private val recentsModel = FakeRecentTasksDataSource() private val taskThumbnailDataSource = FakeTaskThumbnailDataSource() private val taskIconDataSource = FakeTaskIconDataSource() @@ -87,18 +106,25 @@ class TasksRepositoryTest { TestDispatcherProvider(dispatcher), ) + @Before + fun cleanupDataSources() { + taskThumbnailDataSource.completeLoading() + taskIconDataSource.completeLoading() + } + @Test fun getAllTaskDataReturnsFlattenedListOfTasks() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - assertThat(systemUnderTest.getAllTaskData(forceRefresh = true).first()).isEqualTo(tasks) + assertThat(systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true).first()) + .isEqualTo(tasks) } @Test fun getTaskDataByIdReturnsSpecificTask() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) assertThat(systemUnderTest.getTaskDataById(2).first()).isEqualTo(tasks[2]) } @@ -107,7 +133,7 @@ class TasksRepositoryTest { fun getThumbnailByIdReturnsNullWithNoLoadedThumbnails() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) assertThat(systemUnderTest.getThumbnailById(1).first()).isNull() } @@ -116,7 +142,7 @@ class TasksRepositoryTest { fun getCurrentThumbnailByIdReturnsNullWithNoLoadedThumbnails() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) assertThat(systemUnderTest.getCurrentThumbnailById(1)).isNull() } @@ -125,10 +151,10 @@ class TasksRepositoryTest { fun getThumbnailByIdReturnsThumbnailWithLoadedThumbnails() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) assertThat(systemUnderTest.getThumbnailById(1).first()!!.thumbnail).isEqualTo(bitmap1) } @@ -137,13 +163,13 @@ class TasksRepositoryTest { fun whenThumbnailIsLoaded_getAllTaskData_usesPreviousLoadedThumbnailAndIcon() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) assertThat(systemUnderTest.getThumbnailById(1).first()!!.thumbnail).isEqualTo(bitmap1) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) assertThat(systemUnderTest.getThumbnailById(1).first()!!.thumbnail).isEqualTo(bitmap1) } @@ -151,8 +177,8 @@ class TasksRepositoryTest { fun getAllTaskData_copiesPreviouslyLoadedImagesForTasksStillPresent() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(0, 1)) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(0, 1)) // Seed new task with same id val newTask0 = SingleTask(createTaskWithId(0)) @@ -161,7 +187,7 @@ class TasksRepositoryTest { if (it is SingleTask && it.task.key.id == 0) newTask0 else it } recentsModel.seedTasks(newSeededTasks) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) // Assert no additional loads, assert images present assertThat(systemUnderTest.getThumbnailById(0).first()?.thumbnail) @@ -174,18 +200,18 @@ class TasksRepositoryTest { testScope.runTest { // Setup data recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] // Load images for task 1 - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) assertThat(systemUnderTest.getThumbnailById(1).first()!!.thumbnail).isEqualTo(bitmap1) // Remove task 1 from "all data" recentsModel.seedTasks( defaultTaskList.filterNot { groupTask -> groupTask.tasks.any { it.key.id == 1 } } ) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) // Assert task 1 was fully removed assertThat(systemUnderTest.getThumbnailById(1).first()?.thumbnail).isNull() @@ -196,10 +222,10 @@ class TasksRepositoryTest { fun getCurrentThumbnailByIdReturnsThumbnailWithLoadedThumbnails() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) assertThat(systemUnderTest.getCurrentThumbnailById(1)?.thumbnail).isEqualTo(bitmap1) } @@ -210,9 +236,9 @@ class TasksRepositoryTest { recentsModel.seedTasks(defaultTaskList) val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] val bitmap2 = taskThumbnailDataSource.taskIdToBitmap[2] - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) assertThat(systemUnderTest.getTaskDataById(1).first()!!.thumbnail!!.thumbnail) .isEqualTo(bitmap1) @@ -224,9 +250,9 @@ class TasksRepositoryTest { fun setVisibleTasksPopulatesIcons() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) systemUnderTest .getTaskDataById(1) @@ -243,16 +269,16 @@ class TasksRepositoryTest { testScope.runTest { recentsModel.seedTasks(defaultTaskList) val bitmap2 = taskThumbnailDataSource.taskIdToBitmap[2] - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) assertThat(systemUnderTest.getTaskDataById(2).first()!!.thumbnail!!.thumbnail) .isEqualTo(bitmap2) // Prevent new loading of Bitmaps taskThumbnailDataSource.preventThumbnailLoad(2) - systemUnderTest.setVisibleTasks(setOf(2, 3)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(2, 3)) assertThat(systemUnderTest.getTaskDataById(2).first()!!.thumbnail!!.thumbnail) .isEqualTo(bitmap2) @@ -262,9 +288,9 @@ class TasksRepositoryTest { fun changingVisibleTasksContainsAlreadyPopulatedIcons() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) systemUnderTest .getTaskDataById(2) @@ -273,7 +299,7 @@ class TasksRepositoryTest { // Prevent new loading of Drawables taskIconDataSource.preventIconLoad(2) - systemUnderTest.setVisibleTasks(setOf(2, 3)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(2, 3)) systemUnderTest .getTaskDataById(2) @@ -286,15 +312,15 @@ class TasksRepositoryTest { testScope.runTest { recentsModel.seedTasks(defaultTaskList) val bitmap2 = taskThumbnailDataSource.taskIdToBitmap[2] - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) val task2 = systemUnderTest.getTaskDataById(2).first()!! assertThat(task2.thumbnail!!.thumbnail).isEqualTo(bitmap2) task2.assertHasIconDataFromSource(taskIconDataSource) - systemUnderTest.setVisibleTasks(setOf(0, 1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(0, 1)) val task2AfterVisibleTasksChanged = systemUnderTest.getTaskDataById(2).first()!! assertThat(task2AfterVisibleTasksChanged.thumbnail).isNull() @@ -311,7 +337,7 @@ class TasksRepositoryTest { val bitmap2 = taskThumbnailDataSource.taskIdToBitmap[2] // Setup TasksRepository - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val task2DataFlow = systemUnderTest.getTaskDataById(2) val task2BitmapValues = mutableListOf() @@ -322,7 +348,7 @@ class TasksRepositoryTest { // Check for first emission assertThat(task2BitmapValues.single()).isNull() - systemUnderTest.setVisibleTasks(setOf(2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(2)) // Check for second emission assertThat(task2BitmapValues).isEqualTo(listOf(null, bitmap2)) } @@ -331,8 +357,8 @@ class TasksRepositoryTest { fun onTaskThumbnailChanged_setsNewThumbnailDataOnTask() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) val expectedThumbnailData = createThumbnailData() val expectedPreviousBitmap = taskThumbnailDataSource.taskIdToBitmap[1] @@ -353,9 +379,9 @@ class TasksRepositoryTest { testScope.runTest { taskThumbnailDataSource.highResEnabled = false recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) val expectedBitmap = mock() val expectedPreviousBitmap = taskThumbnailDataSource.taskIdToBitmap[1] @@ -384,9 +410,9 @@ class TasksRepositoryTest { testScope.runTest { taskThumbnailDataSource.highResEnabled = false recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) val invisibleTaskId = 2 val taskDataFlow = systemUnderTest.getTaskDataById(invisibleTaskId) @@ -408,9 +434,9 @@ class TasksRepositoryTest { testScope.runTest { taskThumbnailDataSource.highResEnabled = true recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) val expectedBitmap = mock() val expectedPreviousBitmap = taskThumbnailDataSource.taskIdToBitmap[1] @@ -438,9 +464,9 @@ class TasksRepositoryTest { fun onTaskIconChanged_setsNewIconOnTask() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) val expectedIcon = FakeTaskIconDataSource.mockCopyableDrawable() val expectedPreviousIcon = taskIconDataSource.taskIdToDrawable[1] @@ -461,7 +487,7 @@ class TasksRepositoryTest { fun setVisibleTasks_multipleTimesWithDifferentTasks_reusesThumbnailRequests() = testScope.runTest { recentsModel.seedTasks(defaultTaskList) - systemUnderTest.getAllTaskData(forceRefresh = true) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) val taskDataFlow = systemUnderTest.getTaskDataById(1) val task1IconValues = mutableListOf() @@ -469,16 +495,115 @@ class TasksRepositoryTest { taskDataFlow.map { it?.icon }.toList(task1IconValues) } - systemUnderTest.setVisibleTasks(setOf(1)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) assertThat(taskThumbnailDataSource.getNumberOfGetThumbnailCalls(1)).isEqualTo(1) - systemUnderTest.setVisibleTasks(setOf(1, 2)) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) assertThat(taskThumbnailDataSource.getNumberOfGetThumbnailCalls(1)).isEqualTo(1) } + @Test + fun getTaskData_forSecondaryDisplay() = + testScope.runTest { + recentsModel.seedTasks(defaultTaskList + secondaryTaskList) + + assertThat(systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true).first()) + .isEqualTo(tasks) + assertThat( + systemUnderTest.getAllTaskData(SECONDARY_DISPLAY, forceRefresh = true).first() + ) + .isEqualTo(secondaryTasks) + } + + @Test + fun setVisibleTasks_secondaryDisplayConnected() = + testScope.runTest { + recentsModel.seedTasks(defaultTaskList + secondaryTaskList) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) + systemUnderTest.getAllTaskData(SECONDARY_DISPLAY, forceRefresh = true) + val bitmap1 = taskThumbnailDataSource.taskIdToBitmap[1] + val bitmap6 = taskThumbnailDataSource.taskIdToBitmap[6] + + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) + systemUnderTest.setVisibleTasks(SECONDARY_DISPLAY, setOf(6)) + + val actualThumbnails = + (0..11).map { systemUnderTest.getThumbnailById(it).first()?.thumbnail }.toList() + val expectedThumbnails = + arrayOfNulls(12) + .apply { + set(1, bitmap1) + set(6, bitmap6) + } + .toList() + assertThat(actualThumbnails).isEqualTo(expectedThumbnails) + } + + @Test + fun setVisibleTasks_displayDisconnectedBeforeImageReturns_doesNotPopulateThumbnailOrIcon() = + testScope.runTest { + recentsModel.seedTasks(defaultTaskList + secondaryTaskList) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) + systemUnderTest.getAllTaskData(SECONDARY_DISPLAY, forceRefresh = true) + taskThumbnailDataSource.preventThumbnailLoad(6) + taskIconDataSource.preventIconLoad(6) + + val task6DataFlow = systemUnderTest.getTaskDataById(6) + val task6Values = mutableListOf>() + testScope.backgroundScope.launch { + task6DataFlow.map { Pair(it?.thumbnail?.thumbnail, it?.icon) }.toList(task6Values) + } + + launch { systemUnderTest.setVisibleTasks(SECONDARY_DISPLAY, setOf(6)) } + // Check we prevented the resources from loading + assertThat(task6Values.distinct()).isEqualTo(listOf(Pair(null, null))) + // Display disconnects + launch { systemUnderTest.setVisibleTasks(SECONDARY_DISPLAY, emptySet()) } + taskThumbnailDataSource.completeLoadingForTask(6) + taskIconDataSource.completeLoadingForTask(6) + testScope.advanceUntilIdle() + // Still should not be loaded + assertThat(task6Values.distinct()).isEqualTo(listOf(Pair(null, null))) + } + + @Test + fun onDisplayRemoved_removesAllDataForDisplay() = + testScope.runTest { + recentsModel.seedTasks(defaultTaskList + secondaryTaskList) + systemUnderTest.getAllTaskData(DEFAULT_DISPLAY, forceRefresh = true) + systemUnderTest.getAllTaskData(SECONDARY_DISPLAY, forceRefresh = true) + systemUnderTest.setVisibleTasks(DEFAULT_DISPLAY, setOf(1)) + systemUnderTest.setVisibleTasks(SECONDARY_DISPLAY, setOf(6)) + + recentsModel.seedTasks(defaultTaskList) + systemUnderTest.setVisibleTasks(SECONDARY_DISPLAY, emptySet()) + + for (t in 6..11) { + assertThat(systemUnderTest.getThumbnailById(t).first()?.thumbnail).isNull() + assertThat(systemUnderTest.getTaskDataById(t).first()?.icon).isNull() + } + } + private fun createTaskWithId(taskId: Int) = Task(Task.TaskKey(taskId, 0, Intent(), ComponentName("", ""), 0, 2000)) + private fun createTaskWithIdForSecondaryDisplay(taskId: Int) = + Task( + Task.TaskKey( + taskId, + 0, + Intent(), + ComponentName("", ""), + 0, + 2000, + SECONDARY_DISPLAY, + null, + 0, + false, + false, + ) + ) + private fun createThumbnailData(): ThumbnailData { val bitmap = mock() whenever(bitmap.width).thenReturn(THUMBNAIL_WIDTH) @@ -490,5 +615,6 @@ class TasksRepositoryTest { companion object { const val THUMBNAIL_WIDTH = 100 const val THUMBNAIL_HEIGHT = 200 + const val SECONDARY_DISPLAY = 1 } } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/domain/usecase/GetTaskUseCaseTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/domain/usecase/GetTaskUseCaseTest.kt index 8331a99083..d29183f62f 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/domain/usecase/GetTaskUseCaseTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/domain/usecase/GetTaskUseCaseTest.kt @@ -24,6 +24,7 @@ import android.os.UserHandle import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.platform.test.flag.junit.SetFlagsRule +import android.view.Display.DEFAULT_DISPLAY import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.launcher3.Flags import com.android.quickstep.recents.data.FakeAppTimersRepository @@ -95,7 +96,7 @@ class GetTaskUseCaseTest { @EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST) fun taskVisible_returnsData() = testScope.runTest { - tasksRepository.setVisibleTasks(setOf(TASK_1_ID)) + tasksRepository.setVisibleTasks(DEFAULT_DISPLAY, setOf(TASK_1_ID)) val result = sut.invoke(TASK_1_ID).firstOrNull() @@ -120,7 +121,7 @@ class GetTaskUseCaseTest { @EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST) fun taskVisible_noAppTimer_returnsDataWithoutTimer() = testScope.runTest { - tasksRepository.setVisibleTasks(setOf(TASK_1_ID)) + tasksRepository.setVisibleTasks(DEFAULT_DISPLAY, setOf(TASK_1_ID)) timersRepository.resetTimer(PACKAGE_1, UserHandle(USER_1)) val result = sut.invoke(TASK_1_ID).firstOrNull() @@ -148,7 +149,7 @@ class GetTaskUseCaseTest { @DisableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST) fun taskVisible_dwbFlagOff_doesNotFetchTimer() = testScope.runTest { - tasksRepository.setVisibleTasks(setOf(TASK_1_ID)) + tasksRepository.setVisibleTasks(DEFAULT_DISPLAY, setOf(TASK_1_ID)) val result = sut.invoke(TASK_1_ID).firstOrNull() diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/viewmodel/RecentsViewModelTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/viewmodel/RecentsViewModelTest.kt index a32e07dedf..c53f20ffdc 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/viewmodel/RecentsViewModelTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/viewmodel/RecentsViewModelTest.kt @@ -20,6 +20,7 @@ import android.content.ComponentName import android.content.Intent import android.graphics.Bitmap import android.graphics.Color +import android.view.Display.DEFAULT_DISPLAY import android.view.Surface import com.android.quickstep.recents.data.FakeTasksRepository import com.android.systemui.shared.recents.model.Task @@ -34,7 +35,8 @@ import org.mockito.kotlin.whenever class RecentsViewModelTest { private val tasksRepository = FakeTasksRepository() private val recentsViewData = RecentsViewData() - private val systemUnderTest = RecentsViewModel(tasksRepository, recentsViewData) + private val systemUnderTest = + RecentsViewModel(tasksRepository, recentsViewData, DEFAULT_DISPLAY) private val tasks = (0..5).map(::createTaskWithId) @@ -97,7 +99,7 @@ class RecentsViewModelTest { ) // setVisibleTasks forces FakeTasksRepository to update the flows returned by // getThumbnailById - tasksRepository.setVisibleTasks(setOf(1, 2)) + tasksRepository.setVisibleTasks(DEFAULT_DISPLAY, setOf(1, 2)) // Then wait for thumbnailData should complete, and the previous getThumbnailById flow // should return updated values From 9f429958f8528eecb66949f63ee7ec165ba8aade Mon Sep 17 00:00:00 2001 From: Federico Baron Date: Fri, 30 May 2025 17:00:28 +0000 Subject: [PATCH 18/20] Remove screenrecord for TaplUninstallRemoveTest Flag: EXEMPT test only Bug: 386231522 Test: TaplUninstallRemoveTest#testUninstallFromAllApps Change-Id: Iff5e8b081e2e26c83b6d3cfdb0ebb82d7eb0fd7b --- .../com/android/launcher3/dragging/TaplUninstallRemoveTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java b/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java index 7443a9a46e..aa9098b777 100644 --- a/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java +++ b/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java @@ -26,7 +26,6 @@ import static com.google.common.truth.Truth.assertThat; import android.graphics.Point; import android.platform.test.annotations.PlatinumTest; -import android.platform.test.rule.ScreenRecordRule; import android.util.Log; import android.view.View; @@ -109,7 +108,6 @@ public class TaplUninstallRemoveTest extends AbstractLauncherUiTest Date: Thu, 29 May 2025 14:53:00 -0700 Subject: [PATCH 19/20] Add Documentation for LauncherProvider's Preferred Methods. This will make it easier for both the Cross OEM developers and also for others to be able to use these APIs and figure out why their home screen data is not showing up properly. Bug: 379378706 Test: EXEMPT comment Flag: EXEMPT comment Change-Id: If25bb9d394cc90bb7bd074f4d3d6244dad22818c --- .../android/launcher3/LauncherProvider.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index e61519f058..5cc135664c 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -46,6 +46,58 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.ToIntFunction; +/** + * This provider facilitates the import and export of home screen metadata within the + * Launcher's database. This includes managing shortcut placement, launch intents, and labels. + * Each row in the Launcher3 database corresponds to a single item on the workspace (often + * referred to as "favorites"). + * + *

Only applications installed on the system partition or those possessing the platform's + * signature can access this provider. + * + *

After data insertion into the Launcher's database, a row may be deleted during Launcher + * startup if any of these conditions are true. This list is not exhaustive: + *

    + *
  • Missing or invalid launch intent: This includes a null intent, one without a target + * package, or one referencing a non-existent activity.
  • + *
  • When an app previously installed doesn't exist or fails to restore properly.
  • + *
  • If ShortcutManager/WidgetManager haven't finished restoring by the time Launcher loads
  • + *
  • If the App Store hasn't finished restoring when Launcher starts loading.
  • + *
  • The item is linked to a profile that no longer exists (e.g., a deleted work profile).
  • + *
  • A widget's metadata specifies an invalid height or width.
  • + *
  • Incorrect item container: For instance, widgets can only be on the desktop or hotseat
  • + *
  • If the launcher is restoring, but the item isn't flagged as restoring/installing.
  • + *
  • If a widget fails to inflate within AppWidgetManagerService for any reason.
  • + *
  • When items in the database occupy the same or overlapping positions.
  • + *
+ * + *

Although query, bulkInsert, and insert methods are available, their direct use is not + * recommended. Instead, prefer the XML-based insertion methods accessible via the + * {@code call()} method. This preference is due to several reasons, including: + *

    + *
  • The insert methods can can lead to unpredictable behavior if invoked while Launcher + * is in the process of loading.
  • + *
  • The XML approach allows for custom tags which can be ingested for proprietary variants + * of workspace items.
  • + *
  • The XML method clears old data and inserts new data as a single, atomic action. Direct + * Delete/Insert usage requires at least 2 binder calls that are not atomic.
  • + *
+ * + *

It's important to note that the XML format has non-obvious and strict requirements. For + * instance: + *

    + *
  • The Launcher uses the "screen" value to determine hot seat placement order.
  • + *
  • Conversely, for items within a folder, the rank db column dictates their placement + * order.
  • + *
  • When an item is on the top-level workspace (i.e., not in the hot seat), the "screen" + * value signifies its workspace page.
  • + *
+ * + *

During a launcher restore, a grid migration might occur, either due to user preference or + * design updates. This migration can cause items to be repositioned or moved to different pages, + * depending on the old and new grid sizes. Therefore, precise placement cannot be guaranteed + * in all situations. + */ public class LauncherProvider extends ContentProvider { private static final String TAG = "LauncherProvider"; From 7e38e8a0892211dc3e76d3870e7b7123bcd34785 Mon Sep 17 00:00:00 2001 From: Vinay Joglekar Date: Fri, 23 May 2025 13:52:40 +0100 Subject: [PATCH 20/20] Update Scrim values for blur Set foreground color to ScrimView in overview. Added new state property for foreground. Fix: 412928191 Test: Go to overview Flag: com.android.launcher3.enable_overview_background_wallpaper_blur Change-Id: Id4180eaa5501dc11bf7331073edb28dca5c4a13a --- quickstep/res/values/styles.xml | 5 ++ .../uioverrides/states/AllAppsState.java | 13 ++++-- .../states/BackgroundAppState.java | 7 ++- .../uioverrides/states/HintState.java | 13 ++++-- .../uioverrides/states/OverviewState.java | 11 ++++- ...ButtonNavbarToOverviewTouchController.java | 10 ++-- .../NoButtonQuickSwitchTouchController.java | 5 +- .../quickstep/BaseContainerInterface.java | 20 ++++---- .../quickstep/FallbackActivityInterface.java | 4 +- .../quickstep/FallbackWindowInterface.java | 4 +- .../quickstep/LauncherActivityInterface.java | 4 +- .../FallbackRecentsStateController.java | 2 +- .../quickstep/fallback/RecentsState.java | 11 +++-- .../overview_scrim_foreground_primary.xml | 18 ++++++++ ...overview_scrim_foreground_primary_dark.xml | 18 ++++++++ .../overview_scrim_foreground_secondary.xml | 18 ++++++++ ...erview_scrim_foreground_secondary_dark.xml | 18 ++++++++ res/values/attrs.xml | 4 ++ res/values/styles.xml | 4 ++ .../android/launcher3/LauncherAnimUtils.java | 16 +++++++ src/com/android/launcher3/LauncherState.java | 6 ++- .../WorkspaceStateTransitionAnimation.java | 2 +- .../anim/AnimatedPropertySetter.java | 22 +++++---- .../launcher3/anim/PropertySetter.java | 12 +++-- .../android/launcher3/views/ScrimColors.kt | 19 ++++++++ .../launcher3/views/ScrimColorsEvaluator.kt | 46 +++++++++++++++++++ .../android/launcher3/views/ScrimView.java | 29 ++++++++++++ .../uioverrides/states/AllAppsState.java | 10 ++-- .../uioverrides/states/OverviewState.java | 8 +++- 29 files changed, 305 insertions(+), 54 deletions(-) create mode 100644 res/color/overview_scrim_foreground_primary.xml create mode 100644 res/color/overview_scrim_foreground_primary_dark.xml create mode 100644 res/color/overview_scrim_foreground_secondary.xml create mode 100644 res/color/overview_scrim_foreground_secondary_dark.xml create mode 100644 src/com/android/launcher3/views/ScrimColors.kt create mode 100644 src/com/android/launcher3/views/ScrimColorsEvaluator.kt diff --git a/quickstep/res/values/styles.xml b/quickstep/res/values/styles.xml index 0ffd93b8e4..3f20fffc03 100644 --- a/quickstep/res/values/styles.xml +++ b/quickstep/res/values/styles.xml @@ -389,12 +389,17 @@ ?attr/overviewScrimColorBlur @style/OverviewActionsContainerBlur @style/OverviewActionButton.Blur + ?attr/overviewScrimForegroundPrimaryBlur + ?attr/overviewScrimForegroundSecondaryBlur + diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java index 95a43f7d8e..553408afad 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java @@ -20,6 +20,7 @@ import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_ALLAPPS; import android.content.Context; +import android.graphics.Color; import com.android.internal.jank.Cuj; import com.android.launcher3.DeviceProfile; @@ -29,6 +30,7 @@ import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; import com.android.quickstep.util.BaseDepthController; import com.android.systemui.shared.system.InteractionJankMonitorWrapper; @@ -203,14 +205,17 @@ public class AllAppsState extends LauncherState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + int backgroundColor; if (!launcher.getDeviceProfile().shouldShowAllAppsOnSheet()) { // Always use an opaque scrim if there's no sheet. - return launcher.getResources().getColor(R.color.materialColorSurfaceDim); + backgroundColor = launcher.getResources().getColor(R.color.materialColorSurfaceDim); } else if (!Flags.allAppsBlur()) { // If there's a sheet but no blur, use the old scrim color. - return launcher.getResources().getColor(R.color.widgets_picker_scrim); + backgroundColor = launcher.getResources().getColor(R.color.widgets_picker_scrim); + } else { + backgroundColor = Themes.getAttrColor(launcher, R.attr.allAppsScrimColor); } - return Themes.getAttrColor(launcher, R.attr.allAppsScrimColor); + return new ScrimColors(backgroundColor, /* foregroundColor */ Color.TRANSPARENT); } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java b/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java index 9550933c40..a2c69167de 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java @@ -24,6 +24,7 @@ import android.graphics.Color; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.allapps.AllAppsTransitionController; +import com.android.launcher3.views.ScrimColors; import com.android.quickstep.util.BaseDepthController; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.views.RecentsView; @@ -108,8 +109,10 @@ public class BackgroundAppState extends OverviewState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { - return Color.TRANSPARENT; + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + return new ScrimColors( + /* backgroundColor= */ Color.TRANSPARENT, + /* foregroundColor= */ Color.TRANSPARENT); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/HintState.java b/quickstep/src/com/android/launcher3/uioverrides/states/HintState.java index 2bb91c7806..20cddc1aa0 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/HintState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/HintState.java @@ -26,6 +26,7 @@ import androidx.core.graphics.ColorUtils; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; /** * Scale down workspace/hotseat to hint at going to either overview (on pause) or first home screen. @@ -60,10 +61,14 @@ public class HintState extends LauncherState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { - int overviewStateColor = OVERVIEW.getWorkspaceScrimColor(launcher); - return ColorUtils.setAlphaComponent(overviewStateColor, - Math.round(Color.valueOf(overviewStateColor).alpha() * 100)); + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + ScrimColors overviewStateColor = OVERVIEW.getWorkspaceScrimColor(launcher); + return new ScrimColors( + /* backgroundColor */ + ColorUtils.setAlphaComponent(overviewStateColor.getBackgroundColor(), + Math.round(Color.valueOf(overviewStateColor.getBackgroundColor()).alpha() + * 100)), + /* foregroundColor */ Color.TRANSPARENT); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index a8be0545ec..2c92e9b6f3 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -24,6 +24,8 @@ import android.content.Context; import android.graphics.Rect; import android.os.SystemProperties; +import androidx.core.graphics.ColorUtils; + import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; @@ -31,6 +33,7 @@ import com.android.launcher3.R; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; import com.android.quickstep.util.BaseDepthController; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.views.RecentsView; @@ -157,8 +160,12 @@ public class OverviewState extends LauncherState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { - return Themes.getAttrColor(launcher, R.attr.overviewScrimColor); + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + return new ScrimColors( + /* backgroundColor */ Themes.getAttrColor(launcher, R.attr.overviewScrimColor), + /* foregroundColor */ ColorUtils.compositeColors( + Themes.getAttrColor(launcher, R.attr.overviewScrimForegroundPrimary), + Themes.getAttrColor(launcher, R.attr.overviewScrimForegroundSecondary))); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java index 7140d0f010..8d907f4183 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java @@ -17,7 +17,7 @@ package com.android.launcher3.uioverrides.touchcontrollers; import static com.android.app.animation.Interpolators.ACCELERATE_DECELERATE; -import static com.android.launcher3.LauncherAnimUtils.VIEW_BACKGROUND_COLOR; +import static com.android.launcher3.LauncherAnimUtils.SCRIM_COLORS; import static com.android.launcher3.LauncherAnimUtils.newSingleUseCancelListener; import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.HINT_STATE; @@ -47,6 +47,7 @@ import com.android.launcher3.taskbar.LauncherTaskbarUIController; import com.android.launcher3.uioverrides.QuickstepLauncher; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.VibratorWrapper; +import com.android.launcher3.views.ScrimColorsEvaluator; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.AnimatorControllerWithResistance; import com.android.quickstep.util.MotionPauseDetector; @@ -86,7 +87,7 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch private AnimatorPlaybackController mOverviewResistYAnim; // Normal to Hint animation has flag SKIP_OVERVIEW, so we update this scrim with this animator. - private ObjectAnimator mNormalToHintOverviewScrimAnimator; + private ValueAnimator mNormalToHintOverviewScrimAnimator; private final QuickstepLauncher mLauncher; private boolean mIsTrackpadSwipe; @@ -163,9 +164,10 @@ public class NoButtonNavbarToOverviewTouchController extends PortraitStatesTouch } if (mFromState == NORMAL && mToState == HINT_STATE) { - mNormalToHintOverviewScrimAnimator = ObjectAnimator.ofArgb( + mNormalToHintOverviewScrimAnimator = ObjectAnimator.ofObject( mLauncher.getScrimView(), - VIEW_BACKGROUND_COLOR, + SCRIM_COLORS, + ScrimColorsEvaluator.INSTANCE, mFromState.getWorkspaceScrimColor(mLauncher), mToState.getWorkspaceScrimColor(mLauncher)); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java index 60bd54431f..416c8ab4fd 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java @@ -278,8 +278,9 @@ public class NoButtonQuickSwitchTouchController implements TouchController, xAnim.setFloat(mRecentsView, ADJACENT_PAGE_HORIZONTAL_OFFSET, scaleAndOffset[1], LINEAR); // Use QuickSwitchState instead of OverviewState to determine scrim color, // since we need to take potential taskbar into account. - xAnim.setViewBackgroundColor(mLauncher.getScrimView(), - QUICK_SWITCH_FROM_HOME.getWorkspaceScrimColor(mLauncher), LINEAR); + xAnim.setScrimColors(mLauncher.getScrimView(), + QUICK_SWITCH_FROM_HOME.getWorkspaceScrimColor(mLauncher), + LINEAR); if (!mRecentsView.hasTaskViews()) { xAnim.addFloat(mRecentsView, CONTENT_ALPHA, 0f, 1f, LINEAR); } diff --git a/quickstep/src/com/android/quickstep/BaseContainerInterface.java b/quickstep/src/com/android/quickstep/BaseContainerInterface.java index 6e75b79429..b669293516 100644 --- a/quickstep/src/com/android/quickstep/BaseContainerInterface.java +++ b/quickstep/src/com/android/quickstep/BaseContainerInterface.java @@ -17,7 +17,7 @@ package com.android.quickstep; import static com.android.app.animation.Interpolators.INSTANT; import static com.android.app.animation.Interpolators.LINEAR; -import static com.android.launcher3.LauncherAnimUtils.VIEW_BACKGROUND_COLOR; +import static com.android.launcher3.LauncherAnimUtils.SCRIM_COLORS; import static com.android.launcher3.MotionEventsUtils.isTrackpadMultiFingerSwipe; import static com.android.launcher3.util.OverviewReleaseFlags.enableGridOnlyOverview; import static com.android.quickstep.GestureState.GestureEndTarget.LAST_TASK; @@ -47,7 +47,9 @@ import com.android.launcher3.statemanager.StatefulContainer; import com.android.launcher3.taskbar.TaskbarUIController; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.WindowBounds; +import com.android.launcher3.views.ScrimColors; import com.android.launcher3.views.ScrimView; +import com.android.launcher3.views.ScrimColorsEvaluator; import com.android.quickstep.orientation.RecentsPagedOrientationHandler; import com.android.quickstep.util.AnimatorControllerWithResistance; import com.android.quickstep.util.ContextInitListener; @@ -108,7 +110,7 @@ public abstract class BaseContainerInterface { /** * For this state, what color scrim should be drawn behind overview. */ - public int getScrimColor(Context context) { - return hasFlag(FLAG_SCRIM) + public ScrimColors getScrimColor(Context context) { + return new ScrimColors( + /* backgroundColor */ hasFlag(FLAG_SCRIM) ? Themes.getAttrColor(context, R.attr.overviewScrimColor) - : Color.TRANSPARENT; + : Color.TRANSPARENT, + /* foregroundColor */ Color.TRANSPARENT); } public float[] getOverviewScaleAndOffset(RecentsViewContainer container) { diff --git a/res/color/overview_scrim_foreground_primary.xml b/res/color/overview_scrim_foreground_primary.xml new file mode 100644 index 0000000000..68be32d4fa --- /dev/null +++ b/res/color/overview_scrim_foreground_primary.xml @@ -0,0 +1,18 @@ + + + + diff --git a/res/color/overview_scrim_foreground_primary_dark.xml b/res/color/overview_scrim_foreground_primary_dark.xml new file mode 100644 index 0000000000..2b46edc191 --- /dev/null +++ b/res/color/overview_scrim_foreground_primary_dark.xml @@ -0,0 +1,18 @@ + + + + diff --git a/res/color/overview_scrim_foreground_secondary.xml b/res/color/overview_scrim_foreground_secondary.xml new file mode 100644 index 0000000000..f2555ccc0e --- /dev/null +++ b/res/color/overview_scrim_foreground_secondary.xml @@ -0,0 +1,18 @@ + + + + diff --git a/res/color/overview_scrim_foreground_secondary_dark.xml b/res/color/overview_scrim_foreground_secondary_dark.xml new file mode 100644 index 0000000000..79e8d8b4ec --- /dev/null +++ b/res/color/overview_scrim_foreground_secondary_dark.xml @@ -0,0 +1,18 @@ + + + + diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 631dfa9cfd..a3f38323d0 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -48,6 +48,10 @@ + + + + diff --git a/res/values/styles.xml b/res/values/styles.xml index a5b3c17884..801c3d39d9 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -84,6 +84,8 @@ @color/drop_target_hover_text_color_light @color/drop_target_hover_button_color_light @color/overview_scrim + @color/overview_scrim_foreground_primary + @color/overview_scrim_foreground_secondary #80FFFFFF @color/preload_icon_accent_color_light @color/preload_icon_background_color_light @@ -149,6 +151,8 @@ #B3FFFFFF #DD000000 @color/overview_scrim_dark + @color/overview_scrim_foreground_primary_dark + @color/overview_scrim_foreground_secondary_dark #80000000 @color/preload_icon_accent_color_dark @color/preload_icon_background_color_dark diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java index 6a9d170b2c..9157dab143 100644 --- a/src/com/android/launcher3/LauncherAnimUtils.java +++ b/src/com/android/launcher3/LauncherAnimUtils.java @@ -24,12 +24,15 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.util.FloatProperty; import android.util.IntProperty; +import android.util.Property; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import android.widget.TextView; import com.android.launcher3.util.MultiScalePropertyFactory; +import com.android.launcher3.views.ScrimColors; +import com.android.launcher3.views.ScrimView; public class LauncherAnimUtils { /** @@ -201,6 +204,19 @@ public class LauncherAnimUtils { } }; + public static final Property SCRIM_COLORS = + new Property(ScrimColors.class, "scrimColors") { + @Override + public void set(ScrimView scrimView, ScrimColors scrimColors) { + scrimView.setScrimColors(scrimColors); + } + + @Override + public ScrimColors get(ScrimView scrimView) { + return scrimView.getScrimColors(); + } + }; + public static final FloatProperty ROTATION_DRAWABLE_PERCENT = new FloatProperty("drawableRotationPercent") { // RotateDrawable linearly interpolates the rotation degrees between fromDegrees diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index fd91b59aa7..8d628780b4 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -49,6 +49,7 @@ import com.android.launcher3.uioverrides.states.AllAppsState; import com.android.launcher3.uioverrides.states.HintState; import com.android.launcher3.uioverrides.states.OverviewState; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; import java.util.Arrays; @@ -317,8 +318,9 @@ public abstract class LauncherState implements BaseState { * What color should the workspace scrim be in when at rest in this state. * Return {@link Color#TRANSPARENT} for no scrim. */ - public int getWorkspaceScrimColor(Launcher launcher) { - return Color.TRANSPARENT; + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + return new ScrimColors(/* backgroundColor */ Color.TRANSPARENT, + /* foregroundColor */ Color.TRANSPARENT); } /** diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java index 2315111b3b..4043283c1e 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -207,7 +207,7 @@ public class WorkspaceStateTransitionAnimation { propertySetter.setFloat(sysUiScrim.getSysUIProgress(), AnimatedFloat.VALUE, state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR); - propertySetter.setViewBackgroundColor(mLauncher.getScrimView(), + propertySetter.setScrimColors(mLauncher.getScrimView(), state.getWorkspaceScrimColor(mLauncher), config.getInterpolator(ANIM_SCRIM_FADE, ACCELERATE_2)); } diff --git a/src/com/android/launcher3/anim/AnimatedPropertySetter.java b/src/com/android/launcher3/anim/AnimatedPropertySetter.java index 0f1b8ad9c6..9bf479a6dd 100644 --- a/src/com/android/launcher3/anim/AnimatedPropertySetter.java +++ b/src/com/android/launcher3/anim/AnimatedPropertySetter.java @@ -16,7 +16,7 @@ package com.android.launcher3.anim; -import static com.android.launcher3.LauncherAnimUtils.VIEW_BACKGROUND_COLOR; +import static com.android.launcher3.LauncherAnimUtils.SCRIM_COLORS; import android.animation.Animator; import android.animation.Animator.AnimatorListener; @@ -25,13 +25,16 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; -import android.graphics.drawable.ColorDrawable; import android.util.FloatProperty; import android.util.IntProperty; import android.view.View; import androidx.annotation.NonNull; +import com.android.launcher3.views.ScrimColors; +import com.android.launcher3.views.ScrimView; +import com.android.launcher3.views.ScrimColorsEvaluator; + import java.util.function.Consumer; /** @@ -63,15 +66,16 @@ public class AnimatedPropertySetter extends PropertySetter { } @Override - public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) { - if (view == null || (view.getBackground() instanceof ColorDrawable - && ((ColorDrawable) view.getBackground()).getColor() == color)) { + public Animator setScrimColors(ScrimView view, ScrimColors scrimColors, + TimeInterpolator interpolator) { + if (view == null || view.getScrimColors().equals(scrimColors)) { return NO_OP; } - ObjectAnimator anim = ObjectAnimator.ofArgb(view, VIEW_BACKGROUND_COLOR, color); - anim.setInterpolator(interpolator); - add(anim); - return anim; + ObjectAnimator animator = ObjectAnimator.ofObject(view, SCRIM_COLORS, + ScrimColorsEvaluator.INSTANCE, scrimColors); + animator.setInterpolator(interpolator); + add(animator); + return animator; } @Override diff --git a/src/com/android/launcher3/anim/PropertySetter.java b/src/com/android/launcher3/anim/PropertySetter.java index 6ba58b6a98..4ad828169d 100644 --- a/src/com/android/launcher3/anim/PropertySetter.java +++ b/src/com/android/launcher3/anim/PropertySetter.java @@ -19,12 +19,16 @@ package com.android.launcher3.anim; import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.TimeInterpolator; +import android.graphics.drawable.ColorDrawable; import android.util.FloatProperty; import android.util.IntProperty; import android.view.View; import androidx.annotation.NonNull; +import com.android.launcher3.views.ScrimColors; +import com.android.launcher3.views.ScrimView; + import java.util.function.Consumer; /** @@ -59,12 +63,14 @@ public abstract class PropertySetter { } /** - * Sets the background color of the provided view using the provided interpolator. + * Sets the background and foreground color of the provided view using the provided + * interpolator. */ @NonNull - public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) { + public Animator setScrimColors(ScrimView view, ScrimColors scrimColors, + TimeInterpolator interpolator) { if (view != null) { - view.setBackgroundColor(color); + view.setScrimColors(scrimColors); } return NO_OP; } diff --git a/src/com/android/launcher3/views/ScrimColors.kt b/src/com/android/launcher3/views/ScrimColors.kt new file mode 100644 index 0000000000..afbc17209f --- /dev/null +++ b/src/com/android/launcher3/views/ScrimColors.kt @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2025 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.views + +data class ScrimColors(val backgroundColor: Int, val foregroundColor: Int) diff --git a/src/com/android/launcher3/views/ScrimColorsEvaluator.kt b/src/com/android/launcher3/views/ScrimColorsEvaluator.kt new file mode 100644 index 0000000000..81e326a6fa --- /dev/null +++ b/src/com/android/launcher3/views/ScrimColorsEvaluator.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2025 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.views + +import android.animation.ArgbEvaluator +import android.animation.TypeEvaluator + +/** TypeEvaluator that interpolates between [ScrimColors]. */ +object ScrimColorsEvaluator : TypeEvaluator { + + private val argbEvaluator = ArgbEvaluator() + + override fun evaluate( + fraction: Float, + startValue: ScrimColors, + endValue: ScrimColors, + ): ScrimColors = + ScrimColors( + backgroundColor = + argbEvaluator.evaluate( + fraction, + startValue.backgroundColor, + endValue.backgroundColor, + ) as Int, + foregroundColor = + argbEvaluator.evaluate( + fraction, + startValue.foregroundColor, + endValue.foregroundColor, + ) as Int, + ) +} diff --git a/src/com/android/launcher3/views/ScrimView.java b/src/com/android/launcher3/views/ScrimView.java index ec71f3118a..ea87e18703 100644 --- a/src/com/android/launcher3/views/ScrimView.java +++ b/src/com/android/launcher3/views/ScrimView.java @@ -183,6 +183,35 @@ public class ScrimView extends View implements Insettable { mOpaquenessListeners.remove(listener); } + /** + * Set foreground and background color to this ScrimView + */ + public void setScrimColors(ScrimColors scrimColors) { + this.setBackgroundColor(scrimColors.getBackgroundColor()); + setForeground(new ColorDrawable(scrimColors.getForegroundColor())); + } + + /** + * returns foreground and background color of this ScrimView + */ + public ScrimColors getScrimColors() { + int backgroundColor; + if (getBackground() instanceof ColorDrawable colorDrawable) { + backgroundColor = colorDrawable.getColor(); + } else { + backgroundColor = Color.TRANSPARENT; + } + + int foregroundColor; + if (getForeground() instanceof ColorDrawable colorDrawable) { + foregroundColor = colorDrawable.getColor(); + } else { + foregroundColor = Color.TRANSPARENT; + } + + return new ScrimColors(backgroundColor, foregroundColor); + } + /** * A Utility interface allowing for other surfaces to draw on ScrimView */ diff --git a/src_no_quickstep/com/android/launcher3/uioverrides/states/AllAppsState.java b/src_no_quickstep/com/android/launcher3/uioverrides/states/AllAppsState.java index 4882f83f6e..9d0816d5ba 100644 --- a/src_no_quickstep/com/android/launcher3/uioverrides/states/AllAppsState.java +++ b/src_no_quickstep/com/android/launcher3/uioverrides/states/AllAppsState.java @@ -18,11 +18,13 @@ package com.android.launcher3.uioverrides.states; import static com.android.app.animation.Interpolators.DECELERATE; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_ALLAPPS; +import android.graphics.Color; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; /** * Definition for AllApps state @@ -96,9 +98,11 @@ public class AllAppsState extends LauncherState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { - return launcher.getDeviceProfile().getDeviceProperties().isTablet() + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + return new ScrimColors( + /* backgroundColor */ launcher.getDeviceProfile().getDeviceProperties().isTablet() ? launcher.getResources().getColor(R.color.widgets_picker_scrim) - : Themes.getAttrColor(launcher, R.attr.allAppsScrimColor); + : Themes.getAttrColor(launcher, R.attr.allAppsScrimColor), + /* foregroundColor */ Color.TRANSPARENT); } } diff --git a/src_no_quickstep/com/android/launcher3/uioverrides/states/OverviewState.java b/src_no_quickstep/com/android/launcher3/uioverrides/states/OverviewState.java index 532a338237..9627932619 100644 --- a/src_no_quickstep/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/src_no_quickstep/com/android/launcher3/uioverrides/states/OverviewState.java @@ -17,11 +17,13 @@ package com.android.launcher3.uioverrides.states; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_OVERVIEW; +import android.graphics.Color; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.ScrimColors; /** * Definition for overview state @@ -60,7 +62,9 @@ public class OverviewState extends LauncherState { } @Override - public int getWorkspaceScrimColor(Launcher launcher) { - return Themes.getAttrColor(launcher, R.attr.overviewScrimColor); + public ScrimColors getWorkspaceScrimColor(Launcher launcher) { + return new ScrimColors( + /* backgroundColor */ Themes.getAttrColor(launcher, R.attr.overviewScrimColor), + /* foregroundColor */ Color.TRANSPARENT); } }