public abstract class TouchExplorationHelper<T>
extends AccessibilityNodeProviderCompat
| Modifier and Type | Field and Description |
|---|---|
static int |
INVALID_ID
Virtual node identifier value for invalid nodes.
|
| Constructor and Description |
|---|
TouchExplorationHelper(android.content.Context context,
android.view.View parentView)
Constructs a new touch exploration helper.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearFocusedItem()
Clears the current accessibility focused item.
|
AccessibilityNodeInfoCompat |
createAccessibilityNodeInfo(int virtualViewId) |
AccessibilityDelegateCompat |
getAccessibilityDelegate() |
T |
getFocusedItem() |
protected abstract int |
getIdForItem(T item)
Returns the unique identifier for an item.
|
protected abstract T |
getItemAt(float x,
float y)
Returns the item under the specified parent-relative coordinates.
|
protected abstract T |
getItemForId(int id)
Returns the item for a unique identifier.
|
protected abstract void |
getVisibleItems(java.util.List<T> items)
Populates a list with the parent view's visible items.
|
void |
invalidateItem(T item)
Invalidates cached information for a particular item.
|
void |
invalidateParent()
Invalidates cached information about the parent view.
|
boolean |
performAction(int virtualViewId,
int action,
android.os.Bundle arguments) |
protected abstract boolean |
performActionForItem(T item,
int action,
android.os.Bundle arguments)
Performs an accessibility action on the specified item.
|
protected abstract void |
populateEventForItem(T item,
android.view.accessibility.AccessibilityEvent event)
Populates an event with information about the specified item.
|
protected abstract void |
populateNodeForItem(T item,
AccessibilityNodeInfoCompat node)
Populates a node with information about the specified item.
|
boolean |
sendEventForItem(T item,
int eventType)
Populates an event of the specified type with information about an item and attempts to send it up through the
view hierarchy.
|
void |
setFocusedItem(T item)
Requests accessibility focus be placed on the specified item.
|
public static final int INVALID_ID
public TouchExplorationHelper(android.content.Context context,
android.view.View parentView)
context - The parent context.public T getFocusedItem()
null if no item is focused.public void clearFocusedItem()
public void setFocusedItem(T item)
item - The item to place focus on.public void invalidateParent()
You must call this method after adding or removing items from the parent view.
public void invalidateItem(T item)
You must call this method when any of the
properties set in populateNodeForItem(Object, AccessibilityNodeInfoCompat) have changed.
public boolean sendEventForItem(T item, int eventType)
item - The item for which to send an event.eventType - The type of event to send.true if the event was sent successfully.public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId)
public boolean performAction(int virtualViewId,
int action,
android.os.Bundle arguments)
public AccessibilityDelegateCompat getAccessibilityDelegate()
protected abstract boolean performActionForItem(T item, int action, android.os.Bundle arguments)
AccessibilityNodeInfoCompat#performAction(int,
android.os.Bundle). The helper class automatically handles focus management resulting from AccessibilityNodeInfoCompat#ACTION_ACCESSIBILITY_FOCUS and AccessibilityNodeInfoCompat#ACTION_CLEAR_ACCESSIBILITY_FOCUS,
so typically a developer only needs to handle actions added manually in the {populateNodeForItem(Object,
AccessibilityNodeInfoCompat) method.
item - The item on which to perform the action.action - The accessibility action to perform.arguments - Arguments for the action, or optionally null.true if the action was performed successfully.protected abstract void populateEventForItem(T item, android.view.accessibility.AccessibilityEvent event)
At a minimum, a developer must populate the event text by doing one of the following:
AccessibilityRecord.getText()AccessibilityRecord.setContentDescription(CharSequence)item - The item for which to populate the event.event - The event to populate.protected abstract void populateNodeForItem(T item, AccessibilityNodeInfoCompat node)
At a minimum, a developer must:
AccessibilityNodeInfoCompat#setText(CharSequence) or AccessibilityNodeInfoCompat#setContentDescription(CharSequence) AccessibilityNodeInfoCompat#setBoundsInParent(android.graphics.Rect) item - The item for which to populate the node.node - The node to populate.protected abstract void getVisibleItems(java.util.List<T> items)
The result of this method is cached until the
developer calls invalidateParent().
items - The list to populate with visible items.protected abstract T getItemAt(float x, float y)
x - The parent-relative x coordinate.y - The parent-relative y coordinate.protected abstract int getIdForItem(T item)
INVALID_ID.
This result of this method must be consistent with getItemForId(int).
item - The item whose identifier to return.INVALID_ID.protected abstract T getItemForId(int id)
null.id - The identifier for the item to return.null.