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