AccessibilityRecordCompat.java revision 15375aa6fd54b036f97f99229aefab2822c8a1c9
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
17package android.support.v4.view.accessibility;
18
19import android.os.Build;
20import android.os.Parcelable;
21import android.view.View;
22import android.view.accessibility.AccessibilityEvent;
23
24import java.util.Collections;
25import java.util.List;
26
27/**
28 * Helper for accessing {@link android.view.accessibility.AccessibilityRecord}
29 * introduced after API level 4 in a backwards compatible fashion.
30 */
31public class AccessibilityRecordCompat {
32
33    static interface AccessibilityRecordImpl {
34        public Object obtain();
35        public Object obtain(Object record);
36        public void setSource(Object record, View source);
37        public void setSource(Object record, View root, int virtualDescendantId);
38        public AccessibilityNodeInfoCompat getSource(Object record);
39        public int getWindowId(Object record);
40        public boolean isChecked(Object record);
41        public void setChecked(Object record, boolean isChecked);
42        public boolean isEnabled(Object record);
43        public void setEnabled(Object record, boolean isEnabled);
44        public boolean isPassword(Object record);
45        public void setPassword(Object record, boolean isPassword);
46        public boolean isFullScreen(Object record);
47        public void setFullScreen(Object record, boolean isFullScreen);
48        public boolean isScrollable(Object record);
49        public void setScrollable(Object record, boolean scrollable);
50        public int getItemCount(Object record);
51        public void setItemCount(Object record, int itemCount);
52        public int getCurrentItemIndex(Object record);
53        public void setCurrentItemIndex(Object record, int currentItemIndex);
54        public int getFromIndex(Object record);
55        public void setFromIndex(Object record, int fromIndex);
56        public int getToIndex(Object record);
57        public void setToIndex(Object record, int toIndex);
58        public int getScrollX(Object record);
59        public void setScrollX(Object record, int scrollX);
60        public int getScrollY(Object record);
61        public void setScrollY(Object record, int scrollY);
62        public int getMaxScrollX(Object record);
63        public void setMaxScrollX(Object record, int maxScrollX);
64        public int getMaxScrollY(Object record);
65        public void setMaxScrollY(Object record, int maxScrollY);
66        public int getAddedCount(Object record);
67        public void setAddedCount(Object record, int addedCount);
68        public int getRemovedCount(Object record);
69        public void setRemovedCount(Object record, int removedCount);
70        public CharSequence getClassName(Object record);
71        public void setClassName(Object record, CharSequence className);
72        public List<CharSequence> getText(Object record);
73        public CharSequence getBeforeText(Object record);
74        public void setBeforeText(Object record, CharSequence beforeText);
75        public CharSequence getContentDescription(Object record);
76        public void setContentDescription(Object record, CharSequence contentDescription);
77        public Parcelable getParcelableData(Object record);
78        public void setParcelableData(Object record, Parcelable parcelableData);
79        public void recycle(Object record);
80    }
81
82    static class AccessibilityRecordStubImpl implements AccessibilityRecordImpl {
83        @Override
84        public Object obtain() {
85            return null;
86        }
87
88        @Override
89        public Object obtain(Object record) {
90            return null;
91        }
92
93        @Override
94        public int getAddedCount(Object record) {
95            return 0;
96        }
97
98        @Override
99        public CharSequence getBeforeText(Object record) {
100            return null;
101        }
102
103        @Override
104        public CharSequence getClassName(Object record) {
105            return null;
106        }
107
108        @Override
109        public CharSequence getContentDescription(Object record) {
110            return null;
111        }
112
113        @Override
114        public int getCurrentItemIndex(Object record) {
115            return 0;
116        }
117
118        @Override
119        public int getFromIndex(Object record) {
120            return 0;
121        }
122
123        @Override
124        public int getItemCount(Object record) {
125            return 0;
126        }
127
128        @Override
129        public int getMaxScrollX(Object record) {
130            return 0;
131        }
132
133        @Override
134        public int getMaxScrollY(Object record) {
135            return 0;
136        }
137
138        @Override
139        public Parcelable getParcelableData(Object record) {
140            return null;
141        }
142
143        @Override
144        public int getRemovedCount(Object record) {
145            return 0;
146        }
147
148        @Override
149        public int getScrollX(Object record) {
150            return 0;
151        }
152
153        @Override
154        public int getScrollY(Object record) {
155            return 0;
156        }
157
158        @Override
159        public AccessibilityNodeInfoCompat getSource(Object record) {
160            return null;
161        }
162
163        @Override
164        public List<CharSequence> getText(Object record) {
165            return Collections.emptyList();
166        }
167
168        @Override
169        public int getToIndex(Object record) {
170            return 0;
171        }
172
173        @Override
174        public int getWindowId(Object record) {
175            return 0;
176        }
177
178        @Override
179        public boolean isChecked(Object record) {
180            return false;
181        }
182
183        @Override
184        public boolean isEnabled(Object record) {
185            return false;
186        }
187
188        @Override
189        public boolean isFullScreen(Object record) {
190            return false;
191        }
192
193        @Override
194        public boolean isPassword(Object record) {
195            return false;
196        }
197
198        @Override
199        public boolean isScrollable(Object record) {
200            return false;
201        }
202
203        @Override
204        public void recycle(Object record) {
205
206        }
207
208        @Override
209        public void setAddedCount(Object record, int addedCount) {
210
211        }
212
213        @Override
214        public void setBeforeText(Object record, CharSequence beforeText) {
215
216        }
217
218        @Override
219        public void setChecked(Object record, boolean isChecked) {
220
221        }
222
223        @Override
224        public void setClassName(Object record, CharSequence className) {
225
226        }
227
228        @Override
229        public void setContentDescription(Object record, CharSequence contentDescription) {
230
231        }
232
233        @Override
234        public void setCurrentItemIndex(Object record, int currentItemIndex) {
235
236        }
237
238        @Override
239        public void setEnabled(Object record, boolean isEnabled) {
240
241        }
242
243        @Override
244        public void setFromIndex(Object record, int fromIndex) {
245
246        }
247
248        @Override
249        public void setFullScreen(Object record, boolean isFullScreen) {
250
251        }
252
253        @Override
254        public void setItemCount(Object record, int itemCount) {
255
256        }
257
258        @Override
259        public void setMaxScrollX(Object record, int maxScrollX) {
260
261        }
262
263        @Override
264        public void setMaxScrollY(Object record, int maxScrollY) {
265
266        }
267
268        @Override
269        public void setParcelableData(Object record, Parcelable parcelableData) {
270
271        }
272
273        @Override
274        public void setPassword(Object record, boolean isPassword) {
275
276        }
277
278        @Override
279        public void setRemovedCount(Object record, int removedCount) {
280
281        }
282
283        @Override
284        public void setScrollX(Object record, int scrollX) {
285
286        }
287
288        @Override
289        public void setScrollY(Object record, int scrollY) {
290
291        }
292
293        @Override
294        public void setScrollable(Object record, boolean scrollable) {
295
296        }
297
298        @Override
299        public void setSource(Object record, View source) {
300
301        }
302
303        @Override
304        public void setSource(Object record, View root, int virtualDescendantId) {
305
306        }
307
308        @Override
309        public void setToIndex(Object record, int toIndex) {
310
311        }
312    }
313
314    static class AccessibilityRecordIcsImpl extends AccessibilityRecordStubImpl {
315        @Override
316        public Object obtain() {
317            return AccessibilityRecordCompatIcs.obtain();
318        }
319
320        @Override
321        public Object obtain(Object record) {
322            return AccessibilityRecordCompatIcs.obtain(record);
323        }
324
325        @Override
326        public int getAddedCount(Object record) {
327            return AccessibilityRecordCompatIcs.getAddedCount(record);
328        }
329
330        @Override
331        public CharSequence getBeforeText(Object record) {
332            return AccessibilityRecordCompatIcs.getBeforeText(record);
333        }
334
335        @Override
336        public CharSequence getClassName(Object record) {
337            return AccessibilityRecordCompatIcs.getClassName(record);
338        }
339
340        @Override
341        public CharSequence getContentDescription(Object record) {
342            return AccessibilityRecordCompatIcs.getContentDescription(record);
343        }
344
345        @Override
346        public int getCurrentItemIndex(Object record) {
347            return AccessibilityRecordCompatIcs.getCurrentItemIndex(record);
348        }
349
350        @Override
351        public int getFromIndex(Object record) {
352            return AccessibilityRecordCompatIcs.getFromIndex(record);
353        }
354
355        @Override
356        public int getItemCount(Object record) {
357            return AccessibilityRecordCompatIcs.getItemCount(record);
358        }
359
360        @Override
361        public Parcelable getParcelableData(Object record) {
362            return AccessibilityRecordCompatIcs.getParcelableData(record);
363        }
364
365        @Override
366        public int getRemovedCount(Object record) {
367            return AccessibilityRecordCompatIcs.getRemovedCount(record);
368        }
369
370        @Override
371        public int getScrollX(Object record) {
372            return AccessibilityRecordCompatIcs.getScrollX(record);
373        }
374
375        @Override
376        public int getScrollY(Object record) {
377            return AccessibilityRecordCompatIcs.getScrollY(record);
378        }
379
380        @Override
381        public AccessibilityNodeInfoCompat getSource(Object record) {
382            return AccessibilityNodeInfoCompat.wrapNonNullInstance(
383                    AccessibilityRecordCompatIcs.getSource(record));
384        }
385
386        @Override
387        public List<CharSequence> getText(Object record) {
388            return AccessibilityRecordCompatIcs.getText(record);
389        }
390
391        @Override
392        public int getToIndex(Object record) {
393            return AccessibilityRecordCompatIcs.getToIndex(record);
394        }
395
396        @Override
397        public int getWindowId(Object record) {
398            return AccessibilityRecordCompatIcs.getWindowId(record);
399        }
400
401        @Override
402        public boolean isChecked(Object record) {
403            return AccessibilityRecordCompatIcs.isChecked(record);
404        }
405
406        @Override
407        public boolean isEnabled(Object record) {
408            return AccessibilityRecordCompatIcs.isEnabled(record);
409        }
410
411        @Override
412        public boolean isFullScreen(Object record) {
413            return AccessibilityRecordCompatIcs.isFullScreen(record);
414        }
415
416        @Override
417        public boolean isPassword(Object record) {
418            return AccessibilityRecordCompatIcs.isPassword(record);
419        }
420
421        @Override
422        public boolean isScrollable(Object record) {
423            return AccessibilityRecordCompatIcs.isScrollable(record);
424        }
425
426        @Override
427        public void recycle(Object record) {
428            AccessibilityRecordCompatIcs.recycle(record);
429        }
430
431        @Override
432        public void setAddedCount(Object record, int addedCount) {
433            AccessibilityRecordCompatIcs.setAddedCount(record, addedCount);
434        }
435
436        @Override
437        public void setBeforeText(Object record, CharSequence beforeText) {
438            AccessibilityRecordCompatIcs.setBeforeText(record, beforeText);
439        }
440
441        @Override
442        public void setChecked(Object record, boolean isChecked) {
443            AccessibilityRecordCompatIcs.setChecked(record, isChecked);
444        }
445
446        @Override
447        public void setClassName(Object record, CharSequence className) {
448            AccessibilityRecordCompatIcs.setClassName(record, className);
449        }
450
451        @Override
452        public void setContentDescription(Object record, CharSequence contentDescription) {
453            AccessibilityRecordCompatIcs.setContentDescription(record, contentDescription);
454        }
455
456        @Override
457        public void setCurrentItemIndex(Object record, int currentItemIndex) {
458            AccessibilityRecordCompatIcs.setCurrentItemIndex(record, currentItemIndex);
459        }
460
461        @Override
462        public void setEnabled(Object record, boolean isEnabled) {
463            AccessibilityRecordCompatIcs.setEnabled(record, isEnabled);
464        }
465
466        @Override
467        public void setFromIndex(Object record, int fromIndex) {
468            AccessibilityRecordCompatIcs.setFromIndex(record, fromIndex);
469        }
470
471        @Override
472        public void setFullScreen(Object record, boolean isFullScreen) {
473            AccessibilityRecordCompatIcs.setFullScreen(record, isFullScreen);
474        }
475
476        @Override
477        public void setItemCount(Object record, int itemCount) {
478            AccessibilityRecordCompatIcs.setItemCount(record, itemCount);
479        }
480
481        @Override
482        public void setParcelableData(Object record, Parcelable parcelableData) {
483            AccessibilityRecordCompatIcs.setParcelableData(record, parcelableData);
484        }
485
486        @Override
487        public void setPassword(Object record, boolean isPassword) {
488            AccessibilityRecordCompatIcs.setPassword(record, isPassword);
489        }
490
491        @Override
492        public void setRemovedCount(Object record, int removedCount) {
493            AccessibilityRecordCompatIcs.setRemovedCount(record, removedCount);
494        }
495
496        @Override
497        public void setScrollX(Object record, int scrollX) {
498            AccessibilityRecordCompatIcs.setScrollX(record, scrollX);
499        }
500
501        @Override
502        public void setScrollY(Object record, int scrollY) {
503            AccessibilityRecordCompatIcs.setScrollY(record, scrollY);
504        }
505
506        @Override
507        public void setScrollable(Object record, boolean scrollable) {
508            AccessibilityRecordCompatIcs.setScrollable(record, scrollable);
509        }
510
511        @Override
512        public void setSource(Object record, View source) {
513            AccessibilityRecordCompatIcs.setSource(record, source);
514        }
515
516        @Override
517        public void setToIndex(Object record, int toIndex) {
518            AccessibilityRecordCompatIcs.setToIndex(record, toIndex);
519        }
520    }
521
522    static class AccessibilityRecordIcsMr1Impl extends AccessibilityRecordIcsImpl {
523        @Override
524        public int getMaxScrollX(Object record) {
525            return AccessibilityRecordCompatIcsMr1.getMaxScrollX(record);
526        }
527
528        @Override
529        public int getMaxScrollY(Object record) {
530            return AccessibilityRecordCompatIcsMr1.getMaxScrollY(record);
531        }
532
533        @Override
534        public void setMaxScrollX(Object record, int maxScrollX) {
535            AccessibilityRecordCompatIcsMr1.setMaxScrollX(record, maxScrollX);
536        }
537
538        @Override
539        public void setMaxScrollY(Object record, int maxScrollY) {
540            AccessibilityRecordCompatIcsMr1.setMaxScrollY(record, maxScrollY);
541        }
542    }
543
544    static class AccessibilityRecordJellyBeanImpl extends AccessibilityRecordIcsMr1Impl {
545        @Override
546        public void setSource(Object record, View root, int virtualDescendantId) {
547            AccessibilityRecordCompatJellyBean.setSource(record, root, virtualDescendantId);
548        }
549    }
550
551    static {
552        if (Build.VERSION.SDK_INT >= 16) { // JellyBean
553            IMPL = new AccessibilityRecordJellyBeanImpl();
554        } else if (Build.VERSION.SDK_INT >= 15) {  // ICS MR1
555            IMPL = new AccessibilityRecordIcsMr1Impl();
556        } else if (Build.VERSION.SDK_INT >= 14) { // ICS
557            IMPL = new AccessibilityRecordIcsImpl();
558        } else {
559            IMPL = new AccessibilityRecordStubImpl();
560        }
561    }
562
563    private static final AccessibilityRecordImpl IMPL;
564
565    private final Object mRecord;
566
567    /**
568     * @deprecated This is not type safe. If you want to modify an
569     * {@link AccessibilityEvent}'s properties defined in
570     * {@link android.view.accessibility.AccessibilityRecord} use
571     * {@link AccessibilityEventCompat#asRecord(AccessibilityEvent)}. This method will be removed
572     * in a subsequent release of the support library.
573     */
574    @Deprecated
575    public AccessibilityRecordCompat(Object record) {
576        mRecord = record;
577    }
578
579    /**
580     * @return The wrapped implementation.
581     *
582     * @deprecated This method will be removed in a subsequent release of
583     * the support library.
584     */
585    @Deprecated
586    public Object getImpl() {
587        return mRecord;
588    }
589
590    /**
591     * Returns a cached instance if such is available or a new one is
592     * instantiated. The instance is initialized with data from the
593     * given record.
594     *
595     * @return An instance.
596     */
597    public static AccessibilityRecordCompat obtain(AccessibilityRecordCompat record) {
598       return new AccessibilityRecordCompat(IMPL.obtain(record.mRecord));
599    }
600
601    /**
602     * Returns a cached instance if such is available or a new one is
603     * instantiated.
604     *
605     * @return An instance.
606     */
607    public static AccessibilityRecordCompat obtain() {
608        return new AccessibilityRecordCompat(IMPL.obtain());
609    }
610
611    /**
612     * Sets the event source.
613     *
614     * @param source The source.
615     *
616     * @throws IllegalStateException If called from an AccessibilityService.
617     */
618    public void setSource(View source) {
619        IMPL.setSource(mRecord, source);
620    }
621
622    /**
623     * Sets the source to be a virtual descendant of the given <code>root</code>.
624     * If <code>virtualDescendantId</code> equals to {@link View#NO_ID} the root
625     * is set as the source.
626     * <p>
627     * A virtual descendant is an imaginary View that is reported as a part of the view
628     * hierarchy for accessibility purposes. This enables custom views that draw complex
629     * content to report them selves as a tree of virtual views, thus conveying their
630     * logical structure.
631     * </p>
632     *
633     * @param root The root of the virtual subtree.
634     * @param virtualDescendantId The id of the virtual descendant.
635     */
636    public void setSource(View root, int virtualDescendantId) {
637        IMPL.setSource(mRecord, root, virtualDescendantId);
638    }
639
640    /**
641     * Gets the {@link android.view.accessibility.AccessibilityNodeInfo} of
642     * the event source.
643     * <p>
644     * <strong>Note:</strong> It is a client responsibility to recycle the
645     * received info by calling
646     * {@link android.view.accessibility.AccessibilityNodeInfo#recycle()
647     * AccessibilityNodeInfo#recycle()} to avoid creating of multiple instances.
648     *</p>
649     *
650     * @return The info of the source.
651     */
652    public AccessibilityNodeInfoCompat getSource() {
653        return IMPL.getSource(mRecord);
654    }
655
656    /**
657     * Gets the id of the window from which the event comes from.
658     *
659     * @return The window id.
660     */
661    public int getWindowId() {
662        return IMPL.getWindowId(mRecord);
663    }
664
665    /**
666     * Gets if the source is checked.
667     *
668     * @return True if the view is checked, false otherwise.
669     */
670    public boolean isChecked() {
671        return IMPL.isChecked(mRecord);
672    }
673
674    /**
675     * Sets if the source is checked.
676     *
677     * @param isChecked True if the view is checked, false otherwise.
678     *
679     * @throws IllegalStateException If called from an AccessibilityService.
680     */
681    public void setChecked(boolean isChecked) {
682        IMPL.setChecked(mRecord, isChecked);
683    }
684
685    /**
686     * Gets if the source is enabled.
687     *
688     * @return True if the view is enabled, false otherwise.
689     */
690    public boolean isEnabled() {
691        return IMPL.isEnabled(mRecord);
692    }
693
694    /**
695     * Sets if the source is enabled.
696     *
697     * @param isEnabled True if the view is enabled, false otherwise.
698     *
699     * @throws IllegalStateException If called from an AccessibilityService.
700     */
701    public void setEnabled(boolean isEnabled) {
702        IMPL.setEnabled(mRecord, isEnabled);
703    }
704
705    /**
706     * Gets if the source is a password field.
707     *
708     * @return True if the view is a password field, false otherwise.
709     */
710    public boolean isPassword() {
711        return IMPL.isPassword(mRecord);
712    }
713
714    /**
715     * Sets if the source is a password field.
716     *
717     * @param isPassword True if the view is a password field, false otherwise.
718     *
719     * @throws IllegalStateException If called from an AccessibilityService.
720     */
721    public void setPassword(boolean isPassword) {
722        IMPL.setPassword(mRecord, isPassword);
723    }
724
725    /**
726     * Gets if the source is taking the entire screen.
727     *
728     * @return True if the source is full screen, false otherwise.
729     */
730    public boolean isFullScreen() {
731        return IMPL.isFullScreen(mRecord);
732    }
733
734    /**
735     * Sets if the source is taking the entire screen.
736     *
737     * @param isFullScreen True if the source is full screen, false otherwise.
738     *
739     * @throws IllegalStateException If called from an AccessibilityService.
740     */
741    public void setFullScreen(boolean isFullScreen) {
742        IMPL.setFullScreen(mRecord, isFullScreen);
743    }
744
745    /**
746     * Gets if the source is scrollable.
747     *
748     * @return True if the source is scrollable, false otherwise.
749     */
750    public boolean isScrollable() {
751        return IMPL.isScrollable(mRecord);
752    }
753
754    /**
755     * Sets if the source is scrollable.
756     *
757     * @param scrollable True if the source is scrollable, false otherwise.
758     *
759     * @throws IllegalStateException If called from an AccessibilityService.
760     */
761    public void setScrollable(boolean scrollable) {
762        IMPL.setScrollable(mRecord, scrollable);
763    }
764
765    /**
766     * Gets the number of items that can be visited.
767     *
768     * @return The number of items.
769     */
770    public int getItemCount() {
771        return IMPL.getItemCount(mRecord);
772    }
773
774    /**
775     * Sets the number of items that can be visited.
776     *
777     * @param itemCount The number of items.
778     *
779     * @throws IllegalStateException If called from an AccessibilityService.
780     */
781    public void setItemCount(int itemCount) {
782        IMPL.setItemCount(mRecord, itemCount);
783    }
784
785    /**
786     * Gets the index of the source in the list of items the can be visited.
787     *
788     * @return The current item index.
789     */
790    public int getCurrentItemIndex() {
791        return IMPL.getCurrentItemIndex(mRecord);
792    }
793
794    /**
795     * Sets the index of the source in the list of items that can be visited.
796     *
797     * @param currentItemIndex The current item index.
798     *
799     * @throws IllegalStateException If called from an AccessibilityService.
800     */
801    public void setCurrentItemIndex(int currentItemIndex) {
802        IMPL.setCurrentItemIndex(mRecord, currentItemIndex);
803    }
804
805    /**
806     * Gets the index of the first character of the changed sequence,
807     * or the beginning of a text selection or the index of the first
808     * visible item when scrolling.
809     *
810     * @return The index of the first character or selection
811     *        start or the first visible item.
812     */
813    public int getFromIndex() {
814        return IMPL.getFromIndex(mRecord);
815    }
816
817    /**
818     * Sets the index of the first character of the changed sequence
819     * or the beginning of a text selection or the index of the first
820     * visible item when scrolling.
821     *
822     * @param fromIndex The index of the first character or selection
823     *        start or the first visible item.
824     *
825     * @throws IllegalStateException If called from an AccessibilityService.
826     */
827    public void setFromIndex(int fromIndex) {
828        IMPL.setFromIndex(mRecord, fromIndex);
829    }
830
831    /**
832     * Gets the index of text selection end or the index of the last
833     * visible item when scrolling.
834     *
835     * @return The index of selection end or last item index.
836     */
837    public int getToIndex() {
838        return IMPL.getToIndex(mRecord);
839    }
840
841    /**
842     * Sets the index of text selection end or the index of the last
843     * visible item when scrolling.
844     *
845     * @param toIndex The index of selection end or last item index.
846     */
847    public void setToIndex(int toIndex) {
848        IMPL.setToIndex(mRecord, toIndex);
849    }
850
851    /**
852     * Gets the scroll offset of the source left edge in pixels.
853     *
854     * @return The scroll.
855     */
856    public int getScrollX() {
857        return IMPL.getScrollX(mRecord);
858    }
859
860    /**
861     * Sets the scroll offset of the source left edge in pixels.
862     *
863     * @param scrollX The scroll.
864     */
865    public void setScrollX(int scrollX) {
866        IMPL.setScrollX(mRecord, scrollX);
867    }
868
869    /**
870     * Gets the scroll offset of the source top edge in pixels.
871     *
872     * @return The scroll.
873     */
874    public int getScrollY() {
875        return IMPL.getScrollY(mRecord);
876    }
877
878    /**
879     * Sets the scroll offset of the source top edge in pixels.
880     *
881     * @param scrollY The scroll.
882     */
883    public void setScrollY(int scrollY) {
884        IMPL.setScrollY(mRecord, scrollY);
885    }
886
887    /**
888     * Gets the max scroll offset of the source left edge in pixels.
889     *
890     * @return The max scroll.
891     */
892    public int getMaxScrollX() {
893        return IMPL.getMaxScrollX(mRecord);
894    }
895    /**
896     * Sets the max scroll offset of the source left edge in pixels.
897     *
898     * @param maxScrollX The max scroll.
899     */
900    public void setMaxScrollX(int maxScrollX) {
901        IMPL.setMaxScrollX(mRecord, maxScrollX);
902    }
903
904    /**
905     * Gets the max scroll offset of the source top edge in pixels.
906     *
907     * @return The max scroll.
908     */
909    public int getMaxScrollY() {
910        return IMPL.getMaxScrollY(mRecord);
911    }
912
913    /**
914     * Sets the max scroll offset of the source top edge in pixels.
915     *
916     * @param maxScrollY The max scroll.
917     */
918    public void setMaxScrollY(int maxScrollY) {
919        IMPL.setMaxScrollY(mRecord, maxScrollY);
920    }
921
922    /**
923     * Gets the number of added characters.
924     *
925     * @return The number of added characters.
926     */
927    public int getAddedCount() {
928        return IMPL.getAddedCount(mRecord);
929    }
930
931    /**
932     * Sets the number of added characters.
933     *
934     * @param addedCount The number of added characters.
935     *
936     * @throws IllegalStateException If called from an AccessibilityService.
937     */
938    public void setAddedCount(int addedCount) {
939        IMPL.setAddedCount(mRecord, addedCount);
940    }
941
942    /**
943     * Gets the number of removed characters.
944     *
945     * @return The number of removed characters.
946     */
947    public int getRemovedCount() {
948        return IMPL.getRemovedCount(mRecord);
949    }
950
951    /**
952     * Sets the number of removed characters.
953     *
954     * @param removedCount The number of removed characters.
955     *
956     * @throws IllegalStateException If called from an AccessibilityService.
957     */
958    public void setRemovedCount(int removedCount) {
959        IMPL.setRemovedCount(mRecord, removedCount);
960    }
961
962    /**
963     * Gets the class name of the source.
964     *
965     * @return The class name.
966     */
967    public CharSequence getClassName() {
968        return IMPL.getClassName(mRecord);
969    }
970
971    /**
972     * Sets the class name of the source.
973     *
974     * @param className The lass name.
975     *
976     * @throws IllegalStateException If called from an AccessibilityService.
977     */
978    public void setClassName(CharSequence className) {
979        IMPL.setClassName(mRecord, className);
980    }
981
982    /**
983     * Gets the text of the event. The index in the list represents the priority
984     * of the text. Specifically, the lower the index the higher the priority.
985     *
986     * @return The text.
987     */
988    public List<CharSequence> getText() {
989        return IMPL.getText(mRecord);
990    }
991
992    /**
993     * Sets the text before a change.
994     *
995     * @return The text before the change.
996     */
997    public CharSequence getBeforeText() {
998        return IMPL.getBeforeText(mRecord);
999    }
1000
1001    /**
1002     * Sets the text before a change.
1003     *
1004     * @param beforeText The text before the change.
1005     *
1006     * @throws IllegalStateException If called from an AccessibilityService.
1007     */
1008    public void setBeforeText(CharSequence beforeText) {
1009        IMPL.setBeforeText(mRecord, beforeText);
1010    }
1011
1012    /**
1013     * Gets the description of the source.
1014     *
1015     * @return The description.
1016     */
1017    public CharSequence getContentDescription() {
1018        return IMPL.getContentDescription(mRecord);
1019    }
1020
1021    /**
1022     * Sets the description of the source.
1023     *
1024     * @param contentDescription The description.
1025     *
1026     * @throws IllegalStateException If called from an AccessibilityService.
1027     */
1028    public void setContentDescription(CharSequence contentDescription) {
1029        IMPL.setContentDescription(mRecord, contentDescription);
1030    }
1031
1032    /**
1033     * Gets the {@link Parcelable} data.
1034     *
1035     * @return The parcelable data.
1036     */
1037    public Parcelable getParcelableData() {
1038        return IMPL.getParcelableData(mRecord);
1039    }
1040
1041    /**
1042     * Sets the {@link Parcelable} data of the event.
1043     *
1044     * @param parcelableData The parcelable data.
1045     *
1046     * @throws IllegalStateException If called from an AccessibilityService.
1047     */
1048    public void setParcelableData(Parcelable parcelableData) {
1049        IMPL.setParcelableData(mRecord, parcelableData);
1050    }
1051
1052    /**
1053     * Return an instance back to be reused.
1054     * <p>
1055     * <strong>Note:</strong> You must not touch the object after calling this
1056     * function.
1057     * </p>
1058     *
1059     * @throws IllegalStateException If the record is already recycled.
1060     */
1061    public void recycle() {
1062        IMPL.recycle(mRecord);
1063    }
1064
1065    @Override
1066    public int hashCode() {
1067        return (mRecord == null) ? 0 : mRecord.hashCode();
1068    }
1069
1070
1071    @Override
1072    public boolean equals(Object obj) {
1073        if (this == obj) {
1074            return true;
1075        }
1076        if (obj == null) {
1077            return false;
1078        }
1079        if (getClass() != obj.getClass()) {
1080            return false;
1081        }
1082        AccessibilityRecordCompat other = (AccessibilityRecordCompat) obj;
1083        if (mRecord == null) {
1084            if (other.mRecord != null) {
1085                return false;
1086            }
1087        } else if (!mRecord.equals(other.mRecord)) {
1088            return false;
1089        }
1090        return true;
1091    }
1092}
1093