ExploreByTouchHelper
abstract class ExploreByTouchHelper : AccessibilityDelegateCompat
kotlin.Any | ||
↳ | androidx.core.view.AccessibilityDelegateCompat | |
↳ | androidx.customview.widget.ExploreByTouchHelper |
ExploreByTouchHelper is a utility class for implementing accessibility support in custom View
s 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
.
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 | |
---|---|
static Int |
Virtual node identifier value for the host view's node. |
static Int |
Virtual node identifier value for invalid nodes. |
Public constructors | |
---|---|
Constructs a new helper that can expose a virtual view hierarchy for the specified host view. |
Public methods | |
---|---|
Boolean |
clearKeyboardFocusForVirtualView(virtualViewId: Int) Attempts to clear keyboard focus from a virtual view. |
Boolean |
dispatchHoverEvent(@NonNull event: MotionEvent) Delegates hover events from the host view. |
Boolean |
dispatchKeyEvent(@NonNull event: KeyEvent) Delegates key events from the host view. |
Int | |
open AccessibilityNodeProviderCompat! |
getAccessibilityNodeProvider(host: View!) |
open Int |
Returns the virtual view ID for the currently accessibility focused item. |
Int | |
Unit |
Notifies the accessibility framework that the properties of the parent view have changed. |
Unit |
invalidateVirtualView(virtualViewId: Int) Notifies the accessibility framework that the properties of a particular item have changed. |
Unit |
invalidateVirtualView(virtualViewId: Int, changeTypes: Int) Notifies the accessibility framework that the properties of a particular item have changed. |
Unit |
onFocusChanged(gainFocus: Boolean, direction: Int, @Nullable previouslyFocusedRect: Rect?) Delegates focus changes from the host view. |
open Unit |
onInitializeAccessibilityEvent(host: View!, event: AccessibilityEvent!) |
open Unit |
onInitializeAccessibilityNodeInfo(host: View!, info: AccessibilityNodeInfoCompat!) |
Boolean |
requestKeyboardFocusForVirtualView(virtualViewId: Int) Attempts to give keyboard focus to a virtual view. |
Boolean |
sendEventForVirtualView(virtualViewId: Int, eventType: Int) Populates an event of the specified type with information about an item and attempts to send it up through the view hierarchy. |
Protected methods | |
---|---|
abstract Int |
getVirtualViewAt(x: Float, y: Float) Provides a mapping between view-relative coordinates and logical items. |
abstract Unit |
getVisibleVirtualViews(virtualViewIds: MutableList<Int!>!) Populates a list with the view's visible items. |
abstract Boolean |
onPerformActionForVirtualView(virtualViewId: Int, action: Int, @Nullable arguments: Bundle?) Performs the specified accessibility action on the item associated with the virtual view identifier. |
open Unit |
onPopulateEventForHost(@NonNull event: AccessibilityEvent) Populates an |
open Unit |
onPopulateEventForVirtualView(virtualViewId: Int, @NonNull |