Loading widgetpickerlib/Android.bp +34 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,16 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } min_widget_picker_sdk_version = "31" // same as launcher3 android_library { name: "widget_picker_dagger_annotations", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/WidgetPickerSingleton.kt", ], static_libs: [ "androidx.annotation_annotation", "jsr330", Loading @@ -30,6 +35,8 @@ android_library { android_library { name: "widget_picker_component", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/WidgetPickerModule.kt", "src/com/android/widgetpicker/WidgetPickerComponent.kt", Loading @@ -43,6 +50,8 @@ android_library { // Data types that are accessible & potentially provided by hosts using the widget picker library android_library { name: "widget_picker_shared_data_types", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/shared/model/PickableWidget.kt", "src/com/android/widgetpicker/shared/model/WidgetAppIcon.kt", Loading @@ -51,10 +60,16 @@ android_library { "src/com/android/widgetpicker/shared/model/WidgetPreview.kt", "src/com/android/widgetpicker/shared/model/WidgetUserProfiles.kt", ], static_libs: [ "androidx.core_core-ktx", "androidx.annotation_annotation", ], } android_library { name: "widget_picker_data_repositories", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/data/repository/WidgetAppIconsRepository.kt", "src/com/android/widgetpicker/data/repository/WidgetPreviewRepository.kt", Loading @@ -67,5 +82,24 @@ android_library { "kotlinx_coroutines_android", "kotlinx_coroutines", ], } android_library { name: "widget_picker_ui_components", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/ui/components/ScrollableFloatingToolbar.kt", "src/com/android/widgetpicker/ui/components/LeadingIconToolbarTab.kt", ], static_libs: [ "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", ], } widgetpickerlib/TEST_MAPPING 0 → 100644 +7 −0 Original line number Diff line number Diff line { "presubmit": [ { "name": "WidgetPickerLibScreenshotTests" } ] } No newline at end of file widgetpickerlib/build.gradle.kts +67 −0 Original line number Diff line number Diff line Loading @@ -18,22 +18,89 @@ plugins { id(libs.plugins.android.library.get().pluginId) id(libs.plugins.kotlin.android.get().pluginId) id(libs.plugins.kotlin.kapt.get().pluginId) id(libs.plugins.compose.compiler.get().pluginId) } apply<ResourceFixerPlugin>() val androidTop = extra["ANDROID_TOP"].toString() val robolibBuildDir = project(":RobolectricLib").layout.buildDirectory.toString() android.buildFeatures.compose = true android { namespace = "com.android.widgetpicker" testNamespace = "com.android.widgetpicker.tests" defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testApplicationId = "com.android.widgetpicker.tests" } sourceSets { named("main") { java.setSrcDirs(listOf("src")) manifest.srcFile("AndroidManifest.xml") res.setSrcDirs(listOf("res")) } named("androidTest") { java.setSrcDirs(listOf("tests/multivalentScreenshotTests/src/")) manifest.srcFile("tests/AndroidManifest.xml") } } signingConfigs { getByName("debug") { // This is necessary or the private APIs from the studiow-generate SDK won't work. // Without the platform keystore, it will crash with: // "java.lang.NoSuchMethodError: No static method asyncTraceForTrackBegin" storeFile = file("$androidTop/vendor/google/certs/devkeys/platform.keystore") } } testOptions { unitTests { isIncludeAndroidResources = true } } // Exclude META-INF for running test with android studio packagingOptions.resources.excludes.add("META-INF/versions/9/OSGI-INF/MANIFEST.MF") } dependencies { implementation(libs.androidx.core) implementation(libs.dagger) kapt(libs.dagger.compiler) kapt(libs.dagger.android.processor) // Compose UI dependencies implementation(libs.compose.ui) implementation(libs.compose.runtime) implementation(libs.compose.foundation.layout) implementation(libs.compose.material3) // Compose android studio preview support implementation(libs.compose.material.icons.extended) implementation(libs.compose.ui.tooling.preview) debugImplementation(libs.compose.ui.tooling) // Testing // this needs to be modern to support JDK-17 + asm byte code. testImplementation(libs.mockito.robolectric.bytebuddy.agent) testImplementation(libs.mockito.robolectric.bytebuddy) testImplementation(libs.mockito.robolectric) 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) // Compose UI Tests androidTestApi(libs.compose.ui.test.junit4) debugApi(libs.compose.ui.test.manifest) // Shared testing libs testImplementation(project(":RobolectricLib")) androidTestImplementation(project(":SharedTestLib")) androidTestImplementation(project(":PlatformParameterizedLib")) androidTestImplementation(project(":ScreenshotLib")) androidTestImplementation(project(":ScreenshotComposeLib")) } widgetpickerlib/src/com/android/widgetpicker/shared/model/WidgetAppIcon.kt +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.widgetpicker.shared.model import android.annotation.DrawableRes import androidx.annotation.DrawableRes import android.graphics.Bitmap /** Loading widgetpickerlib/src/com/android/widgetpicker/ui/components/LeadingIconToolbarTab.kt 0 → 100644 +115 −0 Original line number Diff line number Diff line /* * 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.widgetpicker.ui.components import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition import androidx.compose.animation.expandIn 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.shape.CircleShape import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.dp /** * A tab (suitable for displaying in a horizontal toolbar) that shows a leading icon along with its * label. * * The icon is shown only when tab is selected (it animates per the provided transition spec.) */ @Composable fun LeadingIconToolbarTab( leadingIcon: ImageVector, label: String, selected: Boolean, onClick: () -> Unit, selectedBackgroundColor: Color = LeadingIconToolbarTabDefaults.selectedBackgroundColor, contentColor: Color = LeadingIconToolbarTabDefaults.contentColor, textStyle: TextStyle = LeadingIconToolbarTabDefaults.textStyle, iconEnterTransition: EnterTransition = LeadingIconToolbarTabDefaults.iconEnterTransition, iconExitTransition: ExitTransition = LeadingIconToolbarTabDefaults.iconExitTransition ) { val backgroundColor = if (selected) { selectedBackgroundColor } else { Color.Transparent } Row( modifier = Modifier .fillMaxWidth() .clip(CircleShape) .background(color = backgroundColor) .minimumInteractiveComponentSize() .padding(horizontal = LeadingIconToolbarTabDefaults.horizontalPadding) .clickable { onClick() }, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center ) { this@Row.AnimatedVisibility( visible = selected, enter = iconEnterTransition, exit = iconExitTransition ) { Icon( imageVector = leadingIcon, contentDescription = null, // decorative modifier = Modifier.padding(end = LeadingIconToolbarTabDefaults.contentSpacing), tint = contentColor ) } Text( text = label, style = textStyle, color = contentColor ) } } /** Holds default values used by the [LeadingIconToolbarTab]. */ object LeadingIconToolbarTabDefaults { val selectedBackgroundColor: Color @Composable get() = MaterialTheme.colorScheme.secondaryContainer val contentColor: Color @Composable get() = MaterialTheme.colorScheme.onSecondaryContainer val textStyle: TextStyle @Composable get() = MaterialTheme.typography.labelLarge val horizontalPadding = 16.dp val contentSpacing = 8.dp val iconEnterTransition: EnterTransition = fadeIn() + expandIn(expandFrom = Alignment.Center) val iconExitTransition: ExitTransition = fadeOut() + shrinkOut(shrinkTowards = Alignment.Center) } Loading
widgetpickerlib/Android.bp +34 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,16 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } min_widget_picker_sdk_version = "31" // same as launcher3 android_library { name: "widget_picker_dagger_annotations", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/WidgetPickerSingleton.kt", ], static_libs: [ "androidx.annotation_annotation", "jsr330", Loading @@ -30,6 +35,8 @@ android_library { android_library { name: "widget_picker_component", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/WidgetPickerModule.kt", "src/com/android/widgetpicker/WidgetPickerComponent.kt", Loading @@ -43,6 +50,8 @@ android_library { // Data types that are accessible & potentially provided by hosts using the widget picker library android_library { name: "widget_picker_shared_data_types", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/shared/model/PickableWidget.kt", "src/com/android/widgetpicker/shared/model/WidgetAppIcon.kt", Loading @@ -51,10 +60,16 @@ android_library { "src/com/android/widgetpicker/shared/model/WidgetPreview.kt", "src/com/android/widgetpicker/shared/model/WidgetUserProfiles.kt", ], static_libs: [ "androidx.core_core-ktx", "androidx.annotation_annotation", ], } android_library { name: "widget_picker_data_repositories", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/data/repository/WidgetAppIconsRepository.kt", "src/com/android/widgetpicker/data/repository/WidgetPreviewRepository.kt", Loading @@ -67,5 +82,24 @@ android_library { "kotlinx_coroutines_android", "kotlinx_coroutines", ], } android_library { name: "widget_picker_ui_components", sdk_version: "current", min_sdk_version: min_widget_picker_sdk_version, srcs: [ "src/com/android/widgetpicker/ui/components/ScrollableFloatingToolbar.kt", "src/com/android/widgetpicker/ui/components/LeadingIconToolbarTab.kt", ], static_libs: [ "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", ], }
widgetpickerlib/TEST_MAPPING 0 → 100644 +7 −0 Original line number Diff line number Diff line { "presubmit": [ { "name": "WidgetPickerLibScreenshotTests" } ] } No newline at end of file
widgetpickerlib/build.gradle.kts +67 −0 Original line number Diff line number Diff line Loading @@ -18,22 +18,89 @@ plugins { id(libs.plugins.android.library.get().pluginId) id(libs.plugins.kotlin.android.get().pluginId) id(libs.plugins.kotlin.kapt.get().pluginId) id(libs.plugins.compose.compiler.get().pluginId) } apply<ResourceFixerPlugin>() val androidTop = extra["ANDROID_TOP"].toString() val robolibBuildDir = project(":RobolectricLib").layout.buildDirectory.toString() android.buildFeatures.compose = true android { namespace = "com.android.widgetpicker" testNamespace = "com.android.widgetpicker.tests" defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testApplicationId = "com.android.widgetpicker.tests" } sourceSets { named("main") { java.setSrcDirs(listOf("src")) manifest.srcFile("AndroidManifest.xml") res.setSrcDirs(listOf("res")) } named("androidTest") { java.setSrcDirs(listOf("tests/multivalentScreenshotTests/src/")) manifest.srcFile("tests/AndroidManifest.xml") } } signingConfigs { getByName("debug") { // This is necessary or the private APIs from the studiow-generate SDK won't work. // Without the platform keystore, it will crash with: // "java.lang.NoSuchMethodError: No static method asyncTraceForTrackBegin" storeFile = file("$androidTop/vendor/google/certs/devkeys/platform.keystore") } } testOptions { unitTests { isIncludeAndroidResources = true } } // Exclude META-INF for running test with android studio packagingOptions.resources.excludes.add("META-INF/versions/9/OSGI-INF/MANIFEST.MF") } dependencies { implementation(libs.androidx.core) implementation(libs.dagger) kapt(libs.dagger.compiler) kapt(libs.dagger.android.processor) // Compose UI dependencies implementation(libs.compose.ui) implementation(libs.compose.runtime) implementation(libs.compose.foundation.layout) implementation(libs.compose.material3) // Compose android studio preview support implementation(libs.compose.material.icons.extended) implementation(libs.compose.ui.tooling.preview) debugImplementation(libs.compose.ui.tooling) // Testing // this needs to be modern to support JDK-17 + asm byte code. testImplementation(libs.mockito.robolectric.bytebuddy.agent) testImplementation(libs.mockito.robolectric.bytebuddy) testImplementation(libs.mockito.robolectric) 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) // Compose UI Tests androidTestApi(libs.compose.ui.test.junit4) debugApi(libs.compose.ui.test.manifest) // Shared testing libs testImplementation(project(":RobolectricLib")) androidTestImplementation(project(":SharedTestLib")) androidTestImplementation(project(":PlatformParameterizedLib")) androidTestImplementation(project(":ScreenshotLib")) androidTestImplementation(project(":ScreenshotComposeLib")) }
widgetpickerlib/src/com/android/widgetpicker/shared/model/WidgetAppIcon.kt +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.widgetpicker.shared.model import android.annotation.DrawableRes import androidx.annotation.DrawableRes import android.graphics.Bitmap /** Loading
widgetpickerlib/src/com/android/widgetpicker/ui/components/LeadingIconToolbarTab.kt 0 → 100644 +115 −0 Original line number Diff line number Diff line /* * 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.widgetpicker.ui.components import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition import androidx.compose.animation.expandIn 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.shape.CircleShape import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.dp /** * A tab (suitable for displaying in a horizontal toolbar) that shows a leading icon along with its * label. * * The icon is shown only when tab is selected (it animates per the provided transition spec.) */ @Composable fun LeadingIconToolbarTab( leadingIcon: ImageVector, label: String, selected: Boolean, onClick: () -> Unit, selectedBackgroundColor: Color = LeadingIconToolbarTabDefaults.selectedBackgroundColor, contentColor: Color = LeadingIconToolbarTabDefaults.contentColor, textStyle: TextStyle = LeadingIconToolbarTabDefaults.textStyle, iconEnterTransition: EnterTransition = LeadingIconToolbarTabDefaults.iconEnterTransition, iconExitTransition: ExitTransition = LeadingIconToolbarTabDefaults.iconExitTransition ) { val backgroundColor = if (selected) { selectedBackgroundColor } else { Color.Transparent } Row( modifier = Modifier .fillMaxWidth() .clip(CircleShape) .background(color = backgroundColor) .minimumInteractiveComponentSize() .padding(horizontal = LeadingIconToolbarTabDefaults.horizontalPadding) .clickable { onClick() }, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center ) { this@Row.AnimatedVisibility( visible = selected, enter = iconEnterTransition, exit = iconExitTransition ) { Icon( imageVector = leadingIcon, contentDescription = null, // decorative modifier = Modifier.padding(end = LeadingIconToolbarTabDefaults.contentSpacing), tint = contentColor ) } Text( text = label, style = textStyle, color = contentColor ) } } /** Holds default values used by the [LeadingIconToolbarTab]. */ object LeadingIconToolbarTabDefaults { val selectedBackgroundColor: Color @Composable get() = MaterialTheme.colorScheme.secondaryContainer val contentColor: Color @Composable get() = MaterialTheme.colorScheme.onSecondaryContainer val textStyle: TextStyle @Composable get() = MaterialTheme.typography.labelLarge val horizontalPadding = 16.dp val contentSpacing = 8.dp val iconEnterTransition: EnterTransition = fadeIn() + expandIn(expandFrom = Alignment.Center) val iconExitTransition: ExitTransition = fadeOut() + shrinkOut(shrinkTowards = Alignment.Center) }