diff options
3 files changed, 74 insertions, 26 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt index 32c03136bf8e..5d87a03fdba7 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt @@ -32,6 +32,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope @@ -45,6 +46,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyGridState @@ -101,6 +103,9 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.CustomAccessibilityAction +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.customActions import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.text.style.TextAlign @@ -119,6 +124,7 @@ import com.android.compose.ui.graphics.painter.rememberDrawablePainter import com.android.internal.R.dimen.system_app_widget_background_radius import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.model.CommunalContentSize +import com.android.systemui.communal.shared.model.CommunalScenes import com.android.systemui.communal.ui.compose.Dimensions.CardOutlineWidth import com.android.systemui.communal.ui.compose.extensions.allowGestures import com.android.systemui.communal.ui.compose.extensions.detectLongPressGesture @@ -223,32 +229,34 @@ fun CommunalHub( .motionEventSpy { onMotionEvent(viewModel) } }, ) { - if (!viewModel.isEditMode && isEmptyState) { - EmptyStateCta( - contentPadding = contentPadding, - viewModel = viewModel, - ) - } else { - CommunalHubLazyGrid( - communalContent = communalContent, - viewModel = viewModel, - contentPadding = contentPadding, - contentOffset = contentOffset, - setGridCoordinates = { gridCoordinates = it }, - updateDragPositionForRemove = { offset -> - isDraggingToRemove = - isPointerWithinCoordinates( - offset = gridCoordinates?.let { it.positionInWindow() + offset }, - containerToCheck = removeButtonCoordinates - ) - isDraggingToRemove - }, - onOpenWidgetPicker = onOpenWidgetPicker, - gridState = gridState, - contentListState = contentListState, - selectedKey = selectedKey, - widgetConfigurator = widgetConfigurator, - ) + AccessibilityContainer(viewModel) { + if (!viewModel.isEditMode && isEmptyState) { + EmptyStateCta( + contentPadding = contentPadding, + viewModel = viewModel, + ) + } else { + CommunalHubLazyGrid( + communalContent = communalContent, + viewModel = viewModel, + contentPadding = contentPadding, + contentOffset = contentOffset, + setGridCoordinates = { gridCoordinates = it }, + updateDragPositionForRemove = { offset -> + isDraggingToRemove = + isPointerWithinCoordinates( + offset = gridCoordinates?.let { it.positionInWindow() + offset }, + containerToCheck = removeButtonCoordinates + ) + isDraggingToRemove + }, + onOpenWidgetPicker = onOpenWidgetPicker, + gridState = gridState, + contentListState = contentListState, + selectedKey = selectedKey, + widgetConfigurator = widgetConfigurator, + ) + } } // TODO(b/326060686): Remove this once keyguard indication area can persist over hub @@ -1028,6 +1036,39 @@ private fun Umo(viewModel: BaseCommunalViewModel, modifier: Modifier = Modifier) ) } +/** Container of the glanceable hub grid to enable accessibility actions when focused. */ +@Composable +fun AccessibilityContainer(viewModel: BaseCommunalViewModel, content: @Composable () -> Unit) { + val context = LocalContext.current + val isFocusable by viewModel.isFocusable.collectAsState(initial = false) + Box( + modifier = + Modifier.fillMaxWidth().wrapContentHeight().thenIf( + isFocusable && !viewModel.isEditMode + ) { + Modifier.focusable(isFocusable).semantics { + contentDescription = + context.getString( + R.string.accessibility_content_description_for_communal_hub + ) + customActions = + listOf( + CustomAccessibilityAction( + context.getString( + R.string.accessibility_action_label_close_communal_hub + ) + ) { + viewModel.changeScene(CommunalScenes.Blank) + true + } + ) + } + } + ) { + content() + } +} + /** * Returns the `contentPadding` of the grid. Use the vertical padding to push the grid content area * below the toolbar and let the grid take the max size. This ensures the item can be dragged diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 2bd025d82403..15b092240897 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1168,6 +1168,10 @@ <string name="work_mode_off_title">Unpause work apps?</string> <!-- Title for button to unpause on work profile. [CHAR LIMIT=NONE] --> <string name="work_mode_turn_on">Unpause</string> + <!-- Label for accessibility action that navigates to lock screen. [CHAR LIMIT=NONE] --> + <string name="accessibility_action_label_close_communal_hub">Close widgets on lock screen</string> + <!-- Accessibility content description for communal hub. [CHAR LIMIT=NONE] --> + <string name="accessibility_content_description_for_communal_hub">Widgets on lock screen</string> <!-- Related to user switcher --><skip/> diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt index 095222a4b47a..71d719df45ff 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt @@ -36,6 +36,9 @@ abstract class BaseCommunalViewModel( ) { val currentScene: Flow<SceneKey> = communalInteractor.desiredScene + /** Whether communal hub can be focused to enable accessibility actions. */ + val isFocusable: Flow<Boolean> = communalInteractor.isIdleOnCommunal + /** Whether widgets are currently being re-ordered. */ open val reorderingWidgets: StateFlow<Boolean> = MutableStateFlow(false) |