I am trying to fire a custom AccessibilityEvent
using the AccessibilityManager and TalkBack.
The use case for the event is when the user clicks an action bar, the fragment polls a list of objects, and then fashions its AccessibilityEvent content based on the size of a list.
When I try to run this, I do not get the expected TalkBack message. I am pretty sure that I'm missing something basic with instantiating an AccessibilityEvent.
I am also not sure whether I need to use, or how to apply AccessibilityDelegate
s here because the callback is coming from a MenuItem
rather than a View
. I know I can call findViewById
to get the view for this MenuItem, but I am not very knowledgeable on these APIs.
Any guidance on these two points would be great!
The problem in question is described basically by the following pseudocode:
public class MyFragment extends Fragment {
//...
private List<Pojo> mPojoList;
//...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.the_id_for_my_menuitem) {
if (booleanCheck() && !mPojoList.isEmpty()) {
//create the Accessibility event
final AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_CLICKED);
event.setContentDescription(String.format("deleting %2d pojos", mPojoList.size()));
//Send a custom accessibility event to let the user know that we're deleting X objects.
final AccessibilityManager mgr = (AccessibilityManager) this.getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
//PROBLEM: We're not seeing this event come through in TalkBack.
mgr.sendAccessibilityEvent(event);
//Delete the objects.
myDeleteObjectsFunction();
}
}
}}