diff options
2 files changed, 34 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt b/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt index 3613c11012dd..c3274b7ca28b 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/composefragment/QSFragmentCompose.kt @@ -45,6 +45,10 @@ import androidx.compose.ui.layout.onGloballyPositioned  import androidx.compose.ui.layout.positionInRoot  import androidx.compose.ui.platform.ComposeView  import androidx.compose.ui.res.dimensionResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.CustomAccessibilityAction +import androidx.compose.ui.semantics.customActions +import androidx.compose.ui.semantics.semantics  import androidx.compose.ui.unit.round  import androidx.lifecycle.Lifecycle  import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -265,7 +269,7 @@ constructor(      }      override fun setCollapseExpandAction(action: Runnable?) { -        // Nothing to do yet. But this should be wired to a11y +        viewModel.collapseExpandAccessibilityAction = action      }      override fun getHeightDiff(): Int { @@ -419,6 +423,9 @@ constructor(                              layout(placeable.width, placeable.height) { placeable.place(0, 0) }                          }                          .padding(top = { qqsPadding }) +                        .collapseExpandSemanticAction( +                            stringResource(id = R.string.accessibility_quick_settings_expand) +                        )              )              Spacer(modifier = Modifier.weight(1f))          } @@ -428,7 +435,12 @@ constructor(      private fun QuickSettingsElement() {          val qqsPadding by viewModel.qqsHeaderHeight.collectAsStateWithLifecycle()          val qsExtraPadding = dimensionResource(R.dimen.qs_panel_padding_top) -        Column { +        Column( +            modifier = +                Modifier.collapseExpandSemanticAction( +                    stringResource(id = R.string.accessibility_quick_settings_collapse) +                ) +        ) {              Box(modifier = Modifier.fillMaxSize().weight(1f)) {                  Column {                      Spacer(modifier = Modifier.height { qqsPadding + qsExtraPadding.roundToPx() }) @@ -444,6 +456,20 @@ constructor(              }          }      } + +    private fun Modifier.collapseExpandSemanticAction(label: String): Modifier { +        return viewModel.collapseExpandAccessibilityAction?.let { +            semantics { +                customActions = +                    listOf( +                        CustomAccessibilityAction(label) { +                            it.run() +                            true +                        } +                    ) +            } +        } ?: this +    }  }  private fun View.setBackPressedDispatcher() { diff --git a/packages/SystemUI/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModel.kt index 4b1312c71ff5..df77878b88d9 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/composefragment/viewmodel/QSFragmentComposeViewModel.kt @@ -218,6 +218,12 @@ constructor(              }              .stateIn(lifecycleScope, SharingStarted.WhileSubscribed(), QSExpansionState.QQS) +    /** +     * Accessibility action for collapsing/expanding QS. The provided runnable is responsible for +     * determining the correct action based on the expansion state. +     */ +    var collapseExpandAccessibilityAction: Runnable? = null +      @AssistedFactory      interface Factory {          fun create(lifecycleScope: LifecycleCoroutineScope): QSFragmentComposeViewModel  |