diff --git a/compose/features/com/android/launcher3/widgetpicker/theme/Colors.kt b/compose/features/com/android/launcher3/widgetpicker/theme/Colors.kt
index 8104259049..bb7ccb3116 100644
--- a/compose/features/com/android/launcher3/widgetpicker/theme/Colors.kt
+++ b/compose/features/com/android/launcher3/widgetpicker/theme/Colors.kt
@@ -55,6 +55,9 @@ fun darkWidgetPickerColors() =
listHeaderTitle = colorResource(R.color.widget_picker_header_app_title_color_dark),
listHeaderSubTitle = colorResource(R.color.widget_picker_header_app_subtitle_color_dark),
+ // Error message
+ noWidgetsErrorText = colorResource(R.color.widget_picker_no_widget_error_color_dark),
+
// Widgets container
widgetsContainerBackground =
colorResource(R.color.widget_picker_widgets_container_background_dark),
@@ -125,6 +128,9 @@ fun lightWidgetPickerColors() =
listHeaderTitle = colorResource(R.color.widget_picker_header_app_title_color_light),
listHeaderSubTitle = colorResource(R.color.widget_picker_header_app_subtitle_color_light),
+ // Error message
+ noWidgetsErrorText = colorResource(R.color.widget_picker_no_widget_error_color_light),
+
// Widgets container
widgetsContainerBackground =
colorResource(R.color.widget_picker_widgets_container_background_light),
diff --git a/modules/widgetpicker/res/values/strings.xml b/modules/widgetpicker/res/values/strings.xml
index efb67cdc93..ddd3caf1d7 100644
--- a/modules/widgetpicker/res/values/strings.xml
+++ b/modules/widgetpicker/res/values/strings.xml
@@ -61,4 +61,11 @@
Clear
Back
+
+
+ Widgets and shortcuts aren\'t available
+
+ No widgets or shortcuts found
diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetAppsList.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetAppsList.kt
index d429fe0ec5..6a02c11bdd 100644
--- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetAppsList.kt
+++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetAppsList.kt
@@ -16,17 +16,22 @@
package com.android.launcher3.widgetpicker.ui.components
-import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.res.stringResource
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.android.launcher3.widgetpicker.R
import com.android.launcher3.widgetpicker.shared.model.AppIcon
@@ -37,6 +42,7 @@ import com.android.launcher3.widgetpicker.shared.model.WidgetId
import com.android.launcher3.widgetpicker.shared.model.WidgetPreview
import com.android.launcher3.widgetpicker.ui.WidgetInteractionInfo
import com.android.launcher3.widgetpicker.ui.model.DisplayableWidgetApp
+import com.android.launcher3.widgetpicker.ui.theme.WidgetPickerTheme
/**
* Displays a various apps on device that host widgets.
@@ -55,68 +61,96 @@ fun WidgetAppsList(
widgetPreviews: Map,
onWidgetInteraction: (WidgetInteractionInfo) -> Unit,
showDragShadow: Boolean,
+ bottomContentSpacing: Dp = 0.dp,
headerDescriptionStyle: AppHeaderDescriptionStyle = AppHeaderDescriptionStyle.WIDGETS_COUNT,
+ emptyWidgetsErrorMessage: String? = null,
) {
- val listState = rememberLazyListState()
+ if (widgetApps.isEmpty()) {
+ NoWidgetsError(
+ modifier = modifier,
+ errorMessage =
+ emptyWidgetsErrorMessage
+ ?: stringResource(R.string.widgets_list_no_widgets_available),
+ )
+ } else {
+ val listState = rememberLazyListState()
- LazyColumn(
- state = listState,
- verticalArrangement = Arrangement.spacedBy(WidgetAppsListDimensions.itemSpacing),
- modifier = modifier.clip(WidgetAppsListDimensions.largeShape),
- ) {
- items(
- count = widgetApps.size,
- key = { index -> widgetApps[index].id.toString() },
- contentType = { widgetAppHeaderStyle },
- ) { index ->
- val widgetApp = widgetApps[index]
- val selected = widgetApp.id == selectedWidgetAppId
+ LazyColumn(
+ state = listState,
+ verticalArrangement = Arrangement.spacedBy(WidgetAppsListDimensions.itemSpacing),
+ modifier = modifier.clip(WidgetAppsListDimensions.largeShape),
+ ) {
+ items(
+ count = widgetApps.size,
+ key = { index -> widgetApps[index].id.toString() },
+ contentType = { widgetAppHeaderStyle },
+ ) { index ->
+ val widgetApp = widgetApps[index]
+ val selected = widgetApp.id == selectedWidgetAppId
- val title = widgetApp.widgetHeaderTitle()
- val description = widgetApp.widgetHeaderDescription(headerDescriptionStyle)
+ val title = widgetApp.widgetHeaderTitle()
+ val description = widgetApp.widgetHeaderDescription(headerDescriptionStyle)
- val appIconForItem =
- remember(appIcons) {
- appIcons[widgetApp.id]
- ?: WidgetAppIcon(AppIcon.PlaceHolderAppIcon, AppIconBadge.NoBadge)
- }
- val appIcon: @Composable () -> Unit =
- remember(appIconForItem) {
- { WidgetAppIcon(widgetAppIcon = appIconForItem, size = AppIconSize.MEDIUM) }
+ val appIconForItem =
+ remember(appIcons) {
+ appIcons[widgetApp.id]
+ ?: WidgetAppIcon(AppIcon.PlaceHolderAppIcon, AppIconBadge.NoBadge)
+ }
+ val appIcon: @Composable () -> Unit =
+ remember(appIconForItem) {
+ { WidgetAppIcon(widgetAppIcon = appIconForItem, size = AppIconSize.MEDIUM) }
+ }
+
+ when (widgetAppHeaderStyle) {
+ WidgetAppHeaderStyle.EXPANDABLE -> {
+ ExpandableWidgetAppHeader(
+ isFirst = index == 0,
+ isLast = index == widgetApps.lastIndex,
+ expanded = selected,
+ widgetApp = widgetApp,
+ appIcon = appIcon,
+ title = title,
+ description = description,
+ widgetPreviews = widgetPreviews,
+ onWidgetAppClick = onWidgetAppClick,
+ onWidgetInteraction = onWidgetInteraction,
+ showDragShadow = showDragShadow,
+ )
+ }
+
+ WidgetAppHeaderStyle.CLICKABLE ->
+ SelectableListHeader(
+ modifier = Modifier.fillMaxWidth(),
+ leadingAppIcon = appIcon,
+ selected = selected,
+ title = title,
+ subTitle = description,
+ shape = WidgetAppsListDimensions.largeShape,
+ onSelect = { onWidgetAppClick(widgetApp) },
+ )
}
+ }
- when (widgetAppHeaderStyle) {
- WidgetAppHeaderStyle.EXPANDABLE -> {
- ExpandableWidgetAppHeader(
- isFirst = index == 0,
- isLast = index == widgetApps.lastIndex,
- expanded = selected,
- widgetApp = widgetApp,
- appIcon = appIcon,
- title = title,
- description = description,
- widgetPreviews = widgetPreviews,
- onWidgetAppClick = onWidgetAppClick,
- onWidgetInteraction = onWidgetInteraction,
- showDragShadow = showDragShadow,
- )
+ if (bottomContentSpacing > 0.dp) {
+ item(key = SPACER_LIST_ITEM_TYPE, contentType = SPACER_LIST_ITEM_TYPE) {
+ Spacer(modifier.height(bottomContentSpacing))
}
-
- WidgetAppHeaderStyle.CLICKABLE ->
- SelectableListHeader(
- modifier = Modifier.fillMaxWidth(),
- leadingAppIcon = appIcon,
- selected = selected,
- title = title,
- subTitle = description,
- shape = WidgetAppsListDimensions.largeShape,
- onSelect = { onWidgetAppClick(widgetApp) },
- )
}
}
}
}
+@Composable
+private fun NoWidgetsError(modifier: Modifier, errorMessage: String) {
+ Box(modifier = modifier, contentAlignment = Alignment.Center) {
+ Text(
+ text = errorMessage,
+ style = WidgetPickerTheme.typography.noWidgetsErrorText,
+ color = WidgetPickerTheme.colors.noWidgetsErrorText,
+ )
+ }
+}
+
@Composable
private fun ExpandableWidgetAppHeader(
isLast: Boolean,
@@ -157,7 +191,7 @@ private fun ExpandableWidgetAppHeader(
when {
isFirst && isLast && !expanded -> WidgetAppsListDimensions.largeShape
isFirst -> WidgetAppsListDimensions.topLargeShape
- isLast && !expanded -> WidgetAppsListDimensions.bottomLargeShape
+ isLast -> WidgetAppsListDimensions.bottomLargeShape
else -> WidgetAppsListDimensions.smallShape
},
)
@@ -192,6 +226,8 @@ enum class AppHeaderDescriptionStyle {
COMBINED_WIDGETS_TITLE,
}
+private const val SPACER_LIST_ITEM_TYPE = "spacer"
+
private object WidgetAppsListDimensions {
val itemSpacing = 4.dp
diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerColors.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerColors.kt
index c02c1f40d6..5dd57ab510 100644
--- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerColors.kt
+++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerColors.kt
@@ -28,56 +28,51 @@ import androidx.compose.ui.graphics.Color
* @param dragHandle color of the drag handle shown in the widget picker bottom sheet.
* @param sheetTitle color of the title of entire bottom sheet
* @param sheetDescription color of long description displayed below the title of the bottom sheet.
- *
* @param expandCollapseIndicatorIcon color of the expand collapse button shown in the expandable
- * list of apps in the single pane view of the widget picker.
+ * list of apps in the single pane view of the widget picker.
* @param expandCollapseIndicatorBackground background color shown below the
- * [expandCollapseIndicatorIcon]
+ * [expandCollapseIndicatorIcon]
* @param expandableListItemsBackground background color of the expandable list of widget apps shown
- * in the single pane view of widget picker.
- * @param selectedListHeaderBackground background color of a widget app header that's selected
- * (in left pane of two pane picker view).
+ * in the single pane view of widget picker.
+ * @param selectedListHeaderBackground background color of a widget app header that's selected (in
+ * left pane of two pane picker view).
* @param unselectedListHeaderBackground background color of a widget app headers that's not
- * selected (in left pane of two pane picker view).
+ * selected (in left pane of two pane picker view).
* @param widgetsContainerBackground background color of the container that displays widgets.
* @param featuredHeaderLeadingIconBackground background color of the leading icon of the featured
- * widgets header (in left pane of two pane picker view).
+ * widgets header (in left pane of two pane picker view).
* @param featuredHeaderLeadingIcon color of the leading icon of the featured widgets header (in
- * left pane of two pane picker view).
+ * left pane of two pane picker view).
* @param listHeaderTitle color of the title text of widget app headers (in left pane of two pane
- * picker view).
+ * picker view).
* @param listHeaderSubTitle color of the subtitle text of widget app headers (in left pane of two
- * pane picker view).
- *
+ * pane picker view).
+ * @param noWidgetsErrorText color of the message shown when no widgets are available or matched.
* @param placeholderAppIcon base color of the placeholder (without alpha) shown while app icon
- * isn't loaded yet.
- *
+ * isn't loaded yet.
* @param widgetLabel color of the text showing widget's label below its preview.
* @param widgetSpanText color of text showing the dimensions of the widget.
* @param widgetDescription color of the text showing the long description of the widget.
* @param addButtonContent color of the text / icon shown within the add button shown for a widget.
* @param addButtonBackground background color of the add button shown for a widget.
- *
* @param widgetPlaceholderBackground background color of the placeholder shown while a widget's
- * preview isn't loaded yet.
+ * preview isn't loaded yet.
* @param widgetPlaceholderContent color of the content (e.g. loading spinner) shown over the
- * [widgetPlaceholderBackground]
- *
+ * [widgetPlaceholderBackground]
* @param toolbarBackground color of the background of the floating toolbar that shows the tabs.
- * @param toolbarTabSelectedBackground background color of a selected tab (personal / work
- * / browse / featured) in a floating toolbar.
- * @param toolbarTabUnSelectedBackground background color of an unselected tab (personal / work
- * / browse / featured) in a floating toolbar.
+ * @param toolbarTabSelectedBackground background color of a selected tab (personal / work / browse
+ * / featured) in a floating toolbar.
+ * @param toolbarTabUnSelectedBackground background color of an unselected tab (personal / work /
+ * browse / featured) in a floating toolbar.
* @param toolbarTabContent color of the text and icons in a tab within a floating toolbar.
- *
* @param searchBarBackground background color of the search bar.
* @param searchBarPlaceholderText color of the placeholder text shown in the search bar.
* @param searchBarText color of the text that use types in the search bar.
* @param searchBarSearchIcon color of the search icon shown leading the text in search bar.
* @param searchBarBackButtonIcon color of the icon in the back button shown in place of
- * [searchBarSearchIcon] when user is in search mode.
- * @param searchBarCloseButtonIcon color of close icon button shown trailing in the search bar when
- * user has typed some text.
+ * [searchBarSearchIcon] when user is in search mode.
+ * @param searchBarClearButtonIcon color of close icon button shown trailing in the search bar when
+ * user has typed some text.
* @param searchBarCursor color of the cursor in the search bar
*/
data class WidgetPickerColors(
@@ -99,6 +94,9 @@ data class WidgetPickerColors(
val expandCollapseIndicatorIcon: Color,
val expandCollapseIndicatorBackground: Color,
+ // Error message
+ val noWidgetsErrorText: Color,
+
// Widgets container
val widgetsContainerBackground: Color,
@@ -139,12 +137,13 @@ data class WidgetPickerColors(
* part of the widget picker. It enables the host to map the widget picker colors different system
* tokens than default.
*/
-val LocalWidgetPickerColors = staticCompositionLocalOf {
- throw IllegalStateException(
- "No WidgetPickerColors configured. Make sure to use WidgetPickerTheme in your top level "
- + "Composable."
- )
-}
+val LocalWidgetPickerColors =
+ staticCompositionLocalOf {
+ throw IllegalStateException(
+ "No WidgetPickerColors configured. Make sure to use WidgetPickerTheme in your top level " +
+ "Composable."
+ )
+ }
/**
* Default colors that can either be used as is in host theme or used a reference to define your own
@@ -178,6 +177,9 @@ fun defaultWidgetPickerColors() =
expandCollapseIndicatorIcon = MaterialTheme.colorScheme.onSecondaryContainer,
expandCollapseIndicatorBackground = MaterialTheme.colorScheme.secondaryContainer,
+ // Error text
+ noWidgetsErrorText = MaterialTheme.colorScheme.onSurface,
+
// App icon
placeholderAppIcon = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.2f),
@@ -199,5 +201,5 @@ fun defaultWidgetPickerColors() =
searchBarSearchIcon = MaterialTheme.colorScheme.onSurfaceVariant,
searchBarBackButtonIcon = MaterialTheme.colorScheme.onSurfaceVariant,
searchBarClearButtonIcon = MaterialTheme.colorScheme.onSurfaceVariant,
- searchBarCursor = MaterialTheme.colorScheme.primary
+ searchBarCursor = MaterialTheme.colorScheme.primary,
)
diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerTextStyles.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerTextStyles.kt
index 7e218b35fe..ad3cb5fc47 100644
--- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerTextStyles.kt
+++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/theme/WidgetPickerTextStyles.kt
@@ -39,6 +39,7 @@ import androidx.compose.ui.unit.sp
* @param unSelectedListHeaderSubTitle style for the sub-title text shown below the
* [unSelectedListHeaderTitle] for the widget app that's collapsed / un-selected in the list of
* widget apps.
+ * @param noWidgetsErrorText style for the text indicating that there are no widgets available.
* @param widgetLabel style for the text showing widget's label below its preview.
* @param widgetSpanText style for the text showing the dimensions of the widget.
* @param widgetDescription style for the text showing the long description of the widget.
@@ -60,6 +61,9 @@ data class WidgetPickerTextStyles(
val selectedListHeaderSubTitle: TextStyle,
val unSelectedListHeaderSubTitle: TextStyle,
+ // No widgets error
+ val noWidgetsErrorText: TextStyle,
+
// Widget details
val widgetLabel: TextStyle,
val widgetSpanText: TextStyle,
@@ -109,6 +113,9 @@ fun defaultWidgetPickerTextStyles() =
unSelectedListHeaderSubTitle =
MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Normal),
+ // No widgets error
+ noWidgetsErrorText = MaterialTheme.typography.bodyLarge,
+
// Widget details
widgetLabel = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.Medium),
widgetSpanText = MaterialTheme.typography.labelLarge,
diff --git a/res/values/colors.xml b/res/values/colors.xml
index f9d8fb9eca..200cbc6656 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -151,6 +151,7 @@
@color/system_primary_light
+ @color/system_on_surface_light
@color/system_secondary_container_light
@@ -222,6 +223,7 @@
@color/system_primary_dark
+ @color/system_on_surface_dark
@color/system_secondary_container_dark