Most visited

Recently visited

Added in API level 16

AccessibilityNodeProvider

public abstract class AccessibilityNodeProvider
extends Object

java.lang.Object
   ↳ android.view.accessibility.AccessibilityNodeProvider


This class is the contract a client should implement to enable support of a virtual view hierarchy rooted at a given view for accessibility purposes. A virtual view hierarchy is a tree of imaginary Views that is reported as a part of the view hierarchy when an AccessibilityService explores the window content. Since the virtual View tree does not exist this class is responsible for managing the AccessibilityNodeInfos describing that tree to accessibility services.

The main use case of these APIs is to enable a custom view that draws complex content, for example a monthly calendar grid, to be presented as a tree of logical nodes, for example month days each containing events, thus conveying its logical structure.

A typical use case is to override getAccessibilityNodeProvider() of the View that is a root of a virtual View hierarchy to return an instance of this class. In such a case this instance is responsible for managing AccessibilityNodeInfos describing the virtual sub-tree rooted at the View including the one representing the View itself. Similarly the returned instance is responsible for performing accessibility actions on any virtual view or the root view itself. For example:

     getAccessibilityNodeProvider(
         if (mAccessibilityNodeProvider == null) {
             mAccessibilityNodeProvider = new AccessibilityNodeProvider() {
                 public boolean performAction(int action, int virtualDescendantId) {
                     // Implementation.
                     return false;
                 }

                 public List findAccessibilityNodeInfosByText(String text,
                         int virtualDescendantId) {
                     // Implementation.
                     return null;
                 }

                 public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualDescendantId) {
                     // Implementation.
                     return null;
                 }
             });
     return mAccessibilityNodeProvider;
 

Summary

Constants

int HOST_VIEW_ID

The virtual id for the hosting View.

Public constructors

AccessibilityNodeProvider()

Public methods

AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId)

Returns an AccessibilityNodeInfo representing a virtual view, i.e.

List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(String text, int virtualViewId)

Finds AccessibilityNodeInfos by text.

AccessibilityNodeInfo findFocus(int focus)

Find the virtual view, i.e.

boolean performAction(int virtualViewId, int action, Bundle arguments)

Performs an accessibility action on a virtual view, i.e.

Inherited methods

From class java.lang.Object

Constants

HOST_VIEW_ID

Added in API level 21
int HOST_VIEW_ID

The virtual id for the hosting View.

Constant Value: -1 (0xffffffff)

Public constructors

AccessibilityNodeProvider

Added in API level 16
AccessibilityNodeProvider ()

Public methods

createAccessibilityNodeInfo

Added in API level 16
AccessibilityNodeInfo createAccessibilityNodeInfo (int virtualViewId)

Returns an AccessibilityNodeInfo 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
virtualViewId int: A client defined virtual view id.
Returns
AccessibilityNodeInfo A populated AccessibilityNodeInfo for a virtual descendant or the host View.

See also:

findAccessibilityNodeInfosByText

Added in API level 16
List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText (String text, 
                int virtualViewId)

Finds AccessibilityNodeInfos 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
text String: The searched text.
virtualViewId int: A client defined virtual view id which defined the root of the tree in which to perform the search.
Returns
List<AccessibilityNodeInfo> A list of node info.

See also:

findFocus

Added in API level 19
AccessibilityNodeInfo findFocus (int focus)

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

Parameters
focus int: The focus to find. One of FOCUS_INPUT or FOCUS_ACCESSIBILITY.
Returns
AccessibilityNodeInfo The node info of the focused view or null.

See also:

performAction

Added in API level 16
boolean performAction (int virtualViewId, 
                int action, 
                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
virtualViewId int: A client defined virtual view id.
action int: The action to perform.
arguments Bundle: Optional action arguments.
Returns
boolean True if the action was performed.

See also:

Hooray!