Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid TalkBack from reading dismissed fragment

I'm developing a simple app that is structured in Activities and Fragments, one of the requirements its to make it accessible so I did all the content decriptions, navigaction, focus, etc.

And it works great, except with fragments, if there is an activity that loads a fragment the talkback reads its content, then the user clicks on something and a detail fragment that could be added on top of the stack.

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
audios = AudiosListFragment.newInstance(params);
ft.add(R.id.audios_fragment_holder, audios);
ft.commit();

If the user keeps navigating talkback still remember the position of each element of the missing fragment.

Is there any way to clear the Accessibility list of events and force it to get it again? Accesibility manager does not seem to have any method for that.

AccessibilityManager manager = (AccessibilityManager) getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
    manager.getAccessibilityServiceList();

-- EDITED -- Things that I've tried and did not work out.

Sending an event from the view creation in the fragment.

    AccessibilityEvent event =
    AccessibilityEvent.obtain(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
    AccessibilityDelegate delegate = new AccessibilityDelegate();
    v.setAccessibilityDelegate(delegate);
    delegate.dispatchPopulateAccessibilityEvent(container, event);

Interrupting all the pending texts on the onResume of the fragment.

 AccessibilityManager mgr = (AccessibilityManager)
 getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
 mgr.interrupt();

Requesting the decorator view to register an event of window_content_change or window_state_change.

 getWindow().getDecorView()
    .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

-- EDITED -- Made a DumpView Hierarchy and in there is no trace of the dismissed fragment, but talkback stills navigates it :(

Thanks, I hope someone can throw some light on this issue :)

Regards.

like image 611
Goofyahead Avatar asked May 19 '14 17:05

Goofyahead


2 Answers

https://medium.com/@guygriv/accessibility-and-fragment-transactions-1aef5596f9d4

I found this, which pretty resolved the problem without the need to use replace,

This link describes on Fragment BackStage change, Check this the fragment added is not the last fragment then set the Accessibility to IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS to disable hidden fragment accessibility otherwise for the fragment that is visible set Accessibility to IMPORTANT_FOR_ACCESSIBILITY_YEs

like image 84
Amit kumar Avatar answered Sep 18 '22 15:09

Amit kumar


The only way that I found so the fragments below don't get read is replacing them on the fragment transaction, which is a drawback cause you loose the state of that fragment...

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
BookDetailFragment book = BookDetailFragment.newInstance(id);
ft.replace(R.id.books_fragment_holder, book);
ft.addToBackStack(BookDetailFragment.TAG);
ft.commit();

Im going to keep looking on how to do this correctly.

like image 35
Goofyahead Avatar answered Sep 19 '22 15:09

Goofyahead