226226 * <li>{@link #getContentDescription()} - The content description of the source.</li>
227227 * </ul>
228228 * </p>
229+ * <b>View text traversed at granularity</b> - represents the event of traversing the
230+ * text of a view at a given granularity. For example, moving to the next word.</br>
231+ * <em>Type:</em> {@link #TYPE_VIEW_TEXT_TRAVERSED_AT_GRANULARITY} </br>
232+ * <em>Properties:</em></br>
233+ * <ul>
234+ * <li>{@link #getEventType()} - The type of the event.</li>
235+ * <li>{@link #getSource()} - The source info (for registered clients).</li>
236+ * <li>{@link #getClassName()} - The class name of the source.</li>
237+ * <li>{@link #getPackageName()} - The package name of the source.</li>
238+ * <li>{@link #getEventTime()} - The event time.</li>
239+ * <li>{@link #getText()} - The text of the current text at the granularity.</li>
240+ * <li>{@link #isPassword()} - Whether the source is password.</li>
241+ * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
242+ * <li>{@link #getContentDescription()} - The content description of the source.</li>
243+ * <li>{@link #getGranularity()} - Sets the granularity at which a view's text was traversed.</li>
244+ * </ul>
245+ * </p>
229246 * <p>
230247 * <b>View scrolled</b> - represents the event of scrolling a view. If
231248 * the source is a descendant of {@link android.widget.AdapterView} the
@@ -579,6 +596,11 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
579596 */
580597 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000 ;
581598
599+ /**
600+ * Represents the event of traversing the text of a view at a given granularity.
601+ */
602+ public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_GRANULARITY = 0x00020000 ;
603+
582604 /**
583605 * Mask for {@link AccessibilityEvent} all types.
584606 *
@@ -597,6 +619,7 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
597619 * @see #TYPE_VIEW_SCROLLED
598620 * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
599621 * @see #TYPE_ANNOUNCEMENT
622+ * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_GRANULARITY
600623 */
601624 public static final int TYPES_ALL_MASK = 0xFFFFFFFF ;
602625
@@ -610,6 +633,7 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
610633 private int mEventType ;
611634 private CharSequence mPackageName ;
612635 private long mEventTime ;
636+ int mGranularity ;
613637
614638 private final ArrayList <AccessibilityRecord > mRecords = new ArrayList <AccessibilityRecord >();
615639
@@ -627,6 +651,7 @@ private AccessibilityEvent() {
627651 void init (AccessibilityEvent event ) {
628652 super .init (event );
629653 mEventType = event .mEventType ;
654+ mGranularity = event .mGranularity ;
630655 mEventTime = event .mEventTime ;
631656 mPackageName = event .mPackageName ;
632657 }
@@ -743,6 +768,27 @@ public void setPackageName(CharSequence packageName) {
743768 mPackageName = packageName ;
744769 }
745770
771+ /**
772+ * Sets the text granularity that was traversed.
773+ *
774+ * @param granularity The granularity.
775+ *
776+ * @throws IllegalStateException If called from an AccessibilityService.
777+ */
778+ public void setGranularity (int granularity ) {
779+ enforceNotSealed ();
780+ mGranularity = granularity ;
781+ }
782+
783+ /**
784+ * Gets the text granularity that was traversed.
785+ *
786+ * @return The granularity.
787+ */
788+ public int getGranularity () {
789+ return mGranularity ;
790+ }
791+
746792 /**
747793 * Returns a cached instance if such is available or a new one is
748794 * instantiated with its type property set.
@@ -831,6 +877,7 @@ public void recycle() {
831877 protected void clear () {
832878 super .clear ();
833879 mEventType = 0 ;
880+ mGranularity = 0 ;
834881 mPackageName = null ;
835882 mEventTime = 0 ;
836883 while (!mRecords .isEmpty ()) {
@@ -847,6 +894,7 @@ protected void clear() {
847894 public void initFromParcel (Parcel parcel ) {
848895 mSealed = (parcel .readInt () == 1 );
849896 mEventType = parcel .readInt ();
897+ mGranularity = parcel .readInt ();
850898 mPackageName = TextUtils .CHAR_SEQUENCE_CREATOR .createFromParcel (parcel );
851899 mEventTime = parcel .readLong ();
852900 mConnectionId = parcel .readInt ();
@@ -897,6 +945,7 @@ private void readAccessibilityRecordFromParcel(AccessibilityRecord record,
897945 public void writeToParcel (Parcel parcel , int flags ) {
898946 parcel .writeInt (isSealed () ? 1 : 0 );
899947 parcel .writeInt (mEventType );
948+ parcel .writeInt (mGranularity );
900949 TextUtils .writeToParcel (mPackageName , parcel , 0 );
901950 parcel .writeLong (mEventTime );
902951 parcel .writeInt (mConnectionId );
@@ -953,6 +1002,7 @@ public String toString() {
9531002 builder .append ("EventType: " ).append (eventTypeToString (mEventType ));
9541003 builder .append ("; EventTime: " ).append (mEventTime );
9551004 builder .append ("; PackageName: " ).append (mPackageName );
1005+ builder .append ("; Granularity: " ).append (mGranularity );
9561006 builder .append (super .toString ());
9571007 if (DEBUG ) {
9581008 builder .append ("\n " );
@@ -1033,6 +1083,8 @@ public static String eventTypeToString(int eventType) {
10331083 return "TYPE_VIEW_ACCESSIBILITY_FOCUSED" ;
10341084 case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED :
10351085 return "TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED" ;
1086+ case TYPE_VIEW_TEXT_TRAVERSED_AT_GRANULARITY :
1087+ return "TYPE_CURRENT_AT_GRANULARITY_CHANGED" ;
10361088 default :
10371089 return null ;
10381090 }
0 commit comments