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