public abstract class ExploreByTouchHelper extends View.AccessibilityDelegate
View
s that represent a collection of View-like
logical items. It extends AccessibilityNodeProvider
and
simplifies many aspects of providing information to accessibility services
and managing accessibility focus. This class does not currently support
hierarchies of logical items.
This should be applied to the parent view using
View.setAccessibilityDelegate(android.view.View.AccessibilityDelegate)
:
mAccessHelper = ExploreByTouchHelper.create(someView, mAccessHelperCallback); ViewCompat.setAccessibilityDelegate(someView, mAccessHelper);
Modifier and Type | Field and Description |
---|---|
static int |
HOST_ID
Virtual node identifier value for the host view's node.
|
static int |
INVALID_ID
Virtual node identifier value for invalid nodes.
|
Constructor and Description |
---|
ExploreByTouchHelper(View forView)
Factory method to create a new
ExploreByTouchHelper . |
Modifier and Type | Method and Description |
---|---|
boolean |
dispatchHoverEvent(MotionEvent event)
Dispatches hover
MotionEvent s to the virtual view hierarchy when
the Explore by Touch feature is enabled. |
AccessibilityNodeProvider |
getAccessibilityNodeProvider(View host)
Returns the
AccessibilityNodeProvider for this helper. |
int |
getFocusedVirtualView()
Returns the virtual view id for the currently focused item,
|
protected abstract int |
getVirtualViewAt(float x,
float y)
Provides a mapping between view-relative coordinates and logical
items.
|
protected abstract void |
getVisibleVirtualViews(IntArray virtualViewIds)
Populates a list with the view's visible items.
|
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 |
invalidateVirtualView(int virtualViewId,
int changeTypes)
Notifies the accessibility framework that the properties of a particular
item have changed.
|
protected abstract boolean |
onPerformActionForVirtualView(int virtualViewId,
int action,
Bundle arguments)
Performs the specified accessibility action on the item associated
with the virtual view identifier.
|
protected void |
onPopulateEventForHost(AccessibilityEvent event)
Populates an
AccessibilityEvent with information about the host
view. |
protected abstract void |
onPopulateEventForVirtualView(int virtualViewId,
AccessibilityEvent event)
Populates an
AccessibilityEvent with information about the
specified item. |
protected void |
onPopulateNodeForHost(AccessibilityNodeInfo node)
Populates an
AccessibilityNodeInfo with information about the
host view. |
protected abstract void |
onPopulateNodeForVirtualView(int virtualViewId,
AccessibilityNodeInfo node)
Populates an
AccessibilityNodeInfo with information
about the specified item. |
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.
|
createAccessibilityNodeInfo, dispatchPopulateAccessibilityEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onPopulateAccessibilityEvent, onRequestSendAccessibilityEvent, performAccessibilityAction, sendAccessibilityEvent, sendAccessibilityEventUnchecked
public static final int INVALID_ID
public static final int HOST_ID
public ExploreByTouchHelper(View forView)
ExploreByTouchHelper
.forView
- View whose logical children are exposed by this helper.public AccessibilityNodeProvider getAccessibilityNodeProvider(View host)
AccessibilityNodeProvider
for this helper.getAccessibilityNodeProvider
in class View.AccessibilityDelegate
host
- View whose logical children are exposed by this helper.AccessibilityNodeProvider
public boolean dispatchHoverEvent(MotionEvent event)
MotionEvent
s to the virtual view hierarchy when
the Explore by Touch feature is enabled.
This method should be called by overriding
View.dispatchHoverEvent(android.view.MotionEvent)
:
@Override public boolean dispatchHoverEvent(MotionEvent event) { if (mHelper.dispatchHoverEvent(this, event) { return true; } return super.dispatchHoverEvent(event); }
event
- The hover event to dispatch to the virtual view hierarchy.public boolean sendEventForVirtualView(int virtualViewId, int eventType)
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); }
virtualViewId
- The virtual view id for which to send an event.eventType
- The type of event to send.public void invalidateRoot()
You must call this method after adding or removing items from the parent view.
public void invalidateVirtualView(int virtualViewId)
You must call this method after changing any of the properties set
in onPopulateNodeForVirtualView(int, android.view.accessibility.AccessibilityNodeInfo)
.
virtualViewId
- The virtual view id to invalidate, or
HOST_ID
to invalidate the root view.invalidateVirtualView(int, int)
public void invalidateVirtualView(int virtualViewId, int changeTypes)
You must call this method after changing any of the properties set
in onPopulateNodeForVirtualView(int, android.view.accessibility.AccessibilityNodeInfo)
.
virtualViewId
- The virtual view id to invalidate, or
HOST_ID
to invalidate the root view.changeTypes
- The bit mask of change types. May be 0
for the
default (undefined) change type or one or more of:
public int getFocusedVirtualView()
INVALID_ID
if no item is
currently focused.protected abstract int getVirtualViewAt(float x, float y)
x
- The view-relative x coordinatey
- The view-relative y coordinateprotected abstract void getVisibleVirtualViews(IntArray virtualViewIds)
virtualViewIds
specifies order of accessibility focus
traversal.virtualViewIds
- The list to populate with visible itemsprotected abstract void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event)
AccessibilityEvent
with information about the
specified item.
Implementations must populate the following required fields:
AccessibilityRecord.getText()
or
AccessibilityRecord.setContentDescription(java.lang.CharSequence)
The helper class automatically populates the following fields with default values, but implementations may optionally override them:
AccessibilityRecord.setClassName(java.lang.CharSequence)
The following required fields are automatically populated by the helper class and may not be overridden:
Context
, see AccessibilityEvent.setPackageName(java.lang.CharSequence)
AccessibilityRecord.setSource(View, int)
virtualViewId
- The virtual view id for the item for which to
populate the eventevent
- The event to populateprotected void onPopulateEventForHost(AccessibilityEvent event)
AccessibilityEvent
with information about the host
view.
The default implementation is a no-op.
event
- the event to populate with information about the host viewprotected abstract void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node)
AccessibilityNodeInfo
with information
about the specified item.
Implementations must populate the following required fields:
AccessibilityNodeInfo.setText(java.lang.CharSequence)
or
AccessibilityNodeInfo.setContentDescription(java.lang.CharSequence)
AccessibilityNodeInfo.setBoundsInParent(android.graphics.Rect)
The helper class automatically populates the following fields with default values, but implementations may optionally override them:
AccessibilityNodeInfo.setEnabled(boolean)
onPopulateEventForVirtualView(int, android.view.accessibility.AccessibilityEvent)
, see
AccessibilityNodeInfo.setClassName(java.lang.CharSequence)
The following required fields are automatically populated by the helper class and may not be overridden:
onPopulateEventForVirtualView(int, android.view.accessibility.AccessibilityEvent)
, see
AccessibilityNodeInfo.setPackageName(java.lang.CharSequence)
onPopulateEventForVirtualView(int, android.view.accessibility.AccessibilityEvent)
, see
AccessibilityNodeInfo.setSource(View, int)
AccessibilityNodeInfo.setParent(View)
AccessibilityNodeInfo.setVisibleToUser(boolean)
AccessibilityNodeInfo.setAccessibilityFocused(boolean)
AccessibilityNodeInfo.setBoundsInScreen(android.graphics.Rect)
Additionally, the helper class automatically handles accessibility
focus management by adding the appropriate
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS
or
AccessibilityNodeInfo.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.
virtualViewId
- The virtual view identifier of the item for
which to populate the nodenode
- The node to populateprotected void onPopulateNodeForHost(AccessibilityNodeInfo node)
AccessibilityNodeInfo
with information about the
host view.
The default implementation is a no-op.
node
- the node to populate with information about the host viewprotected abstract boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments)
AccessibilityNodeInfo.performAction(int, Bundle)
for
more information.
Implementations must handle any actions added manually in
onPopulateNodeForVirtualView(int, android.view.accessibility.AccessibilityNodeInfo)
.
The helper class automatically handles focus management resulting
from AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS
and
AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS
actions.
virtualViewId
- The virtual view identifier of the item on which
to perform the actionaction
- The accessibility action to performarguments
- (Optional) A bundle with additional arguments, or
null