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