public class AccessibilityBridge extends AccessibilityNodeProvider
AccessibilityBridge
requires:
View
, called the rootAccessibilityView
, which contains a
Flutter UI. The rootAccessibilityView
is required at the time of
AccessibilityBridge
's instantiation and is held for the duration of
AccessibilityBridge
's lifespan. AccessibilityBridge
invokes various
accessibility methods on the rootAccessibilityView
, e.g.,
View.onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)
. The
rootAccessibilityView
is expected to notify the AccessibilityBridge
of
relevant interactions: onAccessibilityHoverEvent(MotionEvent)
, reset()
,
updateSemantics(ByteBuffer, String[])
, and updateCustomAccessibilityActions(ByteBuffer, String[])
AccessibilityChannel
that is connected to the running Flutter app.AccessibilityManager
to query and listen for accessibility settings.ContentResolver
to listen for changes to system animation settings.AccessibilityBridge
causes Android to treat Flutter SemanticsNode
s as if
they were accessible Android View
s. 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".Modifier and Type | Class and Description |
---|---|
static class |
AccessibilityBridge.Action |
static interface |
AccessibilityBridge.OnAccessibilityChangeListener
Listener that can be set on a
AccessibilityBridge , which is invoked any time
accessibility is turned on/off, or touch exploration is turned on/off. |
HOST_VIEW_ID
Constructor and Description |
---|
AccessibilityBridge(View rootAccessibilityView,
AccessibilityChannel accessibilityChannel,
AccessibilityManager accessibilityManager,
ContentResolver contentResolver,
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) |
Modifier and Type | Method and Description |
---|---|
AccessibilityNodeInfo |
createAccessibilityNodeInfo(int virtualViewId)
Returns
AccessibilityNodeInfo for the view corresponding to the given virtualViewId . |
boolean |
externalViewRequestSendAccessibilityEvent(View embeddedView,
View eventOrigin,
AccessibilityEvent event)
Delegates handling of
ViewParent.requestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent) to the accessibility bridge. |
AccessibilityNodeInfo |
findFocus(int focus)
Finds the view in a hierarchy that currently has the given type of
focus . |
boolean |
isAccessibilityEnabled()
Returns true if the Android OS currently has accessibility enabled, false otherwise.
|
boolean |
isTouchExplorationEnabled()
Returns true if the Android OS currently has touch exploration enabled, false otherwise.
|
boolean |
onAccessibilityHoverEvent(MotionEvent event)
|
boolean |
performAction(int virtualViewId,
int accessibilityAction,
Bundle arguments)
Instructs the view represented by
virtualViewId to carry out the desired accessibilityAction ,
perhaps configured by additional arguments . |
void |
release()
Disconnects any listeners and/or delegates that were initialized in
AccessibilityBridge 's
constructor, or added after. |
void |
reset()
Resets the
AccessibilityBridge :
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_CHANGED event
|
void |
setOnAccessibilityChangeListener(AccessibilityBridge.OnAccessibilityChangeListener listener)
Sets a listener on this
AccessibilityBridge , which is notified whenever accessibility
activation, or touch exploration activation changes. |
addExtraDataToAccessibilityNodeInfo, findAccessibilityNodeInfosByText
public AccessibilityBridge(@NonNull View rootAccessibilityView, @NonNull AccessibilityChannel accessibilityChannel, @NonNull AccessibilityManager accessibilityManager, @NonNull ContentResolver contentResolver, PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate)
public void release()
AccessibilityBridge
's
constructor, or added after.
Do not use this instance after invoking release
. The behavior of any method invoked
on this AccessibilityBridge
after invoking release()
is undefined.public boolean isAccessibilityEnabled()
public boolean isTouchExplorationEnabled()
public void setOnAccessibilityChangeListener(@Nullable AccessibilityBridge.OnAccessibilityChangeListener listener)
AccessibilityBridge
, which is notified whenever accessibility
activation, or touch exploration activation changes.public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId)
AccessibilityNodeInfo
for the view corresponding to the given virtualViewId
.
This method is invoked by Android's accessibility system when Android needs accessibility info
for a given view.
When a virtualViewId
of View.NO_ID
is requested, accessibility node info is
returned for our rootAccessibilityView
. Otherwise, Flutter's semantics tree,
represented by flutterSemanticsTree
, is searched for a SemanticsNode
with
the given virtualViewId
. If no such SemanticsNode
is found, then this method
returns null. If the desired SemanticsNode
is found, then an AccessibilityNodeInfo
is obtained from the rootAccessibilityView
, filled with appropriate info, and then
returned.
Depending on the type of Flutter SemanticsNode
that is requested, the returned
AccessibilityNodeInfo
pretends that the SemanticsNode
in question comes from
a specialize Android view, e.g., Flag#IS_TEXT_FIELD
maps to android.widget.EditText
,
Flag#IS_BUTTON
maps to android.widget.Button
, and Flag#IS_IMAGE
maps
to android.widget.ImageView
. In the case that no specialized view applies, the
returned AccessibilityNodeInfo
pretends that it represents a android.view.View
.createAccessibilityNodeInfo
in class AccessibilityNodeProvider
public boolean performAction(int virtualViewId, int accessibilityAction, @Nullable Bundle arguments)
virtualViewId
to carry out the desired accessibilityAction
,
perhaps configured by additional arguments
.
This method is invoked by Android's accessibility system. This method returns true if the
desired SemanticsNode
was found and was capable of performing the desired action,
false otherwise.
In a traditional Android app, the given view ID refers to a View
within an Android
View
hierarchy. Flutter does not have an Android View
hierarchy, therefore
the given view ID is a virtualViewId
that refers to a SemanticsNode
within
a Flutter app. The given arguments of this method are forwarded from Android to Flutter.performAction
in class AccessibilityNodeProvider
public AccessibilityNodeInfo findFocus(int focus)
focus
.
This method is invoked by Android's accessibility system.
Flutter does not have an Android View
hierarchy. Therefore, Flutter conceptually
handles this request by searching its semantics tree for the given focus
, represented
by flutterSemanticsTree
. In practice, this AccessibilityBridge
always
caches any active accessibilityFocusedSemanticsNode
and inputFocusedSemanticsNode
.
Therefore, no searching is necessary. This method directly inspects the given focus
type to return one of the cached nodes, null if the cached node is null, or null if a different
focus
type is requested.findFocus
in class AccessibilityNodeProvider
public boolean onAccessibilityHoverEvent(MotionEvent event)
MotionEvent
has occurred in the View
that corresponds to this
AccessibilityBridge
.
This method returns true if Flutter's accessibility system handled the hover event, false
otherwise.
This method should be invoked from the corresponding View
's
View.onHoverEvent(MotionEvent)
.public void reset()
AccessibilityBridge
:
flutterSemanticsTree
, the Android cache of Flutter's semantics treeaccessibilityFocusedSemanticsNode
SemanticsNode
AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
eventpublic boolean externalViewRequestSendAccessibilityEvent(View embeddedView, View eventOrigin, AccessibilityEvent event)
ViewParent.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.embeddedView
- the embedded platform view for which the event is delegatedeventOrigin
- the view in the embedded view's hierarchy that sent the event.