Udostępnij za pośrednictwem


AccessibilityNodeProvider Class

Definition

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.

[Android.Runtime.Register("android/view/accessibility/AccessibilityNodeProvider", DoNotGenerateAcw=true)]
public abstract class AccessibilityNodeProvider : Java.Lang.Object
[<Android.Runtime.Register("android/view/accessibility/AccessibilityNodeProvider", DoNotGenerateAcw=true)>]
type AccessibilityNodeProvider = class
    inherit Object
Inheritance
AccessibilityNodeProvider
Attributes

Remarks

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. </p>

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 View#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:

<div> <div class="ds-selector-tabs"><section><h3 id="kotlin">Kotlin</h3>

// "view" is the View instance on which this class performs accessibility functions.
            class MyCalendarViewAccessibilityDelegate(
                  private var view: MyCalendarView) : AccessibilityDelegate() {
                override fun getAccessibilityNodeProvider(host: View): AccessibilityNodeProvider {
                    return object : AccessibilityNodeProvider() {
                        override fun createAccessibilityNodeInfo(virtualViewId: Int):
                                AccessibilityNodeInfo? {
                            when (virtualViewId) {
<var>host-view-id</var> -&gt; {
                                    val node = AccessibilityNodeInfo.obtain(view)
                                    node.addChild(view, <var>child-view-id</var>)
                                    // Set other attributes like screenReaderFocusable
                                    // and contentDescription.
                                    return node
                                }
<var>child-view-id</var> -&gt; {
                                    val node = AccessibilityNodeInfo
                                            .obtain(view, virtualViewId)
                                    node.setParent(view)
                                    node.addAction(ACTION_SCROLL_UP)
                                    node.addAction(ACTION_SCROLL_DOWN)
                                    // Set other attributes like focusable and visibleToUser.
                                    node.setBoundsInScreen(
                                            Rect(<var>coords-of-edges-relative-to-screen</var>))
                                    return node
                                }
                                else -&gt; return null
                            }
                        }

                        override fun performAction(
                            virtualViewId: Int,
                            action: Int,
                            arguments: Bundle
                        ): Boolean {
                            if (virtualViewId == <var>host-view-id</var>) {
                                return view.performAccessibilityAction(action, arguments)
                            }
                            when (action) {
                                ACTION_SCROLL_UP.id -&gt; {
                                    // Implement logic in a separate method.
                                    navigateToPreviousMonth()

                                    return true
                                }
                                ACTION_SCROLL_DOWN.id -&gt;
                                    // Implement logic in a separate method.
                                    navigateToNextMonth()

                                    return true
                                else -&gt; return false
                            }
                        }
                    }
                }
            }

</section><section><h3 id="java">Java</h3>

final class MyCalendarViewAccessibilityDelegate extends AccessibilityDelegate {
                // The View instance on which this class performs accessibility functions.
                private final MyCalendarView view;

                MyCalendarViewAccessibilityDelegate(MyCalendarView view) {
                    this.view = view;
                }

                &#64;Override
                public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) {
                    return new AccessibilityNodeProvider() {
                        &#64;Override
                        &#64;Nullable
                        public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
                            if (virtualViewId == <var>host-view-id</var>) {
                                AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain(view);
                                node.addChild(view, <var>child-view-id</var>);
                                // Set other attributes like screenReaderFocusable and contentDescription.
                                return node;
                            } else if (virtualViewId == <var>child-view-id</var>) {
                                AccessibilityNodeInfo node =
                                    AccessibilityNodeInfo.obtain(view, virtualViewId);
                                node.setParent(view);
                                node.addAction(ACTION_SCROLL_UP);
                                node.addAction(ACTION_SCROLL_DOWN);
                                // Set other attributes like focusable and visibleToUser.
                                node.setBoundsInScreen(
                                    new Rect(<var>coordinates-of-edges-relative-to-screen</var>));
                                return node;
                            } else {
                                return null;
                            }
                        }

                        &#64;Override
                        public boolean performAction(int virtualViewId, int action, Bundle arguments) {
                            if (virtualViewId == <var>host-view-id</var>) {
                                return view.performAccessibilityAction(action, arguments);
                            }

                            if (action == ACTION_SCROLL_UP.getId()) {
                                // Implement logic in a separate method.
                                navigateToPreviousMonth();

                                return true;
                            } else if (action == ACTION_SCROLL_DOWN.getId()) {
                                // Implement logic in a separate method.
                                navigateToNextMonth();

                                return true;
                            } else {
                                return false;
                            }
                        }
                    };
                }
            }

</section></div></div>

Java documentation for android.view.accessibility.AccessibilityNodeProvider.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

AccessibilityNodeProvider()
AccessibilityNodeProvider(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

HostViewId

The virtual id for the hosting View.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

AddExtraDataToAccessibilityNodeInfo(Int32, AccessibilityNodeInfo, String, Bundle)

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

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CreateAccessibilityNodeInfo(Int32)

Returns an AccessibilityNodeInfo representing a virtual view, such as a descendant of the host View, with the given virtualViewId or the host View itself if virtualViewId equals to #HOST_VIEW_ID.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
FindAccessibilityNodeInfosByText(String, Int32)

Finds AccessibilityNodeInfos by text.

FindFocus(NodeFocus)

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

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
PerformAction(Int32, Action, Bundle)

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

PerformAction(Int32, GlobalAction, Bundle)

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 HostViewId.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to