blob: 5adea669314c3f91e384624c5c952828935982ec [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
Eugene Susla4a34f9c2017-05-16 14:16:38 -070024import com.android.internal.util.BitUtils;
25
svetoslavganov75986cf2009-05-14 22:28:01 -070026import java.util.ArrayList;
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -070027import java.util.List;
svetoslavganov75986cf2009-05-14 22:28:01 -070028
29/**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070030 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -070031 * This class represents accessibility events that are sent by the system when
32 * something notable happens in the user interface. For example, when a
33 * {@link android.widget.Button} is clicked, a {@link android.view.View} is focused, etc.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070034 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -070035 * <p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070036 * An accessibility event is fired by an individual view which populates the event with
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070037 * data for its state and requests from its parent to send the event to interested
38 * parties. The parent can optionally add an {@link AccessibilityRecord} for itself before
39 * dispatching a similar request to its parent. A parent can also choose not to respect the
40 * request for sending an event. The accessibility event is sent by the topmost view in the
41 * view tree. Therefore, an {@link android.accessibilityservice.AccessibilityService} can
42 * explore all records in an accessibility event to obtain more information about the
43 * context in which the event was fired.
44 * </p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070045 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070046 * The main purpose of an accessibility event is to expose enough information for an
47 * {@link android.accessibilityservice.AccessibilityService} to provide meaningful feedback
48 * to the user. Sometimes however, an accessibility service may need more contextual
49 * information then the one in the event pay-load. In such cases the service can obtain
50 * the event source which is an {@link AccessibilityNodeInfo} (snapshot of a View state)
51 * which can be used for exploring the window content. Note that the privilege for accessing
52 * an event's source, thus the window content, has to be explicitly requested. For more
53 * details refer to {@link android.accessibilityservice.AccessibilityService}. If an
54 * accessibility service has not requested to retrieve the window content the event will
55 * not contain reference to its source. Also for events of type
56 * {@link #TYPE_NOTIFICATION_STATE_CHANGED} the source is never available.
57 * </p>
Svetoslav Ganov736c2752011-04-22 18:30:36 -070058 * <p>
svetoslavganov75986cf2009-05-14 22:28:01 -070059 * This class represents various semantically different accessibility event
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070060 * types. Each event type has an associated set of related properties. In other
svetoslavganov75986cf2009-05-14 22:28:01 -070061 * words, each event type is characterized via a subset of the properties exposed
62 * by this class. For each event type there is a corresponding constant defined
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070063 * in this class. Follows a specification of the event types and their associated properties:
64 * </p>
Joe Fernandeze1302ed2012-02-06 14:30:15 -080065 * <div class="special reference">
66 * <h3>Developer Guides</h3>
67 * <p>For more information about creating and processing AccessibilityEvents, read the
68 * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a>
69 * developer guide.</p>
70 * </div>
svetoslavganov75986cf2009-05-14 22:28:01 -070071 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070072 * <b>VIEW TYPES</b></br>
73 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -070074 * <p>
75 * <b>View clicked</b> - represents the event of clicking on a {@link android.view.View}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070076 * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.</br>
77 * <em>Type:</em>{@link #TYPE_VIEW_CLICKED}</br>
78 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -070079 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070080 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -070081 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -070082 * <li>{@link #getClassName()} - The class name of the source.</li>
83 * <li>{@link #getPackageName()} - The package name of the source.</li>
84 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070085 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -070086 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
87 * <li>{@link #isPassword()} - Whether the source is password.</li>
88 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -070089 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070090 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
91 * (without descendants of AdapterView).</li>
92 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
93 * (without descendants of AdapterView).</li>
94 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
95 * inclusive (for descendants of AdapterView).</li>
96 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
97 * inclusive (for descendants of AdapterView).</li>
98 * <li>{@link #getItemCount()} - The total items of the source
99 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700100 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700101 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700102 * <p>
103 * <b>View long clicked</b> - represents the event of long clicking on a {@link android.view.View}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700104 * like {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc </br>
105 * <em>Type:</em>{@link #TYPE_VIEW_LONG_CLICKED}</br>
106 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700107 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700108 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700109 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700110 * <li>{@link #getClassName()} - The class name of the source.</li>
111 * <li>{@link #getPackageName()} - The package name of the source.</li>
112 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700113 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700114 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
115 * <li>{@link #isPassword()} - Whether the source is password.</li>
116 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700117 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700118 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
119 * (without descendants of AdapterView).</li>
120 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
121 * (without descendants of AdapterView).</li>
122 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
123 * inclusive (for descendants of AdapterView).</li>
124 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
125 * inclusive (for descendants of AdapterView).</li>
126 * <li>{@link #getItemCount()} - The total items of the source
127 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700128 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700129 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700130 * <p>
131 * <b>View selected</b> - represents the event of selecting an item usually in
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700132 * the context of an {@link android.widget.AdapterView}.</br>
133 * <em>Type:</em> {@link #TYPE_VIEW_SELECTED}</br>
134 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700135 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700136 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700137 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700138 * <li>{@link #getClassName()} - The class name of the source.</li>
139 * <li>{@link #getPackageName()} - The package name of the source.</li>
140 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700141 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700142 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
143 * <li>{@link #isPassword()} - Whether the source is password.</li>
144 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700145 * <li>{@link #getItemCount()} - The number of selectable items of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700146 * <li>{@link #getCurrentItemIndex()} - The currently selected item index.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700147 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700148 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
149 * (without descendants of AdapterView).</li>
150 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
151 * (without descendants of AdapterView).</li>
152 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
153 * inclusive (for descendants of AdapterView).</li>
154 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
155 * inclusive (for descendants of AdapterView).</li>
156 * <li>{@link #getItemCount()} - The total items of the source
157 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700158 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700159 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700160 * <p>
161 * <b>View focused</b> - represents the event of focusing a
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700162 * {@link android.view.View}.</br>
163 * <em>Type:</em> {@link #TYPE_VIEW_FOCUSED}</br>
164 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700165 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700166 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700167 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700168 * <li>{@link #getClassName()} - The class name of the source.</li>
169 * <li>{@link #getPackageName()} - The package name of the source.</li>
170 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700171 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700172 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
173 * <li>{@link #isPassword()} - Whether the source is password.</li>
174 * <li>{@link #isChecked()} - Whether the source is checked.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700175 * <li>{@link #getItemCount()} - The number of focusable items on the screen.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700176 * <li>{@link #getCurrentItemIndex()} - The currently focused item index.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700177 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700178 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
179 * (without descendants of AdapterView).</li>
180 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
181 * (without descendants of AdapterView).</li>
182 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
183 * inclusive (for descendants of AdapterView).</li>
184 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
185 * inclusive (for descendants of AdapterView).</li>
186 * <li>{@link #getItemCount()} - The total items of the source
187 * (for descendants of AdapterView).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700188 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700189 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700190 * <p>
191 * <b>View text changed</b> - represents the event of changing the text of an
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700192 * {@link android.widget.EditText}.</br>
193 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_CHANGED}</br>
194 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700195 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700196 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700197 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700198 * <li>{@link #getClassName()} - The class name of the source.</li>
199 * <li>{@link #getPackageName()} - The package name of the source.</li>
200 * <li>{@link #getEventTime()} - The event time.</li>
201 * <li>{@link #getText()} - The text of the source.</li>
202 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
203 * <li>{@link #isPassword()} - Whether the source is password.</li>
204 * <li>{@link #isChecked()} - Whether the source is checked.</li>
205 * <li>{@link #getFromIndex()} - The text change start index.</li>
206 * <li>{@link #getAddedCount()} - The number of added characters.</li>
207 * <li>{@link #getRemovedCount()} - The number of removed characters.</li>
208 * <li>{@link #getBeforeText()} - The text of the source before the change.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700209 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700210 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700211 * </p>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700212 * <p>
213 * <b>View text selection changed</b> - represents the event of changing the text
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700214 * selection of an {@link android.widget.EditText}.</br>
215 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED} </br>
216 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700217 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700218 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700219 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700220 * <li>{@link #getClassName()} - The class name of the source.</li>
221 * <li>{@link #getPackageName()} - The package name of the source.</li>
222 * <li>{@link #getEventTime()} - The event time.</li>
223 * <li>{@link #getText()} - The text of the source.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700224 * <li>{@link #isPassword()} - Whether the source is password.</li>
225 * <li>{@link #getFromIndex()} - The selection start index.</li>
226 * <li>{@link #getToIndex()} - The selection end index.</li>
227 * <li>{@link #getItemCount()} - The length of the source text.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700228 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
229 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700230 * </ul>
231 * </p>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700232 * <b>View text traversed at movement granularity</b> - represents the event of traversing the
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700233 * text of a view at a given granularity. For example, moving to the next word.</br>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700234 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY} </br>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700235 * <em>Properties:</em></br>
236 * <ul>
237 * <li>{@link #getEventType()} - The type of the event.</li>
238 * <li>{@link #getSource()} - The source info (for registered clients).</li>
239 * <li>{@link #getClassName()} - The class name of the source.</li>
240 * <li>{@link #getPackageName()} - The package name of the source.</li>
241 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700242 * <li>{@link #getMovementGranularity()} - Sets the granularity at which a view's text
243 * was traversed.</li>
244 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Phil Weaverb12a57d2016-03-08 09:35:00 -0800245 * <li>{@link #getFromIndex()} - The start the text that was skipped over in this movement.
246 * This is the starting point when moving forward through the text, but not when moving
247 * back.</li>
248 * <li>{@link #getToIndex()} - The end of the text that was skipped over in this movement.
249 * This is the ending point when moving forward through the text, but not when moving
250 * back.</li>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700251 * <li>{@link #isPassword()} - Whether the source is password.</li>
252 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
253 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700254 * <li>{@link #getMovementGranularity()} - Sets the granularity at which a view's text
255 * was traversed.</li>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700256 * <li>{@link #getAction()} - Gets traversal action which specifies the direction.</li>
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700257 * </ul>
258 * </p>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700259 * <p>
260 * <b>View scrolled</b> - represents the event of scrolling a view. If
261 * the source is a descendant of {@link android.widget.AdapterView} the
262 * scroll is reported in terms of visible items - the first visible item,
263 * the last visible item, and the total items - because the the source
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700264 * is unaware of its pixel size since its adapter is responsible for
Svetoslav Ganova0156172011-06-26 17:55:44 -0700265 * creating views. In all other cases the scroll is reported as the current
266 * scroll on the X and Y axis respectively plus the height of the source in
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700267 * pixels.</br>
268 * <em>Type:</em> {@link #TYPE_VIEW_SCROLLED}</br>
269 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700270 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700271 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700272 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700273 * <li>{@link #getClassName()} - The class name of the source.</li>
274 * <li>{@link #getPackageName()} - The package name of the source.</li>
275 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700276 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700277 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700278 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700279 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
280 * (without descendants of AdapterView).</li>
281 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
282 * (without descendants of AdapterView).</li>
283 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
284 * inclusive (for descendants of AdapterView).</li>
285 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
286 * inclusive (for descendants of AdapterView).</li>
287 * <li>{@link #getItemCount()} - The total items of the source
288 * (for descendants of AdapterView).</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700289 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700290 * <em>Note:</em> This event type is not dispatched to descendants though
291 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
292 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
293 * source {@link android.view.View} and the sub-tree rooted at it will not receive
294 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
295 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
296 * text content to such events is by setting the
297 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
298 * view.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700299 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700300 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700301 * <b>TRANSITION TYPES</b></br>
302 * </p>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700303 * <p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700304 * <b>Window state changed</b> - represents the event of opening a
svetoslavganov75986cf2009-05-14 22:28:01 -0700305 * {@link android.widget.PopupWindow}, {@link android.view.Menu},
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700306 * {@link android.app.Dialog}, etc.</br>
307 * <em>Type:</em> {@link #TYPE_WINDOW_STATE_CHANGED}</br>
308 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700309 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700310 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700311 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700312 * <li>{@link #getClassName()} - The class name of the source.</li>
313 * <li>{@link #getPackageName()} - The package name of the source.</li>
314 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700315 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
316 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700317 * </ul>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700318 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700319 * <p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700320 * <b>Window content changed</b> - represents the event of change in the
321 * content of a window. This change can be adding/removing view, changing
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700322 * a view size, etc.</br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700323 * </p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700324 * <p>
325 * <strong>Note:</strong> This event is fired only for the window source of the
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700326 * last accessibility event different from {@link #TYPE_NOTIFICATION_STATE_CHANGED}
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700327 * and its purpose is to notify clients that the content of the user interaction
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700328 * window has changed.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700329 * <em>Type:</em> {@link #TYPE_WINDOW_CONTENT_CHANGED}</br>
330 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700331 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700332 * <li>{@link #getEventType()} - The type of the event.</li>
Alan Viverette77e9a282013-09-12 17:16:09 -0700333 * <li>{@link #getContentChangeTypes()} - The type of content changes.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700334 * <li>{@link #getSource()} - The source info (for registered clients).</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700335 * <li>{@link #getClassName()} - The class name of the source.</li>
336 * <li>{@link #getPackageName()} - The package name of the source.</li>
337 * <li>{@link #getEventTime()} - The event time.</li>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700338 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700339 * <em>Note:</em> This event type is not dispatched to descendants though
340 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
341 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
342 * source {@link android.view.View} and the sub-tree rooted at it will not receive
343 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
344 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
345 * text content to such events is by setting the
346 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
347 * view.</br>
348 * </p>
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700349 * <p>
Svetoslav8e3feb12014-02-24 13:46:47 -0800350 * <b>Windows changed</b> - represents the event of changes in the windows shown on
351 * the screen such as a window appeared, a window disappeared, a window size changed,
352 * a window layer changed, etc.</br>
353 * <em>Type:</em> {@link #TYPE_WINDOWS_CHANGED}</br>
354 * <em>Properties:</em></br>
355 * <ul>
356 * <li>{@link #getEventType()} - The type of the event.</li>
357 * <li>{@link #getEventTime()} - The event time.</li>
358 * </ul>
359 * <em>Note:</em> You can retrieve the {@link AccessibilityWindowInfo} for the window
360 * source of the event via {@link AccessibilityEvent#getSource()} to get the source
361 * node on which then call {@link AccessibilityNodeInfo#getWindow()
362 * AccessibilityNodeInfo.getWindow()} to get the window. Also all windows on the screen can
363 * be retrieved by a call to {@link android.accessibilityservice.AccessibilityService#getWindows()
364 * android.accessibilityservice.AccessibilityService.getWindows()}.
365 * </p>
366 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700367 * <b>NOTIFICATION TYPES</b></br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700368 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700369 * <p>
Phil Weaver33c71362017-05-09 16:17:02 -0700370 * <b>Notification state changed</b> - represents the event showing a transient piece of information
371 * to the user. This information may be a {@link android.app.Notification} or
372 * {@link android.widget.Toast}.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700373 * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
374 * <em>Properties:</em></br>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700375 * <ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700376 * <li>{@link #getEventType()} - The type of the event.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700377 * <li>{@link #getClassName()} - The class name of the source.</li>
378 * <li>{@link #getPackageName()} - The package name of the source.</li>
379 * <li>{@link #getEventTime()} - The event time.</li>
Phil Weaver33c71362017-05-09 16:17:02 -0700380 * <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}, if
381 * applicable.</li>
382 * <li>{@link #getText()} - Displayed text of the {@link android.widget.Toast}, if applicable,
383 * or may contain text from the {@link android.app.Notification}, although
384 * {@link #getParcelableData()} is a richer set of data for {@link android.app.Notification}.</li>
Svetoslav Ganova0156172011-06-26 17:55:44 -0700385 * </ul>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700386 * </p>
387 * <p>
388 * <b>EXPLORATION TYPES</b></br>
389 * </p>
390 * <p>
391 * <b>View hover enter</b> - represents the event of beginning to hover
392 * over a {@link android.view.View}. The hover may be generated via
393 * exploring the screen by touch or via a pointing device.</br>
394 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_ENTER}</br>
395 * <em>Properties:</em></br>
396 * <ul>
397 * <li>{@link #getEventType()} - The type of the event.</li>
398 * <li>{@link #getSource()} - The source info (for registered clients).</li>
399 * <li>{@link #getClassName()} - The class name of the source.</li>
400 * <li>{@link #getPackageName()} - The package name of the source.</li>
401 * <li>{@link #getEventTime()} - The event time.</li>
402 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
403 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
404 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700405 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
406 * (without descendants of AdapterView).</li>
407 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
408 * (without descendants of AdapterView).</li>
409 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
410 * inclusive (for descendants of AdapterView).</li>
411 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
412 * inclusive (for descendants of AdapterView).</li>
413 * <li>{@link #getItemCount()} - The total items of the source
414 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700415 * </ul>
416 * </p>
417 * <b>View hover exit</b> - represents the event of stopping to hover
418 * over a {@link android.view.View}. The hover may be generated via
419 * exploring the screen by touch or via a pointing device.</br>
420 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_EXIT}</br>
421 * <em>Properties:</em></br>
422 * <ul>
423 * <li>{@link #getEventType()} - The type of the event.</li>
424 * <li>{@link #getSource()} - The source info (for registered clients).</li>
425 * <li>{@link #getClassName()} - The class name of the source.</li>
426 * <li>{@link #getPackageName()} - The package name of the source.</li>
427 * <li>{@link #getEventTime()} - The event time.</li>
428 * <li>{@link #getText()} - The text of the source's sub-tree.</li>
429 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
430 * <li>{@link #getContentDescription()} - The content description of the source.</li>
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -0700431 * <li>{@link #getScrollX()} - The offset of the source left edge in pixels
432 * (without descendants of AdapterView).</li>
433 * <li>{@link #getScrollY()} - The offset of the source top edge in pixels
434 * (without descendants of AdapterView).</li>
435 * <li>{@link #getFromIndex()} - The zero based index of the first visible item of the source,
436 * inclusive (for descendants of AdapterView).</li>
437 * <li>{@link #getToIndex()} - The zero based index of the last visible item of the source,
438 * inclusive (for descendants of AdapterView).</li>
439 * <li>{@link #getItemCount()} - The total items of the source
440 * (for descendants of AdapterView).</li>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700441 * </ul>
442 * </p>
443 * <p>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700444 * <b>Touch interaction start</b> - represents the event of starting a touch
445 * interaction, which is the user starts touching the screen.</br>
446 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_START}</br>
447 * <em>Properties:</em></br>
448 * <ul>
449 * <li>{@link #getEventType()} - The type of the event.</li>
450 * </ul>
451 * <em>Note:</em> This event is fired only by the system and is not passed to the
452 * view tree to be populated.</br>
453 * </p>
454 * <p>
455 * <b>Touch interaction end</b> - represents the event of ending a touch
456 * interaction, which is the user stops touching the screen.</br>
457 * <em>Type:</em> {@link #TYPE_TOUCH_INTERACTION_END}</br>
458 * <em>Properties:</em></br>
459 * <ul>
460 * <li>{@link #getEventType()} - The type of the event.</li>
461 * </ul>
462 * <em>Note:</em> This event is fired only by the system and is not passed to the
463 * view tree to be populated.</br>
464 * </p>
465 * <p>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700466 * <b>Touch exploration gesture start</b> - represents the event of starting a touch
467 * exploring gesture.</br>
468 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}</br>
469 * <em>Properties:</em></br>
470 * <ul>
471 * <li>{@link #getEventType()} - The type of the event.</li>
472 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700473 * <em>Note:</em> This event is fired only by the system and is not passed to the
474 * view tree to be populated.</br>
Svetoslav Ganov82e236d2011-09-29 19:31:06 -0700475 * </p>
476 * <p>
477 * <b>Touch exploration gesture end</b> - represents the event of ending a touch
478 * exploring gesture.</br>
479 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}</br>
480 * <em>Properties:</em></br>
481 * <ul>
482 * <li>{@link #getEventType()} - The type of the event.</li>
483 * </ul>
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700484 * <em>Note:</em> This event is fired only by the system and is not passed to the
485 * view tree to be populated.</br>
486 * </p>
487 * <p>
488 * <b>Touch gesture detection start</b> - represents the event of starting a user
489 * gesture detection.</br>
490 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_START}</br>
491 * <em>Properties:</em></br>
492 * <ul>
493 * <li>{@link #getEventType()} - The type of the event.</li>
494 * </ul>
495 * <em>Note:</em> This event is fired only by the system and is not passed to the
496 * view tree to be populated.</br>
497 * </p>
498 * <p>
499 * <b>Touch gesture detection end</b> - represents the event of ending a user
500 * gesture detection.</br>
501 * <em>Type:</em> {@link #TYPE_GESTURE_DETECTION_END}</br>
502 * <em>Properties:</em></br>
503 * <ul>
504 * <li>{@link #getEventType()} - The type of the event.</li>
505 * </ul>
506 * <em>Note:</em> This event is fired only by the system and is not passed to the
507 * view tree to be populated.</br>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700508 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700509 * <p>
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800510 * <b>MISCELLANEOUS TYPES</b></br>
511 * </p>
512 * <p>
513 * <b>Announcement</b> - represents the event of an application making an
514 * announcement. Usually this announcement is related to some sort of a context
515 * change for which none of the events representing UI transitions is a good fit.
516 * For example, announcing a new page in a book.</br>
517 * <em>Type:</em> {@link #TYPE_ANNOUNCEMENT}</br>
518 * <em>Properties:</em></br>
519 * <ul>
520 * <li>{@link #getEventType()} - The type of the event.</li>
521 * <li>{@link #getSource()} - The source info (for registered clients).</li>
522 * <li>{@link #getClassName()} - The class name of the source.</li>
523 * <li>{@link #getPackageName()} - The package name of the source.</li>
524 * <li>{@link #getEventTime()} - The event time.</li>
525 * <li>{@link #getText()} - The text of the announcement.</li>
526 * <li>{@link #isEnabled()} - Whether the source is enabled.</li>
527 * </ul>
528 * </p>
svetoslavganov75986cf2009-05-14 22:28:01 -0700529 *
530 * @see android.view.accessibility.AccessibilityManager
531 * @see android.accessibilityservice.AccessibilityService
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700532 * @see AccessibilityNodeInfo
svetoslavganov75986cf2009-05-14 22:28:01 -0700533 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700534public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700535 private static final boolean DEBUG = false;
svetoslavganov75986cf2009-05-14 22:28:01 -0700536
537 /**
538 * Invalid selection/focus position.
539 *
540 * @see #getCurrentItemIndex()
541 */
542 public static final int INVALID_POSITION = -1;
543
544 /**
545 * Maximum length of the text fields.
546 *
547 * @see #getBeforeText()
548 * @see #getText()
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700549 * </br>
550 * Note: This constant is no longer needed since there
551 * is no limit on the length of text that is contained
552 * in an accessibility event anymore.
svetoslavganov75986cf2009-05-14 22:28:01 -0700553 */
Svetoslav Ganovc0a8cd12011-03-18 17:05:56 -0700554 @Deprecated
svetoslavganov75986cf2009-05-14 22:28:01 -0700555 public static final int MAX_TEXT_LENGTH = 500;
556
557 /**
558 * Represents the event of clicking on a {@link android.view.View} like
559 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
560 */
561 public static final int TYPE_VIEW_CLICKED = 0x00000001;
562
563 /**
564 * Represents the event of long clicking on a {@link android.view.View} like
565 * {@link android.widget.Button}, {@link android.widget.CompoundButton}, etc.
566 */
567 public static final int TYPE_VIEW_LONG_CLICKED = 0x00000002;
568
569 /**
570 * Represents the event of selecting an item usually in the context of an
571 * {@link android.widget.AdapterView}.
572 */
573 public static final int TYPE_VIEW_SELECTED = 0x00000004;
574
575 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700576 * Represents the event of setting input focus of a {@link android.view.View}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700577 */
578 public static final int TYPE_VIEW_FOCUSED = 0x00000008;
579
580 /**
581 * Represents the event of changing the text of an {@link android.widget.EditText}.
582 */
583 public static final int TYPE_VIEW_TEXT_CHANGED = 0x00000010;
584
585 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700586 * Represents the event of opening a {@link android.widget.PopupWindow},
svetoslavganov75986cf2009-05-14 22:28:01 -0700587 * {@link android.view.Menu}, {@link android.app.Dialog}, etc.
588 */
589 public static final int TYPE_WINDOW_STATE_CHANGED = 0x00000020;
590
591 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700592 * Represents the event showing a {@link android.app.Notification}.
svetoslavganov75986cf2009-05-14 22:28:01 -0700593 */
594 public static final int TYPE_NOTIFICATION_STATE_CHANGED = 0x00000040;
595
596 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700597 * Represents the event of a hover enter over a {@link android.view.View}.
598 */
599 public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080;
600
601 /**
602 * Represents the event of a hover exit over a {@link android.view.View}.
603 */
604 public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100;
605
606 /**
607 * Represents the event of starting a touch exploration gesture.
608 */
609 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200;
610
611 /**
612 * Represents the event of ending a touch exploration gesture.
613 */
614 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400;
615
616 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700617 * Represents the event of changing the content of a window and more
618 * specifically the sub-tree rooted at the event's source.
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700619 */
620 public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800;
621
622 /**
Phil Weaver2b94bbe2017-06-06 10:48:47 -0700623 * Represents the event of scrolling a view. This event type is generally not sent directly.
624 * @see View#onScrollChanged(int, int, int, int)
Svetoslav Ganova0156172011-06-26 17:55:44 -0700625 */
626 public static final int TYPE_VIEW_SCROLLED = 0x00001000;
627
628 /**
629 * Represents the event of changing the selection in an {@link android.widget.EditText}.
630 */
631 public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000;
632
633 /**
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800634 * Represents the event of an application making an announcement.
635 */
636 public static final int TYPE_ANNOUNCEMENT = 0x00004000;
637
638 /**
Svetoslav Ganov42138042012-03-20 11:51:39 -0700639 * Represents the event of gaining accessibility focus.
640 */
641 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000;
642
643 /**
644 * Represents the event of clearing accessibility focus.
645 */
646 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000;
647
648 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700649 * Represents the event of traversing the text of a view at a given movement granularity.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700650 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700651 public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700652
653 /**
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700654 * Represents the event of beginning gesture detection.
655 */
656 public static final int TYPE_GESTURE_DETECTION_START = 0x00040000;
657
658 /**
659 * Represents the event of ending gesture detection.
660 */
661 public static final int TYPE_GESTURE_DETECTION_END = 0x00080000;
662
663 /**
664 * Represents the event of the user starting to touch the screen.
665 */
666 public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000;
667
668 /**
669 * Represents the event of the user ending to touch the screen.
670 */
671 public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000;
672
673 /**
Svetoslav8e3feb12014-02-24 13:46:47 -0800674 * Represents the event change in the windows shown on the screen.
675 */
676 public static final int TYPE_WINDOWS_CHANGED = 0x00400000;
677
678 /**
Mady Mellore8608912015-06-05 09:02:55 -0700679 * Represents the event of a context click on a {@link android.view.View}.
Mady Mellore82067b2015-04-30 09:58:35 -0700680 */
Mady Mellore8608912015-06-05 09:02:55 -0700681 public static final int TYPE_VIEW_CONTEXT_CLICKED = 0x00800000;
Mady Mellore82067b2015-04-30 09:58:35 -0700682
683 /**
Jorim Jaggie85da2ba2015-06-25 17:26:10 -0700684 * Represents the event of the assistant currently reading the users screen context.
685 */
686 public static final int TYPE_ASSIST_READING_CONTEXT = 0x01000000;
687
688 /**
Svetoslav6254f482013-06-04 17:22:14 -0700689 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
Alan Viverette77e9a282013-09-12 17:16:09 -0700690 * The type of change is not defined.
Svetoslav6254f482013-06-04 17:22:14 -0700691 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700692 public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0x00000000;
Svetoslav6254f482013-06-04 17:22:14 -0700693
694 /**
695 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
Alan Viverette77e9a282013-09-12 17:16:09 -0700696 * A node in the subtree rooted at the source node was added or removed.
Svetoslav6254f482013-06-04 17:22:14 -0700697 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700698 public static final int CONTENT_CHANGE_TYPE_SUBTREE = 0x00000001;
699
700 /**
701 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
702 * The node's text changed.
703 */
704 public static final int CONTENT_CHANGE_TYPE_TEXT = 0x00000002;
705
706 /**
707 * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
708 * The node's content description changed.
709 */
710 public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004;
Svetoslav6254f482013-06-04 17:22:14 -0700711
712 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700713 * Mask for {@link AccessibilityEvent} all types.
714 *
715 * @see #TYPE_VIEW_CLICKED
716 * @see #TYPE_VIEW_LONG_CLICKED
717 * @see #TYPE_VIEW_SELECTED
718 * @see #TYPE_VIEW_FOCUSED
719 * @see #TYPE_VIEW_TEXT_CHANGED
720 * @see #TYPE_WINDOW_STATE_CHANGED
721 * @see #TYPE_NOTIFICATION_STATE_CHANGED
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700722 * @see #TYPE_VIEW_HOVER_ENTER
723 * @see #TYPE_VIEW_HOVER_EXIT
724 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_START
725 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_END
726 * @see #TYPE_WINDOW_CONTENT_CHANGED
727 * @see #TYPE_VIEW_SCROLLED
728 * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
Svetoslav Ganov51ab90c2012-03-09 10:54:49 -0800729 * @see #TYPE_ANNOUNCEMENT
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700730 * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY
Svetoslav Ganov77276b62012-09-14 10:23:00 -0700731 * @see #TYPE_GESTURE_DETECTION_START
732 * @see #TYPE_GESTURE_DETECTION_END
733 * @see #TYPE_TOUCH_INTERACTION_START
734 * @see #TYPE_TOUCH_INTERACTION_END
Svetoslav8e3feb12014-02-24 13:46:47 -0800735 * @see #TYPE_WINDOWS_CHANGED
Mady Mellore8608912015-06-05 09:02:55 -0700736 * @see #TYPE_VIEW_CONTEXT_CLICKED
svetoslavganov75986cf2009-05-14 22:28:01 -0700737 */
738 public static final int TYPES_ALL_MASK = 0xFFFFFFFF;
739
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700740 private static final int MAX_POOL_SIZE = 10;
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -0800741 private static final SynchronizedPool<AccessibilityEvent> sPool =
742 new SynchronizedPool<AccessibilityEvent>(MAX_POOL_SIZE);
svetoslavganov75986cf2009-05-14 22:28:01 -0700743
744 private int mEventType;
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700745 private CharSequence mPackageName;
svetoslavganov75986cf2009-05-14 22:28:01 -0700746 private long mEventTime;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700747 int mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700748 int mAction;
Alan Viverette77e9a282013-09-12 17:16:09 -0700749 int mContentChangeTypes;
svetoslavganov75986cf2009-05-14 22:28:01 -0700750
Alan Viverette502cb332013-10-15 18:29:53 -0700751 private ArrayList<AccessibilityRecord> mRecords;
svetoslavganov75986cf2009-05-14 22:28:01 -0700752
753 /*
754 * Hide constructor from clients.
755 */
756 private AccessibilityEvent() {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700757 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700758
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700759 /**
760 * Initialize an event from another one.
761 *
762 * @param event The event to initialize from.
763 */
764 void init(AccessibilityEvent event) {
765 super.init(event);
766 mEventType = event.mEventType;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700767 mMovementGranularity = event.mMovementGranularity;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700768 mAction = event.mAction;
Alan Viverette77e9a282013-09-12 17:16:09 -0700769 mContentChangeTypes = event.mContentChangeTypes;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700770 mEventTime = event.mEventTime;
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700771 mPackageName = event.mPackageName;
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700772 }
773
774 /**
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700775 * Sets if this instance is sealed.
776 *
777 * @param sealed Whether is sealed.
778 *
779 * @hide
780 */
781 @Override
782 public void setSealed(boolean sealed) {
783 super.setSealed(sealed);
Alan Viverette502cb332013-10-15 18:29:53 -0700784 final List<AccessibilityRecord> records = mRecords;
785 if (records != null) {
786 final int recordCount = records.size();
787 for (int i = 0; i < recordCount; i++) {
788 AccessibilityRecord record = records.get(i);
789 record.setSealed(sealed);
790 }
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -0700791 }
svetoslavganov75986cf2009-05-14 22:28:01 -0700792 }
793
794 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700795 * Gets the number of records contained in the event.
svetoslavganov75986cf2009-05-14 22:28:01 -0700796 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700797 * @return The number of records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700798 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700799 public int getRecordCount() {
Alan Viverette502cb332013-10-15 18:29:53 -0700800 return mRecords == null ? 0 : mRecords.size();
svetoslavganov75986cf2009-05-14 22:28:01 -0700801 }
802
803 /**
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700804 * Appends an {@link AccessibilityRecord} to the end of event records.
svetoslavganov75986cf2009-05-14 22:28:01 -0700805 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700806 * @param record The record to append.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700807 *
808 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700809 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700810 public void appendRecord(AccessibilityRecord record) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700811 enforceNotSealed();
Alan Viverette502cb332013-10-15 18:29:53 -0700812 if (mRecords == null) {
813 mRecords = new ArrayList<AccessibilityRecord>();
814 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700815 mRecords.add(record);
svetoslavganov75986cf2009-05-14 22:28:01 -0700816 }
817
818 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700819 * Gets the record at a given index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700820 *
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700821 * @param index The index.
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700822 * @return The record at the specified index.
svetoslavganov75986cf2009-05-14 22:28:01 -0700823 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700824 public AccessibilityRecord getRecord(int index) {
Alan Viverette502cb332013-10-15 18:29:53 -0700825 if (mRecords == null) {
826 throw new IndexOutOfBoundsException("Invalid index " + index + ", size is 0");
827 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700828 return mRecords.get(index);
svetoslavganov75986cf2009-05-14 22:28:01 -0700829 }
830
831 /**
832 * Gets the event type.
833 *
834 * @return The event type.
835 */
836 public int getEventType() {
837 return mEventType;
838 }
839
840 /**
Alan Viverette77e9a282013-09-12 17:16:09 -0700841 * Gets the bit mask of change types signaled by an
842 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event. A single event may represent
843 * multiple change types.
Svetoslav6254f482013-06-04 17:22:14 -0700844 *
Alan Viverette77e9a282013-09-12 17:16:09 -0700845 * @return The bit mask of change types. One or more of:
846 * <ul>
847 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
848 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_SUBTREE}
849 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_TEXT}
850 * <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_UNDEFINED}
851 * </ul>
Svetoslav6254f482013-06-04 17:22:14 -0700852 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700853 public int getContentChangeTypes() {
854 return mContentChangeTypes;
Svetoslav6254f482013-06-04 17:22:14 -0700855 }
856
Eugene Susla4a34f9c2017-05-16 14:16:38 -0700857 private static String contentChangeTypesToString(int types) {
858 return BitUtils.flagsToString(types, AccessibilityEvent::singleContentChangeTypeToString);
859 }
860
861 private static String singleContentChangeTypeToString(int type) {
862 switch (type) {
863 case CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION: {
864 return "CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION";
865 }
866 case CONTENT_CHANGE_TYPE_SUBTREE: return "CONTENT_CHANGE_TYPE_SUBTREE";
867 case CONTENT_CHANGE_TYPE_TEXT: return "CONTENT_CHANGE_TYPE_TEXT";
868 case CONTENT_CHANGE_TYPE_UNDEFINED: return "CONTENT_CHANGE_TYPE_UNDEFINED";
869 default: return Integer.toHexString(type);
870 }
871 }
872
Svetoslav6254f482013-06-04 17:22:14 -0700873 /**
Alan Viverette77e9a282013-09-12 17:16:09 -0700874 * Sets the bit mask of node tree changes signaled by an
Svetoslav6254f482013-06-04 17:22:14 -0700875 * {@link #TYPE_WINDOW_CONTENT_CHANGED} event.
876 *
Alan Viverette77e9a282013-09-12 17:16:09 -0700877 * @param changeTypes The bit mask of change types.
878 * @throws IllegalStateException If called from an AccessibilityService.
879 * @see #getContentChangeTypes()
Svetoslav6254f482013-06-04 17:22:14 -0700880 */
Alan Viverette77e9a282013-09-12 17:16:09 -0700881 public void setContentChangeTypes(int changeTypes) {
Svetoslav6254f482013-06-04 17:22:14 -0700882 enforceNotSealed();
Alan Viverette77e9a282013-09-12 17:16:09 -0700883 mContentChangeTypes = changeTypes;
Svetoslav6254f482013-06-04 17:22:14 -0700884 }
885
886 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700887 * Sets the event type.
888 *
889 * @param eventType The event type.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700890 *
891 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700892 */
893 public void setEventType(int eventType) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700894 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700895 mEventType = eventType;
896 }
897
898 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700899 * Gets the time in which this event was sent.
900 *
901 * @return The event time.
902 */
903 public long getEventTime() {
904 return mEventTime;
905 }
906
907 /**
908 * Sets the time in which this event was sent.
909 *
910 * @param eventTime The event time.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700911 *
912 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700913 */
914 public void setEventTime(long eventTime) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700915 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700916 mEventTime = eventTime;
917 }
918
919 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700920 * Gets the package name of the source.
921 *
922 * @return The package name.
923 */
924 public CharSequence getPackageName() {
925 return mPackageName;
926 }
927
928 /**
929 * Sets the package name of the source.
930 *
931 * @param packageName The package name.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700932 *
933 * @throws IllegalStateException If called from an AccessibilityService.
svetoslavganov75986cf2009-05-14 22:28:01 -0700934 */
935 public void setPackageName(CharSequence packageName) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -0700936 enforceNotSealed();
svetoslavganov75986cf2009-05-14 22:28:01 -0700937 mPackageName = packageName;
938 }
939
940 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700941 * Sets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700942 *
943 * @param granularity The granularity.
944 *
945 * @throws IllegalStateException If called from an AccessibilityService.
946 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700947 public void setMovementGranularity(int granularity) {
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700948 enforceNotSealed();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700949 mMovementGranularity = granularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700950 }
951
952 /**
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700953 * Gets the movement granularity that was traversed.
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700954 *
955 * @return The granularity.
956 */
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -0700957 public int getMovementGranularity() {
958 return mMovementGranularity;
Svetoslav Ganovb7ff3252012-04-24 18:40:07 -0700959 }
960
961 /**
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700962 * Sets the performed action that triggered this event.
Alan Viveretteaf431102013-10-04 13:16:51 -0700963 * <p>
964 * Valid actions are defined in {@link AccessibilityNodeInfo}:
965 * <ul>
966 * <li>{@link AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS}
967 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_ACCESSIBILITY_FOCUS}
968 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_FOCUS}
969 * <li>{@link AccessibilityNodeInfo#ACTION_CLEAR_SELECTION}
970 * <li>{@link AccessibilityNodeInfo#ACTION_CLICK}
971 * <li>etc.
972 * </ul>
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700973 *
974 * @param action The action.
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700975 * @throws IllegalStateException If called from an AccessibilityService.
Alan Viveretteaf431102013-10-04 13:16:51 -0700976 * @see AccessibilityNodeInfo#performAction(int)
Svetoslav Ganov6d17a932012-04-27 19:30:38 -0700977 */
978 public void setAction(int action) {
979 enforceNotSealed();
980 mAction = action;
981 }
982
983 /**
984 * Gets the performed action that triggered this event.
985 *
986 * @return The action.
987 */
988 public int getAction() {
989 return mAction;
990 }
991
992 /**
svetoslavganov75986cf2009-05-14 22:28:01 -0700993 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -0700994 * instantiated with its type property set.
svetoslavganov75986cf2009-05-14 22:28:01 -0700995 *
996 * @param eventType The event type.
997 * @return An instance.
998 */
999 public static AccessibilityEvent obtain(int eventType) {
1000 AccessibilityEvent event = AccessibilityEvent.obtain();
1001 event.setEventType(eventType);
1002 return event;
1003 }
1004
1005 /**
1006 * Returns a cached instance if such is available or a new one is
Svetoslav Ganov35bfede2011-07-14 17:57:06 -07001007 * created. The returned instance is initialized from the given
1008 * <code>event</code>.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001009 *
1010 * @param event The other event.
1011 * @return An instance.
1012 */
1013 public static AccessibilityEvent obtain(AccessibilityEvent event) {
1014 AccessibilityEvent eventClone = AccessibilityEvent.obtain();
1015 eventClone.init(event);
1016
Alan Viverette502cb332013-10-15 18:29:53 -07001017 if (event.mRecords != null) {
1018 final int recordCount = event.mRecords.size();
1019 eventClone.mRecords = new ArrayList<AccessibilityRecord>(recordCount);
1020 for (int i = 0; i < recordCount; i++) {
1021 final AccessibilityRecord record = event.mRecords.get(i);
1022 final AccessibilityRecord recordClone = AccessibilityRecord.obtain(record);
1023 eventClone.mRecords.add(recordClone);
1024 }
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001025 }
1026
1027 return eventClone;
1028 }
1029
1030 /**
1031 * Returns a cached instance if such is available or a new one is
svetoslavganov75986cf2009-05-14 22:28:01 -07001032 * instantiated.
1033 *
1034 * @return An instance.
1035 */
1036 public static AccessibilityEvent obtain() {
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -08001037 AccessibilityEvent event = sPool.acquire();
1038 return (event != null) ? event : new AccessibilityEvent();
svetoslavganov75986cf2009-05-14 22:28:01 -07001039 }
1040
1041 /**
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001042 * Recycles an instance back to be reused.
svetoslavganov75986cf2009-05-14 22:28:01 -07001043 * <p>
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001044 * <b>Note: You must not touch the object after calling this function.</b>
1045 * </p>
Svetoslav Ganov887e1a12011-04-29 15:09:28 -07001046 *
1047 * @throws IllegalStateException If the event is already recycled.
svetoslavganov75986cf2009-05-14 22:28:01 -07001048 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001049 @Override
svetoslavganov75986cf2009-05-14 22:28:01 -07001050 public void recycle() {
svetoslavganov75986cf2009-05-14 22:28:01 -07001051 clear();
Svetoslav Ganovf4782ec2012-11-28 09:11:41 -08001052 sPool.release(this);
svetoslavganov75986cf2009-05-14 22:28:01 -07001053 }
1054
1055 /**
1056 * Clears the state of this instance.
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001057 *
1058 * @hide
svetoslavganov75986cf2009-05-14 22:28:01 -07001059 */
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001060 @Override
1061 protected void clear() {
1062 super.clear();
svetoslavganov75986cf2009-05-14 22:28:01 -07001063 mEventType = 0;
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001064 mMovementGranularity = 0;
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001065 mAction = 0;
Alan Viverette77e9a282013-09-12 17:16:09 -07001066 mContentChangeTypes = 0;
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001067 mPackageName = null;
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001068 mEventTime = 0;
Alan Viverette502cb332013-10-15 18:29:53 -07001069 if (mRecords != null) {
1070 while (!mRecords.isEmpty()) {
1071 AccessibilityRecord record = mRecords.remove(0);
1072 record.recycle();
1073 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001074 }
1075 }
1076
1077 /**
1078 * Creates a new instance from a {@link Parcel}.
1079 *
1080 * @param parcel A parcel containing the state of a {@link AccessibilityEvent}.
1081 */
1082 public void initFromParcel(Parcel parcel) {
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001083 mSealed = (parcel.readInt() == 1);
svetoslavganov75986cf2009-05-14 22:28:01 -07001084 mEventType = parcel.readInt();
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001085 mMovementGranularity = parcel.readInt();
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001086 mAction = parcel.readInt();
Alan Viverette77e9a282013-09-12 17:16:09 -07001087 mContentChangeTypes = parcel.readInt();
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001088 mPackageName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001089 mEventTime = parcel.readLong();
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001090 mConnectionId = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001091 readAccessibilityRecordFromParcel(this, parcel);
1092
1093 // Read the records.
1094 final int recordCount = parcel.readInt();
Alan Viverette502cb332013-10-15 18:29:53 -07001095 if (recordCount > 0) {
1096 mRecords = new ArrayList<AccessibilityRecord>(recordCount);
1097 for (int i = 0; i < recordCount; i++) {
1098 AccessibilityRecord record = AccessibilityRecord.obtain();
1099 readAccessibilityRecordFromParcel(record, parcel);
1100 record.mConnectionId = mConnectionId;
1101 mRecords.add(record);
1102 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001103 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001104 }
1105
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001106 /**
1107 * Reads an {@link AccessibilityRecord} from a parcel.
1108 *
1109 * @param record The record to initialize.
1110 * @param parcel The parcel to read from.
1111 */
1112 private void readAccessibilityRecordFromParcel(AccessibilityRecord record,
1113 Parcel parcel) {
1114 record.mBooleanProperties = parcel.readInt();
1115 record.mCurrentItemIndex = parcel.readInt();
1116 record.mItemCount = parcel.readInt();
1117 record.mFromIndex = parcel.readInt();
Svetoslav Ganova0156172011-06-26 17:55:44 -07001118 record.mToIndex = parcel.readInt();
1119 record.mScrollX = parcel.readInt();
1120 record.mScrollY = parcel.readInt();
Eugene Suslacb45ddf2017-05-31 10:57:16 -07001121 record.mScrollDeltaX = parcel.readInt();
1122 record.mScrollDeltaY = parcel.readInt();
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001123 record.mMaxScrollX = parcel.readInt();
1124 record.mMaxScrollY = parcel.readInt();
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001125 record.mAddedCount = parcel.readInt();
1126 record.mRemovedCount = parcel.readInt();
1127 record.mClassName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1128 record.mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1129 record.mBeforeText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
1130 record.mParcelableData = parcel.readParcelable(null);
1131 parcel.readList(record.mText, null);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001132 record.mSourceWindowId = parcel.readInt();
Phil Weaver651fe9f2017-05-24 16:43:46 -07001133 record.mSourceNodeId = parcel.readLong();
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001134 record.mSealed = (parcel.readInt() == 1);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001135 }
1136
1137 /**
1138 * {@inheritDoc}
1139 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001140 public void writeToParcel(Parcel parcel, int flags) {
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001141 parcel.writeInt(isSealed() ? 1 : 0);
svetoslavganov75986cf2009-05-14 22:28:01 -07001142 parcel.writeInt(mEventType);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001143 parcel.writeInt(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001144 parcel.writeInt(mAction);
Alan Viverette77e9a282013-09-12 17:16:09 -07001145 parcel.writeInt(mContentChangeTypes);
Adam Powell3fb3d7c2011-04-22 17:08:55 -07001146 TextUtils.writeToParcel(mPackageName, parcel, 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001147 parcel.writeLong(mEventTime);
Svetoslav Ganovd116d7c2011-11-21 18:41:59 -08001148 parcel.writeInt(mConnectionId);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001149 writeAccessibilityRecordToParcel(this, parcel, flags);
1150
1151 // Write the records.
1152 final int recordCount = getRecordCount();
1153 parcel.writeInt(recordCount);
1154 for (int i = 0; i < recordCount; i++) {
1155 AccessibilityRecord record = mRecords.get(i);
1156 writeAccessibilityRecordToParcel(record, parcel, flags);
1157 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001158 }
1159
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001160 /**
1161 * Writes an {@link AccessibilityRecord} to a parcel.
1162 *
1163 * @param record The record to write.
1164 * @param parcel The parcel to which to write.
1165 */
1166 private void writeAccessibilityRecordToParcel(AccessibilityRecord record, Parcel parcel,
1167 int flags) {
1168 parcel.writeInt(record.mBooleanProperties);
1169 parcel.writeInt(record.mCurrentItemIndex);
1170 parcel.writeInt(record.mItemCount);
1171 parcel.writeInt(record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001172 parcel.writeInt(record.mToIndex);
1173 parcel.writeInt(record.mScrollX);
1174 parcel.writeInt(record.mScrollY);
Eugene Suslacb45ddf2017-05-31 10:57:16 -07001175 parcel.writeInt(record.mScrollDeltaX);
1176 parcel.writeInt(record.mScrollDeltaY);
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -07001177 parcel.writeInt(record.mMaxScrollX);
1178 parcel.writeInt(record.mMaxScrollY);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001179 parcel.writeInt(record.mAddedCount);
1180 parcel.writeInt(record.mRemovedCount);
1181 TextUtils.writeToParcel(record.mClassName, parcel, flags);
1182 TextUtils.writeToParcel(record.mContentDescription, parcel, flags);
1183 TextUtils.writeToParcel(record.mBeforeText, parcel, flags);
1184 parcel.writeParcelable(record.mParcelableData, flags);
1185 parcel.writeList(record.mText);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001186 parcel.writeInt(record.mSourceWindowId);
Phil Weaver651fe9f2017-05-24 16:43:46 -07001187 parcel.writeLong(record.mSourceNodeId);
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001188 parcel.writeInt(record.mSealed ? 1 : 0);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001189 }
1190
1191 /**
1192 * {@inheritDoc}
1193 */
svetoslavganov75986cf2009-05-14 22:28:01 -07001194 public int describeContents() {
1195 return 0;
1196 }
1197
1198 @Override
1199 public String toString() {
1200 StringBuilder builder = new StringBuilder();
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001201 builder.append("EventType: ").append(eventTypeToString(mEventType));
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001202 builder.append("; EventTime: ").append(mEventTime);
1203 builder.append("; PackageName: ").append(mPackageName);
Svetoslav Ganov2b435aa2012-05-04 17:16:37 -07001204 builder.append("; MovementGranularity: ").append(mMovementGranularity);
Svetoslav Ganov6d17a932012-04-27 19:30:38 -07001205 builder.append("; Action: ").append(mAction);
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001206 builder.append(super.toString());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001207 if (DEBUG) {
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001208 builder.append("\n");
Eugene Susla4a34f9c2017-05-16 14:16:38 -07001209 builder.append("; ContentChangeTypes: ").append(
1210 contentChangeTypesToString(mContentChangeTypes));
Svetoslav Ganoveeee4d22011-06-10 20:51:30 -07001211 builder.append("; sourceWindowId: ").append(mSourceWindowId);
Phil Weaver651fe9f2017-05-24 16:43:46 -07001212 builder.append("; mSourceNodeId: ").append(mSourceNodeId);
Alan Viverette502cb332013-10-15 18:29:53 -07001213 for (int i = 0; i < getRecordCount(); i++) {
1214 final AccessibilityRecord record = getRecord(i);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001215 builder.append(" Record ");
1216 builder.append(i);
1217 builder.append(":");
1218 builder.append(" [ ClassName: " + record.mClassName);
1219 builder.append("; Text: " + record.mText);
1220 builder.append("; ContentDescription: " + record.mContentDescription);
1221 builder.append("; ItemCount: " + record.mItemCount);
1222 builder.append("; CurrentItemIndex: " + record.mCurrentItemIndex);
1223 builder.append("; IsEnabled: " + record.isEnabled());
1224 builder.append("; IsPassword: " + record.isPassword());
1225 builder.append("; IsChecked: " + record.isChecked());
1226 builder.append("; IsFullScreen: " + record.isFullScreen());
Svetoslav Ganova0156172011-06-26 17:55:44 -07001227 builder.append("; Scrollable: " + record.isScrollable());
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001228 builder.append("; BeforeText: " + record.mBeforeText);
1229 builder.append("; FromIndex: " + record.mFromIndex);
Svetoslav Ganova0156172011-06-26 17:55:44 -07001230 builder.append("; ToIndex: " + record.mToIndex);
1231 builder.append("; ScrollX: " + record.mScrollX);
1232 builder.append("; ScrollY: " + record.mScrollY);
Svetoslav Ganov8643aa02011-04-20 12:12:33 -07001233 builder.append("; AddedCount: " + record.mAddedCount);
1234 builder.append("; RemovedCount: " + record.mRemovedCount);
1235 builder.append("; ParcelableData: " + record.mParcelableData);
1236 builder.append(" ]");
1237 builder.append("\n");
1238 }
1239 } else {
Svetoslav Ganove4aa13b2011-07-31 20:43:45 -07001240 builder.append("; recordCount: ").append(getRecordCount());
Svetoslav Ganov736c2752011-04-22 18:30:36 -07001241 }
svetoslavganov75986cf2009-05-14 22:28:01 -07001242 return builder.toString();
1243 }
1244
1245 /**
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001246 * Returns the string representation of an event type. For example,
1247 * {@link #TYPE_VIEW_CLICKED} is represented by the string TYPE_VIEW_CLICKED.
1248 *
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001249 * @param eventType The event type
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001250 * @return The string representation.
1251 */
Svetoslav Ganov38e8b4e2011-06-29 20:00:53 -07001252 public static String eventTypeToString(int eventType) {
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001253 if (eventType == TYPES_ALL_MASK) {
1254 return "TYPES_ALL_MASK";
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001255 }
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001256 StringBuilder builder = new StringBuilder();
1257 int eventTypeCount = 0;
1258 while (eventType != 0) {
1259 final int eventTypeFlag = 1 << Integer.numberOfTrailingZeros(eventType);
1260 eventType &= ~eventTypeFlag;
Eugene Susla3b867072017-05-16 13:40:31 -07001261
1262 if (eventTypeCount > 0) {
1263 builder.append(", ");
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001264 }
Eugene Susla3b867072017-05-16 13:40:31 -07001265 builder.append(singleEventTypeToString(eventTypeFlag));
1266
1267 eventTypeCount++;
Svetoslav Ganov6ce77cd2012-11-21 16:35:57 -08001268 }
1269 if (eventTypeCount > 1) {
1270 builder.insert(0, '[');
1271 builder.append(']');
1272 }
1273 return builder.toString();
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001274 }
1275
Eugene Susla3b867072017-05-16 13:40:31 -07001276 private static String singleEventTypeToString(int eventType) {
1277 switch (eventType) {
1278 case TYPE_VIEW_CLICKED: return "TYPE_VIEW_CLICKED";
1279 case TYPE_VIEW_LONG_CLICKED: return "TYPE_VIEW_LONG_CLICKED";
1280 case TYPE_VIEW_SELECTED: return "TYPE_VIEW_SELECTED";
1281 case TYPE_VIEW_FOCUSED: return "TYPE_VIEW_FOCUSED";
1282 case TYPE_VIEW_TEXT_CHANGED: return "TYPE_VIEW_TEXT_CHANGED";
1283 case TYPE_WINDOW_STATE_CHANGED: return "TYPE_WINDOW_STATE_CHANGED";
1284 case TYPE_VIEW_HOVER_ENTER: return "TYPE_VIEW_HOVER_ENTER";
1285 case TYPE_VIEW_HOVER_EXIT: return "TYPE_VIEW_HOVER_EXIT";
1286 case TYPE_NOTIFICATION_STATE_CHANGED: return "TYPE_NOTIFICATION_STATE_CHANGED";
1287 case TYPE_TOUCH_EXPLORATION_GESTURE_START: {
1288 return "TYPE_TOUCH_EXPLORATION_GESTURE_START";
1289 }
1290 case TYPE_TOUCH_EXPLORATION_GESTURE_END: return "TYPE_TOUCH_EXPLORATION_GESTURE_END";
1291 case TYPE_WINDOW_CONTENT_CHANGED: return "TYPE_WINDOW_CONTENT_CHANGED";
1292 case TYPE_VIEW_TEXT_SELECTION_CHANGED: return "TYPE_VIEW_TEXT_SELECTION_CHANGED";
1293 case TYPE_VIEW_SCROLLED: return "TYPE_VIEW_SCROLLED";
1294 case TYPE_ANNOUNCEMENT: return "TYPE_ANNOUNCEMENT";
1295 case TYPE_VIEW_ACCESSIBILITY_FOCUSED: return "TYPE_VIEW_ACCESSIBILITY_FOCUSED";
1296 case TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: {
1297 return "TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED";
1298 }
1299 case TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: {
1300 return "TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY";
1301 }
1302 case TYPE_GESTURE_DETECTION_START: return "TYPE_GESTURE_DETECTION_START";
1303 case TYPE_GESTURE_DETECTION_END: return "TYPE_GESTURE_DETECTION_END";
1304 case TYPE_TOUCH_INTERACTION_START: return "TYPE_TOUCH_INTERACTION_START";
1305 case TYPE_TOUCH_INTERACTION_END: return "TYPE_TOUCH_INTERACTION_END";
1306 case TYPE_WINDOWS_CHANGED: return "TYPE_WINDOWS_CHANGED";
1307 case TYPE_VIEW_CONTEXT_CLICKED: return "TYPE_VIEW_CONTEXT_CLICKED";
1308 case TYPE_ASSIST_READING_CONTEXT: return "TYPE_ASSIST_READING_CONTEXT";
1309 default: return Integer.toHexString(eventType);
1310 }
1311 }
1312
Svetoslav Ganovcc4053e2011-05-23 13:37:44 -07001313 /**
svetoslavganov75986cf2009-05-14 22:28:01 -07001314 * @see Parcelable.Creator
1315 */
1316 public static final Parcelable.Creator<AccessibilityEvent> CREATOR =
1317 new Parcelable.Creator<AccessibilityEvent>() {
1318 public AccessibilityEvent createFromParcel(Parcel parcel) {
1319 AccessibilityEvent event = AccessibilityEvent.obtain();
1320 event.initFromParcel(parcel);
1321 return event;
1322 }
1323
1324 public AccessibilityEvent[] newArray(int size) {
1325 return new AccessibilityEvent[size];
1326 }
1327 };
1328}