dequelabs / Deque-University-for-Android

All you need to improve the Accessibility of your Android Applications in one place! Build the application to see Accessible Examples, check out Attest for debugging tools, or post an Issue to leverage our community of Android Accessibility experts.
https://www.deque.com/
Other
27 stars 9 forks source link

How to convey selected state to talkback? #42

Closed switherwax closed 5 years ago

switherwax commented 5 years ago

For example

  1. When I put Select a "Favorites" item and Star it
  2. It announces as "Favorite"

Accessible Behavior

I would expect that in step 2 it announces as "Favorite, selected" or "Favorites, unselected"

chriscm2006 commented 5 years ago

There are two ways to solve this problem:

  1. Ensuring the control is an instance of either the Switch or ToggleButton classes.
  2. Providing proper Accessibility Markup through View.AccessibilityDelegate

Instance of Switch or ToggleButton

The benefit of ensuring you control is an instance of a Switch or ToggleButton is that you get a lot of stuff for free.

Implementing - Inheritance

Basically, in order to implement this all you need to do is take whatever custom control you have, and ensure it is a subclass of ToggleButton. Why ToggleButton? ToggleButtons inherently track state. They come with announcements and all of the other things that a control needs to share the state of something being On or Off, but they do so in a way that is more naturally announced for an Assistive Technology user in the case of a "Favorites" button.

Providing Proper Accessibility Markup

This is deceptively difficult to get correct. There are a lot of different properties involved. We may build out this solution as an example in Deque University application, but if you want to look into the various APIs that matter while we're implementing this:

AccessibilityNodeInfo

Effecting all of these properties directly is actually quite cumbersome, especially if you are not used to working directly with AccessibilityDelegates. It is much easier to just use Inheritance! Not only that, but by utilizing Inheritance you are much more Past/Future proof.

A Popular NON Solution - Overriding Content Description

One thing that developers tend to do THAT IS NOT a solution is to append the information to the content description for the thing.

favoriteStar.setContentDescription("Favorites, selected")

This is a non solution for one very important reason: Programmatic Determinability.

There are too many words that mean "selected" for Assistive Technologies to do anything but announce the word. Sharing the state of "Selected" or "Unselected" is only one job that this state information does. The programmatic determinability is very important and can't be ignored.