AccessibilityRecordCompat.java revision 0574ca37da4619afe4e26753f5a1b4de314b6565
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 Object 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 Object 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 implements AccessibilityRecordImpl {
263        public Object obtain() {
264            return AccessibilityRecordCompatIcs.obtain();
265        }
266
267        public Object obtain(Object record) {
268            return AccessibilityRecordCompatIcs.obtain(record);
269        }
270
271        public int getAddedCount(Object record) {
272            return AccessibilityRecordCompatIcs.getAddedCount(record);
273        }
274
275        public CharSequence getBeforeText(Object record) {
276            return AccessibilityRecordCompatIcs.getBeforeText(record);
277        }
278
279        public CharSequence getClassName(Object record) {
280            return AccessibilityRecordCompatIcs.getClassName(record);
281        }
282
283        public CharSequence getContentDescription(Object record) {
284            return AccessibilityRecordCompatIcs.getContentDescription(record);
285        }
286
287        public int getCurrentItemIndex(Object record) {
288            return AccessibilityRecordCompatIcs.getCurrentItemIndex(record);
289        }
290
291        public int getFromIndex(Object record) {
292            return AccessibilityRecordCompatIcs.getFromIndex(record);
293        }
294
295        public int getItemCount(Object record) {
296            return AccessibilityRecordCompatIcs.getItemCount(record);
297        }
298
299        public int getMaxScrollX(Object record) {
300            // TODO: Uncomment when these APIs become public
301            return 0;//AccessibilityRecordCompatIcs.getMaxScrollX(record);
302        }
303
304        public int getMaxScrollY(Object record) {
305            // TODO: Uncomment when these APIs become public
306            return 0;//AccessibilityRecordCompatIcs.getMaxScrollY(record);
307        }
308
309        public Parcelable getParcelableData(Object record) {
310            return AccessibilityRecordCompatIcs.getParcelableData(record);
311        }
312
313        public int getRemovedCount(Object record) {
314            return AccessibilityRecordCompatIcs.getRemovedCount(record);
315        }
316
317        public int getScrollX(Object record) {
318            return AccessibilityRecordCompatIcs.getScrollX(record);
319        }
320
321        public int getScrollY(Object record) {
322            return AccessibilityRecordCompatIcs.getScrollY(record);
323        }
324
325        public Object getSource(Object record) {
326            return AccessibilityRecordCompatIcs.getSource(record);
327        }
328
329        public List<CharSequence> getText(Object record) {
330            return AccessibilityRecordCompatIcs.getText(record);
331        }
332
333        public int getToIndex(Object record) {
334            return AccessibilityRecordCompatIcs.getToIndex(record);
335        }
336
337        public int getWindowId(Object record) {
338            return AccessibilityRecordCompatIcs.getWindowId(record);
339        }
340
341        public boolean isChecked(Object record) {
342            return AccessibilityRecordCompatIcs.isChecked(record);
343        }
344
345        public boolean isEnabled(Object record) {
346            return AccessibilityRecordCompatIcs.isEnabled(record);
347        }
348
349        public boolean isFullScreen(Object record) {
350            return AccessibilityRecordCompatIcs.isFullScreen(record);
351        }
352
353        public boolean isPassword(Object record) {
354            return AccessibilityRecordCompatIcs.isPassword(record);
355        }
356
357        public boolean isScrollable(Object record) {
358            return AccessibilityRecordCompatIcs.isScrollable(record);
359        }
360
361        public void recycle(Object record) {
362            AccessibilityRecordCompatIcs.recycle(record);
363        }
364
365        public void setAddedCount(Object record, int addedCount) {
366            AccessibilityRecordCompatIcs.setAddedCount(record, addedCount);
367        }
368
369        public void setBeforeText(Object record, CharSequence beforeText) {
370            AccessibilityRecordCompatIcs.setBeforeText(record, beforeText);
371        }
372
373        public void setChecked(Object record, boolean isChecked) {
374            AccessibilityRecordCompatIcs.setChecked(record, isChecked);
375        }
376
377        public void setClassName(Object record, CharSequence className) {
378            AccessibilityRecordCompatIcs.setClassName(record, className);
379        }
380
381        public void setContentDescription(Object record, CharSequence contentDescription) {
382            AccessibilityRecordCompatIcs.setContentDescription(record, contentDescription);
383        }
384
385        public void setCurrentItemIndex(Object record, int currentItemIndex) {
386            AccessibilityRecordCompatIcs.setCurrentItemIndex(record, currentItemIndex);
387        }
388
389        public void setEnabled(Object record, boolean isEnabled) {
390            AccessibilityRecordCompatIcs.setEnabled(record, isEnabled);
391        }
392
393        public void setFromIndex(Object record, int fromIndex) {
394            AccessibilityRecordCompatIcs.setFromIndex(record, fromIndex);
395        }
396
397        public void setFullScreen(Object record, boolean isFullScreen) {
398            AccessibilityRecordCompatIcs.setFullScreen(record, isFullScreen);
399        }
400
401        public void setItemCount(Object record, int itemCount) {
402            AccessibilityRecordCompatIcs.setItemCount(record, itemCount);
403        }
404
405        public void setMaxScrollX(Object record, int maxScrollX) {
406//        TODO: Uncomment when these APIs become public
407//            AccessibilityRecordCompatIcs.setMaxScrollX(record, maxScrollX);
408        }
409
410        public void setMaxScrollY(Object record, int maxScrollY) {
411//        TODO: Uncomment when these APIs become public
412//            AccessibilityRecordCompatIcs.setMaxScrollY(record, maxScrollY);
413        }
414
415        public void setParcelableData(Object record, Parcelable parcelableData) {
416            AccessibilityRecordCompatIcs.setParcelableData(record, parcelableData);
417        }
418
419        public void setPassword(Object record, boolean isPassword) {
420            AccessibilityRecordCompatIcs.setPassword(record, isPassword);
421        }
422
423        public void setRemovedCount(Object record, int removedCount) {
424            AccessibilityRecordCompatIcs.setRemovedCount(record, removedCount);
425        }
426
427        public void setScrollX(Object record, int scrollX) {
428            AccessibilityRecordCompatIcs.setScrollX(record, scrollX);
429        }
430
431        public void setScrollY(Object record, int scrollY) {
432            AccessibilityRecordCompatIcs.setScrollY(record, scrollY);
433        }
434
435        public void setScrollable(Object record, boolean scrollable) {
436            AccessibilityRecordCompatIcs.setScrollable(record, scrollable);
437        }
438
439        public void setSource(Object record, View source) {
440            AccessibilityRecordCompatIcs.setSource(record, source);
441        }
442
443        public void setToIndex(Object record, int toIndex) {
444            AccessibilityRecordCompatIcs.setToIndex(record, toIndex);
445        }
446    }
447
448    static {
449        if (Build.VERSION.SDK_INT >= 14) { // ICS
450            IMPL = new AccessibilityRecordIcsImpl();
451        } else {
452            IMPL = new AccessibilityRecordStubImpl();
453        }
454    }
455
456    private static final AccessibilityRecordImpl IMPL;
457
458    private final Object mRecord;
459
460    /*
461     * Hide constructor from clients.
462     */
463    public AccessibilityRecordCompat(Object record) {
464        mRecord = record;
465    }
466
467    /**
468     * @return The wrapped implementation.
469     */
470    public Object getImpl() {
471        return mRecord;
472    }
473
474    /**
475     * Returns a cached instance if such is available or a new one is
476     * instantiated. The instance is initialized with data from the
477     * given record.
478     *
479     * @return An instance.
480     */
481    public static AccessibilityRecordCompat obtain(AccessibilityRecordCompat record) {
482       return new AccessibilityRecordCompat(IMPL.obtain(record.mRecord));
483    }
484
485    /**
486     * Returns a cached instance if such is available or a new one is
487     * instantiated.
488     *
489     * @return An instance.
490     */
491    public static AccessibilityRecordCompat obtain() {
492        return new AccessibilityRecordCompat(IMPL.obtain());
493    }
494
495    /**
496     * Sets the event source.
497     *
498     * @param source The source.
499     *
500     * @throws IllegalStateException If called from an AccessibilityService.
501     */
502    public void setSource(View source) {
503        IMPL.setSource(mRecord, source);
504    }
505
506    /**
507     * Gets the {@link android.view.accessibility.AccessibilityNodeInfo} of
508     * the event source.
509     * <p>
510     * <strong>Note:</strong> It is a client responsibility to recycle the
511     * received info by calling
512     * {@link android.view.accessibility.AccessibilityNodeInfo#recycle()
513     * AccessibilityNodeInfo#recycle()} to avoid creating of multiple instances.
514     *</p>
515     *
516     * @return The info of the source.
517     */
518    public AccessibilityNodeInfoCompat getSource() {
519        return new AccessibilityNodeInfoCompat(IMPL.getSource(mRecord));
520    }
521
522    /**
523     * Gets the id of the window from which the event comes from.
524     *
525     * @return The window id.
526     */
527    public int getWindowId() {
528        return IMPL.getWindowId(mRecord);
529    }
530
531    /**
532     * Gets if the source is checked.
533     *
534     * @return True if the view is checked, false otherwise.
535     */
536    public boolean isChecked() {
537        return IMPL.isChecked(mRecord);
538    }
539
540    /**
541     * Sets if the source is checked.
542     *
543     * @param isChecked True if the view is checked, false otherwise.
544     *
545     * @throws IllegalStateException If called from an AccessibilityService.
546     */
547    public void setChecked(boolean isChecked) {
548        IMPL.setChecked(mRecord, isChecked);
549    }
550
551    /**
552     * Gets if the source is enabled.
553     *
554     * @return True if the view is enabled, false otherwise.
555     */
556    public boolean isEnabled() {
557        return IMPL.isEnabled(mRecord);
558    }
559
560    /**
561     * Sets if the source is enabled.
562     *
563     * @param isEnabled True if the view is enabled, false otherwise.
564     *
565     * @throws IllegalStateException If called from an AccessibilityService.
566     */
567    public void setEnabled(boolean isEnabled) {
568        IMPL.setEnabled(mRecord, isEnabled);
569    }
570
571    /**
572     * Gets if the source is a password field.
573     *
574     * @return True if the view is a password field, false otherwise.
575     */
576    public boolean isPassword() {
577        return IMPL.isPassword(mRecord);
578    }
579
580    /**
581     * Sets if the source is a password field.
582     *
583     * @param isPassword True if the view is a password field, false otherwise.
584     *
585     * @throws IllegalStateException If called from an AccessibilityService.
586     */
587    public void setPassword(boolean isPassword) {
588        IMPL.setPassword(mRecord, isPassword);
589    }
590
591    /**
592     * Gets if the source is taking the entire screen.
593     *
594     * @return True if the source is full screen, false otherwise.
595     */
596    public boolean isFullScreen() {
597        return IMPL.isFullScreen(mRecord);
598    }
599
600    /**
601     * Sets if the source is taking the entire screen.
602     *
603     * @param isFullScreen True if the source is full screen, false otherwise.
604     *
605     * @throws IllegalStateException If called from an AccessibilityService.
606     */
607    public void setFullScreen(boolean isFullScreen) {
608        IMPL.setFullScreen(mRecord, isFullScreen);
609    }
610
611    /**
612     * Gets if the source is scrollable.
613     *
614     * @return True if the source is scrollable, false otherwise.
615     */
616    public boolean isScrollable() {
617        return IMPL.isScrollable(mRecord);
618    }
619
620    /**
621     * Sets if the source is scrollable.
622     *
623     * @param scrollable True if the source is scrollable, false otherwise.
624     *
625     * @throws IllegalStateException If called from an AccessibilityService.
626     */
627    public void setScrollable(boolean scrollable) {
628        IMPL.setScrollable(mRecord, scrollable);
629    }
630
631    /**
632     * Gets the number of items that can be visited.
633     *
634     * @return The number of items.
635     */
636    public int getItemCount() {
637        return IMPL.getItemCount(mRecord);
638    }
639
640    /**
641     * Sets the number of items that can be visited.
642     *
643     * @param itemCount The number of items.
644     *
645     * @throws IllegalStateException If called from an AccessibilityService.
646     */
647    public void setItemCount(int itemCount) {
648        IMPL.setItemCount(mRecord, itemCount);
649    }
650
651    /**
652     * Gets the index of the source in the list of items the can be visited.
653     *
654     * @return The current item index.
655     */
656    public int getCurrentItemIndex() {
657        return IMPL.getCurrentItemIndex(mRecord);
658    }
659
660    /**
661     * Sets the index of the source in the list of items that can be visited.
662     *
663     * @param currentItemIndex The current item index.
664     *
665     * @throws IllegalStateException If called from an AccessibilityService.
666     */
667    public void setCurrentItemIndex(int currentItemIndex) {
668        IMPL.setCurrentItemIndex(mRecord, currentItemIndex);
669    }
670
671    /**
672     * Gets the index of the first character of the changed sequence,
673     * or the beginning of a text selection or the index of the first
674     * visible item when scrolling.
675     *
676     * @return The index of the first character or selection
677     *        start or the first visible item.
678     */
679    public int getFromIndex() {
680        return IMPL.getFromIndex(mRecord);
681    }
682
683    /**
684     * Sets the index of the first character of the changed sequence
685     * or the beginning of a text selection or the index of the first
686     * visible item when scrolling.
687     *
688     * @param fromIndex The index of the first character or selection
689     *        start or the first visible item.
690     *
691     * @throws IllegalStateException If called from an AccessibilityService.
692     */
693    public void setFromIndex(int fromIndex) {
694        IMPL.setFromIndex(mRecord, fromIndex);
695    }
696
697    /**
698     * Gets the index of text selection end or the index of the last
699     * visible item when scrolling.
700     *
701     * @return The index of selection end or last item index.
702     */
703    public int getToIndex() {
704        return IMPL.getToIndex(mRecord);
705    }
706
707    /**
708     * Sets the index of text selection end or the index of the last
709     * visible item when scrolling.
710     *
711     * @param toIndex The index of selection end or last item index.
712     */
713    public void setToIndex(int toIndex) {
714        IMPL.setToIndex(mRecord, toIndex);
715    }
716
717    /**
718     * Gets the scroll offset of the source left edge in pixels.
719     *
720     * @return The scroll.
721     */
722    public int getScrollX() {
723        return IMPL.getScrollX(mRecord);
724    }
725
726    /**
727     * Sets the scroll offset of the source left edge in pixels.
728     *
729     * @param scrollX The scroll.
730     */
731    public void setScrollX(int scrollX) {
732        IMPL.setScrollX(mRecord, scrollX);
733    }
734
735    /**
736     * Gets the scroll offset of the source top edge in pixels.
737     *
738     * @return The scroll.
739     */
740    public int getScrollY() {
741        return IMPL.getScrollY(mRecord);
742    }
743
744    /**
745     * Sets the scroll offset of the source top edge in pixels.
746     *
747     * @param scrollY The scroll.
748     */
749    public void setScrollY(int scrollY) {
750        IMPL.setScrollY(mRecord, scrollY);
751    }
752
753//  TODO: Uncomment when these APIs become public
754//    /**
755//     * Gets the max scroll offset of the source left edge in pixels.
756//     *
757//     * @return The max scroll.
758//     */
759//    public int getMaxScrollX() {
760//        return IMPL.getMaxScrollX(mRecord);
761//    }
762//    /**
763//     * Sets the max scroll offset of the source left edge in pixels.
764//     *
765//     * @param maxScrollX The max scroll.
766//     */
767//    public void setMaxScrollX(int maxScrollX) {
768//        IMPL.setMaxScrollX(mRecord, maxScrollX);
769//    }
770//
771//    /**
772//     * Gets the max scroll offset of the source top edge in pixels.
773//     *
774//     * @return The max scroll.
775//     */
776//    public int getMaxScrollY() {
777//        return IMPL.getMaxScrollY(mRecord);
778//    }
779//
780//    /**
781//     * Sets the max scroll offset of the source top edge in pixels.
782//     *
783//     * @param maxScrollY The max scroll.
784//     */
785//    public void setMaxScrollY(int maxScrollY) {
786//        IMPL.setMaxScrollY(mRecord, maxScrollY);
787//    }
788
789    /**
790     * Gets the number of added characters.
791     *
792     * @return The number of added characters.
793     */
794    public int getAddedCount() {
795        return IMPL.getAddedCount(mRecord);
796    }
797
798    /**
799     * Sets the number of added characters.
800     *
801     * @param addedCount The number of added characters.
802     *
803     * @throws IllegalStateException If called from an AccessibilityService.
804     */
805    public void setAddedCount(int addedCount) {
806        IMPL.setAddedCount(mRecord, addedCount);
807    }
808
809    /**
810     * Gets the number of removed characters.
811     *
812     * @return The number of removed characters.
813     */
814    public int getRemovedCount() {
815        return IMPL.getRemovedCount(mRecord);
816    }
817
818    /**
819     * Sets the number of removed characters.
820     *
821     * @param removedCount The number of removed characters.
822     *
823     * @throws IllegalStateException If called from an AccessibilityService.
824     */
825    public void setRemovedCount(int removedCount) {
826        IMPL.setRemovedCount(mRecord, removedCount);
827    }
828
829    /**
830     * Gets the class name of the source.
831     *
832     * @return The class name.
833     */
834    public CharSequence getClassName() {
835        return IMPL.getClassName(mRecord);
836    }
837
838    /**
839     * Sets the class name of the source.
840     *
841     * @param className The lass name.
842     *
843     * @throws IllegalStateException If called from an AccessibilityService.
844     */
845    public void setClassName(CharSequence className) {
846        IMPL.setClassName(mRecord, className);
847    }
848
849    /**
850     * Gets the text of the event. The index in the list represents the priority
851     * of the text. Specifically, the lower the index the higher the priority.
852     *
853     * @return The text.
854     */
855    public List<CharSequence> getText() {
856        return IMPL.getText(mRecord);
857    }
858
859    /**
860     * Sets the text before a change.
861     *
862     * @return The text before the change.
863     */
864    public CharSequence getBeforeText() {
865        return IMPL.getBeforeText(mRecord);
866    }
867
868    /**
869     * Sets the text before a change.
870     *
871     * @param beforeText The text before the change.
872     *
873     * @throws IllegalStateException If called from an AccessibilityService.
874     */
875    public void setBeforeText(CharSequence beforeText) {
876        IMPL.setBeforeText(mRecord, beforeText);
877    }
878
879    /**
880     * Gets the description of the source.
881     *
882     * @return The description.
883     */
884    public CharSequence getContentDescription() {
885        return IMPL.getContentDescription(mRecord);
886    }
887
888    /**
889     * Sets the description of the source.
890     *
891     * @param contentDescription The description.
892     *
893     * @throws IllegalStateException If called from an AccessibilityService.
894     */
895    public void setContentDescription(CharSequence contentDescription) {
896        IMPL.setContentDescription(mRecord, contentDescription);
897    }
898
899    /**
900     * Gets the {@link Parcelable} data.
901     *
902     * @return The parcelable data.
903     */
904    public Parcelable getParcelableData() {
905        return IMPL.getParcelableData(mRecord);
906    }
907
908    /**
909     * Sets the {@link Parcelable} data of the event.
910     *
911     * @param parcelableData The parcelable data.
912     *
913     * @throws IllegalStateException If called from an AccessibilityService.
914     */
915    public void setParcelableData(Parcelable parcelableData) {
916        IMPL.setParcelableData(mRecord, parcelableData);
917    }
918
919    /**
920     * Return an instance back to be reused.
921     * <p>
922     * <strong>Note:</strong> You must not touch the object after calling this
923     * function.
924     * </p>
925     *
926     * @throws IllegalStateException If the record is already recycled.
927     */
928    public void recycle() {
929        IMPL.recycle(mRecord);
930    }
931
932    @Override
933    public int hashCode() {
934        return (mRecord == null) ? 0 : mRecord.hashCode();
935    }
936
937
938    @Override
939    public boolean equals(Object obj) {
940        if (this == obj) {
941            return true;
942        }
943        if (obj == null) {
944            return false;
945        }
946        if (getClass() != obj.getClass()) {
947            return false;
948        }
949        AccessibilityRecordCompat other = (AccessibilityRecordCompat) obj;
950        if (mRecord == null) {
951            if (other.mRecord != null) {
952                return false;
953            }
954        } else if (!mRecord.equals(other.mRecord)) {
955            return false;
956        }
957        return true;
958    }
959}
960