Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Android talkback instructions for double tap and long press

I have a view that has a long press action handler. I use the content description to set the message Talkback speaks when the view gets focus.

Currently it says my content description right after getting a focus, and after a short pause says:

Double tap to activate, double tap and hold for long press

I want to change this message into something like

Double tap to "action 1", double tap and hold for "action 2"

Is there a way to do so?

I looked into onPopulateAccessibilityEvent(), it gets TYPE_VIEW_ACCESSIBILITY_FOCUSED event, but I wasn't able to change the desired message.

Am I missing something simple?

like image 307
Paul Avatar asked Sep 12 '16 17:09

Paul


1 Answers

It seems AccessibilityAction has changed slightly since alanv posted his answer. Here is a working solution using ViewCompat:

ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() {
    @Override
    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
        super.onInitializeAccessibilityNodeInfo(host, info);
        // A custom action description. For example, you could use "pause"
        // to have TalkBack speak "double-tap to pause."
        CharSequence description = host.getResources().getText(R.string.my_click_desc);
        AccessibilityActionCompat customClick = new AccessibilityActionCompat(
                    AccessibilityNodeInfoCompat.ACTION_CLICK, description);
        info.addAction(customClick);
    }
});
like image 117
JustinMorris Avatar answered Oct 16 '22 12:10

JustinMorris