Skip to content

Most visited

Recently visited

navigation

ExploreByTouchHelper

public abstract class ExploreByTouchHelper
extends AccessibilityDelegateCompat

java.lang.Object
   ↳ android.support.v4.view.AccessibilityDelegateCompat
     ↳ android.support.v4.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. This class does not currently support hierarchies of logical items.

Clients should override abstract methods on this class and attach it to the host view using setAccessibilityDelegate(View, AccessibilityDelegateCompat):

 mAccessHelper = new MyExploreByTouchHelper(someView);
 ViewCompat.setAccessibilityDelegate(someView, mAccessHelper);
 

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 forView)

Factory method to create a new ExploreByTouchHelper.

Public methods

boolean dispatchHoverEvent(MotionEvent event)

Dispatches hover MotionEvents to the virtual view hierarchy when the Explore by Touch feature is enabled.

AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host)

Returns the AccessibilityNodeProviderCompat for this helper.

int getFocusedVirtualView()

Returns the virtual view id for the currently focused item,

void invalidateRoot()

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

void invalidateVirtualView(int virtualViewId)

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

void onPopulateNodeForHost(AccessibilityNodeInfoCompat node)

Populates an AccessibilityNodeInfoCompat with information about the host view.

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.

Protected methods

abstract int getVirtualViewAt(float x, float y)

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

abstract void getVisibleVirtualViews(List<Integer> virtualViewIds)

Populates a list with the view's visible items.

abstract boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments)

Performs the specified accessibility action on the item associated with the virtual view identifier.

abstract void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event)

Populates an AccessibilityEvent with information about the specified item.

abstract void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node)

Populates an AccessibilityNodeInfoCompat with information about the specified item.

Inherited methods

From class android.support.v4.view.AccessibilityDelegateCompat
From class java.lang.Object

Constants

HOST_ID

int HOST_ID

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

Constant Value: -1 (0xffffffff)

INVALID_ID

int INVALID_ID

Virtual node identifier value for invalid nodes.

Constant Value: -2147483648 (0x80000000)

Public constructors

ExploreByTouchHelper

ExploreByTouchHelper (View forView)

Factory method to create a new ExploreByTouchHelper.

Parameters
forView View: View whose logical children are exposed by this helper.

Public methods

dispatchHoverEvent

boolean dispatchHoverEvent (MotionEvent event)

Dispatches hover MotionEvents to the virtual view hierarchy when the Explore by Touch feature is enabled.

This method should be called by overriding dispatchHoverEvent(MotionEvent):

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

Parameters
event MotionEvent: The hover event to dispatch to the virtual view hierarchy.
Returns
boolean Whether the hover event was handled.

getAccessibilityNodeProvider

AccessibilityNodeProviderCompat getAccessibilityNodeProvider (View host)

Returns the AccessibilityNodeProviderCompat for this helper.

Parameters
host View: View whose logical children are exposed by this helper.
Returns
AccessibilityNodeProviderCompat The accessibility node provider for this helper.

getFocusedVirtualView

int getFocusedVirtualView ()

Returns the virtual view id for the currently focused item,

Returns
int A virtual view id, or INVALID_ID if no item is currently focused.

invalidateRoot

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

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 onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat).

Parameters
virtualViewId int: The virtual view id to invalidate.

onPopulateNodeForHost

void onPopulateNodeForHost (AccessibilityNodeInfoCompat node)

Populates an AccessibilityNodeInfoCompat with information about the host view.

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

Parameters
node AccessibilityNodeInfoCompat

sendEventForVirtualView

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
virtualViewId int: The virtual view id for which to send an event.
eventType int: The type of event to send.
Returns
boolean true if the event was sent successfully.

Protected methods

getVirtualViewAt

int getVirtualViewAt (float x, 
                float y)

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

Parameters
x float: The view-relative x coordinate
y float: The view-relative y coordinate
Returns
int virtual view identifier for the logical item under coordinates (x,y) or HOST_ID if there is no item at the given coordinates

getVisibleVirtualViews

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
virtualViewIds List: The list to populate with visible items

onPerformActionForVirtualView

boolean onPerformActionForVirtualView (int virtualViewId, 
                int action, 
                Bundle arguments)

Performs the specified accessibility action on the item associated with the virtual view identifier. See performAction(int, Bundle) for more information.

Implementations must handle any actions added manually in onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat).

The helper class automatically handles focus management resulting from ACTION_ACCESSIBILITY_FOCUS and ACTION_CLEAR_ACCESSIBILITY_FOCUS actions.

Parameters
virtualViewId int: The virtual view identifier of the item on which to perform the action
action int: The accessibility action to perform
arguments Bundle: (Optional) A bundle with additional arguments, or null
Returns
boolean true if the action was performed

onPopulateEventForVirtualView

void onPopulateEventForVirtualView (int virtualViewId, 
                AccessibilityEvent event)

Populates an AccessibilityEvent with information about the specified item.

Implementations must populate the following required fields:

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

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

Parameters
virtualViewId int: The virtual view id for the item for which to populate the event
event AccessibilityEvent: The event to populate

onPopulateNodeForVirtualView

void onPopulateNodeForVirtualView (int virtualViewId, 
                AccessibilityNodeInfoCompat node)

Populates an AccessibilityNodeInfoCompat with information about the specified item.

Implementations must populate the following required fields:

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

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

Additionally, the helper class automatically handles accessibility focus management by adding the appropriate ACTION_ACCESSIBILITY_FOCUS or ACTION_CLEAR_ACCESSIBILITY_FOCUS action. 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
virtualViewId int: The virtual view identifier of the item for which to populate the node
node AccessibilityNodeInfoCompat: The node to populate
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.