public final class

AccessibilityEvent

extends Object
implements Parcelable
java.lang.Object
   ↳ android.view.accessibility.AccessibilityEvent

Class Overview

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

This class represents various semantically different accessibility event types. Each event type has associated a 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. Since some event types are semantically close there are mask constants that group them together. Follows a specification of the event types and their associated properties:

VIEW TYPES

View clicked - represents the event of clicking on a View like Button, CompoundButton, etc.
Type:TYPE_VIEW_CLICKED
Properties: getClassName(), getPackageName(), getEventTime(), getText(), isChecked(), isEnabled(), isPassword(), getItemCount(), getCurrentItemIndex()

View long clicked - represents the event of long clicking on a View like Button, CompoundButton, etc.
Type:TYPE_VIEW_LONG_CLICKED
Properties: getClassName(), getPackageName(), getEventTime(), getText(), isChecked(), isEnabled(), isPassword(), getItemCount(), getCurrentItemIndex()

View selected - represents the event of selecting an item usually in the context of an AdapterView.
Type: TYPE_VIEW_SELECTED
Properties: getClassName(), getPackageName(), getEventTime(), getText(), isChecked(), isEnabled(), isPassword(), getItemCount(), getCurrentItemIndex()

View focused - represents the event of focusing a View.
Type: TYPE_VIEW_FOCUSED
Properties: getClassName(), getPackageName(), getEventTime(), getText(), isChecked(), isEnabled(), isPassword(), getItemCount(), getCurrentItemIndex()

View text changed - represents the event of changing the text of an EditText.
Type: TYPE_VIEW_TEXT_CHANGED
Properties: getClassName(), getPackageName(), getEventTime(), getText(), isChecked(), isEnabled(), isPassword(), getItemCount(), getCurrentItemIndex(), getFromIndex(), getAddedCount(), getRemovedCount(), getBeforeText()

TRANSITION TYPES

Window state changed - represents the event of opening/closing a PopupWindow, Menu, Dialog, etc.
Type: TYPE_WINDOW_STATE_CHANGED
Properties: getClassName(), getPackageName(), getEventTime(), getText()

NOTIFICATION TYPES

Notification state changed - represents the event showing/hiding Notification. Type: TYPE_NOTIFICATION_STATE_CHANGED
Properties: getClassName(), getPackageName(), getEventTime(), getText() getParcelableData()

Security note

Since an event contains the text of its source privacy can be compromised by leaking of 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.

Summary

Constants
int INVALID_POSITION Invalid selection/focus position.
int MAX_TEXT_LENGTH Maximum length of the text fields.
int TYPES_ALL_MASK Mask for AccessibilityEvent all types.
int TYPE_NOTIFICATION_STATE_CHANGED Represents the event showing/hiding a Notification.
int TYPE_VIEW_CLICKED Represents the event of clicking on a View like Button, CompoundButton, etc.
int TYPE_VIEW_FOCUSED Represents the event of focusing a View.
int TYPE_VIEW_LONG_CLICKED Represents the event of long clicking on a View like Button, CompoundButton, etc.
int TYPE_VIEW_SELECTED Represents the event of selecting an item usually in the context of an AdapterView.
int TYPE_VIEW_TEXT_CHANGED Represents the event of changing the text of an EditText.
int TYPE_WINDOW_STATE_CHANGED Represents the event of opening/closing a PopupWindow, Menu, Dialog, etc.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<AccessibilityEvent> CREATOR
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
int getAddedCount()
Gets the number of added characters.
CharSequence getBeforeText()
Sets the text before a change.
CharSequence getClassName()
Gets the class name of the source.
CharSequence getContentDescription()
Gets the description of the source.
int getCurrentItemIndex()
Gets the index of the source in the list of items the can be visited.
long getEventTime()
Gets the time in which this event was sent.
int getEventType()
Gets the event type.
int getFromIndex()
Gets the index of the first character of the changed sequence.
int getItemCount()
Gets the number of items that can be visited.
CharSequence getPackageName()
Gets the package name of the source.
Parcelable getParcelableData()
Gets the Parcelable data.
int getRemovedCount()
Gets the number of removed characters.
List<CharSequence> getText()
Gets the text of the event.
void initFromParcel(Parcel parcel)
Creates a new instance from a Parcel.
boolean isChecked()
Gets if the source is checked.
boolean isEnabled()
Gets if the source is enabled.
boolean isFullScreen()
Gets if the source is taking the entire screen.
boolean isPassword()
Gets if the source is a password field.
static AccessibilityEvent obtain(int eventType)
Returns a cached instance if such is available or a new one is instantiated with type property set.
static AccessibilityEvent obtain()
Returns a cached instance if such is available or a new one is instantiated.
void recycle()
Return an instance back to be reused.
void setAddedCount(int addedCount)
Sets the number of added characters.
void setBeforeText(CharSequence beforeText)
Sets the text before a change.
void setChecked(boolean isChecked)
Sets if the source is checked.
void setClassName(CharSequence className)
Sets the class name of the source.
void setContentDescription(CharSequence contentDescription)
Sets the description of the source.
void setCurrentItemIndex(int currentItemIndex)
Sets the index of the source in the list of items that can be visited.
void setEnabled(boolean isEnabled)
Sets if the source is enabled.
void setEventTime(long eventTime)
Sets the time in which this event was sent.
void setEventType(int eventType)
Sets the event type.
void setFromIndex(int fromIndex)
Sets the index of the first character of the changed sequence.
void setFullScreen(boolean isFullScreen)
Sets if the source is taking the entire screen.
void setItemCount(int itemCount)
Sets the number of items that can be visited.
void setPackageName(CharSequence packageName)
Sets the package name of the source.
void setParcelableData(Parcelable parcelableData)
Sets the Parcelable data of the event.
void setPassword(boolean isPassword)
Sets if the source is a password field.
void setRemovedCount(int removedCount)
Sets the number of removed characters.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel parcel, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int INVALID_POSITION

Since: API Level 4

Invalid selection/focus position.

Constant Value: -1 (0xffffffff)

public static final int MAX_TEXT_LENGTH

Since: API Level 4

Maximum length of the text fields.

Constant Value: 500 (0x000001f4)

public static final int TYPE_NOTIFICATION_STATE_CHANGED

Since: API Level 4

Represents the event showing/hiding a Notification.

Constant Value: 64 (0x00000040)

public static final int TYPE_VIEW_CLICKED

Since: API Level 4

Represents the event of clicking on a View like Button, CompoundButton, etc.

Constant Value: 1 (0x00000001)

public static final int TYPE_VIEW_FOCUSED

Since: API Level 4

Represents the event of focusing a View.

Constant Value: 8 (0x00000008)

public static final int TYPE_VIEW_LONG_CLICKED

Since: API Level 4

Represents the event of long clicking on a View like Button, CompoundButton, etc.

Constant Value: 2 (0x00000002)

public static final int TYPE_VIEW_SELECTED

Since: API Level 4

Represents the event of selecting an item usually in the context of an AdapterView.

Constant Value: 4 (0x00000004)

public static final int TYPE_VIEW_TEXT_CHANGED

Since: API Level 4

Represents the event of changing the text of an EditText.

Constant Value: 16 (0x00000010)

public static final int TYPE_WINDOW_STATE_CHANGED

Since: API Level 4

Represents the event of opening/closing a PopupWindow, Menu, Dialog, etc.

Constant Value: 32 (0x00000020)

Fields

public static final Creator<AccessibilityEvent> CREATOR

Since: API Level 4

Public Methods

public int describeContents ()

Since: API Level 4

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public int getAddedCount ()

Since: API Level 4

Gets the number of added characters.

Returns
  • The number of added characters.

public CharSequence getBeforeText ()

Since: API Level 4

Sets the text before a change.

Returns
  • The text before the change.

public CharSequence getClassName ()

Since: API Level 4

Gets the class name of the source.

Returns
  • The class name.

public CharSequence getContentDescription ()

Since: API Level 4

Gets the description of the source.

Returns
  • The description.

public int getCurrentItemIndex ()

Since: API Level 4

Gets the index of the source in the list of items the can be visited.

Returns
  • The current item index.

public long getEventTime ()

Since: API Level 4

Gets the time in which this event was sent.

Returns
  • The event time.

public int getEventType ()

Since: API Level 4

Gets the event type.

Returns
  • The event type.

public int getFromIndex ()

Since: API Level 4

Gets the index of the first character of the changed sequence.

Returns
  • The index of the first character.

public int getItemCount ()

Since: API Level 4

Gets the number of items that can be visited.

Returns
  • The number of items.

public CharSequence getPackageName ()

Since: API Level 4

Gets the package name of the source.

Returns
  • The package name.

public Parcelable getParcelableData ()

Since: API Level 4

Gets the Parcelable data.

Returns
  • The parcelable data.

public int getRemovedCount ()

Since: API Level 4

Gets the number of removed characters.

Returns
  • The number of removed characters.

public List<CharSequence> getText ()

Since: API Level 4

Gets the text of the event. The index in the list represents the priority of the text. Specifically, the lower the index the higher the priority.

Returns
  • The text.

public void initFromParcel (Parcel parcel)

Since: API Level 4

Creates a new instance from a Parcel.

Parameters
parcel A parcel containing the state of a AccessibilityEvent.

public boolean isChecked ()

Since: API Level 4

Gets if the source is checked.

Returns
  • True if the view is checked, false otherwise.

public boolean isEnabled ()

Since: API Level 4

Gets if the source is enabled.

Returns
  • True if the view is enabled, false otherwise.

public boolean isFullScreen ()

Since: API Level 4

Gets if the source is taking the entire screen.

Returns
  • True if the source is full screen, false otherwise.

public boolean isPassword ()

Since: API Level 4

Gets if the source is a password field.

Returns
  • True if the view is a password field, false otherwise.

public static AccessibilityEvent obtain (int eventType)

Since: API Level 4

Returns a cached instance if such is available or a new one is instantiated with type property set.

Parameters
eventType The event type.
Returns
  • An instance.

public static AccessibilityEvent obtain ()

Since: API Level 4

Returns a cached instance if such is available or a new one is instantiated.

Returns
  • An instance.

public void recycle ()

Since: API Level 4

Return an instance back to be reused.

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

public void setAddedCount (int addedCount)

Since: API Level 4

Sets the number of added characters.

Parameters
addedCount The number of added characters.

public void setBeforeText (CharSequence beforeText)

Since: API Level 4

Sets the text before a change.

Parameters
beforeText The text before the change.

public void setChecked (boolean isChecked)

Since: API Level 4

Sets if the source is checked.

Parameters
isChecked True if the view is checked, false otherwise.

public void setClassName (CharSequence className)

Since: API Level 4

Sets the class name of the source.

Parameters
className The lass name.

public void setContentDescription (CharSequence contentDescription)

Since: API Level 4

Sets the description of the source.

Parameters
contentDescription The description.

public void setCurrentItemIndex (int currentItemIndex)

Since: API Level 4

Sets the index of the source in the list of items that can be visited.

Parameters
currentItemIndex The current item index.

public void setEnabled (boolean isEnabled)

Since: API Level 4

Sets if the source is enabled.

Parameters
isEnabled True if the view is enabled, false otherwise.

public void setEventTime (long eventTime)

Since: API Level 4

Sets the time in which this event was sent.

Parameters
eventTime The event time.

public void setEventType (int eventType)

Since: API Level 4

Sets the event type.

Parameters
eventType The event type.

public void setFromIndex (int fromIndex)

Since: API Level 4

Sets the index of the first character of the changed sequence.

Parameters
fromIndex The index of the first character.

public void setFullScreen (boolean isFullScreen)

Since: API Level 4

Sets if the source is taking the entire screen.

Parameters
isFullScreen True if the source is full screen, false otherwise.

public void setItemCount (int itemCount)

Since: API Level 4

Sets the number of items that can be visited.

Parameters
itemCount The number of items.

public void setPackageName (CharSequence packageName)

Since: API Level 4

Sets the package name of the source.

Parameters
packageName The package name.

public void setParcelableData (Parcelable parcelableData)

Since: API Level 4

Sets the Parcelable data of the event.

Parameters
parcelableData The parcelable data.

public void setPassword (boolean isPassword)

Since: API Level 4

Sets if the source is a password field.

Parameters
isPassword True if the view is a password field, false otherwise.

public void setRemovedCount (int removedCount)

Since: API Level 4

Sets the number of removed characters.

Parameters
removedCount The number of removed characters.

public String toString ()

Since: API Level 4

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel parcel, int flags)

Since: API Level 4

Flatten this object in to a Parcel.

Parameters
parcel The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.