AccessibilityRecord
public
class
AccessibilityRecord
extends Object
java.lang.Object | |
↳ | android.view.accessibility.AccessibilityRecord |
Represents a record in an AccessibilityEvent
and contains information
about state change of its source View
. When a view fires
an accessibility event it requests from its parent to dispatch the
constructed event. The parent may optionally append a record for itself
for providing more context to
AccessibilityService
s. Hence,
accessibility services can facilitate additional accessibility records
to enhance feedback.
Once the accessibility event containing a record is dispatched the record is made immutable and calling a state mutation method generates an error.
Note: Not all properties are applicable to all accessibility
event types. For detailed information please refer to AccessibilityEvent
.
Developer Guides
For more information about creating and processing AccessibilityRecords, read the Accessibility developer guide.
Summary
Public constructors | |
---|---|
AccessibilityRecord()
Creates a new |
|
AccessibilityRecord(AccessibilityRecord record)
Copy constructor. |
Public methods | |
---|---|
int
|
getAddedCount()
Gets the number of added characters. |
CharSequence
|
getBeforeText()
Gets 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. |
int
|
getDisplayId()
Gets the id of the display from which the event comes from. |
int
|
getFromIndex()
Gets the index of the first character of the changed sequence, or the beginning of a text selection or the index of the first visible item when scrolling. |
int
|
getItemCount()
Gets the number of items that can be visited. |
int
|
getMaxScrollX()
Gets the max scroll offset of the source left edge in pixels. |
int
|
getMaxScrollY()
Gets the max scroll offset of the source top edge in pixels. |
Parcelable
|
getParcelableData()
Gets the |
int
|
getRemovedCount()
Gets the number of removed characters. |
int
|
getScrollDeltaX()
Gets the difference in pixels between the horizontal position before the scroll and the current horizontal position |
int
|
getScrollDeltaY()
Gets the difference in pixels between the vertical position before the scroll and the current vertical position |
int
|
getScrollX()
Gets the scroll offset of the source left edge in pixels. |
int
|
getScrollY()
Gets the scroll offset of the source top edge in pixels. |
AccessibilityNodeInfo
|
getSource()
Gets the |
AccessibilityNodeInfo
|
getSource(int prefetchingStrategy)
Gets the |
List<CharSequence>
|
getText()
Gets the text of the event. |
int
|
getToIndex()
Gets the index of text selection end or the index of the last visible item when scrolling. |
int
|
getWindowId()
Gets the id of the window from which the event comes from. |
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. |
boolean
|
isScrollable()
Gets if the source is scrollable. |
static
AccessibilityRecord
|
obtain(AccessibilityRecord record)
This method was deprecated
in API level 33.
Object pooling has been discontinued. Create a new instance using the
constructor |
static
AccessibilityRecord
|
obtain()
This method was deprecated
in API level 33.
Object pooling has been discontinued. Create a new instance using the
constructor |
void
|
recycle()
This method was deprecated in API level 33. Object pooling has been discontinued. Calling this function now will have no effect. |
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
|
setFromIndex(int fromIndex)
Sets the index of the first character of the changed sequence or the beginning of a text selection or the index of the first visible item when scrolling. |
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
|
setMaxScrollX(int maxScrollX)
Sets the max scroll offset of the source left edge in pixels. |
void
|
setMaxScrollY(int maxScrollY)
Sets the max scroll offset of the source top edge in pixels. |
void
|
setParcelableData(Parcelable parcelableData)
Sets the |
void
|
setPassword(boolean isPassword)
Sets if the source is a password field. |
void
|
setRemovedCount(int removedCount)
Sets the number of removed characters. |
void
|
setScrollDeltaX(int scrollDeltaX)
Sets the difference in pixels between the horizontal position before the scroll and the current horizontal position |
void
|
setScrollDeltaY(int scrollDeltaY)
Sets the difference in pixels between the vertical position before the scroll and the current vertical position |
void
|
setScrollX(int scrollX)
Sets the scroll offset of the source left edge in pixels. |
void
|
setScrollY(int scrollY)
Sets the scroll offset of the source top edge in pixels. |
void
|
setScrollable(boolean scrollable)
Sets if the source is scrollable. |
void
|
setSource(View root, int virtualDescendantId)
Sets the source to be a virtual descendant of the given |
void
|
setSource(View source)
Sets the event source. |
void
|
setToIndex(int toIndex)
Sets the index of text selection end or the index of the last visible item when scrolling. |
String
|
toString()
Returns a string representation of the object. |
Inherited methods | |
---|---|
Public constructors
AccessibilityRecord
public AccessibilityRecord ()
Creates a new AccessibilityRecord
.
AccessibilityRecord
public AccessibilityRecord (AccessibilityRecord record)
Copy constructor. Creates a new AccessibilityRecord
, and this instance is initialized
with data from the given record
.
Parameters | |
---|---|
record |
AccessibilityRecord : The other record.
This value cannot be null . |
Public methods
getAddedCount
public int getAddedCount ()
Gets the number of added characters.
Returns | |
---|---|
int |
The number of added characters. |
getBeforeText
public CharSequence getBeforeText ()
Gets the text before a change.
Returns | |
---|---|
CharSequence |
The text before the change.
This value may be null . |
getClassName
public CharSequence getClassName ()
Gets the class name of the source.
Returns | |
---|---|
CharSequence |
The class name.
This value may be null . |
getContentDescription
public CharSequence getContentDescription ()
Gets the description of the source.
Returns | |
---|---|
CharSequence |
The description.
This value may be null . |
getCurrentItemIndex
public int getCurrentItemIndex ()
Gets the index of the source in the list of items the can be visited.
Returns | |
---|---|
int |
The current item index. |
getDisplayId
public int getDisplayId ()
Gets the id of the display from which the event comes from.
Returns | |
---|---|
int |
The display id. |
getFromIndex
public int getFromIndex ()
Gets the index of the first character of the changed sequence, or the beginning of a text selection or the index of the first visible item when scrolling.
Returns | |
---|---|
int |
The index of the first character or selection start or the first visible item. |
getItemCount
public int getItemCount ()
Gets the number of items that can be visited.
Returns | |
---|---|
int |
The number of items. |
getMaxScrollX
public int getMaxScrollX ()
Gets the max scroll offset of the source left edge in pixels.
Returns | |
---|---|
int |
The max scroll. |
getMaxScrollY
public int getMaxScrollY ()
Gets the max scroll offset of the source top edge in pixels.
Returns | |
---|---|
int |
The max scroll. |
getParcelableData
public Parcelable getParcelableData ()
Gets the Parcelable
data.
Returns | |
---|---|
Parcelable |
The parcelable data.
This value may be null . |
getRemovedCount
public int getRemovedCount ()
Gets the number of removed characters.
Returns | |
---|---|
int |
The number of removed characters. |
getScrollDeltaX
public int getScrollDeltaX ()
Gets the difference in pixels between the horizontal position before the scroll and the current horizontal position
Returns | |
---|---|
int |
the scroll delta x |
getScrollDeltaY
public int getScrollDeltaY ()
Gets the difference in pixels between the vertical position before the scroll and the current vertical position
Returns | |
---|---|
int |
the scroll delta y |
getScrollX
public int getScrollX ()
Gets the scroll offset of the source left edge in pixels.
Returns | |
---|---|
int |
The scroll. |
getScrollY
public int getScrollY ()
Gets the scroll offset of the source top edge in pixels.
Returns | |
---|---|
int |
The scroll. |
getSource
public AccessibilityNodeInfo getSource ()
Gets the AccessibilityNodeInfo
of the event source.
Note: It is a client responsibility to recycle the received info
by calling AccessibilityNodeInfo#recycle()
to avoid creating of multiple instances.
Returns | |
---|---|
AccessibilityNodeInfo |
The info of the source.
This value may be null . |
getSource
public AccessibilityNodeInfo getSource (int prefetchingStrategy)
Gets the AccessibilityNodeInfo
of the event source.
Parameters | |
---|---|
prefetchingStrategy |
int : the prefetching strategy.
Value is either 0 or a combination of AccessibilityNodeInfo.FLAG_PREFETCH_ANCESTORS , AccessibilityNodeInfo.FLAG_PREFETCH_SIBLINGS , AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS_HYBRID , AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS_DEPTH_FIRST , AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS_BREADTH_FIRST , and AccessibilityNodeInfo.FLAG_PREFETCH_UNINTERRUPTIBLE |
Returns | |
---|---|
AccessibilityNodeInfo |
The info of the source.
This value may be null . |
See also:
getText
public List<CharSequence> getText ()
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 | |
---|---|
List<CharSequence> |
The text.
This value cannot be null . |
getToIndex
public int getToIndex ()
Gets the index of text selection end or the index of the last visible item when scrolling.
Returns | |
---|---|
int |
The index of selection end or last item index. |
getWindowId
public int getWindowId ()
Gets the id of the window from which the event comes from.
Returns | |
---|---|
int |
The window id. |
isChecked
public boolean isChecked ()
Gets if the source is checked.
Returns | |
---|---|
boolean |
True if the view is checked, false otherwise. |
isEnabled
public boolean isEnabled ()
Gets if the source is enabled.
Returns | |
---|---|
boolean |
True if the view is enabled, false otherwise. |
isFullScreen
public boolean isFullScreen ()
Gets if the source is taking the entire screen.
Returns | |
---|---|
boolean |
True if the source is full screen, false otherwise. |
isPassword
public boolean isPassword ()
Gets if the source is a password field.
Returns | |
---|---|
boolean |
True if the view is a password field, false otherwise. |
isScrollable
public boolean isScrollable ()
Gets if the source is scrollable.
Returns | |
---|---|
boolean |
True if the source is scrollable, false otherwise. |
obtain
public static AccessibilityRecord obtain (AccessibilityRecord record)
This method was deprecated
in API level 33.
Object pooling has been discontinued. Create a new instance using the
constructor AccessibilityRecord()
instead.
Instantiates a new record initialized with data from the given record.
Parameters | |
---|---|
record |
AccessibilityRecord : This value cannot be null . |
Returns | |
---|---|
AccessibilityRecord |
An instance.
This value cannot be null . |
obtain
public static AccessibilityRecord obtain ()
This method was deprecated
in API level 33.
Object pooling has been discontinued. Create a new instance using the
constructor AccessibilityRecord()
instead.
Instantiates a new record.
Returns | |
---|---|
AccessibilityRecord |
An instance.
This value cannot be null . |
recycle
public void recycle ()
This method was deprecated
in API level 33.
Object pooling has been discontinued. Calling this function now will have
no effect.
Would previously return an instance back to be reused.
setAddedCount
public void setAddedCount (int addedCount)
Sets the number of added characters.
Parameters | |
---|---|
addedCount |
int : The number of added characters. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setBeforeText
public void setBeforeText (CharSequence beforeText)
Sets the text before a change.
Parameters | |
---|---|
beforeText |
CharSequence : The text before the change.
This value may be null . |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setChecked
public void setChecked (boolean isChecked)
Sets if the source is checked.
Parameters | |
---|---|
isChecked |
boolean : True if the view is checked, false otherwise. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setClassName
public void setClassName (CharSequence className)
Sets the class name of the source.
Parameters | |
---|---|
className |
CharSequence : The lass name.
This value may be null . |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setContentDescription
public void setContentDescription (CharSequence contentDescription)
Sets the description of the source.
Parameters | |
---|---|
contentDescription |
CharSequence : The description.
This value may be null . |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setCurrentItemIndex
public void setCurrentItemIndex (int currentItemIndex)
Sets the index of the source in the list of items that can be visited.
Parameters | |
---|---|
currentItemIndex |
int : The current item index. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setEnabled
public void setEnabled (boolean isEnabled)
Sets if the source is enabled.
Parameters | |
---|---|
isEnabled |
boolean : True if the view is enabled, false otherwise. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setFromIndex
public void setFromIndex (int fromIndex)
Sets the index of the first character of the changed sequence or the beginning of a text selection or the index of the first visible item when scrolling.
Parameters | |
---|---|
fromIndex |
int : The index of the first character or selection
start or the first visible item. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setFullScreen
public void setFullScreen (boolean isFullScreen)
Sets if the source is taking the entire screen.
Parameters | |
---|---|
isFullScreen |
boolean : True if the source is full screen, false otherwise. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setItemCount
public void setItemCount (int itemCount)
Sets the number of items that can be visited.
Parameters | |
---|---|
itemCount |
int : The number of items. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setMaxScrollX
public void setMaxScrollX (int maxScrollX)
Sets the max scroll offset of the source left edge in pixels.
Parameters | |
---|---|
maxScrollX |
int : The max scroll. |
setMaxScrollY
public void setMaxScrollY (int maxScrollY)
Sets the max scroll offset of the source top edge in pixels.
Parameters | |
---|---|
maxScrollY |
int : The max scroll. |
setParcelableData
public void setParcelableData (Parcelable parcelableData)
Sets the Parcelable
data of the event.
Parameters | |
---|---|
parcelableData |
Parcelable : The parcelable data.
This value may be null . |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setPassword
public void setPassword (boolean isPassword)
Sets if the source is a password field.
Parameters | |
---|---|
isPassword |
boolean : True if the view is a password field, false otherwise. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setRemovedCount
public void setRemovedCount (int removedCount)
Sets the number of removed characters.
Parameters | |
---|---|
removedCount |
int : The number of removed characters. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setScrollDeltaX
public void setScrollDeltaX (int scrollDeltaX)
Sets the difference in pixels between the horizontal position before the scroll and the current horizontal position
Parameters | |
---|---|
scrollDeltaX |
int : the scroll delta x |
setScrollDeltaY
public void setScrollDeltaY (int scrollDeltaY)
Sets the difference in pixels between the vertical position before the scroll and the current vertical position
Parameters | |
---|---|
scrollDeltaY |
int : the scroll delta y |
setScrollX
public void setScrollX (int scrollX)
Sets the scroll offset of the source left edge in pixels.
Parameters | |
---|---|
scrollX |
int : The scroll. |
setScrollY
public void setScrollY (int scrollY)
Sets the scroll offset of the source top edge in pixels.
Parameters | |
---|---|
scrollY |
int : The scroll. |
setScrollable
public void setScrollable (boolean scrollable)
Sets if the source is scrollable.
Parameters | |
---|---|
scrollable |
boolean : True if the source is scrollable, false otherwise. |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setSource
public void setSource (View root, int virtualDescendantId)
Sets the source to be a virtual descendant of the given root
.
If virtualDescendantId
equals to View.NO_ID
the root
is set as the source.
A virtual descendant is an imaginary View that is reported as a part of the view hierarchy for accessibility purposes. This enables custom views that draw complex content to report them selves as a tree of virtual views, thus conveying their logical structure.
Parameters | |
---|---|
root |
View : The root of the virtual subtree.
This value may be null . |
virtualDescendantId |
int : The id of the virtual descendant. |
setSource
public void setSource (View source)
Sets the event source.
Parameters | |
---|---|
source |
View : The source.
This value may be null . |
Throws | |
---|---|
IllegalStateException |
If called from an AccessibilityService. |
setToIndex
public void setToIndex (int toIndex)
Sets the index of text selection end or the index of the last visible item when scrolling.
Parameters | |
---|---|
toIndex |
int : The index of selection end or last item index. |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |