Skip to content

Commit b303d83

Browse files
committed
docs: a couple notes for a11y methods in View and cleanup to the
A11y service HTML to be semantically correct and thus improve its accessibility :) Change-Id: I483a8a441d802b056f68f82e0e782d86a73298ac
1 parent f4b40de commit b303d83

File tree

3 files changed

+80
-106
lines changed

3 files changed

+80
-106
lines changed

core/java/android/accessibilityservice/AccessibilityService.java

Lines changed: 52 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
* when {@link AccessibilityEvent}s are fired. Such events denote some state transition
3333
* in the user interface, for example, the focus has changed, a button has been clicked,
3434
* etc. Such a service can optionally request the capability for querying the content
35-
* of the active window. Development of an accessibility service requires extends this
36-
* class and implements its abstract methods.
37-
* <p>
38-
* <strong>Lifecycle</strong>
39-
* </p>
35+
* of the active window. Development of an accessibility service requires extending this
36+
* class and implementing its abstract methods.
37+
* <h3>Lifecycle</h3>
4038
* <p>
4139
* The lifecycle of an accessibility service is managed exclusively by the system and
4240
* follows the established service life cycle. Additionally, starting or stopping an
@@ -45,30 +43,20 @@
4543
* calls {@link AccessibilityService#onServiceConnected()}. This method can be
4644
* overriden by clients that want to perform post binding setup.
4745
* </p>
48-
* <p>
49-
* <strong>Declaration</strong>
50-
* </p>
46+
* <h3>Declaration</h3>
5147
* <p>
5248
* An accessibility is declared as any other service in an AndroidManifest.xml but it
5349
* must also specify that it handles the "android.accessibilityservice.AccessibilityService"
5450
* {@link android.content.Intent}. Failure to declare this intent will cause the system to
5551
* ignore the accessibility service. Following is an example declaration:
5652
* </p>
57-
* <p>
58-
* <code>
59-
* <pre>
60-
* &lt;service android:name=".MyAccessibilityService"&gt;
53+
* <pre> &lt;service android:name=".MyAccessibilityService"&gt;
6154
* &lt;intent-filter&gt;
62-
* &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
55+
* &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
6356
* &lt;/intent-filter&gt;
6457
* . . .
65-
* &lt;/service&gt;
66-
* </pre>
67-
* </code>
68-
* </p>
69-
* <p>
70-
* <strong>Configuration</strong>
71-
* </p>
58+
* &lt;/service&gt;</pre>
59+
* <h3>Configuration</h3>
7260
* <p>
7361
* An accessibility service can be configured to receive specific types of accessibility events,
7462
* listen only to specific packages, get events from each type only once in a given time frame,
@@ -81,30 +69,24 @@
8169
* <li>
8270
* Providing a {@link #SERVICE_META_DATA meta-data} entry in the manifest when declaring
8371
* the service. A service declaration with a meta-data tag is presented below:
84-
* <p>
85-
* <code>
86-
* <pre>
87-
* &lt;service android:name=".MyAccessibilityService"&gt;
72+
* <pre> &lt;service android:name=".MyAccessibilityService"&gt;
8873
* &lt;intent-filter&gt;
89-
* &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
74+
* &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
9075
* &lt;/intent-filter&gt;
9176
* &lt;meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" /&gt;
92-
* &lt;/service&gt;
93-
* </pre>
94-
* </code>
95-
* </p>
96-
* <p>
97-
* <strong>Note:</strong>This approach enables setting all properties.
77+
* &lt;/service&gt;</pre>
78+
* <p class="note">
79+
* <strong>Note:</strong> This approach enables setting all properties.
9880
* </p>
9981
* <p>
10082
* For more details refer to {@link #SERVICE_META_DATA} and
101-
* <code>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</code>..
83+
* <code>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</code>.
10284
* </p>
10385
* </li>
10486
* <li>
10587
* Calling {@link AccessibilityService#setServiceInfo(AccessibilityServiceInfo)}. Note
10688
* that this method can be called any time to dynamically change the service configuration.
107-
* <p>
89+
* <p class="note">
10890
* <strong>Note:</strong> This approach enables setting only dynamically configurable properties:
10991
* {@link AccessibilityServiceInfo#eventTypes},
11092
* {@link AccessibilityServiceInfo#feedbackType},
@@ -117,9 +99,7 @@
11799
* </p>
118100
* </li>
119101
* </ul>
120-
* <p>
121-
* <strong>Retrieving window content</strong>
122-
* </p>
102+
* <h3>Retrieving window content</h3>
123103
* <p>
124104
* An service can specify in its declaration that it can retrieve the active window
125105
* content which is represented as a tree of {@link AccessibilityNodeInfo}. Note that
@@ -144,8 +124,8 @@
144124
* this method will return an {@link AccessibilityNodeInfo} that can be used to traverse the
145125
* window content which represented as a tree of such objects.
146126
* </p>
147-
* <p>
148-
* <strong>Note</strong>An accessibility service may have requested to be notified for
127+
* <p class="note">
128+
* <strong>Note</strong> An accessibility service may have requested to be notified for
149129
* a subset of the event types, thus be unaware that the active window has changed. Therefore
150130
* accessibility service that would like to retrieve window content should:
151131
* <ul>
@@ -158,15 +138,13 @@
158138
* <li>
159139
* Prepare that a retrieval method on {@link AccessibilityNodeInfo} may fail since the
160140
* active window has changed and the service did not get the accessibility event yet. Note
161-
* that it is possible to have a retrieval method failing event adopting the strategy
141+
* that it is possible to have a retrieval method failing even adopting the strategy
162142
* specified in the previous bullet because the accessibility event dispatch is asynchronous
163143
* and crosses process boundaries.
164144
* </li>
165145
* </ul>
166146
* </p>
167-
* <p>
168-
* <b>Notification strategy</b>
169-
* </p>
147+
* <h3>Notification strategy</h3>
170148
* <p>
171149
* For each feedback type only one accessibility service is notified. Services are notified
172150
* in the order of registration. Hence, if two services are registered for the same
@@ -178,40 +156,39 @@
178156
* well with most applications to coexist with "polished" ones that are targeted for
179157
* specific applications.
180158
* </p>
181-
* <p>
182-
* <b>Event types</b>
183-
* </p>
184-
* {@link AccessibilityEvent#TYPE_VIEW_CLICKED}
185-
* {@link AccessibilityEvent#TYPE_VIEW_LONG_CLICKED}
186-
* {@link AccessibilityEvent#TYPE_VIEW_FOCUSED}
187-
* {@link AccessibilityEvent#TYPE_VIEW_SELECTED}
188-
* {@link AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED}
189-
* {@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED}
190-
* {@link AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED}
191-
* {@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START}
192-
* {@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END}
193-
* {@link AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}
194-
* {@link AccessibilityEvent#TYPE_VIEW_HOVER_EXIT}
195-
* {@link AccessibilityEvent#TYPE_VIEW_SCROLLED}
196-
* {@link AccessibilityEvent#TYPE_VIEW_TEXT_SELECTION_CHANGED}
197-
* {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED}
198-
* <p>
199-
* <b>Feedback types</b>
200-
* <p>
201-
* {@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE}
202-
* {@link AccessibilityServiceInfo#FEEDBACK_HAPTIC}
203-
* {@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE}
204-
* {@link AccessibilityServiceInfo#FEEDBACK_VISUAL}
205-
* {@link AccessibilityServiceInfo#FEEDBACK_GENERIC}
206-
*
207-
* @see AccessibilityEvent
208-
* @see AccessibilityServiceInfo
209-
* @see android.view.accessibility.AccessibilityManager
210-
*
159+
* <p class="note">
211160
* <strong>Note:</strong> The event notification timeout is useful to avoid propagating
212161
* events to the client too frequently since this is accomplished via an expensive
213162
* interprocess call. One can think of the timeout as a criteria to determine when
214-
* event generation has settled down.
163+
* event generation has settled down.</p>
164+
* <h3>Event types</h3>
165+
* <ul>
166+
* <li>{@link AccessibilityEvent#TYPE_VIEW_CLICKED}
167+
* <li>{@link AccessibilityEvent#TYPE_VIEW_LONG_CLICKED}
168+
* <li>{@link AccessibilityEvent#TYPE_VIEW_FOCUSED}
169+
* <li>{@link AccessibilityEvent#TYPE_VIEW_SELECTED}
170+
* <li>{@link AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED}
171+
* <li>{@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED}
172+
* <li>{@link AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED}
173+
* <li>{@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START}
174+
* <li>{@link AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END}
175+
* <li>{@link AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}
176+
* <li>{@link AccessibilityEvent#TYPE_VIEW_HOVER_EXIT}
177+
* <li>{@link AccessibilityEvent#TYPE_VIEW_SCROLLED}
178+
* <li>{@link AccessibilityEvent#TYPE_VIEW_TEXT_SELECTION_CHANGED}
179+
* <li>{@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED}
180+
* </ul>
181+
* <h3>Feedback types</h3>
182+
* <ul>
183+
* <li>{@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE}
184+
* <li>{@link AccessibilityServiceInfo#FEEDBACK_HAPTIC}
185+
* <li>{@link AccessibilityServiceInfo#FEEDBACK_AUDIBLE}
186+
* <li>{@link AccessibilityServiceInfo#FEEDBACK_VISUAL}
187+
* <li>{@link AccessibilityServiceInfo#FEEDBACK_GENERIC}
188+
* </ul>
189+
* @see AccessibilityEvent
190+
* @see AccessibilityServiceInfo
191+
* @see android.view.accessibility.AccessibilityManager
215192
*/
216193
public abstract class AccessibilityService extends Service {
217194
/**
@@ -225,10 +202,7 @@ public abstract class AccessibilityService extends Service {
225202
* about itself. This meta-data must reference an XML resource containing an
226203
* <code>&lt;{@link android.R.styleable#AccessibilityService accessibility-service}&gt;</code>
227204
* tag. This is a a sample XML file configuring an accessibility service:
228-
* <p>
229-
* <code>
230-
* <pre>
231-
* &lt;accessibility-service
205+
* <pre> &lt;accessibility-service
232206
* android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
233207
* android:packageNames="foo.bar, foo.baz"
234208
* android:accessibilityFeedbackType="feedbackSpoken"
@@ -237,10 +211,7 @@ public abstract class AccessibilityService extends Service {
237211
* android:settingsActivity="foo.bar.TestBackActivity"
238212
* android:canRetrieveWindowContent="true"
239213
* . . .
240-
* /&gt;
241-
* </pre>
242-
* </code>
243-
* </p>
214+
* /&gt;</pre>
244215
*/
245216
public static final String SERVICE_META_DATA = "android.accessibilityservice";
246217

core/java/android/view/View.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,7 +3810,10 @@ protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyF
38103810
* responsible for handling this call.
38113811
* </p>
38123812
*
3813-
* @param eventType The type of the event to send.
3813+
* @param eventType The type of the event to send, as defined by several types from
3814+
* {@link android.view.accessibility.AccessibilityEvent}, such as
3815+
* {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or
3816+
* {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}.
38143817
*
38153818
* @see #onInitializeAccessibilityEvent(AccessibilityEvent)
38163819
* @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
@@ -3923,27 +3926,28 @@ boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
39233926
/**
39243927
* Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
39253928
* giving a chance to this View to populate the accessibility event with its
3926-
* text content. While the implementation is free to modify other event
3927-
* attributes this should be performed in
3929+
* text content. While this method is free to modify event
3930+
* attributes other than text content, doing so should normally be performed in
39283931
* {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}.
39293932
* <p>
39303933
* Example: Adding formatted date string to an accessibility event in addition
3931-
* to the text added by the super implementation.
3932-
* </p><p><pre><code>
3933-
* public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
3934+
* to the text added by the super implementation:
3935+
* <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
39343936
* super.onPopulateAccessibilityEvent(event);
39353937
* final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
39363938
* String selectedDateUtterance = DateUtils.formatDateTime(mContext,
39373939
* mCurrentDate.getTimeInMillis(), flags);
39383940
* event.getText().add(selectedDateUtterance);
3939-
* }
3940-
* </code></pre></p>
3941+
* }</pre>
39413942
* <p>
39423943
* If an {@link AccessibilityDelegate} has been specified via calling
39433944
* {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
39443945
* {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)}
39453946
* is responsible for handling this call.
39463947
* </p>
3948+
* <p class="note"><strong>Note:</strong> Always call the super implementation before adding
3949+
* information to the event, in case the default implementation has basic information to add.
3950+
* </p>
39473951
*
39483952
* @param event The accessibility event which to populate.
39493953
*
@@ -3974,20 +3978,20 @@ void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
39743978
* the event.
39753979
* <p>
39763980
* Example: Setting the password property of an event in addition
3977-
* to properties set by the super implementation.
3978-
* </p><p><pre><code>
3979-
* public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
3980-
* super.onInitializeAccessibilityEvent(event);
3981-
* event.setPassword(true);
3982-
* }
3983-
* </code></pre></p>
3981+
* to properties set by the super implementation:
3982+
* <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
3983+
* super.onInitializeAccessibilityEvent(event);
3984+
* event.setPassword(true);
3985+
* }</pre>
39843986
* <p>
39853987
* If an {@link AccessibilityDelegate} has been specified via calling
39863988
* {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
39873989
* {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)}
39883990
* is responsible for handling this call.
39893991
* </p>
3990-
*
3992+
* <p class="note"><strong>Note:</strong> Always call the super implementation before adding
3993+
* information to the event, in case the default implementation has basic information to add.
3994+
* </p>
39913995
* @param event The event to initialize.
39923996
*
39933997
* @see #sendAccessibilityEvent(int)
@@ -6159,8 +6163,7 @@ public boolean onTrackballEvent(MotionEvent event) {
61596163
* are delivered to the view under the pointer. All other generic motion events are
61606164
* delivered to the focused view.
61616165
* </p>
6162-
* <code>
6163-
* public boolean onGenericMotionEvent(MotionEvent event) {
6166+
* <pre> public boolean onGenericMotionEvent(MotionEvent event) {
61646167
* if ((event.getSource() &amp; InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
61656168
* if (event.getAction() == MotionEvent.ACTION_MOVE) {
61666169
* // process the joystick movement...
@@ -6178,8 +6181,7 @@ public boolean onTrackballEvent(MotionEvent event) {
61786181
* }
61796182
* }
61806183
* return super.onGenericMotionEvent(event);
6181-
* }
6182-
* </code>
6184+
* }</pre>
61836185
*
61846186
* @param event The generic motion event being processed.
61856187
* @return True if the event was handled, false otherwise.

core/java/android/view/accessibility/AccessibilityManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@
4949
* </p>
5050
* <p>
5151
* <code>
52-
* <pre>
53-
* AccessibilityManager accessibilityManager =
54-
* (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
55-
* </pre>
52+
* <pre>AccessibilityManager accessibilityManager =
53+
* (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);</pre>
5654
* </code>
5755
* </p>
5856
*
@@ -91,7 +89,10 @@ public final class AccessibilityManager {
9189
new CopyOnWriteArrayList<AccessibilityStateChangeListener>();
9290

9391
/**
94-
* Listener for the accessibility state.
92+
* Listener for the system accessibility state. To listen for changes to the accessibility
93+
* state on the device, implement this interface and register it with the system by
94+
* calling {@link AccessibilityManager#addAccessibilityStateChangeListener
95+
* addAccessibilityStateChangeListener()}.
9596
*/
9697
public interface AccessibilityStateChangeListener {
9798

0 commit comments

Comments
 (0)