FileDocCategorySizeDatePackage
AccessibilityRecord.javaAPI DocAndroid 5.1 API24902Thu Mar 12 22:22:10 GMT 2015android.view.accessibility

AccessibilityRecord

public class AccessibilityRecord extends Object
Represents a record in an {@link AccessibilityEvent} and contains information about state change of its source {@link android.view.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 {@link android.accessibilityservice.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 {@link AccessibilityEvent}.

Developer Guides

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

see
AccessibilityEvent
see
AccessibilityManager
see
android.accessibilityservice.AccessibilityService
see
AccessibilityNodeInfo

Fields Summary
private static final int
UNDEFINED
private static final int
PROPERTY_CHECKED
private static final int
PROPERTY_ENABLED
private static final int
PROPERTY_PASSWORD
private static final int
PROPERTY_FULL_SCREEN
private static final int
PROPERTY_SCROLLABLE
private static final int
PROPERTY_IMPORTANT_FOR_ACCESSIBILITY
private static final int
GET_SOURCE_PREFETCH_FLAGS
private static final int
MAX_POOL_SIZE
private static final Object
sPoolLock
private static AccessibilityRecord
sPool
private static int
sPoolSize
private AccessibilityRecord
mNext
private boolean
mIsInPool
boolean
mSealed
int
mBooleanProperties
int
mCurrentItemIndex
int
mItemCount
int
mFromIndex
int
mToIndex
int
mScrollX
int
mScrollY
int
mMaxScrollX
int
mMaxScrollY
int
mAddedCount
int
mRemovedCount
long
mSourceNodeId
int
mSourceWindowId
CharSequence
mClassName
CharSequence
mContentDescription
CharSequence
mBeforeText
android.os.Parcelable
mParcelableData
final List
mText
int
mConnectionId
Constructors Summary
AccessibilityRecord()


    /*
     * Hide constructor.
     */
     
    
Methods Summary
voidclear()
Clears the state of this instance.

        mSealed = false;
        mBooleanProperties = 0;
        mCurrentItemIndex = UNDEFINED;
        mItemCount = UNDEFINED;
        mFromIndex = UNDEFINED;
        mToIndex = UNDEFINED;
        mScrollX = UNDEFINED;
        mScrollY = UNDEFINED;
        mMaxScrollX = UNDEFINED;
        mMaxScrollY = UNDEFINED;
        mAddedCount = UNDEFINED;
        mRemovedCount = UNDEFINED;
        mClassName = null;
        mContentDescription = null;
        mBeforeText = null;
        mParcelableData = null;
        mText.clear();
        mSourceNodeId = AccessibilityNodeInfo.makeNodeId(UNDEFINED, UNDEFINED);
        mSourceWindowId = UNDEFINED;
        mConnectionId = UNDEFINED;
    
voidenforceNotSealed()
Enforces that this instance is not sealed.

throws
IllegalStateException If this instance is sealed.

        if (isSealed()) {
            throw new IllegalStateException("Cannot perform this "
                    + "action on a sealed instance.");
        }
    
voidenforceSealed()
Enforces that this instance is sealed.

throws
IllegalStateException If this instance is not sealed.

        if (!isSealed()) {
            throw new IllegalStateException("Cannot perform this "
                    + "action on a not sealed instance.");
        }
    
public intgetAddedCount()
Gets the number of added characters.

return
The number of added characters.

        return mAddedCount;
    
public java.lang.CharSequencegetBeforeText()
Sets the text before a change.

return
The text before the change.

        return mBeforeText;
    
private booleangetBooleanProperty(int property)
Gets the value of a boolean property.

param
property The property.
return
The value.

        return (mBooleanProperties & property) == property;
    
public java.lang.CharSequencegetClassName()
Gets the class name of the source.

return
The class name.

        return mClassName;
    
public java.lang.CharSequencegetContentDescription()
Gets the description of the source.

return
The description.

        return mContentDescription;
    
public intgetCurrentItemIndex()
Gets the index of the source in the list of items the can be visited.

return
The current item index.

        return mCurrentItemIndex;
    
public intgetFromIndex()
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.

return
The index of the first character or selection start or the first visible item.

        return mFromIndex;
    
public intgetItemCount()
Gets the number of items that can be visited.

return
The number of items.

        return mItemCount;
    
public intgetMaxScrollX()
Gets the max scroll offset of the source left edge in pixels.

return
The max scroll.

        return mMaxScrollX;
    
public intgetMaxScrollY()
Gets the max scroll offset of the source top edge in pixels.

return
The max scroll.

        return mMaxScrollY;
    
public android.os.ParcelablegetParcelableData()
Gets the {@link Parcelable} data.

return
The parcelable data.

        return mParcelableData;
    
public intgetRemovedCount()
Gets the number of removed characters.

return
The number of removed characters.

        return mRemovedCount;
    
public intgetScrollX()
Gets the scroll offset of the source left edge in pixels.

return
The scroll.

        return mScrollX;
    
public intgetScrollY()
Gets the scroll offset of the source top edge in pixels.

return
The scroll.

        return mScrollY;
    
public AccessibilityNodeInfogetSource()
Gets the {@link AccessibilityNodeInfo} of the event source.

Note: It is a client responsibility to recycle the received info by calling {@link AccessibilityNodeInfo#recycle() AccessibilityNodeInfo#recycle()} to avoid creating of multiple instances.

return
The info of the source.

        enforceSealed();
        if (mConnectionId == UNDEFINED || mSourceWindowId == UNDEFINED
                || AccessibilityNodeInfo.getAccessibilityViewId(mSourceNodeId) == UNDEFINED) {
            return null;
        }
        AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance();
        return client.findAccessibilityNodeInfoByAccessibilityId(mConnectionId, mSourceWindowId,
                mSourceNodeId, false, GET_SOURCE_PREFETCH_FLAGS);
    
public longgetSourceNodeId()
Gets the id of the source node.

return
The id.
hide

        return mSourceNodeId;
    
public java.util.ListgetText()
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.

return
The text.

        return mText;
    
public intgetToIndex()
Gets the index of text selection end or the index of the last visible item when scrolling.

return
The index of selection end or last item index.

        return mToIndex;
    
public intgetWindowId()
Gets the id of the window from which the event comes from.

return
The window id.

        return mSourceWindowId;
    
voidinit(android.view.accessibility.AccessibilityRecord record)
Initialize this record from another one.

param
record The to initialize from.

        mSealed = record.mSealed;
        mBooleanProperties = record.mBooleanProperties;
        mCurrentItemIndex = record.mCurrentItemIndex;
        mItemCount = record.mItemCount;
        mFromIndex = record.mFromIndex;
        mToIndex = record.mToIndex;
        mScrollX = record.mScrollX;
        mScrollY = record.mScrollY;
        mMaxScrollX = record.mMaxScrollX;
        mMaxScrollY = record.mMaxScrollY;
        mAddedCount = record.mAddedCount;
        mRemovedCount = record.mRemovedCount;
        mClassName = record.mClassName;
        mContentDescription = record.mContentDescription;
        mBeforeText = record.mBeforeText;
        mParcelableData = record.mParcelableData;
        mText.addAll(record.mText);
        mSourceWindowId = record.mSourceWindowId;
        mSourceNodeId = record.mSourceNodeId;
        mConnectionId = record.mConnectionId;
    
public booleanisChecked()
Gets if the source is checked.

return
True if the view is checked, false otherwise.

        return getBooleanProperty(PROPERTY_CHECKED);
    
public booleanisEnabled()
Gets if the source is enabled.

return
True if the view is enabled, false otherwise.

        return getBooleanProperty(PROPERTY_ENABLED);
    
public booleanisFullScreen()
Gets if the source is taking the entire screen.

return
True if the source is full screen, false otherwise.

        return getBooleanProperty(PROPERTY_FULL_SCREEN);
    
public booleanisImportantForAccessibility()
Gets if the source is important for accessibility. Note: Used only internally to determine whether to deliver the event to a given accessibility service since some services may want to regard all views for accessibility while others may want to regard only the important views for accessibility.

return
True if the source is important for accessibility, false otherwise.
hide

        return getBooleanProperty(PROPERTY_IMPORTANT_FOR_ACCESSIBILITY);
    
public booleanisPassword()
Gets if the source is a password field.

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

        return getBooleanProperty(PROPERTY_PASSWORD);
    
public booleanisScrollable()
Gets if the source is scrollable.

return
True if the source is scrollable, false otherwise.

        return getBooleanProperty(PROPERTY_SCROLLABLE);
    
booleanisSealed()
Gets if this instance is sealed.

return
Whether is sealed.

        return mSealed;
    
public static android.view.accessibility.AccessibilityRecordobtain(android.view.accessibility.AccessibilityRecord record)
Returns a cached instance if such is available or a new one is instantiated. The instance is initialized with data from the given record.

return
An instance.

       AccessibilityRecord clone = AccessibilityRecord.obtain();
       clone.init(record);
       return clone;
    
public static android.view.accessibility.AccessibilityRecordobtain()
Returns a cached instance if such is available or a new one is instantiated.

return
An instance.

        synchronized (sPoolLock) {
            if (sPool != null) {
                AccessibilityRecord record = sPool;
                sPool = sPool.mNext;
                sPoolSize--;
                record.mNext = null;
                record.mIsInPool = false;
                return record;
            }
            return new AccessibilityRecord();
        }
    
public voidrecycle()
Return an instance back to be reused.

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

throws
IllegalStateException If the record is already recycled.

        if (mIsInPool) {
            throw new IllegalStateException("Record already recycled!");
        }
        clear();
        synchronized (sPoolLock) {
            if (sPoolSize <= MAX_POOL_SIZE) {
                mNext = sPool;
                sPool = this;
                mIsInPool = true;
                sPoolSize++;
            }
        }
    
public voidsetAddedCount(int addedCount)
Sets the number of added characters.

param
addedCount The number of added characters.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mAddedCount = addedCount;
    
public voidsetBeforeText(java.lang.CharSequence beforeText)
Sets the text before a change.

param
beforeText The text before the change.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mBeforeText = beforeText;
    
private voidsetBooleanProperty(int property, boolean value)
Sets a boolean property.

param
property The property.
param
value The value.

        if (value) {
            mBooleanProperties |= property;
        } else {
            mBooleanProperties &= ~property;
        }
    
public voidsetChecked(boolean isChecked)
Sets if the source is checked.

param
isChecked True if the view is checked, false otherwise.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        setBooleanProperty(PROPERTY_CHECKED, isChecked);
    
public voidsetClassName(java.lang.CharSequence className)
Sets the class name of the source.

param
className The lass name.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mClassName = className;
    
public voidsetConnectionId(int connectionId)
Sets the unique id of the IAccessibilityServiceConnection over which this instance can send requests to the system.

param
connectionId The connection id.
hide

        enforceNotSealed();
        mConnectionId = connectionId;
    
public voidsetContentDescription(java.lang.CharSequence contentDescription)
Sets the description of the source.

param
contentDescription The description.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mContentDescription = contentDescription;
    
public voidsetCurrentItemIndex(int currentItemIndex)
Sets the index of the source in the list of items that can be visited.

param
currentItemIndex The current item index.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mCurrentItemIndex = currentItemIndex;
    
public voidsetEnabled(boolean isEnabled)
Sets if the source is enabled.

param
isEnabled True if the view is enabled, false otherwise.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        setBooleanProperty(PROPERTY_ENABLED, isEnabled);
    
public voidsetFromIndex(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.

param
fromIndex The index of the first character or selection start or the first visible item.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mFromIndex = fromIndex;
    
public voidsetFullScreen(boolean isFullScreen)
Sets if the source is taking the entire screen.

param
isFullScreen True if the source is full screen, false otherwise.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        setBooleanProperty(PROPERTY_FULL_SCREEN, isFullScreen);
    
public voidsetItemCount(int itemCount)
Sets the number of items that can be visited.

param
itemCount The number of items.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mItemCount = itemCount;
    
public voidsetMaxScrollX(int maxScrollX)
Sets the max scroll offset of the source left edge in pixels.

param
maxScrollX The max scroll.

        enforceNotSealed();
        mMaxScrollX = maxScrollX;
    
public voidsetMaxScrollY(int maxScrollY)
Sets the max scroll offset of the source top edge in pixels.

param
maxScrollY The max scroll.

        enforceNotSealed();
        mMaxScrollY = maxScrollY;
    
public voidsetParcelableData(android.os.Parcelable parcelableData)
Sets the {@link Parcelable} data of the event.

param
parcelableData The parcelable data.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mParcelableData = parcelableData;
    
public voidsetPassword(boolean isPassword)
Sets if the source is a password field.

param
isPassword True if the view is a password field, false otherwise.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        setBooleanProperty(PROPERTY_PASSWORD, isPassword);
    
public voidsetRemovedCount(int removedCount)
Sets the number of removed characters.

param
removedCount The number of removed characters.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        mRemovedCount = removedCount;
    
public voidsetScrollX(int scrollX)
Sets the scroll offset of the source left edge in pixels.

param
scrollX The scroll.

        enforceNotSealed();
        mScrollX = scrollX;
    
public voidsetScrollY(int scrollY)
Sets the scroll offset of the source top edge in pixels.

param
scrollY The scroll.

        enforceNotSealed();
        mScrollY = scrollY;
    
public voidsetScrollable(boolean scrollable)
Sets if the source is scrollable.

param
scrollable True if the source is scrollable, false otherwise.
throws
IllegalStateException If called from an AccessibilityService.

        enforceNotSealed();
        setBooleanProperty(PROPERTY_SCROLLABLE, scrollable);
    
public voidsetSealed(boolean sealed)
Sets if this instance is sealed.

param
sealed Whether is sealed.
hide

        mSealed = sealed;
    
public voidsetSource(android.view.View source)
Sets the event source.

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

        setSource(source, UNDEFINED);
    
public voidsetSource(android.view.View root, int virtualDescendantId)
Sets the source to be a virtual descendant of the given root. If virtualDescendantId equals to {@link 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.

param
root The root of the virtual subtree.
param
virtualDescendantId The id of the virtual descendant.

        enforceNotSealed();
        final boolean important;
        if (virtualDescendantId == UNDEFINED) {
            important = (root != null) ? root.isImportantForAccessibility() : true;
        } else {
            important = true;
        }
        setBooleanProperty(PROPERTY_IMPORTANT_FOR_ACCESSIBILITY, important);
        mSourceWindowId = (root != null) ? root.getAccessibilityWindowId() : UNDEFINED;
        final int rootViewId = (root != null) ? root.getAccessibilityViewId() : UNDEFINED;
        mSourceNodeId = AccessibilityNodeInfo.makeNodeId(rootViewId, virtualDescendantId);
    
public voidsetToIndex(int toIndex)
Sets the index of text selection end or the index of the last visible item when scrolling.

param
toIndex The index of selection end or last item index.

        enforceNotSealed();
        mToIndex = toIndex;
    
public voidsetWindowId(int windowId)
Sets the window id.

param
windowId The window id.
hide

        mSourceWindowId = windowId;
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();
        builder.append(" [ ClassName: " + mClassName);
        builder.append("; Text: " + mText);
        builder.append("; ContentDescription: " + mContentDescription);
        builder.append("; ItemCount: " + mItemCount);
        builder.append("; CurrentItemIndex: " + mCurrentItemIndex);
        builder.append("; IsEnabled: " + getBooleanProperty(PROPERTY_ENABLED));
        builder.append("; IsPassword: " + getBooleanProperty(PROPERTY_PASSWORD));
        builder.append("; IsChecked: " + getBooleanProperty(PROPERTY_CHECKED));
        builder.append("; IsFullScreen: " + getBooleanProperty(PROPERTY_FULL_SCREEN));
        builder.append("; Scrollable: " + getBooleanProperty(PROPERTY_SCROLLABLE));
        builder.append("; BeforeText: " + mBeforeText);
        builder.append("; FromIndex: " + mFromIndex);
        builder.append("; ToIndex: " + mToIndex);
        builder.append("; ScrollX: " + mScrollX);
        builder.append("; ScrollY: " + mScrollY);
        builder.append("; MaxScrollX: " + mMaxScrollX);
        builder.append("; MaxScrollY: " + mMaxScrollY);
        builder.append("; AddedCount: " + mAddedCount);
        builder.append("; RemovedCount: " + mRemovedCount);
        builder.append("; ParcelableData: " + mParcelableData);
        builder.append(" ]");
        return builder.toString();