Fix a11y announcements in DND duration dialogs

We are using a separate RadioButton just for the button and a view (possibly complex) fo the text. The latter didn't report an accurate selection status (especially when selecting, which didn't announce anything at all). Note that we are _not_ setting the "unselected" status to avoid repetition when walking through with Talkback (button -> text -> button -> text, ...).

Fixes: 265468127
Test: Unit tests
Change-Id: I87aad93d942a868776ecec163136fd9bfcb8276f
This commit is contained in:
Matías Hernández
2023-02-21 16:55:24 +01:00
parent 9070618cf1
commit 3d3ef50243
5 changed files with 57 additions and 1 deletions

View File

@@ -65,7 +65,7 @@ android_library {
"src/**/*.kt",
],
min_sdk_version: "29",
min_sdk_version: "30",
}

View File

@@ -224,6 +224,9 @@ public class EnableZenModeDialog {
mMetricsLogger.logOnConditionSelected();
updateAlarmWarningText(tag.condition);
}
tag.line1.setStateDescription(
isChecked ? buttonView.getContext().getString(
com.android.internal.R.string.selected) : null);
}
});

View File

@@ -196,6 +196,9 @@ public class ZenDurationDialog {
if (isChecked) {
tag.rb.setChecked(true);
}
tag.line1.setStateDescription(
isChecked ? buttonView.getContext().getString(
com.android.internal.R.string.selected) : null);
}
});

View File

@@ -16,6 +16,8 @@
package com.android.settingslib.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -78,6 +80,8 @@ public class EnableZenModeDialogTest {
mController.mForeverId = Condition.newId(mContext).appendPath("forever").build();
when(mContext.getString(com.android.internal.R.string.zen_mode_forever))
.thenReturn("testSummary");
when(mContext.getString(com.android.internal.R.string.selected))
.thenReturn("selected");
NotificationManager.Policy alarmsEnabledPolicy = new NotificationManager.Policy(
NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS, 0, 0, 0);
doReturn(alarmsEnabledPolicy).when(mNotificationManager).getNotificationPolicy();
@@ -190,4 +194,25 @@ public class EnableZenModeDialogTest {
// alarm warning should NOT be null
assertNotNull(mController.computeAlarmWarningText(null));
}
@Test
public void testAccessibility() {
mController.bindConditions(null);
EnableZenModeDialog.ConditionTag forever = mController.getConditionTagAt(
ZenDurationDialog.FOREVER_CONDITION_INDEX);
EnableZenModeDialog.ConditionTag countdown = mController.getConditionTagAt(
ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
EnableZenModeDialog.ConditionTag alwaysAsk = mController.getConditionTagAt(
ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX);
forever.rb.setChecked(true);
assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected");
assertThat(countdown.line1.getStateDescription()).isNull();
assertThat(alwaysAsk.line1.getStateDescription()).isNull();
alwaysAsk.rb.setChecked(true);
assertThat(forever.line1.getStateDescription()).isNull();
assertThat(countdown.line1.getStateDescription()).isNull();
assertThat(alwaysAsk.line1.getStateDescription().toString()).isEqualTo("selected");
}
}

View File

@@ -16,6 +16,8 @@
package com.android.settingslib.notification;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
@@ -205,4 +207,27 @@ public class ZenDurationDialogTest {
ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
assertEquals(120, tag.countdownZenDuration);
}
@Test
public void testAccessibility() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
Settings.Secure.ZEN_DURATION_FOREVER);
mController.setupDialog(mBuilder);
ZenDurationDialog.ConditionTag forever = mController.getConditionTagAt(
ZenDurationDialog.FOREVER_CONDITION_INDEX);
ZenDurationDialog.ConditionTag countdown = mController.getConditionTagAt(
ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
ZenDurationDialog.ConditionTag alwaysAsk = mController.getConditionTagAt(
ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX);
forever.rb.setChecked(true);
assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected");
assertThat(countdown.line1.getStateDescription()).isNull();
assertThat(alwaysAsk.line1.getStateDescription()).isNull();
alwaysAsk.rb.setChecked(true);
assertThat(forever.line1.getStateDescription()).isNull();
assertThat(countdown.line1.getStateDescription()).isNull();
assertThat(alwaysAsk.line1.getStateDescription().toString()).isEqualTo("selected");
}
}