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

Commit 95c32877 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

[Spa] Improve RestrictedSwitchPreference semantics

Now Talkback reads like,
- Off
- Unavailable
- Title
- Summary
- Switch
- Double-tap to Learn more

Bug: 422439682
Flag: EXEMPT new library
Test: manual test with Talkback
Change-Id: I9e0cd4cb0d09054f9aafd817f9c4893c1c79d524
parent 97370356
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2025 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<resources>
    <!-- Content description for the unavailable item. [CHAR LIMIT=NONE]-->
    <string name="spa_unavailable">Unavailable</string>
    <!-- An action, to learn more. [CHAR LIMIT=NONE]-->
    <string name="spa_learn_more">Learn more</string>
</resources>
+9 −1
Original line number Diff line number Diff line
@@ -19,10 +19,13 @@ package com.android.settingslib.spa.restricted
import androidx.compose.foundation.clickable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.toggleableState
import androidx.compose.ui.state.ToggleableState
import com.android.settingslib.spa.R
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel

internal class RestrictedSwitchPreferenceModel(
@@ -62,11 +65,16 @@ internal class RestrictedSwitchPreferenceModel(
        val modifier =
            when (restrictedMode) {
                is BlockedWithDetails -> {
                    val statusDescription = stringResource(R.string.spa_unavailable)
                    Modifier.clickable(
                            onClickLabel = stringResource(R.string.spa_learn_more),
                            role = Role.Switch,
                            onClick = { restrictedMode.showDetails() },
                        )
                        .semantics { this.toggleableState = toggleableState(checked()) }
                        .semantics {
                            contentDescription = statusDescription
                            toggleableState = toggleableState(checked())
                        }
                }

                else -> Modifier