# ExploreByTouchHelper

Artifact: [androidx.customview:customview](https://developer.android.com/jetpack/androidx/releases/customview) [View Source](https://cs.android.com/search?q=file:androidx/customview/widget/ExploreByTouchHelper.java+class:androidx.customview.widget.ExploreByTouchHelper) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

*** ** * ** ***


```
public abstract class ExploreByTouchHelper extends AccessibilityDelegateCompat
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.core.view.AccessibilityDelegateCompat](https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat) ||
|   | ↳ | [androidx.customview.widget.ExploreByTouchHelper](https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper) |

*** ** * ** ***

ExploreByTouchHelper is a utility class for implementing accessibility support in custom `https://developer.android.com/reference/android/view/View.html`s that represent a collection of View-like logical items. It extends `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeProviderCompat` and simplifies many aspects of providing information to accessibility services and managing accessibility focus.

Clients should override abstract methods on this class and attach it to the host view using `https://developer.android.com/reference/androidx/core/view/ViewCompat#setAccessibilityDelegate(android.view.View,androidx.core.view.AccessibilityDelegateCompat)`.

The host view should also override the events in the following code snippet so that the view's logical items are detected properly by the framework:

```
class MyCustomView extends View {
    private MyExploreByTouchHelper mExploreByTouchHelper;

    public MyCustomView(Context context, ...) {
        ...
        mExploreByTouchHelper = new MyExploreByTouchHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    }

    @Override
    public boolean dispatchHoverEvent(MotionEvent event) {
      return mExploreByTouchHelper.dispatchHoverEvent(event)
          || super.dispatchHoverEvent(event);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
      return mExploreByTouchHelper.dispatchKeyEvent(event)
          || super.dispatchKeyEvent(event);
    }

    @Override
    public void onFocusChanged(boolean gainFocus, int direction,
        Rect previouslyFocusedRect) {
      super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
      mExploreByTouchHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }
}
```

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#HOST_ID() = -1` Virtual node identifier value for the host view's node. |
| `static final int` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#INVALID_ID() = -2147483648` Virtual node identifier value for invalid nodes. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#ExploreByTouchHelper(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host)` Constructs a new helper that can expose a virtual view hierarchy for the specified host view. |

| ### Public methods |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#clearKeyboardFocusForVirtualView(int)(int virtualViewId)` Attempts to clear keyboard focus from a virtual view. |
| `final boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#dispatchHoverEvent(android.view.MotionEvent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MotionEvent.html event)` Delegates hover events from the host view. |
| `final boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#dispatchKeyEvent(android.view.KeyEvent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/KeyEvent.html event)` Delegates key events from the host view. |
| `final int` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getAccessibilityFocusedVirtualViewId()()` |
| `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeProviderCompat` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getAccessibilityNodeProvider(android.view.View)(https://developer.android.com/reference/android/view/View.html host)` Gets the provider for managing a virtual view hierarchy rooted at this View and reported to `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html`s that explore the window content. |
| `int` | `[getFocusedVirtualView](https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getFocusedVirtualView())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getAccessibilityFocusedVirtualViewId()`. <br /> |
| `final int` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getKeyboardFocusedVirtualViewId()()` |
| `final void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#invalidateRoot()()` Notifies the accessibility framework that the properties of the parent view have changed. |
| `final void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#invalidateVirtualView(int)(int virtualViewId)` Notifies the accessibility framework that the properties of a particular item have changed. |
| `final void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#invalidateVirtualView(int,int)(int virtualViewId, int changeTypes)` Notifies the accessibility framework that the properties of a particular item have changed. |
| `final void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onFocusChanged(boolean,int,android.graphics.Rect)( boolean gainFocus, int direction, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Rect.html previouslyFocusedRect )` Delegates focus changes from the host view. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onInitializeAccessibilityEvent(android.view.View,android.view.accessibility.AccessibilityEvent)(https://developer.android.com/reference/android/view/View.html host, https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event)` Initializes an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the the host View which is the event source. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onInitializeAccessibilityNodeInfo(android.view.View,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)( https://developer.android.com/reference/android/view/View.html host, https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat info )` Initializes an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the host view. |
| `final boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#requestKeyboardFocusForVirtualView(int)(int virtualViewId)` Attempts to give keyboard focus to a virtual view. |
| `final boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#sendEventForVirtualView(int,int)(int virtualViewId, int eventType)` Populates an event of the specified type with information about an item and attempts to send it up through the view hierarchy. |
| `final void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#setBoundsInScreenFromBoundsInParent(androidx.core.view.accessibility.AccessibilityNodeInfoCompat,android.graphics.Rect)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html boundsInParent )` Calculates and assigns screen-relative bounds based on bounds in parent. |

| ### Protected methods |
|---|---|
| `abstract int` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getVirtualViewAt(float,float)(float x, float y)` Provides a mapping between view-relative coordinates and logical items. |
| `abstract void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getVisibleVirtualViews(java.util.List<java.lang.Integer>)(https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/Integer.html> virtualViewIds)` Populates a list with the view's visible items. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPerformActionForVirtualView(int,int,android.os.Bundle)( int virtualViewId, int action, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html arguments )` Performs the specified accessibility action on the item associated with the virtual view identifier. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateEventForHost(android.view.accessibility.AccessibilityEvent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event)` Populates an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the host view. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateEventForVirtualView(int,android.view.accessibility.AccessibilityEvent)( int virtualViewId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` Populates an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the specified item. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForHost(androidx.core.view.accessibility.AccessibilityNodeInfoCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node)` Populates an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the host view. |
| `abstract void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)( int virtualViewId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node )` Populates an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the specified item. |
| `void` | `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onVirtualViewKeyboardFocusChanged(int,boolean)(int virtualViewId, boolean hasFocus)` Called when the focus state of a virtual view changes. |

| ### Inherited methods |
|---|
| From [androidx.core.view.AccessibilityDelegateCompat](https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat) |---|---| | `boolean` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#dispatchPopulateAccessibilityEvent(android.view.View,android.view.accessibility.AccessibilityEvent)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` Dispatches an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` to the host `https://developer.android.com/reference/android/view/View.html` first and then to its children for adding their text content to the event. | | `void` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#onPopulateAccessibilityEvent(android.view.View,android.view.accessibility.AccessibilityEvent)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` Gives a chance to the host View to populate the accessibility event with its text content. | | `boolean` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#onRequestSendAccessibilityEvent(android.view.ViewGroup,android.view.View,android.view.accessibility.AccessibilityEvent)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html host, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html child, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` Called when a child of the host View has requested sending an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` and gives an opportunity to the parent (the host) to augment the event. | | `boolean` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#performAccessibilityAction(android.view.View,int,android.os.Bundle)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host, int action, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html args )` Performs the specified accessibility action on the view. | | `void` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#sendAccessibilityEvent(android.view.View,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host, int eventType)` Sends an accessibility event of the given type. | | `void` | `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#sendAccessibilityEventUnchecked(android.view.View,android.view.accessibility.AccessibilityEvent)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` Sends an accessibility event. | |

## Constants

### HOST_ID

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public static final int HOST_ID = -1
```

Virtual node identifier value for the host view's node.

### INVALID_ID

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public static final int INVALID_ID = -2147483648
```

Virtual node identifier value for invalid nodes.

## Public constructors

### ExploreByTouchHelper

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public ExploreByTouchHelper(@NonNull View host)
```

Constructs a new helper that can expose a virtual view hierarchy for the specified host view.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html host` | view whose virtual view hierarchy is exposed by this helper |

## Public methods

### clearKeyboardFocusForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final boolean clearKeyboardFocusForVirtualView(int virtualViewId)
```

Attempts to clear keyboard focus from a virtual view.

| Parameters |
|---|---|
| `int virtualViewId` | the identifier of the virtual view from which to clear keyboard focus |

| Returns |
|---|---|
| `boolean` | whether this virtual view actually cleared keyboard focus |

### dispatchHoverEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final boolean dispatchHoverEvent(@NonNull MotionEvent event)
```

Delegates hover events from the host view.

Dispatches hover `https://developer.android.com/reference/android/view/MotionEvent.html`s to the virtual view hierarchy when the Explore by Touch feature is enabled.

This method should be called by overriding the host view's `https://developer.android.com/reference/android/view/View.html#dispatchHoverEvent(android.view.MotionEvent)` method:

```
@Override
public boolean dispatchHoverEvent(MotionEvent event) {
  return mHelper.dispatchHoverEvent(this, event)
      || super.dispatchHoverEvent(event);
}
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MotionEvent.html event` | The hover event to dispatch to the virtual view hierarchy. |

| Returns |
|---|---|
| `boolean` | Whether the hover event was handled. |

### dispatchKeyEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final boolean dispatchKeyEvent(@NonNull KeyEvent event)
```

Delegates key events from the host view.

This method should be called by overriding the host view's `https://developer.android.com/reference/android/view/View.html#dispatchKeyEvent(android.view.KeyEvent)` method:

```
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
  return mHelper.dispatchKeyEvent(event)
      || super.dispatchKeyEvent(event);
}
```

### getAccessibilityFocusedVirtualViewId

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final int getAccessibilityFocusedVirtualViewId()
```

| Returns |
|---|---|
| `int` | the identifier of the virtual view that has accessibility focus or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#INVALID_ID()` if no virtual view has accessibility focus |

### getAccessibilityNodeProvider

```
public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host)
```

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to `https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html`s that explore the window content.

The default implementation behaves as `https://developer.android.com/reference/androidx/core/view/ViewCompat#getAccessibilityNodeProvider(android.view.View)` for the case of no accessibility delegate been set.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeProviderCompat` | The provider. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeProviderCompat` |   |

### getFocusedVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public int [getFocusedVirtualView](https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getFocusedVirtualView())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#getAccessibilityFocusedVirtualViewId()`.

Returns the virtual view ID for the currently accessibility focused item.

| Returns |
|---|---|
| `int` | the identifier of the virtual view that has accessibility focus or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#INVALID_ID()` if no virtual view has accessibility focus |

### getKeyboardFocusedVirtualViewId

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final int getKeyboardFocusedVirtualViewId()
```

| Returns |
|---|---|
| `int` | the identifier of the virtual view that has keyboard focus or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#INVALID_ID()` if no virtual view has keyboard focus |

### invalidateRoot

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final void invalidateRoot()
```

Notifies the accessibility framework that the properties of the parent view have changed.

You **must** call this method after adding or removing items from the parent view.

### invalidateVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final void invalidateVirtualView(int virtualViewId)
```

Notifies the accessibility framework that the properties of a particular item have changed.

You **must** call this method after changing any of the properties set in `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)`.

| Parameters |
|---|---|
| `int virtualViewId` | the virtual view id to invalidate, or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#HOST_ID()` to invalidate the root view |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#invalidateVirtualView(int,int)` |   |

### invalidateVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final void invalidateVirtualView(int virtualViewId, int changeTypes)
```

Notifies the accessibility framework that the properties of a particular item have changed.

You **must** call this method after changing any of the properties set in `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)`.

| Parameters |
|---|---|
| `int virtualViewId` | the virtual view id to invalidate, or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#HOST_ID()` to invalidate the root view |
| `int changeTypes` | the bit mask of change types. May be `0` for the default (undefined) change type or one or more of: - `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityEventCompat#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION()` - `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityEventCompat#CONTENT_CHANGE_TYPE_SUBTREE()` - `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityEventCompat#CONTENT_CHANGE_TYPE_TEXT()` - `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityEventCompat#CONTENT_CHANGE_TYPE_UNDEFINED()` |

### onFocusChanged

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final void onFocusChanged(
    boolean gainFocus,
    int direction,
    @Nullable Rect previouslyFocusedRect
)
```

Delegates focus changes from the host view.

This method should be called by overriding the host view's `https://developer.android.com/reference/android/view/View.html#onFocusChanged(boolean, int, android.graphics.Rect)` method:

```
@Override
public boolean onFocusChanged(boolean gainFocus, int direction,
    Rect previouslyFocusedRect) {
  super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
  mHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
}
```

### onInitializeAccessibilityEvent

```
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event)
```

Initializes an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the the host View which is the event source.

The default implementation behaves as `https://developer.android.com/reference/androidx/core/view/ViewCompat#onInitializeAccessibilityEvent(android.view.View,android.view.accessibility.AccessibilityEvent)` for the case of no accessibility delegate been set.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html host` | The View hosting the delegate. |
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event` | The event to initialize. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#onInitializeAccessibilityEvent(android.view.View,android.view.accessibility.AccessibilityEvent)` | ViewCompat#onInitializeAccessibilityEvent(View, AccessibilityEvent) |

### onInitializeAccessibilityNodeInfo

```
public void onInitializeAccessibilityNodeInfo(
    View host,
    AccessibilityNodeInfoCompat info
)
```

Initializes an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the host view.

The default implementation behaves as `https://developer.android.com/reference/androidx/core/view/ViewCompat#onInitializeAccessibilityNodeInfo(android.view.View,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)` for the case of no accessibility delegate been set.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html host` | The View hosting the delegate. |
| `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat info` | The instance to initialize. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#onInitializeAccessibilityNodeInfo(android.view.View,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)` | ViewCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat) |

### requestKeyboardFocusForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final boolean requestKeyboardFocusForVirtualView(int virtualViewId)
```

Attempts to give keyboard focus to a virtual view.

| Parameters |
|---|---|
| `int virtualViewId` | the identifier of the virtual view on which to place keyboard focus |

| Returns |
|---|---|
| `boolean` | whether this virtual view actually took keyboard focus |

### sendEventForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
public final boolean sendEventForVirtualView(int virtualViewId, int eventType)
```

Populates an event of the specified type with information about an item and attempts to send it up through the view hierarchy.

You should call this method after performing a user action that normally fires an accessibility event, such as clicking on an item.

```
public void performItemClick(T item) {
  ...
  sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
}
```

| Parameters |
|---|---|
| `int virtualViewId` | the identifier of the virtual view for which to send an event |
| `int eventType` | the type of event to send |

| Returns |
|---|---|
| `boolean` | `true` if the event was sent successfully, `false` otherwise |

### setBoundsInScreenFromBoundsInParent

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/customview#1.2.0)

```
public final void setBoundsInScreenFromBoundsInParent(
    @NonNull AccessibilityNodeInfoCompat node,
    @NonNull Rect boundsInParent
)
```

Calculates and assigns screen-relative bounds based on bounds in parent. Instead of calling the deprecated `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setBoundsInParent(android.graphics.Rect)`, it provides a convenient method to calculate and assign `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setBoundsInScreen(android.graphics.Rect)` based on `boundsInParent`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node` | The node to populate |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Rect.html boundsInParent` | The node bounds in the viewParent's coordinates. |

## Protected methods

### getVirtualViewAt

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected abstract int getVirtualViewAt(float x, float y)
```

Provides a mapping between view-relative coordinates and logical items.

| Parameters |
|---|---|
| `float x` | The view-relative x coordinate |
| `float y` | The view-relative y coordinate |

| Returns |
|---|---|
| `int` | virtual view identifier for the logical item under coordinates (x,y) or `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#HOST_ID()` if there is no item at the given coordinates |

### getVisibleVirtualViews

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected abstract void getVisibleVirtualViews(List<Integer> virtualViewIds)
```

Populates a list with the view's visible items. The ordering of items within `virtualViewIds` specifies order of accessibility focus traversal.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/Integer.html> virtualViewIds` | The list to populate with visible items |

### onPerformActionForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected abstract boolean onPerformActionForVirtualView(
    int virtualViewId,
    int action,
    @Nullable Bundle arguments
)
```

Performs the specified accessibility action on the item associated with the virtual view identifier. See `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#performAction(int,android.os.Bundle)` for more information.

Implementations **must** handle any actions added manually in `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)`.

The helper class automatically handles focus management resulting from `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_ACCESSIBILITY_FOCUS()` and `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_CLEAR_ACCESSIBILITY_FOCUS()` actions.

| Parameters |
|---|---|
| `int virtualViewId` | The virtual view identifier of the item on which to perform the action |
| `int action` | The accessibility action to perform |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html arguments` | (Optional) A bundle with additional arguments, or null |

| Returns |
|---|---|
| `boolean` | true if the action was performed |

### onPopulateEventForHost

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected void onPopulateEventForHost(@NonNull AccessibilityEvent event)
```

Populates an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the host view.

The default implementation is a no-op.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event` | the event to populate with information about the host view |

### onPopulateEventForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected void onPopulateEventForVirtualView(
    int virtualViewId,
    @NonNull AccessibilityEvent event
)
```

Populates an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` with information about the specified item.

The helper class automatically populates the following fields based on the values set by `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)`, but implementations may optionally override them:

- event text, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#getText()`
- content description, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#setContentDescription(java.lang.CharSequence)`
- scrollability, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#setScrollable(boolean)`
- password state, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#setPassword(boolean)`
- enabled state, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#setEnabled(boolean)`
- checked state, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityRecord.html#setChecked(boolean)`

The following required fields are automatically populated by the helper class and may not be overridden:

- item class name, set to the value used in `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateNodeForVirtualView(int,androidx.core.view.accessibility.AccessibilityNodeInfoCompat)`
- package name, set to the package of the host view's `https://developer.android.com/reference/android/content/Context.html`, see `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html#setPackageName(java.lang.CharSequence)`
- event source, set to the host view and virtual view identifier, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityRecordCompat#setSource(android.view.accessibility.AccessibilityRecord,android.view.View,int)`

| Parameters |
|---|---|
| `int virtualViewId` | The virtual view id for the item for which to populate the event |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event` | The event to populate |

### onPopulateNodeForHost

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected void onPopulateNodeForHost(@NonNull AccessibilityNodeInfoCompat node)
```

Populates an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the host view.

The default implementation is a no-op.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node` | the node to populate with information about the host view |

### onPopulateNodeForVirtualView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected abstract void onPopulateNodeForVirtualView(
    int virtualViewId,
    @NonNull AccessibilityNodeInfoCompat node
)
```

Populates an `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat` with information about the specified item.

Implementations **must** populate the following required fields:

- event text, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setText(java.lang.CharSequence)` or `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setContentDescription(java.lang.CharSequence)`
- bounds in screen coordinates, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setBoundsInScreen(android.graphics.Rect)` and `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#setBoundsInScreenFromBoundsInParent(androidx.core.view.accessibility.AccessibilityNodeInfoCompat,android.graphics.Rect)`

The helper class automatically populates the following fields with default values, but implementations may optionally override them:

- enabled state, set to `true`, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setEnabled(boolean)`
- keyboard focusability, set to `true`, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setFocusable(boolean)`
- item class name, set to `android.view.View`, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setClassName(java.lang.CharSequence)`

The following required fields are automatically populated by the helper class and may not be overridden:

- package name, identical to the package name set by `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateEventForVirtualView(int,android.view.accessibility.AccessibilityEvent)`, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setPackageName(java.lang.CharSequence)`
- node source, identical to the event source set in `https://developer.android.com/reference/androidx/customview/widget/ExploreByTouchHelper#onPopulateEventForVirtualView(int,android.view.accessibility.AccessibilityEvent)`, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setSource(android.view.View,int)`
- parent view, set to the host view, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setParent(android.view.View)`
- visibility, computed based on parent-relative bounds, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setVisibleToUser(boolean)`
- accessibility focus, computed based on internal helper state, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setAccessibilityFocused(boolean)`
- keyboard focus, computed based on internal helper state, see `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#setFocused(boolean)`

Additionally, the helper class automatically handles keyboard focus and accessibility focus management by adding the appropriate `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_FOCUS()`, `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_CLEAR_FOCUS()`, `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_ACCESSIBILITY_FOCUS()`, or `https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat#ACTION_CLEAR_ACCESSIBILITY_FOCUS()` actions. Implementations must **never** manually add these actions.

The helper class also automatically modifies parent- and screen-relative bounds to reflect the portion of the item visible within its parent.

| Parameters |
|---|---|
| `int virtualViewId` | The virtual view identifier of the item for which to populate the node |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/accessibility/AccessibilityNodeInfoCompat node` | The node to populate |

### onVirtualViewKeyboardFocusChanged

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

```
protected void onVirtualViewKeyboardFocusChanged(int virtualViewId, boolean hasFocus)
```

Called when the focus state of a virtual view changes.

| Parameters |
|---|---|
| `int virtualViewId` | the virtual view identifier |
| `boolean hasFocus` | `true` if the view has focus, `false` otherwise |