Class AccessibilityBridge
An AccessibilityBridge requires:
- A real Android
View, called therootAccessibilityView, which contains a Flutter UI. TherootAccessibilityViewis required at the time ofAccessibilityBridge's instantiation and is held for the duration ofAccessibilityBridge's lifespan.AccessibilityBridgeinvokes various accessibility methods on therootAccessibilityView, e.g.,View.onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo). TherootAccessibilityViewis expected to notify theAccessibilityBridgeof relevant interactions:onAccessibilityHoverEvent(MotionEvent),reset(),updateSemantics(ByteBuffer, String[], ByteBuffer[]), andupdateCustomAccessibilityActions(ByteBuffer, String[]) - An
AccessibilityChannelthat is connected to the running Flutter app. - Android's
AccessibilityManagerto query and listen for accessibility settings. - Android's
ContentResolverto listen for changes to system animation settings.
AccessibilityBridge causes Android to treat Flutter SemanticsNodes as if they
were accessible Android Views. Accessibility requests may be sent from a Flutter widget
to the Android OS, as if it were an Android View, and accessibility events may be
consumed by a Flutter widget, as if it were an Android View. AccessibilityBridge
refers to Flutter's accessible widgets as "virtual views" and identifies them with "virtual view
IDs".-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfaceListener that can be set on aAccessibilityBridge, which is invoked any time accessibility is turned on/off, or touch exploration is turned on/off. -
Field Summary
Fields inherited from class android.view.accessibility.AccessibilityNodeProvider
HOST_VIEW_ID -
Constructor Summary
ConstructorsConstructorDescriptionAccessibilityBridge(View rootAccessibilityView, AccessibilityChannel accessibilityChannel, AccessibilityManager accessibilityManager, ContentResolver contentResolver, PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) AccessibilityBridge(View rootAccessibilityView, AccessibilityChannel accessibilityChannel, AccessibilityManager accessibilityManager, ContentResolver contentResolver, io.flutter.view.AccessibilityViewEmbedder accessibilityViewEmbedder, PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) -
Method Summary
Modifier and TypeMethodDescriptioncreateAccessibilityNodeInfo(int virtualViewId) ReturnsAccessibilityNodeInfofor the view corresponding to the givenvirtualViewId.booleanexternalViewRequestSendAccessibilityEvent(View embeddedView, View eventOrigin, AccessibilityEvent event) Delegates handling ofViewParent.requestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent)to the accessibility bridge.findFocus(int focus) Finds the view in a hierarchy that currently has the given type offocus.booleanintbooleanReturns true if the Android OS currently has accessibility enabled, false otherwise.booleanReturns true if the Android OS currently has touch exploration enabled, false otherwise.obtainAccessibilityEvent(int eventType) obtainAccessibilityNodeInfo(View rootView) obtainAccessibilityNodeInfo(View rootView, int virtualViewId) booleanbooleanonAccessibilityHoverEvent(MotionEvent event, boolean ignorePlatformViews) booleanperformAction(int virtualViewId, int accessibilityAction, Bundle arguments) Instructs the view represented byvirtualViewIdto carry out the desiredaccessibilityAction, perhaps configured by additionalarguments.voidrelease()Disconnects any listeners and/or delegates that were initialized inAccessibilityBridge's constructor, or added after.voidreset()Resets theAccessibilityBridge: ClearsflutterSemanticsTree, the Android cache of Flutter's semantics tree Releases focus on any activeaccessibilityFocusedSemanticsNodeClears any hoveredSemanticsNodeSends aAccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGEDeventvoidsendAccessibilityEvent(int viewId, int eventType) Sends an accessibility event of the giveneventTypeto Android's accessibility system with the givenviewIdrepresented as the source of the event.voidSets a listener on thisAccessibilityBridge, which is notified whenever accessibility activation, or touch exploration activation changes.Methods inherited from class android.view.accessibility.AccessibilityNodeProvider
addExtraDataToAccessibilityNodeInfo, findAccessibilityNodeInfosByText
-
Constructor Details
-
AccessibilityBridge
public AccessibilityBridge(@NonNull View rootAccessibilityView, @NonNull AccessibilityChannel accessibilityChannel, @NonNull AccessibilityManager accessibilityManager, @NonNull ContentResolver contentResolver, @NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) -
AccessibilityBridge
@VisibleForTesting public AccessibilityBridge(@NonNull View rootAccessibilityView, @NonNull AccessibilityChannel accessibilityChannel, @NonNull AccessibilityManager accessibilityManager, @NonNull ContentResolver contentResolver, @NonNull io.flutter.view.AccessibilityViewEmbedder accessibilityViewEmbedder, @NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate)
-
-
Method Details
-
getHoveredObjectId
@VisibleForTesting public int getHoveredObjectId() -
release
public void release()Disconnects any listeners and/or delegates that were initialized inAccessibilityBridge's constructor, or added after.Do not use this instance after invoking
release. The behavior of any method invoked on thisAccessibilityBridgeafter invokingrelease()is undefined. -
isAccessibilityEnabled
public boolean isAccessibilityEnabled()Returns true if the Android OS currently has accessibility enabled, false otherwise. -
isTouchExplorationEnabled
public boolean isTouchExplorationEnabled()Returns true if the Android OS currently has touch exploration enabled, false otherwise. -
setOnAccessibilityChangeListener
public void setOnAccessibilityChangeListener(@Nullable AccessibilityBridge.OnAccessibilityChangeListener listener) Sets a listener on thisAccessibilityBridge, which is notified whenever accessibility activation, or touch exploration activation changes. -
obtainAccessibilityNodeInfo
-
obtainAccessibilityNodeInfo
@VisibleForTesting public AccessibilityNodeInfo obtainAccessibilityNodeInfo(View rootView, int virtualViewId) -
createAccessibilityNodeInfo
ReturnsAccessibilityNodeInfofor the view corresponding to the givenvirtualViewId.This method is invoked by Android's accessibility system when Android needs accessibility info for a given view.
When a
virtualViewIdofView.NO_IDis requested, accessibility node info is returned for ourrootAccessibilityView. Otherwise, Flutter's semantics tree, represented byflutterSemanticsTree, is searched for aAccessibilityBridge.SemanticsNodewith the givenvirtualViewId. If no suchAccessibilityBridge.SemanticsNodeis found, then this method returns null. If the desiredAccessibilityBridge.SemanticsNodeis found, then anAccessibilityNodeInfois obtained from therootAccessibilityView, filled with appropriate info, and then returned.Depending on the type of Flutter
SemanticsNodethat is requested, the returnedAccessibilityNodeInfopretends that theSemanticsNodein question comes from a specialize Android view, e.g.,AccessibilityBridge.Flag.IS_TEXT_FIELDmaps toandroid.widget.EditText,AccessibilityBridge.Flag.IS_BUTTONmaps toandroid.widget.Button, andAccessibilityBridge.Flag.IS_IMAGEmaps toandroid.widget.ImageView. In the case that no specialized view applies, the returnedAccessibilityNodeInfopretends that it represents aandroid.view.View.- Overrides:
createAccessibilityNodeInfoin classAccessibilityNodeProvider
-
performAction
public boolean performAction(int virtualViewId, int accessibilityAction, @Nullable Bundle arguments) Instructs the view represented byvirtualViewIdto carry out the desiredaccessibilityAction, perhaps configured by additionalarguments.This method is invoked by Android's accessibility system. This method returns true if the desired
SemanticsNodewas found and was capable of performing the desired action, false otherwise.In a traditional Android app, the given view ID refers to a
Viewwithin an AndroidViewhierarchy. Flutter does not have an AndroidViewhierarchy, therefore the given view ID is avirtualViewIdthat refers to aSemanticsNodewithin a Flutter app. The given arguments of this method are forwarded from Android to Flutter.- Overrides:
performActionin classAccessibilityNodeProvider
-
findFocus
Finds the view in a hierarchy that currently has the given type offocus.This method is invoked by Android's accessibility system.
Flutter does not have an Android
Viewhierarchy. Therefore, Flutter conceptually handles this request by searching its semantics tree for the givenfocus, represented byflutterSemanticsTree. In practice, thisAccessibilityBridgealways caches any activeaccessibilityFocusedSemanticsNodeandinputFocusedSemanticsNode. Therefore, no searching is necessary. This method directly inspects the givenfocustype to return one of the cached nodes, null if the cached node is null, or null if a differentfocustype is requested.- Overrides:
findFocusin classAccessibilityNodeProvider
-
onAccessibilityHoverEvent
A hoverMotionEventhas occurred in theViewthat corresponds to thisAccessibilityBridge.This method returns true if Flutter's accessibility system handled the hover event, false otherwise.
This method should be invoked from the corresponding
View'sView.onHoverEvent(MotionEvent). -
onAccessibilityHoverEvent
A hoverMotionEventhas occurred in theViewthat corresponds to thisAccessibilityBridge.If
ignorePlatformViewsis true, if hit testing for the event finds a platform view, the event will not be handled. This is useful when handling accessibility events for views overlaying platform views. SeePlatformOverlayViewfor details.This method returns true if Flutter's accessibility system handled the hover event, false otherwise.
This method should be invoked from the corresponding
View'sView.onHoverEvent(MotionEvent). -
sendAccessibilityEvent
@VisibleForTesting public void sendAccessibilityEvent(int viewId, int eventType) Sends an accessibility event of the giveneventTypeto Android's accessibility system with the givenviewIdrepresented as the source of the event.The given
viewIdmay either belong torootAccessibilityView, or any FlutterAccessibilityBridge.SemanticsNode. -
obtainAccessibilityEvent
-
reset
public void reset()Resets theAccessibilityBridge:- Clears
flutterSemanticsTree, the Android cache of Flutter's semantics tree - Releases focus on any active
accessibilityFocusedSemanticsNode - Clears any hovered
SemanticsNode - Sends a
AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGEDevent
- Clears
-
externalViewRequestSendAccessibilityEvent
public boolean externalViewRequestSendAccessibilityEvent(View embeddedView, View eventOrigin, AccessibilityEvent event) Delegates handling ofViewParent.requestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent)to the accessibility bridge.This is used by embedded platform views to propagate accessibility events from their view hierarchy to the accessibility bridge.
As the embedded view doesn't have to be the only View in the embedded hierarchy (it can have child views) and the event might have been originated from any view in this hierarchy, this method gets both a reference to the embedded platform view, and a reference to the view from its hierarchy that sent the event.
- Parameters:
embeddedView- the embedded platform view for which the event is delegatedeventOrigin- the view in the embedded view's hierarchy that sent the event.- Returns:
- True if the event was sent.
-