blob: 82c8163b392330710f8d27328e89f76336e75b39 [file] [log] [blame]
svetoslavganov75986cf2009-05-14 22:28:01 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view.accessibility;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.text.TextUtils;
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -080022import android.util.Pools.SynchronizedPool;
svetoslavganov75986cf2009-05-14 22:28:01 -070023
24import java.util.ArrayList;
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -070025import java.util.List;
svetoslavganov75986cf2009-05-14 22:28:01 -070026
27/**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070028 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -070029 * This class represents accessibility events that are sent by the system when
30 * something notable happens in the user interface. For example, when a
31 * {@link android.widget.Button} is clicked, a {@link android.view.View} is focused, etc.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070032 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -070033 * <p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070034 * An accessibility event is fired by an individual view which populates the event with
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070035 * data for its state and requests from its parent to send the event to interested
36 * parties. The parent can optionally add an {@link AccessibilityRecord} for itself before
37 * dispatching a similar request to its parent. A parent can also choose not to respect the
38 * request for sending an event. The accessibility event is sent by the topmost view in the
39 * view tree. Therefore, an {@link android.accessibilityservice.AccessibilityService} can
40 * explore all records in an accessibility event to obtain more information about the
41 * context in which the event was fired.
42 * </p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070043 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070044 * The main purpose of an accessibility event is to expose enough information for an
45 * {@link android.accessibilityservice.AccessibilityService} to provide meaningful feedback
46 * to the user. Sometimes however, an accessibility service may need more contextual
47 * information then the one in the event pay-load. In such cases the service can obtain
48 * the event source which is an {@link AccessibilityNodeInfo} (snapshot of a View state)
49 * which can be used for exploring the window content. Note that the privilege for accessing
50 * an event's source, thus the window content, has to be explicitly requested. For more
51 * details refer to {@link android.accessibilityservice.AccessibilityService}. If an
52 * accessibility service has not requested to retrieve the window content the event will
53 * not contain reference to its source. Also for events of type
54 * {@link #TYPE_NOTIFICATION_STATE_CHANGED} the source is never available.
55 * </p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070056 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -070057 * This class represents various semantically different accessibility event
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070058 * types. Each event type has an associated set of related properties. In other
svetoslavganov75986cf2009-05-14 22:28:01 -070059 * words, each event type is characterized via a subset of the properties exposed
60 * by this class. For each event type there is a corresponding constant defined
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070061 * in this class. Follows a specification of the event types and their associated properties:
62 * </p>
Joe Fernandeze1302ed2012-02-06 14:30:15 -080063 * <div class="special reference">
64 * <h3>Developer Guides</h3>
65 * <p>For more information about creating and processing AccessibilityEvents, read the
66 * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a>
67 * developer guide.</p>
68 * </div>
svetoslavganov75986cf2009-05-14 22:28:01 -070069 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070070 * <b>VIEW TYPES</b></br>
71 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -070072 * <p>
73 * <b>View clicked</b> - represents the event of clicking on a {@link android.view.View}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070074 * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.</br>
75 * <em>Type:</em>{@link #TYPE_VIEW_CLICKED}</br>
76 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -070077 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070078 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070079 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -070080 * <li>{@link #getClassName()} - The class name of the source.</li>
81 * <li>{@link #getPackageName()} - The package name of the source.</li>
82 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070083 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -070084 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
85 * <li>{@link #isPassword()} - Whether the source is password.</li>
86 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070087 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070088 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
89 * (without descendants of AdapterView).</li>
90 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
91 * (without descendants of AdapterView).</li>
92 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
93 * inclusive (for descendants of AdapterView).</li>
94 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
95 * inclusive (for descendants of AdapterView).</li>
96 * <li>{@link #getItemCount()} - The total items of the source
97 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -070098 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070099 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700100 * <p>
101 * <b>View long clicked</b> - represents the event of long clicking on a {@link android.view.View}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700102 * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc </br>
103 * <em>Type:</em>{@link #TYPE_VIEW_LONG_CLICKED}</br>
104 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700105 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700106 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700107 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700108 * <li>{@link #getClassName()} - The class name of the source.</li>
109 * <li>{@link #getPackageName()} - The package name of the source.</li>
110 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700111 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700112 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
113 * <li>{@link #isPassword()} - Whether the source is password.</li>
114 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700115 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700116 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
117 * (without descendants of AdapterView).</li>
118 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
119 * (without descendants of AdapterView).</li>
120 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
121 * inclusive (for descendants of AdapterView).</li>
122 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
123 * inclusive (for descendants of AdapterView).</li>
124 * <li>{@link #getItemCount()} - The total items of the source
125 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700126 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700127 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700128 * <p>
129 * <b>View selected</b> - represents the event of selecting an item usually in
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700130 * the context of an {@link android.widget.AdapterView}.</br>
131 * <em>Type:</em> {@link #TYPE_VIEW_SELECTED}</br>
132 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700133 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700134 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700135 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700136 * <li>{@link #getClassName()} - The class name of the source.</li>
137 * <li>{@link #getPackageName()} - The package name of the source.</li>
138 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700139 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700140 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
141 * <li>{@link #isPassword()} - Whether the source is password.</li>
142 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700143 * <li>{@link #getItemCount()} - The number of selectable items of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700144 * <li>{@link #getCurrentItemIndex()} - The currently selected item index.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700145 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700146 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
147 * (without descendants of AdapterView).</li>
148 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
149 * (without descendants of AdapterView).</li>
150 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
151 * inclusive (for descendants of AdapterView).</li>
152 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
153 * inclusive (for descendants of AdapterView).</li>
154 * <li>{@link #getItemCount()} - The total items of the source
155 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700156 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700157 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700158 * <p>
159 * <b>View focused</b> - represents the event of focusing a
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700160 * {@link android.view.View}.</br>
161 * <em>Type:</em> {@link #TYPE_VIEW_FOCUSED}</br>
162 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700163 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700164 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700165 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700166 * <li>{@link #getClassName()} - The class name of the source.</li>
167 * <li>{@link #getPackageName()} - The package name of the source.</li>
168 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700169 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700170 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
171 * <li>{@link #isPassword()} - Whether the source is password.</li>
172 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700173 * <li>{@link #getItemCount()} - The number of focusable items on the screen.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700174 * <li>{@link #getCurrentItemIndex()} - The currently focused item index.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700175 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700176 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
177 * (without descendants of AdapterView).</li>
178 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
179 * (without descendants of AdapterView).</li>
180 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
181 * inclusive (for descendants of AdapterView).</li>
182 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
183 * inclusive (for descendants of AdapterView).</li>
184 * <li>{@link #getItemCount()} - The total items of the source
185 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700186 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700187 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700188 * <p>
189 * <b>View text changed</b> - represents the event of changing the text of an
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700190 * {@link android.widget.EditText}.</br>
191 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_CHANGED}</br>
192 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700193 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700194 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700195 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700196 * <li>{@link #getClassName()} - The class name of the source.</li>
197 * <li>{@link #getPackageName()} - The package name of the source.</li>
198 * <li>{@link #getEventTime()} - The event time.</li>
199 * <li>{@link #getText()} - The text of the source.</li>
200 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
201 * <li>{@link #isPassword()} - Whether the source is password.</li>
202 * <li>{@link #isChecked()} - Whether the source is checked.</li>
203 * <li>{@link #getFromIndex()} - The text change start index.</li>
204 * <li>{@link #getAddedCount()} - The number of added characters.</li>
205 * <li>{@link #getRemovedCount()} - The number of removed characters.</li>
206 * <li>{@link #getBeforeText()} - The text of the source before the change.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700207 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700208 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700209 * </p>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700210 * <p>
211 * <b>View text selection changed</b> - represents the event of changing the text
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700212 * selection of an {@link android.widget.EditText}.</br>
213 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED} </br>
214 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700215 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700216 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700217 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700218 * <li>{@link #getClassName()} - The class name of the source.</li>
219 * <li>{@link #getPackageName()} - The package name of the source.</li>
220 * <li>{@link #getEventTime()} - The event time.</li>
221 * <li>{@link #getText()} - The text of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700222 * <li>{@link #isPassword()} - Whether the source is password.</li>
223 * <li>{@link #getFromIndex()} - The selection start index.</li>
224 * <li>{@link #getToIndex()} - The selection end index.</li>
225 * <li>{@link #getItemCount()} - The length of the source text.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700226 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
227 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700228 * </ul>
229 * </p>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700230 * <b>View text traversed at movement granularity</b> - represents the event of traversing the
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700231 * text of a view at a given granularity. For example, moving to the next word.</br>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700232 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY} </br>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700233 * <em>Properties:</em></br>
234 * <ul>
235 * <li>{@link #getEventType()} - The type of the event.</li>
236 * <li>{@link #getSource()} - The source info (for registered clients).</li>
237 * <li>{@link #getClassName()} - The class name of the source.</li>
238 * <li>{@link #getPackageName()} - The package name of the source.</li>
239 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700240 * <li>{@link #getMovementGranularity()} - Sets the granularity at which a view's text
241 * was traversed.</li>
242 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
243 * <li>{@link #getFromIndex()} - The start of the next/previous text at the specified granularity
244 * - inclusive.</li>
245 * <li>{@link #getToIndex()} - The end of the next/previous text at the specified granularity
246 * - exclusive.</li>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700247 * <li>{@link #isPassword()} - Whether the source is password.</li>
248 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
249 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700250 * <li>{@link #getMovementGranularity()} - Sets the granularity at which a view's text
251 * was traversed.</li>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700252 * <li>{@link #getAction()} - Gets traversal action which specifies the direction.</li>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700253 * </ul>
254 * </p>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700255 * <p>
256 * <b>View scrolled</b> - represents the event of scrolling a view. If
257 * the source is a descendant of {@link android.widget.AdapterView} the
258 * scroll is reported in terms of visible items - the first visible item,
259 * the last visible item, and the total items - because the the source
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700260 * is unaware of its pixel size since its adapter is responsible for
Svetoslav Ganova0156172011-06-26 17:55:44 -0700261 * creating views. In all other cases the scroll is reported as the current
262 * scroll on the X and Y axis respectively plus the height of the source in
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700263 * pixels.</br>
264 * <em>Type:</em> {@link #TYPE_VIEW_SCROLLED}</br>
265 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700266 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700267 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700268 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700269 * <li>{@link #getClassName()} - The class name of the source.</li>
270 * <li>{@link #getPackageName()} - The package name of the source.</li>
271 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700272 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700273 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700274 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700275 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
276 * (without descendants of AdapterView).</li>
277 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
278 * (without descendants of AdapterView).</li>
279 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
280 * inclusive (for descendants of AdapterView).</li>
281 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
282 * inclusive (for descendants of AdapterView).</li>
283 * <li>{@link #getItemCount()} - The total items of the source
284 * (for descendants of AdapterView).</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700285 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700286 * <em>Note:</em> This event type is not dispatched to descendants though
287 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
288 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
289 * source {@link android.view.View} and the sub-tree rooted at it will not receive
290 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
291 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
292 * text content to such events is by setting the
293 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
294 * view.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700295 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700296 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700297 * <b>TRANSITION TYPES</b></br>
298 * </p>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700299 * <p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700300 * <b>Window state changed</b> - represents the event of opening a
svetoslavganov75986cf2009-05-14 22:28:01 -0700301 * {@link android.widget.PopupWindow}, {@link android.view.Menu},
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700302 * {@link android.app.Dialog}, etc.</br>
303 * <em>Type:</em> {@link #TYPE_WINDOW_STATE_CHANGED}</br>
304 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700305 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700306 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700307 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700308 * <li>{@link #getClassName()} - The class name of the source.</li>
309 * <li>{@link #getPackageName()} - The package name of the source.</li>
310 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700311 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
312 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700313 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700314 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700315 * <p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700316 * <b>Window content changed</b> - represents the event of change in the
317 * content of a window. This change can be adding/removing view, changing
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700318 * a view size, etc.</br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700319 * </p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700320 * <p>
321 * <strong>Note:</strong> This event is fired only for the window source of the
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700322 * last accessibility event different from {@link #TYPE_NOTIFICATION_STATE_CHANGED}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700323 * and its purpose is to notify clients that the content of the user interaction
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700324 * window has changed.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700325 * <em>Type:</em> {@link #TYPE_WINDOW_CONTENT_CHANGED}</br>
326 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700327 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700328 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav6254f482013-06-04 17:22:14 -0700329 * <li>{@link #getContentChangeType()} - The type of content change.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700330 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700331 * <li>{@link #getClassName()} - The class name of the source.</li>
332 * <li>{@link #getPackageName()} - The package name of the source.</li>
333 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700334 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700335 * <em>Note:</em> This event type is not dispatched to descendants though
336 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
337 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
338 * source {@link android.view.View} and the sub-tree rooted at it will not receive
339 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
340 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
341 * text content to such events is by setting the
342 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
343 * view.</br>
344 * </p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700345 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700346 * <b>NOTIFICATION TYPES</b></br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700347 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700348 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700349 * <b>Notification state changed</b> - represents the event showing
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700350 * {@link android.app.Notification}.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700351 * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
352 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700353 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700354 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700355 * <li>{@link #getClassName()} - The class name of the source.</li>
356 * <li>{@link #getPackageName()} - The package name of the source.</li>
357 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700358 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700359 * <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700360 * <li>{@link #getText()} - Text for providing more context.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700361 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700362 * <em>Note:</em> This event type is not dispatched to descendants though
363 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
364 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
365 * source {@link android.view.View} and the sub-tree rooted at it will not receive
366 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
367 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
368 * text content to such events is by setting the
369 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
370 * view.</br>
371 * </p>
372 * <p>
373 * <b>EXPLORATION TYPES</b></br>
374 * </p>
375 * <p>
376 * <b>View hover enter</b> - represents the event of beginning to hover
377 * over a {@link android.view.View}. The hover may be generated via
378 * exploring the screen by touch or via a pointing device.</br>
379 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_ENTER}</br>
380 * <em>Properties:</em></br>
381 * <ul>
382 * <li>{@link #getEventType()} - The type of the event.</li>
383 * <li>{@link #getSource()} - The source info (for registered clients).</li>
384 * <li>{@link #getClassName()} - The class name of the source.</li>
385 * <li>{@link #getPackageName()} - The package name of the source.</li>
386 * <li>{@link #getEventTime()} - The event time.</li>
387 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
388 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
389 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700390 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
391 * (without descendants of AdapterView).</li>
392 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
393 * (without descendants of AdapterView).</li>
394 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
395 * inclusive (for descendants of AdapterView).</li>
396 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
397 * inclusive (for descendants of AdapterView).</li>
398 * <li>{@link #getItemCount()} - The total items of the source
399 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700400 * </ul>
401 * </p>
402 * <b>View hover exit</b> - represents the event of stopping to hover
403 * over a {@link android.view.View}. The hover may be generated via
404 * exploring the screen by touch or via a pointing device.</br>
405 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_EXIT}</br>
406 * <em>Properties:</em></br>
407 * <ul>
408 * <li>{@link #getEventType()} - The type of the event.</li>
409 * <li>{@link #getSource()} - The source info (for registered clients).</li>
410 * <li>{@link #getClassName()} - The class name of the source.</li>
411 * <li>{@link #getPackageName()} - The package name of the source.</li>
412 * <li>{@link #getEventTime()} - The event time.</li>
413 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
414 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
415 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700416 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
417 * (without descendants of AdapterView).</li>
418 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
419 * (without descendants of AdapterView).</li>
420 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
421 * inclusive (for descendants of AdapterView).</li>
422 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
423 * inclusive (for descendants of AdapterView).</li>
424 * <li>{@link #getItemCount()} - The total items of the source
425 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700426 * </ul>
427 * </p>
428 * <p>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700429 * <b>Touch interaction start</b> - represents the event of starting a touch
430 * interaction, which is the user starts touching the screen.</br>
431 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_START}</br>
432 * <em>Properties:</em></br>
433 * <ul>
434 * <li>{@link #getEventType()} - The type of the event.</li>
435 * </ul>
436 * <em>Note:</em> This event is fired only by the system and is not passed to the
437 * view tree to be populated.</br>
438 * </p>
439 * <p>
440 * <b>Touch interaction end</b> - represents the event of ending a touch
441 * interaction, which is the user stops touching the screen.</br>
442 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_END}</br>
443 * <em>Properties:</em></br>
444 * <ul>
445 * <li>{@link #getEventType()} - The type of the event.</li>
446 * </ul>
447 * <em>Note:</em> This event is fired only by the system and is not passed to the
448 * view tree to be populated.</br>
449 * </p>
450 * <p>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700451 * <b>Touch exploration gesture start</b> - represents the event of starting a touch
452 * exploring gesture.</br>
453 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}</br>
454 * <em>Properties:</em></br>
455 * <ul>
456 * <li>{@link #getEventType()} - The type of the event.</li>
457 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700458 * <em>Note:</em> This event is fired only by the system and is not passed to the
459 * view tree to be populated.</br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700460 * </p>
461 * <p>
462 * <b>Touch exploration gesture end</b> - represents the event of ending a touch
463 * exploring gesture.</br>
464 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}</br>
465 * <em>Properties:</em></br>
466 * <ul>
467 * <li>{@link #getEventType()} - The type of the event.</li>
468 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700469 * <em>Note:</em> This event is fired only by the system and is not passed to the
470 * view tree to be populated.</br>
471 * </p>
472 * <p>
473 * <b>Touch gesture detection start</b> - represents the event of starting a user
474 * gesture detection.</br>
475 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_START}</br>
476 * <em>Properties:</em></br>
477 * <ul>
478 * <li>{@link #getEventType()} - The type of the event.</li>
479 * </ul>
480 * <em>Note:</em> This event is fired only by the system and is not passed to the
481 * view tree to be populated.</br>
482 * </p>
483 * <p>
484 * <b>Touch gesture detection end</b> - represents the event of ending a user
485 * gesture detection.</br>
486 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_END}</br>
487 * <em>Properties:</em></br>
488 * <ul>
489 * <li>{@link #getEventType()} - The type of the event.</li>
490 * </ul>
491 * <em>Note:</em> This event is fired only by the system and is not passed to the
492 * view tree to be populated.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700493 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700494 * <p>
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800495 * <b>MISCELLANEOUS TYPES</b></br>
496 * </p>
497 * <p>
498 * <b>Announcement</b> - represents the event of an application making an
499 * announcement. Usually this announcement is related to some sort of a context
500 * change for which none of the events representing UI transitions is a good fit.
501 * For example, announcing a new page in a book.</br>
502 * <em>Type:</em> {@link #TYPE_ANNOUNCEMENT}</br>
503 * <em>Properties:</em></br>
504 * <ul>
505 * <li>{@link #getEventType()} - The type of the event.</li>
506 * <li>{@link #getSource()} - The source info (for registered clients).</li>
507 * <li>{@link #getClassName()} - The class name of the source.</li>
508 * <li>{@link #getPackageName()} - The package name of the source.</li>
509 * <li>{@link #getEventTime()} - The event time.</li>
510 * <li>{@link #getText()} - The text of the announcement.</li>
511 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
512 * </ul>
513 * </p>
514 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700515 * <b>Security note</b>
516 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700517 * Since an event contains the text of its source privacy can be compromised by leaking
svetoslavganov75986cf2009-05-14 22:28:01 -0700518 * sensitive information such as passwords. To address this issue any event fired in response
519 * to manipulation of a PASSWORD field does NOT CONTAIN the text of the password.
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700520 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700521 *
522 * @see android.view.accessibility.AccessibilityManager
523 * @see android.accessibilityservice.AccessibilityService
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700524 * @see AccessibilityNodeInfo
svetoslavganov75986cf2009-05-14 22:28:01 -0700525 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700526public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700527 private static final boolean DEBUG = false;
svetoslavganov75986cf2009-05-14 22:28:01 -0700528
529 /**
530 * Invalid selection/focus position.
531 *
532 * @see #getCurrentItemIndex()
533 */
534 public static final int INVALID_POSITION = -1;
535
536 /**
537 * Maximum length of the text fields.
538 *
539 * @see #getBeforeText()
540 * @see #getText()
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700541 * </br>
542 * Note: This constant is no longer needed since there
543 * is no limit on the length of text that is contained
544 * in an accessibility event anymore.
svetoslavganov75986cf2009-05-14 22:28:01 -0700545 */
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700546 @Deprecated
svetoslavganov75986cf2009-05-14 22:28:01 -0700547 public static final int MAX_TEXT_LENGTH = 500;
548
549 /**
550 * Represents the event of clicking on a {@link android.view.View} like
551 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
552 */
553 public static final int TYPE_VIEW_CLICKED = 0x00000001;
554
555 /**
556 * Represents the event of long clicking on a {@link android.view.View} like
557 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
558 */
559 public static final int TYPE_VIEW_LONG_CLICKED = 0x00000002;
560
561 /**
562 * Represents the event of selecting an item usually in the context of an
563 * {@link android.widget.AdapterView}.
564 */
565 public static final int TYPE_VIEW_SELECTED = 0x00000004;
566
567 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700568 * Represents the event of setting input focus of a {@link android.view.View}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700569 */
570 public static final int TYPE_VIEW_FOCUSED = 0x00000008;
571
572 /**
573 * Represents the event of changing the text of an {@link android.widget.EditText}.
574 */
575 public static final int TYPE_VIEW_TEXT_CHANGED = 0x00000010;
576
577 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700578 * Represents the event of opening a {@link android.widget.PopupWindow},
svetoslavganov75986cf2009-05-14 22:28:01 -0700579 * {@link android.view.Menu}, {@link android.app.Dialog}, etc.
580 */
581 public static final int TYPE_WINDOW_STATE_CHANGED = 0x00000020;
582
583 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700584 * Represents the event showing a {@link android.app.Notification}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700585 */
586 public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040;
587
588 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700589 * Represents the event of a hover enter over a {@link android.view.View}.
590 */
591 public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080;
592
593 /**
594 * Represents the event of a hover exit over a {@link android.view.View}.
595 */
596 public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100;
597
598 /**
599 * Represents the event of starting a touch exploration gesture.
600 */
601 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200;
602
603 /**
604 * Represents the event of ending a touch exploration gesture.
605 */
606 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400;
607
608 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700609 * Represents the event of changing the content of a window and more
610 * specifically the sub-tree rooted at the event's source.
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700611 */
612 public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800;
613
614 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700615 * Represents the event of scrolling a view.
616 */
617 public static final int TYPE_VIEW_SCROLLED = 0x00001000;
618
619 /**
620 * Represents the event of changing the selection in an {@link android.widget.EditText}.
621 */
622 public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000;
623
624 /**
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800625 * Represents the event of an application making an announcement.
626 */
627 public static final int TYPE_ANNOUNCEMENT = 0x00004000;
628
629 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700630 * Represents the event of gaining accessibility focus.
631 */
632 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000;
633
634 /**
635 * Represents the event of clearing accessibility focus.
636 */
637 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000;
638
639 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700640 * Represents the event of traversing the text of a view at a given movement granularity.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700641 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700642 public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700643
644 /**
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700645 * Represents the event of beginning gesture detection.
646 */
647 public static final int TYPE_GESTURE_DETECTION_START = 0x00040000;
648
649 /**
650 * Represents the event of ending gesture detection.
651 */
652 public static final int TYPE_GESTURE_DETECTION_END = 0x00080000;
653
654 /**
655 * Represents the event of the user starting to touch the screen.
656 */
657 public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000;
658
659 /**
660 * Represents the event of the user ending to touch the screen.
661 */
662 public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000;
663
664 /**
Svetoslav6254f482013-06-04 17:22:14 -0700665 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
666 * The subtree rooted at the source node changed.
667 */
668 public static final int CONTENT_CHANGE_TYPE_SUBTREE = 0;
669
670 /**
671 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
672 * Only the source node changed.
673 */
674 public static final int CONTENT_CHANGE_TYPE_NODE = 1;
675
676 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700677 * Mask for {@link AccessibilityEvent} all types.
678 *
679 * @see #TYPE_VIEW_CLICKED
680 * @see #TYPE_VIEW_LONG_CLICKED
681 * @see #TYPE_VIEW_SELECTED
682 * @see #TYPE_VIEW_FOCUSED
683 * @see #TYPE_VIEW_TEXT_CHANGED
684 * @see #TYPE_WINDOW_STATE_CHANGED
685 * @see #TYPE_NOTIFICATION_STATE_CHANGED
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700686 * @see #TYPE_VIEW_HOVER_ENTER
687 * @see #TYPE_VIEW_HOVER_EXIT
688 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_START
689 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_END
690 * @see #TYPE_WINDOW_CONTENT_CHANGED
691 * @see #TYPE_VIEW_SCROLLED
692 * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800693 * @see #TYPE_ANNOUNCEMENT
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700694 * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700695 * @see #TYPE_GESTURE_DETECTION_START
696 * @see #TYPE_GESTURE_DETECTION_END
697 * @see #TYPE_TOUCH_INTERACTION_START
698 * @see #TYPE_TOUCH_INTERACTION_END
svetoslavganov75986cf2009-05-14 22:28:01 -0700699 */
700 public static final int TYPES_ALL_MASK = 0xFFFFFFFF;
701
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700702 private static final int MAX_POOL_SIZE = 10;
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -0800703 private static final SynchronizedPool<AccessibilityEvent> sPool =
704 new SynchronizedPool<AccessibilityEvent>(MAX_POOL_SIZE);
svetoslavganov75986cf2009-05-14 22:28:01 -0700705
706 private int mEventType;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700707 private CharSequence mPackageName;
svetoslavganov75986cf2009-05-14 22:28:01 -0700708 private long mEventTime;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700709 int mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700710 int mAction;
Svetoslav6254f482013-06-04 17:22:14 -0700711 int mContentChangeType;
svetoslavganov75986cf2009-05-14 22:28:01 -0700712
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700713 private final ArrayList<AccessibilityRecord> mRecords = new ArrayList<AccessibilityRecord>();
svetoslavganov75986cf2009-05-14 22:28:01 -0700714
715 /*
716 * Hide constructor from clients.
717 */
718 private AccessibilityEvent() {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700719 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700720
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700721 /**
722 * Initialize an event from another one.
723 *
724 * @param event The event to initialize from.
725 */
726 void init(AccessibilityEvent event) {
727 super.init(event);
728 mEventType = event.mEventType;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700729 mMovementGranularity = event.mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700730 mAction = event.mAction;
Svetoslav6254f482013-06-04 17:22:14 -0700731 mContentChangeType = event.mContentChangeType;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700732 mEventTime = event.mEventTime;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700733 mPackageName = event.mPackageName;
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700734 }
735
736 /**
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700737 * Sets if this instance is sealed.
738 *
739 * @param sealed Whether is sealed.
740 *
741 * @hide
742 */
743 @Override
744 public void setSealed(boolean sealed) {
745 super.setSealed(sealed);
746 List<AccessibilityRecord> records = mRecords;
747 final int recordCount = records.size();
748 for (int i = 0; i < recordCount; i++) {
749 AccessibilityRecord record = records.get(i);
750 record.setSealed(sealed);
751 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700752 }
753
754 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700755 * Gets the number of records contained in the event.
svetoslavganov75986cf2009-05-14 22:28:01 -0700756 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700757 * @return The number of records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700758 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700759 public int getRecordCount() {
760 return mRecords.size();
svetoslavganov75986cf2009-05-14 22:28:01 -0700761 }
762
763 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700764 * Appends an {@link AccessibilityRecord} to the end of event records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700765 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700766 * @param record The record to append.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700767 *
768 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700769 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700770 public void appendRecord(AccessibilityRecord record) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700771 enforceNotSealed();
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700772 mRecords.add(record);
svetoslavganov75986cf2009-05-14 22:28:01 -0700773 }
774
775 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700776 * Gets the record at a given index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700777 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700778 * @param index The index.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700779 * @return The record at the specified index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700780 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700781 public AccessibilityRecord getRecord(int index) {
782 return mRecords.get(index);
svetoslavganov75986cf2009-05-14 22:28:01 -0700783 }
784
785 /**
786 * Gets the event type.
787 *
788 * @return The event type.
789 */
790 public int getEventType() {
791 return mEventType;
792 }
793
794 /**
Svetoslav6254f482013-06-04 17:22:14 -0700795 * Gets the type of node tree change signaled by an
796 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event.
797 *
798 * @see #CONTENT_CHANGE_TYPE_NODE
799 * @see #CONTENT_CHANGE_TYPE_SUBTREE
800 *
801 * @return The change type.
802 */
803 public int getContentChangeType() {
804 return mContentChangeType;
805 }
806
807 /**
808 * Sets the type of node tree change signaled by an
809 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event.
810 *
811 * @see #CONTENT_CHANGE_TYPE_NODE
812 * @see #CONTENT_CHANGE_TYPE_SUBTREE
813 *
814 * @param changeType The change type.
815 */
816 public void setContentChangeType(int changeType) {
817 enforceNotSealed();
818 mContentChangeType = changeType;
819 }
820
821 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700822 * Sets the event type.
823 *
824 * @param eventType The event type.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700825 *
826 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700827 */
828 public void setEventType(int eventType) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700829 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700830 mEventType = eventType;
831 }
832
833 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700834 * Gets the time in which this event was sent.
835 *
836 * @return The event time.
837 */
838 public long getEventTime() {
839 return mEventTime;
840 }
841
842 /**
843 * Sets the time in which this event was sent.
844 *
845 * @param eventTime The event time.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700846 *
847 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700848 */
849 public void setEventTime(long eventTime) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700850 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700851 mEventTime = eventTime;
852 }
853
854 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700855 * Gets the package name of the source.
856 *
857 * @return The package name.
858 */
859 public CharSequence getPackageName() {
860 return mPackageName;
861 }
862
863 /**
864 * Sets the package name of the source.
865 *
866 * @param packageName The package name.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700867 *
868 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700869 */
870 public void setPackageName(CharSequence packageName) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700871 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700872 mPackageName = packageName;
873 }
874
875 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700876 * Sets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700877 *
878 * @param granularity The granularity.
879 *
880 * @throws IllegalStateException If called from an AccessibilityService.
881 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700882 public void setMovementGranularity(int granularity) {
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700883 enforceNotSealed();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700884 mMovementGranularity = granularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700885 }
886
887 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700888 * Gets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700889 *
890 * @return The granularity.
891 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700892 public int getMovementGranularity() {
893 return mMovementGranularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700894 }
895
896 /**
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700897 * Sets the performed action that triggered this event.
898 *
899 * @param action The action.
900 *
901 * @throws IllegalStateException If called from an AccessibilityService.
902 */
903 public void setAction(int action) {
904 enforceNotSealed();
905 mAction = action;
906 }
907
908 /**
909 * Gets the performed action that triggered this event.
910 *
911 * @return The action.
912 */
913 public int getAction() {
914 return mAction;
915 }
916
917 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700918 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700919 * instantiated with its type property set.
svetoslavganov75986cf2009-05-14 22:28:01 -0700920 *
921 * @param eventType The event type.
922 * @return An instance.
923 */
924 public static AccessibilityEvent obtain(int eventType) {
925 AccessibilityEvent event = AccessibilityEvent.obtain();
926 event.setEventType(eventType);
927 return event;
928 }
929
930 /**
931 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov35bfede2011-07-14 17:57:06 -0700932 * created. The returned instance is initialized from the given
933 * <code>event</code>.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700934 *
935 * @param event The other event.
936 * @return An instance.
937 */
938 public static AccessibilityEvent obtain(AccessibilityEvent event) {
939 AccessibilityEvent eventClone = AccessibilityEvent.obtain();
940 eventClone.init(event);
941
942 final int recordCount = event.mRecords.size();
943 for (int i = 0; i < recordCount; i++) {
944 AccessibilityRecord record = event.mRecords.get(i);
945 AccessibilityRecord recordClone = AccessibilityRecord.obtain(record);
946 eventClone.mRecords.add(recordClone);
947 }
948
949 return eventClone;
950 }
951
952 /**
953 * Returns a cached instance if such is available or a new one is
svetoslavganov75986cf2009-05-14 22:28:01 -0700954 * instantiated.
955 *
956 * @return An instance.
957 */
958 public static AccessibilityEvent obtain() {
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -0800959 AccessibilityEvent event = sPool.acquire();
960 return (event != null) ? event : new AccessibilityEvent();
svetoslavganov75986cf2009-05-14 22:28:01 -0700961 }
962
963 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700964 * Recycles an instance back to be reused.
svetoslavganov75986cf2009-05-14 22:28:01 -0700965 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700966 * <b>Note: You must not touch the object after calling this function.</b>
967 * </p>
Svetoslav Ganov887e1a12011-04-29 15:09:28 -0700968 *
969 * @throws IllegalStateException If the event is already recycled.
svetoslavganov75986cf2009-05-14 22:28:01 -0700970 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700971 @Override
svetoslavganov75986cf2009-05-14 22:28:01 -0700972 public void recycle() {
svetoslavganov75986cf2009-05-14 22:28:01 -0700973 clear();
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -0800974 sPool.release(this);
svetoslavganov75986cf2009-05-14 22:28:01 -0700975 }
976
977 /**
978 * Clears the state of this instance.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700979 *
980 * @hide
svetoslavganov75986cf2009-05-14 22:28:01 -0700981 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700982 @Override
983 protected void clear() {
984 super.clear();
svetoslavganov75986cf2009-05-14 22:28:01 -0700985 mEventType = 0;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700986 mMovementGranularity = 0;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700987 mAction = 0;
Svetoslav6254f482013-06-04 17:22:14 -0700988 mContentChangeType = 0;
Adam Powell3fb3d7c2011-04-22 17:08:55 -0700989 mPackageName = null;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700990 mEventTime = 0;
991 while (!mRecords.isEmpty()) {
992 AccessibilityRecord record = mRecords.remove(0);
993 record.recycle();
svetoslavganov75986cf2009-05-14 22:28:01 -0700994 }
995 }
996
997 /**
998 * Creates a new instance from a {@link Parcel}.
999 *
1000 * @param parcel A parcel containing the state of a {@link AccessibilityEvent}.
1001 */
1002 public void initFromParcel(Parcel parcel) {
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001003 mSealed = (parcel.readInt() == 1);
svetoslavganov75986cf2009-05-14 22:28:01 -07001004 mEventType = parcel.readInt();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001005 mMovementGranularity = parcel.readInt();
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001006 mAction = parcel.readInt();
Svetoslav6254f482013-06-04 17:22:14 -07001007 mContentChangeType = parcel.readInt();
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001008 mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001009 mEventTime = parcel.readLong();
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001010 mConnectionId = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001011 readAccessibilityRecordFromParcel(this, parcel);
1012
1013 // Read the records.
1014 final int recordCount = parcel.readInt();
1015 for (int i = 0; i < recordCount; i++) {
1016 AccessibilityRecord record = AccessibilityRecord.obtain();
Svetoslav Ganov34e350d2011-06-20 21:48:55 -07001017 readAccessibilityRecordFromParcel(record, parcel);
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001018 record.mConnectionId = mConnectionId;
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001019 mRecords.add(record);
1020 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001021 }
1022
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001023 /**
1024 * Reads an {@link AccessibilityRecord} from a parcel.
1025 *
1026 * @param record The record to initialize.
1027 * @param parcel The parcel to read from.
1028 */
1029 private void readAccessibilityRecordFromParcel(AccessibilityRecord record,
1030 Parcel parcel) {
1031 record.mBooleanProperties = parcel.readInt();
1032 record.mCurrentItemIndex = parcel.readInt();
1033 record.mItemCount = parcel.readInt();
1034 record.mFromIndex = parcel.readInt();
Svetoslav Ganova0156172011-06-26 17:55:44 -07001035 record.mToIndex = parcel.readInt();
1036 record.mScrollX = parcel.readInt();
1037 record.mScrollY = parcel.readInt();
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001038 record.mMaxScrollX = parcel.readInt();
1039 record.mMaxScrollY = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001040 record.mAddedCount = parcel.readInt();
1041 record.mRemovedCount = parcel.readInt();
1042 record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1043 record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1044 record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1045 record.mParcelableData = parcel.readParcelable(null);
1046 parcel.readList(record.mText, null);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001047 record.mSourceWindowId = parcel.readInt();
Svetoslav Ganov02107852011-10-03 17:06:56 -07001048 record.mSourceNodeId = parcel.readLong();
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001049 record.mSealed = (parcel.readInt() == 1);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001050 }
1051
1052 /**
1053 * {@inheritDoc}
1054 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001055 public void writeToParcel(Parcel parcel, int flags) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001056 parcel.writeInt(isSealed() ? 1 : 0);
svetoslavganov75986cf2009-05-14 22:28:01 -07001057 parcel.writeInt(mEventType);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001058 parcel.writeInt(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001059 parcel.writeInt(mAction);
Svetoslav6254f482013-06-04 17:22:14 -07001060 parcel.writeInt(mContentChangeType);
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001061 TextUtils.writeToParcel(mPackageName, parcel, 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001062 parcel.writeLong(mEventTime);
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001063 parcel.writeInt(mConnectionId);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001064 writeAccessibilityRecordToParcel(this, parcel, flags);
1065
1066 // Write the records.
1067 final int recordCount = getRecordCount();
1068 parcel.writeInt(recordCount);
1069 for (int i = 0; i < recordCount; i++) {
1070 AccessibilityRecord record = mRecords.get(i);
1071 writeAccessibilityRecordToParcel(record, parcel, flags);
1072 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001073 }
1074
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001075 /**
1076 * Writes an {@link AccessibilityRecord} to a parcel.
1077 *
1078 * @param record The record to write.
1079 * @param parcel The parcel to which to write.
1080 */
1081 private void writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel,
1082 int flags) {
1083 parcel.writeInt(record.mBooleanProperties);
1084 parcel.writeInt(record.mCurrentItemIndex);
1085 parcel.writeInt(record.mItemCount);
1086 parcel.writeInt(record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001087 parcel.writeInt(record.mToIndex);
1088 parcel.writeInt(record.mScrollX);
1089 parcel.writeInt(record.mScrollY);
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001090 parcel.writeInt(record.mMaxScrollX);
1091 parcel.writeInt(record.mMaxScrollY);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001092 parcel.writeInt(record.mAddedCount);
1093 parcel.writeInt(record.mRemovedCount);
1094 TextUtils.writeToParcel(record.mClassName, parcel, flags);
1095 TextUtils.writeToParcel(record.mContentDescription, parcel, flags);
1096 TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
1097 parcel.writeParcelable(record.mParcelableData, flags);
1098 parcel.writeList(record.mText);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001099 parcel.writeInt(record.mSourceWindowId);
Svetoslav Ganov02107852011-10-03 17:06:56 -07001100 parcel.writeLong(record.mSourceNodeId);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001101 parcel.writeInt(record.mSealed ? 1 : 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001102 }
1103
1104 /**
1105 * {@inheritDoc}
1106 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001107 public int describeContents() {
1108 return 0;
1109 }
1110
1111 @Override
1112 public String toString() {
1113 StringBuilder builder = new StringBuilder();
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001114 builder.append("EventType: ").append(eventTypeToString(mEventType));
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001115 builder.append("; EventTime: ").append(mEventTime);
1116 builder.append("; PackageName: ").append(mPackageName);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001117 builder.append("; MovementGranularity: ").append(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001118 builder.append("; Action: ").append(mAction);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001119 builder.append(super.toString());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001120 if (DEBUG) {
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001121 builder.append("\n");
Svetoslav6254f482013-06-04 17:22:14 -07001122 builder.append("; ContentChangeType: ").append(mContentChangeType);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001123 builder.append("; sourceWindowId: ").append(mSourceWindowId);
Svetoslav Ganov02107852011-10-03 17:06:56 -07001124 builder.append("; mSourceNodeId: ").append(mSourceNodeId);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001125 for (int i = 0; i < mRecords.size(); i++) {
1126 AccessibilityRecord record = mRecords.get(i);
1127 builder.append(" Record ");
1128 builder.append(i);
1129 builder.append(":");
1130 builder.append(" [ ClassName: " + record.mClassName);
1131 builder.append("; Text: " + record.mText);
1132 builder.append("; ContentDescription: " + record.mContentDescription);
1133 builder.append("; ItemCount: " + record.mItemCount);
1134 builder.append("; CurrentItemIndex: " + record.mCurrentItemIndex);
1135 builder.append("; IsEnabled: " + record.isEnabled());
1136 builder.append("; IsPassword: " + record.isPassword());
1137 builder.append("; IsChecked: " + record.isChecked());
1138 builder.append("; IsFullScreen: " + record.isFullScreen());
Svetoslav Ganova0156172011-06-26 17:55:44 -07001139 builder.append("; Scrollable: " + record.isScrollable());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001140 builder.append("; BeforeText: " + record.mBeforeText);
1141 builder.append("; FromIndex: " + record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001142 builder.append("; ToIndex: " + record.mToIndex);
1143 builder.append("; ScrollX: " + record.mScrollX);
1144 builder.append("; ScrollY: " + record.mScrollY);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001145 builder.append("; AddedCount: " + record.mAddedCount);
1146 builder.append("; RemovedCount: " + record.mRemovedCount);
1147 builder.append("; ParcelableData: " + record.mParcelableData);
1148 builder.append(" ]");
1149 builder.append("\n");
1150 }
1151 } else {
Svetoslav Ganove4aa13b2011-07-31 20:43:45 -07001152 builder.append("; recordCount: ").append(getRecordCount());
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001153 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001154 return builder.toString();
1155 }
1156
1157 /**
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001158 * Returns the string representation of an event type. For example,
1159 * {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.
1160 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001161 * @param eventType The event type
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001162 * @return The string representation.
1163 */
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001164 public static String eventTypeToString(int eventType) {
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001165 if (eventType == TYPES_ALL_MASK) {
1166 return "TYPES_ALL_MASK";
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001167 }
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001168 StringBuilder builder = new StringBuilder();
1169 int eventTypeCount = 0;
1170 while (eventType != 0) {
1171 final int eventTypeFlag = 1 << Integer.numberOfTrailingZeros(eventType);
1172 eventType &= ~eventTypeFlag;
1173 switch (eventTypeFlag) {
1174 case TYPE_VIEW_CLICKED: {
1175 if (eventTypeCount > 0) {
1176 builder.append(", ");
1177 }
1178 builder.append("TYPE_VIEW_CLICKED");
1179 eventTypeCount++;
1180 } break;
1181 case TYPE_VIEW_LONG_CLICKED: {
1182 if (eventTypeCount > 0) {
1183 builder.append(", ");
1184 }
1185 builder.append("TYPE_VIEW_LONG_CLICKED");
1186 eventTypeCount++;
1187 } break;
1188 case TYPE_VIEW_SELECTED: {
1189 if (eventTypeCount > 0) {
1190 builder.append(", ");
1191 }
1192 builder.append("TYPE_VIEW_SELECTED");
1193 eventTypeCount++;
1194 } break;
1195 case TYPE_VIEW_FOCUSED: {
1196 if (eventTypeCount > 0) {
1197 builder.append(", ");
1198 }
1199 builder.append("TYPE_VIEW_FOCUSED");
1200 eventTypeCount++;
1201 } break;
1202 case TYPE_VIEW_TEXT_CHANGED: {
1203 if (eventTypeCount > 0) {
1204 builder.append(", ");
1205 }
1206 builder.append("TYPE_VIEW_TEXT_CHANGED");
1207 eventTypeCount++;
1208 } break;
1209 case TYPE_WINDOW_STATE_CHANGED: {
1210 if (eventTypeCount > 0) {
1211 builder.append(", ");
1212 }
1213 builder.append("TYPE_WINDOW_STATE_CHANGED");
1214 eventTypeCount++;
1215 } break;
1216 case TYPE_VIEW_HOVER_ENTER: {
1217 if (eventTypeCount > 0) {
1218 builder.append(", ");
1219 }
1220 builder.append("TYPE_VIEW_HOVER_ENTER");
1221 eventTypeCount++;
1222 } break;
1223 case TYPE_VIEW_HOVER_EXIT: {
1224 if (eventTypeCount > 0) {
1225 builder.append(", ");
1226 }
1227 builder.append("TYPE_VIEW_HOVER_EXIT");
1228 eventTypeCount++;
1229 } break;
1230 case TYPE_NOTIFICATION_STATE_CHANGED: {
1231 if (eventTypeCount > 0) {
1232 builder.append(", ");
1233 }
1234 builder.append("TYPE_NOTIFICATION_STATE_CHANGED");
1235 eventTypeCount++;
1236 } break;
1237 case TYPE_TOUCH_EXPLORATION_GESTURE_START: {
1238 if (eventTypeCount > 0) {
1239 builder.append(", ");
1240 }
1241 builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_START");
1242 eventTypeCount++;
1243 } break;
1244 case TYPE_TOUCH_EXPLORATION_GESTURE_END: {
1245 if (eventTypeCount > 0) {
1246 builder.append(", ");
1247 }
1248 builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_END");
1249 eventTypeCount++;
1250 } break;
1251 case TYPE_WINDOW_CONTENT_CHANGED: {
1252 if (eventTypeCount > 0) {
1253 builder.append(", ");
1254 }
1255 builder.append("TYPE_WINDOW_CONTENT_CHANGED");
1256 eventTypeCount++;
1257 } break;
1258 case TYPE_VIEW_TEXT_SELECTION_CHANGED: {
1259 if (eventTypeCount > 0) {
1260 builder.append(", ");
1261 }
1262 builder.append("TYPE_VIEW_TEXT_SELECTION_CHANGED");
1263 eventTypeCount++;
1264 } break;
1265 case TYPE_VIEW_SCROLLED: {
1266 if (eventTypeCount > 0) {
1267 builder.append(", ");
1268 }
1269 builder.append("TYPE_VIEW_SCROLLED");
1270 eventTypeCount++;
1271 } break;
1272 case TYPE_ANNOUNCEMENT: {
1273 if (eventTypeCount > 0) {
1274 builder.append(", ");
1275 }
1276 builder.append("TYPE_ANNOUNCEMENT");
1277 eventTypeCount++;
1278 } break;
1279 case TYPE_VIEW_ACCESSIBILITY_FOCUSED: {
1280 if (eventTypeCount > 0) {
1281 builder.append(", ");
1282 }
1283 builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUSED");
1284 eventTypeCount++;
1285 } break;
1286 case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: {
1287 if (eventTypeCount > 0) {
1288 builder.append(", ");
1289 }
1290 builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED");
1291 eventTypeCount++;
1292 } break;
1293 case TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: {
1294 if (eventTypeCount > 0) {
1295 builder.append(", ");
1296 }
Svetoslavabad55d2013-05-07 18:49:51 -07001297 builder.append("TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY");
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001298 eventTypeCount++;
1299 } break;
1300 case TYPE_GESTURE_DETECTION_START: {
1301 if (eventTypeCount > 0) {
1302 builder.append(", ");
1303 }
1304 builder.append("TYPE_GESTURE_DETECTION_START");
1305 eventTypeCount++;
1306 } break;
1307 case TYPE_GESTURE_DETECTION_END: {
1308 if (eventTypeCount > 0) {
1309 builder.append(", ");
1310 }
1311 builder.append("TYPE_GESTURE_DETECTION_END");
1312 eventTypeCount++;
1313 } break;
1314 case TYPE_TOUCH_INTERACTION_START: {
1315 if (eventTypeCount > 0) {
1316 builder.append(", ");
1317 }
1318 builder.append("TYPE_TOUCH_INTERACTION_START");
1319 eventTypeCount++;
1320 } break;
1321 case TYPE_TOUCH_INTERACTION_END: {
1322 if (eventTypeCount > 0) {
1323 builder.append(", ");
1324 }
1325 builder.append("TYPE_TOUCH_INTERACTION_END");
1326 eventTypeCount++;
1327 } break;
1328 }
1329 }
1330 if (eventTypeCount > 1) {
1331 builder.insert(0, '[');
1332 builder.append(']');
1333 }
1334 return builder.toString();
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001335 }
1336
1337 /**
svetoslavganov75986cf2009-05-14 22:28:01 -07001338 * @see Parcelable.Creator
1339 */
1340 public static final Parcelable.Creator<AccessibilityEvent> CREATOR =
1341 new Parcelable.Creator<AccessibilityEvent>() {
1342 public AccessibilityEvent createFromParcel(Parcel parcel) {
1343 AccessibilityEvent event = AccessibilityEvent.obtain();
1344 event.initFromParcel(parcel);
1345 return event;
1346 }
1347
1348 public AccessibilityEvent[] newArray(int size) {
1349 return new AccessibilityEvent[size];
1350 }
1351 };
1352}