Search code examples
androidaccessibilitytalkback

Interrupt current TalkBack readout and begin new one?


I have a reorderable RecyclerView and every time you move an item below or above another item, TalkBack will read out:

"Moved ItemTitle above item 2".

The problem is that it queues all these readouts and executes them all. So if you move an item from position 12 to position 1 really quickly, it will say:

"Moved ItemTitle above item 12. Moved ItemTitle above item 11. Moved ItemTitle above item 10. Moved ItemTitle above item 9..."

How do I tell it to stop the current readout, clear the queue and just read the most recent announcement?

This is the method which fires every time a RecyclerView item is dragged above or below another item.

@Override
public boolean onItemMove(int fromPosition, int toPosition) {

    String direction = fromPosition < toPosition ? "below" : "above";
    String title1 = viewModel.get(fromPosition).getItemTitle();
    String title2 = viewModel.get(toPosition)).getItemTitle();

    // these announcements are queued 
    view.announceForAccessibility(view.getContext().getString(R.string.on_move_draggable_item_announce, title1, direction, title2));

    return true;
}

Solution

  • Do this:

    ((AccessibilityManager) view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).interrupt();
    

    Before you announce like this:

    view.announceForAccessibility(announcementMessage);