WidgetPicker: Implement no widgets available message

- Shows an error message when there are no widgets to show.
- Also adds a spacer item for edge padding to offset floating toolbar.

Bug: 408283627
Flag: com.android.launcher3.enable_widget_picker_refactor
Test: Test changes
Change-Id: I89e78a9dafc23bb02be13e6fde08971835ff18f0
This commit is contained in:
shamalip committed 2025-06-05 13:50:48 +00:00
1 parent 7718224896
commit dfe273543f
6 files changed
+144 -84

No files matched your search

@@ -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),
@@ -61,4 +61,11 @@
<string name="widget_search_bar_clear_button_label">Clear</string>
<!-- Accessibility label for the button to go back from the search screen -->
<string name="widget_search_bar_back_button_label">Back</string>
<!-- Text shown when there are no widgets or shortcuts that can be added to the device.
[CHAR_LIMIT=150] -->
<string name="widgets_list_no_widgets_available">Widgets and shortcuts aren\'t available</string>
<!-- Text shown when there are no matching widget or shortcut search results for user's search
query. [CHAR_LIMIT=150] -->
<string name="widgets_no_search_results">No widgets or shortcuts found</string>
</resources>
@@ -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<WidgetId, WidgetPreview>,
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
@@ -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<WidgetPickerColors> {
throw IllegalStateException(
"No WidgetPickerColors configured. Make sure to use WidgetPickerTheme in your top level "
+ "Composable."
)
}
val LocalWidgetPickerColors =
staticCompositionLocalOf<WidgetPickerColors> {
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,
)
@@ -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,
+2
View File
@@ -151,6 +151,7 @@
<color name="widget_picker_featured_header_icon_color_light">
@color/system_primary_light
</color>
<color name="widget_picker_no_widget_error_color_light">@color/system_on_surface_light</color>
<color name="widget_picker_preview_placeholder_background_light">
@color/system_secondary_container_light
@@ -222,6 +223,7 @@
<color name="widget_picker_featured_header_icon_color_dark">
@color/system_primary_dark
</color>
<color name="widget_picker_no_widget_error_color_dark">@color/system_on_surface_dark</color>
<color name="widget_picker_preview_placeholder_background_dark">
@color/system_secondary_container_dark