Snap for 13545933 from 1bec329180 to 25Q3-release
Change-Id: I3727296009d465c09dbe68c51e52d63aa7b049e8
This commit is contained in:
commit
86bc885343
196 files changed
+5762
-474
No files matched your search
+67
-44
@@ -61,6 +61,13 @@ filegroup {
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "launcher-compose-tests-src",
|
||||
srcs: [
|
||||
"compose/tests/**/*.kt",
|
||||
],
|
||||
}
|
||||
|
||||
// Source code for quickstep build, on top of launcher-src
|
||||
filegroup {
|
||||
name: "launcher-quickstep-src",
|
||||
@@ -73,6 +80,13 @@ filegroup {
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "quickstep-compose-tests-src",
|
||||
srcs: [
|
||||
"quickstep/compose/tests/**/*.kt",
|
||||
],
|
||||
}
|
||||
|
||||
// Launcher ProtoLog support
|
||||
filegroup {
|
||||
name: "launcher-quickstep-unprocessed-protolog-src",
|
||||
@@ -185,6 +199,10 @@ filegroup {
|
||||
srcs: ["proguard.flags"],
|
||||
}
|
||||
|
||||
soong_config_bool_variable {
|
||||
name: "release_enable_compose_in_launcher",
|
||||
}
|
||||
|
||||
// Opt-in configuration for Launcher3 code depending on Jetpack Compose.
|
||||
soong_config_module_type {
|
||||
name: "launcher_compose_java_defaults",
|
||||
@@ -197,32 +215,6 @@ soong_config_module_type {
|
||||
],
|
||||
}
|
||||
|
||||
// Opt-in configuration for Launcher Quickstep code depending on Jetpack Compose.
|
||||
soong_config_bool_variable {
|
||||
name: "release_enable_compose_in_launcher",
|
||||
}
|
||||
|
||||
soong_config_module_type {
|
||||
name: "quickstep_compose_java_defaults",
|
||||
module_type: "java_defaults",
|
||||
config_namespace: "ANDROID",
|
||||
bool_variables: ["release_enable_compose_in_launcher"],
|
||||
properties: [
|
||||
"srcs",
|
||||
"static_libs",
|
||||
],
|
||||
}
|
||||
|
||||
soong_config_module_type {
|
||||
name: "launcher_compose_tests_java_defaults",
|
||||
module_type: "java_defaults",
|
||||
config_namespace: "ANDROID",
|
||||
bool_variables: ["release_enable_compose_in_launcher"],
|
||||
properties: [
|
||||
"static_libs",
|
||||
],
|
||||
}
|
||||
|
||||
launcher_compose_java_defaults {
|
||||
name: "launcher_compose_defaults",
|
||||
soong_config_variables: {
|
||||
@@ -235,6 +227,8 @@ launcher_compose_java_defaults {
|
||||
static_libs: [
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.compose.ui_ui-tooling-preview",
|
||||
"androidx.compose.ui_ui-tooling",
|
||||
],
|
||||
|
||||
// By default, Compose is disabled and we compile the ComposeFacade
|
||||
@@ -249,6 +243,51 @@ launcher_compose_java_defaults {
|
||||
},
|
||||
}
|
||||
|
||||
soong_config_module_type {
|
||||
name: "launcher_compose_tests_java_defaults",
|
||||
module_type: "java_defaults",
|
||||
config_namespace: "ANDROID",
|
||||
bool_variables: ["release_enable_compose_in_launcher"],
|
||||
properties: [
|
||||
"srcs",
|
||||
"static_libs",
|
||||
],
|
||||
}
|
||||
|
||||
launcher_compose_tests_java_defaults {
|
||||
name: "launcher_compose_tests_defaults",
|
||||
soong_config_variables: {
|
||||
release_enable_compose_in_launcher: {
|
||||
srcs: [
|
||||
":launcher-compose-tests-src",
|
||||
],
|
||||
// Compose dependencies
|
||||
static_libs: [
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui-test-junit4",
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
],
|
||||
|
||||
conditions_default: {
|
||||
srcs: [],
|
||||
static_libs: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Opt-in configuration for Launcher Quickstep code depending on Jetpack Compose.
|
||||
soong_config_module_type {
|
||||
name: "quickstep_compose_java_defaults",
|
||||
module_type: "java_defaults",
|
||||
config_namespace: "ANDROID",
|
||||
bool_variables: ["release_enable_compose_in_launcher"],
|
||||
properties: [
|
||||
"srcs",
|
||||
"static_libs",
|
||||
],
|
||||
}
|
||||
|
||||
quickstep_compose_java_defaults {
|
||||
name: "quickstep_compose_defaults",
|
||||
soong_config_variables: {
|
||||
@@ -261,6 +300,8 @@ quickstep_compose_java_defaults {
|
||||
static_libs: [
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.compose.ui_ui-tooling-preview",
|
||||
"androidx.compose.ui_ui-tooling",
|
||||
],
|
||||
|
||||
// By default, Compose is disabled and we compile the ComposeFacade
|
||||
@@ -275,24 +316,6 @@ quickstep_compose_java_defaults {
|
||||
},
|
||||
}
|
||||
|
||||
launcher_compose_tests_java_defaults {
|
||||
name: "launcher_compose_tests_defaults",
|
||||
soong_config_variables: {
|
||||
release_enable_compose_in_launcher: {
|
||||
// Compose dependencies
|
||||
static_libs: [
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui-test-junit4",
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
],
|
||||
|
||||
conditions_default: {
|
||||
static_libs: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "launcher-aosp-tapl",
|
||||
libs: [
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
import android.animation.TimeInterpolator
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.animation.core.Easing
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
|
||||
/**
|
||||
* Converts a [TimeInterpolator] to a compose [Easing].
|
||||
*
|
||||
* This function allows you to use Android's [TimeInterpolator] instances, such as those defined in
|
||||
* `android.R.interpolator`, directly with Compose animations that expect an [Easing].
|
||||
*/
|
||||
fun TimeInterpolator.toComposeEasing(): Easing = Easing { fraction -> getInterpolation(fraction) }
|
||||
|
||||
/**
|
||||
* A composable function that takes a [Drawable] and converts it into a [Painter] which can be used
|
||||
* to draw the drawable on a Compose canvas.
|
||||
*
|
||||
* This function uses [remember] to cache the conversion of the [Drawable] to an [ImageBitmap]. This
|
||||
* means that if the same [Drawable] instance is provided across recompositions, the conversion will
|
||||
* only happen once, improving performance.
|
||||
*/
|
||||
@Composable
|
||||
fun painterResource(drawable: Drawable): Painter {
|
||||
val imageBitmap = remember(drawable) { drawable.toBitmap().asImageBitmap() }
|
||||
return BitmapPainter(imageBitmap)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A multi-preview annotation that displays the same Composable with different font scales.
|
||||
*/
|
||||
@Preview(name = "normal font", group = "font scales", fontScale = 1f)
|
||||
@Preview(name = "large font", group = "font scales", fontScale = 2f)
|
||||
annotation class FontScalePreviews
|
||||
@@ -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.helper
|
||||
|
||||
import androidx.compose.ui.input.key.KeyEvent
|
||||
import androidx.compose.ui.input.key.NativeKeyEvent
|
||||
import androidx.compose.ui.test.SemanticsMatcher
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
val NATIVE_DPAD_DOWN = NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_DPAD_DOWN)
|
||||
val NATIVE_TAB = NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_TAB)
|
||||
val NavigateDownKeyEvent = KeyEvent(NATIVE_DPAD_DOWN)
|
||||
val NavigateDownTabEvent = KeyEvent(NATIVE_TAB)
|
||||
|
||||
fun hasMinTouchArea(minWidth: Dp = 48.dp, minHeight: Dp = 48.dp): SemanticsMatcher =
|
||||
SemanticsMatcher("touch area is smaller than $minWidth x $minHeight") { node ->
|
||||
val density: Density = node.root?.density ?: error("root node not available!")
|
||||
with(density) {
|
||||
val rect = node.touchBoundsInRoot
|
||||
val size = node.size
|
||||
(rect.width.toDp() >= minWidth && rect.height.toDp() >= minHeight) ||
|
||||
(size.width.toDp() >= minWidth && size.height.toDp() >= minHeight)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ android_library {
|
||||
sdk_version: "current",
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
srcs: [
|
||||
"src/com/android/launcher3/widgetpicker/WidgetPickerSingleton.kt",
|
||||
"src/com/android/launcher3/widgetpicker/Annotations.kt",
|
||||
],
|
||||
|
||||
static_libs: [
|
||||
@@ -42,6 +42,10 @@ android_library {
|
||||
static_libs: [
|
||||
"dagger2",
|
||||
"widget_picker_dagger_annotations",
|
||||
"widget_picker_data_repositories",
|
||||
"widget_picker_shared_data_types",
|
||||
"widget_picker_domain_layer",
|
||||
"widget_picker_ui",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -52,11 +56,13 @@ android_library {
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
srcs: [
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/PickableWidget.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetApp.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetAppIcon.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetAppId.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetId.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetPreview.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetUserProfiles.kt",
|
||||
"src/com/android/launcher3/widgetpicker/shared/model/WidgetHostInfo.kt",
|
||||
],
|
||||
static_libs: [
|
||||
"androidx.core_core-ktx",
|
||||
@@ -70,8 +76,6 @@ android_library {
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
srcs: [
|
||||
"src/com/android/launcher3/widgetpicker/data/repository/WidgetAppIconsRepository.kt",
|
||||
"src/com/android/launcher3/widgetpicker/data/repository/WidgetPreviewRepository.kt",
|
||||
"src/com/android/launcher3/widgetpicker/data/repository/WidgetRecommendationsRepository.kt",
|
||||
"src/com/android/launcher3/widgetpicker/data/repository/WidgetsRepository.kt",
|
||||
"src/com/android/launcher3/widgetpicker/data/repository/WidgetUsersRepository.kt",
|
||||
],
|
||||
@@ -82,6 +86,26 @@ android_library {
|
||||
],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "widget_picker_domain_layer",
|
||||
sdk_version: "current",
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
srcs: [
|
||||
"src/com/android/launcher3/widgetpicker/domain/usecase/GroupWidgetAppsByProfileUseCase.kt",
|
||||
"src/com/android/launcher3/widgetpicker/domain/usecase/FilterWidgetsForHostUseCase.kt",
|
||||
"src/com/android/launcher3/widgetpicker/domain/interactor/WidgetsInteractor.kt",
|
||||
"src/com/android/launcher3/widgetpicker/domain/interactor/WidgetAppIconsInteractor.kt",
|
||||
],
|
||||
static_libs: [
|
||||
"widget_picker_shared_data_types",
|
||||
"widget_picker_data_repositories",
|
||||
"widget_picker_dagger_annotations",
|
||||
"dagger2",
|
||||
"kotlinx-coroutines-android",
|
||||
"kotlinx-coroutines-core",
|
||||
],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "widget_picker_ui_data_types",
|
||||
sdk_version: "current",
|
||||
@@ -137,6 +161,43 @@ android_library {
|
||||
],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "widget_picker_ui",
|
||||
sdk_version: "current",
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
srcs: [
|
||||
"src/com/android/launcher3/widgetpicker/ui/ViewModel.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalog.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalogViewModel.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreen.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePane.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPane.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenViewModel.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreen.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/search/SearchScreenViewModel.kt",
|
||||
"src/com/android/launcher3/widgetpicker/ui/WidgetPickerEventListeners.kt",
|
||||
],
|
||||
static_libs: [
|
||||
"widget_picker_ui_components",
|
||||
"widget_picker_ui_data_types",
|
||||
"widget_picker_domain_layer",
|
||||
"dagger2",
|
||||
"widget_picker_dagger_annotations",
|
||||
"androidx.compose.foundation_foundation",
|
||||
"androidx.compose.foundation_foundation-layout",
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui",
|
||||
"androidx.compose.ui_ui-tooling",
|
||||
"androidx.compose.material3_material3",
|
||||
"androidx.compose.material3_material3-window-size-class",
|
||||
"androidx.compose.material_material-icons-extended",
|
||||
"androidx.activity_activity-compose",
|
||||
"widget_picker_window_size_class",
|
||||
"kotlinx-coroutines-android",
|
||||
"kotlinx-coroutines-core",
|
||||
],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "widget_picker_window_size_class",
|
||||
sdk_version: "current",
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
"presubmit": [
|
||||
{
|
||||
"name": "WidgetPickerScreenshotTests"
|
||||
},
|
||||
{
|
||||
"name": "WidgetPickerDeviceTests"
|
||||
},
|
||||
{
|
||||
"name": "WidgetPickerRoboTests"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -44,7 +44,17 @@ android {
|
||||
res.setSrcDirs(listOf("$widgetPickerDir/res"))
|
||||
}
|
||||
named("androidTest") {
|
||||
java.setSrcDirs(listOf("$widgetPickerDir/tests/multivalentScreenshotTests/src/"))
|
||||
java.setSrcDirs(
|
||||
listOf(
|
||||
"$widgetPickerDir/tests/multivalentScreenshotTests/src",
|
||||
"$widgetPickerDir/tests/multivalentTestsForDevice/src",
|
||||
)
|
||||
)
|
||||
manifest.srcFile("$widgetPickerDir/tests/AndroidManifest.xml")
|
||||
}
|
||||
named("test") {
|
||||
java.setSrcDirs(listOf("$widgetPickerDir/tests/multivalentTests/src"))
|
||||
resources.setSrcDirs(listOf("$widgetPickerDir/tests/config"))
|
||||
manifest.srcFile("$widgetPickerDir/tests/AndroidManifest.xml")
|
||||
res.setSrcDirs(listOf("$widgetPickerDir/tests/multivalentScreenshotTests/res"))
|
||||
}
|
||||
@@ -94,14 +104,19 @@ dependencies {
|
||||
testImplementation(libs.mockito.robolectric.bytebuddy.agent)
|
||||
testImplementation(libs.mockito.robolectric.bytebuddy)
|
||||
testImplementation(libs.mockito.robolectric)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.google.truth)
|
||||
testImplementation(libs.androidx.test.runner)
|
||||
testImplementation(libs.androidx.junit)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
|
||||
androidTestImplementation(libs.google.truth)
|
||||
androidTestImplementation(libs.junit)
|
||||
androidTestImplementation(libs.mockito.kotlin)
|
||||
androidTestImplementation(libs.androidx.test.runner)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.test.rules)
|
||||
androidTestImplementation(libs.kotlinx.coroutines.test)
|
||||
|
||||
// Compose UI Tests
|
||||
testApi(libs.compose.ui.test.junit4)
|
||||
androidTestApi(libs.compose.ui.test.junit4)
|
||||
debugApi(libs.compose.ui.test.manifest)
|
||||
|
||||
@@ -112,3 +127,8 @@ dependencies {
|
||||
androidTestImplementation(project(":ScreenshotLib"))
|
||||
androidTestImplementation(project(":ScreenshotComposeLib"))
|
||||
}
|
||||
|
||||
// Work around for kotlin bug with symlinked source: http://b/316363701
|
||||
tasks.matching { it.name.matches(Regex("widgetpicker.*compile.*TestKotlin")) }.configureEach {
|
||||
inputs.dir("$widgetPickerDir/tests/multivalentTests/src")
|
||||
}
|
||||
@@ -34,6 +34,13 @@
|
||||
[CHAR_LIMIT=25] -->
|
||||
<string name="featured_widgets_tab_label">Featured</string>
|
||||
|
||||
<!-- Tab label. A user can tap this tab to access list of all apps hosting appwidgets.
|
||||
[CHAR_LIMIT=25] -->
|
||||
<string name="browse_widgets_tab_label">Browse</string>
|
||||
|
||||
<!-- accessibilityPaneTitle for the right pane when showing widgets selected on left. -->
|
||||
<string name="widget_picker_right_pane_accessibility_label"><xliff:g id="selected_header" example="Calendar">%1$s</xliff:g> widgets on right, search and options on left</string>
|
||||
|
||||
<!-- Search bar strings -->
|
||||
<!-- Placeholder text displayed in the widget's search bar [CHAR_LIMIT=50] -->
|
||||
<string name="widgets_search_bar_hint">Search</string>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 javax.inject.Qualifier
|
||||
import javax.inject.Scope
|
||||
|
||||
/** Scope annotation for singleton items within the widget picker. */
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Scope
|
||||
annotation class WidgetPickerSingleton
|
||||
|
||||
/** Qualifier annotation for the background context used in interactors. */
|
||||
@Qualifier
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class WidgetPickerBackground
|
||||
|
||||
/** Qualifier annotation for information about the widget host. */
|
||||
@Qualifier
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class WidgetPickerHostInfo
|
||||
|
||||
@Qualifier
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class WidgetPickerRepository
|
||||
+32
-20
@@ -16,7 +16,14 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker
|
||||
|
||||
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 com.android.launcher3.widgetpicker.ui.fullcatalog.FullWidgetsCatalog
|
||||
import dagger.BindsInstance
|
||||
import dagger.Subcomponent
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* A sub-component that apps can include in their dagger module to bootstrap & interact with apis
|
||||
@@ -25,39 +32,44 @@ import dagger.Subcomponent
|
||||
* Steps:
|
||||
* 1. Include this component as a sub-component on your app's main dagger module (and remember to
|
||||
* update Android.bp & gradle files).
|
||||
* 2. Ensure bindings necessary for repository interfaces used in [WidgetPickerModule] are provided
|
||||
* in your app.
|
||||
* 3. Host a singleton class in your app to create an instance of widget picker component on-demand
|
||||
* e.g. when user wants to open widget picker.
|
||||
* 2. Host a singleton class in your app to create an instance of widget picker component on-demand
|
||||
* e.g. when user wants to open widget picker. The component factory takes in a few dependencies
|
||||
* that should be implemented e.g. the repository implementations.
|
||||
*
|
||||
* Example for #3.
|
||||
* Example of using the component and opening the picker.
|
||||
*
|
||||
* ```
|
||||
* @MyAppSingleton
|
||||
* public class WidgetPickerProvider {
|
||||
* private final Provider<WidgetPickerComponent.Factory> widgetPickerComponentProvider;
|
||||
*
|
||||
* @Inject
|
||||
* public WidgetPickerProvider(Provider<WidgetPickerComponent.Factory> widgetPickerComponentProvider) {
|
||||
* this.widgetPickerComponentProvider = widgetPickerComponentProvider;
|
||||
* }
|
||||
*
|
||||
* public class WidgetPickerProvider @Inject constructor(
|
||||
* private val Provider<WidgetPickerComponent.Factory> widgetPickerComponentProvider
|
||||
* ) {
|
||||
* public boolean show(...) {
|
||||
* WidgetPickerComponent component = widgetPickerComponentProvider.get().build();
|
||||
* WidgetPickerUiInteractor interactor = component.getWidgetInteractor();
|
||||
* return interactor.show(...);
|
||||
* WidgetPickerComponent component = widgetPickerComponentProvider.get().build(...);
|
||||
* FullCatalog catalog = component.getFullWidgetsCatalog();
|
||||
* return catalog.show(...);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
@WidgetPickerSingleton
|
||||
@Subcomponent(modules = [WidgetPickerModule::class])
|
||||
@Subcomponent
|
||||
interface WidgetPickerComponent {
|
||||
@Subcomponent.Factory
|
||||
interface Factory {
|
||||
fun build(): WidgetPickerComponent
|
||||
fun build(
|
||||
@WidgetPickerRepository @BindsInstance
|
||||
widgetsRepository: WidgetsRepository,
|
||||
@WidgetPickerRepository @BindsInstance
|
||||
widgetUsersRepository: WidgetUsersRepository,
|
||||
@WidgetPickerRepository @BindsInstance
|
||||
widgetAppIconsRepository: WidgetAppIconsRepository,
|
||||
@WidgetPickerHostInfo @BindsInstance
|
||||
widgetHostInfo: WidgetHostInfo,
|
||||
@WidgetPickerBackground @BindsInstance
|
||||
backgroundContext: CoroutineContext
|
||||
): WidgetPickerComponent
|
||||
}
|
||||
|
||||
// Interactors / APIs available for clients to interact with widget picker will go here.
|
||||
// e.g. fun getWidgetPickerUiInteractor(): WidgetPickerUiInteractor
|
||||
/** Provides UI for the catalog of all widgets on device. */
|
||||
fun getFullWidgetsCatalog(): FullWidgetsCatalog
|
||||
}
|
||||
+9
@@ -22,9 +22,18 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/** A repository that provides app icons for the widget picker. */
|
||||
interface WidgetAppIconsRepository {
|
||||
/**
|
||||
* A hook to setup the repository so clients can observe the widgets available on device.
|
||||
* This serves as a place to start listening to the backing caches / data sources.
|
||||
*/
|
||||
fun initialize()
|
||||
|
||||
/**
|
||||
* Loads and returns app icon (may initially return a low res icon, followed by a high res once
|
||||
* available).
|
||||
*/
|
||||
fun getAppIcon(widgetAppId: WidgetAppId): Flow<WidgetAppIcon>
|
||||
|
||||
/** Clean up any external listeners or state (if necessary). */
|
||||
fun cleanUp()
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* 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.data.repository
|
||||
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetId
|
||||
|
||||
/** A repository of widgets that can be recommended to the users in widget picker. */
|
||||
interface WidgetRecommendationsRepository {
|
||||
/** Returns a list of widgets that can be recommended to the users in the widget picker. */
|
||||
suspend fun getRecommendations(): List<WidgetId>
|
||||
}
|
||||
+14
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker.data.repository
|
||||
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfileType
|
||||
import android.os.UserHandle
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@@ -25,6 +25,18 @@ import kotlinx.coroutines.flow.Flow
|
||||
* the widget picker.
|
||||
*/
|
||||
interface WidgetUsersRepository {
|
||||
/**
|
||||
* A hook to setup the repository so clients can observe the widgets available on device.
|
||||
* This serves as a place to start listening to the backing caches / data sources.
|
||||
*/
|
||||
fun initialize()
|
||||
|
||||
/** Get and listen to the changes in available user profiles. */
|
||||
fun observeUsers(types: List<WidgetUserProfileType>): Flow<WidgetUserProfiles>
|
||||
fun observeUserProfiles(): Flow<WidgetUserProfiles?>
|
||||
|
||||
/** Indicates if a user is a work profile user. */
|
||||
fun getWorkProfileUser(): UserHandle?
|
||||
|
||||
/** Clean up any external listeners or state (if necessary). */
|
||||
fun cleanUp()
|
||||
}
|
||||
+25
-2
@@ -17,11 +17,34 @@
|
||||
package com.android.launcher3.widgetpicker.data.repository
|
||||
|
||||
import com.android.launcher3.widgetpicker.shared.model.PickableWidget
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetApp
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/** A repository of widgets available on the device from various apps */
|
||||
interface WidgetsRepository {
|
||||
/**
|
||||
* A hook to setup the repository so clients can observe the widgets available on device.
|
||||
* This serves as a place to start listening to the backing caches / data sources.
|
||||
*/
|
||||
fun initialize()
|
||||
|
||||
/** Observe widgets available on the device. */
|
||||
fun observeWidgets(): Flow<List<PickableWidget>>
|
||||
/** Observe widgets available on the device from different apps. */
|
||||
fun observeWidgets(): Flow<List<WidgetApp>>
|
||||
|
||||
/** Loads a preview for an app widget. Returns a placeholder preview if the widget is not found. */
|
||||
suspend fun getWidgetPreview(id: WidgetId): WidgetPreview
|
||||
|
||||
/** Get widgets that can be featured in widget picker. */
|
||||
fun getFeaturedWidgets(): Flow<List<PickableWidget>>
|
||||
|
||||
/**
|
||||
* Search widgets and their apps that match the given plain text [query] string typed by the
|
||||
* user. Matches the widget's label, description and app's title (case-insensitive).
|
||||
*/
|
||||
suspend fun searchWidgets(query: String): List<WidgetApp>
|
||||
|
||||
/** Clean up any external listeners or state (if necessary). */
|
||||
fun cleanUp()
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.domain.interactor
|
||||
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerBackground
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerRepository
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerSingleton
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppIcon
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* A domain layer object that enables the UI layer to get the apps icons from data layer.
|
||||
* - Responsible for merging the necessary information from widgets and app icons repositories to
|
||||
* provide the app icons.
|
||||
*/
|
||||
@WidgetPickerSingleton
|
||||
class WidgetAppIconsInteractor @Inject constructor(
|
||||
@WidgetPickerRepository
|
||||
private val widgetAppIconsRepository: WidgetAppIconsRepository,
|
||||
@WidgetPickerRepository
|
||||
private val widgetsRepository: WidgetsRepository,
|
||||
@WidgetPickerBackground
|
||||
private val backgroundContext: CoroutineContext,
|
||||
) {
|
||||
/** Returns a flow of icons for all widget apps that host widgets. */
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun getAllWidgetAppIcons(): Flow<Map<WidgetAppId, WidgetAppIcon>> =
|
||||
widgetsRepository.observeWidgets().flatMapLatest { widgetApps ->
|
||||
val flows: List<Flow<Pair<WidgetAppId, WidgetAppIcon>>> = widgetApps.map { widgetApp ->
|
||||
widgetAppIconsRepository.getAppIcon(widgetApp.id).map {
|
||||
widgetApp.id to it
|
||||
}
|
||||
}
|
||||
|
||||
combine(flows) { it.toMap() }
|
||||
}.flowOn(backgroundContext)
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.domain.interactor
|
||||
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerBackground
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerRepository
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerSingleton
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.FilterWidgetsForHostUseCase
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.GroupWidgetAppsByProfileUseCase
|
||||
import com.android.launcher3.widgetpicker.shared.model.PickableWidget
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetApp
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* A domain layer object that enables the UI layer to interact with the widgets in data layer.
|
||||
* - Responsible for applying business rules such as applying host constraints, filtering data for
|
||||
* paused work profile, etc.
|
||||
*/
|
||||
@WidgetPickerSingleton
|
||||
class WidgetsInteractor
|
||||
@Inject
|
||||
constructor(
|
||||
@WidgetPickerRepository
|
||||
private val widgetsRepository: WidgetsRepository,
|
||||
@WidgetPickerRepository
|
||||
private val widgetUsersRepository: WidgetUsersRepository,
|
||||
private val filterWidgetsForHostUseCase: FilterWidgetsForHostUseCase,
|
||||
private val getWidgetAppsByProfileUseCase: GroupWidgetAppsByProfileUseCase,
|
||||
@WidgetPickerBackground
|
||||
private val backgroundContext: CoroutineContext,
|
||||
) {
|
||||
/** Returns the list of widget apps per user profiles. */
|
||||
fun getWidgetAppsByProfile(): Flow<Map<WidgetUserProfile, List<WidgetApp>>> =
|
||||
combine(
|
||||
widgetsRepository.observeWidgets(),
|
||||
widgetUsersRepository.observeUserProfiles()
|
||||
) { widgetApps,
|
||||
widgetUserProfiles ->
|
||||
val filteredWidgets =
|
||||
widgetApps
|
||||
.map { it.copy(widgets = filterWidgetsForHostUseCase(it.widgets)) }
|
||||
.filter { it.widgets.isNotEmpty() }
|
||||
.sortedBy { it.title?.toString() ?: "" }
|
||||
widgetUserProfiles?.let {
|
||||
getWidgetAppsByProfileUseCase(
|
||||
filteredWidgets,
|
||||
widgetUserProfiles,
|
||||
widgetUsersRepository.getWorkProfileUser(),
|
||||
)
|
||||
} ?: emptyMap()
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.flowOn(backgroundContext)
|
||||
|
||||
/** Loads and returns the preview for an appwidget. */
|
||||
suspend fun getWidgetPreview(widgetId: WidgetId): WidgetPreview =
|
||||
widgetsRepository.getWidgetPreview(widgetId)
|
||||
|
||||
/** Returns widgets that can be featured in the widget picker. */
|
||||
fun getFeaturedWidgets(): Flow<List<PickableWidget>> =
|
||||
combine(
|
||||
widgetsRepository.getFeaturedWidgets(),
|
||||
widgetUsersRepository.observeUserProfiles(),
|
||||
) { widgets, widgetUserProfiles ->
|
||||
val filteredWidgets = filterWidgetsForHostUseCase(widgets)
|
||||
|
||||
val hasPausedWorkProfile =
|
||||
widgetUserProfiles?.work?.paused ?: false
|
||||
val workProfileUser =
|
||||
if (hasPausedWorkProfile) {
|
||||
checkNotNull(widgetUsersRepository.getWorkProfileUser())
|
||||
} else null
|
||||
|
||||
return@combine if (hasPausedWorkProfile) {
|
||||
filteredWidgets.filter { it.id.userHandle != workProfileUser }
|
||||
} else {
|
||||
filteredWidgets
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Returns the list of widget apps that match the given plain text [query] string entered by the
|
||||
* user. The widget's label, description and app's title is expected to be considered for
|
||||
* returning matches.
|
||||
*
|
||||
* Filters out
|
||||
* - widgets that don't match the host criteria
|
||||
* - when work profile is paused, work profile widgets are also filtered out.
|
||||
*/
|
||||
suspend fun searchWidgetApps(query: String): Flow<List<WidgetApp>> =
|
||||
withContext(backgroundContext) {
|
||||
val matchedWidgetApps = widgetsRepository.searchWidgets(query).map {
|
||||
it.copy(
|
||||
widgets = filterWidgetsForHostUseCase(it.widgets)
|
||||
)
|
||||
}.filter { it.widgets.isNotEmpty() }
|
||||
|
||||
// business rule: We don't show work profile widgets when profile is paused.
|
||||
val workProfileUser = widgetUsersRepository.getWorkProfileUser()
|
||||
if (workProfileUser != null) {
|
||||
widgetUsersRepository.observeUserProfiles().map { profiles ->
|
||||
val paused = checkNotNull(profiles?.work).paused
|
||||
if (paused) {
|
||||
matchedWidgetApps.filter { it.id.userHandle != workProfileUser }
|
||||
} else {
|
||||
matchedWidgetApps
|
||||
}
|
||||
}
|
||||
} else {
|
||||
flowOf(matchedWidgetApps)
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.domain.usecase
|
||||
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerHostInfo
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerSingleton
|
||||
import com.android.launcher3.widgetpicker.shared.model.HostConstraint
|
||||
import com.android.launcher3.widgetpicker.shared.model.PickableWidget
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
/**
|
||||
* A usecase that hosts the business logic of filtering widgets based on host constraints and
|
||||
* information.
|
||||
*/
|
||||
@WidgetPickerSingleton
|
||||
class FilterWidgetsForHostUseCase
|
||||
@Inject
|
||||
constructor(@WidgetPickerHostInfo private val hostInfo: WidgetHostInfo) {
|
||||
operator fun invoke(widgets: List<PickableWidget>) =
|
||||
widgets.filter { widget ->
|
||||
val eligibleForHost =
|
||||
hostInfo.constraints.all { constraint ->
|
||||
when (constraint) {
|
||||
is HostConstraint.HostUserConstraint ->
|
||||
!constraint.userFilters.contains(widget.id.userHandle)
|
||||
|
||||
is HostConstraint.HostCategoryConstraint -> {
|
||||
val widgetCategory = widget.appWidgetProviderInfo.widgetCategory
|
||||
matchesCategory(constraint.categoryInclusionMask, widgetCategory) &&
|
||||
matchesCategory(constraint.categoryExclusionMask, widgetCategory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eligibleForHost
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* A filter that can be applied on the widgetCategory attribute from appwidget-provider to
|
||||
* identify if the widget can be displayed on a specific widget surface.
|
||||
* - Negative value (e.g. "category_a.inv() and category_b.inv()" excludes the widgets with
|
||||
* given categories.
|
||||
* - Positive value (e.g. "category_a or category_b" includes widgets with those categories.
|
||||
* - 0 means no filter.
|
||||
*/
|
||||
private fun matchesCategory(categoryMask: Int, widgetCategory: Int): Boolean {
|
||||
return if (categoryMask > 0) { // inclusion filter
|
||||
(widgetCategory and categoryMask) != 0
|
||||
} else if (categoryMask < 0) { // exclusion filter
|
||||
(widgetCategory and categoryMask) == widgetCategory
|
||||
} else {
|
||||
true // no filter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.domain.usecase
|
||||
|
||||
import android.os.UserHandle
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetApp
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import javax.inject.Inject
|
||||
|
||||
/** A helper class that groups widget apps by user profiles. */
|
||||
class GroupWidgetAppsByProfileUseCase @Inject constructor() {
|
||||
operator fun invoke(
|
||||
widgetApps: List<WidgetApp>,
|
||||
userProfiles: WidgetUserProfiles,
|
||||
workProfileUser: UserHandle?,
|
||||
): Map<WidgetUserProfile, List<WidgetApp>> {
|
||||
val personalProfile = userProfiles.personal
|
||||
val workProfile = userProfiles.work
|
||||
|
||||
return when {
|
||||
(workProfile != null && workProfileUser != null) -> {
|
||||
val (workWidgetApps, personalWidgetApps) =
|
||||
widgetApps.partition { it.id.userHandle == workProfileUser }
|
||||
val finalWorkWidgetApps =
|
||||
(workWidgetApps.takeIf { !workProfile.paused } ?: emptyList())
|
||||
|
||||
mapOf(personalProfile to personalWidgetApps, workProfile to finalWorkWidgetApps)
|
||||
}
|
||||
|
||||
else -> mapOf(personalProfile to widgetApps)
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -39,7 +39,12 @@ data class PickableWidget(
|
||||
val description: CharSequence?,
|
||||
val appWidgetProviderInfo: AppWidgetProviderInfo,
|
||||
val sizeInfo: WidgetSizeInfo,
|
||||
)
|
||||
) {
|
||||
// Custom toString to account for the appWidgetProviderInfo.
|
||||
override fun toString(): String =
|
||||
"PickableWidget(id=$id,appId=$appId,label=$label,description=$description," +
|
||||
"sizeInfo=$sizeInfo,provider=${appWidgetProviderInfo.provider})"
|
||||
}
|
||||
|
||||
/**
|
||||
* Sizing information for a specific widget shown in a grid.
|
||||
|
||||
+15
-10
@@ -1,3 +1,5 @@
|
||||
package com.android.launcher3.widgetpicker.shared.model
|
||||
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
@@ -14,13 +16,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.widgetpicker.data.repository
|
||||
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
|
||||
/** A repository that provides previews for the widgets to be displayed in the widget picker. */
|
||||
interface WidgetPreviewRepository {
|
||||
/** Returns the preview for a widget represented by given [WidgetId]. */
|
||||
suspend fun getPreview(widgetId: WidgetId): WidgetPreview
|
||||
}
|
||||
/**
|
||||
* Represents an app hosting widgets that is shown in widget picker.
|
||||
*
|
||||
* @param id a unique identifier for the app
|
||||
* @param title a user readable title for the app; if null a placeholder text (e.g. "pending..")
|
||||
* is shown until the title is loaded.
|
||||
* @param widgets list of widgets available to picker from the app.
|
||||
*/
|
||||
data class WidgetApp(
|
||||
val id: WidgetAppId,
|
||||
val title: CharSequence?,
|
||||
val widgets: List<PickableWidget>,
|
||||
)
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.shared.model
|
||||
|
||||
import android.os.UserHandle
|
||||
|
||||
/**
|
||||
* Data class that holds information about the host needs to display the widget picker.
|
||||
*
|
||||
* @param title an optional title that should be shown in place of default "Widgets" title.
|
||||
* @param description an optional 1-2 line description to be shown below the title. If not set, no
|
||||
* description is shown.
|
||||
* @param constraints constraints around which widgets can be shown in the picker.
|
||||
*/
|
||||
data class WidgetHostInfo(
|
||||
val title: String? = null,
|
||||
val description: String? = null,
|
||||
val constraints: List<HostConstraint> = emptyList(),
|
||||
)
|
||||
|
||||
/** Various constraints for the widget host. */
|
||||
sealed class HostConstraint {
|
||||
/**
|
||||
* A constraint to apply on `widgetCategory` when deciding whether to show a widget in the
|
||||
* widget picker.
|
||||
*
|
||||
* @param categoryInclusionMask mask that includes widgets matching the given widget category
|
||||
* mask e.g. HOME_SCREEN or KEYGUARD; 0 implies no mask
|
||||
* @param categoryExclusionMask mask that excludes widgets matching the mask e.g.
|
||||
* NOT_KEYGUARD.inv(); 0 implies no mask
|
||||
*/
|
||||
data class HostCategoryConstraint(
|
||||
val categoryInclusionMask: Int,
|
||||
val categoryExclusionMask: Int,
|
||||
) : HostConstraint()
|
||||
|
||||
/**
|
||||
* A constraint to apply on `user` associated with widgets shown in widget picker.
|
||||
*
|
||||
* @param userFilters user profiles for which widgets list should be shown as empty. e.g. for
|
||||
* lockscreen widgets, based on an admin setting, the host may filter out work widgets. In
|
||||
* such case, the profile tab shows a generic no widgets available message.
|
||||
*/
|
||||
data class HostUserConstraint(val userFilters: List<UserHandle>) : HostConstraint()
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ package com.android.launcher3.widgetpicker.shared.model
|
||||
* Holds data about all the available user profiles on device that are supported in the widget
|
||||
* picker.
|
||||
*/
|
||||
data class WidgetUserProfiles(val users: List<WidgetUserProfile>)
|
||||
data class WidgetUserProfiles(val personal: WidgetUserProfile, val work: WidgetUserProfile?)
|
||||
|
||||
/**
|
||||
* Data about a specific user profile that is supported in the widget picker.
|
||||
@@ -36,8 +36,8 @@ data class WidgetUserProfiles(val users: List<WidgetUserProfile>)
|
||||
data class WidgetUserProfile(
|
||||
val type: WidgetUserProfileType,
|
||||
val label: String,
|
||||
val paused: Boolean,
|
||||
val pausedProfileMessage: String,
|
||||
val paused: Boolean = false,
|
||||
val pausedProfileMessage: String? = null,
|
||||
)
|
||||
|
||||
/** Represents types of user profiles that are supported in the widget picker. */
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.ui
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
/**
|
||||
* An interface defining general structure of a view model in widget picker.
|
||||
*/
|
||||
// TODO(b/419844646): Once stable, introduce a reusable library.
|
||||
internal interface ViewModel {
|
||||
/**
|
||||
* Implement this function to initialize the state of viewmodel by binding to the flows from the
|
||||
* interactors.
|
||||
*
|
||||
* Then when the UI calls [rememberViewModel], this callback function will be invoked.
|
||||
*
|
||||
* e.g. coroutineScope {
|
||||
* launch { myInteractor.myData().collectLatest {..} }
|
||||
* launch { myChildViewModel.onInit() }
|
||||
*
|
||||
* awaitCancellation()
|
||||
* }
|
||||
*/
|
||||
suspend fun onInit() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a remembered instance of the [ViewModel] of type [T].
|
||||
*
|
||||
* Also, initialize the view model.
|
||||
* @param key a unique key to remember the view model
|
||||
* @param animationDelay delay for animations to finish (if animations are enabled) before binding
|
||||
* data in view model for a smoother transition.
|
||||
*/
|
||||
@Composable
|
||||
fun <T : ViewModel> rememberViewModel(
|
||||
key: Any = Unit,
|
||||
animationDelay: Long = 0L,
|
||||
factory: () -> T,
|
||||
): T {
|
||||
val instance = remember(key) { factory() }
|
||||
// Here we initialize our view model using the launched effect so that it is tied to lifecycle
|
||||
// of the UI.
|
||||
LaunchedEffect(instance) {
|
||||
if (ValueAnimator.areAnimatorsEnabled() && animationDelay > 0) {
|
||||
delay(animationDelay)
|
||||
}
|
||||
instance.onInit()
|
||||
}
|
||||
|
||||
return instance
|
||||
}
|
||||
+8
-7
@@ -16,10 +16,11 @@
|
||||
|
||||
package com.android.launcher3.widgetpicker
|
||||
|
||||
import javax.inject.Scope
|
||||
|
||||
/** Scope annotation for singleton items within the widget picker. */
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Scope
|
||||
annotation class WidgetPickerSingleton
|
||||
/**
|
||||
* General interface that clients can implement to listen to events from different types of
|
||||
* widget picker.
|
||||
*/
|
||||
interface WidgetPickerEventListeners {
|
||||
/** Called when the widget picker is dismissed. */
|
||||
fun onClose()
|
||||
}
|
||||
+7
-3
@@ -24,11 +24,11 @@ import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkOut
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -70,9 +70,13 @@ fun LeadingIconToolbarTab(
|
||||
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(CircleShape)
|
||||
.clickable { onClick() }
|
||||
.selectable(
|
||||
selected = selected,
|
||||
onClick = onClick
|
||||
)
|
||||
.background(color = backgroundColor)
|
||||
.minimumInteractiveComponentSize()
|
||||
.padding(horizontal = LeadingIconToolbarTabDefaults.horizontalPadding),
|
||||
|
||||
+22
-10
@@ -32,8 +32,9 @@ package com.android.launcher3.widgetpicker.ui.components
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -48,29 +49,40 @@ import com.android.launcher3.widgetpicker.ui.components.SinglePaneLayoutDimensio
|
||||
* A layout that shows all the widget picker content in a column like pane.
|
||||
*
|
||||
* @param searchBar A sticky search bar shown on top in the left pane.
|
||||
* @param toolbar an option toolbar shown at bottom of the screen that allows users to select what
|
||||
* to see in the [content]
|
||||
* @param content the primary content e.g. widgets expand collapse list.
|
||||
* @param bottomFloatingContent an option toolbar that floats at the bottom of the screen and
|
||||
* allows users to choose what to see in the [content]
|
||||
*/
|
||||
@Composable
|
||||
fun SinglePaneLayout(
|
||||
searchBar: @Composable () -> Unit,
|
||||
toolbar: (@Composable () -> Unit)? = null,
|
||||
content: @Composable () -> Unit,
|
||||
bottomFloatingContent: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
val topContent: @Composable ColumnScope.() -> Unit = {
|
||||
Column(modifier = Modifier.fillMaxWidth().weight(1f)) {
|
||||
val topContent: @Composable BoxScope.() -> Unit = {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
searchBar()
|
||||
Spacer(modifier = Modifier.fillMaxWidth().height(searchBarBottomMargin))
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(searchBarBottomMargin)
|
||||
)
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
val bottomContent: @Composable ColumnScope.() -> Unit = { toolbar?.let { it() } }
|
||||
val floatingContent: @Composable BoxScope.() -> Unit = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.BottomCenter),
|
||||
contentAlignment = Alignment.Center
|
||||
) { bottomFloatingContent?.let { it() } }
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
topContent()
|
||||
bottomContent()
|
||||
floatingContent()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -168,6 +168,12 @@ private object DragHandleDimens {
|
||||
val dragHandleWidth = 32.dp
|
||||
}
|
||||
|
||||
/** Default values for the [TitledBottomSheet] component. */
|
||||
object TitledBottomSheetDefaults {
|
||||
/** Animation duration for the bottom sheet to fully expand. */
|
||||
const val SLIDE_IN_ANIMATION_DURATION: Long = 400L
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes how should the default height of the bottom sheet look like (excluding the insets such
|
||||
* as status bar).
|
||||
|
||||
+1
-6
@@ -93,12 +93,7 @@ fun WidgetAppsList(
|
||||
appIcon = appIcon,
|
||||
title = title,
|
||||
description = description,
|
||||
widgetPreviews =
|
||||
if (selected) {
|
||||
widgetPreviews
|
||||
} else {
|
||||
emptyMap()
|
||||
},
|
||||
widgetPreviews = widgetPreviews,
|
||||
onWidgetAppClick = onWidgetAppClick,
|
||||
)
|
||||
}
|
||||
|
||||
+6
-4
@@ -80,11 +80,11 @@ fun ExpandableListHeader(
|
||||
modifier
|
||||
.clip(shape = shape)
|
||||
.background(color = ExpandedListHeaderDefaults.backgroundColor)
|
||||
.clickable { onClick() }
|
||||
|
||||
Column(modifier = finalModifier) {
|
||||
WidgetAppHeader(
|
||||
modifier = Modifier,
|
||||
modifier = Modifier
|
||||
.clickable { onClick() },
|
||||
leadingIcon = { leadingAppIcon() },
|
||||
title = title,
|
||||
subTitle = subTitle,
|
||||
@@ -192,7 +192,8 @@ fun SelectableSuggestionsHeader(
|
||||
imageVector = Icons.Filled.Star,
|
||||
contentDescription = null,
|
||||
modifier =
|
||||
Modifier.clip(shape)
|
||||
Modifier
|
||||
.clip(shape)
|
||||
.background(MaterialTheme.colorScheme.surfaceBright)
|
||||
.minimumInteractiveComponentSize(),
|
||||
)
|
||||
@@ -224,7 +225,8 @@ private fun WidgetAppHeader(
|
||||
leadingIcon()
|
||||
CenterText(
|
||||
modifier =
|
||||
Modifier.weight(1f)
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = ListHeaderDimensions.centerTextHorizontalPadding),
|
||||
title = title,
|
||||
subTitle = subTitle,
|
||||
|
||||
+6
-2
@@ -60,7 +60,10 @@ fun WidgetDetails(
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = modifier.fillMaxSize().padding(WidgetDetailsDimension.padding),
|
||||
modifier = modifier.fillMaxSize().padding(
|
||||
horizontal = WidgetDetailsDimension.horizontalPadding,
|
||||
vertical = WidgetDetailsDimension.verticalPadding
|
||||
),
|
||||
) {
|
||||
WidgetLabel(label = widget.label, appIcon = appIcon, modifier = Modifier)
|
||||
if (showAllDetails) {
|
||||
@@ -134,6 +137,7 @@ private fun WidgetSpanSizeLabel(spanX: Int, spanY: Int) {
|
||||
}
|
||||
|
||||
private object WidgetDetailsDimension {
|
||||
val padding: Dp = 4.dp
|
||||
val horizontalPadding: Dp = 4.dp
|
||||
val verticalPadding: Dp = 12.dp
|
||||
val appIconLabelSpacing = 8.dp
|
||||
}
|
||||
+7
-2
@@ -53,6 +53,7 @@ import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -92,6 +93,7 @@ fun WidgetsSearchBar(
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val focusManager = LocalFocusManager.current
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
val exitSearchMode = {
|
||||
onSearch("")
|
||||
@@ -114,7 +116,10 @@ fun WidgetsSearchBar(
|
||||
singleLine = true,
|
||||
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||
keyboardActions = KeyboardActions(onSearch = { onSearch(text) }),
|
||||
keyboardActions = KeyboardActions(onSearch = {
|
||||
keyboardController?.hide()
|
||||
onSearch(text)
|
||||
}),
|
||||
interactionSource = interactionSource,
|
||||
textStyle = WidgetsSearchBarDefaults.textStyle,
|
||||
decorationBox =
|
||||
@@ -214,7 +219,7 @@ private fun BackButton(onClick: () -> Unit) {
|
||||
IconButton(colors = WidgetsSearchBarDefaults.iconButtonColors, onClick = onClick) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Outlined.ArrowBack,
|
||||
contentDescription = stringResource(R.string.widget_search_bar_clear_button_label),
|
||||
contentDescription = stringResource(R.string.widget_search_bar_back_button_label),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+89
@@ -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.ui.fullcatalog
|
||||
|
||||
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
|
||||
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import com.android.launcher3.widgetpicker.WidgetPickerEventListeners
|
||||
import com.android.launcher3.widgetpicker.ui.components.ModalBottomSheetHeightStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.TitledBottomSheet
|
||||
import com.android.launcher3.widgetpicker.ui.components.TitledBottomSheetDefaults
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.FullWidgetsCatalogViewModel.Screen
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreen
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.search.SearchScreen
|
||||
import com.android.launcher3.widgetpicker.ui.rememberViewModel
|
||||
import com.android.launcher3.widgetpicker.ui.windowsizeclass.calculateWindowInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* A catalog of all widgets available on device.
|
||||
*
|
||||
* When opened, first shows a landing page that comprises of the featured widgets and the list of
|
||||
* apps hosting widgets. User can enter search mode by tapping the search bar and see matching
|
||||
* results.
|
||||
*
|
||||
*/
|
||||
class FullWidgetsCatalog @Inject constructor(
|
||||
private val viewModelFactory: FullWidgetsCatalogViewModel.Factory,
|
||||
) {
|
||||
@Composable
|
||||
fun Content(
|
||||
eventListeners: WidgetPickerEventListeners,
|
||||
) {
|
||||
val viewModel: FullWidgetsCatalogViewModel =
|
||||
rememberViewModel(
|
||||
animationDelay = TitledBottomSheetDefaults.SLIDE_IN_ANIMATION_DURATION
|
||||
) {
|
||||
viewModelFactory.create()
|
||||
}
|
||||
val windowInfo = LocalConfiguration.current.calculateWindowInfo()
|
||||
val isCompactWidth =
|
||||
windowInfo.windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact
|
||||
val isCompactHeight =
|
||||
windowInfo.windowSizeClass.heightSizeClass == WindowHeightSizeClass.Compact
|
||||
|
||||
TitledBottomSheet(
|
||||
title = viewModel.title.takeIf { !isCompactHeight },
|
||||
modifier = Modifier,
|
||||
description = null,
|
||||
heightStyle = ModalBottomSheetHeightStyle.FILL_HEIGHT,
|
||||
showDragHandle = true,
|
||||
onDismissRequest = { eventListeners.onClose() },
|
||||
) {
|
||||
when (viewModel.activeScreen) {
|
||||
Screen.LANDING -> {
|
||||
LandingScreen(
|
||||
isCompact = isCompactWidth,
|
||||
onEnterSearchMode = { viewModel.onActiveScreenChange(Screen.SEARCH) },
|
||||
viewModel = viewModel.landingScreenViewModel,
|
||||
)
|
||||
}
|
||||
|
||||
Screen.SEARCH -> {
|
||||
SearchScreen(
|
||||
isCompact = isCompactWidth,
|
||||
onExitSearchMode = { viewModel.onActiveScreenChange(Screen.LANDING) },
|
||||
viewModel = viewModel.searchScreenViewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog
|
||||
|
||||
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.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.ui.ViewModel
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenViewModel
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.search.SearchScreenViewModel
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Top-level view model for the widget picker view that shows a full catalog of widgets available
|
||||
* on the device.
|
||||
*/
|
||||
class FullWidgetsCatalogViewModel @AssistedInject constructor(
|
||||
landingScreenViewModelFactory: LandingScreenViewModel.Factory,
|
||||
searchScreenViewModelFactory: SearchScreenViewModel.Factory,
|
||||
@WidgetPickerHostInfo private val hostInfo: WidgetHostInfo,
|
||||
) : ViewModel {
|
||||
val landingScreenViewModel = landingScreenViewModelFactory.create()
|
||||
val searchScreenViewModel = searchScreenViewModelFactory.create()
|
||||
|
||||
val title: String? = hostInfo.title
|
||||
val description: String? = hostInfo.description
|
||||
var activeScreen by mutableStateOf(Screen.LANDING)
|
||||
private set
|
||||
|
||||
override suspend fun onInit() {
|
||||
coroutineScope {
|
||||
launch { landingScreenViewModel.onInit() }
|
||||
launch { searchScreenViewModel.onInit() }
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
}
|
||||
|
||||
fun onActiveScreenChange(screen: Screen) {
|
||||
activeScreen = screen
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(): FullWidgetsCatalogViewModel
|
||||
}
|
||||
|
||||
enum class Screen {
|
||||
LANDING,
|
||||
SEARCH
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetsGrid
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetsSearchBar
|
||||
|
||||
/**
|
||||
* View displayed when user opens the full catalog of widgets in widget picker.
|
||||
*
|
||||
* @param isCompact indicates whether to show the compact single pane layout or the two pane layout.
|
||||
* @param onEnterSearchMode callback for when user focuses on the search bar.
|
||||
* @param viewModel the view model backing the state and data for the landing screen.
|
||||
*/
|
||||
@Composable
|
||||
fun LandingScreen(
|
||||
isCompact: Boolean,
|
||||
onEnterSearchMode: () -> Unit,
|
||||
viewModel: LandingScreenViewModel,
|
||||
) {
|
||||
val browseState = viewModel.browseWidgetsState
|
||||
|
||||
if (browseState is BrowseWidgetsState.Data) {
|
||||
val searchBar: @Composable () -> Unit = remember {
|
||||
{
|
||||
WidgetsSearchBar(
|
||||
text = "",
|
||||
isSearching = false,
|
||||
onSearch = {},
|
||||
onToggleSearchMode = { enter ->
|
||||
if (enter) {
|
||||
viewModel.onSelectedPersonalAppToggle(null)
|
||||
viewModel.onSelectedWorkAppToggle(null)
|
||||
onEnterSearchMode()
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LandingScreen(
|
||||
isCompact = isCompact,
|
||||
searchBarContent = searchBar,
|
||||
featuredWidgetsState = viewModel.featuredWidgetsState,
|
||||
featuredWidgetPreviewsState = viewModel.featuredWidgetPreviewsState,
|
||||
widgetAppIconsState = viewModel.appIconsState,
|
||||
browseWidgetsState = browseState,
|
||||
personalWidgetPreviewsState = viewModel.personalWidgetsPreviewsState,
|
||||
workWidgetPreviewsState = viewModel.workWidgetsPreviewState,
|
||||
selectedPersonalWidgetAppId = viewModel.selectedPersonalAppId,
|
||||
onPersonalWidgetAppToggle = viewModel::onSelectedPersonalAppToggle,
|
||||
selectedWorkWidgetAppId = viewModel.selectedWorkAppId,
|
||||
onWorkWidgetAppToggle = viewModel::onSelectedWorkAppToggle,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LandingScreen(
|
||||
isCompact: Boolean,
|
||||
searchBarContent: @Composable () -> Unit,
|
||||
featuredWidgetsState: FeaturedWidgetsState,
|
||||
featuredWidgetPreviewsState: PreviewsState,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
workWidgetPreviewsState: PreviewsState,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
onPersonalWidgetAppToggle: (WidgetAppId?) -> Unit,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
onWorkWidgetAppToggle: (WidgetAppId?) -> Unit,
|
||||
) {
|
||||
val featuredWidgetsContent: @Composable () -> Unit = {
|
||||
WidgetsGrid(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
widgetSizeGroups = featuredWidgetsState.sizeGroups,
|
||||
showAllWidgetDetails = false,
|
||||
previews = featuredWidgetPreviewsState.previews,
|
||||
appIcons = widgetAppIconsState.icons
|
||||
)
|
||||
}
|
||||
|
||||
when {
|
||||
isCompact ->
|
||||
LandingScreenSinglePane(
|
||||
searchBarContent = searchBarContent,
|
||||
featuredWidgetsContent = featuredWidgetsContent,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
personalWidgetPreviewsState = personalWidgetPreviewsState,
|
||||
workWidgetPreviewsState = workWidgetPreviewsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
onPersonalWidgetAppToggle = onPersonalWidgetAppToggle,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId,
|
||||
onWorkWidgetAppToggle = onWorkWidgetAppToggle
|
||||
)
|
||||
|
||||
else ->
|
||||
LandingScreenTwoPane(
|
||||
searchBar = searchBarContent,
|
||||
featuredWidgets = featuredWidgetsContent,
|
||||
featuredWidgetsCount = featuredWidgetsState.widgetsCount,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
personalWidgetPreviewsState = personalWidgetPreviewsState,
|
||||
workWidgetPreviewsState = workWidgetPreviewsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
onPersonalWidgetAppToggle = onPersonalWidgetAppToggle,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId,
|
||||
onWorkWidgetAppToggle = onWorkWidgetAppToggle,
|
||||
)
|
||||
}
|
||||
}
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.PagerState
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.List
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.outlined.Work
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile
|
||||
import com.android.launcher3.widgetpicker.ui.components.AppHeaderDescriptionStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.LeadingIconToolbarTab
|
||||
import com.android.launcher3.widgetpicker.ui.components.ScrollableFloatingToolbar
|
||||
import com.android.launcher3.widgetpicker.ui.components.SinglePaneLayout
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppHeaderStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppsList
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.DEFAULT_SELECTED_TAB
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.FEATURED_TAB_INDEX
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.PERSONAL_TAB_INDEX
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.TABS_COUNT_WITHOUT_WORK_PROFILE
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.TABS_COUNT_WITH_WORK_PROFILE
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.WORK_TAB_INDEX
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.bottomTabsBottomPadding
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.bottomTabsHorizontalPadding
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.bottomTabsTopPadding
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.contentShape
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.pagerItemsSpacing
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* A composable function that provides a single pane layout for landing screen of the full catalog
|
||||
* of widgets in the widget picker.
|
||||
*/
|
||||
@Composable
|
||||
fun LandingScreenSinglePane(
|
||||
searchBarContent: @Composable () -> Unit,
|
||||
featuredWidgetsContent: @Composable () -> Unit,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
workWidgetPreviewsState: PreviewsState,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
onPersonalWidgetAppToggle: (WidgetAppId) -> Unit,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
onWorkWidgetAppToggle: (WidgetAppId) -> Unit,
|
||||
) {
|
||||
val hasWorkProfile = remember(browseWidgetsState) { browseWidgetsState.workProfile != null }
|
||||
|
||||
val pagerState = rememberPagerState(
|
||||
initialPage = DEFAULT_SELECTED_TAB,
|
||||
pageCount = {
|
||||
if (hasWorkProfile) {
|
||||
TABS_COUNT_WITH_WORK_PROFILE
|
||||
} else {
|
||||
TABS_COUNT_WITHOUT_WORK_PROFILE
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
SinglePaneLayout(
|
||||
searchBar = searchBarContent,
|
||||
bottomFloatingContent = {
|
||||
BottomTabs(
|
||||
personalUserProfile = browseWidgetsState.personalProfile,
|
||||
workUserProfile = browseWidgetsState.workProfile,
|
||||
pagerState = pagerState
|
||||
)
|
||||
},
|
||||
content = {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
verticalAlignment = Alignment.Top,
|
||||
pageSpacing = pagerItemsSpacing,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(contentShape),
|
||||
) { pageIndex ->
|
||||
when (pageIndex) {
|
||||
FEATURED_TAB_INDEX -> {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clip(contentShape)
|
||||
.background(MaterialTheme.colorScheme.surfaceBright)
|
||||
) {
|
||||
featuredWidgetsContent()
|
||||
}
|
||||
}
|
||||
|
||||
PERSONAL_TAB_INDEX -> {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = browseWidgetsState.personalWidgetApps,
|
||||
selectedWidgetAppId = selectedPersonalWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.EXPANDABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.WIDGETS_COUNT,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onPersonalWidgetAppToggle(widgetApp.id)
|
||||
},
|
||||
appIcons = widgetAppIconsState.icons,
|
||||
widgetPreviews = personalWidgetPreviewsState.previews
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
WORK_TAB_INDEX -> if (hasWorkProfile) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = browseWidgetsState.workWidgetApps,
|
||||
selectedWidgetAppId = selectedWorkWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.EXPANDABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.WIDGETS_COUNT,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onWorkWidgetAppToggle(widgetApp.id)
|
||||
},
|
||||
appIcons = widgetAppIconsState.icons,
|
||||
widgetPreviews = workWidgetPreviewsState.previews
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BottomTabs(
|
||||
pagerState: PagerState,
|
||||
personalUserProfile: WidgetUserProfile,
|
||||
workUserProfile: WidgetUserProfile?
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
val tabs: List<@Composable () -> Unit> = buildList {
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = stringResource(R.string.featured_widgets_tab_label),
|
||||
leadingIcon = Icons.Filled.Star,
|
||||
selected = pagerState.currentPage == FEATURED_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(FEATURED_TAB_INDEX)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if (workUserProfile == null) {
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = stringResource(R.string.browse_widgets_tab_label),
|
||||
leadingIcon = Icons.AutoMirrored.Filled.List,
|
||||
selected = pagerState.currentPage == PERSONAL_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(PERSONAL_TAB_INDEX)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
} else {
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = personalUserProfile.label,
|
||||
leadingIcon = Icons.Filled.Person,
|
||||
selected = pagerState.currentPage == PERSONAL_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(PERSONAL_TAB_INDEX)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = workUserProfile.label,
|
||||
leadingIcon = Icons.Outlined.Work,
|
||||
selected = pagerState.currentPage == WORK_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(WORK_TAB_INDEX)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScrollableFloatingToolbar(
|
||||
modifier =
|
||||
Modifier
|
||||
.padding(horizontal = bottomTabsHorizontalPadding)
|
||||
.padding(
|
||||
top = bottomTabsTopPadding,
|
||||
bottom = bottomTabsBottomPadding
|
||||
),
|
||||
selectedTabIndex = pagerState.currentPage,
|
||||
tabs = tabs
|
||||
)
|
||||
}
|
||||
|
||||
private object LandingScreenSinglePaneDimens {
|
||||
const val TABS_COUNT_WITH_WORK_PROFILE = 3
|
||||
const val TABS_COUNT_WITHOUT_WORK_PROFILE = 2
|
||||
|
||||
const val FEATURED_TAB_INDEX = 0
|
||||
const val PERSONAL_TAB_INDEX = 1
|
||||
const val WORK_TAB_INDEX = 2
|
||||
const val DEFAULT_SELECTED_TAB = FEATURED_TAB_INDEX
|
||||
|
||||
val contentShape = RoundedCornerShape(24.dp)
|
||||
val pagerItemsSpacing = 8.dp
|
||||
|
||||
val bottomTabsTopPadding = 8.dp
|
||||
val bottomTabsHorizontalPadding = 32.dp
|
||||
val bottomTabsBottomPadding = 8.dp
|
||||
}
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.PagerState
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material.icons.outlined.Work
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile
|
||||
import com.android.launcher3.widgetpicker.ui.components.AppHeaderDescriptionStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.LeadingIconToolbarTab
|
||||
import com.android.launcher3.widgetpicker.ui.components.ScrollableFloatingToolbar
|
||||
import com.android.launcher3.widgetpicker.ui.components.SelectableSuggestionsHeader
|
||||
import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayout
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppHeaderStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppsList
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetsGrid
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.DEFAULT_SELECTED_TAB
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.PERSONAL_TAB_INDEX
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.TABS_COUNT_WITHOUT_WORK_PROFILE
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.TABS_COUNT_WITH_WORK_PROFILE
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.WORK_TAB_INDEX
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.contentShape
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.leftPaneContentBottomPadding
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.pagerItemsSpacing
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
/**
|
||||
* A composable function that provides a two pane layout for landing screen of the full catalog
|
||||
* of widgets in the widget picker.
|
||||
*
|
||||
* Ideal for large screens.
|
||||
*/
|
||||
@Composable
|
||||
fun LandingScreenTwoPane(
|
||||
searchBar: @Composable () -> Unit,
|
||||
featuredWidgets: @Composable () -> Unit,
|
||||
featuredWidgetsCount: Int,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
workWidgetPreviewsState: PreviewsState,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
onPersonalWidgetAppToggle: (WidgetAppId?) -> Unit,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
onWorkWidgetAppToggle: (WidgetAppId?) -> Unit,
|
||||
) {
|
||||
val hasWorkProfile = remember(browseWidgetsState) { browseWidgetsState.workProfile != null }
|
||||
var isFeaturedSectionShowing by rememberSaveable { mutableStateOf(true) }
|
||||
val pageCount = remember {
|
||||
if (hasWorkProfile) {
|
||||
TABS_COUNT_WITH_WORK_PROFILE
|
||||
} else {
|
||||
TABS_COUNT_WITHOUT_WORK_PROFILE
|
||||
}
|
||||
}
|
||||
|
||||
val pagerState =
|
||||
rememberPagerState(
|
||||
initialPage = DEFAULT_SELECTED_TAB,
|
||||
pageCount = { pageCount }
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
TwoPaneLayout(
|
||||
searchBar = searchBar,
|
||||
leftContent = {
|
||||
LeftPaneContent(
|
||||
isFeaturedSectionSelected = isFeaturedSectionShowing,
|
||||
featuredWidgetsCount = featuredWidgetsCount,
|
||||
pagerState = pagerState,
|
||||
hasWorkProfile = hasWorkProfile,
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
personalWidgetPreviewsState = personalWidgetPreviewsState,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId,
|
||||
workWidgetPreviewsState = workWidgetPreviewsState,
|
||||
onFeaturedHeaderClick = {
|
||||
isFeaturedSectionShowing = true
|
||||
onPersonalWidgetAppToggle(null)
|
||||
onWorkWidgetAppToggle(null)
|
||||
},
|
||||
onPersonalWidgetAppToggle = { id ->
|
||||
isFeaturedSectionShowing = false
|
||||
onPersonalWidgetAppToggle(id)
|
||||
},
|
||||
onWorkWidgetAppToggle = { id ->
|
||||
isFeaturedSectionShowing = false
|
||||
onWorkWidgetAppToggle(id)
|
||||
},
|
||||
)
|
||||
},
|
||||
rightPaneTitle = rightPaneTitle(
|
||||
showingFeaturedTab = isFeaturedSectionShowing,
|
||||
currentPageIndex = pagerState.currentPage,
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId
|
||||
),
|
||||
rightContent = {
|
||||
RightPaneContent(
|
||||
pagerState = pagerState,
|
||||
isFeaturedSectionSelected = isFeaturedSectionShowing,
|
||||
featuredWidgets = featuredWidgets,
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
personalWidgetPreviewsState = personalWidgetPreviewsState,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId,
|
||||
workWidgetPreviewsState = workWidgetPreviewsState,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for the right pane that is updated when selected tab on left changes. When set, a talkback
|
||||
* user can use four finger swipe down to switch to right pane.
|
||||
*/
|
||||
@Composable
|
||||
private fun rightPaneTitle(
|
||||
showingFeaturedTab: Boolean,
|
||||
currentPageIndex: Int,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
): String? {
|
||||
val selectedAppName: CharSequence? =
|
||||
if (currentPageIndex == 0) {
|
||||
selectedPersonalWidgetAppId?.let { selectedId ->
|
||||
browseWidgetsState.personalWidgetApps.find { it.id == selectedId }?.title
|
||||
}
|
||||
} else {
|
||||
selectedWorkWidgetAppId?.let { selectedId ->
|
||||
browseWidgetsState.workWidgetApps.find { it.id == selectedId }?.title
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return if (showingFeaturedTab) {
|
||||
stringResource(
|
||||
R.string.widget_picker_right_pane_accessibility_label,
|
||||
stringResource(R.string.featured_widgets_tab_label)
|
||||
)
|
||||
} else if (selectedAppName != null) {
|
||||
stringResource(
|
||||
R.string.widget_picker_right_pane_accessibility_label,
|
||||
selectedAppName
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RightPaneContent(
|
||||
pagerState: PagerState,
|
||||
isFeaturedSectionSelected: Boolean,
|
||||
featuredWidgets: @Composable () -> Unit,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
workWidgetPreviewsState: PreviewsState
|
||||
) {
|
||||
when {
|
||||
isFeaturedSectionSelected -> featuredWidgets()
|
||||
|
||||
pagerState.currentPage == PERSONAL_TAB_INDEX -> {
|
||||
selectedPersonalWidgetAppId?.let {
|
||||
val selectedPersonalWidgets =
|
||||
remember(selectedPersonalWidgetAppId, browseWidgetsState.personalWidgetApps) {
|
||||
selectedPersonalWidgetAppId.let { selectedId ->
|
||||
browseWidgetsState.personalWidgetApps.find {
|
||||
it.id == selectedId
|
||||
}?.widgetSizeGroups
|
||||
} ?: listOf()
|
||||
}
|
||||
|
||||
WidgetsGrid(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
showAllWidgetDetails = true,
|
||||
widgetSizeGroups = selectedPersonalWidgets,
|
||||
previews = personalWidgetPreviewsState.previews,
|
||||
appIcons = widgetAppIconsState.icons
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pagerState.currentPage == WORK_TAB_INDEX -> {
|
||||
selectedWorkWidgetAppId?.let {
|
||||
val selectedWorkWidgets =
|
||||
remember(selectedWorkWidgetAppId, browseWidgetsState.workWidgetApps) {
|
||||
selectedWorkWidgetAppId.let { selectedId ->
|
||||
browseWidgetsState.workWidgetApps.find {
|
||||
it.id == selectedId
|
||||
}?.widgetSizeGroups
|
||||
} ?: listOf()
|
||||
}
|
||||
|
||||
WidgetsGrid(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
showAllWidgetDetails = true,
|
||||
widgetSizeGroups = selectedWorkWidgets,
|
||||
previews = workWidgetPreviewsState.previews,
|
||||
appIcons = widgetAppIconsState.icons
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LeftPaneContent(
|
||||
isFeaturedSectionSelected: Boolean,
|
||||
onFeaturedHeaderClick: () -> Unit,
|
||||
featuredWidgetsCount: Int,
|
||||
pagerState: PagerState,
|
||||
hasWorkProfile: Boolean,
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
onPersonalWidgetAppToggle: (WidgetAppId) -> Unit,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
workWidgetPreviewsState: PreviewsState,
|
||||
onWorkWidgetAppToggle: (WidgetAppId) -> Unit,
|
||||
) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
SelectableSuggestionsHeader(
|
||||
selected = isFeaturedSectionSelected,
|
||||
onSelect = onFeaturedHeaderClick,
|
||||
count = featuredWidgetsCount,
|
||||
shape = contentShape,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
verticalAlignment = Alignment.Top,
|
||||
pageSpacing = pagerItemsSpacing,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(
|
||||
bottom = leftPaneContentBottomPadding(
|
||||
hasFloatingToolbar = hasWorkProfile
|
||||
)
|
||||
)
|
||||
.weight(1f),
|
||||
) { index ->
|
||||
when (index) {
|
||||
PERSONAL_TAB_INDEX -> {
|
||||
PersonalSection(
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
selectedPersonalWidgetAppId = selectedPersonalWidgetAppId,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
personalWidgetPreviewsState = personalWidgetPreviewsState,
|
||||
onPersonalWidgetAppToggle = onPersonalWidgetAppToggle
|
||||
)
|
||||
}
|
||||
|
||||
WORK_TAB_INDEX -> if (hasWorkProfile) {
|
||||
WorkSection(
|
||||
browseWidgetsState = browseWidgetsState,
|
||||
selectedWorkWidgetAppId = selectedWorkWidgetAppId,
|
||||
widgetAppIconsState = widgetAppIconsState,
|
||||
workWidgetPreviewsState = workWidgetPreviewsState,
|
||||
onWorkWidgetAppToggle = onWorkWidgetAppToggle
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
browseWidgetsState.workProfile?.let { workProfile ->
|
||||
PersonalWorkToolbar(
|
||||
pagerState = pagerState,
|
||||
personalUserProfile = browseWidgetsState.personalProfile,
|
||||
workUserProfile = workProfile,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PersonalSection(
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
selectedPersonalWidgetAppId: WidgetAppId?,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
personalWidgetPreviewsState: PreviewsState,
|
||||
onPersonalWidgetAppToggle: (WidgetAppId) -> Unit
|
||||
) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = browseWidgetsState.personalWidgetApps,
|
||||
selectedWidgetAppId = selectedPersonalWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.CLICKABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.WIDGETS_COUNT,
|
||||
appIcons = widgetAppIconsState.icons,
|
||||
widgetPreviews = personalWidgetPreviewsState.previews,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onPersonalWidgetAppToggle(widgetApp.id)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WorkSection(
|
||||
browseWidgetsState: BrowseWidgetsState.Data,
|
||||
selectedWorkWidgetAppId: WidgetAppId?,
|
||||
widgetAppIconsState: AppIconsState,
|
||||
workWidgetPreviewsState: PreviewsState,
|
||||
onWorkWidgetAppToggle: (WidgetAppId) -> Unit
|
||||
) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = browseWidgetsState.workWidgetApps,
|
||||
selectedWidgetAppId = selectedWorkWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.CLICKABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.WIDGETS_COUNT,
|
||||
appIcons = widgetAppIconsState.icons,
|
||||
widgetPreviews = workWidgetPreviewsState.previews,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onWorkWidgetAppToggle(widgetApp.id)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PersonalWorkToolbar(
|
||||
pagerState: PagerState,
|
||||
personalUserProfile: WidgetUserProfile,
|
||||
workUserProfile: WidgetUserProfile,
|
||||
modifier: Modifier,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val currentPage = pagerState.currentPage
|
||||
|
||||
val tabs: List<@Composable () -> Unit> =
|
||||
remember(currentPage, personalUserProfile, workUserProfile) {
|
||||
buildList {
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = personalUserProfile.label,
|
||||
leadingIcon = Icons.Filled.Person,
|
||||
selected = currentPage == PERSONAL_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(PERSONAL_TAB_INDEX)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
add {
|
||||
LeadingIconToolbarTab(
|
||||
label = workUserProfile.label,
|
||||
leadingIcon = Icons.Outlined.Work,
|
||||
selected = currentPage == WORK_TAB_INDEX,
|
||||
onClick = {
|
||||
scope.launch {
|
||||
pagerState.animateScrollToPage(WORK_TAB_INDEX)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScrollableFloatingToolbar(
|
||||
modifier = modifier,
|
||||
selectedTabIndex = currentPage,
|
||||
tabs = tabs
|
||||
)
|
||||
}
|
||||
|
||||
private object LandingScreenTwoPaneDimens {
|
||||
val contentShape = RoundedCornerShape(24.dp)
|
||||
val pagerItemsSpacing = 8.dp
|
||||
|
||||
fun leftPaneContentBottomPadding(hasFloatingToolbar: Boolean) = if (hasFloatingToolbar) {
|
||||
56.dp
|
||||
} else 0.dp
|
||||
|
||||
const val TABS_COUNT_WITH_WORK_PROFILE = 2
|
||||
const val TABS_COUNT_WITHOUT_WORK_PROFILE = 1
|
||||
|
||||
const val PERSONAL_TAB_INDEX = 0
|
||||
const val WORK_TAB_INDEX = 1
|
||||
const val DEFAULT_SELECTED_TAB = PERSONAL_TAB_INDEX
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
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.domain.interactor.WidgetAppIconsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppIcon
|
||||
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.WidgetUserProfile
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfileType
|
||||
import com.android.launcher3.widgetpicker.ui.ViewModel
|
||||
import com.android.launcher3.widgetpicker.ui.model.DisplayableWidgetApp
|
||||
import com.android.launcher3.widgetpicker.ui.model.DisplayableWidgetApp.Companion.getWidgetIdsForApp
|
||||
import com.android.launcher3.widgetpicker.ui.model.WidgetSizeGroup
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* A view model responsible for providing the data to the landing screen UI within the full catalog
|
||||
* of widgets in widget picker.
|
||||
*/
|
||||
class LandingScreenViewModel @AssistedInject constructor(
|
||||
private val widgetsInteractor: WidgetsInteractor,
|
||||
private val widgetAppIconsInteractor: WidgetAppIconsInteractor
|
||||
) : ViewModel {
|
||||
override suspend fun onInit() {
|
||||
coroutineScope {
|
||||
launch { initBrowseWidgets() }
|
||||
launch { initBrowseWidgetPreviews() }
|
||||
launch { initWorkWidgetPreviews() }
|
||||
launch { initFeaturedWidgets() }
|
||||
launch { initAppIcons() }
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
}
|
||||
|
||||
/** Data backing the browse section in the landing screen. */
|
||||
var browseWidgetsState by mutableStateOf<BrowseWidgetsState>(BrowseWidgetsState.NoData)
|
||||
private set
|
||||
|
||||
/** Previews for the widgets shown for personal tab in browse section of landing screen. */
|
||||
var personalWidgetsPreviewsState by mutableStateOf(PreviewsState())
|
||||
private set
|
||||
|
||||
/** Previews for the widgets shown for work tab in browse section of landing screen. */
|
||||
var workWidgetsPreviewState by mutableStateOf(PreviewsState())
|
||||
private set
|
||||
|
||||
/** Data about all app icons shown on landing screen. */
|
||||
var appIconsState by mutableStateOf(AppIconsState())
|
||||
private set
|
||||
|
||||
/**
|
||||
* Id of the app that is currently selected / expanded in personal list of apps. When null,
|
||||
* implies none of the apps is expanded.
|
||||
*/
|
||||
var selectedPersonalAppId by mutableStateOf<WidgetAppId?>(null)
|
||||
private set
|
||||
private val _selectedPersonalWidgetAppWidgetIds = snapshotFlow {
|
||||
val selectedId = selectedPersonalAppId
|
||||
val currentBrowseState = browseWidgetsState
|
||||
when {
|
||||
selectedId != null && currentBrowseState is BrowseWidgetsState.Data ->
|
||||
currentBrowseState.personalWidgetApps.getWidgetIdsForApp(selectedId)
|
||||
|
||||
else ->
|
||||
listOf()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Id of the app that is currently selected / expanded in work list of apps. When null,
|
||||
* implies none of the apps is expanded.
|
||||
*/
|
||||
var selectedWorkAppId by mutableStateOf<WidgetAppId?>(null)
|
||||
private set
|
||||
private val _selectedWorkWidgetAppWidgetIds = snapshotFlow {
|
||||
val selectedId = selectedWorkAppId
|
||||
val currentBrowseState = browseWidgetsState
|
||||
when {
|
||||
selectedId != null && currentBrowseState is BrowseWidgetsState.Data ->
|
||||
currentBrowseState.workWidgetApps.getWidgetIdsForApp(selectedId)
|
||||
|
||||
else ->
|
||||
listOf()
|
||||
}
|
||||
}
|
||||
|
||||
/** Data backing the featured section in landing screen; holds widgets that are featured. */
|
||||
var featuredWidgetsState by mutableStateOf(FeaturedWidgetsState())
|
||||
private set
|
||||
|
||||
/** Preview information about the widgets shown in the featured section. */
|
||||
var featuredWidgetPreviewsState by mutableStateOf(PreviewsState())
|
||||
private set
|
||||
|
||||
private suspend fun initBrowseWidgets() {
|
||||
widgetsInteractor.getWidgetAppsByProfile().collect { result ->
|
||||
val personalEntry =
|
||||
result.entries.find { it.key.type == WidgetUserProfileType.PERSONAL }
|
||||
val workEntry = result.entries.find { it.key.type == WidgetUserProfileType.WORK }
|
||||
browseWidgetsState = if (personalEntry == null) {
|
||||
BrowseWidgetsState.NoData
|
||||
} else {
|
||||
BrowseWidgetsState.Data(
|
||||
personalProfile = personalEntry.key,
|
||||
personalWidgetApps = personalEntry.value.map {
|
||||
DisplayableWidgetApp.fromWidgetApp(it)
|
||||
},
|
||||
workProfile = workEntry?.key,
|
||||
workWidgetApps = workEntry?.value?.map {
|
||||
DisplayableWidgetApp.fromWidgetApp(it)
|
||||
} ?: emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initBrowseWidgetPreviews() {
|
||||
_selectedPersonalWidgetAppWidgetIds.collect { ids ->
|
||||
personalWidgetsPreviewsState =
|
||||
PreviewsState(
|
||||
personalWidgetsPreviewsState.previews + ids.associateWith {
|
||||
widgetsInteractor.getWidgetPreview(
|
||||
it
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initWorkWidgetPreviews() {
|
||||
_selectedWorkWidgetAppWidgetIds.collect { ids ->
|
||||
workWidgetsPreviewState =
|
||||
PreviewsState(workWidgetsPreviewState.previews + ids.associateWith {
|
||||
widgetsInteractor.getWidgetPreview(
|
||||
it
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initFeaturedWidgets() {
|
||||
widgetsInteractor.getFeaturedWidgets().collect { result ->
|
||||
featuredWidgetsState = FeaturedWidgetsState(result.groupBy {
|
||||
Pair(it.sizeInfo.containerWidthPx, it.sizeInfo.containerHeightPx)
|
||||
}.map { (containerSize, value) ->
|
||||
WidgetSizeGroup(
|
||||
previewContainerWidthPx = containerSize.first,
|
||||
previewContainerHeightPx = containerSize.second,
|
||||
widgets = value
|
||||
)
|
||||
}, result.size)
|
||||
|
||||
featuredWidgetPreviewsState =
|
||||
PreviewsState(result.associate { res ->
|
||||
res.id to widgetsInteractor.getWidgetPreview(res.id)
|
||||
})
|
||||
}
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initAppIcons() {
|
||||
widgetAppIconsInteractor.getAllWidgetAppIcons().collect { result ->
|
||||
appIconsState = AppIconsState(icons = result)
|
||||
}
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to handle the toggle of a personal widget app; e.g. when user clicks an app to
|
||||
* expand or collapse.
|
||||
*
|
||||
* @param id id of the widget app that was tapped; if its same as last id that was tapped, the
|
||||
* [selectedPersonalAppId] is reset to null (aka toggled); if its different, then the provided
|
||||
* id is set as the [selectedPersonalAppId]. To clear the [selectedPersonalAppId] invoke this
|
||||
* with `null`
|
||||
*/
|
||||
fun onSelectedPersonalAppToggle(id: WidgetAppId?) {
|
||||
selectedPersonalAppId = if (id == selectedPersonalAppId) {
|
||||
null
|
||||
} else {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to handle the toggle of a work widget app; e.g. when user clicks an app to expand or
|
||||
* collapse.
|
||||
*
|
||||
* @param id id of the widget app that was tapped; if its same as last id that was tapped, the
|
||||
* [selectedWorkAppId] is reset to null (aka toggled); if its different, then the provided id is
|
||||
* set as the [selectedWorkAppId]. To clear the [selectedWorkAppId] invoke this with `null`
|
||||
*/
|
||||
fun onSelectedWorkAppToggle(id: WidgetAppId?) {
|
||||
selectedWorkAppId = if (id == selectedWorkAppId) {
|
||||
null
|
||||
} else {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
/** A factory that should be injected whenever [LandingScreenViewModel] is required. */
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(): LandingScreenViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents data that backs the widgets browsing experience in the full catalog. */
|
||||
@Stable
|
||||
@Immutable
|
||||
sealed class BrowseWidgetsState {
|
||||
/**
|
||||
* Information that is displayed when user taps browse tab.
|
||||
*
|
||||
* @param personalProfile data about the personal user profile that is used to display the
|
||||
* personal tab; when there is no work profile, it is referred to as "browse" tab.
|
||||
* @param personalWidgetApps list of apps (with their widgets) belonging to the personal user
|
||||
* profile
|
||||
* @param workProfile data about the work user profile that is used to display the work tab.
|
||||
* @param workWidgetApps list of apps (with their widgets) belonging to the work user profile.
|
||||
*/
|
||||
data class Data(
|
||||
val personalProfile: WidgetUserProfile,
|
||||
val personalWidgetApps: List<DisplayableWidgetApp>,
|
||||
val workProfile: WidgetUserProfile?,
|
||||
val workWidgetApps: List<DisplayableWidgetApp>
|
||||
) : BrowseWidgetsState()
|
||||
|
||||
/** No data loaded yet or unavailable for some reason. */
|
||||
data object NoData : BrowseWidgetsState()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents widgets data to be shown in the "featured" section.
|
||||
* @param sizeGroups groups holding widgets of similar sizes that can be presented in a coherent
|
||||
* manner in the featured section.
|
||||
* @param widgetsCount total count of widgets in the size groups (pre-computed so UI doesn't need to
|
||||
* count).
|
||||
*/
|
||||
@Stable
|
||||
@Immutable
|
||||
data class FeaturedWidgetsState(
|
||||
val sizeGroups: List<WidgetSizeGroup> = emptyList(),
|
||||
val widgetsCount: Int = 0
|
||||
)
|
||||
|
||||
/**
|
||||
* State class holding preview information about widgets in a specific section (featured, browse,
|
||||
* etc)
|
||||
* @param previews previews per widget (keyed by its id)
|
||||
*/
|
||||
@Stable
|
||||
@Immutable
|
||||
data class PreviewsState(
|
||||
val previews: Map<WidgetId, WidgetPreview> = emptyMap()
|
||||
)
|
||||
|
||||
/**
|
||||
* State class holding app icons shown in a specific section (featured, browse, etc.)
|
||||
* @param icons icons per app (keyed by its app id)
|
||||
*/
|
||||
@Stable
|
||||
@Immutable
|
||||
data class AppIconsState(
|
||||
val icons: Map<WidgetAppId, WidgetAppIcon> = emptyMap()
|
||||
)
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.search
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import com.android.launcher3.widgetpicker.ui.components.AppHeaderDescriptionStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.SinglePaneLayout
|
||||
import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayout
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppHeaderStyle
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetAppsList
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetsGrid
|
||||
import com.android.launcher3.widgetpicker.ui.components.WidgetsSearchBar
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.AppIconsState
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.PreviewsState
|
||||
|
||||
/**
|
||||
* Screen showing the search results in the widget picker when browsing the full widget catalog.
|
||||
*/
|
||||
@Composable
|
||||
fun SearchScreen(
|
||||
isCompact: Boolean,
|
||||
onExitSearchMode: () -> Unit,
|
||||
viewModel: SearchScreenViewModel,
|
||||
) {
|
||||
SearchScreen(
|
||||
isCompact = isCompact,
|
||||
input = viewModel.query,
|
||||
resultsState = viewModel.resultsState,
|
||||
selectedWidgetAppId = viewModel.selectedWidgetAppId,
|
||||
appIconsState = viewModel.appIconsState,
|
||||
widgetPreviewsState = viewModel.previewsState,
|
||||
onSearch = viewModel::onQueryChange,
|
||||
onSelectedWidgetAppToggle = viewModel::onSelectedWidgetAppToggle,
|
||||
onExitSearchMode = onExitSearchMode,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchScreen(
|
||||
isCompact: Boolean,
|
||||
input: String,
|
||||
resultsState: SearchResultsState,
|
||||
selectedWidgetAppId: WidgetAppId?,
|
||||
appIconsState: AppIconsState,
|
||||
widgetPreviewsState: PreviewsState,
|
||||
onSearch: (String) -> Unit,
|
||||
onSelectedWidgetAppToggle: (id: WidgetAppId) -> Unit,
|
||||
onExitSearchMode: () -> Unit,
|
||||
) {
|
||||
val searchBar: @Composable () -> Unit = {
|
||||
WidgetsSearchBar(
|
||||
text = input,
|
||||
isSearching = true,
|
||||
onSearch = onSearch,
|
||||
onToggleSearchMode = { searchModeEnabled ->
|
||||
if (!searchModeEnabled) {
|
||||
onExitSearchMode()
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
if (isCompact) {
|
||||
SearchScreenSinglePane(
|
||||
searchBar = searchBar,
|
||||
resultsState = resultsState,
|
||||
selectedWidgetAppId = selectedWidgetAppId,
|
||||
appIconsState = appIconsState,
|
||||
widgetPreviewsState = widgetPreviewsState,
|
||||
onSelectedWidgetAppChange = onSelectedWidgetAppToggle
|
||||
)
|
||||
} else {
|
||||
SearchScreenTwoPane(
|
||||
searchBar = searchBar,
|
||||
resultsState = resultsState,
|
||||
selectedWidgetAppId = selectedWidgetAppId,
|
||||
appIconsState = appIconsState,
|
||||
widgetPreviewsState = widgetPreviewsState,
|
||||
onSelectedWidgetAppChange = onSelectedWidgetAppToggle
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchScreenSinglePane(
|
||||
searchBar: @Composable () -> Unit,
|
||||
resultsState: SearchResultsState,
|
||||
selectedWidgetAppId: WidgetAppId?,
|
||||
appIconsState: AppIconsState,
|
||||
widgetPreviewsState: PreviewsState,
|
||||
onSelectedWidgetAppChange: (id: WidgetAppId) -> Unit
|
||||
) {
|
||||
SinglePaneLayout(
|
||||
searchBar = searchBar,
|
||||
content = {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = resultsState.results,
|
||||
selectedWidgetAppId = selectedWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.EXPANDABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.COMBINED_WIDGETS_TITLE,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onSelectedWidgetAppChange(widgetApp.id)
|
||||
},
|
||||
appIcons = appIconsState.icons,
|
||||
widgetPreviews = widgetPreviewsState.previews
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SearchScreenTwoPane(
|
||||
searchBar: @Composable () -> Unit,
|
||||
resultsState: SearchResultsState,
|
||||
selectedWidgetAppId: WidgetAppId?,
|
||||
appIconsState: AppIconsState,
|
||||
widgetPreviewsState: PreviewsState,
|
||||
onSelectedWidgetAppChange: (id: WidgetAppId) -> Unit
|
||||
) {
|
||||
TwoPaneLayout(
|
||||
searchBar = searchBar,
|
||||
leftContent = {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
WidgetAppsList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
widgetApps = resultsState.results,
|
||||
selectedWidgetAppId = selectedWidgetAppId,
|
||||
widgetAppHeaderStyle = WidgetAppHeaderStyle.CLICKABLE,
|
||||
headerDescriptionStyle = AppHeaderDescriptionStyle.COMBINED_WIDGETS_TITLE,
|
||||
appIcons = appIconsState.icons,
|
||||
widgetPreviews = widgetPreviewsState.previews,
|
||||
onWidgetAppClick = { widgetApp ->
|
||||
onSelectedWidgetAppChange(widgetApp.id)
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
rightPaneTitle = rightPaneTitle(
|
||||
resultsState = resultsState,
|
||||
selectedWidgetAppId = selectedWidgetAppId,
|
||||
),
|
||||
rightContent = {
|
||||
selectedWidgetAppId?.let { id ->
|
||||
val selectedWidgets =
|
||||
remember(id, resultsState) {
|
||||
id.let { selectedId ->
|
||||
resultsState.results.find {
|
||||
it.id == selectedId
|
||||
}?.widgetSizeGroups
|
||||
} ?: listOf()
|
||||
}
|
||||
|
||||
WidgetsGrid(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
showAllWidgetDetails = true,
|
||||
widgetSizeGroups = selectedWidgets,
|
||||
previews = widgetPreviewsState.previews,
|
||||
appIcons = appIconsState.icons
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for the right pane that is updated when selected tab on left changes. When set, a talkback
|
||||
* user can use four finger swipe down to switch to right pane.
|
||||
*/
|
||||
@Composable
|
||||
private fun rightPaneTitle(
|
||||
resultsState: SearchResultsState,
|
||||
selectedWidgetAppId: WidgetAppId?
|
||||
): String? {
|
||||
val selectedAppName: CharSequence? =
|
||||
selectedWidgetAppId?.let { selectedId ->
|
||||
resultsState.results.find { it.id == selectedId }?.title
|
||||
}
|
||||
|
||||
return if (selectedAppName != null) {
|
||||
stringResource(
|
||||
R.string.widget_picker_right_pane_accessibility_label,
|
||||
selectedAppName
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.search
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
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.domain.interactor.WidgetAppIconsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
import com.android.launcher3.widgetpicker.ui.ViewModel
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.AppIconsState
|
||||
import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.PreviewsState
|
||||
import com.android.launcher3.widgetpicker.ui.model.DisplayableWidgetApp
|
||||
import com.android.launcher3.widgetpicker.ui.model.DisplayableWidgetApp.Companion.getWidgetIdsForApp
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* View model for the search screen that allows searching for all widgets in the full catalog view
|
||||
* of the widget picker.
|
||||
*/
|
||||
class SearchScreenViewModel @AssistedInject constructor(
|
||||
private val widgetsInteractor: WidgetsInteractor,
|
||||
private val widgetAppIconsInteractor: WidgetAppIconsInteractor
|
||||
) : ViewModel {
|
||||
/** Data backing the results (widget apps & their widgets) that match the provided input. */
|
||||
var resultsState by mutableStateOf(SearchResultsState())
|
||||
private set
|
||||
|
||||
/** Current query that is input in search bar by the user. */
|
||||
var query by mutableStateOf("")
|
||||
private set
|
||||
|
||||
/** Data about all app icons shown on search screen. */
|
||||
var appIconsState by mutableStateOf(AppIconsState())
|
||||
private set
|
||||
|
||||
/**
|
||||
* Id of the app that is currently selected / expanded in search results. When null, implies
|
||||
* none of the apps is expanded.
|
||||
*/
|
||||
var selectedWidgetAppId by mutableStateOf<WidgetAppId?>(null)
|
||||
private val _selectedWidgetAppWidgetIds = snapshotFlow {
|
||||
selectedWidgetAppId?.let {
|
||||
resultsState.results.getWidgetIdsForApp(it)
|
||||
} ?: listOf()
|
||||
}
|
||||
|
||||
/** Preview information about the widgets in the search results. */
|
||||
var previewsState by mutableStateOf(PreviewsState())
|
||||
private set
|
||||
|
||||
override suspend fun onInit() {
|
||||
coroutineScope {
|
||||
launch { initializeSearchResults() }
|
||||
launch { initAppIcons() }
|
||||
launch { initialWidgetPreviews() }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun initializeSearchResults() {
|
||||
snapshotFlow { query }.collectLatest { newInput ->
|
||||
if (newInput.isEmpty()) {
|
||||
resultsState = SearchResultsState()
|
||||
} else {
|
||||
widgetsInteractor.searchWidgetApps(query).collectLatest { matchedResults ->
|
||||
resultsState = SearchResultsState(
|
||||
results = matchedResults.map { DisplayableWidgetApp.fromWidgetApp(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initAppIcons() {
|
||||
widgetAppIconsInteractor.getAllWidgetAppIcons().collect { result ->
|
||||
appIconsState = AppIconsState(icons = result)
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
private suspend fun initialWidgetPreviews() {
|
||||
_selectedWidgetAppWidgetIds.collect { ids ->
|
||||
previewsState =
|
||||
PreviewsState(
|
||||
previewsState.previews +
|
||||
ids.associateWith { widgetsInteractor.getWidgetPreview(it) })
|
||||
}
|
||||
|
||||
awaitCancellation()
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when user types a search query and its changed. Updates the [query] state
|
||||
* so that the search results can update as well.
|
||||
*/
|
||||
fun onQueryChange(query: String) {
|
||||
this.query = query
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to handle the visibility toggle of a widget app in search results; e.g. when user
|
||||
* clicks an app to expand or collapse.
|
||||
*
|
||||
* @param id id of the widget app that was tapped; if its same as last id that was tapped, the
|
||||
* [selectedWidgetAppId] is reset to null (aka toggled); if its different, then the provided id
|
||||
* is set as the [selectedWidgetAppId]. To clear the [selectedWidgetAppId] invoke this with
|
||||
* `null`
|
||||
*/
|
||||
fun onSelectedWidgetAppToggle(id: WidgetAppId) {
|
||||
selectedWidgetAppId = if (selectedWidgetAppId != id) {
|
||||
id
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/** A factory that should be injected whenever [SearchScreenViewModel] is required. */
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(): SearchScreenViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents data that backs the list of widget apps (and their widgets) shown in the results. */
|
||||
@Stable
|
||||
@Immutable
|
||||
data class SearchResultsState(
|
||||
val results: List<DisplayableWidgetApp> = emptyList()
|
||||
)
|
||||
+29
-1
@@ -18,6 +18,7 @@ package com.android.launcher3.widgetpicker.ui.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetApp
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetAppId
|
||||
|
||||
/**
|
||||
@@ -35,4 +36,31 @@ data class DisplayableWidgetApp(
|
||||
val title: CharSequence?,
|
||||
val widgetSizeGroups: List<WidgetSizeGroup>,
|
||||
val widgetsCount: Int,
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
/**
|
||||
* Helper function to create a [DisplayableWidgetApp] from a [WidgetApp].
|
||||
* Converts the list of widgets in the app to a list of [WidgetSizeGroup]s.
|
||||
*/
|
||||
fun fromWidgetApp(widgetApp: WidgetApp): DisplayableWidgetApp =
|
||||
DisplayableWidgetApp(
|
||||
id = widgetApp.id,
|
||||
title = widgetApp.title,
|
||||
widgetSizeGroups = widgetApp.widgets.groupBy {
|
||||
Pair(it.sizeInfo.containerWidthPx, it.sizeInfo.containerHeightPx)
|
||||
}.map { (containerSize, value) ->
|
||||
WidgetSizeGroup(
|
||||
previewContainerWidthPx = containerSize.first,
|
||||
previewContainerHeightPx = containerSize.second,
|
||||
widgets = value
|
||||
)
|
||||
},
|
||||
widgetsCount = widgetApp.widgets.size,
|
||||
)
|
||||
|
||||
fun List<DisplayableWidgetApp>.getWidgetIdsForApp(appId: WidgetAppId) =
|
||||
find { it.id == appId }?.widgetSizeGroups?.flatMap { group ->
|
||||
group.widgets.map { it.id }
|
||||
} ?: listOf()
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,13 @@ android_app {
|
||||
certificate: "platform",
|
||||
system_ext_specific: true,
|
||||
static_libs: [
|
||||
"widget_picker_ui",
|
||||
"widget_picker_ui_components",
|
||||
"widget_picker_domain_layer",
|
||||
"widget_picker_data_repositories",
|
||||
],
|
||||
kotlincflags: ["-Xjvm-default=all"],
|
||||
use_resource_processor: false,
|
||||
}
|
||||
|
||||
android_test {
|
||||
@@ -77,3 +82,98 @@ android_test {
|
||||
"multivalentScreenshotTests/res",
|
||||
],
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "widget-picker-multivalent-tests-src",
|
||||
srcs: [
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/TestUtils.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/domain/usecase/GroupWidgetAppsByProfileUseCaseTest.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/domain/usecase/FilterWidgetsForHostUseCaseTest.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/domain/interactor/WidgetsInteractorTest.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/domain/interactor/WidgetAppIconsInteractorTest.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/repository/FakeWidgetsRepository.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/repository/FakeWidgetUsersRepository.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/repository/FakeWidgetAppIconsRepository.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePaneTest.kt",
|
||||
"multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPaneTest.kt",
|
||||
],
|
||||
}
|
||||
|
||||
android_test {
|
||||
name: "WidgetPickerDeviceTests",
|
||||
manifest: "AndroidManifest.xml",
|
||||
srcs: [":widget-picker-multivalent-tests-src"],
|
||||
platform_apis: true,
|
||||
static_libs: [
|
||||
"widget_picker_ui",
|
||||
"widget_picker_ui_components",
|
||||
"widget_picker_domain_layer",
|
||||
"widget_picker_data_repositories",
|
||||
"androidx.compose.ui_ui-test-junit4",
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui",
|
||||
"collector-device-lib-platform",
|
||||
"testables",
|
||||
"platform-test-annotations",
|
||||
"platform-test-rules",
|
||||
"platform-parametric-runner-lib",
|
||||
"junit",
|
||||
"androidx.test.ext.junit",
|
||||
"androidx.test.rules",
|
||||
"androidx.test.runner",
|
||||
],
|
||||
libs: [
|
||||
"android.test.base.impl",
|
||||
"android.test.runner.impl",
|
||||
"android.test.mock.impl",
|
||||
],
|
||||
// Libraries used by mockito inline extended
|
||||
jni_libs: [
|
||||
"libdexmakerjvmtiagent",
|
||||
"libstaticjvmtiagent",
|
||||
],
|
||||
// Needed to link mokito libraries to run unbundled
|
||||
use_embedded_native_libs: false,
|
||||
// Needed to compile native libs for cuttlefish
|
||||
compile_multilib: "both",
|
||||
instrumentation_for: "WidgetPickerTestApp",
|
||||
plugins: ["dagger2-compiler"],
|
||||
test_suites: ["device-tests"],
|
||||
test_config: "WidgetPickerDeviceTests.xml",
|
||||
}
|
||||
|
||||
android_robolectric_test {
|
||||
enabled: true,
|
||||
name: "WidgetPickerRoboTests",
|
||||
srcs: [":widget-picker-multivalent-tests-src"],
|
||||
java_resource_dirs: ["config"],
|
||||
static_libs: [
|
||||
"widget_picker_ui",
|
||||
"widget_picker_ui_components",
|
||||
"widget_picker_domain_layer",
|
||||
"widget_picker_data_repositories",
|
||||
"androidx.compose.runtime_runtime",
|
||||
"androidx.compose.ui_ui",
|
||||
"androidx.compose.ui_ui-test-junit4",
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
"kotlinx_coroutines_test",
|
||||
"platform-test-rules-deviceless",
|
||||
"testables",
|
||||
"platform-parametric-runner-lib",
|
||||
"junit",
|
||||
"androidx.test.ext.junit",
|
||||
"platform-test-annotations",
|
||||
"androidx.test.rules",
|
||||
],
|
||||
libs: [
|
||||
"android.test.runner.impl",
|
||||
"android.test.base.impl",
|
||||
"android.test.mock.impl",
|
||||
"truth",
|
||||
],
|
||||
plugins: ["dagger2-compiler"],
|
||||
instrumentation_for: "WidgetPickerTestApp",
|
||||
strict_mode: true,
|
||||
test_suites: ["general-tests"],
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<configuration description="Runs device tests for the widget picker library.">
|
||||
<option name="test-suite-tag" value="apct-instrumentation" />
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
|
||||
<option name="max-tmp-logcat-file" value="104857600" /> <!-- 100 * 1024 * 1024 -->
|
||||
|
||||
<logger class="com.android.tradefed.log.FileLogger">
|
||||
<option name="max-log-size" value="20" />
|
||||
</logger>
|
||||
|
||||
<!-- Disables the "Ramdump uploader to betterbug" -->
|
||||
<option name="post-boot-command" value="am broadcast --async --user 0 -a com.google.gservices.intent.action.GSERVICES_OVERRIDE -e betterbug_enable_ramdump_uploader false" />
|
||||
|
||||
<target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
|
||||
<option name="optimized-property-setting" value="true" />
|
||||
<option name="run-command" value="settings put global airplane_mode_on 1" />
|
||||
<option name="run-command" value="am broadcast -a android.intent.action.AIRPLANE_MODE" />
|
||||
<option name="run-command" value="settings put global verifier_verify_adb_installs 0" />
|
||||
</target_preparer>
|
||||
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||
<option name="cleanup-apks" value="true" />
|
||||
<option name="test-file-name" value="WidgetPickerDeviceTests.apk" />
|
||||
</target_preparer>
|
||||
<metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
|
||||
<option name="directory-keys" value="/data/user/0/com.android.launcher3.widgetpicker.tests/files" />
|
||||
<option name="directory-keys" value="/data/user/10/com.android.launcher3.widgetpicker.tests/files" />
|
||||
<option name="collect-on-run-ended-only" value="true" />
|
||||
</metrics_collector>
|
||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
|
||||
<option name="package" value="com.android.launcher3.widgetpicker.tests" />
|
||||
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||
</test>
|
||||
</configuration>
|
||||
@@ -0,0 +1 @@
|
||||
sdk=NEWEST_SDK
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.appwidget.AppWidgetProviderInfo
|
||||
import android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN
|
||||
import android.content.ComponentName
|
||||
import android.os.UserHandle
|
||||
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.WidgetSizeInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfile
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfileType
|
||||
|
||||
/** Utilities and constants to build test data. */
|
||||
object TestUtils {
|
||||
val personalUser: UserHandle = UserHandle.of(1)
|
||||
val workUser: UserHandle = UserHandle.of(10)
|
||||
|
||||
val PERSONAL_LABEL = "personal"
|
||||
val WORK_LABEL = "work"
|
||||
|
||||
val widgetUserProfilePersonal =
|
||||
WidgetUserProfile(type = WidgetUserProfileType.PERSONAL, label = PERSONAL_LABEL)
|
||||
val widgetUserProfileWork =
|
||||
WidgetUserProfile(type = WidgetUserProfileType.WORK, label = WORK_LABEL)
|
||||
|
||||
private const val PACKAGE_NAME = "com.example.test"
|
||||
private val PERSONAL_WIDGET_APP_1 = buildWidgetAppId("AppOne", personalUser)
|
||||
private val PERSONAL_WIDGET_APP_2 = buildWidgetAppId("AppTwo", personalUser)
|
||||
private val WORK_WIDGET_APP_1 = buildWidgetAppId("WAppOne", workUser)
|
||||
|
||||
val PERSONAL_TEST_APPS =
|
||||
listOf(
|
||||
WidgetApp(
|
||||
id = PERSONAL_WIDGET_APP_1,
|
||||
title = "Personal App 1",
|
||||
widgets =
|
||||
listOf(
|
||||
buildTestWidget(
|
||||
providerClassName = "PersonalWidget1A",
|
||||
widgetAppId = PERSONAL_WIDGET_APP_1,
|
||||
userHandle = personalUser,
|
||||
)
|
||||
),
|
||||
),
|
||||
WidgetApp(
|
||||
id = PERSONAL_WIDGET_APP_2,
|
||||
title = "Personal App 2",
|
||||
widgets =
|
||||
listOf(
|
||||
buildTestWidget(
|
||||
providerClassName = "PersonalWidget2A",
|
||||
widgetAppId = PERSONAL_WIDGET_APP_2,
|
||||
userHandle = personalUser,
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val WORK_TEST_APPS =
|
||||
listOf(
|
||||
WidgetApp(
|
||||
id = WORK_WIDGET_APP_1,
|
||||
title = "Work App 1",
|
||||
widgets =
|
||||
listOf(
|
||||
buildTestWidget(
|
||||
providerClassName = "WorkWidget1A",
|
||||
widgetAppId = WORK_WIDGET_APP_1,
|
||||
userHandle = workUser,
|
||||
),
|
||||
buildTestWidget(
|
||||
providerClassName = "WorkWidget1B",
|
||||
widgetAppId = WORK_WIDGET_APP_1,
|
||||
userHandle = workUser,
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
private fun buildWidgetAppId(suffix: String, userHandle: UserHandle) =
|
||||
WidgetAppId(packageName = "$PACKAGE_NAME.$suffix", category = null, userHandle = userHandle)
|
||||
|
||||
fun buildTestWidget(
|
||||
providerClassName: String,
|
||||
category: Int = WIDGET_CATEGORY_HOME_SCREEN,
|
||||
widgetAppId: WidgetAppId? = null,
|
||||
userHandle: UserHandle = UserHandle.of(0),
|
||||
): PickableWidget {
|
||||
val finalWidgetAppId =
|
||||
widgetAppId
|
||||
?: WidgetAppId(packageName = PACKAGE_NAME, userHandle = userHandle, category = null)
|
||||
|
||||
return PickableWidget(
|
||||
id =
|
||||
WidgetId(ComponentName.createRelative(PACKAGE_NAME, providerClassName), userHandle),
|
||||
appId = finalWidgetAppId,
|
||||
label = providerClassName,
|
||||
description = null,
|
||||
appWidgetProviderInfo = AppWidgetProviderInfo().apply { widgetCategory = category },
|
||||
sizeInfo =
|
||||
WidgetSizeInfo(
|
||||
spanX = 2,
|
||||
spanY = 2,
|
||||
widthPx = 200,
|
||||
heightPx = 200,
|
||||
containerWidthPx = 200,
|
||||
containerHeightPx = 200,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.domain.interactor
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetsRepository
|
||||
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 kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class WidgetAppIconsInteractorTest {
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(testDispatcher)
|
||||
private val widgetsRepository = FakeWidgetsRepository()
|
||||
private val widgetAppIconsRepository = FakeWidgetAppIconsRepository()
|
||||
|
||||
private val underTest = WidgetAppIconsInteractor(
|
||||
widgetAppIconsRepository = widgetAppIconsRepository,
|
||||
widgetsRepository = widgetsRepository,
|
||||
backgroundContext = testDispatcher
|
||||
)
|
||||
|
||||
@Test
|
||||
fun returnsMappedAppIcons() = testScope.runTest {
|
||||
widgetsRepository.seedWidgets(
|
||||
listOf(
|
||||
PERSONAL_TEST_APPS[0],
|
||||
PERSONAL_TEST_APPS[1],
|
||||
WORK_TEST_APPS[0]
|
||||
)
|
||||
)
|
||||
val widgetAppId1 = PERSONAL_TEST_APPS[0].id
|
||||
val widgetAppId2 = PERSONAL_TEST_APPS[1].id
|
||||
val widgetAppId3 = WORK_TEST_APPS[0].id // no app icon yet
|
||||
val appIcon1 = WidgetAppIcon(
|
||||
icon = AppIcon.LowResColorIcon(color = Color.BLUE),
|
||||
badge = AppIconBadge.NoBadge
|
||||
)
|
||||
val appIcon2 = WidgetAppIcon(
|
||||
icon = AppIcon.HighResBitmapIcon(
|
||||
Bitmap.createBitmap(
|
||||
50,
|
||||
50,
|
||||
Bitmap.Config.ARGB_8888
|
||||
)
|
||||
),
|
||||
badge = AppIconBadge.DrawableBadge(
|
||||
drawableResId = android.R.drawable.ic_menu_add,
|
||||
tintColor = Color.RED
|
||||
)
|
||||
)
|
||||
widgetAppIconsRepository.seedAppIcons(
|
||||
mapOf(
|
||||
widgetAppId1 to appIcon1,
|
||||
widgetAppId2 to appIcon2,
|
||||
// no widgetAppId3
|
||||
)
|
||||
)
|
||||
val expected = mapOf(
|
||||
widgetAppId1 to appIcon1,
|
||||
widgetAppId2 to appIcon2,
|
||||
widgetAppId3 to WidgetAppIcon(
|
||||
icon = AppIcon.PlaceHolderAppIcon,
|
||||
badge = AppIconBadge.NoBadge
|
||||
)
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
underTest.getAllWidgetAppIcons().filter { it == expected }.first() // no error
|
||||
runCurrent()
|
||||
}
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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.domain.interactor
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.widgetUserProfilePersonal
|
||||
import com.android.launcher3.widgetpicker.TestUtils.widgetUserProfileWork
|
||||
import com.android.launcher3.widgetpicker.TestUtils.workUser
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.FilterWidgetsForHostUseCase
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.GroupWidgetAppsByProfileUseCase
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class WidgetsInteractorTest {
|
||||
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(testDispatcher)
|
||||
|
||||
private val widgetUsersRepository = FakeWidgetUsersRepository()
|
||||
private val widgetsRepository = FakeWidgetsRepository()
|
||||
private val underTest =
|
||||
WidgetsInteractor(
|
||||
widgetsRepository = widgetsRepository,
|
||||
widgetUsersRepository = widgetUsersRepository,
|
||||
getWidgetAppsByProfileUseCase = GroupWidgetAppsByProfileUseCase(),
|
||||
filterWidgetsForHostUseCase = FilterWidgetsForHostUseCase(WidgetHostInfo()),
|
||||
backgroundContext = testDispatcher
|
||||
)
|
||||
|
||||
@Test
|
||||
fun noWidgets_returnsEmpty() =
|
||||
testScope.runTest {
|
||||
assertThat(underTest.getWidgetAppsByProfile().first()).isEmpty()
|
||||
assertThat(underTest.getFeaturedWidgets().first()).isEmpty()
|
||||
runCurrent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun userProfilesNotLoaded_returnsEmpty() =
|
||||
testScope.runTest {
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
runCurrent()
|
||||
|
||||
assertThat(underTest.getWidgetAppsByProfile().first()).isEmpty()
|
||||
assertThat(underTest.getFeaturedWidgets().first()).isEmpty()
|
||||
runCurrent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getWidgetAppsByProfile_returnsWidgetGroupedByProfile() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork,
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
runCurrent()
|
||||
|
||||
val result = underTest.getWidgetAppsByProfile().first()
|
||||
runCurrent()
|
||||
|
||||
assertThat(result).hasSize(2)
|
||||
assertThat(result[widgetUserProfilePersonal])
|
||||
.containsExactlyElementsIn(PERSONAL_TEST_APPS)
|
||||
assertThat(result[widgetUserProfileWork]).containsExactlyElementsIn(WORK_TEST_APPS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getFeaturedWidgets_returnsAllFeaturedWidgets() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork,
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
val personalFeaturedWidget = PERSONAL_TEST_APPS[0].widgets[0]
|
||||
val workFeaturedWidget = WORK_TEST_APPS[0].widgets[0]
|
||||
widgetsRepository.seedFeaturedWidgets(
|
||||
setOf(workFeaturedWidget.id, personalFeaturedWidget.id)
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
val result = underTest.getFeaturedWidgets().first()
|
||||
runCurrent()
|
||||
|
||||
assertThat(result).containsExactly(personalFeaturedWidget, workFeaturedWidget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getFeaturedWidgets_pausedWorkProfile_returnsOnlyPersonalWidgets() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork.copy(paused = true),
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
val personalFeaturedWidget = PERSONAL_TEST_APPS[0].widgets[0]
|
||||
val workFeaturedWidget = WORK_TEST_APPS[0].widgets[0]
|
||||
widgetsRepository.seedFeaturedWidgets(
|
||||
setOf(workFeaturedWidget.id, personalFeaturedWidget.id)
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
val result = underTest.getFeaturedWidgets().first()
|
||||
runCurrent()
|
||||
|
||||
assertThat(result).containsExactly(personalFeaturedWidget)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getWidgetPreviews_returnsExpectedPreviews() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork,
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
val personalWidgetId = PERSONAL_TEST_APPS[0].widgets[0].id
|
||||
val personalWidgetPreview =
|
||||
WidgetPreview.BitmapWidgetPreview(
|
||||
Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888)
|
||||
)
|
||||
val workWidgetId = WORK_TEST_APPS[0].widgets[0].id
|
||||
widgetsRepository.seedWidgetPreviews(
|
||||
mapOf(
|
||||
personalWidgetId to personalWidgetPreview
|
||||
) // no work widget preview available.
|
||||
)
|
||||
runCurrent()
|
||||
|
||||
assertThat(underTest.getWidgetPreview(personalWidgetId))
|
||||
.isEqualTo(personalWidgetPreview)
|
||||
assertThat(underTest.getWidgetPreview(workWidgetId))
|
||||
.isEqualTo(WidgetPreview.PlaceholderWidgetPreview)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchWidgets_returnsExpectedWidgets() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork,
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
runCurrent()
|
||||
|
||||
val input = PERSONAL_TEST_APPS[0].widgets[0].label
|
||||
val result = underTest.searchWidgetApps(input).first()
|
||||
runCurrent()
|
||||
|
||||
assertThat(result.size).isEqualTo(1)
|
||||
assertThat(result[0].widgets.size).isEqualTo(1)
|
||||
assertThat(result[0].widgets[0].label).isEqualTo(input)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchWidgets_pausedWorkProfile_returnsOnlyPersonalWidgets() =
|
||||
testScope.runTest {
|
||||
widgetUsersRepository.seedUserProfiles(
|
||||
profiles =
|
||||
WidgetUserProfiles(
|
||||
personal = widgetUserProfilePersonal,
|
||||
work = widgetUserProfileWork.copy(paused = true),
|
||||
),
|
||||
workProfileUser = workUser,
|
||||
)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
runCurrent()
|
||||
|
||||
val input = "Widget"
|
||||
val result = underTest.searchWidgetApps(input).first()
|
||||
runCurrent()
|
||||
|
||||
assertThat(result.size).isEqualTo(PERSONAL_TEST_APPS.size)
|
||||
assertThat(result.filter { it.title == WORK_TEST_APPS[0].title }).isEmpty()
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.domain.usecase
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN
|
||||
import android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD
|
||||
import android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD
|
||||
import android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX
|
||||
import android.os.UserHandle
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.launcher3.widgetpicker.TestUtils.buildTestWidget
|
||||
import com.android.launcher3.widgetpicker.shared.model.HostConstraint
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class FilterWidgetsForHostUseCaseTest {
|
||||
@Test
|
||||
fun noFilter_returnsAll() {
|
||||
val underTest = FilterWidgetsForHostUseCase(hostInfo = WidgetHostInfo())
|
||||
val inputWidgets = listOf(buildTestWidget("provider1"), buildTestWidget("provider2"))
|
||||
|
||||
val filteredWidgets = underTest(inputWidgets)
|
||||
|
||||
assertThat(filteredWidgets).containsExactlyElementsIn(inputWidgets)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun userAndCategoryFilter_appliesBoth() {
|
||||
val underTest =
|
||||
FilterWidgetsForHostUseCase(
|
||||
hostInfo =
|
||||
WidgetHostInfo(
|
||||
constraints =
|
||||
listOf(
|
||||
HostConstraint.HostUserConstraint(
|
||||
userFilters = listOf(UserHandle.of(10))
|
||||
),
|
||||
HostConstraint.HostCategoryConstraint(
|
||||
categoryInclusionMask =
|
||||
WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD,
|
||||
categoryExclusionMask = WIDGET_CATEGORY_NOT_KEYGUARD.inv(),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val provider1 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider1",
|
||||
category = WIDGET_CATEGORY_HOME_SCREEN, // match
|
||||
userHandle = UserHandle(0), // match
|
||||
)
|
||||
val provider2 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider2",
|
||||
category = WIDGET_CATEGORY_KEYGUARD, // match
|
||||
userHandle = UserHandle(0), // match
|
||||
)
|
||||
val provider3 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider3",
|
||||
category = WIDGET_CATEGORY_HOME_SCREEN, // match
|
||||
userHandle = UserHandle(10), // no match
|
||||
)
|
||||
val provider4 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider4",
|
||||
category = WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_NOT_KEYGUARD, // no match
|
||||
userHandle = UserHandle(0), // match
|
||||
)
|
||||
val provider5 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider5",
|
||||
category = WIDGET_CATEGORY_SEARCHBOX, // no match
|
||||
userHandle = UserHandle(0), // match
|
||||
)
|
||||
val provider6 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider6",
|
||||
category = WIDGET_CATEGORY_KEYGUARD or WIDGET_CATEGORY_HOME_SCREEN, // match
|
||||
userHandle = UserHandle(0), // match
|
||||
)
|
||||
val filteredWidgets =
|
||||
underTest(listOf(provider1, provider2, provider3, provider4, provider5, provider6))
|
||||
|
||||
assertThat(filteredWidgets)
|
||||
.containsExactlyElementsIn(listOf(provider1, provider2, provider6))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onlyOneOfInclusionOrExclusionFilter() {
|
||||
val inclusionOnlyFilter =
|
||||
FilterWidgetsForHostUseCase(
|
||||
hostInfo =
|
||||
WidgetHostInfo(
|
||||
constraints =
|
||||
listOf(
|
||||
HostConstraint.HostCategoryConstraint(
|
||||
categoryInclusionMask =
|
||||
WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD,
|
||||
categoryExclusionMask = 0,
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
val exclusionOnlyFilter =
|
||||
FilterWidgetsForHostUseCase(
|
||||
hostInfo =
|
||||
WidgetHostInfo(
|
||||
constraints =
|
||||
listOf(
|
||||
HostConstraint.HostCategoryConstraint(
|
||||
categoryInclusionMask = 0,
|
||||
categoryExclusionMask = WIDGET_CATEGORY_NOT_KEYGUARD.inv(),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val provider1 =
|
||||
buildTestWidget(providerClassName = "provider1", category = WIDGET_CATEGORY_HOME_SCREEN)
|
||||
val provider2 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider2",
|
||||
category = WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD,
|
||||
)
|
||||
val provider3 =
|
||||
buildTestWidget(
|
||||
providerClassName = "provider3",
|
||||
category = WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_NOT_KEYGUARD,
|
||||
)
|
||||
val provider4 =
|
||||
buildTestWidget(providerClassName = "provider4", category = WIDGET_CATEGORY_SEARCHBOX)
|
||||
val filteredInclusionOnlyWidgets =
|
||||
inclusionOnlyFilter(listOf(provider1, provider2, provider3, provider4))
|
||||
val filteredExclusionOnlyWidgets =
|
||||
exclusionOnlyFilter(listOf(provider1, provider2, provider3, provider4))
|
||||
|
||||
assertThat(filteredInclusionOnlyWidgets)
|
||||
.containsExactlyElementsIn(listOf(provider1, provider2, provider3))
|
||||
assertThat(filteredExclusionOnlyWidgets)
|
||||
.containsExactlyElementsIn(listOf(provider1, provider2, provider4))
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.domain.usecase
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.widgetUserProfilePersonal
|
||||
import com.android.launcher3.widgetpicker.TestUtils.widgetUserProfileWork
|
||||
import com.android.launcher3.widgetpicker.TestUtils.workUser
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class GroupWidgetAppsByProfileUseCaseTest {
|
||||
private val underTest = GroupWidgetAppsByProfileUseCase()
|
||||
|
||||
@Test
|
||||
fun noWorkProfile_mapsOnlyPersonalProfile() {
|
||||
val allWidgetApps = PERSONAL_TEST_APPS
|
||||
val personalProfile = widgetUserProfilePersonal
|
||||
val workProfile = null
|
||||
|
||||
val result = underTest(
|
||||
workProfileUser = null,
|
||||
widgetApps = allWidgetApps,
|
||||
userProfiles = WidgetUserProfiles(personal = personalProfile, work = workProfile),
|
||||
)
|
||||
|
||||
assertThat(result).hasSize(1)
|
||||
assertThat(result).containsExactlyEntriesIn(mapOf(personalProfile to allWidgetApps))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun workProfile_mapsBothPersonalAndWorkProfiles() {
|
||||
val allWidgetApps = PERSONAL_TEST_APPS + WORK_TEST_APPS
|
||||
val personalProfile = widgetUserProfilePersonal
|
||||
val workProfile = widgetUserProfileWork.copy(paused = false)
|
||||
|
||||
val result = underTest(
|
||||
workProfileUser = workUser,
|
||||
widgetApps = allWidgetApps,
|
||||
userProfiles = WidgetUserProfiles(personal = personalProfile, work = workProfile),
|
||||
)
|
||||
|
||||
assertThat(result).hasSize(2)
|
||||
assertThat(result[personalProfile]).containsExactlyElementsIn(PERSONAL_TEST_APPS)
|
||||
assertThat(result[workProfile]).containsExactlyElementsIn(WORK_TEST_APPS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun workProfilePaused_setsWorkWidgetsToEmpty() {
|
||||
val allWidgetApps = PERSONAL_TEST_APPS + WORK_TEST_APPS
|
||||
val personalProfile = widgetUserProfilePersonal
|
||||
val workProfile = widgetUserProfileWork.copy(paused = true)
|
||||
|
||||
val result = underTest(
|
||||
workProfileUser = workUser,
|
||||
widgetApps = allWidgetApps,
|
||||
userProfiles = WidgetUserProfiles(personal = personalProfile, work = workProfile),
|
||||
)
|
||||
|
||||
assertThat(result).hasSize(2)
|
||||
assertThat(result[personalProfile]).containsExactlyElementsIn(PERSONAL_TEST_APPS)
|
||||
assertThat(result[workProfile]).isEmpty()
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.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.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
/** A fake implementation of [WidgetAppIconsRepository] for testing */
|
||||
class FakeWidgetAppIconsRepository : WidgetAppIconsRepository {
|
||||
private val _appIcons = MutableStateFlow(emptyMap<WidgetAppId, WidgetAppIcon>())
|
||||
fun seedAppIcons(icons: Map<WidgetAppId, WidgetAppIcon>) {
|
||||
_appIcons.update { icons }
|
||||
}
|
||||
|
||||
override fun initialize() {}
|
||||
|
||||
override fun getAppIcon(widgetAppId: WidgetAppId): Flow<WidgetAppIcon> = flow {
|
||||
emit(
|
||||
WidgetAppIcon(
|
||||
icon = AppIcon.PlaceHolderAppIcon,
|
||||
badge = AppIconBadge.NoBadge
|
||||
)
|
||||
)
|
||||
|
||||
val appIcon = _appIcons.value[widgetAppId]
|
||||
if (appIcon != null) {
|
||||
emit(appIcon)
|
||||
}
|
||||
}
|
||||
|
||||
override fun cleanUp() {
|
||||
_appIcons.update { emptyMap() }
|
||||
}
|
||||
}
|
||||
+46
@@ -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.widgetpicker.repository
|
||||
|
||||
import android.os.UserHandle
|
||||
import com.android.launcher3.widgetpicker.data.repository.WidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
/** A fake implementation of [WidgetUsersRepository] for testing */
|
||||
class FakeWidgetUsersRepository : WidgetUsersRepository {
|
||||
private val _userProfiles = MutableStateFlow<WidgetUserProfiles?>(null)
|
||||
private var workProfileUser: UserHandle? = null
|
||||
|
||||
fun seedUserProfiles(profiles: WidgetUserProfiles?, workProfileUser: UserHandle?) {
|
||||
this.workProfileUser = workProfileUser
|
||||
_userProfiles.update { profiles }
|
||||
}
|
||||
|
||||
override fun initialize() {}
|
||||
|
||||
override fun observeUserProfiles(): Flow<WidgetUserProfiles?> = _userProfiles
|
||||
|
||||
override fun getWorkProfileUser(): UserHandle? = workProfileUser
|
||||
|
||||
override fun cleanUp() {
|
||||
_userProfiles.update { null }
|
||||
workProfileUser = null
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.widgetpicker.data.repository.WidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.PickableWidget
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetApp
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetId
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
/** A fake implementation of [WidgetsRepository] for testing */
|
||||
class FakeWidgetsRepository : WidgetsRepository {
|
||||
private val _widgetApps = MutableStateFlow<List<WidgetApp>>(emptyList())
|
||||
private val _widgetPreviews = MutableStateFlow<Map<WidgetId, WidgetPreview>>(emptyMap())
|
||||
private var _featuredWidgetIds = MutableStateFlow(emptySet<WidgetId>())
|
||||
|
||||
fun seedWidgets(widgetApps: List<WidgetApp>) {
|
||||
_widgetApps.update { widgetApps }
|
||||
}
|
||||
|
||||
fun seedWidgetPreviews(map: Map<WidgetId, WidgetPreview>) {
|
||||
_widgetPreviews.update { map }
|
||||
}
|
||||
|
||||
fun seedFeaturedWidgets(widgetIds: Set<WidgetId>) {
|
||||
_featuredWidgetIds.update { widgetIds }
|
||||
}
|
||||
|
||||
override fun initialize() {}
|
||||
|
||||
override fun observeWidgets(): Flow<List<WidgetApp>> = _widgetApps
|
||||
|
||||
override suspend fun getWidgetPreview(id: WidgetId): WidgetPreview =
|
||||
_widgetPreviews.value[id] ?: WidgetPreview.PlaceholderWidgetPreview
|
||||
|
||||
override fun getFeaturedWidgets(): Flow<List<PickableWidget>> =
|
||||
combine(_featuredWidgetIds, _widgetApps) { widgetIds, widgetApps ->
|
||||
widgetApps.flatMap { it.widgets }.filter { widgetIds.contains(it.id) }
|
||||
}
|
||||
|
||||
override suspend fun searchWidgets(input: String): List<WidgetApp> = _widgetApps.value.map {
|
||||
it.copy(widgets = it.widgets.filter { widget ->
|
||||
val description = widget.description?.toString() ?: ""
|
||||
widget.label.contains(input) || description.contains(input)
|
||||
})
|
||||
}.filter { it.widgets.isNotEmpty() }
|
||||
|
||||
override fun cleanUp() {
|
||||
_widgetApps.update { emptyList() }
|
||||
_widgetPreviews.update { emptyMap() }
|
||||
_featuredWidgetIds.update { emptySet() }
|
||||
}
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import android.platform.test.rule.AllowedDevices
|
||||
import android.platform.test.rule.DeviceProduct
|
||||
import android.platform.test.rule.LimitDevicesRule
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.test.assertCountEquals
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotSelected
|
||||
import androidx.compose.ui.test.assertIsSelected
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.hasTextExactly
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onSiblings
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.TestUtils
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_LABEL
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_LABEL
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.workUser
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetAppIconsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.FilterWidgetsForHostUseCase
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.GroupWidgetAppsByProfileUseCase
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import com.android.launcher3.widgetpicker.ui.rememberViewModel
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@AllowedDevices(allowed = [DeviceProduct.CF_PHONE])
|
||||
class LandingScreenSinglePaneTest {
|
||||
@get:Rule
|
||||
val limitDevicesRule = LimitDevicesRule()
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(testDispatcher)
|
||||
private val context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private lateinit var viewModel: LandingScreenViewModel
|
||||
private val widgetsRepository = FakeWidgetsRepository()
|
||||
private val widgetAppIconsRepository = FakeWidgetAppIconsRepository()
|
||||
private val widgetsUsersRepository = FakeWidgetUsersRepository()
|
||||
|
||||
private lateinit var featuredTabLabel: String
|
||||
private lateinit var browseTabLabel: String
|
||||
private val featuredWidgetA = PERSONAL_TEST_APPS[0].widgets[0]
|
||||
private val featuredWidgetB = WORK_TEST_APPS[0].widgets[0]
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
viewModel = LandingScreenViewModel(
|
||||
widgetsInteractor = WidgetsInteractor(
|
||||
widgetsRepository = widgetsRepository,
|
||||
widgetUsersRepository = widgetsUsersRepository,
|
||||
filterWidgetsForHostUseCase = FilterWidgetsForHostUseCase(WidgetHostInfo()),
|
||||
getWidgetAppsByProfileUseCase = GroupWidgetAppsByProfileUseCase(),
|
||||
backgroundContext = testDispatcher
|
||||
),
|
||||
widgetAppIconsInteractor = WidgetAppIconsInteractor(
|
||||
widgetAppIconsRepository = widgetAppIconsRepository,
|
||||
widgetsRepository = widgetsRepository,
|
||||
backgroundContext = testDispatcher
|
||||
)
|
||||
)
|
||||
|
||||
featuredTabLabel =
|
||||
context.resources.getString(R.string.featured_widgets_tab_label)
|
||||
browseTabLabel =
|
||||
context.resources.getString(R.string.browse_widgets_tab_label)
|
||||
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
widgetsRepository.seedFeaturedWidgets(setOf(featuredWidgetA.id, featuredWidgetB.id))
|
||||
widgetsUsersRepository.seedUserProfiles(
|
||||
WidgetUserProfiles(
|
||||
personal = TestUtils.widgetUserProfilePersonal,
|
||||
work = TestUtils.widgetUserProfileWork
|
||||
),
|
||||
workProfileUser = workUser
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SinglePaneTestContent() {
|
||||
val viewModel = rememberViewModel { viewModel }
|
||||
|
||||
LandingScreen(
|
||||
isCompact = true,
|
||||
onEnterSearchMode = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun showsFeaturedSectionByDefault() = testScope.runTest {
|
||||
composeTestRule.setContent { SinglePaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Toolbar tabs state
|
||||
composeTestRule.onNode(hasTextExactly(featuredTabLabel))
|
||||
.assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().assertIsNotSelected()
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().assertIsNotSelected()
|
||||
// Featured Widgets state
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetA.label)).assertExists()
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetB.label)).assertExists()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun clickingOnAnotherTabShowsAppsList() = testScope.runTest {
|
||||
composeTestRule.setContent { SinglePaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().performClick()
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Toolbar tabs state
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(featuredTabLabel))
|
||||
.assertIsNotSelected()
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().assertIsNotSelected()
|
||||
// No recommendations showing
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetA.label)).assertIsNotDisplayed()
|
||||
// Has list of personal apps showing
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
// But not the work apps
|
||||
composeTestRule.onNode(hasText(WORK_TEST_APPS[0].title!!.toString()))
|
||||
.assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun noWorkProfile() = testScope.runTest {
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS)
|
||||
widgetsRepository.seedFeaturedWidgets(setOf(featuredWidgetA.id))
|
||||
widgetsUsersRepository.seedUserProfiles(
|
||||
WidgetUserProfiles(
|
||||
personal = TestUtils.widgetUserProfilePersonal,
|
||||
work = null
|
||||
),
|
||||
workProfileUser = null
|
||||
)
|
||||
|
||||
composeTestRule.setContent { SinglePaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Toolbar tabs state shows 2 tabs (featured / browse)
|
||||
composeTestRule.onNode(hasTextExactly(featuredTabLabel))
|
||||
.assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(browseTabLabel)).assertExists().assertIsNotSelected()
|
||||
composeTestRule.onNode(hasTextExactly(browseTabLabel)).onSiblings().assertCountEquals(1)
|
||||
// featured widgets showing
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetA.label)).assertIsDisplayed()
|
||||
// Widget apps list is not showing.
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertIsNotDisplayed()
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.landing
|
||||
|
||||
import android.platform.test.rule.AllowedDevices
|
||||
import android.platform.test.rule.DeviceProduct
|
||||
import android.platform.test.rule.LimitDevicesRule
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.semantics.SemanticsProperties
|
||||
import androidx.compose.ui.semantics.getOrNull
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.SemanticsMatcher
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotSelected
|
||||
import androidx.compose.ui.test.assertIsSelected
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.hasTextExactly
|
||||
import androidx.compose.ui.test.isSelected
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.TestUtils
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_LABEL
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_LABEL
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.workUser
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetAppIconsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.FilterWidgetsForHostUseCase
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.GroupWidgetAppsByProfileUseCase
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import com.android.launcher3.widgetpicker.ui.rememberViewModel
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@AllowedDevices(allowed = [DeviceProduct.CF_TABLET])
|
||||
class LandingScreenTwoPaneTest {
|
||||
@get:Rule
|
||||
val limitDevicesRule = LimitDevicesRule()
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(testDispatcher)
|
||||
private val context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private lateinit var viewModel: LandingScreenViewModel
|
||||
private val widgetsRepository = FakeWidgetsRepository()
|
||||
private val widgetAppIconsRepository = FakeWidgetAppIconsRepository()
|
||||
private val widgetsUsersRepository = FakeWidgetUsersRepository()
|
||||
|
||||
private lateinit var featuredTabLabel: String
|
||||
private lateinit var browseTabLabel: String
|
||||
private val featuredWidgetA = PERSONAL_TEST_APPS[0].widgets[0]
|
||||
private val featuredWidgetB = WORK_TEST_APPS[0].widgets[0]
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
viewModel = LandingScreenViewModel(
|
||||
widgetsInteractor = WidgetsInteractor(
|
||||
widgetsRepository = widgetsRepository,
|
||||
widgetUsersRepository = widgetsUsersRepository,
|
||||
filterWidgetsForHostUseCase = FilterWidgetsForHostUseCase(WidgetHostInfo()),
|
||||
getWidgetAppsByProfileUseCase = GroupWidgetAppsByProfileUseCase(),
|
||||
backgroundContext = testDispatcher,
|
||||
),
|
||||
widgetAppIconsInteractor = WidgetAppIconsInteractor(
|
||||
widgetAppIconsRepository = widgetAppIconsRepository,
|
||||
widgetsRepository = widgetsRepository,
|
||||
backgroundContext = testDispatcher
|
||||
)
|
||||
)
|
||||
|
||||
featuredTabLabel =
|
||||
context.resources.getString(R.string.featured_widgets_tab_label)
|
||||
browseTabLabel =
|
||||
context.resources.getString(R.string.browse_widgets_tab_label)
|
||||
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
widgetsRepository.seedFeaturedWidgets(setOf(featuredWidgetA.id, featuredWidgetB.id))
|
||||
widgetsUsersRepository.seedUserProfiles(
|
||||
WidgetUserProfiles(
|
||||
personal = TestUtils.widgetUserProfilePersonal,
|
||||
work = TestUtils.widgetUserProfileWork
|
||||
),
|
||||
workProfileUser = workUser
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TwoPaneTestContent() {
|
||||
val viewModel = rememberViewModel { viewModel }
|
||||
|
||||
LandingScreen(
|
||||
isCompact = false,
|
||||
onEnterSearchMode = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun showsFeaturedSectionByDefault() = testScope.runTest {
|
||||
composeTestRule.setContent { TwoPaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Featured tab as list item
|
||||
composeTestRule.onNode(hasText(featuredTabLabel)).assertIsSelected()
|
||||
// And toolbar also simultaneously shows one of the tabs as selected
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().assertIsNotSelected()
|
||||
// Featured Widgets state
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetA.label)).assertExists()
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetB.label)).assertExists()
|
||||
// List on left showing personal apps
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists().assertIsNotSelected()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalTestApi::class)
|
||||
@Test
|
||||
fun clickingOnWorkTab_updatesAppsListInLeftPane() = testScope.runTest {
|
||||
composeTestRule.setContent { TwoPaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().assertIsNotSelected()
|
||||
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().performClick()
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
composeTestRule.waitUntilAtLeastOneExists(hasTextExactly(WORK_LABEL) and isSelected())
|
||||
|
||||
// Toolbar tabs state
|
||||
composeTestRule.onNode(hasTextExactly(WORK_LABEL)).assertExists().assertIsSelected()
|
||||
composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().assertIsNotSelected()
|
||||
// Selecting toolbar tabs in 2-pane view doesn't reset what's showing in right pane; one has
|
||||
// to click on specific app header to see the widgets.
|
||||
composeTestRule.onNode(hasText(featuredTabLabel)).assertIsSelected()
|
||||
// No recommendations showing
|
||||
composeTestRule.onNode(hasText(featuredWidgetA.label)).assertIsDisplayed()
|
||||
// Has list of work apps showing
|
||||
composeTestRule.onNode(hasText(WORK_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
.assertIsNotSelected()
|
||||
// But not the personal apps
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun selectingAppOnLeft_updatesRightPane() = testScope.runTest {
|
||||
val appToSelect = PERSONAL_TEST_APPS[1].title!!.toString()
|
||||
|
||||
composeTestRule.setContent { TwoPaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Feature tab selected and right pane title indicating the same.
|
||||
composeTestRule.onNode(hasText(featuredTabLabel)).assertIsSelected()
|
||||
val rightPaneTitleBefore = context.resources.getString(
|
||||
R.string.widget_picker_right_pane_accessibility_label,
|
||||
featuredTabLabel
|
||||
)
|
||||
composeTestRule.onNode(SemanticsMatcher("Right paneTitle before selecting an app on left") {
|
||||
it.config.getOrNull(SemanticsProperties.PaneTitle) == rightPaneTitleBefore
|
||||
}).assertExists()
|
||||
|
||||
composeTestRule.onNode(hasText(appToSelect)).assertExists().performClick()
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Now app is selected and featured tab is not.
|
||||
composeTestRule.onNode(hasText(appToSelect)).assertIsSelected()
|
||||
composeTestRule.onNode(hasText(featuredTabLabel)).assertIsNotSelected()
|
||||
// widgets for the selected app are showing
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].widgets[0].label))
|
||||
.assertIsDisplayed()
|
||||
val rightPaneTitleAfter = context.resources.getString(
|
||||
R.string.widget_picker_right_pane_accessibility_label,
|
||||
appToSelect
|
||||
)
|
||||
composeTestRule.onNode(SemanticsMatcher("Right PaneTitle after clicking on app") {
|
||||
it.config.getOrNull(SemanticsProperties.PaneTitle) == rightPaneTitleAfter
|
||||
}).assertExists()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun noWorkProfile_noFloatingToolbar() = testScope.runTest {
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS)
|
||||
widgetsRepository.seedFeaturedWidgets(setOf(featuredWidgetA.id))
|
||||
widgetsUsersRepository.seedUserProfiles(
|
||||
profiles = WidgetUserProfiles(
|
||||
personal = TestUtils.widgetUserProfilePersonal,
|
||||
work = null
|
||||
),
|
||||
workProfileUser = null
|
||||
)
|
||||
|
||||
composeTestRule.setContent { TwoPaneTestContent() }
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// Featured list header
|
||||
composeTestRule.onNode(hasText(featuredTabLabel))
|
||||
.assertIsSelected()
|
||||
// No toolbar i.e. browse tab
|
||||
composeTestRule.onNode(hasTextExactly(browseTabLabel)).assertDoesNotExist()
|
||||
// featured widgets showing
|
||||
composeTestRule.onNode(hasTextExactly(featuredWidgetA.label))
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
// But not other widgets
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].widgets[0].label))
|
||||
.assertDoesNotExist()
|
||||
// Widget apps list shown on left
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertIsDisplayed().assertIsNotSelected()
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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.ui.fullcatalog.screens.search
|
||||
|
||||
import android.platform.test.rule.AllowedDevices
|
||||
import android.platform.test.rule.DeviceProduct
|
||||
import android.platform.test.rule.LimitDevicesRule
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.widgetpicker.R
|
||||
import com.android.launcher3.widgetpicker.TestUtils
|
||||
import com.android.launcher3.widgetpicker.TestUtils.PERSONAL_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.WORK_TEST_APPS
|
||||
import com.android.launcher3.widgetpicker.TestUtils.workUser
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetAppIconsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.interactor.WidgetsInteractor
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.FilterWidgetsForHostUseCase
|
||||
import com.android.launcher3.widgetpicker.domain.usecase.GroupWidgetAppsByProfileUseCase
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetAppIconsRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetUsersRepository
|
||||
import com.android.launcher3.widgetpicker.repository.FakeWidgetsRepository
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetHostInfo
|
||||
import com.android.launcher3.widgetpicker.shared.model.WidgetUserProfiles
|
||||
import com.android.launcher3.widgetpicker.ui.rememberViewModel
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@AllowedDevices(allowed = [DeviceProduct.CF_TABLET])
|
||||
class SearchScreenTest {
|
||||
@get:Rule
|
||||
val limitDevicesRule = LimitDevicesRule()
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(testDispatcher)
|
||||
private val context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private lateinit var viewModel: SearchScreenViewModel
|
||||
private val widgetsRepository = FakeWidgetsRepository()
|
||||
private val widgetAppIconsRepository = FakeWidgetAppIconsRepository()
|
||||
private val widgetsUsersRepository = FakeWidgetUsersRepository()
|
||||
|
||||
private lateinit var searchBarHint: String
|
||||
private lateinit var clearButtonContentDescription: String
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
viewModel = SearchScreenViewModel(
|
||||
widgetsInteractor = WidgetsInteractor(
|
||||
widgetsRepository = widgetsRepository,
|
||||
widgetUsersRepository = widgetsUsersRepository,
|
||||
filterWidgetsForHostUseCase = FilterWidgetsForHostUseCase(WidgetHostInfo()),
|
||||
getWidgetAppsByProfileUseCase = GroupWidgetAppsByProfileUseCase(),
|
||||
backgroundContext = testDispatcher,
|
||||
),
|
||||
widgetAppIconsInteractor = WidgetAppIconsInteractor(
|
||||
widgetAppIconsRepository = widgetAppIconsRepository,
|
||||
widgetsRepository = widgetsRepository,
|
||||
backgroundContext = testDispatcher
|
||||
),
|
||||
)
|
||||
|
||||
searchBarHint = context.applicationContext.resources.getString(
|
||||
R.string.widgets_search_bar_hint
|
||||
)
|
||||
clearButtonContentDescription =
|
||||
context.applicationContext.resources.getString(R.string.widget_search_bar_clear_button_label)
|
||||
widgetsRepository.seedWidgets(PERSONAL_TEST_APPS + WORK_TEST_APPS)
|
||||
widgetsUsersRepository.seedUserProfiles(
|
||||
WidgetUserProfiles(
|
||||
personal = TestUtils.widgetUserProfilePersonal,
|
||||
work = TestUtils.widgetUserProfileWork
|
||||
),
|
||||
workProfileUser = workUser
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TestContent(isCompact: Boolean) {
|
||||
val viewModel = rememberViewModel { viewModel }
|
||||
|
||||
SearchScreen(
|
||||
isCompact = isCompact,
|
||||
onExitSearchMode = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun singlePane_showMatchingApps() = testScope.runTest {
|
||||
composeTestRule.setContent {
|
||||
TestContent(
|
||||
isCompact = true
|
||||
)
|
||||
}
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
val testInputOne = "PersonalWidget"
|
||||
composeTestRule.onNodeWithText(searchBarHint)
|
||||
.performTextInput(testInputOne)
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// has both apps
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].title!!.toString()))
|
||||
.assertExists()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription(clearButtonContentDescription)
|
||||
.performClick()
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// change query
|
||||
val testInputTwo = "PersonalWidget1A"
|
||||
composeTestRule.onNodeWithText(searchBarHint).performTextInput(testInputTwo)
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// has only app 1
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].title!!.toString()))
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun twoPane_showMatchingApps() = testScope.runTest {
|
||||
composeTestRule.setContent {
|
||||
TestContent(
|
||||
isCompact = false
|
||||
)
|
||||
}
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
val testInputOne = "PersonalWidget"
|
||||
composeTestRule.onNodeWithText(searchBarHint)
|
||||
.performTextInput(testInputOne)
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// has both apps
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].title!!.toString()))
|
||||
.assertExists()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription(clearButtonContentDescription)
|
||||
.performClick()
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// change query
|
||||
val testInputTwo = "PersonalWidget1A"
|
||||
composeTestRule.onNodeWithText(searchBarHint).performTextInput(testInputTwo)
|
||||
|
||||
runCurrent()
|
||||
composeTestRule.waitForIdle()
|
||||
|
||||
// has only app 1
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString()))
|
||||
.assertExists()
|
||||
composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[1].title!!.toString()))
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
./multivalentTests
|
||||
@@ -16,4 +16,16 @@
|
||||
|
||||
package com.android.quickstep.compose.core
|
||||
|
||||
interface QuickstepComposeFeatures
|
||||
import android.view.View
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskViewModel
|
||||
import com.android.quickstep.views.TaskViewIcon
|
||||
|
||||
interface QuickstepComposeFeatures {
|
||||
fun startIconAppChip(
|
||||
composeView: TaskViewIcon,
|
||||
viewModel: TaskViewModel,
|
||||
taskId: Int,
|
||||
onClick: () -> Unit = {},
|
||||
onLongClick: () -> Unit = {},
|
||||
): View
|
||||
}
|
||||
@@ -17,13 +17,29 @@
|
||||
package com.android.quickstep.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.android.launcher3.compose.ComposeFacade
|
||||
import com.android.launcher3.compose.core.BaseComposeFacade
|
||||
import com.android.quickstep.compose.core.QuickstepComposeFeatures
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskViewModel
|
||||
import com.android.quickstep.views.TaskViewIcon
|
||||
|
||||
object QuickstepComposeFacade : BaseComposeFacade, QuickstepComposeFeatures {
|
||||
|
||||
override fun isComposeAvailable() = ComposeFacade.isComposeAvailable()
|
||||
|
||||
override fun initComposeView(appContext: Context) = ComposeFacade.initComposeView(appContext)
|
||||
|
||||
override fun startIconAppChip(
|
||||
composeView: TaskViewIcon,
|
||||
viewModel: TaskViewModel,
|
||||
taskId: Int,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit,
|
||||
): View {
|
||||
error(
|
||||
"Compose is not available. Make sure to check isComposeAvailable() before calling any" +
|
||||
" other function on ComposeFacade."
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,29 @@
|
||||
package com.android.quickstep.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import com.android.launcher3.compose.ComposeFacade
|
||||
import com.android.launcher3.compose.core.BaseComposeFacade
|
||||
import com.android.quickstep.compose.core.QuickstepComposeFeatures
|
||||
import com.android.quickstep.recents.ui.composable.TaskAppChip
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskViewModel
|
||||
import com.android.quickstep.views.TaskViewIcon
|
||||
|
||||
object QuickstepComposeFacade : BaseComposeFacade, QuickstepComposeFeatures {
|
||||
override fun isComposeAvailable() = ComposeFacade.isComposeAvailable()
|
||||
|
||||
override fun initComposeView(appContext: Context) = ComposeFacade.initComposeView(appContext)
|
||||
|
||||
override fun startIconAppChip(
|
||||
composeView: TaskViewIcon,
|
||||
viewModel: TaskViewModel,
|
||||
taskId: Int,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit,
|
||||
): View =
|
||||
(composeView.asView() as ComposeView).apply {
|
||||
setContent { MaterialTheme { TaskAppChip(viewModel, taskId, onClick, onLongClick) } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* 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.quickstep.recents.ui.composable
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.basicMarquee
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.CompositingStrategy
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.text.PlatformTextStyle
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.PreviewLightDark
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.android.app.animation.Interpolators
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.util.FontScalePreviews
|
||||
import com.android.launcher3.util.painterResource
|
||||
import com.android.launcher3.util.toComposeEasing
|
||||
import com.android.quickstep.recents.ui.composable.AppChip.IconSize
|
||||
import com.android.quickstep.recents.ui.composable.AppChip.IconSizeExpanded
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskData
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskTileUiState
|
||||
import com.android.quickstep.recents.ui.viewmodel.TaskViewModel
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
private data class AppChipInfo(val title: String, val icon: Drawable, val expanded: Boolean)
|
||||
|
||||
private fun mapAppChipInfo(state: TaskTileUiState, taskId: Int): AppChipInfo? =
|
||||
state.tasks
|
||||
.firstOrNull { it.taskId == taskId }
|
||||
.let {
|
||||
if (it is TaskData.Data && it.title != null && it.icon != null) {
|
||||
AppChipInfo(
|
||||
title = it.title,
|
||||
icon = it.icon,
|
||||
expanded = false,
|
||||
// TODO: The state needs to be implemented in the VM when this AppChip
|
||||
// is added to the TaskView. The state will be called isMenuExpanded, and it
|
||||
// indicates whether the menu is expanded or not. When the chip is clicked,
|
||||
// it will notify the VM that the menu is expanded. Then, this property will
|
||||
// be either Open or Collapsed.
|
||||
// state.isMenuExpanded is MenuState.Open &&
|
||||
// state.isMenuExpanded.taskId == taskId,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TaskAppChip(
|
||||
viewModel: TaskViewModel,
|
||||
taskId: Int,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit,
|
||||
) {
|
||||
val chipState: AppChipInfo? by
|
||||
viewModel.state.map { mapAppChipInfo(it, taskId) }.collectAsState(null)
|
||||
|
||||
chipState?.let {
|
||||
AppChip(
|
||||
title = it.title,
|
||||
icon = it.icon,
|
||||
expanded = it.expanded,
|
||||
onClick = {
|
||||
// viewModel.toggleMenu(taskId, !it.expanded)
|
||||
onClick()
|
||||
},
|
||||
onLongClick = {
|
||||
// viewModel.toggleMenu(taskId, !it.expanded)
|
||||
onLongClick()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AppChip(
|
||||
title: String,
|
||||
icon: Drawable,
|
||||
modifier: Modifier = Modifier,
|
||||
expanded: Boolean = false,
|
||||
interactionSource: MutableInteractionSource? = remember { MutableInteractionSource() },
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit = {},
|
||||
) {
|
||||
val style = AppChip.getStyle(expanded)
|
||||
var isFocused = remember { mutableStateOf(false) }
|
||||
val haptic = LocalHapticFeedback.current
|
||||
|
||||
Box(modifier = Modifier.height(52.dp), contentAlignment = Alignment.CenterStart) {
|
||||
Row(
|
||||
modifier =
|
||||
modifier
|
||||
.offset { IntOffset(style.startOffset.roundToPx(), 0) }
|
||||
.size(style.width, style.height)
|
||||
.shadow(AppChip.Shadow, AppChip.ChipShape)
|
||||
.drawBehind {
|
||||
drawRoundRect(
|
||||
color = style.backgroundColor,
|
||||
size = DpSize(style.width, style.height).toSize(),
|
||||
)
|
||||
}
|
||||
.focusBorder(isFocused, width = 2.dp, color = style.focusBorderColor)
|
||||
.combinedClickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null,
|
||||
onClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.VirtualKey)
|
||||
onClick.invoke()
|
||||
},
|
||||
onLongClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onLongClick.invoke()
|
||||
},
|
||||
)
|
||||
.clip(AppChip.ChipShape)
|
||||
.padding(
|
||||
start = style.startPadding,
|
||||
top = style.topPadding,
|
||||
end = style.endPadding,
|
||||
bottom = style.bottomPadding,
|
||||
),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(icon),
|
||||
modifier = Modifier.requiredSize(IconSize).scale(style.iconScale).clip(CircleShape),
|
||||
contentDescription = title,
|
||||
)
|
||||
Text(
|
||||
text = title,
|
||||
modifier =
|
||||
Modifier.padding(start = style.dividerSize)
|
||||
.weight(1f)
|
||||
.fadingEdge()
|
||||
.heightIn(max = IconSizeExpanded)
|
||||
.then(if (expanded) Modifier.basicMarquee(1) else Modifier),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Visible,
|
||||
softWrap = false,
|
||||
style =
|
||||
TextStyle(
|
||||
platformStyle = PlatformTextStyle(includeFontPadding = false),
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 20.sp,
|
||||
color = style.contentColor,
|
||||
),
|
||||
)
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_chevron_down),
|
||||
contentDescription = "",
|
||||
modifier = Modifier.size(24.dp).scale(1f, style.chevronScaleY),
|
||||
tint = style.contentColor,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Modifier.focusBorder(
|
||||
isFocused: MutableState<Boolean>,
|
||||
width: Dp = 1.dp,
|
||||
color: Color = Color.Black,
|
||||
shape: Shape = CircleShape,
|
||||
): Modifier =
|
||||
this.onFocusChanged { isFocused.value = it.isFocused }
|
||||
.focusable()
|
||||
.then(if (isFocused.value) Modifier.border(width, color, shape) else Modifier)
|
||||
|
||||
fun Modifier.fadingEdge(): Modifier {
|
||||
val fade = Brush.horizontalGradient(.8f to Color.Red, 1f to Color.Transparent)
|
||||
return this.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen).drawWithContent {
|
||||
drawContent()
|
||||
drawRect(brush = fade, blendMode = BlendMode.DstIn)
|
||||
}
|
||||
}
|
||||
|
||||
private object AppChip {
|
||||
private const val REVEAL_DURATION = 417
|
||||
private const val HIDE_DURATION = 333
|
||||
|
||||
val Shadow = 4.dp
|
||||
val IconSize = 24.dp
|
||||
val IconSizeExpanded = 32.dp
|
||||
val ChipShape = RoundedCornerShape(100.dp)
|
||||
|
||||
private val Collapsed =
|
||||
AppChipSizes(
|
||||
size = DpSize(156.dp, 36.dp),
|
||||
startPadding = 6.dp,
|
||||
endPadding = 8.dp,
|
||||
topPadding = 6.dp,
|
||||
bottomPadding = 6.dp,
|
||||
offset = DpOffset(6.dp, 12.dp),
|
||||
dividerSize = 8.dp,
|
||||
chevronScaleY = 1f,
|
||||
iconScale = 1f,
|
||||
)
|
||||
|
||||
private val Expanded =
|
||||
AppChipSizes(
|
||||
size = DpSize(216.dp, 52.dp),
|
||||
startPadding = 10.dp,
|
||||
endPadding = 10.dp,
|
||||
topPadding = 10.dp,
|
||||
bottomPadding = 10.dp,
|
||||
offset = DpOffset(0.dp, 4.dp),
|
||||
dividerSize = 12.dp,
|
||||
chevronScaleY = -1f,
|
||||
iconScale = IconSizeExpanded / IconSize,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun getStyle(isExpanded: Boolean): AppChipStyle {
|
||||
val backgroundColor = MaterialTheme.colorScheme.surfaceBright
|
||||
val contentColor = MaterialTheme.colorScheme.contentColorFor(backgroundColor)
|
||||
val focusBorderColor = MaterialTheme.colorScheme.secondary
|
||||
|
||||
val transition =
|
||||
updateTransition(if (isExpanded) Expanded else Collapsed, label = "AppChip State")
|
||||
val emphasizedEasing = Interpolators.EMPHASIZED.toComposeEasing()
|
||||
val duration = if (isExpanded) HIDE_DURATION else REVEAL_DURATION
|
||||
val animationSpecInDp = tween<Dp>(durationMillis = duration, easing = emphasizedEasing)
|
||||
val animationSpecInFloat =
|
||||
tween<Float>(durationMillis = duration, easing = emphasizedEasing)
|
||||
|
||||
val width = transition.animateDp({ animationSpecInDp }) { it.size.width }
|
||||
val height = transition.animateDp({ animationSpecInDp }) { it.size.height }
|
||||
val iconScale = transition.animateFloat({ animationSpecInFloat }) { it.iconScale }
|
||||
val dividerSize = transition.animateDp({ animationSpecInDp }) { it.dividerSize }
|
||||
val chevronScaleY = transition.animateFloat({ animationSpecInFloat }) { it.chevronScaleY }
|
||||
val animatedStartOffset = transition.animateDp({ animationSpecInDp }) { it.offset.x }
|
||||
|
||||
val startPadding = transition.animateDp({ animationSpecInDp }) { it.startPadding }
|
||||
val endPadding = transition.animateDp({ animationSpecInDp }) { it.endPadding }
|
||||
val topPadding = transition.animateDp({ animationSpecInDp }) { it.topPadding }
|
||||
val bottomPadding = transition.animateDp({ animationSpecInDp }) { it.bottomPadding }
|
||||
|
||||
return remember(transition) {
|
||||
AppChipStyle(
|
||||
backgroundColor = backgroundColor,
|
||||
contentColor = contentColor,
|
||||
focusBorderColor = focusBorderColor,
|
||||
width = width,
|
||||
height = height,
|
||||
iconScale = iconScale,
|
||||
dividerSize = dividerSize,
|
||||
chevronScaleY = chevronScaleY,
|
||||
animatedStartOffset = animatedStartOffset,
|
||||
startPadding = startPadding,
|
||||
endPadding = endPadding,
|
||||
topPadding = topPadding,
|
||||
bottomPadding = bottomPadding,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private data class AppChipSizes(
|
||||
val size: DpSize,
|
||||
val startPadding: Dp,
|
||||
val endPadding: Dp,
|
||||
val topPadding: Dp,
|
||||
val bottomPadding: Dp,
|
||||
val offset: DpOffset,
|
||||
val dividerSize: Dp,
|
||||
val chevronScaleY: Float,
|
||||
val iconScale: Float,
|
||||
)
|
||||
}
|
||||
|
||||
private class AppChipStyle(
|
||||
val backgroundColor: Color,
|
||||
val contentColor: Color,
|
||||
val focusBorderColor: Color,
|
||||
width: State<Dp>,
|
||||
height: State<Dp>,
|
||||
iconScale: State<Float>,
|
||||
dividerSize: State<Dp>,
|
||||
chevronScaleY: State<Float>,
|
||||
animatedStartOffset: State<Dp>,
|
||||
startPadding: State<Dp>,
|
||||
endPadding: State<Dp>,
|
||||
topPadding: State<Dp>,
|
||||
bottomPadding: State<Dp>,
|
||||
) {
|
||||
val width by width
|
||||
val height by height
|
||||
val iconScale by iconScale
|
||||
val dividerSize by dividerSize
|
||||
val chevronScaleY by chevronScaleY
|
||||
val startOffset by animatedStartOffset
|
||||
val startPadding by startPadding
|
||||
val endPadding by endPadding
|
||||
val topPadding by topPadding
|
||||
val bottomPadding by bottomPadding
|
||||
}
|
||||
|
||||
@Composable
|
||||
@PreviewLightDark
|
||||
@FontScalePreviews
|
||||
private fun ChipPreview() {
|
||||
val (expanded, setExpanded) = remember { mutableStateOf(false) }
|
||||
val appName = "Very long-name-for the app that won't fit in the chip"
|
||||
val appIcon =
|
||||
AppCompatResources.getDrawable(
|
||||
LocalContext.current,
|
||||
R.drawable.ic_conversations_widget_category,
|
||||
)
|
||||
|
||||
MaterialTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.surface) {
|
||||
Box(modifier = Modifier.widthIn(170.dp)) {
|
||||
AppChip(
|
||||
title = appName,
|
||||
icon = appIcon!!,
|
||||
expanded = expanded,
|
||||
onClick = { setExpanded(!expanded) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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.quickstep.recents.ui.composable
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.test.assertIsFocused
|
||||
import androidx.compose.ui.test.assertIsNotFocused
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.compose.ui.test.performKeyPress
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.helper.NavigateDownTabEvent
|
||||
import com.google.android.apps.nexuslauncher.imagecomparison.goldenpathmanager.ViewScreenshotGoldenPathManager
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
|
||||
import platform.test.runner.parameterized.Parameters
|
||||
import platform.test.screenshot.DeviceEmulationSpec
|
||||
import platform.test.screenshot.Displays
|
||||
import platform.test.screenshot.getEmulatedDevicePathConfig
|
||||
import platform.test.screenshot.utils.compose.ComposeScreenshotTestRule
|
||||
|
||||
@RunWith(ParameterizedAndroidJunit4::class)
|
||||
class AppChipScreenshotTest(emulationSpec: DeviceEmulationSpec) {
|
||||
|
||||
@get:Rule val screenshotRule = composeScreenshotTestRule(emulationSpec)
|
||||
|
||||
@Composable
|
||||
private fun AppChipForTest(expanded: Boolean, onClick: () -> Unit = {}) {
|
||||
Column(
|
||||
modifier = Modifier.widthIn(min = COLLAPSED_WIDTH_OFFSET),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
AppChip(
|
||||
title = SHORT_APP_NAME,
|
||||
icon = getGoogleDrawable()!!,
|
||||
modifier = Modifier.testTag("appChip_short"),
|
||||
expanded = expanded,
|
||||
onClick = onClick,
|
||||
)
|
||||
AppChip(
|
||||
title = LONG_APP_NAME,
|
||||
icon = getGoogleDrawable()!!,
|
||||
modifier = Modifier.testTag("appChip_long"),
|
||||
expanded = expanded,
|
||||
onClick = onClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun collapsed() =
|
||||
screenshotRule.screenshotTest("appchip_collapsed") { AppChipForTest(expanded = false) }
|
||||
|
||||
@Test
|
||||
fun expanded() =
|
||||
screenshotRule.screenshotTest("appchip_expanded") { AppChipForTest(expanded = true) }
|
||||
|
||||
@Test
|
||||
fun focusableState() {
|
||||
screenshotRule.screenshotTest(
|
||||
"appchip_focusable",
|
||||
beforeScreenshot = {
|
||||
val composeTestRule = screenshotRule.composeRule
|
||||
composeTestRule.onNodeWithTag("appChip").assertIsNotFocused()
|
||||
|
||||
// Press down to focus first element
|
||||
composeTestRule.onRoot().performKeyPress(keyEvent = NavigateDownTabEvent)
|
||||
|
||||
composeTestRule.onNodeWithTag("appChip").assertIsFocused()
|
||||
},
|
||||
) {
|
||||
Box(modifier = Modifier.widthIn(min = COLLAPSED_WIDTH_OFFSET)) {
|
||||
AppChip(
|
||||
title = SHORT_APP_NAME,
|
||||
icon = getGoogleDrawable()!!,
|
||||
modifier = Modifier.testTag("appChip"),
|
||||
expanded = false,
|
||||
onClick = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGoogleDrawable(): Drawable? {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
val identifier =
|
||||
context.resources.getIdentifier(
|
||||
APP_ICON,
|
||||
"drawable",
|
||||
InstrumentationRegistry.getInstrumentation().context.packageName,
|
||||
)
|
||||
return context.getDrawable(identifier)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SHORT_APP_NAME = "App name"
|
||||
const val LONG_APP_NAME = "Very long name for the app"
|
||||
const val APP_ICON = "ic_super_g_color"
|
||||
val COLLAPSED_WIDTH_OFFSET = 156.dp + 6.dp
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
@JvmStatic
|
||||
fun getTestSpecs(): List<DeviceEmulationSpec> {
|
||||
return DeviceEmulationSpec.forDisplays(Displays.Phone, isLandscape = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a [ComposeScreenshotTestRule] for screenshot tests of Compose-based UI. If
|
||||
* [enforcePerfectPixelMatch] is true, enables a strict pixel-by-pixel comparison to detect any
|
||||
* visual differences between images.
|
||||
*/
|
||||
fun composeScreenshotTestRule(
|
||||
emulationSpec: DeviceEmulationSpec,
|
||||
enforcePerfectPixelMatch: Boolean = false,
|
||||
): ComposeScreenshotTestRule {
|
||||
return ComposeScreenshotTestRule(
|
||||
emulationSpec = emulationSpec,
|
||||
pathManager = ViewScreenshotGoldenPathManager(getEmulatedDevicePathConfig(emulationSpec)),
|
||||
enforcePerfectPixelMatch = enforcePerfectPixelMatch,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.quickstep.recents.ui.composable
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.semantics.SemanticsActions
|
||||
import androidx.compose.ui.test.SemanticsMatcher
|
||||
import androidx.compose.ui.test.assertAll
|
||||
import androidx.compose.ui.test.assertHasClickAction
|
||||
import androidx.compose.ui.test.assertWidthIsEqualTo
|
||||
import androidx.compose.ui.test.hasContentDescription
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.helper.hasMinTouchArea
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AppChipTest {
|
||||
@get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Composable
|
||||
private fun AppChipForTest(expanded: Boolean, onClick: () -> Unit = {}) =
|
||||
AppChip(
|
||||
title = APP_NAME,
|
||||
icon = getGoogleDrawable()!!,
|
||||
expanded = expanded,
|
||||
onClick = onClick,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun givenIsCollapsed_whenClicked_chipExpands() {
|
||||
composeTestRule.setContent {
|
||||
val (expanded, setExpanded) = remember { mutableStateOf(false) }
|
||||
AppChipForTest(expanded, onClick = { setExpanded(!expanded) })
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithText(APP_NAME)
|
||||
.assertWidthIsEqualTo(156.dp)
|
||||
.assertHasClickAction()
|
||||
.performClick()
|
||||
.assertWidthIsEqualTo(216.dp)
|
||||
}
|
||||
|
||||
// Accessibility Checks
|
||||
@Test
|
||||
fun checkAccessibility_contentDescription() {
|
||||
composeTestRule.setContent {
|
||||
val (expanded, setExpanded) = remember { mutableStateOf(false) }
|
||||
AppChipForTest(expanded, onClick = { setExpanded(!expanded) })
|
||||
}
|
||||
composeTestRule
|
||||
.onAllNodes(SemanticsMatcher.keyIsDefined(SemanticsActions.OnClick))
|
||||
.assertAll(hasContentDescription(APP_NAME))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkAccessibility_touchTargetArea() {
|
||||
composeTestRule.setContent {
|
||||
val (expanded, setExpanded) = remember { mutableStateOf(false) }
|
||||
AppChipForTest(expanded, onClick = { setExpanded(!expanded) })
|
||||
}
|
||||
composeTestRule
|
||||
.onAllNodes(SemanticsMatcher.keyIsDefined(SemanticsActions.OnClick))
|
||||
.assertAll(hasMinTouchArea())
|
||||
}
|
||||
|
||||
private fun getGoogleDrawable(): Drawable? {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
val identifier =
|
||||
context.resources.getIdentifier(
|
||||
APP_ICON,
|
||||
"drawable",
|
||||
InstrumentationRegistry.getInstrumentation().context.packageName,
|
||||
)
|
||||
return AppCompatResources.getDrawable(context, identifier)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val APP_NAME = "Very long name for the app that won't fit in the chip"
|
||||
const val APP_ICON = "ic_super_g_color"
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"شكل مجاني"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"الكمبيوتر المكتبي"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"نقل التطبيق إلى شاشة خارجية"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"محو"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"كمبيوتر مكتبي"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"ما مِن عناصر تم استخدامها مؤخرًا"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"إعدادات استخدام التطبيق"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Адвольная форма"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Працоўны стол"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Перамясціць на знешні дысплэй"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Ачысціць"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Працоўны стол"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Няма новых элементаў"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Налады выкарыстання праграмы"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Format lliure"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Escriptori"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Mou a la pantalla externa"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Esborra"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Escriptori"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"No hi ha cap element recent"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Configuració d\'ús d\'aplicacions"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Freeform"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Desktop"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Move to external display"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Clear"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Desktop"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"No recent items"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"App usage settings"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Formato libre"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Escritorio"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Mover a pantalla externa"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Borrar"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Ordenador"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"No hay nada reciente"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Ajustes de uso de la aplicación"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Vapaamuotoinen"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Tietokone"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Siirrä ulkoiselle näytölle"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Tyhjennä"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Tietokone"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Ei viimeaikaisia kohteita"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Sovelluksen käyttöasetukset"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Frjálst snið"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Tölva"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Færa í annað tæki"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Hreinsa"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Tölva"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Engin nýleg atriði"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Notkunarstillingar forrits"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"フリーフォーム"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"デスクトップ"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"外部ディスプレイに移動する"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"消去"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"デスクトップ"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"最近のアイテムはありません"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"アプリの使用状況の設定"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"មុខងារទម្រង់សេរី"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"ដែសថប"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"ផ្លាស់ទីទៅផ្ទាំងអេក្រង់ខាងក្រៅ"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"សម្អាត"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"អេក្រង់ដើម"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"មិនមានធាតុថ្មីៗទេ"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"ការកំណត់ការប្រើប្រាស់កម្មវិធី"</string>
|
||||
@@ -95,7 +94,7 @@
|
||||
<string name="allset_description_fallback" msgid="2488751930355201578">"អ្នកអាចចាប់ផ្ដើមប្រើឧបករណ៍របស់អ្នកបានហើយ"</string>
|
||||
<string name="allset_navigation_settings" msgid="4713404605961476027"><annotation id="link">"ការកំណត់ការរុករកប្រព័ន្ធ"</annotation></string>
|
||||
<string name="action_share" msgid="2648470652637092375">"ចែករំលែក"</string>
|
||||
<string name="action_screenshot" msgid="8171125848358142917">"រូបថតអេក្រង់"</string>
|
||||
<string name="action_screenshot" msgid="8171125848358142917">"ថតរូបអេក្រង់"</string>
|
||||
<string name="action_split" msgid="2098009717623550676">"បំបែក"</string>
|
||||
<string name="action_save_app_pair" msgid="5974823919237645229">"រក្សាទុកគូកម្មវិធី"</string>
|
||||
<string name="toast_split_select_app" msgid="8464310533320556058">"ចុចកម្មវិធីផ្សេងទៀត ដើម្បីប្រើមុខងារបំបែកអេក្រង់"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"ຮູບແບບອິດສະຫລະ"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"ເດັສທັອບ"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"ຍ້າຍໄປຫາຈໍສະແດງຜົນພາຍນອກ"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"ລຶບລ້າງ"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"ເດັສທັອບ"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"ບໍ່ມີລາຍການຫຼ້າສຸດ"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"ການຕັ້ງຄ່າການນຳໃຊ້ແອັບ"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Freeform"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Работна површина"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Префрлете се на надворешниот екран"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Избришете"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"За компјутер"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Нема неодамнешни ставки"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Поставки за користење на апликациите"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"ഫ്രീഫോം"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"ഡെസ്ക്ടോപ്പ്"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"ബാഹ്യ ഡിസ്പ്ലേയിലേക്ക് നീക്കുക"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"മായ്ക്കുക"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"ഡെസ്ക്ടോപ്പ്"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"സമീപകാല ഇനങ്ങൾ ഒന്നുമില്ല"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"ആപ്പ് ഉപയോഗ ക്രമീകരണം"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Bentuk bebas"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Desktop"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Alihkan kepada paparan luaran"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Kosongkan"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Desktop"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Tiada item terbaharu"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Tetapan penggunaan apl"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"ଫ୍ରିଫର୍ମ"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"ଡେସ୍କଟପ"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"ଏକ୍ସଟର୍ନଲ ଡିସପ୍ଲେକୁ ମୁଭ କରନ୍ତୁ"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"ଖାଲି କରନ୍ତୁ"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"ଡେସ୍କଟପ"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"ବର୍ତ୍ତମାନର କୌଣସି ଆଇଟମ ନାହିଁ"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"ଆପ ବ୍ୟବହାର ସେଟିଂସ"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Forma livre"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Computador"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Mover para o ecrã externo"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Limpar"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Computador"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Nenhum item recente"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Definições de utilização de aplicações"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Произвольная форма"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Мультиоконный режим"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Перенести на внешний дисплей"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Очистить"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Мультиоконный режим"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Здесь пока ничего нет."</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Настройки использования приложения"</string>
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
<string name="back_gesture_feedback_cancelled" msgid="762621530959111290">"Musíte potiahnuť z pravého alebo ľavého okraja do stredu obrazovky a potom uvoľniť"</string>
|
||||
<string name="back_gesture_feedback_complete_with_overview_follow_up" msgid="9176400654037014471">"Naučili ste sa prejsť späť potiahnutím sprava. V ďalšom kroku sa naučíte prepínať aplikácie."</string>
|
||||
<string name="back_gesture_feedback_complete_with_follow_up" msgid="8653374779579748392">"Dokončili ste gesto na prechod späť. V ďalšom kroku sa naučíte, ako prepínať aplikácie."</string>
|
||||
<string name="back_gesture_feedback_complete_without_follow_up" msgid="197189945858268342">"Použili ste gesto na prechod späť."</string>
|
||||
<string name="back_gesture_feedback_complete_without_follow_up" msgid="197189945858268342">"Dokončili ste gesto na prechod späť"</string>
|
||||
<string name="back_gesture_feedback_swipe_in_nav_bar" msgid="9157480023651452969">"Nesmiete potiahnuť príliš blízko dolnej časti obrazovky"</string>
|
||||
<string name="back_gesture_tutorial_confirm_subtitle" msgid="5181305411668713250">"Ak chcete zmeniť citlivosť gesta Späť, prejdite do Nastavení"</string>
|
||||
<string name="back_gesture_intro_title" msgid="19551256430224428">"Prechod späť potiahnutím"</string>
|
||||
@@ -76,7 +76,7 @@
|
||||
<string name="overview_gesture_feedback_home_detected" msgid="663432226180397138">"Skúste okno pred uvoľnením podržať dlhšie"</string>
|
||||
<string name="overview_gesture_feedback_wrong_swipe_direction" msgid="1191055451018584958">"Musite potiahnuť priamo nahor a potom zastať."</string>
|
||||
<string name="overview_gesture_feedback_complete_with_follow_up" msgid="3544611727467765026">"Naučili ste sa používať gestá. Gestá môžete vypnúť v Nastaveniach."</string>
|
||||
<string name="overview_gesture_feedback_complete_without_follow_up" msgid="2903050864432331629">"Použili ste gesto na prepnutie aplikácií."</string>
|
||||
<string name="overview_gesture_feedback_complete_without_follow_up" msgid="2903050864432331629">"Dokončili ste gesto na prepnutie aplikácií"</string>
|
||||
<string name="overview_gesture_intro_title" msgid="2902054412868489378">"Prepínanie aplikácií potiahnutím"</string>
|
||||
<string name="overview_gesture_intro_subtitle" msgid="4968091015637850859">"Aplikácie môžete prepínať potiahnutím obrazovky zdola nahor, pridržaním a následným uvoľnením."</string>
|
||||
<string name="overview_gesture_tutorial_title" msgid="4125835002668708720">"Prepnutie aplikácií"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Prosta oblika"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Namizni računalnik"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Premik v zunanji zaslon"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Počisti"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Namizni način"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Ni nedavnih elementov"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Nastavitve uporabe aplikacij"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"รูปแบบอิสระ"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"เดสก์ท็อป"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"ย้ายไปยังจอแสดงผลภายนอก"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"ล้าง"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"เดสก์ท็อป"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"ไม่มีรายการล่าสุด"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"การตั้งค่าการใช้แอป"</string>
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<string name="recent_task_option_freeform" msgid="48863056265284071">"Erkin shakl"</string>
|
||||
<string name="recent_task_option_desktop" msgid="8280879717125435668">"Desktop"</string>
|
||||
<string name="recent_task_option_external_display" msgid="4533840664313389484">"Tashqi displeyga olish"</string>
|
||||
<!-- no translation found for recent_task_option_remove_task (803559928027541555) -->
|
||||
<skip />
|
||||
<string name="recent_task_option_remove_task" msgid="803559928027541555">"Tozalash"</string>
|
||||
<string name="recent_task_desktop" msgid="8081113562549637334">"Desktop"</string>
|
||||
<string name="recents_empty_message" msgid="7040467240571714191">"Yaqinda ishlatilgan ilovalar yo‘q"</string>
|
||||
<string name="accessibility_app_usage_settings" msgid="6312864233673544149">"Ilovadan foydalanish sozlamalari"</string>
|
||||
|
||||
@@ -404,6 +404,7 @@
|
||||
<dimen name="transient_taskbar_stashed_height">32dp</dimen>
|
||||
<dimen name="transient_taskbar_all_apps_button_translation_x_offset">8dp</dimen>
|
||||
<dimen name="transient_taskbar_stash_spring_velocity_dp_per_s">400dp</dimen>
|
||||
<dimen name="transient_taskbar_action_corner_padding">48dp</dimen>
|
||||
<dimen name="taskbar_tooltip_vertical_padding">8dp</dimen>
|
||||
<dimen name="taskbar_tooltip_horizontal_padding">16dp</dimen>
|
||||
<dimen name="taskbar_tooltip_y_offset">4dp</dimen>
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.launcher3.taskbar
|
||||
import android.content.Context
|
||||
import android.util.SparseArray
|
||||
import android.view.View
|
||||
import android.window.DesktopExperienceFlags
|
||||
import com.android.launcher3.DeviceProfile
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT
|
||||
@@ -28,7 +29,6 @@ import com.android.launcher3.model.data.ItemInfo
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo
|
||||
import com.android.launcher3.popup.SystemShortcut
|
||||
import com.android.launcher3.views.ActivityContext
|
||||
import com.android.window.flags.Flags.enablePinningAppWithContextMenu
|
||||
|
||||
/**
|
||||
* A single menu item shortcut to allow users to pin an item to the taskbar and unpin an item from
|
||||
@@ -91,8 +91,8 @@ class PinToTaskbarShortcut<T>(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun isPinningAppWithContextMenuEnabled(context: TaskbarActivityContext): Boolean {
|
||||
return enablePinningAppWithContextMenu() && context.isTaskbarShowingDesktopTasks
|
||||
}
|
||||
fun isPinningAppWithContextMenuEnabled(context: TaskbarActivityContext): Boolean =
|
||||
DesktopExperienceFlags.ENABLE_PINNING_APP_WITH_CONTEXT_MENU.isTrue &&
|
||||
context.isTaskbarShowingDesktopTasks
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,8 @@ public class TaskbarAutohideSuspendController implements
|
||||
public static final int FLAG_AUTOHIDE_SUSPEND_MULTI_INSTANCE_MENU_OPEN = 1 << 7;
|
||||
// User has taskbar overflow open.
|
||||
public static final int FLAG_AUTOHIDE_SUSPEND_TASKBAR_OVERFLOW = 1 << 8;
|
||||
// Growth Framework nudge overlay is open above the Taskbar.
|
||||
public static final int FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN = 1 << 9;
|
||||
|
||||
@IntDef(flag = true, value = {
|
||||
FLAG_AUTOHIDE_SUSPEND_FULLSCREEN,
|
||||
@@ -62,6 +64,7 @@ public class TaskbarAutohideSuspendController implements
|
||||
FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS,
|
||||
FLAG_AUTOHIDE_SUSPEND_MULTI_INSTANCE_MENU_OPEN,
|
||||
FLAG_AUTOHIDE_SUSPEND_TASKBAR_OVERFLOW,
|
||||
FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface AutohideSuspendFlag {}
|
||||
@@ -143,6 +146,8 @@ public class TaskbarAutohideSuspendController implements
|
||||
"FLAG_AUTOHIDE_SUSPEND_MULTI_INSTANCE_MENU_OPEN");
|
||||
appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_TASKBAR_OVERFLOW,
|
||||
"FLAG_AUTOHIDE_SUSPEND_TASKBAR_OVERFLOW");
|
||||
appendFlag(str, flags, FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN,
|
||||
"FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN");
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import com.airbnb.lottie.LottieAnimationView
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.taskbar.TaskbarActivityContext
|
||||
import com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_EDU_OPEN
|
||||
import com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN
|
||||
import com.android.launcher3.taskbar.TaskbarControllers
|
||||
import com.android.launcher3.taskbar.TaskbarControllers.LoggableTaskbarController
|
||||
import com.android.launcher3.views.ActivityContext
|
||||
@@ -148,16 +148,15 @@ class NudgeController(context: Context) : LoggableTaskbarController {
|
||||
false,
|
||||
) as NudgeView
|
||||
|
||||
// TODO: b/411210699 - considering adding a auto hide suspend flag for the nudge.
|
||||
controllers.taskbarAutohideSuspendController.updateFlag(
|
||||
FLAG_AUTOHIDE_SUSPEND_EDU_OPEN,
|
||||
FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN,
|
||||
true,
|
||||
)
|
||||
|
||||
nudgeView.onCloseCallback = {
|
||||
this.nudgeView = null
|
||||
controllers.taskbarAutohideSuspendController.updateFlag(
|
||||
FLAG_AUTOHIDE_SUSPEND_EDU_OPEN,
|
||||
FLAG_AUTOHIDE_SUSPEND_GROWTH_NUDGE_OPEN,
|
||||
false,
|
||||
)
|
||||
controllers.taskbarStashController.updateAndAnimateTransientTaskbar(true)
|
||||
|
||||
+6
-4
@@ -323,11 +323,13 @@ CONTAINER : StatefulContainer<T> {
|
||||
springAnimation =
|
||||
recentsView.runTaskDismissSettlingSpringAnimation(
|
||||
taskBeingDragged,
|
||||
velocity,
|
||||
isDismissing,
|
||||
dismissLength,
|
||||
dismissThreshold,
|
||||
finalPosition,
|
||||
RecentsDismissUtils.DismissedTaskData(
|
||||
startVelocity = velocity,
|
||||
dismissLength = dismissLength,
|
||||
finalPosition = finalPosition,
|
||||
dismissThreshold = dismissThreshold,
|
||||
),
|
||||
/* shouldRemoveTaskView= */ isDismissing,
|
||||
/* isSplitSelection= */ false,
|
||||
)
|
||||
|
||||
@@ -226,6 +226,21 @@ public class QuickstepTestInformationHandler extends TestInformationHandler {
|
||||
resources.getDimensionPixelSize(R.dimen.task_dismiss_detach_threshold));
|
||||
return response;
|
||||
}
|
||||
|
||||
case TestProtocol.REQUEST_TASKBAR_ACTION_CORNER_PADDING: {
|
||||
final Resources resources = mContext.getResources();
|
||||
response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
|
||||
resources.getDimensionPixelSize(
|
||||
R.dimen.transient_taskbar_action_corner_padding));
|
||||
return response;
|
||||
}
|
||||
case TestProtocol.REQUEST_TASKBAR_UNSTASHED_INPUT_AREA: {
|
||||
final Resources resources = mContext.getResources();
|
||||
response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
|
||||
resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_unstash_input_area));
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
return super.call(method, arg, extras);
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.android.quickstep.logging.SettingsChangeLogger;
|
||||
import com.android.quickstep.util.AsyncClockEventDelegate;
|
||||
import com.android.quickstep.util.ContextualSearchHapticManager;
|
||||
import com.android.quickstep.util.ContextualSearchStateManager;
|
||||
import com.android.quickstep.views.RecentsDismissUtils;
|
||||
|
||||
/**
|
||||
* Launcher Quickstep base component for Dagger injection.
|
||||
@@ -79,6 +80,8 @@ public interface QuickstepBaseAppComponent extends LauncherBaseAppComponent {
|
||||
|
||||
RecentsModel getRecentsModel();
|
||||
|
||||
RecentsDismissUtils.Factory getRecentsDismissUtilsFactory();
|
||||
|
||||
SettingsChangeLogger getSettingsChangeLogger();
|
||||
|
||||
SimpleOrientationTouchTransformer getSimpleOrientationTouchTransformer();
|
||||
|
||||
+28
-2
@@ -17,20 +17,26 @@ package com.android.quickstep.inputconsumers;
|
||||
|
||||
import static android.view.MotionEvent.ACTION_MOVE;
|
||||
import static android.view.MotionEvent.INVALID_POINTER_ID;
|
||||
import static android.view.RoundedCorner.POSITION_BOTTOM_LEFT;
|
||||
import static android.view.RoundedCorner.POSITION_BOTTOM_RIGHT;
|
||||
|
||||
import static com.android.launcher3.Flags.enableCursorHoverStates;
|
||||
import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation;
|
||||
import static com.android.launcher3.MotionEventsUtils.isTrackpadMotionEvent;
|
||||
import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_TOUCHING;
|
||||
import static com.android.systemui.shared.Flags.cursorHotCorner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.Display;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.RoundedCorner;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
@@ -62,7 +68,9 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer {
|
||||
|
||||
private final TaskbarActivityContext mTaskbarActivityContext;
|
||||
private final OverviewCommandHelper mOverviewCommandHelper;
|
||||
private final DisplayManager mDisplayManager;
|
||||
private final float mUnstashArea;
|
||||
private final int mActionCornerPadding;
|
||||
private final int mTaskbarNavThreshold;
|
||||
private final int mTaskbarNavThresholdY;
|
||||
private final boolean mIsTaskbarAllAppsOpen;
|
||||
@@ -100,10 +108,13 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer {
|
||||
mTaskbarActivityContext = taskbarActivityContext;
|
||||
mIsTransientTaskbar = DisplayController.isTransientTaskbar(context);
|
||||
mOverviewCommandHelper = overviewCommandHelper;
|
||||
mDisplayManager = context.getSystemService(DisplayManager.class);
|
||||
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
|
||||
Resources res = context.getResources();
|
||||
mUnstashArea = res.getDimensionPixelSize(R.dimen.taskbar_unstash_input_area);
|
||||
mActionCornerPadding = res.getDimensionPixelSize(
|
||||
R.dimen.transient_taskbar_action_corner_padding);
|
||||
|
||||
boolean pinnedTaskbarWithAutoStashing =
|
||||
mTaskbarActivityContext.shouldAllowTaskbarToAutoStash() && !mIsTransientTaskbar;
|
||||
@@ -284,7 +295,7 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer {
|
||||
if (mIsStashedTaskbarHovered) {
|
||||
updateHoveredTaskbarState((int) ev.getX(), (int) ev.getY());
|
||||
} else {
|
||||
updateUnhoveredTaskbarState((int) ev.getX(), (int) ev.getY());
|
||||
updateUnhoveredTaskbarState((int) ev.getX(), (int) ev.getY(), ev.getDisplayId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +324,7 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUnhoveredTaskbarState(int x, int y) {
|
||||
private void updateUnhoveredTaskbarState(int x, int y, int displayId) {
|
||||
sUnstashHandler.removeCallbacksAndMessages(null);
|
||||
|
||||
DeviceProfile dp = mTaskbarActivityContext.getDeviceProfile();
|
||||
@@ -323,6 +334,21 @@ public class TaskbarUnstashInputConsumer extends DelegateInputConsumer {
|
||||
dp.widthPx,
|
||||
dp.heightPx);
|
||||
|
||||
if (cursorHotCorner() && mDisplayManager != null) {
|
||||
Display display = mDisplayManager.getDisplay(displayId);
|
||||
if (display != null) {
|
||||
RoundedCorner leftBottomCorner = display.getRoundedCorner(POSITION_BOTTOM_LEFT);
|
||||
int leftCornerRadius =
|
||||
leftBottomCorner == null ? 0 : leftBottomCorner.getRadius();
|
||||
RoundedCorner rightBottomCorner = display.getRoundedCorner(
|
||||
POSITION_BOTTOM_RIGHT);
|
||||
int rightCornerRadius =
|
||||
rightBottomCorner == null ? 0 : rightBottomCorner.getRadius();
|
||||
mBottomEdgeBounds.inset(leftCornerRadius + mActionCornerPadding, 0,
|
||||
rightCornerRadius + mActionCornerPadding, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (isStashedTaskbarHovered(x, y)) {
|
||||
// If enter hovering stashed taskbar, start hint.
|
||||
startStashedTaskbarHover(/* isHovered = */ true);
|
||||
|
||||
@@ -323,10 +323,10 @@ public class BaseDepthController {
|
||||
// Only blur workspace if the current state wants to blur based on the target state.
|
||||
boolean shouldBlurWorkspace =
|
||||
stateManager.getCurrentStableState().shouldBlurWorkspace(stateManager.getState());
|
||||
// If blur is not desired, apply 0 blur to force reset.
|
||||
int blurRadius = shouldBlurWorkspace ? mCurrentBlur : 0;
|
||||
RenderEffect blurEffect =
|
||||
RenderEffect.createBlurEffect(blurRadius, blurRadius, Shader.TileMode.DECAL);
|
||||
RenderEffect blurEffect = shouldBlurWorkspace && mCurrentBlur > 0
|
||||
? RenderEffect.createBlurEffect(mCurrentBlur, mCurrentBlur, Shader.TileMode.DECAL)
|
||||
// If blur is not desired, clear the blur effect from the depth targets.
|
||||
: null;
|
||||
mLauncher.getDepthBlurTargets().forEach(target -> target.setRenderEffect(blurEffect));
|
||||
return shouldBlurWorkspace;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.quickstep.util
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Typeface
|
||||
import com.android.wm.shell.shared.TypefaceUtils
|
||||
|
||||
object FontUtils {
|
||||
|
||||
private val baseTypeface =
|
||||
Typeface.create(TypefaceUtils.FontFamily.GSF_LABEL_LARGE.value, Typeface.NORMAL)
|
||||
|
||||
@JvmStatic
|
||||
fun getTypeFace(resources: Resources): Typeface =
|
||||
Typeface.create(baseTypeface, getFontWeight(resources), /* italic= */ false)
|
||||
|
||||
fun getFontWeight(resources: Resources): Int {
|
||||
val fontWeightAdjustment: Int = resources.configuration.fontWeightAdjustment
|
||||
return if (fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED) {
|
||||
Typeface.Builder.NORMAL_WEIGHT + fontWeightAdjustment
|
||||
} else {
|
||||
Typeface.Builder.NORMAL_WEIGHT
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,16 +27,24 @@ import androidx.dynamicanimation.animation.SpringForce
|
||||
import com.android.internal.jank.Cuj
|
||||
import com.android.launcher3.PagedView
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.concurrent.annotations.LightweightBackground
|
||||
import com.android.launcher3.concurrent.annotations.LightweightBackgroundPriority
|
||||
import com.android.launcher3.logging.StatsLogManager.LauncherEvent
|
||||
import com.android.launcher3.util.DynamicResource
|
||||
import com.android.launcher3.util.MSDLPlayerWrapper
|
||||
import com.android.launcher3.util.OverviewReleaseFlags.enableGridOnlyOverview
|
||||
import com.android.launcher3.views.ActivityContext
|
||||
import com.android.quickstep.SystemUiProxy
|
||||
import com.android.quickstep.util.TaskGridNavHelper
|
||||
import com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY
|
||||
import com.android.quickstep.views.TaskView.Companion.GRID_END_TRANSLATION_X
|
||||
import com.android.systemui.shared.system.ActivityManagerWrapper
|
||||
import com.android.systemui.shared.system.InteractionJankMonitorWrapper
|
||||
import com.google.android.msdl.data.model.MSDLToken
|
||||
import com.google.common.util.concurrent.ListeningExecutorService
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
@@ -46,7 +54,20 @@ import kotlin.math.sign
|
||||
* Helper class for [RecentsView]. This util class contains refactored and extracted functions from
|
||||
* RecentsView related to TaskView dismissal.
|
||||
*/
|
||||
class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
class RecentsDismissUtils
|
||||
@AssistedInject
|
||||
constructor(
|
||||
@Assisted private val recentsView: RecentsView<*, *>,
|
||||
private val systemUiProxy: SystemUiProxy,
|
||||
@LightweightBackground(LightweightBackgroundPriority.UI)
|
||||
private val uiHelperExecutor: ListeningExecutorService,
|
||||
private val activityManagerWrapper: ActivityManagerWrapper,
|
||||
private val msdlPlayerWrapper: MSDLPlayerWrapper,
|
||||
) {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(recentsView: RecentsView<*, *>): RecentsDismissUtils
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the default spring animation when a dismissed task view in overview is released.
|
||||
@@ -60,44 +81,27 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
shouldRemoveTaskView: Boolean,
|
||||
isSplitSelection: Boolean,
|
||||
): SpringSet? {
|
||||
with(recentsView) {
|
||||
if (dismissedTaskView == null || isSplitSelection) {
|
||||
return createTaskDismissSpringAnimation(
|
||||
dismissedTaskView,
|
||||
velocity = 0f,
|
||||
isDismissing = true,
|
||||
if (dismissedTaskView == null || isSplitSelection) {
|
||||
return createTaskDismissSpringAnimation(
|
||||
dismissedTaskView,
|
||||
isDismissing = true,
|
||||
DismissedTaskData(
|
||||
startVelocity = 0f,
|
||||
dismissLength = 0,
|
||||
dismissThreshold = 0,
|
||||
finalPosition = 0f,
|
||||
shouldRemoveTaskView,
|
||||
isSplitSelection,
|
||||
)
|
||||
}
|
||||
|
||||
dismissedTaskView.getThumbnailBounds(mTempRect, /* relativeToDragLayer= */ true)
|
||||
val secondaryLayerDimension: Int =
|
||||
pagedOrientationHandler.getSecondaryDimension(
|
||||
(mContainer as ActivityContext).getDragLayer()
|
||||
)
|
||||
val verticalFactor = pagedOrientationHandler.getTaskDismissVerticalDirection().toFloat()
|
||||
val dismissLength =
|
||||
(pagedOrientationHandler.getTaskDismissLength(secondaryLayerDimension, mTempRect) *
|
||||
verticalFactor)
|
||||
.toInt()
|
||||
val dismissThreshold = (dismissLength * DEFAULT_DISMISS_THRESHOLD_FRACTION).toInt()
|
||||
val velocity = mTempRect.height().toFloat()
|
||||
val finalPosition = dismissLength.toFloat()
|
||||
return createTaskDismissSpringAnimation(
|
||||
dismissedTaskView,
|
||||
velocity,
|
||||
isDismissing = true,
|
||||
dismissLength,
|
||||
dismissThreshold,
|
||||
finalPosition,
|
||||
),
|
||||
shouldRemoveTaskView,
|
||||
isSplitSelection,
|
||||
)
|
||||
}
|
||||
return createTaskDismissSpringAnimation(
|
||||
dismissedTaskView,
|
||||
isDismissing = true,
|
||||
getDefaultDismissedTaskData(dismissedTaskView),
|
||||
shouldRemoveTaskView,
|
||||
isSplitSelection,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,11 +113,8 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
*/
|
||||
fun createTaskDismissSpringAnimation(
|
||||
dismissedTaskView: TaskView?,
|
||||
velocity: Float,
|
||||
isDismissing: Boolean,
|
||||
dismissLength: Int,
|
||||
dismissThreshold: Int,
|
||||
finalPosition: Float,
|
||||
dismissedTaskData: DismissedTaskData,
|
||||
shouldRemoveTaskView: Boolean,
|
||||
isSplitSelection: Boolean,
|
||||
): SpringSet? {
|
||||
@@ -131,7 +132,8 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
val verticalFactor =
|
||||
recentsView.pagedOrientationHandler.getTaskDismissVerticalDirection().toFloat()
|
||||
val startVelocity =
|
||||
abs(velocity).coerceAtLeast(dismissedTaskSecondaryDimension) * velocity.sign
|
||||
abs(dismissedTaskData.startVelocity).coerceAtLeast(dismissedTaskSecondaryDimension) *
|
||||
dismissedTaskData.startVelocity.sign
|
||||
|
||||
// Spring that animates the dismissed task.
|
||||
val dismissedTaskViewSpring =
|
||||
@@ -140,15 +142,18 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
createDismissedTaskViewSpringAnimation(
|
||||
dismissedTaskView,
|
||||
isDismissing,
|
||||
startVelocity,
|
||||
dismissLength,
|
||||
finalPosition,
|
||||
dismissThreshold,
|
||||
DismissedTaskData(
|
||||
startVelocity = startVelocity,
|
||||
dismissLength = dismissedTaskData.dismissLength,
|
||||
finalPosition = dismissedTaskData.finalPosition,
|
||||
dismissThreshold = dismissedTaskData.dismissThreshold,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// SpringSet tracking all dismiss springs before running end-snapping and relayout.
|
||||
var springSet = dismissedTaskViewSpring?.let { SpringSet(it, finalPosition) }
|
||||
var springSet =
|
||||
dismissedTaskViewSpring?.let { SpringSet(it, dismissedTaskData.finalPosition) }
|
||||
|
||||
if (isDismissing) {
|
||||
// The spring set that will reflow the tasks to fill the gap left by the dismissed task.
|
||||
@@ -173,7 +178,7 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
val neighborSettlingSpringSet =
|
||||
createNeighborSettlingSpringSet(dismissedTaskView, isSpringDirectionVertical = true)
|
||||
springSet.playAfterThreshold(
|
||||
driverThreshold = finalPosition,
|
||||
driverThreshold = dismissedTaskData.finalPosition,
|
||||
triggeredSpringSet = neighborSettlingSpringSet,
|
||||
minVelocity = startVelocity,
|
||||
)
|
||||
@@ -209,14 +214,22 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
return springSet.addEndListener(endRunnable).start()
|
||||
}
|
||||
|
||||
/** Default dismissed task view spring animation. */
|
||||
private fun createDismissedTaskViewSpringAnimation(
|
||||
dismissedTaskView: TaskView
|
||||
): SpringAnimation? {
|
||||
return createDismissedTaskViewSpringAnimation(
|
||||
dismissedTaskView,
|
||||
isDismissing = true,
|
||||
getDefaultDismissedTaskData(dismissedTaskView),
|
||||
)
|
||||
}
|
||||
|
||||
/** Dismissed task view spring animation. */
|
||||
private fun createDismissedTaskViewSpringAnimation(
|
||||
dismissedTaskView: TaskView,
|
||||
isDismissing: Boolean,
|
||||
startVelocity: Float,
|
||||
dismissLength: Int,
|
||||
finalPosition: Float,
|
||||
dismissThreshold: Int,
|
||||
dismissedTaskData: DismissedTaskData,
|
||||
): SpringAnimation? {
|
||||
val taskDismissFloatProperty =
|
||||
FloatPropertyCompat.createFloatPropertyCompat(
|
||||
@@ -226,15 +239,19 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
// Animate dismissed task towards dismissal or rest state.
|
||||
val dismissedTaskViewSpringAnimation =
|
||||
SpringAnimation(dismissedTaskView, taskDismissFloatProperty)
|
||||
.setSpring(createExpressiveDismissSpringForce().setFinalPosition(finalPosition))
|
||||
.setStartVelocity(startVelocity)
|
||||
.setSpring(
|
||||
createExpressiveDismissSpringForce()
|
||||
.setFinalPosition(dismissedTaskData.finalPosition)
|
||||
)
|
||||
.setStartVelocity(dismissedTaskData.startVelocity)
|
||||
.addUpdateListener { animation, currentDisplacement, _ ->
|
||||
// Play haptic as task crosses dismiss threshold from above or below.
|
||||
val previousBeyondThreshold = abs(previousDisplacement) >= abs(dismissThreshold)
|
||||
val currentBeyondThreshold = abs(currentDisplacement) >= abs(dismissThreshold)
|
||||
val previousBeyondThreshold =
|
||||
abs(previousDisplacement) >= abs(dismissedTaskData.dismissThreshold)
|
||||
val currentBeyondThreshold =
|
||||
abs(currentDisplacement) >= abs(dismissedTaskData.dismissThreshold)
|
||||
if (previousBeyondThreshold != currentBeyondThreshold) {
|
||||
MSDLPlayerWrapper.INSTANCE.get(recentsView.context)
|
||||
.playToken(MSDLToken.SWIPE_THRESHOLD_INDICATOR)
|
||||
msdlPlayerWrapper.playToken(MSDLToken.SWIPE_THRESHOLD_INDICATOR)
|
||||
}
|
||||
previousDisplacement = currentDisplacement
|
||||
|
||||
@@ -246,13 +263,68 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
recentsView.redrawLiveTile()
|
||||
}
|
||||
// End dismissed task animation once beyond the screen so next animations play.
|
||||
if (isDismissing && abs(currentDisplacement) >= abs(dismissLength)) {
|
||||
if (
|
||||
isDismissing &&
|
||||
abs(currentDisplacement) >= abs(dismissedTaskData.dismissLength)
|
||||
) {
|
||||
(animation as SpringAnimation).skipToEnd()
|
||||
}
|
||||
}
|
||||
return dismissedTaskViewSpringAnimation
|
||||
}
|
||||
|
||||
private fun getDefaultDismissedTaskData(dismissedTaskView: TaskView): DismissedTaskData {
|
||||
with(recentsView) {
|
||||
dismissedTaskView.getThumbnailBounds(mTempRect, /* relativeToDragLayer= */ true)
|
||||
val secondaryLayerDimension =
|
||||
pagedOrientationHandler.getSecondaryDimension(
|
||||
(mContainer as ActivityContext).getDragLayer()
|
||||
)
|
||||
val verticalFactor = pagedOrientationHandler.getTaskDismissVerticalDirection().toFloat()
|
||||
val dismissLength =
|
||||
(pagedOrientationHandler.getTaskDismissLength(secondaryLayerDimension, mTempRect) *
|
||||
verticalFactor)
|
||||
.toInt()
|
||||
val dismissThreshold = (dismissLength * DEFAULT_DISMISS_THRESHOLD_FRACTION).toInt()
|
||||
val startVelocity = mTempRect.height().toFloat()
|
||||
val finalPosition = dismissLength.toFloat()
|
||||
return DismissedTaskData(
|
||||
startVelocity = startVelocity,
|
||||
dismissLength = dismissLength,
|
||||
finalPosition = finalPosition,
|
||||
dismissThreshold = dismissThreshold,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Dismisses all */
|
||||
fun dismissAllTasks() {
|
||||
val allDismissSprings =
|
||||
recentsView.mUtils.taskViews
|
||||
.reversed()
|
||||
.filter { taskView -> recentsView.isTaskViewVisible(taskView) }
|
||||
.mapNotNull { createDismissedTaskViewSpringAnimation(it) }
|
||||
SpringSet(SpringAnimation(FloatValueHolder()).setSpring(SpringForce(1f)))
|
||||
.playTogether(allDismissSprings)
|
||||
.addEndListener {
|
||||
with(recentsView) {
|
||||
// Remove desktops first, since desks can be empty (so they have no recent
|
||||
// tasks), and closing all tasks on a desk doesn't always necessarily mean that
|
||||
// the desk will be removed. So, there are no guarantees that the below call to
|
||||
// `ActivityManagerWrapper::removeAllRecentTasks()` will be enough.
|
||||
systemUiProxy.removeAllDesks()
|
||||
|
||||
// Remove all the task views now
|
||||
finishRecentsAnimation(/* toRecents */ true, /* shouldPip */ false) {
|
||||
uiHelperExecutor.execute { activityManagerWrapper.removeAllRecentTasks() }
|
||||
removeAllTaskViews()
|
||||
startHome()
|
||||
}
|
||||
}
|
||||
}
|
||||
.start()
|
||||
}
|
||||
|
||||
/** Bounce neighboring tasks due to a canceled dismiss or the reflow of tasks after dismiss. */
|
||||
private fun createNeighborSettlingSpringSet(
|
||||
dismissedTaskView: TaskView,
|
||||
@@ -1235,6 +1307,14 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun playTogether(springs: List<SpringAnimation>): SpringSet {
|
||||
springs.forEach {
|
||||
trackSpring(it)
|
||||
addStartListener { it.start() }
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
data class GridEndData(
|
||||
@@ -1244,6 +1324,13 @@ class RecentsDismissUtils(private val recentsView: RecentsView<*, *>) {
|
||||
val currentPageSnapsToEndOfGrid: Boolean,
|
||||
)
|
||||
|
||||
data class DismissedTaskData(
|
||||
val startVelocity: Float,
|
||||
val dismissLength: Int,
|
||||
val finalPosition: Float,
|
||||
val dismissThreshold: Int,
|
||||
)
|
||||
|
||||
private companion object {
|
||||
// The additional damping to apply to tasks further from the dismissed task.
|
||||
private const val ADDITIONAL_DISMISS_DAMPING_RATIO = 0.15f
|
||||
|
||||
@@ -157,6 +157,7 @@ import com.android.launcher3.anim.PendingAnimation;
|
||||
import com.android.launcher3.anim.SpringProperty;
|
||||
import com.android.launcher3.compat.AccessibilityManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dagger.LauncherComponentProvider;
|
||||
import com.android.launcher3.desktop.DesktopRecentsTransitionController;
|
||||
import com.android.launcher3.logger.LauncherAtom;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
@@ -217,6 +218,7 @@ import com.android.quickstep.recents.viewmodel.RecentsViewModel;
|
||||
import com.android.quickstep.util.ActiveGestureProtoLogProxy;
|
||||
import com.android.quickstep.util.AnimUtils;
|
||||
import com.android.quickstep.util.DesktopTask;
|
||||
import com.android.quickstep.util.FontUtils;
|
||||
import com.android.quickstep.util.GroupTask;
|
||||
import com.android.quickstep.util.LayoutUtils;
|
||||
import com.android.quickstep.util.RecentsAtomicAnimationFactory;
|
||||
@@ -873,7 +875,8 @@ public abstract class RecentsView<
|
||||
protected final RecentsViewModel mRecentsViewModel;
|
||||
private final RecentsViewModelHelper mHelper;
|
||||
protected final RecentsViewUtils mUtils = new RecentsViewUtils(this);
|
||||
protected final RecentsDismissUtils mDismissUtils = new RecentsDismissUtils(this);
|
||||
protected final RecentsDismissUtils mDismissUtils = LauncherComponentProvider.get(
|
||||
getContext()).getRecentsDismissUtilsFactory().create(this);
|
||||
|
||||
private final Matrix mTmpMatrix = new Matrix();
|
||||
|
||||
@@ -983,12 +986,7 @@ public abstract class RecentsView<
|
||||
|
||||
mEmptyMessagePaint.setTextSize(getResources()
|
||||
.getDimension(R.dimen.recents_empty_message_text_size));
|
||||
Typeface typeface = Typeface.create(
|
||||
Typeface.create(TypefaceUtils.FontFamily.GSF_LABEL_LARGE.getValue(),
|
||||
Typeface.NORMAL),
|
||||
getFontWeight(),
|
||||
false);
|
||||
mEmptyMessagePaint.setTypeface(typeface);
|
||||
mEmptyMessagePaint.setTypeface(FontUtils.getTypeFace(getResources()));
|
||||
mEmptyMessagePaint.setAntiAlias(true);
|
||||
mEmptyMessagePadding = getResources()
|
||||
.getDimensionPixelSize(R.dimen.recents_empty_message_text_padding);
|
||||
@@ -2191,7 +2189,7 @@ public abstract class RecentsView<
|
||||
return mModel.isLoadingTasksInBackground();
|
||||
}
|
||||
|
||||
private void removeAllTaskViews() {
|
||||
protected void removeAllTaskViews() {
|
||||
// This handles an edge case where applyLoadPlan happens during a gesture when the only
|
||||
// Task is one with excludeFromRecents, in which case we should not remove it.
|
||||
CollectionsKt
|
||||
@@ -2955,7 +2953,8 @@ public abstract class RecentsView<
|
||||
}
|
||||
|
||||
private void animateRecentsRotationInPlace(int newRotation) {
|
||||
if (mOrientationState.isRecentsActivityRotationAllowed()) {
|
||||
if (mOrientationState.isRecentsActivityRotationAllowed()
|
||||
|| mOrientationState.isLauncherFixedLandscape()) {
|
||||
// Let system take care of the rotation
|
||||
return;
|
||||
}
|
||||
@@ -4571,7 +4570,11 @@ public abstract class RecentsView<
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void dismissAllTasks(View view) {
|
||||
runDismissAnimation(createAllTasksDismissAnimation(DISMISS_TASK_DURATION));
|
||||
if (enableExpressiveDismissTaskMotion()) {
|
||||
mDismissUtils.dismissAllTasks();
|
||||
} else {
|
||||
runDismissAnimation(createAllTasksDismissAnimation(DISMISS_TASK_DURATION));
|
||||
}
|
||||
mContainer.getStatsLogManager().logger().log(LAUNCHER_TASK_CLEAR_ALL);
|
||||
}
|
||||
|
||||
@@ -7006,14 +7009,6 @@ public abstract class RecentsView<
|
||||
}
|
||||
}
|
||||
|
||||
private int getFontWeight() {
|
||||
int fontWeightAdjustment = getResources().getConfiguration().fontWeightAdjustment;
|
||||
if (fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED) {
|
||||
return Typeface.Builder.NORMAL_WEIGHT + fontWeightAdjustment;
|
||||
}
|
||||
return Typeface.Builder.NORMAL_WEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the spring animations as a task dismisses or settles back into its place in overview.
|
||||
*
|
||||
@@ -7022,12 +7017,11 @@ public abstract class RecentsView<
|
||||
* spring in response to the perceived impact of the settling task.
|
||||
*/
|
||||
public RecentsDismissUtils.SpringSet runTaskDismissSettlingSpringAnimation(
|
||||
TaskView draggedTaskView, float velocity, boolean isDismissing, int dismissLength,
|
||||
int dismissThreshold, float finalPosition, boolean shouldRemoveTaskView,
|
||||
TaskView draggedTaskView, boolean isDismissing,
|
||||
RecentsDismissUtils.DismissedTaskData dismissedTaskData, boolean shouldRemoveTaskView,
|
||||
boolean isSplitSelection) {
|
||||
return mDismissUtils.createTaskDismissSpringAnimation(draggedTaskView, velocity,
|
||||
isDismissing, dismissLength, dismissThreshold, finalPosition, shouldRemoveTaskView,
|
||||
isSplitSelection);
|
||||
return mDismissUtils.createTaskDismissSpringAnimation(draggedTaskView, isDismissing,
|
||||
dismissedTaskData, shouldRemoveTaskView, isSplitSelection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -954,7 +954,9 @@ constructor(
|
||||
// onAttach or another moment in the lifecycle.
|
||||
val coroutineJobsToCancel = coroutineJobs.toList()
|
||||
coroutineJobs.clear()
|
||||
if (enableCoroutineThreadingImprovements() && coroutineJobsToCancel.isNotEmpty()) {
|
||||
if (coroutineJobsToCancel.isEmpty()) return
|
||||
|
||||
if (enableCoroutineThreadingImprovements()) {
|
||||
// TODO(b/391842220): This should ideally be handled in the completion block of the
|
||||
// jobs above to be cancelled.
|
||||
taskContainers.forEach {
|
||||
|
||||
-14
@@ -21,13 +21,11 @@ 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.dx.mockito.inline.extended.ExtendedMockito.mockitoSession
|
||||
import com.android.launcher3.util.DaggerSingletonTracker
|
||||
import com.android.quickstep.SystemUiProxy
|
||||
import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND
|
||||
import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_FRONTEND
|
||||
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@@ -35,7 +33,6 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.mockito.quality.Strictness
|
||||
|
||||
/**
|
||||
* Tests the behavior of [DesktopVisibilityController] in regards to multiple desktops and multiple
|
||||
@@ -47,12 +44,6 @@ class DesktopVisibilityControllerTest {
|
||||
|
||||
@get:Rule val setFlagsRule = SetFlagsRule()
|
||||
|
||||
private val mockitoSession =
|
||||
mockitoSession()
|
||||
.strictness(Strictness.LENIENT)
|
||||
.mockStatic(DesktopModeStatus::class.java)
|
||||
.startMocking()
|
||||
|
||||
private val context = mock<Context>()
|
||||
private val systemUiProxy = mock<SystemUiProxy>()
|
||||
private val lifeCycleTracker = mock<DaggerSingletonTracker>()
|
||||
@@ -66,11 +57,6 @@ class DesktopVisibilityControllerTest {
|
||||
DesktopVisibilityController(context, systemUiProxy, lifeCycleTracker)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockitoSession.finishMocking()
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, FLAG_ENABLE_MULTIPLE_DESKTOPS_FRONTEND)
|
||||
fun noCrashWhenCheckingNonExistentDisplay() {
|
||||
+3
-3
@@ -20,6 +20,7 @@ import android.content.Intent
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.app.displaylib.DisplayRepository
|
||||
import com.android.app.displaylib.fakes.FakePerDisplayRepository
|
||||
import com.android.app.displaylib.PerDisplayRepository
|
||||
import com.android.launcher3.LauncherState
|
||||
import com.android.launcher3.statemanager.StateManager
|
||||
@@ -96,8 +97,6 @@ class OverviewCommandHelperTest {
|
||||
whenever(overviewComponentObserver.getHomeIntent(any())).thenReturn(mock<Intent>())
|
||||
whenever(recentView.getStateManager()).thenReturn(stateManager)
|
||||
whenever(containerInterface.switchToRecentsIfVisible(any())).thenReturn(true)
|
||||
val taskAnimationManagerRepository = mock<PerDisplayRepository<TaskAnimationManager>>()
|
||||
whenever(taskAnimationManagerRepository.get(any())).thenReturn(taskAnimationManager)
|
||||
whenever(taskAnimationManager.maybeStartHomeAction(any())).thenAnswer { invocation ->
|
||||
invocation.getArgument<Runnable>(0).run()
|
||||
}
|
||||
@@ -110,7 +109,8 @@ class OverviewCommandHelperTest {
|
||||
dispatcherProvider = TestDispatcherProvider(dispatcher),
|
||||
displayRepository = displayRepository,
|
||||
taskbarManager = mock(),
|
||||
taskAnimationManagerRepository = taskAnimationManagerRepository,
|
||||
taskAnimationManagerRepository =
|
||||
FakePerDisplayRepository<TaskAnimationManager> { _ -> taskAnimationManager },
|
||||
elapsedRealtime = ::elapsedRealtime,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -102,7 +102,10 @@ public class DigitalWellBeingToastTest extends BaseLauncherActivityTest<Quickste
|
||||
|
||||
private DigitalWellBeingToast getToast() {
|
||||
getLauncherActivity().goToState(LauncherState.OVERVIEW);
|
||||
final TaskView task = getOnceNotNull("No latest task", launcher -> getLatestTask(launcher));
|
||||
final TaskView task = getLauncherActivity().getOnceNotNull(
|
||||
"No latest task",
|
||||
launcher -> getLatestTask(launcher)
|
||||
);
|
||||
|
||||
return getLauncherActivity().getFromLauncher(launcher -> {
|
||||
TaskContainer taskContainer = task.getFirstTaskContainer();
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.quickstep;
|
||||
import static com.android.launcher3.Flags.enableCursorHoverStates;
|
||||
import static com.android.launcher3.util.TestConstants.AppNames.TEST_APP_NAME;
|
||||
import static com.android.quickstep.TaskbarModeSwitchRule.Mode.TRANSIENT;
|
||||
import static com.android.systemui.shared.Flags.cursorHotCorner;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@@ -41,14 +42,6 @@ public class TaplTestsTransientTaskbar extends AbstractTaplTestsTaskbar {
|
||||
mLauncher.getLaunchedAppState().hoverToShowTaskbarUnstashHint();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TaskbarModeSwitch(mode = TRANSIENT)
|
||||
public void testUnstashTaskbarOnScreenBottomEdgeHover() {
|
||||
assumeTrue(enableCursorHoverStates());
|
||||
getTaskbar().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
|
||||
mLauncher.getLaunchedAppState().hoverScreenBottomEdgeToUnstashTaskbar();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TaskbarModeSwitch(mode = TRANSIENT)
|
||||
public void testHoverBelowHintedTaskbarToUnstash() {
|
||||
@@ -71,4 +64,31 @@ public class TaplTestsTransientTaskbar extends AbstractTaplTestsTaskbar {
|
||||
getTaskbar().swipeDownToStash();
|
||||
mLauncher.getLaunchedAppState().swipeUpToUnstashTaskbar();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TaskbarModeSwitch(mode = TRANSIENT)
|
||||
public void testUnstashTaskbarOnScreenBottomEdgeHover() {
|
||||
assumeTrue(enableCursorHoverStates());
|
||||
getTaskbar().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
|
||||
mLauncher.getLaunchedAppState().hoverScreenBottomEdgeToUnstashTaskbar();
|
||||
mLauncher.getLaunchedAppState().assertTaskbarVisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TaskbarModeSwitch(mode = TRANSIENT)
|
||||
public void testUnstashTaskbarOnScreenBottomEdgeOutsideActionCornerHover() {
|
||||
assumeTrue(cursorHotCorner());
|
||||
getTaskbar().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
|
||||
mLauncher.getLaunchedAppState().hoverScreenBottomEdgeOutsideActionCornerToUnstashTaskbar();
|
||||
mLauncher.getLaunchedAppState().assertTaskbarVisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TaskbarModeSwitch(mode = TRANSIENT)
|
||||
public void testNotShowTaskbarOnActionCornerPaddingHover() {
|
||||
assumeTrue(cursorHotCorner());
|
||||
getTaskbar().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
|
||||
mLauncher.getLaunchedAppState().hoverScreenBottomCornerToTryUnstashTaskbar();
|
||||
mLauncher.getLaunchedAppState().assertTaskbarHidden();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="@dimen/horizontal_ellipsis_size"
|
||||
android:height="@dimen/horizontal_ellipsis_size"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?android:attr/textColorSecondary" >
|
||||
|
||||
<path
|
||||
android:pathData="M6 10c-1.1 0-2 0.9-2 2s0.9 2 2 2 2-0.9 2-2-0.9-2-2-2zm12 0c-1.1 0-2 0.9-2 2s0.9 2 2 2 2-0.9 2-2-0.9-2-2-2zm-6 0c-1.1 0-2 0.9-2 2s0.9 2 2 2 2-0.9 2-2-0.9-2-2-2z"
|
||||
android:fillColor="@android:color/white" />
|
||||
</vector>
|
||||
@@ -138,7 +138,8 @@
|
||||
<string name="allow_rotation_title" msgid="7222049633713050106">"Laat toe dat tuisskerm gedraai word"</string>
|
||||
<string name="allow_rotation_desc" msgid="8662546029078692509">"Wanneer foon gedraai word"</string>
|
||||
<string name="landscape_mode_title" msgid="5138814555934843926">"Landskapmodus"</string>
|
||||
<string name="landscape_mode_desc" msgid="7372569859592816793">"Stel foon op landskapmodus"</string>
|
||||
<!-- no translation found for landscape_mode_desc (3085236452297838664) -->
|
||||
<skip />
|
||||
<string name="notification_dots_title" msgid="9062440428204120317">"Kennisgewingkolle"</string>
|
||||
<string name="notification_dots_desc_on" msgid="1679848116452218908">"Aan"</string>
|
||||
<string name="notification_dots_desc_off" msgid="1760796511504341095">"Af"</string>
|
||||
|
||||
@@ -138,7 +138,8 @@
|
||||
<string name="allow_rotation_title" msgid="7222049633713050106">"የመነሻ ማያ ገፅ ማሽከርከርን ይፍቀዱ"</string>
|
||||
<string name="allow_rotation_desc" msgid="8662546029078692509">"ስልኩ ሲዞር"</string>
|
||||
<string name="landscape_mode_title" msgid="5138814555934843926">"የመሬት አቀማመጥ ሁኔታ"</string>
|
||||
<string name="landscape_mode_desc" msgid="7372569859592816793">"ስልክን ወደ የመሬት አቀማመጥ ሁኔታ ያቀናብሩ"</string>
|
||||
<!-- no translation found for landscape_mode_desc (3085236452297838664) -->
|
||||
<skip />
|
||||
<string name="notification_dots_title" msgid="9062440428204120317">"የማሳወቂያ ነጥቦች"</string>
|
||||
<string name="notification_dots_desc_on" msgid="1679848116452218908">"አብራ"</string>
|
||||
<string name="notification_dots_desc_off" msgid="1760796511504341095">"ጠፍቷል"</string>
|
||||
|
||||
Loaded 100 of 196 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user