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