AccessibilityEventCompat

Added in 1.1.0

public final class AccessibilityEventCompat


Helper for accessing features in AccessibilityEvent.

Summary

Constants

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The node's content description changed.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its content validity returned by isContentInvalid.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag in with accessibility enabled has ended.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag in with accessibility enabled has ended.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: A drag has started while accessibility is enabled.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its ability to interact returned by isEnabled.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The source node changed its erroneous content's error message returned by getError.

static final int

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.

static final int

Change type for TYPE_WINDOW_STATE_CHANGED event: Can mean one of two slightly different things.

static final int

Change type for TYPE_WINDOW_STATE_CHANGED event: The node's pane title changed.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: state description of the node as returned by getStateDescription was changed.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: A node in the subtree rooted at the source node was added or removed.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The node's text changed.

static final int

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The type of change is not defined.

static final int

Mask for AccessibilityEvent all types.

static final int

Represents the event of an application making an announcement.

static final int

Represents the event of the assistant currently reading the users screen context.

static final int

Represents the event of ending gesture detection.

static final int

Represents the event of beginning gesture detection.

static final int

This field is deprecated.

Use TYPE_TOUCH_EXPLORATION_GESTURE_END directly.

static final int

This field is deprecated.

Use TYPE_TOUCH_EXPLORATION_GESTURE_START directly.

static final int

Represents the event of the user ending to touch the screen.

static final int

Represents the event of the user starting to touch the screen.

static final int

Represents the event of gaining accessibility focus.

static final int

Represents the event of clearing accessibility focus.

static final int

Represents the event of a context click on a View.

static final int

This field is deprecated.

Use TYPE_VIEW_HOVER_ENTER directly.

static final int

This field is deprecated.

Use TYPE_VIEW_HOVER_EXIT directly.

static final int

This field is deprecated.

Use TYPE_VIEW_SCROLLED directly.

static final int

Represents the event of a scroll having completed and brought the target node on screen.

static final int

This field is deprecated.

Use TYPE_VIEW_TEXT_SELECTION_CHANGED directly.

static final int

Represents the event of traversing the text of a view at a given movement granularity.

static final int

Represents the event change in the windows shown on the screen.

static final int

This field is deprecated.

Use TYPE_WINDOW_CONTENT_CHANGED directly.

Public methods

static void
@ReplaceWith(expression = "event.appendRecord(record)")
appendRecord(
    AccessibilityEvent event,
    AccessibilityRecordCompat record
)

This method is deprecated.

Use appendRecord directly.

static AccessibilityRecordCompat

This method is deprecated.

Use the AccessibilityEvent directly as AccessibilityRecord.

static int
@ReplaceWith(expression = "event.getAction()")
getAction(@NonNull AccessibilityEvent event)

This method is deprecated.

Call getAction directly.

static int
@ReplaceWith(expression = "event.getContentChangeTypes()")
getContentChangeTypes(@NonNull AccessibilityEvent event)

This method is deprecated.

Call getContentChangeTypes directly.

static int
@ReplaceWith(expression = "event.getMovementGranularity()")
getMovementGranularity(@NonNull AccessibilityEvent event)

This method is deprecated.

Call getMovementGranularity directly.

static AccessibilityRecordCompat
getRecord(AccessibilityEvent event, int index)

This method is deprecated.

Use getRecord directly.

static int
@ReplaceWith(expression = "event.getRecordCount()")
getRecordCount(AccessibilityEvent event)

This method is deprecated.

Use getRecordCount directly.

static boolean

Whether the event should only be delivered to an android.accessibilityservice.AccessibilityService with the isAccessibilityTool property set to true.

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.

static void
@ReplaceWith(expression = "event.setAction(action)")
setAction(@NonNull AccessibilityEvent event, int action)

This method is deprecated.

Call setAction directly.

static void
@ReplaceWith(expression = "event.setContentChangeTypes(changeTypes)")
setContentChangeTypes(@NonNull AccessibilityEvent event, int changeTypes)

This method is deprecated.

Call setContentChangeTypes directly.

static void
@ReplaceWith(expression = "event.setMovementGranularity(granularity)")
setMovementGranularity(
    @NonNull AccessibilityEvent event,
    int granularity
)

This method is deprecated.

Call setMovementGranularity directly.

Constants

CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION

Added in 1.1.0
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

Added in 1.12.0
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.

CONTENT_CHANGE_TYPE_DRAG_CANCELLED

Added in 1.9.0
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.

CONTENT_CHANGE_TYPE_DRAG_DROPPED

Added in 1.9.0
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

Added in 1.9.0
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.

CONTENT_CHANGE_TYPE_ENABLED

Added in 1.12.0
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.

CONTENT_CHANGE_TYPE_ERROR

Added in 1.12.0
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.

See also
getError
setError

CONTENT_CHANGE_TYPE_PANE_APPEARED

Added in 1.1.0
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.

CONTENT_CHANGE_TYPE_PANE_DISAPPEARED

Added in 1.1.0
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().

CONTENT_CHANGE_TYPE_PANE_TITLE

Added in 1.1.0
public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 8

Change type for TYPE_WINDOW_STATE_CHANGED event: The node's pane title changed.

CONTENT_CHANGE_TYPE_STATE_DESCRIPTION

Added in 1.5.0
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

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0

Change type for TYPE_WINDOW_CONTENT_CHANGED event: The type of change is not defined.

TYPE_ANNOUNCEMENT

Added in 1.1.0
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 setTitle and setAccessibilityPaneTitle )}.
  • Use setAccessibilityLiveRegion to 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

Added in 1.1.0
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

Added in 1.1.0
public static final int TYPE_GESTURE_DETECTION_END = 524288

Represents the event of ending gesture detection.

TYPE_GESTURE_DETECTION_START

Added in 1.1.0
public static final int TYPE_GESTURE_DETECTION_START = 262144

Represents the event of beginning gesture detection.

TYPE_TOUCH_EXPLORATION_GESTURE_END

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 1024

Represents the event of ending a touch exploration gesture.

TYPE_TOUCH_EXPLORATION_GESTURE_START

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 512

Represents the event of starting a touch exploration gesture.

TYPE_TOUCH_INTERACTION_END

Added in 1.1.0
public static final int TYPE_TOUCH_INTERACTION_END = 2097152

Represents the event of the user ending to touch the screen.

TYPE_TOUCH_INTERACTION_START

Added in 1.1.0
public static final int TYPE_TOUCH_INTERACTION_START = 1048576

Represents the event of the user starting to touch the screen.

TYPE_VIEW_ACCESSIBILITY_FOCUSED

Added in 1.1.0
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 32768

Represents the event of gaining accessibility focus.

TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED

Added in 1.1.0
public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 65536

Represents the event of clearing accessibility focus.

TYPE_VIEW_CONTEXT_CLICKED

Added in 1.1.0
public static final int TYPE_VIEW_CONTEXT_CLICKED = 8388608

Represents the event of a context click on a View.

TYPE_VIEW_HOVER_ENTER

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_VIEW_HOVER_ENTER = 128

Represents the event of a hover enter over a View.

TYPE_VIEW_HOVER_EXIT

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_VIEW_HOVER_EXIT = 256

Represents the event of a hover exit over a View.

TYPE_VIEW_SCROLLED

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_VIEW_SCROLLED = 4096

Represents the event of scrolling a view.

TYPE_VIEW_TARGETED_BY_SCROLL

Added in 1.12.0
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.

TYPE_VIEW_TEXT_SELECTION_CHANGED

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
public static final int TYPE_WINDOWS_CHANGED = 4194304

Represents the event change in the windows shown on the screen.

TYPE_WINDOW_CONTENT_CHANGED

Added in 1.1.0
Deprecated in 1.1.0
public static final int TYPE_WINDOW_CONTENT_CHANGED = 2048

Represents the event of changing the content of a window.

Public methods

appendRecord

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "event.appendRecord(record)")
public static void appendRecord(
    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.

asRecord

Added in 1.1.0
Deprecated in 1.1.0
public static AccessibilityRecordCompat asRecord(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.

getAction

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.getAction()")
public static int getAction(@NonNull AccessibilityEvent event)

Gets the performed action that triggered this event.

Returns
int

The action.

getContentChangeTypes

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.getContentChangeTypes()")
public static int getContentChangeTypes(@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.

getMovementGranularity

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.getMovementGranularity()")
public static int getMovementGranularity(@NonNull AccessibilityEvent event)

Gets the movement granularity that was traversed.

Returns
int

The granularity.

getRecord

Added in 1.1.0
Deprecated in 1.1.0
public static AccessibilityRecordCompat getRecord(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.

getRecordCount

Added in 1.1.0
Deprecated in 1.1.0
@ReplaceWith(expression = "event.getRecordCount()")
public static int getRecordCount(AccessibilityEvent event)

Gets the number of records contained in the event.

Returns
int

The number of records.

isAccessibilityDataSensitive

Added in 1.12.0
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.

setAccessibilityDataSensitive

Added in 1.12.0
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.

setAction

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.setAction(action)")
public static void setAction(@NonNull AccessibilityEvent event, int action)

Sets the performed action that triggered this event.

Valid actions are defined in AccessibilityNodeInfoCompat:

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

setContentChangeTypes

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.setContentChangeTypes(changeTypes)")
public static void setContentChangeTypes(@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.

setMovementGranularity

Added in 1.1.0
Deprecated in 1.15.0-rc01
@ReplaceWith(expression = "event.setMovementGranularity(granularity)")
public static void setMovementGranularity(
    @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.