I am trying to start custom AccessibilityEventusing AccessibilityManager and TalkBack.
A use case for an event is when the user clicks on the action bar, the fragment polls the list of objects, and then changes its AccessibilityEvent content based on the size of the list.
When I try to run this, I do not receive the expected TalkBack message. I'm sure I missed something basic by creating an instance of AccessibilityEvent.
I'm also not sure whether I need to use or how to apply AccessibilityDelegatehere, because the callback comes from MenuItem, not from View. I know that I can call findViewByIdto get an idea for this MenuItem, but I'm not very good at these APIs.
Any guidance on these two points would be great!
The problem in question is mainly described by the following pseudo-code:
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()) {
final AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_CLICKED);
event.setContentDescription(String.format("deleting %2d pojos", mPojoList.size()));
final AccessibilityManager mgr = (AccessibilityManager) this.getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
mgr.sendAccessibilityEvent(event);
myDeleteObjectsFunction();
}
}
}}
source
share