Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to get talkBack to read text when RelativeLayout is displayed

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

  • when this coach mark view is displayed nothing is read out loud for this view
  • If the user presses where the textviews and bitmaps are, nothing is read out loud

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");
}
like image 733
se22as Avatar asked Aug 12 '14 14:08

se22as


People also ask

Do gestures down then right to open TalkBack menu?

If you get the TalkBack menu: Your device supports both multi-finger gestures and one-finger gestures. If you don't get the TalkBack menu: Your device only supports one-finger gestures. To open the TalkBack menu, swipe down then right, or swipe up and right.

What is TalkBack menu?

The TalkBack menu includes these options by default: Read from next item: From the last focused item, hear the items on the screen. Copy last spoken phrase: Copy the last spoken phrase. Then, you can paste it in another app or take other actions on it.

How do I know if TalkBack is enabled Android?

More details: if you are strictly interested in whether TalkBack is enabled, use am. isTouchExplorationEnabled() . (If Select to Speak is enabled and TalkBack disabled, am. isEnabled() will still return true.)


1 Answers

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:

  • [TalkBack] Explore By Touch event does not pass through SeekBar's AccessibilityEvent handling methods
  • [TalkBack] AccessibilityEvents ignored when source is not set, and no way to set it
like image 103
AwayTeam Avatar answered Sep 19 '22 04:09

AwayTeam