What I am trying to do/What I have done: I am trying to make a very basic version of TalkBack for visually impaired users. I have made a simple accessibility service that reads the contentDescription of a button clicked by the user and reads it out loud.
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
// get the source node of the event
AccessibilityNodeInfo source = event.getSource();
if (source == null) {
return;
}
// Check if a button is clicked and speak out the content
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED
&& BUTTON_CLASS_NAME.equals(source.getClassName()) {
Log.d("Button clicked", source.getViewIdResourceName().toString());
convertTextToSpeech(source.getContentDescription().toString());
}
if (source != null)
source.recycle();
return;
}
The problem: But, this way the user can't listen to the button's description BEFORE actually performing the action that fires when the button is clicked. By the time the user listens to the description, the button has already been clicked and an action has been performed.
Question: How do I interrupt the action (eg: opening a new activity after clicking the button) from being performed so that the user can safely explore the current views on the screen with the feedback I provide without starting new activities or firing other actions?
Sort of like what happens in Talkback: the user single taps to hear the description, and double taps to perform the action. How does Talkback prevent an action from happening unless the user double taps? I have looked into TouchExplorationMode but I guess it is mostly used for gestures rather than clicks.