AccessibilityEventCompat
public final class AccessibilityEventCompat
Helper for accessing features in AccessibilityEvent.
Summary
Constants |
|
|---|---|
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
CONTENT_CHANGE_TYPE_ENABLED = 4096Change type for |
static final int |
CONTENT_CHANGE_TYPE_ERROR = 2048Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
Change type for |
static final int |
TYPES_ALL_MASK = -1Mask for |
static final int |
TYPE_ANNOUNCEMENT = 16384Represents the event of an application making an announcement. |
static final int |
TYPE_ASSIST_READING_CONTEXT = 16777216Represents the event of the assistant currently reading the users screen context. |
static final int |
TYPE_GESTURE_DETECTION_END = 524288Represents the event of ending gesture detection. |
static final int |
TYPE_GESTURE_DETECTION_START = 262144Represents the event of beginning gesture detection. |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
TYPE_TOUCH_INTERACTION_END = 2097152Represents the event of the user ending to touch the screen. |
static final int |
TYPE_TOUCH_INTERACTION_START = 1048576Represents the event of the user starting to touch the screen. |
static final int |
TYPE_VIEW_ACCESSIBILITY_FOCUSED = 32768Represents the event of gaining accessibility focus. |
static final int |
Represents the event of clearing accessibility focus. |
static final int |
TYPE_VIEW_CONTEXT_CLICKED = 8388608Represents the event of a context click on a |
static final int |
TYPE_VIEW_HOVER_ENTER = 128This field is deprecated. Use |
static final int |
TYPE_VIEW_HOVER_EXIT = 256This field is deprecated. Use |
static final int |
TYPE_VIEW_SCROLLED = 4096This field is deprecated. Use |
static final int |
TYPE_VIEW_TARGETED_BY_SCROLL = 67108864Represents the event of a scroll having completed and brought the target node on screen. |
static final int |
This field is deprecated. Use |
static final int |
Represents the event of traversing the text of a view at a given movement granularity. |
static final int |
TYPE_WINDOWS_CHANGED = 4194304Represents the event change in the windows shown on the screen. |
static final int |
TYPE_WINDOW_CONTENT_CHANGED = 2048This field is deprecated. Use |
Public methods |
|
|---|---|
static void |
@ReplaceWith(expression = "event.appendRecord(record)")This method is deprecated. Use |
static AccessibilityRecordCompat |
This method is deprecated. Use the |
static int |
@ReplaceWith(expression = "event.getAction()")This method is deprecated. Call |
static int |
@ReplaceWith(expression = "event.getContentChangeTypes()")This method is deprecated. Call |
static int |
@ReplaceWith(expression = "event.getMovementGranularity()")This method is deprecated. Call |
static AccessibilityRecordCompat |
This method is deprecated. Use |
static int |
@ReplaceWith(expression = "event.getRecordCount()")This method is deprecated. Use |
static boolean |
Whether the event should only be delivered to an |
static void |
setAccessibilityDataSensitive(Sets whether the event should only be delivered to an |
static void |
@ReplaceWith(expression = "event.setAction(action)")This method is deprecated. Call setAction directly. |
static void |
@ReplaceWith(expression = "event.setContentChangeTypes(changeTypes)")This method is deprecated. Call setContentChangeTypes directly. |
static void |
@ReplaceWith(expression = "event.setMovementGranularity(granularity)")This method is deprecated. Call setMovementGranularity directly. |
Constants
CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION
public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 4
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The node's content description changed.
CONTENT_CHANGE_TYPE_CONTENT_INVALID
public static final int CONTENT_CHANGE_TYPE_CONTENT_INVALID = 1024
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its content validity returned by isContentInvalid. The view changing content validity should call setContentInvalid and then send this event.
| See also | |
|---|---|
isContentInvalid |
|
setContentInvalid |
CONTENT_CHANGE_TYPE_DRAG_CANCELLED
public static final int CONTENT_CHANGE_TYPE_DRAG_CANCELLED = 512
Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag in with accessibility enabled has ended. This means the content has been unsuccessfully dropped, the user has canceled the action via an AccessibilityAction, or no drop has been detected within a timeout and the drag was automatically cancelled. This is sent from the source that initiated the drag.
| See also | |
|---|---|
ACTION_DRAG_CANCEL |
CONTENT_CHANGE_TYPE_DRAG_DROPPED
public static final int CONTENT_CHANGE_TYPE_DRAG_DROPPED = 256
Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag in with accessibility enabled has ended. This means the content has been successfully dropped. This is sent from the target that accepted the dragged content.
| See also | |
|---|---|
ACTION_DRAG_DROP |
CONTENT_CHANGE_TYPE_DRAG_STARTED
public static final int CONTENT_CHANGE_TYPE_DRAG_STARTED = 128
Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag has started while accessibility is enabled. This is either via an AccessibilityAction, or via touch events. This is sent from the source that initiated the drag.
| See also | |
|---|---|
ACTION_DRAG_START |
CONTENT_CHANGE_TYPE_ENABLED
public static final int CONTENT_CHANGE_TYPE_ENABLED = 4096
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its ability to interact returned by isEnabled. The view changing content's ability to interact should call setEnabled and then send this event.
| See also | |
|---|---|
isEnabled |
|
setEnabled |
CONTENT_CHANGE_TYPE_ERROR
public static final int CONTENT_CHANGE_TYPE_ERROR = 2048
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its erroneous content's error message returned by getError. The view changing erroneous content's error message should call setError and then send this event.
CONTENT_CHANGE_TYPE_PANE_APPEARED
public static final int CONTENT_CHANGE_TYPE_PANE_APPEARED = 16
Change type for TYPE_WINDOW_STATE_CHANGED event: The node has a pane title, and either just appeared or just was assigned a title when it had none before.
| See also | |
|---|---|
setAccessibilityPaneTitle |
CONTENT_CHANGE_TYPE_PANE_DISAPPEARED
public static final int CONTENT_CHANGE_TYPE_PANE_DISAPPEARED = 32
Change type for TYPE_WINDOW_STATE_CHANGED event: Can mean one of two slightly different things. The primary meaning is that the node has a pane title, and was removed from the node hierarchy. It can also be sent if the pane title is set to null after it contained a title. No source will be returned if the node is no longer on the screen. To make the change more clear for the user, the first entry in getText can return the value that would have been returned by getSource().getPaneTitle().
| See also | |
|---|---|
setAccessibilityPaneTitle |
CONTENT_CHANGE_TYPE_PANE_TITLE
public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 8
Change type for TYPE_WINDOW_STATE_CHANGED event: The node's pane title changed.
| See also | |
|---|---|
setAccessibilityPaneTitle |
CONTENT_CHANGE_TYPE_STATE_DESCRIPTION
public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 64
Change type for TYPE_WINDOW_CONTENT_CHANGED event: state description of the node as returned by getStateDescription was changed.
CONTENT_CHANGE_TYPE_SUBTREE
public static final int CONTENT_CHANGE_TYPE_SUBTREE = 1
Change type for TYPE_WINDOW_CONTENT_CHANGED event: A node in the subtree rooted at the source node was added or removed.
CONTENT_CHANGE_TYPE_TEXT
public static final int CONTENT_CHANGE_TYPE_TEXT = 2
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The node's text changed.
CONTENT_CHANGE_TYPE_UNDEFINED
public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0
Change type for TYPE_WINDOW_CONTENT_CHANGED event: The type of change is not defined.
TYPES_ALL_MASK
public static final int TYPES_ALL_MASK = -1
Mask for AccessibilityEvent all types.
TYPE_ANNOUNCEMENT
public static final int TYPE_ANNOUNCEMENT = 16384
Represents the event of an application making an announcement.
Note: This event carries no semantic meaning and is appropriate only in exceptional situations. Apps can generally achieve correct behavior for accessibility by accurately supplying the semantics of their UI. They should not need to specify what exactly is announced to users.
In general, only announce transitions that can't be handled by the following preferred alternatives:
- Label your controls concisely and precisely. Don’t generate a confirmation message for simple actions like a button press.
- For significant UI changes like window changes, use
setTitleandsetAccessibilityPaneTitle)}. - Use
setAccessibilityLiveRegionto inform the user of changes to critical views within the user interface. These should still be used sparingly as they may generate announcements every time a View is updated.
TYPE_ASSIST_READING_CONTEXT
public static final int TYPE_ASSIST_READING_CONTEXT = 16777216
Represents the event of the assistant currently reading the users screen context.
TYPE_GESTURE_DETECTION_END
public static final int TYPE_GESTURE_DETECTION_END = 524288
Represents the event of ending gesture detection.
TYPE_GESTURE_DETECTION_START
public static final int TYPE_GESTURE_DETECTION_START = 262144
Represents the event of beginning gesture detection.
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 1024
Represents the event of ending a touch exploration gesture.
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 512
Represents the event of starting a touch exploration gesture.
TYPE_TOUCH_INTERACTION_END
public static final int TYPE_TOUCH_INTERACTION_END = 2097152
Represents the event of the user ending to touch the screen.
TYPE_TOUCH_INTERACTION_START
public static final int TYPE_TOUCH_INTERACTION_START = 1048576
Represents the event of the user starting to touch the screen.
TYPE_VIEW_ACCESSIBILITY_FOCUSED
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 32768
Represents the event of gaining accessibility focus.
| See also | |
|---|---|
ACTION_ACCESSIBILITY_FOCUS |
TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 65536
Represents the event of clearing accessibility focus.
| See also | |
|---|---|
ACTION_CLEAR_ACCESSIBILITY_FOCUS |
TYPE_VIEW_CONTEXT_CLICKED
public static final int TYPE_VIEW_CONTEXT_CLICKED = 8388608
Represents the event of a context click on a View.
public static final int TYPE_VIEW_HOVER_ENTER = 128
Represents the event of a hover enter over a View.
public static final int TYPE_VIEW_HOVER_EXIT = 256
Represents the event of a hover exit over a View.
TYPE_VIEW_TARGETED_BY_SCROLL
public static final int TYPE_VIEW_TARGETED_BY_SCROLL = 67108864
Represents the event of a scroll having completed and brought the target node on screen.
public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 8192
Represents the event of changing the selection in an EditText.
TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 131072
Represents the event of traversing the text of a view at a given movement granularity.
TYPE_WINDOWS_CHANGED
public static final int TYPE_WINDOWS_CHANGED = 4194304
Represents the event change in the windows shown on the screen.
public static final int TYPE_WINDOW_CONTENT_CHANGED = 2048
Represents the event of changing the content of a window.
Public methods
@ReplaceWith(expression = "event.appendRecord(record)")
public static voidappendRecord(
AccessibilityEvent event,
AccessibilityRecordCompat record
)
Appends an AccessibilityRecord to the end of event records.
| Parameters | |
|---|---|
AccessibilityEvent event |
event for which to append the record. |
AccessibilityRecordCompat record |
The record to append. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |
public static AccessibilityRecordCompatasRecord(AccessibilityEvent event)
Creates an AccessibilityRecordCompat from an AccessibilityEvent that can be used to manipulate the event properties defined in AccessibilityRecord.
Note: Do not call recycle on the returned AccessibilityRecordCompat. Call recycle in case you want to recycle the event.
| Parameters | |
|---|---|
AccessibilityEvent event |
The from which to create a record. |
| Returns | |
|---|---|
AccessibilityRecordCompat |
@ReplaceWith(expression = "event.getAction()")
public static intgetAction(@NonNull AccessibilityEvent event)
Gets the performed action that triggered this event.
| Returns | |
|---|---|
int |
The action. |
@ReplaceWith(expression = "event.getContentChangeTypes()")
public static intgetContentChangeTypes(@NonNull AccessibilityEvent event)
Gets the bit mask of change types signaled by an TYPE_WINDOW_CONTENT_CHANGED event. A single event may represent multiple change types.
| Returns | |
|---|---|
int |
The bit mask of change types. One or more of: |
@ReplaceWith(expression = "event.getMovementGranularity()")
public static intgetMovementGranularity(@NonNull AccessibilityEvent event)
Gets the movement granularity that was traversed.
| Returns | |
|---|---|
int |
The granularity. |
public static AccessibilityRecordCompatgetRecord(AccessibilityEvent event, int index)
Gets the record at a given index.
| Parameters | |
|---|---|
AccessibilityEvent event |
event for which to get the record. |
int index |
The index. |
| Returns | |
|---|---|
AccessibilityRecordCompat |
The record at the specified index. |
@ReplaceWith(expression = "event.getRecordCount()")
public static intgetRecordCount(AccessibilityEvent event)
Gets the number of records contained in the event.
| Returns | |
|---|---|
int |
The number of records. |
isAccessibilityDataSensitive
public static boolean isAccessibilityDataSensitive(@NonNull AccessibilityEvent event)
Whether the event should only be delivered to an android.accessibilityservice.AccessibilityService with the isAccessibilityTool property set to true.
Initial value matches the isAccessibilityDataSensitive property from the event's source node, if present, or false by default.
| Returns | |
|---|---|
boolean |
True if the event should be delivered only to isAccessibilityTool services, false otherwise. |
| See also | |
|---|---|
setAccessibilityDataSensitive |
setAccessibilityDataSensitive
public static void setAccessibilityDataSensitive(
@NonNull AccessibilityEvent event,
boolean accessibilityDataSensitive
)
Sets whether the event should only be delivered to an android.accessibilityservice.AccessibilityService with the isAccessibilityTool property set to true.
This will be set automatically based on the event's source (if present). If creating and sending an event directly through android.view.accessibility.AccessibilityManager (where an event may have no source) then this method must be called explicitly if you want non-default behavior.
| Parameters | |
|---|---|
@NonNull AccessibilityEvent event |
The event to update. |
boolean accessibilityDataSensitive |
True if the event should be delivered only to isAccessibilityTool services, false otherwise. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |
@ReplaceWith(expression = "event.setAction(action)")
public static voidsetAction(@NonNull AccessibilityEvent event, int action)
Sets the performed action that triggered this event.
Valid actions are defined in AccessibilityNodeInfoCompat:
ACTION_ACCESSIBILITY_FOCUSACTION_CLEAR_ACCESSIBILITY_FOCUSACTION_CLEAR_FOCUSACTION_CLEAR_SELECTIONACTION_CLICK- etc.
| Parameters | |
|---|---|
@NonNull AccessibilityEvent event |
event for which to set the action. |
int action |
The action. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |
| See also | |
|---|---|
performAction |
@ReplaceWith(expression = "event.setContentChangeTypes(changeTypes)")
public static voidsetContentChangeTypes(@NonNull AccessibilityEvent event, int changeTypes)
Sets the bit mask of node tree changes signaled by an TYPE_WINDOW_CONTENT_CHANGED event.
| Parameters | |
|---|---|
@NonNull AccessibilityEvent event |
event for which to set the types. |
int changeTypes |
The bit mask of change types. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |
| See also | |
|---|---|
getContentChangeTypes |
@ReplaceWith(expression = "event.setMovementGranularity(granularity)")
public static voidsetMovementGranularity(
@NonNull AccessibilityEvent event,
int granularity
)
Sets the movement granularity that was traversed.
| Parameters | |
|---|---|
@NonNull AccessibilityEvent event |
event for which to set the granularity. |
int granularity |
The granularity. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |