*bump*
I would have expected the framework to have some standard about what is
a word, line, character, etc. and for it to be sufficient for me to set
the text on a node and have those traversals supported.
I looked through the 4.1 sources, and it seems like this might happen on
an event's contentDescription. Why not on its text?
So I added the page's text to the contentDescription. I do this both in
onInitializeAccessibilityNodeInfo() and onPopulateAccessibilityEvent().
I added all granularities, as well as the traversal actions. I can get
the entire page of text read. I can select a granularity. I cannot then
navigate by that granularity.
I also tried populating the contentDescription of the view via
setContentDescription() before generating the event. I can't populate
that on view creation because I'm not certain what the text of the page
being displayed is until the event is needed. That didn't seem to work
either.
I just tried setting the node's text, and calling super() last. Neither
worked. I feel less like I'm working with an API and more like I'm
playing a game of Myst. Surely it shouldn't be *this* complicated to
implement text traversal?
Help a fella out? How do I support text traversal on a custom view that
descends from SurfaceView and, as such, has no concept of text?
Here's my code. Perhaps I'm doing more than I need to, but this is a
corner of the framework that isn't well-defined or documented.
@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
// Set the view's contentDescription then populate the event,
// seems like the only way to support text review. Putting it
// directly in the event doesn't support traversal.
PositionProperties props = doc.getPositionProps(null);
setContentDescription(props.pageText);
super.onPopulateAccessibilityEvent(event);
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo
node) {
super.onInitializeAccessibilityNodeInfo(node);
PositionProperties props = doc.getPositionProps(null);
node.setContentDescription(props.pageText);
if(VERSION.SDK_INT >= 16) {
node.setMovementGranularities(
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE |
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH
);
node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
node.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
node.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
node.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);