RecyclerViewAccessibilityDelegate.ItemDelegate

public class RecyclerViewAccessibilityDelegate.ItemDelegate extends AccessibilityDelegateCompat


The default implementation of accessibility delegate for the individual items of the RecyclerView.

If you are overriding RecyclerViewAccessibilityDelegate#getItemDelegate() but still want to keep some default behavior, you can create an instance of this class and delegate to the parent as necessary.

Summary

Public constructors

Creates an item delegate for the given RecyclerViewAccessibilityDelegate.

Public methods

boolean

Dispatches an AccessibilityEvent to the host View first and then to its children for adding their text content to the event.

@Nullable AccessibilityNodeProviderCompat

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.

void

Initializes an AccessibilityEvent with information about the the host View which is the event source.

void

Initializes an AccessibilityNodeInfoCompat with information about the host view.

void

Gives a chance to the host View to populate the accessibility event with its text content.

boolean

Called when a child of the host View has requested sending an AccessibilityEvent and gives an opportunity to the parent (the host) to augment the event.

boolean
performAccessibilityAction(
    @NonNull View host,
    int action,
    @Nullable Bundle args
)

Performs the specified accessibility action on the view.

void
sendAccessibilityEvent(@NonNull View host, int eventType)

Sends an accessibility event of the given type.

void

Sends an accessibility event.

Public constructors

ItemDelegate

Added in 1.0.0
public ItemDelegate(
    @NonNull RecyclerViewAccessibilityDelegate recyclerViewDelegate
)

Creates an item delegate for the given RecyclerViewAccessibilityDelegate.

Parameters
@NonNull RecyclerViewAccessibilityDelegate recyclerViewDelegate

The parent RecyclerView's accessibility delegate.

Public methods

dispatchPopulateAccessibilityEvent

public boolean dispatchPopulateAccessibilityEvent(
    @NonNull View host,
    @NonNull AccessibilityEvent event
)

Dispatches an AccessibilityEvent to the host View first and then to its children for adding their text content to the event.

The default implementation behaves as View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

@NonNull AccessibilityEvent event

The event.

Returns
boolean

True if the event population was completed.

See also
dispatchPopulateAccessibilityEvent

View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)

getAccessibilityNodeProvider

public @Nullable AccessibilityNodeProviderCompat getAccessibilityNodeProvider(@NonNull View host)

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.

The default implementation behaves as ViewCompat#getAccessibilityNodeProvider(View) for the case of no accessibility delegate been set.

Returns
@Nullable AccessibilityNodeProviderCompat

The provider.

onInitializeAccessibilityEvent

public void onInitializeAccessibilityEvent(
    @NonNull View host,
    @NonNull AccessibilityEvent event
)

Initializes an AccessibilityEvent with information about the the host View which is the event source.

The default implementation behaves as ViewCompat#onInitalizeAccessibilityEvent(View v, AccessibilityEvent event) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

@NonNull AccessibilityEvent event

The event to initialize.

See also
onInitializeAccessibilityEvent

ViewCompat#onInitializeAccessibilityEvent(View, AccessibilityEvent)

onInitializeAccessibilityNodeInfo

public void onInitializeAccessibilityNodeInfo(
    @NonNull View host,
    @NonNull AccessibilityNodeInfoCompat info
)

Initializes an AccessibilityNodeInfoCompat with information about the host view.

The default implementation behaves as ViewCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

@NonNull AccessibilityNodeInfoCompat info

The instance to initialize.

See also
onInitializeAccessibilityNodeInfo

ViewCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat)

onPopulateAccessibilityEvent

public void onPopulateAccessibilityEvent(
    @NonNull View host,
    @NonNull AccessibilityEvent event
)

Gives a chance to the host View to populate the accessibility event with its text content.

The default implementation behaves as ViewCompat#onPopulateAccessibilityEvent(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

@NonNull AccessibilityEvent event

The accessibility event which to populate.

See also
onPopulateAccessibilityEvent

ViewCompat#onPopulateAccessibilityEvent(View, AccessibilityEvent)

onRequestSendAccessibilityEvent

public boolean onRequestSendAccessibilityEvent(
    @NonNull ViewGroup host,
    @NonNull View child,
    @NonNull AccessibilityEvent event
)

Called when a child of the host View has requested sending an AccessibilityEvent and gives an opportunity to the parent (the host) to augment the event.

The default implementation behaves as ViewGroupCompat#onRequestSendAccessibilityEvent(ViewGroup, View, AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
@NonNull ViewGroup host

The View hosting the delegate.

@NonNull View child

The child which requests sending the event.

@NonNull AccessibilityEvent event

The event to be sent.

Returns
boolean

True if the event should be sent

See also
onRequestSendAccessibilityEvent

ViewGroupCompat#onRequestSendAccessibilityEvent(ViewGroup, View, AccessibilityEvent)

performAccessibilityAction

public boolean performAccessibilityAction(
    @NonNull View host,
    int action,
    @Nullable Bundle args
)

Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfoCompat.

The default implementation behaves as View#performAccessibilityAction(int, Bundle) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

View on which to perform the action.

int action

The action to perform.

@Nullable Bundle args

Optional action arguments.

Returns
boolean

Whether the action was performed.

See also
performAccessibilityAction

View#performAccessibilityAction(int, Bundle)

sendAccessibilityEvent

public void sendAccessibilityEvent(@NonNull View host, int eventType)

Sends an accessibility event of the given type. If accessibility is not enabled this method has no effect.

The default implementation behaves as View#sendAccessibilityEvent(int) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

int eventType

The type of the event to send.

See also
sendAccessibilityEvent

View#sendAccessibilityEvent(int)

sendAccessibilityEventUnchecked

public void sendAccessibilityEventUnchecked(
    @NonNull View host,
    @NonNull AccessibilityEvent event
)

Sends an accessibility event. This method behaves exactly as sendAccessibilityEvent but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.

The default implementation behaves as View#sendAccessibilityEventUnchecked(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
@NonNull View host

The View hosting the delegate.

@NonNull AccessibilityEvent event

The event to send.

See also
sendAccessibilityEventUnchecked

View#sendAccessibilityEventUnchecked(AccessibilityEvent)