Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Add View.setUsageHint() to describe click actions for TalkBack users #483

Closed
wants to merge 1 commit into from

Conversation

ataulm
Copy link
Contributor

@ataulm ataulm commented Apr 2, 2018

Usage hints are used by TalkBack to describe the action that will be triggered on click or long click, e.g.:

"The Matrix... <pause>... Double tap to start playing movie"

where "The Matrix" is the content description and "Double tap to start playing movie" is the usage hint.

Without a custom hint set, it will read: "The Matrix... <pause>... Double tap to activate".


Java implementation:

    ...
    setUsageHint(movieItemView, "start playing movie", null);
}

private static void setUsageHint(View view, @Nullable CharSequence clickLabel, @Nullable CharSequence longClickLabel) {
    ViewCompat.setAccessibilityDelegate(
        this, new AccessibilityDelegateCompat() {
            @Override
            public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
                super.onInitializeAccessibilityNodeInfo(host, info);

                if (host.isClickable()) {
                    info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(ACTION_CLICK, clickLabel));
                }

                if (host.isLongClickable()) {
                    info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(ACTION_LONG_CLICK, longClickLabel));
                }
            }
        }
    );
}

with Kotlin-ktx:

movieItemView.setUsageHint("start playing movie")

There are many more combinations of tests I can add but I dunno if it's too much. I am concerned that View.kt and consequently ViewTest.kt will get very large - is there some strategy to mitigate this or is it not considered an issue?


On pre-Lollipop, this behaviour is a no-op (handled by ViewCompat's implementation of AccessibilityDelegate under the hood).

@ataulm
Copy link
Contributor Author

ataulm commented Apr 2, 2018

⚠️ Note: ViewCompat comes from the support library.

This functionality is possible without ViewCompat, since View also has setAccessibilityDelegate but would require RequiresSdk annotations. I don't mind either.

@ataulm ataulm changed the title Add extension function to set custom usage hints for accessibility services Add View.setUsageHint() to describe click actions for TalkBack users Apr 2, 2018
@ataulm
Copy link
Contributor Author

ataulm commented Jul 1, 2018

Is there something I could answer or change to get this merged in?

If it's not suitable for this library, could we close the PR?

@ataulm ataulm closed this Jul 28, 2018
@ataulm ataulm deleted the view-usage-hints branch July 28, 2018 18:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant