I have an activity which adds a custom view to the entire activity's view using the following code
activity.getWindow().getDecorView()).addView(newView)
in order to have a screen of coach marks/usertips displayed.
My custom view extends from RelativeLayout and in its constructor a button is added at the bottom of the screen which when clicked upon dismisses the view.
I have overwritten the "dispatchDraw" method so that I can add multiple coachmark UI objects (textviews and bitmaps) to the layout at specific locations. These coachmark objects draw themselves on the view using code such as the following
canvas.save();
canvas.translate(positioning[0], positioning[1]);
textView.draw(canvas);
canvas.restore();
canvas.save();
canvas.drawBitmap(bitmap, positioning[2], positioning[3], new Paint());
canvas.restore();
ISSUE: When TalkBack is enabled
however when the user presses on the button the button's contentDescription is read out loud.
I assume the reason the textViews and Bitmaps are not read out is due to the way they are rendered on the canvas by my code above.
QUESTION 1: Is there a way to get the TalkBack to say something out loud when the textview and bitmaps are clicked upon? - I have tried setting contentDescriptions and focusable for the textviews and bitmaps but this does not make any difference.
QUESTION 2: An alternative is to get TalkBack to read out something when the custom view is displayed and this text can summarize all the coachmarks displayed in the screen. I can not work out how to do this, does anyone have any suggestions? - I have tried setting my customView to be focusable (setFocasable(true) and give it a contentDescription but this does not work. - I have tried instigating an action when the custom view is drawn and then adding a content description to the event but this does not work either, i.e.
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
}
@Override
public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
// this is not read out load when the view is displayed, but is read when the view is pressed
info.setContentDescription("on Initialize Accessibility Node Info User Tips");
}
I've recently been wrestling with a similar problem.
The short answer is to use View.announceForAccessibility(text)
when you want TalkBack to be triggered, assuming that you are using Android API 16 or later - see Android docs.
However, if you want to support earlier Android APIs, there is a more-involved answer using View.requestFocus()
, which I have outlined here: Android: How to force Explore-By-Touch/Talkback to repeat the ContentDescription of the current View in AccessibilityFocus?
I also suggest you have a look at a couple of bugs I raised against Google's Eyes-Free code, which might save you some wasted effort: