Hanseul Cho
Hanseul Cho

Reputation: 31

About Android Accessibility Talkback. Is there any talkback focus listener?

I am developing android photo application for visually impaired people.

Of course, my application is running in Talkback context. Under Talkback context, when button is focused the system reads text of button. the green box represents the focused content

What I want to do is playing audio file when button is focused not text label of button. However, I cannot find any listener that detects button's focused state. Is there any way to do that?

Upvotes: 3

Views: 3789

Answers (1)

MobA11y
MobA11y

Reputation: 18860

DISCLAIMER: Things that happen on focus is potentially a major accessibility violation per WCAG 2.0 - 3.2.1. I would encourage you to rethink your design/do extensive user research, to ensure what you end up doing isn't just creating a frustrating user experience. Not only that, but remember TalkBack is not the only Assistive technology, it strikes me that this mechanism could be incredibly frustrating for users using Switch Access and potentially completely broken for a BrailleBack user.

That being said, this is how you would accomplish this behavior:

You want to look at the callbacks available in View.AccessibilityDelegate

I believe you should be looking for code that looks something like this:

void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        //do stuff here
    }
}

Attach this to the view that is receiving focus, or depending on which callback you use, you may be able to attach it to the layout containing a series of controls.

Now, I say "something like this" because there are a lot of different accessibility delegate callbacks, pre event firing, post event firing, things that allow you to tweak the event as it is populated up the view hierarchy, etc. Which callback you choose depends on exactly when you want this to happen and the nature of things you may need to tweak about the AccessibilityEvent that is firing.

Upvotes: 4

Related Questions