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