ExploreByTouchHelper

public abstract class ExploreByTouchHelper
extends AccessibilityDelegateCompat

java.lang.Object
   ↳ androidx.core.view.AccessibilityDelegateCompat
     ↳ androidx.customview.widget.ExploreByTouchHelper


ExploreByTouchHelper is a utility class for implementing accessibility support in custom Views that represent a collection of View-like logical items. It extends 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 ViewCompat.setAccessibilityDelegate(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 mHelper.dispatchHoverEvent(this, event)
           || super.dispatchHoverEvent(event);
     }

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

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

Summary

Constants

int HOST_ID

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

int INVALID_ID

Virtual node identifier value for invalid nodes.

Public constructors

ExploreByTouchHelper(View host)

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

Public methods

final boolean clearKeyboardFocusForVirtualView(int virtualViewId)

Attempts to clear keyboard focus from a virtual view.

final boolean dispatchHoverEvent(MotionEvent event)

Delegates hover events from the host view.

final boolean dispatchKeyEvent(KeyEvent event)

Delegates key events from the host view.

final int getAccessibilityFocusedVirtualViewId()
AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host)

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

int getFocusedVirtualView()

This method is deprecated. Use