Add content description to the master switch toggle button.

Set the preference title as the toggle button's content description, so
that when user focus on the button, it will read the lable as well on
top of just "switch on" or "switch off".

Change-Id: Id1954fd54b7d38cb4e75d8b3e49d05ee694e0e41
Fix: 37618855
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-04-27 15:09:21 -07:00
parent 32d3d383cb
commit e2ad415fdb
2 changed files with 16 additions and 0 deletions

View File

@@ -83,6 +83,7 @@ public class MasterSwitchPreference extends TwoTargetPreference {
mSwitch = (Switch) holder.findViewById(R.id.switchWidget); mSwitch = (Switch) holder.findViewById(R.id.switchWidget);
if (mSwitch != null) { if (mSwitch != null) {
mSwitch.setContentDescription(getTitle());
mSwitch.setChecked(mChecked); mSwitch.setChecked(mChecked);
mSwitch.setEnabled(mEnableSwitch); mSwitch.setEnabled(mEnableSwitch);
} }

View File

@@ -183,4 +183,19 @@ public class MasterSwitchPreferenceTest {
preference.setDisabledByAdmin(null); preference.setDisabledByAdmin(null);
assertThat(toggle.isEnabled()).isTrue(); assertThat(toggle.isEnabled()).isTrue();
} }
@Test
public void onBindViewHolder_toggleButtonShouldHaveContentDescription() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext)
.inflate(R.layout.preference_widget_master_switch, null));
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
final String label = "TestButton";
preference.setTitle(label);
preference.onBindViewHolder(holder);
assertThat(toggle.getContentDescription()).isEqualTo(label);
}
} }