blob: 2cde03d635294b171fa91751825efce3e0cb9b63 [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>
Alan Viverette77e9a282013-09-12 17:16:09 -0700329 * <li>{@link #getContentChangeTypes()} - The type of content changes.</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>
Svetoslav8e3feb12014-02-24 13:46:47 -0800346 * <b>Windows changed</b> - represents the event of changes in the windows shown on
347 * the screen such as a window appeared, a window disappeared, a window size changed,
348 * a window layer changed, etc.</br>
349 * <em>Type:</em> {@link #TYPE_WINDOWS_CHANGED}</br>
350 * <em>Properties:</em></br>
351 * <ul>
352 * <li>{@link #getEventType()} - The type of the event.</li>
353 * <li>{@link #getEventTime()} - The event time.</li>
354 * </ul>
355 * <em>Note:</em> You can retrieve the {@link AccessibilityWindowInfo} for the window
356 * source of the event via {@link AccessibilityEvent#getSource()} to get the source
357 * node on which then call {@link AccessibilityNodeInfo#getWindow()
358 * AccessibilityNodeInfo.getWindow()} to get the window. Also all windows on the screen can
359 * be retrieved by a call to {@link android.accessibilityservice.AccessibilityService#getWindows()
360 * android.accessibilityservice.AccessibilityService.getWindows()}.
361 * </p>
362 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700363 * <b>NOTIFICATION TYPES</b></br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700364 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700365 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700366 * <b>Notification state changed</b> - represents the event showing
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700367 * {@link android.app.Notification}.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700368 * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
369 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700370 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700371 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700372 * <li>{@link #getClassName()} - The class name of the source.</li>
373 * <li>{@link #getPackageName()} - The package name of the source.</li>
374 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700375 * <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700376 * <li>{@link #getText()} - Text for providing more context.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700377 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700378 * <em>Note:</em> This event type is not dispatched to descendants though
379 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
380 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
381 * source {@link android.view.View} and the sub-tree rooted at it will not receive
382 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
383 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
384 * text content to such events is by setting the
385 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
386 * view.</br>
387 * </p>
388 * <p>
389 * <b>EXPLORATION TYPES</b></br>
390 * </p>
391 * <p>
392 * <b>View hover enter</b> - represents the event of beginning to hover
393 * over a {@link android.view.View}. The hover may be generated via
394 * exploring the screen by touch or via a pointing device.</br>
395 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_ENTER}</br>
396 * <em>Properties:</em></br>
397 * <ul>
398 * <li>{@link #getEventType()} - The type of the event.</li>
399 * <li>{@link #getSource()} - The source info (for registered clients).</li>
400 * <li>{@link #getClassName()} - The class name of the source.</li>
401 * <li>{@link #getPackageName()} - The package name of the source.</li>
402 * <li>{@link #getEventTime()} - The event time.</li>
403 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
404 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
405 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700406 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
407 * (without descendants of AdapterView).</li>
408 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
409 * (without descendants of AdapterView).</li>
410 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
411 * inclusive (for descendants of AdapterView).</li>
412 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
413 * inclusive (for descendants of AdapterView).</li>
414 * <li>{@link #getItemCount()} - The total items of the source
415 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700416 * </ul>
417 * </p>
418 * <b>View hover exit</b> - represents the event of stopping to hover
419 * over a {@link android.view.View}. The hover may be generated via
420 * exploring the screen by touch or via a pointing device.</br>
421 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_EXIT}</br>
422 * <em>Properties:</em></br>
423 * <ul>
424 * <li>{@link #getEventType()} - The type of the event.</li>
425 * <li>{@link #getSource()} - The source info (for registered clients).</li>
426 * <li>{@link #getClassName()} - The class name of the source.</li>
427 * <li>{@link #getPackageName()} - The package name of the source.</li>
428 * <li>{@link #getEventTime()} - The event time.</li>
429 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
430 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
431 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700432 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
433 * (without descendants of AdapterView).</li>
434 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
435 * (without descendants of AdapterView).</li>
436 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
437 * inclusive (for descendants of AdapterView).</li>
438 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
439 * inclusive (for descendants of AdapterView).</li>
440 * <li>{@link #getItemCount()} - The total items of the source
441 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700442 * </ul>
443 * </p>
444 * <p>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700445 * <b>Touch interaction start</b> - represents the event of starting a touch
446 * interaction, which is the user starts touching the screen.</br>
447 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_START}</br>
448 * <em>Properties:</em></br>
449 * <ul>
450 * <li>{@link #getEventType()} - The type of the event.</li>
451 * </ul>
452 * <em>Note:</em> This event is fired only by the system and is not passed to the
453 * view tree to be populated.</br>
454 * </p>
455 * <p>
456 * <b>Touch interaction end</b> - represents the event of ending a touch
457 * interaction, which is the user stops touching the screen.</br>
458 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_END}</br>
459 * <em>Properties:</em></br>
460 * <ul>
461 * <li>{@link #getEventType()} - The type of the event.</li>
462 * </ul>
463 * <em>Note:</em> This event is fired only by the system and is not passed to the
464 * view tree to be populated.</br>
465 * </p>
466 * <p>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700467 * <b>Touch exploration gesture start</b> - represents the event of starting a touch
468 * exploring gesture.</br>
469 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}</br>
470 * <em>Properties:</em></br>
471 * <ul>
472 * <li>{@link #getEventType()} - The type of the event.</li>
473 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700474 * <em>Note:</em> This event is fired only by the system and is not passed to the
475 * view tree to be populated.</br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700476 * </p>
477 * <p>
478 * <b>Touch exploration gesture end</b> - represents the event of ending a touch
479 * exploring gesture.</br>
480 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}</br>
481 * <em>Properties:</em></br>
482 * <ul>
483 * <li>{@link #getEventType()} - The type of the event.</li>
484 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700485 * <em>Note:</em> This event is fired only by the system and is not passed to the
486 * view tree to be populated.</br>
487 * </p>
488 * <p>
489 * <b>Touch gesture detection start</b> - represents the event of starting a user
490 * gesture detection.</br>
491 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_START}</br>
492 * <em>Properties:</em></br>
493 * <ul>
494 * <li>{@link #getEventType()} - The type of the event.</li>
495 * </ul>
496 * <em>Note:</em> This event is fired only by the system and is not passed to the
497 * view tree to be populated.</br>
498 * </p>
499 * <p>
500 * <b>Touch gesture detection end</b> - represents the event of ending a user
501 * gesture detection.</br>
502 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_END}</br>
503 * <em>Properties:</em></br>
504 * <ul>
505 * <li>{@link #getEventType()} - The type of the event.</li>
506 * </ul>
507 * <em>Note:</em> This event is fired only by the system and is not passed to the
508 * view tree to be populated.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700509 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700510 * <p>
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800511 * <b>MISCELLANEOUS TYPES</b></br>
512 * </p>
513 * <p>
514 * <b>Announcement</b> - represents the event of an application making an
515 * announcement. Usually this announcement is related to some sort of a context
516 * change for which none of the events representing UI transitions is a good fit.
517 * For example, announcing a new page in a book.</br>
518 * <em>Type:</em> {@link #TYPE_ANNOUNCEMENT}</br>
519 * <em>Properties:</em></br>
520 * <ul>
521 * <li>{@link #getEventType()} - The type of the event.</li>
522 * <li>{@link #getSource()} - The source info (for registered clients).</li>
523 * <li>{@link #getClassName()} - The class name of the source.</li>
524 * <li>{@link #getPackageName()} - The package name of the source.</li>
525 * <li>{@link #getEventTime()} - The event time.</li>
526 * <li>{@link #getText()} - The text of the announcement.</li>
527 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
528 * </ul>
529 * </p>
530 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700531 * <b>Security note</b>
532 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700533 * Since an event contains the text of its source privacy can be compromised by leaking
svetoslavganov75986cf2009-05-14 22:28:01 -0700534 * sensitive information such as passwords. To address this issue any event fired in response
535 * to manipulation of a PASSWORD field does NOT CONTAIN the text of the password.
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700536 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700537 *
538 * @see android.view.accessibility.AccessibilityManager
539 * @see android.accessibilityservice.AccessibilityService
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700540 * @see AccessibilityNodeInfo
svetoslavganov75986cf2009-05-14 22:28:01 -0700541 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700542public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700543 private static final boolean DEBUG = false;
svetoslavganov75986cf2009-05-14 22:28:01 -0700544
545 /**
546 * Invalid selection/focus position.
547 *
548 * @see #getCurrentItemIndex()
549 */
550 public static final int INVALID_POSITION = -1;
551
552 /**
553 * Maximum length of the text fields.
554 *
555 * @see #getBeforeText()
556 * @see #getText()
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700557 * </br>
558 * Note: This constant is no longer needed since there
559 * is no limit on the length of text that is contained
560 * in an accessibility event anymore.
svetoslavganov75986cf2009-05-14 22:28:01 -0700561 */
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700562 @Deprecated
svetoslavganov75986cf2009-05-14 22:28:01 -0700563 public static final int MAX_TEXT_LENGTH = 500;
564
565 /**
566 * Represents the event of clicking on a {@link android.view.View} like
567 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
568 */
569 public static final int TYPE_VIEW_CLICKED = 0x00000001;
570
571 /**
572 * Represents the event of long clicking on a {@link android.view.View} like
573 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
574 */
575 public static final int TYPE_VIEW_LONG_CLICKED = 0x00000002;
576
577 /**
578 * Represents the event of selecting an item usually in the context of an
579 * {@link android.widget.AdapterView}.
580 */
581 public static final int TYPE_VIEW_SELECTED = 0x00000004;
582
583 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700584 * Represents the event of setting input focus of a {@link android.view.View}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700585 */
586 public static final int TYPE_VIEW_FOCUSED = 0x00000008;
587
588 /**
589 * Represents the event of changing the text of an {@link android.widget.EditText}.
590 */
591 public static final int TYPE_VIEW_TEXT_CHANGED = 0x00000010;
592
593 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700594 * Represents the event of opening a {@link android.widget.PopupWindow},
svetoslavganov75986cf2009-05-14 22:28:01 -0700595 * {@link android.view.Menu}, {@link android.app.Dialog}, etc.
596 */
597 public static final int TYPE_WINDOW_STATE_CHANGED = 0x00000020;
598
599 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700600 * Represents the event showing a {@link android.app.Notification}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700601 */
602 public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040;
603
604 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700605 * Represents the event of a hover enter over a {@link android.view.View}.
606 */
607 public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080;
608
609 /**
610 * Represents the event of a hover exit over a {@link android.view.View}.
611 */
612 public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100;
613
614 /**
615 * Represents the event of starting a touch exploration gesture.
616 */
617 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200;
618
619 /**
620 * Represents the event of ending a touch exploration gesture.
621 */
622 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400;
623
624 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700625 * Represents the event of changing the content of a window and more
626 * specifically the sub-tree rooted at the event's source.
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700627 */
628 public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800;
629
630 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700631 * Represents the event of scrolling a view.
632 */
633 public static final int TYPE_VIEW_SCROLLED = 0x00001000;
634
635 /**
636 * Represents the event of changing the selection in an {@link android.widget.EditText}.
637 */
638 public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000;
639
640 /**
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800641 * Represents the event of an application making an announcement.
642 */
643 public static final int TYPE_ANNOUNCEMENT = 0x00004000;
644
645 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700646 * Represents the event of gaining accessibility focus.
647 */
648 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000;
649
650 /**
651 * Represents the event of clearing accessibility focus.
652 */
653 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000;
654
655 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700656 * Represents the event of traversing the text of a view at a given movement granularity.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700657 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700658 public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700659
660 /**
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700661 * Represents the event of beginning gesture detection.
662 */
663 public static final int TYPE_GESTURE_DETECTION_START = 0x00040000;
664
665 /**
666 * Represents the event of ending gesture detection.
667 */
668 public static final int TYPE_GESTURE_DETECTION_END = 0x00080000;
669
670 /**
671 * Represents the event of the user starting to touch the screen.
672 */
673 public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000;
674
675 /**
676 * Represents the event of the user ending to touch the screen.
677 */
678 public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000;
679
680 /**
Svetoslav8e3feb12014-02-24 13:46:47 -0800681 * Represents the event change in the windows shown on the screen.
682 */
683 public static final int TYPE_WINDOWS_CHANGED = 0x00400000;
684
685 /**
Mady Mellore8608912015-06-05 09:02:55 -0700686 * Represents the event of a context click on a {@link android.view.View}.
Mady Mellore82067b2015-04-30 09:58:35 -0700687 */
Mady Mellore8608912015-06-05 09:02:55 -0700688 public static final int TYPE_VIEW_CONTEXT_CLICKED = 0x00800000;
Mady Mellore82067b2015-04-30 09:58:35 -0700689
690 /**
Jorim Jaggie85da2ba2015-06-25 17:26:10 -0700691 * Represents the event of the assistant currently reading the users screen context.
692 */
693 public static final int TYPE_ASSIST_READING_CONTEXT = 0x01000000;
694
695 /**
Svetoslav6254f482013-06-04 17:22:14 -0700696 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
Alan Viverette77e9a282013-09-12 17:16:09 -0700697 * The type of change is not defined.
Svetoslav6254f482013-06-04 17:22:14 -0700698 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700699 public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0x00000000;
Svetoslav6254f482013-06-04 17:22:14 -0700700
701 /**
702 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
Alan Viverette77e9a282013-09-12 17:16:09 -0700703 * A node in the subtree rooted at the source node was added or removed.
Svetoslav6254f482013-06-04 17:22:14 -0700704 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700705 public static final int CONTENT_CHANGE_TYPE_SUBTREE = 0x00000001;
706
707 /**
708 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
709 * The node's text changed.
710 */
711 public static final int CONTENT_CHANGE_TYPE_TEXT = 0x00000002;
712
713 /**
714 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
715 * The node's content description changed.
716 */
717 public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004;
Svetoslav6254f482013-06-04 17:22:14 -0700718
719 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700720 * Mask for {@link AccessibilityEvent} all types.
721 *
722 * @see #TYPE_VIEW_CLICKED
723 * @see #TYPE_VIEW_LONG_CLICKED
724 * @see #TYPE_VIEW_SELECTED
725 * @see #TYPE_VIEW_FOCUSED
726 * @see #TYPE_VIEW_TEXT_CHANGED
727 * @see #TYPE_WINDOW_STATE_CHANGED
728 * @see #TYPE_NOTIFICATION_STATE_CHANGED
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700729 * @see #TYPE_VIEW_HOVER_ENTER
730 * @see #TYPE_VIEW_HOVER_EXIT
731 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_START
732 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_END
733 * @see #TYPE_WINDOW_CONTENT_CHANGED
734 * @see #TYPE_VIEW_SCROLLED
735 * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800736 * @see #TYPE_ANNOUNCEMENT
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700737 * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700738 * @see #TYPE_GESTURE_DETECTION_START
739 * @see #TYPE_GESTURE_DETECTION_END
740 * @see #TYPE_TOUCH_INTERACTION_START
741 * @see #TYPE_TOUCH_INTERACTION_END
Svetoslav8e3feb12014-02-24 13:46:47 -0800742 * @see #TYPE_WINDOWS_CHANGED
Mady Mellore8608912015-06-05 09:02:55 -0700743 * @see #TYPE_VIEW_CONTEXT_CLICKED
svetoslavganov75986cf2009-05-14 22:28:01 -0700744 */
745 public static final int TYPES_ALL_MASK = 0xFFFFFFFF;
746
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700747 private static final int MAX_POOL_SIZE = 10;
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -0800748 private static final SynchronizedPool<AccessibilityEvent> sPool =
749 new SynchronizedPool<AccessibilityEvent>(MAX_POOL_SIZE);
svetoslavganov75986cf2009-05-14 22:28:01 -0700750
751 private int mEventType;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700752 private CharSequence mPackageName;
svetoslavganov75986cf2009-05-14 22:28:01 -0700753 private long mEventTime;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700754 int mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700755 int mAction;
Alan Viverette77e9a282013-09-12 17:16:09 -0700756 int mContentChangeTypes;
svetoslavganov75986cf2009-05-14 22:28:01 -0700757
Alan Viverette502cb332013-10-15 18:29:53 -0700758 private ArrayList<AccessibilityRecord> mRecords;
svetoslavganov75986cf2009-05-14 22:28:01 -0700759
760 /*
761 * Hide constructor from clients.
762 */
763 private AccessibilityEvent() {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700764 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700765
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700766 /**
767 * Initialize an event from another one.
768 *
769 * @param event The event to initialize from.
770 */
771 void init(AccessibilityEvent event) {
772 super.init(event);
773 mEventType = event.mEventType;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700774 mMovementGranularity = event.mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700775 mAction = event.mAction;
Alan Viverette77e9a282013-09-12 17:16:09 -0700776 mContentChangeTypes = event.mContentChangeTypes;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700777 mEventTime = event.mEventTime;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700778 mPackageName = event.mPackageName;
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700779 }
780
781 /**
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700782 * Sets if this instance is sealed.
783 *
784 * @param sealed Whether is sealed.
785 *
786 * @hide
787 */
788 @Override
789 public void setSealed(boolean sealed) {
790 super.setSealed(sealed);
Alan Viverette502cb332013-10-15 18:29:53 -0700791 final List<AccessibilityRecord> records = mRecords;
792 if (records != null) {
793 final int recordCount = records.size();
794 for (int i = 0; i < recordCount; i++) {
795 AccessibilityRecord record = records.get(i);
796 record.setSealed(sealed);
797 }
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700798 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700799 }
800
801 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700802 * Gets the number of records contained in the event.
svetoslavganov75986cf2009-05-14 22:28:01 -0700803 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700804 * @return The number of records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700805 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700806 public int getRecordCount() {
Alan Viverette502cb332013-10-15 18:29:53 -0700807 return mRecords == null ? 0 : mRecords.size();
svetoslavganov75986cf2009-05-14 22:28:01 -0700808 }
809
810 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700811 * Appends an {@link AccessibilityRecord} to the end of event records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700812 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700813 * @param record The record to append.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700814 *
815 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700816 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700817 public void appendRecord(AccessibilityRecord record) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700818 enforceNotSealed();
Alan Viverette502cb332013-10-15 18:29:53 -0700819 if (mRecords == null) {
820 mRecords = new ArrayList<AccessibilityRecord>();
821 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700822 mRecords.add(record);
svetoslavganov75986cf2009-05-14 22:28:01 -0700823 }
824
825 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700826 * Gets the record at a given index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700827 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700828 * @param index The index.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700829 * @return The record at the specified index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700830 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700831 public AccessibilityRecord getRecord(int index) {
Alan Viverette502cb332013-10-15 18:29:53 -0700832 if (mRecords == null) {
833 throw new IndexOutOfBoundsException("Invalid index " + index + ", size is 0");
834 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700835 return mRecords.get(index);
svetoslavganov75986cf2009-05-14 22:28:01 -0700836 }
837
838 /**
839 * Gets the event type.
840 *
841 * @return The event type.
842 */
843 public int getEventType() {
844 return mEventType;
845 }
846
847 /**
Alan Viverette77e9a282013-09-12 17:16:09 -0700848 * Gets the bit mask of change types signaled by an
849 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event. A single event may represent
850 * multiple change types.
Svetoslav6254f482013-06-04 17:22:14 -0700851 *
Alan Viverette77e9a282013-09-12 17:16:09 -0700852 * @return The bit mask of change types. One or more of:
853 * <ul>
854 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
855 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_SUBTREE}
856 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_TEXT}
857 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_UNDEFINED}
858 * </ul>
Svetoslav6254f482013-06-04 17:22:14 -0700859 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700860 public int getContentChangeTypes() {
861 return mContentChangeTypes;
Svetoslav6254f482013-06-04 17:22:14 -0700862 }
863
864 /**
Alan Viverette77e9a282013-09-12 17:16:09 -0700865 * Sets the bit mask of node tree changes signaled by an
Svetoslav6254f482013-06-04 17:22:14 -0700866 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event.
867 *
Alan Viverette77e9a282013-09-12 17:16:09 -0700868 * @param changeTypes The bit mask of change types.
869 * @throws IllegalStateException If called from an AccessibilityService.
870 * @see #getContentChangeTypes()
Svetoslav6254f482013-06-04 17:22:14 -0700871 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700872 public void setContentChangeTypes(int changeTypes) {
Svetoslav6254f482013-06-04 17:22:14 -0700873 enforceNotSealed();
Alan Viverette77e9a282013-09-12 17:16:09 -0700874 mContentChangeTypes = changeTypes;
Svetoslav6254f482013-06-04 17:22:14 -0700875 }
876
877 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700878 * Sets the event type.
879 *
880 * @param eventType The event type.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700881 *
882 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700883 */
884 public void setEventType(int eventType) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700885 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700886 mEventType = eventType;
887 }
888
889 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700890 * Gets the time in which this event was sent.
891 *
892 * @return The event time.
893 */
894 public long getEventTime() {
895 return mEventTime;
896 }
897
898 /**
899 * Sets the time in which this event was sent.
900 *
901 * @param eventTime The event time.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700902 *
903 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700904 */
905 public void setEventTime(long eventTime) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700906 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700907 mEventTime = eventTime;
908 }
909
910 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700911 * Gets the package name of the source.
912 *
913 * @return The package name.
914 */
915 public CharSequence getPackageName() {
916 return mPackageName;
917 }
918
919 /**
920 * Sets the package name of the source.
921 *
922 * @param packageName The package name.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700923 *
924 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700925 */
926 public void setPackageName(CharSequence packageName) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700927 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700928 mPackageName = packageName;
929 }
930
931 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700932 * Sets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700933 *
934 * @param granularity The granularity.
935 *
936 * @throws IllegalStateException If called from an AccessibilityService.
937 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700938 public void setMovementGranularity(int granularity) {
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700939 enforceNotSealed();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700940 mMovementGranularity = granularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700941 }
942
943 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700944 * Gets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700945 *
946 * @return The granularity.
947 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700948 public int getMovementGranularity() {
949 return mMovementGranularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700950 }
951
952 /**
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700953 * Sets the performed action that triggered this event.
Alan Viveretteaf431102013-10-04 13:16:51 -0700954 * <p>
955 * Valid actions are defined in {@link AccessibilityNodeInfo}:
956 * <ul>
957 * <li>{@link AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS}
958 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_ACCESSIBILITY_FOCUS}
959 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_FOCUS}
960 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_SELECTION}
961 * <li>{@link AccessibilityNodeInfo#ACTION_CLICK}
962 * <li>etc.
963 * </ul>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700964 *
965 * @param action The action.
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700966 * @throws IllegalStateException If called from an AccessibilityService.
Alan Viveretteaf431102013-10-04 13:16:51 -0700967 * @see AccessibilityNodeInfo#performAction(int)
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700968 */
969 public void setAction(int action) {
970 enforceNotSealed();
971 mAction = action;
972 }
973
974 /**
975 * Gets the performed action that triggered this event.
976 *
977 * @return The action.
978 */
979 public int getAction() {
980 return mAction;
981 }
982
983 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700984 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700985 * instantiated with its type property set.
svetoslavganov75986cf2009-05-14 22:28:01 -0700986 *
987 * @param eventType The event type.
988 * @return An instance.
989 */
990 public static AccessibilityEvent obtain(int eventType) {
991 AccessibilityEvent event = AccessibilityEvent.obtain();
992 event.setEventType(eventType);
993 return event;
994 }
995
996 /**
997 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov35bfede2011-07-14 17:57:06 -0700998 * created. The returned instance is initialized from the given
999 * <code>event</code>.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001000 *
1001 * @param event The other event.
1002 * @return An instance.
1003 */
1004 public static AccessibilityEvent obtain(AccessibilityEvent event) {
1005 AccessibilityEvent eventClone = AccessibilityEvent.obtain();
1006 eventClone.init(event);
1007
Alan Viverette502cb332013-10-15 18:29:53 -07001008 if (event.mRecords != null) {
1009 final int recordCount = event.mRecords.size();
1010 eventClone.mRecords = new ArrayList<AccessibilityRecord>(recordCount);
1011 for (int i = 0; i < recordCount; i++) {
1012 final AccessibilityRecord record = event.mRecords.get(i);
1013 final AccessibilityRecord recordClone = AccessibilityRecord.obtain(record);
1014 eventClone.mRecords.add(recordClone);
1015 }
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001016 }
1017
1018 return eventClone;
1019 }
1020
1021 /**
1022 * Returns a cached instance if such is available or a new one is
svetoslavganov75986cf2009-05-14 22:28:01 -07001023 * instantiated.
1024 *
1025 * @return An instance.
1026 */
1027 public static AccessibilityEvent obtain() {
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -08001028 AccessibilityEvent event = sPool.acquire();
1029 return (event != null) ? event : new AccessibilityEvent();
svetoslavganov75986cf2009-05-14 22:28:01 -07001030 }
1031
1032 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001033 * Recycles an instance back to be reused.
svetoslavganov75986cf2009-05-14 22:28:01 -07001034 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001035 * <b>Note: You must not touch the object after calling this function.</b>
1036 * </p>
Svetoslav Ganov887e1a12011-04-29 15:09:28 -07001037 *
1038 * @throws IllegalStateException If the event is already recycled.
svetoslavganov75986cf2009-05-14 22:28:01 -07001039 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001040 @Override
svetoslavganov75986cf2009-05-14 22:28:01 -07001041 public void recycle() {
svetoslavganov75986cf2009-05-14 22:28:01 -07001042 clear();
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -08001043 sPool.release(this);
svetoslavganov75986cf2009-05-14 22:28:01 -07001044 }
1045
1046 /**
1047 * Clears the state of this instance.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001048 *
1049 * @hide
svetoslavganov75986cf2009-05-14 22:28:01 -07001050 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001051 @Override
1052 protected void clear() {
1053 super.clear();
svetoslavganov75986cf2009-05-14 22:28:01 -07001054 mEventType = 0;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001055 mMovementGranularity = 0;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001056 mAction = 0;
Alan Viverette77e9a282013-09-12 17:16:09 -07001057 mContentChangeTypes = 0;
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001058 mPackageName = null;
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001059 mEventTime = 0;
Alan Viverette502cb332013-10-15 18:29:53 -07001060 if (mRecords != null) {
1061 while (!mRecords.isEmpty()) {
1062 AccessibilityRecord record = mRecords.remove(0);
1063 record.recycle();
1064 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001065 }
1066 }
1067
1068 /**
1069 * Creates a new instance from a {@link Parcel}.
1070 *
1071 * @param parcel A parcel containing the state of a {@link AccessibilityEvent}.
1072 */
1073 public void initFromParcel(Parcel parcel) {
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001074 mSealed = (parcel.readInt() == 1);
svetoslavganov75986cf2009-05-14 22:28:01 -07001075 mEventType = parcel.readInt();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001076 mMovementGranularity = parcel.readInt();
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001077 mAction = parcel.readInt();
Alan Viverette77e9a282013-09-12 17:16:09 -07001078 mContentChangeTypes = parcel.readInt();
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001079 mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001080 mEventTime = parcel.readLong();
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001081 mConnectionId = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001082 readAccessibilityRecordFromParcel(this, parcel);
1083
1084 // Read the records.
1085 final int recordCount = parcel.readInt();
Alan Viverette502cb332013-10-15 18:29:53 -07001086 if (recordCount > 0) {
1087 mRecords = new ArrayList<AccessibilityRecord>(recordCount);
1088 for (int i = 0; i < recordCount; i++) {
1089 AccessibilityRecord record = AccessibilityRecord.obtain();
1090 readAccessibilityRecordFromParcel(record, parcel);
1091 record.mConnectionId = mConnectionId;
1092 mRecords.add(record);
1093 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001094 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001095 }
1096
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001097 /**
1098 * Reads an {@link AccessibilityRecord} from a parcel.
1099 *
1100 * @param record The record to initialize.
1101 * @param parcel The parcel to read from.
1102 */
1103 private void readAccessibilityRecordFromParcel(AccessibilityRecord record,
1104 Parcel parcel) {
1105 record.mBooleanProperties = parcel.readInt();
1106 record.mCurrentItemIndex = parcel.readInt();
1107 record.mItemCount = parcel.readInt();
1108 record.mFromIndex = parcel.readInt();
Svetoslav Ganova0156172011-06-26 17:55:44 -07001109 record.mToIndex = parcel.readInt();
1110 record.mScrollX = parcel.readInt();
1111 record.mScrollY = parcel.readInt();
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001112 record.mMaxScrollX = parcel.readInt();
1113 record.mMaxScrollY = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001114 record.mAddedCount = parcel.readInt();
1115 record.mRemovedCount = parcel.readInt();
1116 record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1117 record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1118 record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1119 record.mParcelableData = parcel.readParcelable(null);
1120 parcel.readList(record.mText, null);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001121 record.mSourceWindowId = parcel.readInt();
Maxim Bogatov2f55a3f2015-06-09 15:00:44 -07001122 record.mSourceNode = parcel.readParcelable(null);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001123 record.mSealed = (parcel.readInt() == 1);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001124 }
1125
1126 /**
1127 * {@inheritDoc}
1128 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001129 public void writeToParcel(Parcel parcel, int flags) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001130 parcel.writeInt(isSealed() ? 1 : 0);
svetoslavganov75986cf2009-05-14 22:28:01 -07001131 parcel.writeInt(mEventType);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001132 parcel.writeInt(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001133 parcel.writeInt(mAction);
Alan Viverette77e9a282013-09-12 17:16:09 -07001134 parcel.writeInt(mContentChangeTypes);
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001135 TextUtils.writeToParcel(mPackageName, parcel, 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001136 parcel.writeLong(mEventTime);
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001137 parcel.writeInt(mConnectionId);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001138 writeAccessibilityRecordToParcel(this, parcel, flags);
1139
1140 // Write the records.
1141 final int recordCount = getRecordCount();
1142 parcel.writeInt(recordCount);
1143 for (int i = 0; i < recordCount; i++) {
1144 AccessibilityRecord record = mRecords.get(i);
1145 writeAccessibilityRecordToParcel(record, parcel, flags);
1146 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001147 }
1148
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001149 /**
1150 * Writes an {@link AccessibilityRecord} to a parcel.
1151 *
1152 * @param record The record to write.
1153 * @param parcel The parcel to which to write.
1154 */
1155 private void writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel,
1156 int flags) {
1157 parcel.writeInt(record.mBooleanProperties);
1158 parcel.writeInt(record.mCurrentItemIndex);
1159 parcel.writeInt(record.mItemCount);
1160 parcel.writeInt(record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001161 parcel.writeInt(record.mToIndex);
1162 parcel.writeInt(record.mScrollX);
1163 parcel.writeInt(record.mScrollY);
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001164 parcel.writeInt(record.mMaxScrollX);
1165 parcel.writeInt(record.mMaxScrollY);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001166 parcel.writeInt(record.mAddedCount);
1167 parcel.writeInt(record.mRemovedCount);
1168 TextUtils.writeToParcel(record.mClassName, parcel, flags);
1169 TextUtils.writeToParcel(record.mContentDescription, parcel, flags);
1170 TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
1171 parcel.writeParcelable(record.mParcelableData, flags);
1172 parcel.writeList(record.mText);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001173 parcel.writeInt(record.mSourceWindowId);
Maxim Bogatov2f55a3f2015-06-09 15:00:44 -07001174 // create copy of the node here because the node would be recycled just after it is written
1175 // to parcel
1176 parcel.writeParcelable(record.mSourceNode != null ?
1177 AccessibilityNodeInfo.obtain(record.mSourceNode) : null, flags);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001178 parcel.writeInt(record.mSealed ? 1 : 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001179 }
1180
1181 /**
1182 * {@inheritDoc}
1183 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001184 public int describeContents() {
1185 return 0;
1186 }
1187
1188 @Override
1189 public String toString() {
1190 StringBuilder builder = new StringBuilder();
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001191 builder.append("EventType: ").append(eventTypeToString(mEventType));
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001192 builder.append("; EventTime: ").append(mEventTime);
1193 builder.append("; PackageName: ").append(mPackageName);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001194 builder.append("; MovementGranularity: ").append(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001195 builder.append("; Action: ").append(mAction);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001196 builder.append(super.toString());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001197 if (DEBUG) {
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001198 builder.append("\n");
Alan Viverette77e9a282013-09-12 17:16:09 -07001199 builder.append("; ContentChangeTypes: ").append(mContentChangeTypes);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001200 builder.append("; sourceWindowId: ").append(mSourceWindowId);
Maxim Bogatov2f55a3f2015-06-09 15:00:44 -07001201 if (mSourceNode != null) {
1202 builder.append("; mSourceNodeId: ").append(mSourceNode.getSourceNodeId());
1203 }
Alan Viverette502cb332013-10-15 18:29:53 -07001204 for (int i = 0; i < getRecordCount(); i++) {
1205 final AccessibilityRecord record = getRecord(i);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001206 builder.append(" Record ");
1207 builder.append(i);
1208 builder.append(":");
1209 builder.append(" [ ClassName: " + record.mClassName);
1210 builder.append("; Text: " + record.mText);
1211 builder.append("; ContentDescription: " + record.mContentDescription);
1212 builder.append("; ItemCount: " + record.mItemCount);
1213 builder.append("; CurrentItemIndex: " + record.mCurrentItemIndex);
1214 builder.append("; IsEnabled: " + record.isEnabled());
1215 builder.append("; IsPassword: " + record.isPassword());
1216 builder.append("; IsChecked: " + record.isChecked());
1217 builder.append("; IsFullScreen: " + record.isFullScreen());
Svetoslav Ganova0156172011-06-26 17:55:44 -07001218 builder.append("; Scrollable: " + record.isScrollable());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001219 builder.append("; BeforeText: " + record.mBeforeText);
1220 builder.append("; FromIndex: " + record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001221 builder.append("; ToIndex: " + record.mToIndex);
1222 builder.append("; ScrollX: " + record.mScrollX);
1223 builder.append("; ScrollY: " + record.mScrollY);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001224 builder.append("; AddedCount: " + record.mAddedCount);
1225 builder.append("; RemovedCount: " + record.mRemovedCount);
1226 builder.append("; ParcelableData: " + record.mParcelableData);
1227 builder.append(" ]");
1228 builder.append("\n");
1229 }
1230 } else {
Svetoslav Ganove4aa13b2011-07-31 20:43:45 -07001231 builder.append("; recordCount: ").append(getRecordCount());
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001232 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001233 return builder.toString();
1234 }
1235
1236 /**
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001237 * Returns the string representation of an event type. For example,
1238 * {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.
1239 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001240 * @param eventType The event type
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001241 * @return The string representation.
1242 */
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001243 public static String eventTypeToString(int eventType) {
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001244 if (eventType == TYPES_ALL_MASK) {
1245 return "TYPES_ALL_MASK";
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001246 }
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001247 StringBuilder builder = new StringBuilder();
1248 int eventTypeCount = 0;
1249 while (eventType != 0) {
1250 final int eventTypeFlag = 1 << Integer.numberOfTrailingZeros(eventType);
1251 eventType &= ~eventTypeFlag;
1252 switch (eventTypeFlag) {
1253 case TYPE_VIEW_CLICKED: {
1254 if (eventTypeCount > 0) {
1255 builder.append(", ");
1256 }
1257 builder.append("TYPE_VIEW_CLICKED");
1258 eventTypeCount++;
1259 } break;
1260 case TYPE_VIEW_LONG_CLICKED: {
1261 if (eventTypeCount > 0) {
1262 builder.append(", ");
1263 }
1264 builder.append("TYPE_VIEW_LONG_CLICKED");
1265 eventTypeCount++;
1266 } break;
1267 case TYPE_VIEW_SELECTED: {
1268 if (eventTypeCount > 0) {
1269 builder.append(", ");
1270 }
1271 builder.append("TYPE_VIEW_SELECTED");
1272 eventTypeCount++;
1273 } break;
1274 case TYPE_VIEW_FOCUSED: {
1275 if (eventTypeCount > 0) {
1276 builder.append(", ");
1277 }
1278 builder.append("TYPE_VIEW_FOCUSED");
1279 eventTypeCount++;
1280 } break;
1281 case TYPE_VIEW_TEXT_CHANGED: {
1282 if (eventTypeCount > 0) {
1283 builder.append(", ");
1284 }
1285 builder.append("TYPE_VIEW_TEXT_CHANGED");
1286 eventTypeCount++;
1287 } break;
1288 case TYPE_WINDOW_STATE_CHANGED: {
1289 if (eventTypeCount > 0) {
1290 builder.append(", ");
1291 }
1292 builder.append("TYPE_WINDOW_STATE_CHANGED");
1293 eventTypeCount++;
1294 } break;
1295 case TYPE_VIEW_HOVER_ENTER: {
1296 if (eventTypeCount > 0) {
1297 builder.append(", ");
1298 }
1299 builder.append("TYPE_VIEW_HOVER_ENTER");
1300 eventTypeCount++;
1301 } break;
1302 case TYPE_VIEW_HOVER_EXIT: {
1303 if (eventTypeCount > 0) {
1304 builder.append(", ");
1305 }
1306 builder.append("TYPE_VIEW_HOVER_EXIT");
1307 eventTypeCount++;
1308 } break;
1309 case TYPE_NOTIFICATION_STATE_CHANGED: {
1310 if (eventTypeCount > 0) {
1311 builder.append(", ");
1312 }
1313 builder.append("TYPE_NOTIFICATION_STATE_CHANGED");
1314 eventTypeCount++;
1315 } break;
1316 case TYPE_TOUCH_EXPLORATION_GESTURE_START: {
1317 if (eventTypeCount > 0) {
1318 builder.append(", ");
1319 }
1320 builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_START");
1321 eventTypeCount++;
1322 } break;
1323 case TYPE_TOUCH_EXPLORATION_GESTURE_END: {
1324 if (eventTypeCount > 0) {
1325 builder.append(", ");
1326 }
1327 builder.append("TYPE_TOUCH_EXPLORATION_GESTURE_END");
1328 eventTypeCount++;
1329 } break;
1330 case TYPE_WINDOW_CONTENT_CHANGED: {
1331 if (eventTypeCount > 0) {
1332 builder.append(", ");
1333 }
1334 builder.append("TYPE_WINDOW_CONTENT_CHANGED");
1335 eventTypeCount++;
1336 } break;
1337 case TYPE_VIEW_TEXT_SELECTION_CHANGED: {
1338 if (eventTypeCount > 0) {
1339 builder.append(", ");
1340 }
1341 builder.append("TYPE_VIEW_TEXT_SELECTION_CHANGED");
1342 eventTypeCount++;
1343 } break;
1344 case TYPE_VIEW_SCROLLED: {
1345 if (eventTypeCount > 0) {
1346 builder.append(", ");
1347 }
1348 builder.append("TYPE_VIEW_SCROLLED");
1349 eventTypeCount++;
1350 } break;
1351 case TYPE_ANNOUNCEMENT: {
1352 if (eventTypeCount > 0) {
1353 builder.append(", ");
1354 }
1355 builder.append("TYPE_ANNOUNCEMENT");
1356 eventTypeCount++;
1357 } break;
1358 case TYPE_VIEW_ACCESSIBILITY_FOCUSED: {
1359 if (eventTypeCount > 0) {
1360 builder.append(", ");
1361 }
1362 builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUSED");
1363 eventTypeCount++;
1364 } break;
1365 case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: {
1366 if (eventTypeCount > 0) {
1367 builder.append(", ");
1368 }
1369 builder.append("TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED");
1370 eventTypeCount++;
1371 } break;
1372 case TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: {
1373 if (eventTypeCount > 0) {
1374 builder.append(", ");
1375 }
Svetoslavabad55d2013-05-07 18:49:51 -07001376 builder.append("TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY");
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001377 eventTypeCount++;
1378 } break;
1379 case TYPE_GESTURE_DETECTION_START: {
1380 if (eventTypeCount > 0) {
1381 builder.append(", ");
1382 }
1383 builder.append("TYPE_GESTURE_DETECTION_START");
1384 eventTypeCount++;
1385 } break;
1386 case TYPE_GESTURE_DETECTION_END: {
1387 if (eventTypeCount > 0) {
1388 builder.append(", ");
1389 }
1390 builder.append("TYPE_GESTURE_DETECTION_END");
1391 eventTypeCount++;
1392 } break;
1393 case TYPE_TOUCH_INTERACTION_START: {
1394 if (eventTypeCount > 0) {
1395 builder.append(", ");
1396 }
1397 builder.append("TYPE_TOUCH_INTERACTION_START");
1398 eventTypeCount++;
1399 } break;
1400 case TYPE_TOUCH_INTERACTION_END: {
1401 if (eventTypeCount > 0) {
1402 builder.append(", ");
1403 }
1404 builder.append("TYPE_TOUCH_INTERACTION_END");
1405 eventTypeCount++;
1406 } break;
Svetoslav8e3feb12014-02-24 13:46:47 -08001407 case TYPE_WINDOWS_CHANGED: {
1408 if (eventTypeCount > 0) {
1409 builder.append(", ");
1410 }
1411 builder.append("TYPE_WINDOWS_CHANGED");
1412 eventTypeCount++;
1413 } break;
Mady Mellore8608912015-06-05 09:02:55 -07001414 case TYPE_VIEW_CONTEXT_CLICKED: {
Mady Mellore82067b2015-04-30 09:58:35 -07001415 if (eventTypeCount > 0) {
1416 builder.append(", ");
1417 }
Mady Mellore8608912015-06-05 09:02:55 -07001418 builder.append("TYPE_VIEW_CONTEXT_CLICKED");
Mady Mellore82067b2015-04-30 09:58:35 -07001419 eventTypeCount++;
Alan Viverette5d3d2312015-07-09 09:51:46 -07001420 } break;
Jorim Jaggie85da2ba2015-06-25 17:26:10 -07001421 case TYPE_ASSIST_READING_CONTEXT: {
1422 if (eventTypeCount > 0) {
1423 builder.append(", ");
1424 }
1425 builder.append("TYPE_ASSIST_READING_CONTEXT");
1426 eventTypeCount++;
Alan Viverette5d3d2312015-07-09 09:51:46 -07001427 } break;
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001428 }
1429 }
1430 if (eventTypeCount > 1) {
1431 builder.insert(0, '[');
1432 builder.append(']');
1433 }
1434 return builder.toString();
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001435 }
1436
1437 /**
svetoslavganov75986cf2009-05-14 22:28:01 -07001438 * @see Parcelable.Creator
1439 */
1440 public static final Parcelable.Creator<AccessibilityEvent> CREATOR =
1441 new Parcelable.Creator<AccessibilityEvent>() {
1442 public AccessibilityEvent createFromParcel(Parcel parcel) {
1443 AccessibilityEvent event = AccessibilityEvent.obtain();
1444 event.initFromParcel(parcel);
1445 return event;
1446 }
1447
1448 public AccessibilityEvent[] newArray(int size) {
1449 return new AccessibilityEvent[size];
1450 }
1451 };
1452}