Skip to content

Commit b7ff325

Browse files
committed
Adding explicit text traversal granularities and actions for web navigation.
1. The granularities for traversing the text content of an accessibility node info are now predefined constants and custom ones will not be supported. This is the simplest solution - we can always add namespaced user defined ones (unlikely). 2. Added actions for traversing web content. These actions can be used by an accessibility service to transparently drive the JavaScript based screen reader that is used for handling web content. 3. Added a new accessibility event type for traversing the content of a view. This event is needed to announce to the user what is the next element, i.e. the one next to the cursor, after the view's text was traversed. bug:5932640 bug:6389591 Change-Id: I144647da55bc4005c64f89865ef333af8359e145
1 parent 76f287e commit b7ff325

File tree

4 files changed

+246
-72
lines changed

4 files changed

+246
-72
lines changed

api/current.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24927,6 +24927,7 @@ package android.view.accessibility {
2492724927
method public static java.lang.String eventTypeToString(int);
2492824928
method public long getEventTime();
2492924929
method public int getEventType();
24930+
method public int getGranularity();
2493024931
method public java.lang.CharSequence getPackageName();
2493124932
method public android.view.accessibility.AccessibilityRecord getRecord(int);
2493224933
method public int getRecordCount();
@@ -24936,6 +24937,7 @@ package android.view.accessibility {
2493624937
method public static android.view.accessibility.AccessibilityEvent obtain();
2493724938
method public void setEventTime(long);
2493824939
method public void setEventType(int);
24940+
method public void setGranularity(int);
2493924941
method public void setPackageName(java.lang.CharSequence);
2494024942
method public void writeToParcel(android.os.Parcel, int);
2494124943
field public static final android.os.Parcelable.Creator CREATOR;
@@ -24957,6 +24959,7 @@ package android.view.accessibility {
2495724959
field public static final int TYPE_VIEW_SELECTED = 4; // 0x4
2495824960
field public static final int TYPE_VIEW_TEXT_CHANGED = 16; // 0x10
2495924961
field public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 8192; // 0x2000
24962+
field public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_GRANULARITY = 131072; // 0x20000
2496024963
field public static final int TYPE_WINDOW_CONTENT_CHANGED = 2048; // 0x800
2496124964
field public static final int TYPE_WINDOW_STATE_CHANGED = 32; // 0x20
2496224965
}
@@ -24997,7 +25000,7 @@ package android.view.accessibility {
2499725000
method public int getChildCount();
2499825001
method public java.lang.CharSequence getClassName();
2499925002
method public java.lang.CharSequence getContentDescription();
25000-
method public java.lang.CharSequence[] getGranularities();
25003+
method public int getGranularities();
2500125004
method public java.lang.CharSequence getPackageName();
2500225005
method public android.view.accessibility.AccessibilityNodeInfo getParent();
2500325006
method public java.lang.CharSequence getText();
@@ -25031,7 +25034,7 @@ package android.view.accessibility {
2503125034
method public void setEnabled(boolean);
2503225035
method public void setFocusable(boolean);
2503325036
method public void setFocused(boolean);
25034-
method public void setGranularities(java.lang.CharSequence[]);
25037+
method public void setGranularities(int);
2503525038
method public void setLongClickable(boolean);
2503625039
method public void setPackageName(java.lang.CharSequence);
2503725040
method public void setParent(android.view.View);
@@ -25044,19 +25047,27 @@ package android.view.accessibility {
2504425047
method public void setText(java.lang.CharSequence);
2504525048
method public void writeToParcel(android.os.Parcel, int);
2504625049
field public static final int ACTION_ACCESSIBILITY_FOCUS = 64; // 0x40
25047-
field public static final java.lang.String ACTION_ARGUMENT_GRANULARITY = "ACTION_ARGUMENT_GRANULARITY";
25050+
field public static final java.lang.String ACTION_ARGUMENT_GRANULARITY_INT = "ACTION_ARGUMENT_GRANULARITY_INT";
25051+
field public static final java.lang.String ACTION_ARGUMENT_HTML_ELEMENT_STRING = "ACTION_ARGUMENT_HTML_ELEMENT_STRING";
2504825052
field public static final int ACTION_CLEAR_ACCESSIBILITY_FOCUS = 128; // 0x80
2504925053
field public static final int ACTION_CLEAR_FOCUS = 2; // 0x2
2505025054
field public static final int ACTION_CLEAR_SELECTION = 8; // 0x8
2505125055
field public static final int ACTION_CLICK = 16; // 0x10
2505225056
field public static final int ACTION_FOCUS = 1; // 0x1
2505325057
field public static final int ACTION_LONG_CLICK = 32; // 0x20
2505425058
field public static final int ACTION_NEXT_AT_GRANULARITY = 256; // 0x100
25059+
field public static final int ACTION_NEXT_HTML_ELEMENT = 1024; // 0x400
2505525060
field public static final int ACTION_PREVIOUS_AT_GRANULARITY = 512; // 0x200
25061+
field public static final int ACTION_PREVIOUS_HTML_ELEMENT = 2048; // 0x800
2505625062
field public static final int ACTION_SELECT = 4; // 0x4
2505725063
field public static final android.os.Parcelable.Creator CREATOR;
2505825064
field public static final int FOCUS_ACCESSIBILITY = 2; // 0x2
2505925065
field public static final int FOCUS_INPUT = 1; // 0x1
25066+
field public static final int GRANULARITY_CHARACTER = 1; // 0x1
25067+
field public static final int GRANULARITY_LINE = 4; // 0x4
25068+
field public static final int GRANULARITY_PAGE = 16; // 0x10
25069+
field public static final int GRANULARITY_PARAGRAPH = 8; // 0x8
25070+
field public static final int GRANULARITY_WORD = 2; // 0x2
2506025071
}
2506125072

2506225073
public abstract class AccessibilityNodeProvider {

core/java/android/view/accessibility/AccessibilityEvent.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,23 @@
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

Comments
 (0)