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