Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using TalkBack, what is the preferred way to alert the user when the contents of a TextView have changed?

I have an unlock screen where the user is prompted to enter a four digit pin. If the user enters their pin incorrectly, a previously invisible TextView is shown with an error message. At this point it would be useful for TalkBack to read the contents of the error message out loud.

Through some experimentation, I realized I could set android:focusableInTouchMode="true" on the view and programmatically call View#requestFocus(). This works the first time, but fails on subsequent errors since the view already has focus. Also it seems like a bad idea in general to override the current view focus.

I then tried invoking View#announceForAccessibility(java.lang.CharSequence) when the error message is displayed. Apparently this method will silently fail if the view is not currently visible. No problem and otherwise it works perfectly. However, it's only available in API level 16+ (Jelly Bean) which really limits it's usefulness. There has to be a better solution since TalkBack supports API level 7+.

I've watched both the 2011 and 2012 Google I/O sessions on accessibility, but neither seem to cover this basic use case. What's the best way to do this?

Edit 1: TLDR; Is there a way to force TalkBack to read some text out loud prior to the introduction of View#announceForAccessibility(java.lang.CharSequence) in Jelly Bean?

like image 250
twaddington Avatar asked Nov 03 '12 02:11

twaddington


People also ask

When using TalkBack How do you activate a link or a button?

Open the TalkBack menu. On devices with multi-finger gestures: Three-finger tap. Or, in one motion, swipe down then right. On devices without multi-finger gestures (prior to updated Android R with TalkBack 9.1): In one motion, swipe down then right.

What is accessibility TalkBack?

TalkBack is the Google screen reader included on Android devices. TalkBack gives you eyes-free control of your device. The setup of your device depends on the device manufacturer, Android version, and TalkBack version.

How do I know if TalkBack is enabled Android?

More details: if you are strictly interested in whether TalkBack is enabled, use am. isTouchExplorationEnabled() . (If Select to Speak is enabled and TalkBack disabled, am. isEnabled() will still return true.)


2 Answers

I was using the accepted answer, which works well. However, I didn't like the misleading sound when accessibility focus was set on the text view - the same sound as when input focus is given to an EditField by double-tapping (a sort of drawer-open sound), because the input focus had not actually moved from the EditText with inputfocus (eg with cursor).

So I tried:

m_textView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);`

and interestingly it works - the label is read, without moving any focus or giving any other sound.

like image 77
salfon Avatar answered Oct 18 '22 05:10

salfon


You should be able to use View.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) on your TextView to trigger TalkBack in the same way that View.requestFocus() would. Since it only triggers the event, and doesn't actually focus the View, it shouldn't crash after the first time.

like image 12
Techwolf Avatar answered Oct 18 '22 03:10

Techwolf