Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dee191cd authored by Coco Duan's avatar Coco Duan
Browse files

Add accessibility action to navigate to keyguard from glanceable hub

Bug: b/333563969
Test: manual
Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD
Change-Id: I4bdb5ccb7e57ba65b353f17e87aa699135349206
parent 26c3a134
Loading
Loading
Loading
Loading
+67 −26
Original line number Diff line number Diff line
@@ -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,6 +229,7 @@ fun CommunalHub(
                        .motionEventSpy { onMotionEvent(viewModel) }
                },
    ) {
        AccessibilityContainer(viewModel) {
            if (!viewModel.isEditMode && isEmptyState) {
                EmptyStateCta(
                    contentPadding = contentPadding,
@@ -250,6 +257,7 @@ fun CommunalHub(
                    widgetConfigurator = widgetConfigurator,
                )
            }
        }

        // TODO(b/326060686): Remove this once keyguard indication area can persist over hub
        if (viewModel is CommunalViewModel) {
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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/>

+3 −0
Original line number Diff line number Diff line
@@ -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)