• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package android.support.v4.view.accessibility;
18 
19 import android.graphics.Rect;
20 import android.os.Build;
21 import android.os.Bundle;
22 import android.view.View;
23 
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 
28 /**
29  * Helper for accessing {@link android.view.accessibility.AccessibilityNodeInfo}
30  * introduced after API level 4 in a backwards compatible fashion.
31  */
32 public class AccessibilityNodeInfoCompat {
33 
34     static interface AccessibilityNodeInfoImpl {
obtain()35         public Object obtain();
obtain(View source)36         public Object obtain(View source);
obtain(Object info)37         public Object obtain(Object info);
obtain(View root, int virtualDescendantId)38         public Object obtain(View root, int virtualDescendantId);
setSource(Object info, View source)39         public void setSource(Object info, View source);
setSource(Object info, View root, int virtualDescendantId)40         public void setSource(Object info, View root, int virtualDescendantId);
findFocus(Object info, int focus)41         public Object findFocus(Object info, int focus);
focusSearch(Object info, int direction)42         public Object focusSearch(Object info, int direction);
getWindowId(Object info)43         public int getWindowId(Object info);
getChildCount(Object info)44         public int getChildCount(Object info);
getChild(Object info, int index)45         public Object getChild(Object info, int index);
addChild(Object info, View child)46         public void addChild(Object info, View child);
addChild(Object info, View child, int virtualDescendantId)47         public void addChild(Object info, View child, int virtualDescendantId);
getActions(Object info)48         public int getActions(Object info);
addAction(Object info, int action)49         public void addAction(Object info, int action);
performAction(Object info, int action)50         public boolean performAction(Object info, int action);
performAction(Object info, int action, Bundle arguments)51         public boolean performAction(Object info, int action, Bundle arguments);
setMovementGranularities(Object info, int granularities)52         public void setMovementGranularities(Object info, int granularities);
getMovementGranularities(Object info)53         public int getMovementGranularities(Object info);
findAccessibilityNodeInfosByText(Object info, String text)54         public List<Object> findAccessibilityNodeInfosByText(Object info, String text);
getParent(Object info)55         public Object getParent(Object info);
setParent(Object info, View root, int virtualDescendantId)56         public void setParent(Object info, View root, int virtualDescendantId);
setParent(Object info, View parent)57         public void setParent(Object info, View parent);
getBoundsInParent(Object info, Rect outBounds)58         public void getBoundsInParent(Object info, Rect outBounds);
setBoundsInParent(Object info, Rect bounds)59         public void setBoundsInParent(Object info, Rect bounds);
getBoundsInScreen(Object info, Rect outBounds)60         public void getBoundsInScreen(Object info, Rect outBounds);
setBoundsInScreen(Object info, Rect bounds)61         public void setBoundsInScreen(Object info, Rect bounds);
isCheckable(Object info)62         public boolean isCheckable(Object info);
setCheckable(Object info, boolean checkable)63         public void setCheckable(Object info, boolean checkable);
isChecked(Object info)64         public boolean isChecked(Object info);
setChecked(Object info, boolean checked)65         public void setChecked(Object info, boolean checked);
isFocusable(Object info)66         public boolean isFocusable(Object info);
setFocusable(Object info, boolean focusable)67         public void setFocusable(Object info, boolean focusable);
isFocused(Object info)68         public boolean isFocused(Object info);
setFocused(Object info, boolean focused)69         public void setFocused(Object info, boolean focused);
isVisibleToUser(Object info)70         public boolean isVisibleToUser(Object info);
setVisibleToUser(Object info, boolean visibleToUser)71         public void setVisibleToUser(Object info, boolean visibleToUser);
isAccessibilityFocused(Object info)72         public boolean isAccessibilityFocused(Object info);
setAccessibilityFocused(Object info, boolean focused)73         public void setAccessibilityFocused(Object info, boolean focused);
isSelected(Object info)74         public boolean isSelected(Object info);
setSelected(Object info, boolean selected)75         public void setSelected(Object info, boolean selected);
isClickable(Object info)76         public boolean isClickable(Object info);
setClickable(Object info, boolean clickable)77         public void setClickable(Object info, boolean clickable);
isLongClickable(Object info)78         public boolean isLongClickable(Object info);
setLongClickable(Object info, boolean longClickable)79         public void setLongClickable(Object info, boolean longClickable);
isEnabled(Object info)80         public boolean isEnabled(Object info);
setEnabled(Object info, boolean enabled)81         public void setEnabled(Object info, boolean enabled);
isPassword(Object info)82         public boolean isPassword(Object info);
setPassword(Object info, boolean password)83         public void setPassword(Object info, boolean password);
isScrollable(Object info)84         public boolean isScrollable(Object info);
setScrollable(Object info, boolean scrollable)85         public void setScrollable(Object info, boolean scrollable);
getPackageName(Object info)86         public CharSequence getPackageName(Object info);
setPackageName(Object info, CharSequence packageName)87         public void setPackageName(Object info, CharSequence packageName);
getClassName(Object info)88         public CharSequence getClassName(Object info);
setClassName(Object info, CharSequence className)89         public void setClassName(Object info, CharSequence className);
getText(Object info)90         public CharSequence getText(Object info);
setText(Object info, CharSequence text)91         public void setText(Object info, CharSequence text);
getContentDescription(Object info)92         public CharSequence getContentDescription(Object info);
setContentDescription(Object info, CharSequence contentDescription)93         public void setContentDescription(Object info, CharSequence contentDescription);
recycle(Object info)94         public void recycle(Object info);
95     }
96 
97     static class AccessibilityNodeInfoStubImpl implements AccessibilityNodeInfoImpl {
98         @Override
obtain()99         public Object obtain() {
100             return null;
101         }
102 
103         @Override
obtain(View source)104         public Object obtain(View source) {
105             return null;
106         }
107 
108         @Override
obtain(View root, int virtualDescendantId)109         public Object obtain(View root, int virtualDescendantId) {
110             return null;
111         }
112 
113         @Override
obtain(Object info)114         public Object obtain(Object info) {
115             return null;
116         }
117 
118         @Override
addAction(Object info, int action)119         public void addAction(Object info, int action) {
120 
121         }
122 
123         @Override
addChild(Object info, View child)124         public void addChild(Object info, View child) {
125 
126         }
127 
128         @Override
addChild(Object info, View child, int virtualDescendantId)129         public void addChild(Object info, View child, int virtualDescendantId) {
130 
131         }
132 
133         @Override
findAccessibilityNodeInfosByText(Object info, String text)134         public List<Object> findAccessibilityNodeInfosByText(Object info, String text) {
135             return Collections.emptyList();
136         }
137 
138         @Override
getActions(Object info)139         public int getActions(Object info) {
140             return 0;
141         }
142 
143         @Override
getBoundsInParent(Object info, Rect outBounds)144         public void getBoundsInParent(Object info, Rect outBounds) {
145 
146         }
147 
148         @Override
getBoundsInScreen(Object info, Rect outBounds)149         public void getBoundsInScreen(Object info, Rect outBounds) {
150 
151         }
152 
153         @Override
getChild(Object info, int index)154         public Object getChild(Object info, int index) {
155             return null;
156         }
157 
158         @Override
getChildCount(Object info)159         public int getChildCount(Object info) {
160             return 0;
161         }
162 
163         @Override
getClassName(Object info)164         public CharSequence getClassName(Object info) {
165             return null;
166         }
167 
168         @Override
getContentDescription(Object info)169         public CharSequence getContentDescription(Object info) {
170             return null;
171         }
172 
173         @Override
getPackageName(Object info)174         public CharSequence getPackageName(Object info) {
175             return null;
176         }
177 
178         @Override
getParent(Object info)179         public Object getParent(Object info) {
180             return null;
181         }
182 
183         @Override
getText(Object info)184         public CharSequence getText(Object info) {
185             return null;
186         }
187 
188         @Override
getWindowId(Object info)189         public int getWindowId(Object info) {
190             return 0;
191         }
192 
193         @Override
isCheckable(Object info)194         public boolean isCheckable(Object info) {
195             return false;
196         }
197 
198         @Override
isChecked(Object info)199         public boolean isChecked(Object info) {
200             return false;
201         }
202 
203         @Override
isClickable(Object info)204         public boolean isClickable(Object info) {
205             return false;
206         }
207 
208         @Override
isEnabled(Object info)209         public boolean isEnabled(Object info) {
210             return false;
211         }
212 
213         @Override
isFocusable(Object info)214         public boolean isFocusable(Object info) {
215             return false;
216         }
217 
218         @Override
isFocused(Object info)219         public boolean isFocused(Object info) {
220             return false;
221         }
222 
223         @Override
isVisibleToUser(Object info)224         public boolean isVisibleToUser(Object info) {
225             return false;
226         }
227 
228         @Override
isAccessibilityFocused(Object info)229         public boolean isAccessibilityFocused(Object info) {
230             return false;
231         }
232 
233         @Override
isLongClickable(Object info)234         public boolean isLongClickable(Object info) {
235             return false;
236         }
237 
238         @Override
isPassword(Object info)239         public boolean isPassword(Object info) {
240             return false;
241         }
242 
243         @Override
isScrollable(Object info)244         public boolean isScrollable(Object info) {
245             return false;
246         }
247 
248         @Override
isSelected(Object info)249         public boolean isSelected(Object info) {
250             return false;
251         }
252 
253         @Override
performAction(Object info, int action)254         public boolean performAction(Object info, int action) {
255             return false;
256         }
257 
258         @Override
performAction(Object info, int action, Bundle arguments)259         public boolean performAction(Object info, int action, Bundle arguments) {
260             return false;
261         }
262 
263         @Override
setMovementGranularities(Object info, int granularities)264         public void setMovementGranularities(Object info, int granularities) {
265 
266         }
267 
268         @Override
getMovementGranularities(Object info)269         public int getMovementGranularities(Object info) {
270             return 0;
271         }
272 
273         @Override
setBoundsInParent(Object info, Rect bounds)274         public void setBoundsInParent(Object info, Rect bounds) {
275 
276         }
277 
278         @Override
setBoundsInScreen(Object info, Rect bounds)279         public void setBoundsInScreen(Object info, Rect bounds) {
280 
281         }
282 
283         @Override
setCheckable(Object info, boolean checkable)284         public void setCheckable(Object info, boolean checkable) {
285 
286         }
287 
288         @Override
setChecked(Object info, boolean checked)289         public void setChecked(Object info, boolean checked) {
290 
291         }
292 
293         @Override
setClassName(Object info, CharSequence className)294         public void setClassName(Object info, CharSequence className) {
295 
296         }
297 
298         @Override
setClickable(Object info, boolean clickable)299         public void setClickable(Object info, boolean clickable) {
300 
301         }
302 
303         @Override
setContentDescription(Object info, CharSequence contentDescription)304         public void setContentDescription(Object info, CharSequence contentDescription) {
305 
306         }
307 
308         @Override
setEnabled(Object info, boolean enabled)309         public void setEnabled(Object info, boolean enabled) {
310 
311         }
312 
313         @Override
setFocusable(Object info, boolean focusable)314         public void setFocusable(Object info, boolean focusable) {
315 
316         }
317 
318         @Override
setFocused(Object info, boolean focused)319         public void setFocused(Object info, boolean focused) {
320 
321         }
322 
323         @Override
setVisibleToUser(Object info, boolean visibleToUser)324         public void setVisibleToUser(Object info, boolean visibleToUser) {
325 
326         }
327 
328         @Override
setAccessibilityFocused(Object info, boolean focused)329         public void setAccessibilityFocused(Object info, boolean focused) {
330 
331         }
332 
333         @Override
setLongClickable(Object info, boolean longClickable)334         public void setLongClickable(Object info, boolean longClickable) {
335 
336         }
337 
338         @Override
setPackageName(Object info, CharSequence packageName)339         public void setPackageName(Object info, CharSequence packageName) {
340 
341         }
342 
343         @Override
setParent(Object info, View parent)344         public void setParent(Object info, View parent) {
345 
346         }
347 
348         @Override
setPassword(Object info, boolean password)349         public void setPassword(Object info, boolean password) {
350 
351         }
352 
353         @Override
setScrollable(Object info, boolean scrollable)354         public void setScrollable(Object info, boolean scrollable) {
355 
356         }
357 
358         @Override
setSelected(Object info, boolean selected)359         public void setSelected(Object info, boolean selected) {
360 
361         }
362 
363         @Override
setSource(Object info, View source)364         public void setSource(Object info, View source) {
365 
366         }
367 
368         @Override
setSource(Object info, View root, int virtualDescendantId)369         public void setSource(Object info, View root, int virtualDescendantId) {
370 
371         }
372 
373         @Override
findFocus(Object info, int focus)374         public Object findFocus(Object info, int focus) {
375             return null;
376         }
377 
378         @Override
focusSearch(Object info, int direction)379         public Object focusSearch(Object info, int direction) {
380             return null;
381         }
382 
383         @Override
setText(Object info, CharSequence text)384         public void setText(Object info, CharSequence text) {
385 
386         }
387 
388         @Override
recycle(Object info)389         public void recycle(Object info) {
390 
391         }
392 
393         @Override
setParent(Object info, View root, int virtualDescendantId)394         public void setParent(Object info, View root, int virtualDescendantId) {
395 
396         }
397     }
398 
399     static class AccessibilityNodeInfoIcsImpl extends AccessibilityNodeInfoStubImpl {
400         @Override
obtain()401         public Object obtain() {
402             return AccessibilityNodeInfoCompatIcs.obtain();
403         }
404 
405         @Override
obtain(View source)406         public Object obtain(View source) {
407             return AccessibilityNodeInfoCompatIcs.obtain(source);
408         }
409 
410         @Override
obtain(Object info)411         public Object obtain(Object info) {
412             return AccessibilityNodeInfoCompatIcs.obtain(info);
413         }
414 
415         @Override
addAction(Object info, int action)416         public void addAction(Object info, int action) {
417             AccessibilityNodeInfoCompatIcs.addAction(info, action);
418         }
419 
420         @Override
addChild(Object info, View child)421         public void addChild(Object info, View child) {
422             AccessibilityNodeInfoCompatIcs.addChild(info, child);
423         }
424 
425         @Override
findAccessibilityNodeInfosByText(Object info, String text)426         public List<Object> findAccessibilityNodeInfosByText(Object info, String text) {
427             return AccessibilityNodeInfoCompatIcs.findAccessibilityNodeInfosByText(info, text);
428         }
429 
430         @Override
getActions(Object info)431         public int getActions(Object info) {
432             return AccessibilityNodeInfoCompatIcs.getActions(info);
433         }
434 
435         @Override
getBoundsInParent(Object info, Rect outBounds)436         public void getBoundsInParent(Object info, Rect outBounds) {
437             AccessibilityNodeInfoCompatIcs.getBoundsInParent(info, outBounds);
438         }
439 
440         @Override
getBoundsInScreen(Object info, Rect outBounds)441         public void getBoundsInScreen(Object info, Rect outBounds) {
442             AccessibilityNodeInfoCompatIcs.getBoundsInScreen(info, outBounds);
443         }
444 
445         @Override
getChild(Object info, int index)446         public Object getChild(Object info, int index) {
447             return AccessibilityNodeInfoCompatIcs.getChild(info, index);
448         }
449 
450         @Override
getChildCount(Object info)451         public int getChildCount(Object info) {
452             return AccessibilityNodeInfoCompatIcs.getChildCount(info);
453         }
454 
455         @Override
getClassName(Object info)456         public CharSequence getClassName(Object info) {
457             return AccessibilityNodeInfoCompatIcs.getClassName(info);
458         }
459 
460         @Override
getContentDescription(Object info)461         public CharSequence getContentDescription(Object info) {
462             return AccessibilityNodeInfoCompatIcs.getContentDescription(info);
463         }
464 
465         @Override
getPackageName(Object info)466         public CharSequence getPackageName(Object info) {
467             return AccessibilityNodeInfoCompatIcs.getPackageName(info);
468         }
469 
470         @Override
getParent(Object info)471         public Object getParent(Object info) {
472             return AccessibilityNodeInfoCompatIcs.getParent(info);
473         }
474 
475         @Override
getText(Object info)476         public CharSequence getText(Object info) {
477             return AccessibilityNodeInfoCompatIcs.getText(info);
478         }
479 
480         @Override
getWindowId(Object info)481         public int getWindowId(Object info) {
482             return AccessibilityNodeInfoCompatIcs.getWindowId(info);
483         }
484 
485         @Override
isCheckable(Object info)486         public boolean isCheckable(Object info) {
487             return AccessibilityNodeInfoCompatIcs.isCheckable(info);
488         }
489 
490         @Override
isChecked(Object info)491         public boolean isChecked(Object info) {
492             return AccessibilityNodeInfoCompatIcs.isChecked(info);
493         }
494 
495         @Override
isClickable(Object info)496         public boolean isClickable(Object info) {
497             return AccessibilityNodeInfoCompatIcs.isClickable(info);
498         }
499 
500         @Override
isEnabled(Object info)501         public boolean isEnabled(Object info) {
502             return AccessibilityNodeInfoCompatIcs.isEnabled(info);
503         }
504 
505         @Override
isFocusable(Object info)506         public boolean isFocusable(Object info) {
507             return AccessibilityNodeInfoCompatIcs.isFocusable(info);
508         }
509 
510         @Override
isFocused(Object info)511         public boolean isFocused(Object info) {
512             return AccessibilityNodeInfoCompatIcs.isFocused(info);
513         }
514 
515         @Override
isLongClickable(Object info)516         public boolean isLongClickable(Object info) {
517             return AccessibilityNodeInfoCompatIcs.isLongClickable(info);
518         }
519 
520         @Override
isPassword(Object info)521         public boolean isPassword(Object info) {
522             return AccessibilityNodeInfoCompatIcs.isPassword(info);
523         }
524 
525         @Override
isScrollable(Object info)526         public boolean isScrollable(Object info) {
527             return AccessibilityNodeInfoCompatIcs.isScrollable(info);
528         }
529 
530         @Override
isSelected(Object info)531         public boolean isSelected(Object info) {
532             return AccessibilityNodeInfoCompatIcs.isSelected(info);
533         }
534 
535         @Override
performAction(Object info, int action)536         public boolean performAction(Object info, int action) {
537             return AccessibilityNodeInfoCompatIcs.performAction(info, action);
538         }
539 
540         @Override
setBoundsInParent(Object info, Rect bounds)541         public void setBoundsInParent(Object info, Rect bounds) {
542             AccessibilityNodeInfoCompatIcs.setBoundsInParent(info, bounds);
543         }
544 
545         @Override
setBoundsInScreen(Object info, Rect bounds)546         public void setBoundsInScreen(Object info, Rect bounds) {
547             AccessibilityNodeInfoCompatIcs.setBoundsInScreen(info, bounds);
548         }
549 
550         @Override
setCheckable(Object info, boolean checkable)551         public void setCheckable(Object info, boolean checkable) {
552             AccessibilityNodeInfoCompatIcs.setCheckable(info, checkable);
553         }
554 
555         @Override
setChecked(Object info, boolean checked)556         public void setChecked(Object info, boolean checked) {
557             AccessibilityNodeInfoCompatIcs.setChecked(info, checked);
558         }
559 
560         @Override
setClassName(Object info, CharSequence className)561         public void setClassName(Object info, CharSequence className) {
562             AccessibilityNodeInfoCompatIcs.setClassName(info, className);
563         }
564 
565         @Override
setClickable(Object info, boolean clickable)566         public void setClickable(Object info, boolean clickable) {
567             AccessibilityNodeInfoCompatIcs.setClickable(info, clickable);
568         }
569 
570         @Override
setContentDescription(Object info, CharSequence contentDescription)571         public void setContentDescription(Object info, CharSequence contentDescription) {
572             AccessibilityNodeInfoCompatIcs.setContentDescription(info, contentDescription);
573         }
574 
575         @Override
setEnabled(Object info, boolean enabled)576         public void setEnabled(Object info, boolean enabled) {
577             AccessibilityNodeInfoCompatIcs.setEnabled(info, enabled);
578         }
579 
580         @Override
setFocusable(Object info, boolean focusable)581         public void setFocusable(Object info, boolean focusable) {
582             AccessibilityNodeInfoCompatIcs.setFocusable(info, focusable);
583         }
584 
585         @Override
setFocused(Object info, boolean focused)586         public void setFocused(Object info, boolean focused) {
587             AccessibilityNodeInfoCompatIcs.setFocused(info, focused);
588         }
589 
590         @Override
setLongClickable(Object info, boolean longClickable)591         public void setLongClickable(Object info, boolean longClickable) {
592             AccessibilityNodeInfoCompatIcs.setLongClickable(info, longClickable);
593         }
594 
595         @Override
setPackageName(Object info, CharSequence packageName)596         public void setPackageName(Object info, CharSequence packageName) {
597             AccessibilityNodeInfoCompatIcs.setPackageName(info, packageName);
598         }
599 
600         @Override
setParent(Object info, View parent)601         public void setParent(Object info, View parent) {
602             AccessibilityNodeInfoCompatIcs.setParent(info, parent);
603         }
604 
605         @Override
setPassword(Object info, boolean password)606         public void setPassword(Object info, boolean password) {
607             AccessibilityNodeInfoCompatIcs.setPassword(info, password);
608         }
609 
610         @Override
setScrollable(Object info, boolean scrollable)611         public void setScrollable(Object info, boolean scrollable) {
612             AccessibilityNodeInfoCompatIcs.setScrollable(info, scrollable);
613         }
614 
615         @Override
setSelected(Object info, boolean selected)616         public void setSelected(Object info, boolean selected) {
617             AccessibilityNodeInfoCompatIcs.setSelected(info, selected);
618         }
619 
620         @Override
setSource(Object info, View source)621         public void setSource(Object info, View source) {
622             AccessibilityNodeInfoCompatIcs.setSource(info, source);
623         }
624 
625         @Override
setText(Object info, CharSequence text)626         public void setText(Object info, CharSequence text) {
627             AccessibilityNodeInfoCompatIcs.setText(info, text);
628         }
629 
630         @Override
recycle(Object info)631         public void recycle(Object info) {
632             AccessibilityNodeInfoCompatIcs.recycle(info);
633         }
634     }
635 
636     static class AccessibilityNodeInfoJellybeanImpl extends AccessibilityNodeInfoIcsImpl {
637         @Override
obtain(View root, int virtualDescendantId)638         public Object obtain(View root, int virtualDescendantId) {
639             return AccessibilityNodeInfoCompatJellyBean.obtain(root, virtualDescendantId);
640         }
641 
642         @Override
findFocus(Object info, int focus)643         public Object findFocus(Object info, int focus) {
644             return AccessibilityNodeInfoCompatJellyBean.findFocus(info, focus);
645         }
646 
647         @Override
focusSearch(Object info, int direction)648         public Object focusSearch(Object info, int direction) {
649             return AccessibilityNodeInfoCompatJellyBean.focusSearch(info, direction);
650         }
651 
652         @Override
addChild(Object info, View child, int virtualDescendantId)653         public void addChild(Object info, View child, int virtualDescendantId) {
654             AccessibilityNodeInfoCompatJellyBean.addChild(info, child, virtualDescendantId);
655         }
656 
657         @Override
setSource(Object info, View root, int virtualDescendantId)658         public void setSource(Object info, View root, int virtualDescendantId) {
659             AccessibilityNodeInfoCompatJellyBean.setSource(info, root, virtualDescendantId);
660         }
661 
662         @Override
isVisibleToUser(Object info)663         public boolean isVisibleToUser(Object info) {
664             return AccessibilityNodeInfoCompatJellyBean.isVisibleToUser(info);
665         }
666 
667         @Override
setVisibleToUser(Object info, boolean visibleToUser)668         public void setVisibleToUser(Object info, boolean visibleToUser) {
669             AccessibilityNodeInfoCompatJellyBean.setVisibleToUser(info, visibleToUser);
670         }
671 
672         @Override
isAccessibilityFocused(Object info)673         public boolean isAccessibilityFocused(Object info) {
674             return AccessibilityNodeInfoCompatJellyBean.isAccessibilityFocused(info);
675         }
676 
677         @Override
setAccessibilityFocused(Object info, boolean focused)678         public void setAccessibilityFocused(Object info, boolean focused) {
679             AccessibilityNodeInfoCompatJellyBean.setAccesibilityFocused(info, focused);
680         }
681 
682         @Override
performAction(Object info, int action, Bundle arguments)683         public boolean performAction(Object info, int action, Bundle arguments) {
684             return AccessibilityNodeInfoCompatJellyBean.performAction(info, action, arguments);
685         }
686 
687         @Override
setMovementGranularities(Object info, int granularities)688         public void setMovementGranularities(Object info, int granularities) {
689             AccessibilityNodeInfoCompatJellyBean.setMovementGranularities(info, granularities);
690         }
691 
692         @Override
getMovementGranularities(Object info)693         public int getMovementGranularities(Object info) {
694             return AccessibilityNodeInfoCompatJellyBean.getMovementGranularities(info);
695         }
696 
697         @Override
setParent(Object info, View root, int virtualDescendantId)698         public void setParent(Object info, View root, int virtualDescendantId) {
699             AccessibilityNodeInfoCompatJellyBean.setParent(info, root, virtualDescendantId);
700         }
701     }
702 
703     static {
704         if (Build.VERSION.SDK_INT >= 16) { // JellyBean
705             IMPL = new AccessibilityNodeInfoJellybeanImpl();
706         } else if (Build.VERSION.SDK_INT >= 14) { // ICS
707             IMPL = new AccessibilityNodeInfoIcsImpl();
708         } else {
709             IMPL = new AccessibilityNodeInfoStubImpl();
710         }
711     }
712 
713     private static final AccessibilityNodeInfoImpl IMPL;
714 
715     private final Object mInfo;
716 
717     // Actions.
718 
719     /**
720      * Action that focuses the node.
721      */
722     public static final int ACTION_FOCUS = 0x00000001;
723 
724     /**
725      * Action that unfocuses the node.
726      */
727     public static final int ACTION_CLEAR_FOCUS = 0x00000002;
728 
729     /**
730      * Action that selects the node.
731      */
732     public static final int ACTION_SELECT = 0x00000004;
733 
734     /**
735      * Action that unselects the node.
736      */
737     public static final int ACTION_CLEAR_SELECTION = 0x00000008;
738 
739     /**
740      * Action that clicks on the node info.
741      */
742     public static final int ACTION_CLICK = 0x00000010;
743 
744     /**
745      * Action that long clicks on the node.
746      */
747     public static final int ACTION_LONG_CLICK = 0x00000020;
748 
749     /**
750      * Action that gives accessibility focus to the node.
751      */
752     public static final int ACTION_ACCESSIBILITY_FOCUS = 0x00000040;
753 
754     /**
755      * Action that clears accessibility focus of the node.
756      */
757     public static final int ACTION_CLEAR_ACCESSIBILITY_FOCUS = 0x00000080;
758 
759     /**
760      * Action that requests to go to the next entity in this node's text
761      * at a given movement granularity. For example, move to the next character,
762      * word, etc.
763      * <p>
764      * <strong>Arguments:</strong> {@link #ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT}<br>
765      * <strong>Example:</strong>
766      * <code><pre><p>
767      *   Bundle arguments = new Bundle();
768      *   arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
769      *           AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
770      *   info.performAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, arguments);
771      * </code></pre></p>
772      * </p>
773      *
774      * @see #setMovementGranularities(int)
775      * @see #getMovementGranularities()
776      *
777      * @see #MOVEMENT_GRANULARITY_CHARACTER
778      * @see #MOVEMENT_GRANULARITY_WORD
779      * @see #MOVEMENT_GRANULARITY_LINE
780      * @see #MOVEMENT_GRANULARITY_PARAGRAPH
781      * @see #MOVEMENT_GRANULARITY_PAGE
782      */
783     public static final int ACTION_NEXT_AT_MOVEMENT_GRANULARITY = 0x00000100;
784 
785     /**
786      * Action that requests to go to the previous entity in this node's text
787      * at a given movement granularity. For example, move to the next character,
788      * word, etc.
789      * <p>
790      * <strong>Arguments:</strong> {@link #ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT}<br>
791      * <strong>Example:</strong>
792      * <code><pre><p>
793      *   Bundle arguments = new Bundle();
794      *   arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
795      *           AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
796      *   info.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
797      *           arguments);
798      * </code></pre></p>
799      * </p>
800      *
801      * @see #setMovementGranularities(int)
802      * @see #getMovementGranularities()
803      *
804      * @see #MOVEMENT_GRANULARITY_CHARACTER
805      * @see #MOVEMENT_GRANULARITY_WORD
806      * @see #MOVEMENT_GRANULARITY_LINE
807      * @see #MOVEMENT_GRANULARITY_PARAGRAPH
808      * @see #MOVEMENT_GRANULARITY_PAGE
809      */
810     public static final int ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY = 0x00000200;
811 
812     /**
813      * Action to move to the next HTML element of a given type. For example, move
814      * to the BUTTON, INPUT, TABLE, etc.
815      * <p>
816      * <strong>Arguments:</strong> {@link #ACTION_ARGUMENT_HTML_ELEMENT_STRING}<br>
817      * <strong>Example:</strong>
818      * <code><pre><p>
819      *   Bundle arguments = new Bundle();
820      *   arguments.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING, "BUTTON");
821      *   info.performAction(AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT, arguments);
822      * </code></pre></p>
823      * </p>
824      */
825     public static final int ACTION_NEXT_HTML_ELEMENT = 0x00000400;
826 
827     /**
828      * Action to move to the previous HTML element of a given type. For example, move
829      * to the BUTTON, INPUT, TABLE, etc.
830      * <p>
831      * <strong>Arguments:</strong> {@link #ACTION_ARGUMENT_HTML_ELEMENT_STRING}<br>
832      * <strong>Example:</strong>
833      * <code><pre><p>
834      *   Bundle arguments = new Bundle();
835      *   arguments.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING, "BUTTON");
836      *   info.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT, arguments);
837      * </code></pre></p>
838      * </p>
839      */
840     public static final int ACTION_PREVIOUS_HTML_ELEMENT = 0x00000800;
841 
842     /**
843      * Action to scroll the node content forward.
844      */
845     public static final int ACTION_SCROLL_FORWARD = 0x00001000;
846 
847     /**
848      * Action to scroll the node content backward.
849      */
850     public static final int ACTION_SCROLL_BACKWARD = 0x00002000;
851 
852     /**
853      * Argument for which movement granularity to be used when traversing the node text.
854      * <p>
855      * <strong>Type:</strong> int<br>
856      * <strong>Actions:</strong> {@link #ACTION_NEXT_AT_MOVEMENT_GRANULARITY},
857      * {@link #ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY}
858      * </p>
859      */
860     public static final String ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT =
861         "ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT";
862 
863     /**
864      * Argument for which HTML element to get moving to the next/previous HTML element.
865      * <p>
866      * <strong>Type:</strong> String<br>
867      * <strong>Actions:</strong> {@link #ACTION_NEXT_HTML_ELEMENT},
868      *         {@link #ACTION_PREVIOUS_HTML_ELEMENT}
869      * </p>
870      */
871     public static final String ACTION_ARGUMENT_HTML_ELEMENT_STRING =
872         "ACTION_ARGUMENT_HTML_ELEMENT_STRING";
873 
874     /**
875      * The input focus.
876      */
877     public static final int FOCUS_INPUT = 1;
878 
879     /**
880      * The accessibility focus.
881      */
882     public static final int FOCUS_ACCESSIBILITY = 2;
883 
884     // Movement granularities
885 
886     /**
887      * Movement granularity bit for traversing the text of a node by character.
888      */
889     public static final int MOVEMENT_GRANULARITY_CHARACTER = 0x00000001;
890 
891     /**
892      * Movement granularity bit for traversing the text of a node by word.
893      */
894     public static final int MOVEMENT_GRANULARITY_WORD = 0x00000002;
895 
896     /**
897      * Movement granularity bit for traversing the text of a node by line.
898      */
899     public static final int MOVEMENT_GRANULARITY_LINE = 0x00000004;
900 
901     /**
902      * Movement granularity bit for traversing the text of a node by paragraph.
903      */
904     public static final int MOVEMENT_GRANULARITY_PARAGRAPH = 0x00000008;
905 
906     /**
907      * Movement granularity bit for traversing the text of a node by page.
908      */
909     public static final int MOVEMENT_GRANULARITY_PAGE = 0x00000010;
910 
911     /**
912      * Creates a wrapper for info implementation.
913      *
914      * @param object The info to wrap.
915      * @return A wrapper for if the object is not null, null otherwise.
916      */
wrapNonNullInstance(Object object)917     static AccessibilityNodeInfoCompat wrapNonNullInstance(Object object) {
918         if (object != null) {
919             return new AccessibilityNodeInfoCompat(object);
920         }
921         return null;
922     }
923 
924     /**
925      * Creates a new instance wrapping an
926      * {@link android.view.accessibility.AccessibilityNodeInfo}.
927      *
928      * @param info The info.
929      */
AccessibilityNodeInfoCompat(Object info)930     public AccessibilityNodeInfoCompat(Object info) {
931         mInfo = info;
932     }
933 
934     /**
935      * @return The wrapped {@link android.view.accessibility.AccessibilityNodeInfo}.
936      */
getInfo()937     public Object getInfo() {
938         return mInfo;
939     }
940 
941     /**
942      * Returns a cached instance if such is available otherwise a new one and
943      * sets the source.
944      *
945      * @return An instance.
946      * @see #setSource(View)
947      */
obtain(View source)948     public static AccessibilityNodeInfoCompat obtain(View source) {
949         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.obtain(source));
950     }
951 
952     /**
953      * Returns a cached instance if such is available otherwise a new one
954      * and sets the source.
955      *
956      * @param root The root of the virtual subtree.
957      * @param virtualDescendantId The id of the virtual descendant.
958      * @return An instance.
959      *
960      * @see #setSource(View, int)
961      */
obtain(View root, int virtualDescendantId)962     public static AccessibilityNodeInfoCompat obtain(View root, int virtualDescendantId) {
963         return AccessibilityNodeInfoCompat.wrapNonNullInstance(
964                 IMPL.obtain(root, virtualDescendantId));
965     }
966 
967     /**
968      * Returns a cached instance if such is available otherwise a new one.
969      *
970      * @return An instance.
971      */
obtain()972     public static AccessibilityNodeInfoCompat obtain() {
973         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.obtain());
974     }
975 
976     /**
977      * Returns a cached instance if such is available or a new one is create.
978      * The returned instance is initialized from the given <code>info</code>.
979      *
980      * @param info The other info.
981      * @return An instance.
982      */
obtain(AccessibilityNodeInfoCompat info)983     public static AccessibilityNodeInfoCompat obtain(AccessibilityNodeInfoCompat info) {
984         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.obtain(info.mInfo));
985     }
986 
987     /**
988      * Sets the source.
989      *
990      * @param source The info source.
991      */
setSource(View source)992     public void setSource(View source) {
993         IMPL.setSource(mInfo, source);
994     }
995 
996     /**
997      * Sets the source to be a virtual descendant of the given <code>root</code>.
998      * If <code>virtualDescendantId</code> is {@link View#NO_ID} the root
999      * is set as the source.
1000      * <p>
1001      * A virtual descendant is an imaginary View that is reported as a part of the view
1002      * hierarchy for accessibility purposes. This enables custom views that draw complex
1003      * content to report themselves as a tree of virtual views, thus conveying their
1004      * logical structure.
1005      * </p>
1006      * <p>
1007      *   <strong>Note:</strong> Cannot be called from an
1008      *   {@link android.accessibilityservice.AccessibilityService}.
1009      *   This class is made immutable before being delivered to an AccessibilityService.
1010      * </p>
1011      *
1012      * @param root The root of the virtual subtree.
1013      * @param virtualDescendantId The id of the virtual descendant.
1014      */
setSource(View root, int virtualDescendantId)1015     public void setSource(View root, int virtualDescendantId) {
1016         IMPL.setSource(mInfo, root, virtualDescendantId);
1017     }
1018 
1019     /**
1020      * Find the view that has the specified focus type. The search starts from
1021      * the view represented by this node info.
1022      *
1023      * @param focus The focus to find. One of {@link #FOCUS_INPUT} or
1024      *         {@link #FOCUS_ACCESSIBILITY}.
1025      * @return The node info of the focused view or null.
1026      *
1027      * @see #FOCUS_INPUT
1028      * @see #FOCUS_ACCESSIBILITY
1029      */
findFocus(int focus)1030     public AccessibilityNodeInfoCompat findFocus(int focus) {
1031         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.findFocus(mInfo, focus));
1032     }
1033 
1034     /**
1035      * Searches for the nearest view in the specified direction that can take
1036      * input focus.
1037      *
1038      * @param direction The direction. Can be one of:
1039      *     {@link View#FOCUS_DOWN},
1040      *     {@link View#FOCUS_UP},
1041      *     {@link View#FOCUS_LEFT},
1042      *     {@link View#FOCUS_RIGHT},
1043      *     {@link View#FOCUS_FORWARD},
1044      *     {@link View#FOCUS_BACKWARD}.
1045      *
1046      * @return The node info for the view that can take accessibility focus.
1047      */
focusSearch(int direction)1048     public AccessibilityNodeInfoCompat focusSearch(int direction) {
1049         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.focusSearch(mInfo, direction));
1050     }
1051 
1052     /**
1053      * Gets the id of the window from which the info comes from.
1054      *
1055      * @return The window id.
1056      */
getWindowId()1057     public int getWindowId() {
1058         return IMPL.getWindowId(mInfo);
1059     }
1060 
1061     /**
1062      * Gets the number of children.
1063      *
1064      * @return The child count.
1065      */
getChildCount()1066     public int getChildCount() {
1067         return IMPL.getChildCount(mInfo);
1068     }
1069 
1070     /**
1071      * Get the child at given index.
1072      * <p>
1073      * <strong>Note:</strong> It is a client responsibility to recycle the
1074      * received info by calling {@link AccessibilityNodeInfoCompat#recycle()} to
1075      * avoid creating of multiple instances.
1076      * </p>
1077      *
1078      * @param index The child index.
1079      * @return The child node.
1080      * @throws IllegalStateException If called outside of an
1081      *             AccessibilityService.
1082      */
getChild(int index)1083     public AccessibilityNodeInfoCompat getChild(int index) {
1084         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.getChild(mInfo, index));
1085     }
1086 
1087     /**
1088      * Adds a child.
1089      * <p>
1090      * <strong>Note:</strong> Cannot be called from an
1091      * {@link android.accessibilityservice.AccessibilityService}. This class is
1092      * made immutable before being delivered to an AccessibilityService.
1093      * </p>
1094      *
1095      * @param child The child.
1096      * @throws IllegalStateException If called from an AccessibilityService.
1097      */
addChild(View child)1098     public void addChild(View child) {
1099         IMPL.addChild(mInfo, child);
1100     }
1101 
1102     /**
1103      * Adds a virtual child which is a descendant of the given <code>root</code>.
1104      * If <code>virtualDescendantId</code> is {@link View#NO_ID} the root
1105      * is added as a child.
1106      * <p>
1107      * A virtual descendant is an imaginary View that is reported as a part of the view
1108      * hierarchy for accessibility purposes. This enables custom views that draw complex
1109      * content to report them selves as a tree of virtual views, thus conveying their
1110      * logical structure.
1111      * </p>
1112      *
1113      * @param root The root of the virtual subtree.
1114      * @param virtualDescendantId The id of the virtual child.
1115      */
addChild(View root, int virtualDescendantId)1116     public void addChild(View root, int virtualDescendantId) {
1117         IMPL.addChild(mInfo, root, virtualDescendantId);
1118     }
1119 
1120     /**
1121      * Gets the actions that can be performed on the node.
1122      *
1123      * @return The bit mask of with actions.
1124      * @see android.view.accessibility.AccessibilityNodeInfo#ACTION_FOCUS
1125      * @see android.view.accessibility.AccessibilityNodeInfo#ACTION_CLEAR_FOCUS
1126      * @see android.view.accessibility.AccessibilityNodeInfo#ACTION_SELECT
1127      * @see android.view.accessibility.AccessibilityNodeInfo#ACTION_CLEAR_SELECTION
1128      */
getActions()1129     public int getActions() {
1130         return IMPL.getActions(mInfo);
1131     }
1132 
1133     /**
1134      * Adds an action that can be performed on the node.
1135      * <p>
1136      * <strong>Note:</strong> Cannot be called from an
1137      * {@link android.accessibilityservice.AccessibilityService}. This class is
1138      * made immutable before being delivered to an AccessibilityService.
1139      * </p>
1140      *
1141      * @param action The action.
1142      * @throws IllegalStateException If called from an AccessibilityService.
1143      */
addAction(int action)1144     public void addAction(int action) {
1145         IMPL.addAction(mInfo, action);
1146     }
1147 
1148     /**
1149      * Performs an action on the node.
1150      * <p>
1151      * <strong>Note:</strong> An action can be performed only if the request is
1152      * made from an {@link android.accessibilityservice.AccessibilityService}.
1153      * </p>
1154      *
1155      * @param action The action to perform.
1156      * @return True if the action was performed.
1157      * @throws IllegalStateException If called outside of an
1158      *             AccessibilityService.
1159      */
performAction(int action)1160     public boolean performAction(int action) {
1161         return IMPL.performAction(mInfo, action);
1162     }
1163 
1164     /**
1165      * Performs an action on the node.
1166      * <p>
1167      *   <strong>Note:</strong> An action can be performed only if the request is made
1168      *   from an {@link android.accessibilityservice.AccessibilityService}.
1169      * </p>
1170      *
1171      * @param action The action to perform.
1172      * @param arguments A bundle with additional arguments.
1173      * @return True if the action was performed.
1174      *
1175      * @throws IllegalStateException If called outside of an AccessibilityService.
1176      */
performAction(int action, Bundle arguments)1177     public boolean performAction(int action, Bundle arguments) {
1178         return IMPL.performAction(mInfo, action, arguments);
1179     }
1180 
1181     /**
1182      * Sets the movement granularities for traversing the text of this node.
1183      * <p>
1184      *   <strong>Note:</strong> Cannot be called from an
1185      *   {@link android.accessibilityservice.AccessibilityService}.
1186      *   This class is made immutable before being delivered to an AccessibilityService.
1187      * </p>
1188      *
1189      * @param granularities The bit mask with granularities.
1190      *
1191      * @throws IllegalStateException If called from an AccessibilityService.
1192      */
setMovementGranularities(int granularities)1193     public void setMovementGranularities(int granularities) {
1194         IMPL.setMovementGranularities(mInfo, granularities);
1195     }
1196 
1197     /**
1198      * Gets the movement granularities for traversing the text of this node.
1199      *
1200      * @return The bit mask with granularities.
1201      */
getMovementGranularities()1202     public int getMovementGranularities() {
1203         return IMPL.getMovementGranularities(mInfo);
1204     }
1205 
1206     /**
1207      * Finds {@link android.view.accessibility.AccessibilityNodeInfo}s by text. The match
1208      * is case insensitive containment. The search is relative to this info i.e. this
1209      * info is the root of the traversed tree.
1210      * <p>
1211      * <strong>Note:</strong> It is a client responsibility to recycle the
1212      * received info by calling {@link android.view.accessibility.AccessibilityNodeInfo#recycle()}
1213      * to avoid creating of multiple instances.
1214      * </p>
1215      *
1216      * @param text The searched text.
1217      * @return A list of node info.
1218      */
findAccessibilityNodeInfosByText(String text)1219     public List<AccessibilityNodeInfoCompat> findAccessibilityNodeInfosByText(String text) {
1220         List<AccessibilityNodeInfoCompat> result = new ArrayList<AccessibilityNodeInfoCompat>();
1221         List<Object> infos = IMPL.findAccessibilityNodeInfosByText(mInfo, text);
1222         final int infoCount = infos.size();
1223         for (int i = 0; i < infoCount; i++) {
1224             Object info = infos.get(i);
1225             result.add(new AccessibilityNodeInfoCompat(info));
1226         }
1227         return result;
1228     }
1229 
1230     /**
1231      * Gets the parent.
1232      * <p>
1233      * <strong>Note:</strong> It is a client responsibility to recycle the
1234      * received info by calling {@link android.view.accessibility.AccessibilityNodeInfo#recycle()}
1235      * to avoid creating of multiple instances.
1236      * </p>
1237      *
1238      * @return The parent.
1239      */
getParent()1240     public AccessibilityNodeInfoCompat getParent() {
1241         return AccessibilityNodeInfoCompat.wrapNonNullInstance(IMPL.getParent(mInfo));
1242     }
1243 
1244     /**
1245      * Sets the parent.
1246      * <p>
1247      * <strong>Note:</strong> Cannot be called from an
1248      * {@link android.accessibilityservice.AccessibilityService}. This class is
1249      * made immutable before being delivered to an AccessibilityService.
1250      * </p>
1251      *
1252      * @param parent The parent.
1253      * @throws IllegalStateException If called from an AccessibilityService.
1254      */
setParent(View parent)1255     public void setParent(View parent) {
1256         IMPL.setParent(mInfo, parent);
1257     }
1258 
1259     /**
1260      * Sets the parent to be a virtual descendant of the given <code>root</code>.
1261      * If <code>virtualDescendantId</code> equals to {@link View#NO_ID} the root
1262      * is set as the parent.
1263      * <p>
1264      * A virtual descendant is an imaginary View that is reported as a part of the view
1265      * hierarchy for accessibility purposes. This enables custom views that draw complex
1266      * content to report them selves as a tree of virtual views, thus conveying their
1267      * logical structure.
1268      * </p>
1269      * <p>
1270      *   <strong>Note:</strong> Cannot be called from an
1271      *   {@link android.accessibilityservice.AccessibilityService}.
1272      *   This class is made immutable before being delivered to an AccessibilityService.
1273      * </p>
1274      *
1275      * @param root The root of the virtual subtree.
1276      * @param virtualDescendantId The id of the virtual descendant.
1277      */
setParent(View root, int virtualDescendantId)1278     public void setParent(View root, int virtualDescendantId) {
1279         IMPL.setParent(mInfo, root, virtualDescendantId);
1280     }
1281 
1282     /**
1283      * Gets the node bounds in parent coordinates.
1284      *
1285      * @param outBounds The output node bounds.
1286      */
getBoundsInParent(Rect outBounds)1287     public void getBoundsInParent(Rect outBounds) {
1288         IMPL.getBoundsInParent(mInfo, outBounds);
1289     }
1290 
1291     /**
1292      * Sets the node bounds in parent coordinates.
1293      * <p>
1294      * <strong>Note:</strong> Cannot be called from an
1295      * {@link android.accessibilityservice.AccessibilityService}. This class is
1296      * made immutable before being delivered to an AccessibilityService.
1297      * </p>
1298      *
1299      * @param bounds The node bounds.
1300      *@throws IllegalStateException If called from an AccessibilityService.
1301      */
setBoundsInParent(Rect bounds)1302     public void setBoundsInParent(Rect bounds) {
1303         IMPL.setBoundsInParent(mInfo, bounds);
1304     }
1305 
1306     /**
1307      * Gets the node bounds in screen coordinates.
1308      *
1309      * @param outBounds The output node bounds.
1310      */
getBoundsInScreen(Rect outBounds)1311     public void getBoundsInScreen(Rect outBounds) {
1312         IMPL.getBoundsInScreen(mInfo, outBounds);
1313     }
1314 
1315     /**
1316      * Sets the node bounds in screen coordinates.
1317      * <p>
1318      * <strong>Note:</strong> Cannot be called from an
1319      * {@link android.accessibilityservice.AccessibilityService}. This class is
1320      * made immutable before being delivered to an AccessibilityService.
1321      * </p>
1322      *
1323      * @param bounds The node bounds.
1324      * @throws IllegalStateException If called from an AccessibilityService.
1325      */
setBoundsInScreen(Rect bounds)1326     public void setBoundsInScreen(Rect bounds) {
1327         IMPL.setBoundsInScreen(mInfo, bounds);
1328     }
1329 
1330     /**
1331      * Gets whether this node is checkable.
1332      *
1333      * @return True if the node is checkable.
1334      */
isCheckable()1335     public boolean isCheckable() {
1336         return IMPL.isCheckable(mInfo);
1337     }
1338 
1339     /**
1340      * Sets whether this node is checkable.
1341      * <p>
1342      * <strong>Note:</strong> Cannot be called from an
1343      * {@link android.accessibilityservice.AccessibilityService}. This class is
1344      * made immutable before being delivered to an AccessibilityService.
1345      * </p>
1346      *
1347      * @param checkable True if the node is checkable.
1348      * @throws IllegalStateException If called from an AccessibilityService.
1349      */
setCheckable(boolean checkable)1350     public void setCheckable(boolean checkable) {
1351         IMPL.setCheckable(mInfo, checkable);
1352     }
1353 
1354     /**
1355      * Gets whether this node is checked.
1356      *
1357      * @return True if the node is checked.
1358      */
isChecked()1359     public boolean isChecked() {
1360         return IMPL.isChecked(mInfo);
1361     }
1362 
1363     /**
1364      * Sets whether this node is checked.
1365      * <p>
1366      * <strong>Note:</strong> Cannot be called from an
1367      * {@link android.accessibilityservice.AccessibilityService}. This class is
1368      * made immutable before being delivered to an AccessibilityService.
1369      * </p>
1370      *
1371      * @param checked True if the node is checked.
1372      * @throws IllegalStateException If called from an AccessibilityService.
1373      */
setChecked(boolean checked)1374     public void setChecked(boolean checked) {
1375         IMPL.setChecked(mInfo, checked);
1376     }
1377 
1378     /**
1379      * Gets whether this node is focusable.
1380      *
1381      * @return True if the node is focusable.
1382      */
isFocusable()1383     public boolean isFocusable() {
1384         return IMPL.isFocusable(mInfo);
1385     }
1386 
1387     /**
1388      * Sets whether this node is focusable.
1389      * <p>
1390      * <strong>Note:</strong> Cannot be called from an
1391      * {@link android.accessibilityservice.AccessibilityService}. This class is
1392      * made immutable before being delivered to an AccessibilityService.
1393      * </p>
1394      *
1395      * @param focusable True if the node is focusable.
1396      * @throws IllegalStateException If called from an AccessibilityService.
1397      */
setFocusable(boolean focusable)1398     public void setFocusable(boolean focusable) {
1399         IMPL.setFocusable(mInfo, focusable);
1400     }
1401 
1402     /**
1403      * Gets whether this node is focused.
1404      *
1405      * @return True if the node is focused.
1406      */
isFocused()1407     public boolean isFocused() {
1408         return IMPL.isFocused(mInfo);
1409     }
1410 
1411     /**
1412      * Sets whether this node is focused.
1413      * <p>
1414      * <strong>Note:</strong> Cannot be called from an
1415      * {@link android.accessibilityservice.AccessibilityService}. This class is
1416      * made immutable before being delivered to an AccessibilityService.
1417      * </p>
1418      *
1419      * @param focused True if the node is focused.
1420      * @throws IllegalStateException If called from an AccessibilityService.
1421      */
setFocused(boolean focused)1422     public void setFocused(boolean focused) {
1423         IMPL.setFocused(mInfo, focused);
1424     }
1425 
1426     /**
1427      * Sets whether this node is visible to the user.
1428      *
1429      * @return Whether the node is visible to the user.
1430      */
isVisibleToUser()1431     public boolean isVisibleToUser() {
1432         return IMPL.isVisibleToUser(mInfo);
1433     }
1434 
1435     /**
1436      * Sets whether this node is visible to the user.
1437      * <p>
1438      *   <strong>Note:</strong> Cannot be called from an
1439      *   {@link android.accessibilityservice.AccessibilityService}.
1440      *   This class is made immutable before being delivered to an AccessibilityService.
1441      * </p>
1442      *
1443      * @param visibleToUser Whether the node is visible to the user.
1444      *
1445      * @throws IllegalStateException If called from an AccessibilityService.
1446      */
setVisibleToUser(boolean visibleToUser)1447     public void setVisibleToUser(boolean visibleToUser) {
1448         IMPL.setVisibleToUser(mInfo, visibleToUser);
1449     }
1450 
1451     /**
1452      * Gets whether this node is accessibility focused.
1453      *
1454      * @return True if the node is accessibility focused.
1455      */
isAccessibilityFocused()1456     public boolean isAccessibilityFocused() {
1457         return IMPL.isAccessibilityFocused(mInfo);
1458     }
1459 
1460     /**
1461      * Sets whether this node is accessibility focused.
1462      * <p>
1463      *   <strong>Note:</strong> Cannot be called from an
1464      *   {@link android.accessibilityservice.AccessibilityService}.
1465      *   This class is made immutable before being delivered to an AccessibilityService.
1466      * </p>
1467      *
1468      * @param focused True if the node is accessibility focused.
1469      *
1470      * @throws IllegalStateException If called from an AccessibilityService.
1471      */
setAccessibilityFocused(boolean focused)1472     public void setAccessibilityFocused(boolean focused) {
1473         IMPL.setAccessibilityFocused(mInfo, focused);
1474     }
1475 
1476     /**
1477      * Gets whether this node is selected.
1478      *
1479      * @return True if the node is selected.
1480      */
isSelected()1481     public boolean isSelected() {
1482         return IMPL.isSelected(mInfo);
1483     }
1484 
1485     /**
1486      * Sets whether this node is selected.
1487      * <p>
1488      * <strong>Note:</strong> Cannot be called from an
1489      * {@link android.accessibilityservice.AccessibilityService}. This class is
1490      * made immutable before being delivered to an AccessibilityService.
1491      * </p>
1492      *
1493      * @param selected True if the node is selected.
1494      * @throws IllegalStateException If called from an AccessibilityService.
1495      */
setSelected(boolean selected)1496     public void setSelected(boolean selected) {
1497         IMPL.setSelected(mInfo, selected);
1498     }
1499 
1500     /**
1501      * Gets whether this node is clickable.
1502      *
1503      * @return True if the node is clickable.
1504      */
isClickable()1505     public boolean isClickable() {
1506         return IMPL.isClickable(mInfo);
1507     }
1508 
1509     /**
1510      * Sets whether this node is clickable.
1511      * <p>
1512      * <strong>Note:</strong> Cannot be called from an
1513      * {@link android.accessibilityservice.AccessibilityService}. This class is
1514      * made immutable before being delivered to an AccessibilityService.
1515      * </p>
1516      *
1517      * @param clickable True if the node is clickable.
1518      * @throws IllegalStateException If called from an AccessibilityService.
1519      */
setClickable(boolean clickable)1520     public void setClickable(boolean clickable) {
1521         IMPL.setClickable(mInfo, clickable);
1522     }
1523 
1524     /**
1525      * Gets whether this node is long clickable.
1526      *
1527      * @return True if the node is long clickable.
1528      */
isLongClickable()1529     public boolean isLongClickable() {
1530         return IMPL.isLongClickable(mInfo);
1531     }
1532 
1533     /**
1534      * Sets whether this node is long clickable.
1535      * <p>
1536      * <strong>Note:</strong> Cannot be called from an
1537      * {@link android.accessibilityservice.AccessibilityService}. This class is
1538      * made immutable before being delivered to an AccessibilityService.
1539      * </p>
1540      *
1541      * @param longClickable True if the node is long clickable.
1542      * @throws IllegalStateException If called from an AccessibilityService.
1543      */
setLongClickable(boolean longClickable)1544     public void setLongClickable(boolean longClickable) {
1545         IMPL.setLongClickable(mInfo, longClickable);
1546     }
1547 
1548     /**
1549      * Gets whether this node is enabled.
1550      *
1551      * @return True if the node is enabled.
1552      */
isEnabled()1553     public boolean isEnabled() {
1554         return IMPL.isEnabled(mInfo);
1555     }
1556 
1557     /**
1558      * Sets whether this node is enabled.
1559      * <p>
1560      * <strong>Note:</strong> Cannot be called from an
1561      * {@link android.accessibilityservice.AccessibilityService}. This class is
1562      * made immutable before being delivered to an AccessibilityService.
1563      * </p>
1564      *
1565      * @param enabled True if the node is enabled.
1566      * @throws IllegalStateException If called from an AccessibilityService.
1567      */
setEnabled(boolean enabled)1568     public void setEnabled(boolean enabled) {
1569         IMPL.setEnabled(mInfo, enabled);
1570     }
1571 
1572     /**
1573      * Gets whether this node is a password.
1574      *
1575      * @return True if the node is a password.
1576      */
isPassword()1577     public boolean isPassword() {
1578         return IMPL.isPassword(mInfo);
1579     }
1580 
1581     /**
1582      * Sets whether this node is a password.
1583      * <p>
1584      * <strong>Note:</strong> Cannot be called from an
1585      * {@link android.accessibilityservice.AccessibilityService}. This class is
1586      * made immutable before being delivered to an AccessibilityService.
1587      * </p>
1588      *
1589      * @param password True if the node is a password.
1590      * @throws IllegalStateException If called from an AccessibilityService.
1591      */
setPassword(boolean password)1592     public void setPassword(boolean password) {
1593         IMPL.setPassword(mInfo, password);
1594     }
1595 
1596     /**
1597      * Gets if the node is scrollable.
1598      *
1599      * @return True if the node is scrollable, false otherwise.
1600      */
isScrollable()1601     public boolean isScrollable() {
1602         return IMPL.isScrollable(mInfo);
1603     }
1604 
1605     /**
1606      * Sets if the node is scrollable.
1607      * <p>
1608      * <strong>Note:</strong> Cannot be called from an
1609      * {@link android.accessibilityservice.AccessibilityService}. This class is
1610      * made immutable before being delivered to an AccessibilityService.
1611      * </p>
1612      *
1613      * @param scrollable True if the node is scrollable, false otherwise.
1614      * @throws IllegalStateException If called from an AccessibilityService.
1615      */
setScrollable(boolean scrollable)1616     public void setScrollable(boolean scrollable) {
1617         IMPL.setScrollable(mInfo, scrollable);
1618     }
1619 
1620     /**
1621      * Gets the package this node comes from.
1622      *
1623      * @return The package name.
1624      */
getPackageName()1625     public CharSequence getPackageName() {
1626         return IMPL.getPackageName(mInfo);
1627     }
1628 
1629     /**
1630      * Sets the package this node comes from.
1631      * <p>
1632      * <strong>Note:</strong> Cannot be called from an
1633      * {@link android.accessibilityservice.AccessibilityService}. This class is
1634      * made immutable before being delivered to an AccessibilityService.
1635      * </p>
1636      *
1637      * @param packageName The package name.
1638      * @throws IllegalStateException If called from an AccessibilityService.
1639      */
setPackageName(CharSequence packageName)1640     public void setPackageName(CharSequence packageName) {
1641         IMPL.setPackageName(mInfo, packageName);
1642     }
1643 
1644     /**
1645      * Gets the class this node comes from.
1646      *
1647      * @return The class name.
1648      */
getClassName()1649     public CharSequence getClassName() {
1650         return IMPL.getClassName(mInfo);
1651     }
1652 
1653     /**
1654      * Sets the class this node comes from.
1655      * <p>
1656      * <strong>Note:</strong> Cannot be called from an
1657      * {@link android.accessibilityservice.AccessibilityService}. This class is
1658      * made immutable before being delivered to an AccessibilityService.
1659      * </p>
1660      *
1661      * @param className The class name.
1662      * @throws IllegalStateException If called from an AccessibilityService.
1663      */
setClassName(CharSequence className)1664     public void setClassName(CharSequence className) {
1665         IMPL.setClassName(mInfo, className);
1666     }
1667 
1668     /**
1669      * Gets the text of this node.
1670      *
1671      * @return The text.
1672      */
getText()1673     public CharSequence getText() {
1674         return IMPL.getText(mInfo);
1675     }
1676 
1677     /**
1678      * Sets the text of this node.
1679      * <p>
1680      * <strong>Note:</strong> Cannot be called from an
1681      * {@link android.accessibilityservice.AccessibilityService}. This class is
1682      * made immutable before being delivered to an AccessibilityService.
1683      * </p>
1684      *
1685      * @param text The text.
1686      * @throws IllegalStateException If called from an AccessibilityService.
1687      */
setText(CharSequence text)1688     public void setText(CharSequence text) {
1689         IMPL.setText(mInfo, text);
1690     }
1691 
1692     /**
1693      * Gets the content description of this node.
1694      *
1695      * @return The content description.
1696      */
getContentDescription()1697     public CharSequence getContentDescription() {
1698         return IMPL.getContentDescription(mInfo);
1699     }
1700 
1701     /**
1702      * Sets the content description of this node.
1703      * <p>
1704      * <strong>Note:</strong> Cannot be called from an
1705      * {@link android.accessibilityservice.AccessibilityService}. This class is
1706      * made immutable before being delivered to an AccessibilityService.
1707      * </p>
1708      *
1709      * @param contentDescription The content description.
1710      * @throws IllegalStateException If called from an AccessibilityService.
1711      */
setContentDescription(CharSequence contentDescription)1712     public void setContentDescription(CharSequence contentDescription) {
1713         IMPL.setContentDescription(mInfo, contentDescription);
1714     }
1715 
1716     /**
1717      * Return an instance back to be reused.
1718      * <p>
1719      * <strong>Note:</strong> You must not touch the object after calling this function.
1720      *
1721      * @throws IllegalStateException If the info is already recycled.
1722      */
recycle()1723     public void recycle() {
1724         IMPL.recycle(mInfo);
1725     }
1726 
1727     @Override
hashCode()1728     public int hashCode() {
1729         return (mInfo == null) ? 0 : mInfo.hashCode();
1730     }
1731 
1732     @Override
equals(Object obj)1733     public boolean equals(Object obj) {
1734         if (this == obj) {
1735             return true;
1736         }
1737         if (obj == null) {
1738             return false;
1739         }
1740         if (getClass() != obj.getClass()) {
1741             return false;
1742         }
1743         AccessibilityNodeInfoCompat other = (AccessibilityNodeInfoCompat) obj;
1744         if (mInfo == null) {
1745             if (other.mInfo != null) {
1746                 return false;
1747             }
1748         } else if (!mInfo.equals(other.mInfo)) {
1749             return false;
1750         }
1751         return true;
1752     }
1753 }
1754