AccessibilityNodeProviderCompat

Added in 1.1.0

public class AccessibilityNodeProviderCompat


Helper for accessing android.view.accessibility.AccessibilityNodeProvider.

Consider using a , a utility extension of AccessibilityNodeProvider, to simplify many aspects of providing information to accessibility services and managing accessibility focus.

Summary

Constants

static final int

The virtual id for the hosting View.

Public constructors

Creates a new instance.

Creates a new instance wrapping an android.view.accessibility.AccessibilityNodeProvider.

Public methods

void
addExtraDataToAccessibilityNodeInfo(
    int virtualViewId,
    @NonNull AccessibilityNodeInfoCompat info,
    @NonNull String extraDataKey,
    @Nullable Bundle arguments
)

Adds extra data to an AccessibilityNodeInfoCompat based on an explicit request for the additional data.

@Nullable AccessibilityNodeInfoCompat
createAccessibilityNodeInfo(int virtualViewId)

Returns an AccessibilityNodeInfoCompat representing a virtual view, i.e. a descendant of the host View, with the given virtualViewId or the host View itself if virtualViewId equals to HOST_VIEW_ID.

@Nullable List<AccessibilityNodeInfoCompat>
findAccessibilityNodeInfosByText(@NonNull String text, int virtualViewId)

Finds AccessibilityNodeInfoCompats by text.

@Nullable AccessibilityNodeInfoCompat
findFocus(int focus)

Find the virtual view, i.e. a descendant of the host View, that has the specified focus type.

@Nullable Object
boolean
performAction(int virtualViewId, int action, @Nullable Bundle arguments)

Performs an accessibility action on a virtual view, i.e. a descendant of the host View, with the given virtualViewId or the host View itself if virtualViewId equals to HOST_VIEW_ID.

Constants

HOST_VIEW_ID

Added in 1.1.0
public static final int HOST_VIEW_ID = -1

The virtual id for the hosting View.

Public constructors

AccessibilityNodeProviderCompat

Added in 1.1.0
public AccessibilityNodeProviderCompat()

Creates a new instance.

AccessibilityNodeProviderCompat

Added in 1.1.0
public AccessibilityNodeProviderCompat(@Nullable Object provider)

Creates a new instance wrapping an android.view.accessibility.AccessibilityNodeProvider.

Parameters
@Nullable Object provider

The provider.

Public methods

addExtraDataToAccessibilityNodeInfo

Added in 1.5.0
public void addExtraDataToAccessibilityNodeInfo(
    int virtualViewId,
    @NonNull AccessibilityNodeInfoCompat info,
    @NonNull String extraDataKey,
    @Nullable Bundle arguments
)

Adds extra data to an AccessibilityNodeInfoCompat based on an explicit request for the additional data.

This method only needs to be implemented if a virtual view offers to provide additional data.

Parameters
int virtualViewId

The virtual view id used to create the node

@NonNull AccessibilityNodeInfoCompat info

The info to which to add the extra data

@NonNull String extraDataKey

A key specifying the type of extra data to add to the info. The extra data should be added to the Bundle returned by the info's getExtras method.

@Nullable Bundle arguments

A Bundle holding any arguments relevant for this request.

createAccessibilityNodeInfo

Added in 1.1.0
public @Nullable AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId)

Returns an AccessibilityNodeInfoCompat representing a virtual view, i.e. a descendant of the host View, with the given virtualViewId or the host View itself if virtualViewId equals to HOST_VIEW_ID.

A virtual descendant is an imaginary View that is reported as a part of the view hierarchy for accessibility purposes. This enables custom views that draw complex content to report them selves as a tree of virtual views, thus conveying their logical structure.

The implementer is responsible for obtaining an accessibility node info from the pool of reusable instances and setting the desired properties of the node info before returning it.

Parameters
int virtualViewId

A client defined virtual view id.

Returns
@Nullable AccessibilityNodeInfoCompat

A populated AccessibilityNodeInfoCompat for a virtual descendant or the host View.

findAccessibilityNodeInfosByText

Added in 1.1.0
public @Nullable List<AccessibilityNodeInfoCompatfindAccessibilityNodeInfosByText(@NonNull String text, int virtualViewId)

Finds AccessibilityNodeInfoCompats by text. The match is case insensitive containment. The search is relative to the virtual view, i.e. a descendant of the host View, with the given virtualViewId or the host View itself virtualViewId equals to HOST_VIEW_ID.

Parameters
@NonNull String text

The searched text.

int virtualViewId

A client defined virtual view id which defined the root of the tree in which to perform the search.

Returns
@Nullable List<AccessibilityNodeInfoCompat>

A list of node info.

findFocus

Added in 1.1.0
public @Nullable AccessibilityNodeInfoCompat findFocus(int focus)

Find the virtual view, i.e. a descendant of the host View, that has the specified focus type.

Parameters
int focus

The focus to find. One of FOCUS_INPUT or FOCUS_ACCESSIBILITY.

Returns
@Nullable AccessibilityNodeInfoCompat

The node info of the focused view or null.

performAction

Added in 1.1.0
public boolean performAction(int virtualViewId, int action, @Nullable Bundle arguments)

Performs an accessibility action on a virtual view, i.e. a descendant of the host View, with the given virtualViewId or the host View itself if virtualViewId equals to HOST_VIEW_ID.

Parameters
int virtualViewId

A client defined virtual view id.

int action

The action to perform.

@Nullable Bundle arguments

Optional arguments.

Returns
boolean

True if the action was performed.