FileDocCategorySizeDatePackage
AccessibilityEvent.javaAPI DocAndroid 5.1 API59580Thu Mar 12 22:22:10 GMT 2015android.view.accessibility

AccessibilityEvent

public final class AccessibilityEvent extends AccessibilityRecord implements android.os.Parcelable

This class represents accessibility events that are sent by the system when something notable happens in the user interface. For example, when a {@link android.widget.Button} is clicked, a {@link android.view.View} is focused, etc.

An accessibility event is fired by an individual view which populates the event with data for its state and requests from its parent to send the event to interested parties. The parent can optionally add an {@link AccessibilityRecord} for itself before dispatching a similar request to its parent. A parent can also choose not to respect the request for sending an event. The accessibility event is sent by the topmost view in the view tree. Therefore, an {@link android.accessibilityservice.AccessibilityService} can explore all records in an accessibility event to obtain more information about the context in which the event was fired.

The main purpose of an accessibility event is to expose enough information for an {@link android.accessibilityservice.AccessibilityService} to provide meaningful feedback to the user. Sometimes however, an accessibility service may need more contextual information then the one in the event pay-load. In such cases the service can obtain the event source which is an {@link AccessibilityNodeInfo} (snapshot of a View state) which can be used for exploring the window content. Note that the privilege for accessing an event's source, thus the window content, has to be explicitly requested. For more details refer to {@link android.accessibilityservice.AccessibilityService}. If an accessibility service has not requested to retrieve the window content the event will not contain reference to its source. Also for events of type {@link #TYPE_NOTIFICATION_STATE_CHANGED} the source is never available.

This class represents various semantically different accessibility event types. Each event type has an associated set of related properties. In other words, each event type is characterized via a subset of the properties exposed by this class. For each event type there is a corresponding constant defined in this class. Follows a specification of the event types and their associated properties:

Developer Guides

For more information about creating and processing AccessibilityEvents, read the Accessibility developer guide.

VIEW TYPES

View clicked - represents the event of clicking on a {@link android.view.View} like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
Type:{@link #TYPE_VIEW_CLICKED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isChecked()} - Whether the source is checked.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

View long clicked - represents the event of long clicking on a {@link android.view.View} like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc
Type:{@link #TYPE_VIEW_LONG_CLICKED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isChecked()} - Whether the source is checked.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

View selected - represents the event of selecting an item usually in the context of an {@link android.widget.AdapterView}.
Type: {@link #TYPE_VIEW_SELECTED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isChecked()} - Whether the source is checked.
  • {@link #getItemCount()} - The number of selectable items of the source.
  • {@link #getCurrentItemIndex()} - The currently selected item index.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

View focused - represents the event of focusing a {@link android.view.View}.
Type: {@link #TYPE_VIEW_FOCUSED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isChecked()} - Whether the source is checked.
  • {@link #getItemCount()} - The number of focusable items on the screen.
  • {@link #getCurrentItemIndex()} - The currently focused item index.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

View text changed - represents the event of changing the text of an {@link android.widget.EditText}.
Type: {@link #TYPE_VIEW_TEXT_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isChecked()} - Whether the source is checked.
  • {@link #getFromIndex()} - The text change start index.
  • {@link #getAddedCount()} - The number of added characters.
  • {@link #getRemovedCount()} - The number of removed characters.
  • {@link #getBeforeText()} - The text of the source before the change.
  • {@link #getContentDescription()} - The content description of the source.

View text selection changed - represents the event of changing the text selection of an {@link android.widget.EditText}.
Type: {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #getFromIndex()} - The selection start index.
  • {@link #getToIndex()} - The selection end index.
  • {@link #getItemCount()} - The length of the source text.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #getContentDescription()} - The content description of the source.

View text traversed at movement granularity - represents the event of traversing the text of a view at a given granularity. For example, moving to the next word.
Type: {@link #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY}
Properties:
  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getMovementGranularity()} - Sets the granularity at which a view's text was traversed.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #getFromIndex()} - The start of the next/previous text at the specified granularity - inclusive.
  • {@link #getToIndex()} - The end of the next/previous text at the specified granularity - exclusive.
  • {@link #isPassword()} - Whether the source is password.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getMovementGranularity()} - Sets the granularity at which a view's text was traversed.
  • {@link #getAction()} - Gets traversal action which specifies the direction.

View scrolled - represents the event of scrolling a view. If the source is a descendant of {@link android.widget.AdapterView} the scroll is reported in terms of visible items - the first visible item, the last visible item, and the total items - because the the source is unaware of its pixel size since its adapter is responsible for creating views. In all other cases the scroll is reported as the current scroll on the X and Y axis respectively plus the height of the source in pixels.
Type: {@link #TYPE_VIEW_SCROLLED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).
Note: This event type is not dispatched to descendants though {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event source {@link android.view.View} and the sub-tree rooted at it will not receive calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent) View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add text content to such events is by setting the {@link android.R.styleable#View_contentDescription contentDescription} of the source view.

TRANSITION TYPES

Window state changed - represents the event of opening a {@link android.widget.PopupWindow}, {@link android.view.Menu}, {@link android.app.Dialog}, etc.
Type: {@link #TYPE_WINDOW_STATE_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.

Window content changed - represents the event of change in the content of a window. This change can be adding/removing view, changing a view size, etc.

Note: This event is fired only for the window source of the last accessibility event different from {@link #TYPE_NOTIFICATION_STATE_CHANGED} and its purpose is to notify clients that the content of the user interaction window has changed.
Type: {@link #TYPE_WINDOW_CONTENT_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getContentChangeTypes()} - The type of content changes.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
Note: This event type is not dispatched to descendants though {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event source {@link android.view.View} and the sub-tree rooted at it will not receive calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent) View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add text content to such events is by setting the {@link android.R.styleable#View_contentDescription contentDescription} of the source view.

Windows changed - represents the event of changes in the windows shown on the screen such as a window appeared, a window disappeared, a window size changed, a window layer changed, etc.
Type: {@link #TYPE_WINDOWS_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getEventTime()} - The event time.
Note: You can retrieve the {@link AccessibilityWindowInfo} for the window source of the event via {@link AccessibilityEvent#getSource()} to get the source node on which then call {@link AccessibilityNodeInfo#getWindow() AccessibilityNodeInfo.getWindow()} to get the window. Also all windows on the screen can be retrieved by a call to {@link android.accessibilityservice.AccessibilityService#getWindows() android.accessibilityservice.AccessibilityService.getWindows()}.

NOTIFICATION TYPES

Notification state changed - represents the event showing {@link android.app.Notification}.
Type: {@link #TYPE_NOTIFICATION_STATE_CHANGED}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #getParcelableData()} - The posted {@link android.app.Notification}.
  • {@link #getText()} - Text for providing more context.
Note: This event type is not dispatched to descendants though {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event source {@link android.view.View} and the sub-tree rooted at it will not receive calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent) View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add text content to such events is by setting the {@link android.R.styleable#View_contentDescription contentDescription} of the source view.

EXPLORATION TYPES

View hover enter - represents the event of beginning to hover over a {@link android.view.View}. The hover may be generated via exploring the screen by touch or via a pointing device.
Type: {@link #TYPE_VIEW_HOVER_ENTER}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

View hover exit - represents the event of stopping to hover over a {@link android.view.View}. The hover may be generated via exploring the screen by touch or via a pointing device.
Type: {@link #TYPE_VIEW_HOVER_EXIT}
Properties:
  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the source's sub-tree.
  • {@link #isEnabled()} - Whether the source is enabled.
  • {@link #getContentDescription()} - The content description of the source.
  • {@link #getScrollX()} - The offset of the source left edge in pixels (without descendants of AdapterView).
  • {@link #getScrollY()} - The offset of the source top edge in pixels (without descendants of AdapterView).
  • {@link #getFromIndex()} - The zero based index of the first visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getToIndex()} - The zero based index of the last visible item of the source, inclusive (for descendants of AdapterView).
  • {@link #getItemCount()} - The total items of the source (for descendants of AdapterView).

Touch interaction start - represents the event of starting a touch interaction, which is the user starts touching the screen.
Type: {@link #TYPE_TOUCH_INTERACTION_START}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

Touch interaction end - represents the event of ending a touch interaction, which is the user stops touching the screen.
Type: {@link #TYPE_TOUCH_INTERACTION_END}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

Touch exploration gesture start - represents the event of starting a touch exploring gesture.
Type: {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

Touch exploration gesture end - represents the event of ending a touch exploring gesture.
Type: {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

Touch gesture detection start - represents the event of starting a user gesture detection.
Type: {@link #TYPE_GESTURE_DETECTION_START}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

Touch gesture detection end - represents the event of ending a user gesture detection.
Type: {@link #TYPE_GESTURE_DETECTION_END}
Properties:

  • {@link #getEventType()} - The type of the event.
Note: This event is fired only by the system and is not passed to the view tree to be populated.

MISCELLANEOUS TYPES

Announcement - represents the event of an application making an announcement. Usually this announcement is related to some sort of a context change for which none of the events representing UI transitions is a good fit. For example, announcing a new page in a book.
Type: {@link #TYPE_ANNOUNCEMENT}
Properties:

  • {@link #getEventType()} - The type of the event.
  • {@link #getSource()} - The source info (for registered clients).
  • {@link #getClassName()} - The class name of the source.
  • {@link #getPackageName()} - The package name of the source.
  • {@link #getEventTime()} - The event time.
  • {@link #getText()} - The text of the announcement.
  • {@link #isEnabled()} - Whether the source is enabled.

Security note

Since an event contains the text of its source privacy can be compromised by leaking sensitive information such as passwords. To address this issue any event fired in response to manipulation of a PASSWORD field does NOT CONTAIN the text of the password.

see
android.view.accessibility.AccessibilityManager
see
android.accessibilityservice.AccessibilityService
see
AccessibilityNodeInfo

Fields Summary
private static final boolean
DEBUG
public static final int
INVALID_POSITION
Invalid selection/focus position.
public static final int
MAX_TEXT_LENGTH
Maximum length of the text fields.
public static final int
TYPE_VIEW_CLICKED
Represents the event of clicking on a {@link android.view.View} like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
public static final int
TYPE_VIEW_LONG_CLICKED
Represents the event of long clicking on a {@link android.view.View} like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
public static final int
TYPE_VIEW_SELECTED
Represents the event of selecting an item usually in the context of an {@link android.widget.AdapterView}.
public static final int
TYPE_VIEW_FOCUSED
Represents the event of setting input focus of a {@link android.view.View}.
public static final int
TYPE_VIEW_TEXT_CHANGED
Represents the event of changing the text of an {@link android.widget.EditText}.
public static final int
TYPE_WINDOW_STATE_CHANGED
Represents the event of opening a {@link android.widget.PopupWindow}, {@link android.view.Menu}, {@link android.app.Dialog}, etc.
public static final int
TYPE_NOTIFICATION_STATE_CHANGED
Represents the event showing a {@link android.app.Notification}.
public static final int
TYPE_VIEW_HOVER_ENTER
Represents the event of a hover enter over a {@link android.view.View}.
public static final int
TYPE_VIEW_HOVER_EXIT
Represents the event of a hover exit over a {@link android.view.View}.
public static final int
TYPE_TOUCH_EXPLORATION_GESTURE_START
Represents the event of starting a touch exploration gesture.
public static final int
TYPE_TOUCH_EXPLORATION_GESTURE_END
Represents the event of ending a touch exploration gesture.
public static final int
TYPE_WINDOW_CONTENT_CHANGED
Represents the event of changing the content of a window and more specifically the sub-tree rooted at the event's source.
public static final int
TYPE_VIEW_SCROLLED
Represents the event of scrolling a view.
public static final int
TYPE_VIEW_TEXT_SELECTION_CHANGED
Represents the event of changing the selection in an {@link android.widget.EditText}.
public static final int
TYPE_ANNOUNCEMENT
Represents the event of an application making an announcement.
public static final int
TYPE_VIEW_ACCESSIBILITY_FOCUSED
Represents the event of gaining accessibility focus.
public static final int
TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED
Represents the event of clearing accessibility focus.
public static final int
TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
Represents the event of traversing the text of a view at a given movement granularity.
public static final int
TYPE_GESTURE_DETECTION_START
Represents the event of beginning gesture detection.
public static final int
TYPE_GESTURE_DETECTION_END
Represents the event of ending gesture detection.
public static final int
TYPE_TOUCH_INTERACTION_START
Represents the event of the user starting to touch the screen.
public static final int
TYPE_TOUCH_INTERACTION_END
Represents the event of the user ending to touch the screen.
public static final int
TYPE_WINDOWS_CHANGED
Represents the event change in the windows shown on the screen.
public static final int
CONTENT_CHANGE_TYPE_UNDEFINED
Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: The type of change is not defined.
public static final int
CONTENT_CHANGE_TYPE_SUBTREE
Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: A node in the subtree rooted at the source node was added or removed.
public static final int
CONTENT_CHANGE_TYPE_TEXT
Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: The node's text changed.
public static final int
CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION
Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: The node's content description changed.
public static final int
TYPES_ALL_MASK
Mask for {@link AccessibilityEvent} all types.
private static final int
MAX_POOL_SIZE
private static final android.util.Pools.SynchronizedPool
sPool
private int
mEventType
private CharSequence
mPackageName
private long
mEventTime
int
mMovementGranularity
int
mAction
int
mContentChangeTypes
private ArrayList
mRecords
public static final Parcelable.Creator
CREATOR
Constructors Summary
private AccessibilityEvent()


    /*
     * Hide constructor from clients.
     */
      
    
Methods Summary
public voidappendRecord(AccessibilityRecord record)
Appends an {@link AccessibilityRecord} to the end of event records.

param
record The record to append.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        if (mRecords == null) {
            mRecords = new ArrayList<AccessibilityRecord>();
        }
        mRecords.add(record);
    
protected voidclear()
Clears the state of this instance.

hide

        super.clear();
        mEventType = 0;
        mMovementGranularity = 0;
        mAction = 0;
        mContentChangeTypes = 0;
        mPackageName = null;
        mEventTime = 0;
        if (mRecords != null) {
            while (!mRecords.isEmpty()) {
                AccessibilityRecord record = mRecords.remove(0);
                record.recycle();
            }
        }
    
public intdescribeContents()
{@inheritDoc}

        return 0;
    
public static java.lang.StringeventTypeToString(int eventType)
Returns the string representation of an event type. For example, {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.

param
eventType The event type
return
The string representation.

        if (eventType == TYPES_ALL_MASK) {
            return "TYPES_ALL_MASK";
        }
        StringBuilder builder = new StringBuilder();
        int eventTypeCount = 0;
        while (eventType != 0) {
            final int eventTypeFlag = 1 << Integer.numberOfTrailingZeros(eventType);
            eventType &= ~eventTypeFlag;
            switch (eventTypeFlag) {
                case TYPE_VIEW_CLICKED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_CLICKED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_LONG_CLICKED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_LONG_CLICKED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_SELECTED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_SELECTED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_FOCUSED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_FOCUSED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_TEXT_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_TEXT_CHANGED");
                    eventTypeCount++;
                } break;
                case TYPE_WINDOW_STATE_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_WINDOW_STATE_CHANGED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_HOVER_ENTER: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_HOVER_ENTER");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_HOVER_EXIT: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_HOVER_EXIT");
                    eventTypeCount++;
                } break;
                case TYPE_NOTIFICATION_STATE_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_NOTIFICATION_STATE_CHANGED");
                    eventTypeCount++;
                } break;
                case TYPE_TOUCH_EXPLORATION_GESTURE_START: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_START");
                    eventTypeCount++;
                } break;
                case TYPE_TOUCH_EXPLORATION_GESTURE_END: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_END");
                    eventTypeCount++;
                } break;
                case TYPE_WINDOW_CONTENT_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_WINDOW_CONTENT_CHANGED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_TEXT_SELECTION_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_TEXT_SELECTION_CHANGED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_SCROLLED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_SCROLLED");
                    eventTypeCount++;
                } break;
                case TYPE_ANNOUNCEMENT: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_ANNOUNCEMENT");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_ACCESSIBILITY_FOCUSED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUSED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED");
                    eventTypeCount++;
                } break;
                case TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY");
                    eventTypeCount++;
                } break;
                case TYPE_GESTURE_DETECTION_START: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_GESTURE_DETECTION_START");
                    eventTypeCount++;
                } break;
                case TYPE_GESTURE_DETECTION_END: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_GESTURE_DETECTION_END");
                    eventTypeCount++;
                } break;
                case TYPE_TOUCH_INTERACTION_START: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_TOUCH_INTERACTION_START");
                    eventTypeCount++;
                } break;
                case TYPE_TOUCH_INTERACTION_END: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_TOUCH_INTERACTION_END");
                    eventTypeCount++;
                } break;
                case TYPE_WINDOWS_CHANGED: {
                    if (eventTypeCount > 0) {
                        builder.append(", ");
                    }
                    builder.append("TYPE_WINDOWS_CHANGED");
                    eventTypeCount++;
                } break;
            }
        }
        if (eventTypeCount > 1) {
            builder.insert(0, '[");
            builder.append(']");
        }
        return builder.toString();
    
public intgetAction()
Gets the performed action that triggered this event.

return
The action.

        return mAction;
    
public intgetContentChangeTypes()
Gets the bit mask of change types signaled by an {@link #TYPE_WINDOW_CONTENT_CHANGED} event. A single event may represent multiple change types.

return
The bit mask of change types. One or more of:
  • {@link AccessibilityEvent#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
  • {@link AccessibilityEvent#CONTENT_CHANGE_TYPE_SUBTREE}
  • {@link AccessibilityEvent#CONTENT_CHANGE_TYPE_TEXT}
  • {@link AccessibilityEvent#CONTENT_CHANGE_TYPE_UNDEFINED}

        return mContentChangeTypes;
    
public longgetEventTime()
Gets the time in which this event was sent.

return
The event time.

        return mEventTime;
    
public intgetEventType()
Gets the event type.

return
The event type.

        return mEventType;
    
public intgetMovementGranularity()
Gets the movement granularity that was traversed.

return
The granularity.

        return mMovementGranularity;
    
public java.lang.CharSequencegetPackageName()
Gets the package name of the source.

return
The package name.

        return mPackageName;
    
public AccessibilityRecordgetRecord(int index)
Gets the record at a given index.

param
index The index.
return
The record at the specified index.

        if (mRecords == null) {
            throw new IndexOutOfBoundsException("Invalid index " + index + ", size is 0");
        }
        return mRecords.get(index);
    
public intgetRecordCount()
Gets the number of records contained in the event.

return
The number of records.

        return mRecords == null ? 0 : mRecords.size();
    
voidinit(android.view.accessibility.AccessibilityEvent event)
Initialize an event from another one.

param
event The event to initialize from.

        super.init(event);
        mEventType = event.mEventType;
        mMovementGranularity = event.mMovementGranularity;
        mAction = event.mAction;
        mContentChangeTypes = event.mContentChangeTypes;
        mEventTime = event.mEventTime;
        mPackageName = event.mPackageName;
    
public voidinitFromParcel(android.os.Parcel parcel)
Creates a new instance from a {@link Parcel}.

param
parcel A parcel containing the state of a {@link AccessibilityEvent}.

        mSealed = (parcel.readInt() == 1);
        mEventType = parcel.readInt();
        mMovementGranularity = parcel.readInt();
        mAction = parcel.readInt();
        mContentChangeTypes = parcel.readInt();
        mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        mEventTime = parcel.readLong();
        mConnectionId = parcel.readInt();
        readAccessibilityRecordFromParcel(this, parcel);

        // Read the records.
        final int recordCount = parcel.readInt();
        if (recordCount > 0) {
            mRecords = new ArrayList<AccessibilityRecord>(recordCount);
            for (int i = 0; i < recordCount; i++) {
                AccessibilityRecord record = AccessibilityRecord.obtain();
                readAccessibilityRecordFromParcel(record, parcel);
                record.mConnectionId = mConnectionId;
                mRecords.add(record);
            }
        }
    
public static android.view.accessibility.AccessibilityEventobtain(int eventType)
Returns a cached instance if such is available or a new one is instantiated with its type property set.

param
eventType The event type.
return
An instance.

        AccessibilityEvent event = AccessibilityEvent.obtain();
        event.setEventType(eventType);
        return event;
    
public static android.view.accessibility.AccessibilityEventobtain(android.view.accessibility.AccessibilityEvent event)
Returns a cached instance if such is available or a new one is created. The returned instance is initialized from the given event.

param
event The other event.
return
An instance.

        AccessibilityEvent eventClone = AccessibilityEvent.obtain();
        eventClone.init(event);

        if (event.mRecords != null) {
            final int recordCount = event.mRecords.size();
            eventClone.mRecords = new ArrayList<AccessibilityRecord>(recordCount);
            for (int i = 0; i < recordCount; i++) {
                final AccessibilityRecord record = event.mRecords.get(i);
                final AccessibilityRecord recordClone = AccessibilityRecord.obtain(record);
                eventClone.mRecords.add(recordClone);
            }
        }

        return eventClone;
    
public static android.view.accessibility.AccessibilityEventobtain()
Returns a cached instance if such is available or a new one is instantiated.

return
An instance.

        AccessibilityEvent event = sPool.acquire();
        return (event != null) ? event : new AccessibilityEvent();
    
private voidreadAccessibilityRecordFromParcel(AccessibilityRecord record, android.os.Parcel parcel)
Reads an {@link AccessibilityRecord} from a parcel.

param
record The record to initialize.
param
parcel The parcel to read from.

        record.mBooleanProperties = parcel.readInt();
        record.mCurrentItemIndex = parcel.readInt();
        record.mItemCount = parcel.readInt();
        record.mFromIndex = parcel.readInt();
        record.mToIndex = parcel.readInt();
        record.mScrollX = parcel.readInt();
        record.mScrollY =  parcel.readInt();
        record.mMaxScrollX = parcel.readInt();
        record.mMaxScrollY =  parcel.readInt();
        record.mAddedCount = parcel.readInt();
        record.mRemovedCount = parcel.readInt();
        record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        record.mParcelableData = parcel.readParcelable(null);
        parcel.readList(record.mText, null);
        record.mSourceWindowId = parcel.readInt();
        record.mSourceNodeId = parcel.readLong();
        record.mSealed = (parcel.readInt() == 1);
    
public voidrecycle()
Recycles an instance back to be reused.

Note: You must not touch the object after calling this function.

throws
IllegalStateException If the event is already recycled.

        clear();
        sPool.release(this);
    
public voidsetAction(int action)
Sets the performed action that triggered this event.

Valid actions are defined in {@link AccessibilityNodeInfo}:

  • {@link AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS}
  • {@link AccessibilityNodeInfo#ACTION_CLEAR_ACCESSIBILITY_FOCUS}
  • {@link AccessibilityNodeInfo#ACTION_CLEAR_FOCUS}
  • {@link AccessibilityNodeInfo#ACTION_CLEAR_SELECTION}
  • {@link AccessibilityNodeInfo#ACTION_CLICK}
  • etc.

param
action The action.
throws
IllegalStateException If called from an AccessibilityService.
see
AccessibilityNodeInfo#performAction(int)

        enforceNotSealed();
        mAction = action;
    
public voidsetContentChangeTypes(int changeTypes)
Sets the bit mask of node tree changes signaled by an {@link #TYPE_WINDOW_CONTENT_CHANGED} event.

param
changeTypes The bit mask of change types.
throws
IllegalStateException If called from an AccessibilityService.
see
#getContentChangeTypes()

        enforceNotSealed();
        mContentChangeTypes = changeTypes;
    
public voidsetEventTime(long eventTime)
Sets the time in which this event was sent.

param
eventTime The event time.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mEventTime = eventTime;
    
public voidsetEventType(int eventType)
Sets the event type.

param
eventType The event type.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mEventType = eventType;
    
public voidsetMovementGranularity(int granularity)
Sets the movement granularity that was traversed.

param
granularity The granularity.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mMovementGranularity = granularity;
    
public voidsetPackageName(java.lang.CharSequence packageName)
Sets the package name of the source.

param
packageName The package name.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mPackageName = packageName;
    
public voidsetSealed(boolean sealed)
Sets if this instance is sealed.

param
sealed Whether is sealed.
hide

        super.setSealed(sealed);
        final List<AccessibilityRecord> records = mRecords;
        if (records != null) {
            final int recordCount = records.size();
            for (int i = 0; i < recordCount; i++) {
                AccessibilityRecord record = records.get(i);
                record.setSealed(sealed);
            }
        }
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();
        builder.append("EventType: ").append(eventTypeToString(mEventType));
        builder.append("; EventTime: ").append(mEventTime);
        builder.append("; PackageName: ").append(mPackageName);
        builder.append("; MovementGranularity: ").append(mMovementGranularity);
        builder.append("; Action: ").append(mAction);
        builder.append(super.toString());
        if (DEBUG) {
            builder.append("\n");
            builder.append("; ContentChangeTypes: ").append(mContentChangeTypes);
            builder.append("; sourceWindowId: ").append(mSourceWindowId);
            builder.append("; mSourceNodeId: ").append(mSourceNodeId);
            for (int i = 0; i < getRecordCount(); i++) {
                final AccessibilityRecord record = getRecord(i);
                builder.append("  Record ");
                builder.append(i);
                builder.append(":");
                builder.append(" [ ClassName: " + record.mClassName);
                builder.append("; Text: " + record.mText);
                builder.append("; ContentDescription: " + record.mContentDescription);
                builder.append("; ItemCount: " + record.mItemCount);
                builder.append("; CurrentItemIndex: " + record.mCurrentItemIndex);
                builder.append("; IsEnabled: " + record.isEnabled());
                builder.append("; IsPassword: " + record.isPassword());
                builder.append("; IsChecked: " + record.isChecked());
                builder.append("; IsFullScreen: " + record.isFullScreen());
                builder.append("; Scrollable: " + record.isScrollable());
                builder.append("; BeforeText: " + record.mBeforeText);
                builder.append("; FromIndex: " + record.mFromIndex);
                builder.append("; ToIndex: " + record.mToIndex);
                builder.append("; ScrollX: " + record.mScrollX);
                builder.append("; ScrollY: " + record.mScrollY);
                builder.append("; AddedCount: " + record.mAddedCount);
                builder.append("; RemovedCount: " + record.mRemovedCount);
                builder.append("; ParcelableData: " + record.mParcelableData);
                builder.append(" ]");
                builder.append("\n");
            }
        } else {
            builder.append("; recordCount: ").append(getRecordCount());
        }
        return builder.toString();
    
private voidwriteAccessibilityRecordToParcel(AccessibilityRecord record, android.os.Parcel parcel, int flags)
Writes an {@link AccessibilityRecord} to a parcel.

param
record The record to write.
param
parcel The parcel to which to write.

        parcel.writeInt(record.mBooleanProperties);
        parcel.writeInt(record.mCurrentItemIndex);
        parcel.writeInt(record.mItemCount);
        parcel.writeInt(record.mFromIndex);
        parcel.writeInt(record.mToIndex);
        parcel.writeInt(record.mScrollX);
        parcel.writeInt(record.mScrollY);
        parcel.writeInt(record.mMaxScrollX);
        parcel.writeInt(record.mMaxScrollY);
        parcel.writeInt(record.mAddedCount);
        parcel.writeInt(record.mRemovedCount);
        TextUtils.writeToParcel(record.mClassName, parcel, flags);
        TextUtils.writeToParcel(record.mContentDescription, parcel, flags);
        TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
        parcel.writeParcelable(record.mParcelableData, flags);
        parcel.writeList(record.mText);
        parcel.writeInt(record.mSourceWindowId);
        parcel.writeLong(record.mSourceNodeId);
        parcel.writeInt(record.mSealed ? 1 : 0);
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)
{@inheritDoc}

        parcel.writeInt(isSealed() ? 1 : 0);
        parcel.writeInt(mEventType);
        parcel.writeInt(mMovementGranularity);
        parcel.writeInt(mAction);
        parcel.writeInt(mContentChangeTypes);
        TextUtils.writeToParcel(mPackageName, parcel, 0);
        parcel.writeLong(mEventTime);
        parcel.writeInt(mConnectionId);
        writeAccessibilityRecordToParcel(this, parcel, flags);

        // Write the records.
        final int recordCount = getRecordCount();
        parcel.writeInt(recordCount);
        for (int i = 0; i < recordCount; i++) {
            AccessibilityRecord record = mRecords.get(i);
            writeAccessibilityRecordToParcel(record, parcel, flags);
        }