1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.contentcapture;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.assist.AssistStructure;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.Parcel;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewParent;
import android.view.ViewStructure;
import android.view.ViewStructure.HtmlInfo.Builder;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
import com.android.internal.util.Preconditions;
//TODO(b/122484602): add javadocs / implement Parcelable / implement
//TODO(b/122484602): for now it's extending ViewNode directly as it needs most of its properties,
// but it might be better to create a common, abstract android.view.ViewNode class that both extend
// instead
/** @hide */
@SystemApi
@TestApi
public final class ViewNode extends AssistStructure.ViewNode {
private static final String TAG = ViewNode.class.getSimpleName();
private static final long FLAGS_HAS_TEXT = 1L << 0;
private static final long FLAGS_HAS_COMPLEX_TEXT = 1L << 1;
private static final long FLAGS_VISIBILITY_MASK = View.VISIBLE | View.INVISIBLE | View.GONE;
private static final long FLAGS_HAS_CLASSNAME = 1L << 4;
private static final long FLAGS_HAS_AUTOFILL_ID = 1L << 5;
private static final long FLAGS_HAS_AUTOFILL_PARENT_ID = 1L << 6;
private static final long FLAGS_HAS_ID = 1L << 7;
private static final long FLAGS_HAS_LARGE_COORDS = 1L << 8;
private static final long FLAGS_HAS_SCROLL = 1L << 9;
private static final long FLAGS_ASSIST_BLOCKED = 1L << 10;
private static final long FLAGS_DISABLED = 1L << 11;
private static final long FLAGS_CLICKABLE = 1L << 12;
private static final long FLAGS_LONG_CLICKABLE = 1L << 13;
private static final long FLAGS_CONTEXT_CLICKABLE = 1L << 14;
private static final long FLAGS_FOCUSABLE = 1L << 15;
private static final long FLAGS_FOCUSED = 1L << 16;
private static final long FLAGS_ACCESSIBILITY_FOCUSED = 1L << 17;
private static final long FLAGS_CHECKABLE = 1L << 18;
private static final long FLAGS_CHECKED = 1L << 19;
private static final long FLAGS_SELECTED = 1L << 20;
private static final long FLAGS_ACTIVATED = 1L << 21;
private static final long FLAGS_OPAQUE = 1L << 22;
private static final long FLAGS_HAS_CONTENT_DESCRIPTION = 1L << 23;
private static final long FLAGS_HAS_EXTRAS = 1L << 24;
private static final long FLAGS_HAS_LOCALE_LIST = 1L << 25;
private static final long FLAGS_HAS_INPUT_TYPE = 1L << 26;
private static final long FLAGS_HAS_MIN_TEXT_EMS = 1L << 27;
private static final long FLAGS_HAS_MAX_TEXT_EMS = 1L << 28;
private static final long FLAGS_HAS_MAX_TEXT_LENGTH = 1L << 29;
private static final long FLAGS_HAS_TEXT_ID_ENTRY = 1L << 30;
private static final long FLAGS_HAS_AUTOFILL_TYPE = 1L << 31;
private static final long FLAGS_HAS_AUTOFILL_VALUE = 1L << 32;
private static final long FLAGS_HAS_AUTOFILL_HINTS = 1L << 33;
private static final long FLAGS_HAS_AUTOFILL_OPTIONS = 1L << 34;
/** Flags used to optimize what's written to the parcel */
private long mFlags;
private AutofillId mParentAutofillId;
private AutofillId mAutofillId;
private ViewNodeText mText;
private String mClassName;
private int mId = View.NO_ID;
private String mIdPackage;
private String mIdType;
private String mIdEntry;
private int mX;
private int mY;
private int mScrollX;
private int mScrollY;
private int mWidth;
private int mHeight;
private CharSequence mContentDescription;
private Bundle mExtras;
private LocaleList mLocaleList;
private int mInputType;
private int mMinEms = -1;
private int mMaxEms = -1;
private int mMaxLength = -1;
private String mTextIdEntry;
private @View.AutofillType int mAutofillType = View.AUTOFILL_TYPE_NONE;
private String[] mAutofillHints;
private AutofillValue mAutofillValue;
private CharSequence[] mAutofillOptions;
/** @hide */
public ViewNode() {
}
private ViewNode(long nodeFlags, @NonNull Parcel parcel) {
mFlags = nodeFlags;
if ((nodeFlags & FLAGS_HAS_AUTOFILL_ID) != 0) {
mAutofillId = parcel.readParcelable(null);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_PARENT_ID) != 0) {
mParentAutofillId = parcel.readParcelable(null);
}
if ((nodeFlags & FLAGS_HAS_TEXT) != 0) {
mText = new ViewNodeText(parcel, (nodeFlags & FLAGS_HAS_COMPLEX_TEXT) == 0);
}
if ((nodeFlags & FLAGS_HAS_CLASSNAME) != 0) {
mClassName = parcel.readString();
}
if ((nodeFlags & FLAGS_HAS_ID) != 0) {
mId = parcel.readInt();
if (mId != View.NO_ID) {
mIdEntry = parcel.readString();
if (mIdEntry != null) {
mIdType = parcel.readString();
mIdPackage = parcel.readString();
}
}
}
if ((nodeFlags & FLAGS_HAS_LARGE_COORDS) != 0) {
mX = parcel.readInt();
mY = parcel.readInt();
mWidth = parcel.readInt();
mHeight = parcel.readInt();
} else {
int val = parcel.readInt();
mX = val & 0x7fff;
mY = (val >> 16) & 0x7fff;
val = parcel.readInt();
mWidth = val & 0x7fff;
mHeight = (val >> 16) & 0x7fff;
}
if ((nodeFlags & FLAGS_HAS_SCROLL) != 0) {
mScrollX = parcel.readInt();
mScrollY = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_CONTENT_DESCRIPTION) != 0) {
mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
}
if ((nodeFlags & FLAGS_HAS_EXTRAS) != 0) {
mExtras = parcel.readBundle();
}
if ((nodeFlags & FLAGS_HAS_LOCALE_LIST) != 0) {
mLocaleList = parcel.readParcelable(null);
}
if ((nodeFlags & FLAGS_HAS_INPUT_TYPE) != 0) {
mInputType = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_MIN_TEXT_EMS) != 0) {
mMinEms = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_MAX_TEXT_EMS) != 0) {
mMaxEms = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_MAX_TEXT_LENGTH) != 0) {
mMaxLength = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_TEXT_ID_ENTRY) != 0) {
mTextIdEntry = parcel.readString();
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_TYPE) != 0) {
mAutofillType = parcel.readInt();
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_HINTS) != 0) {
mAutofillHints = parcel.readStringArray();
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_VALUE) != 0) {
mAutofillValue = parcel.readParcelable(null);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_OPTIONS) != 0) {
mAutofillOptions = parcel.readCharSequenceArray();
}
}
/**
* Returns the {@link AutofillId} of this view's parent, if the parent is also part of the
* screen observation tree.
*/
@Nullable
public AutofillId getParentAutofillId() {
return mParentAutofillId;
}
@Override
public AutofillId getAutofillId() {
return mAutofillId;
}
@Override
public CharSequence getText() {
return mText != null ? mText.mText : null;
}
@Override
public String getClassName() {
return mClassName;
}
@Override
public int getId() {
return mId;
}
@Override
public String getIdPackage() {
return mIdPackage;
}
@Override
public String getIdType() {
return mIdType;
}
@Override
public String getIdEntry() {
return mIdEntry;
}
@Override
public int getLeft() {
return mX;
}
@Override
public int getTop() {
return mY;
}
@Override
public int getScrollX() {
return mScrollX;
}
@Override
public int getScrollY() {
return mScrollY;
}
@Override
public int getWidth() {
return mWidth;
}
@Override
public int getHeight() {
return mHeight;
}
@Override
public boolean isAssistBlocked() {
return (mFlags & FLAGS_ASSIST_BLOCKED) != 0;
}
@Override
public boolean isEnabled() {
return (mFlags & FLAGS_DISABLED) == 0;
}
@Override
public boolean isClickable() {
return (mFlags & FLAGS_CLICKABLE) != 0;
}
@Override
public boolean isLongClickable() {
return (mFlags & FLAGS_LONG_CLICKABLE) != 0;
}
@Override
public boolean isContextClickable() {
return (mFlags & FLAGS_CONTEXT_CLICKABLE) != 0;
}
@Override
public boolean isFocusable() {
return (mFlags & FLAGS_FOCUSABLE) != 0;
}
@Override
public boolean isFocused() {
return (mFlags & FLAGS_FOCUSED) != 0;
}
@Override
public boolean isAccessibilityFocused() {
return (mFlags & FLAGS_ACCESSIBILITY_FOCUSED) != 0;
}
@Override
public boolean isCheckable() {
return (mFlags & FLAGS_CHECKABLE) != 0;
}
@Override
public boolean isChecked() {
return (mFlags & FLAGS_CHECKED) != 0;
}
@Override
public boolean isSelected() {
return (mFlags & FLAGS_SELECTED) != 0;
}
@Override
public boolean isActivated() {
return (mFlags & FLAGS_ACTIVATED) != 0;
}
@Override
public boolean isOpaque() {
return (mFlags & FLAGS_OPAQUE) != 0;
}
@Override
public CharSequence getContentDescription() {
return mContentDescription;
}
@Override
public Bundle getExtras() {
return mExtras;
}
@Override
public String getHint() {
return mText != null ? mText.mHint : null;
}
@Override
public int getTextSelectionStart() {
return mText != null ? mText.mTextSelectionStart : -1;
}
@Override
public int getTextSelectionEnd() {
return mText != null ? mText.mTextSelectionEnd : -1;
}
@Override
public int getTextColor() {
return mText != null ? mText.mTextColor : TEXT_COLOR_UNDEFINED;
}
@Override
public int getTextBackgroundColor() {
return mText != null ? mText.mTextBackgroundColor : TEXT_COLOR_UNDEFINED;
}
@Override
public float getTextSize() {
return mText != null ? mText.mTextSize : 0;
}
@Override
public int getTextStyle() {
return mText != null ? mText.mTextStyle : 0;
}
@Override
public int[] getTextLineCharOffsets() {
return mText != null ? mText.mLineCharOffsets : null;
}
@Override
public int[] getTextLineBaselines() {
return mText != null ? mText.mLineBaselines : null;
}
@Override
public int getVisibility() {
return (int) (mFlags & FLAGS_VISIBILITY_MASK);
}
@Override
public int getInputType() {
return mInputType;
}
@Override
public int getMinTextEms() {
return mMinEms;
}
@Override
public int getMaxTextEms() {
return mMaxEms;
}
@Override
public int getMaxTextLength() {
return mMaxLength;
}
@Override
public String getTextIdEntry() {
return mTextIdEntry;
}
@Override
public @View.AutofillType int getAutofillType() {
return mAutofillType;
}
@Override
@Nullable public String[] getAutofillHints() {
return mAutofillHints;
}
@Override
@Nullable public AutofillValue getAutofillValue() {
return mAutofillValue;
}
@Override
@Nullable public CharSequence[] getAutofillOptions() {
return mAutofillOptions;
}
@Override
public LocaleList getLocaleList() {
return mLocaleList;
}
private void writeSelfToParcel(@NonNull Parcel parcel, int parcelFlags) {
long nodeFlags = mFlags;
if (mAutofillId != null) {
nodeFlags |= FLAGS_HAS_AUTOFILL_ID;
}
if (mParentAutofillId != null) {
nodeFlags |= FLAGS_HAS_AUTOFILL_PARENT_ID;
}
if (mText != null) {
nodeFlags |= FLAGS_HAS_TEXT;
if (!mText.isSimple()) {
nodeFlags |= FLAGS_HAS_COMPLEX_TEXT;
}
}
if (mClassName != null) {
nodeFlags |= FLAGS_HAS_CLASSNAME;
}
if (mId != View.NO_ID) {
nodeFlags |= FLAGS_HAS_ID;
}
if ((mX & ~0x7fff) != 0 || (mY & ~0x7fff) != 0
|| (mWidth & ~0x7fff) != 0 | (mHeight & ~0x7fff) != 0) {
nodeFlags |= FLAGS_HAS_LARGE_COORDS;
}
if (mScrollX != 0 || mScrollY != 0) {
nodeFlags |= FLAGS_HAS_SCROLL;
}
if (mContentDescription != null) {
nodeFlags |= FLAGS_HAS_CONTENT_DESCRIPTION;
}
if (mExtras != null) {
nodeFlags |= FLAGS_HAS_EXTRAS;
}
if (mLocaleList != null) {
nodeFlags |= FLAGS_HAS_LOCALE_LIST;
}
if (mInputType != 0) {
nodeFlags |= FLAGS_HAS_INPUT_TYPE;
}
if (mMinEms > -1) {
nodeFlags |= FLAGS_HAS_MIN_TEXT_EMS;
}
if (mMaxEms > -1) {
nodeFlags |= FLAGS_HAS_MAX_TEXT_EMS;
}
if (mMaxLength > -1) {
nodeFlags |= FLAGS_HAS_MAX_TEXT_LENGTH;
}
if (mTextIdEntry != null) {
nodeFlags |= FLAGS_HAS_TEXT_ID_ENTRY;
}
if (mAutofillValue != null) {
nodeFlags |= FLAGS_HAS_AUTOFILL_VALUE;
}
if (mAutofillType != View.AUTOFILL_TYPE_NONE) {
nodeFlags |= FLAGS_HAS_AUTOFILL_TYPE;
}
if (mAutofillHints != null) {
nodeFlags |= FLAGS_HAS_AUTOFILL_HINTS;
}
if (mAutofillOptions != null) {
nodeFlags |= FLAGS_HAS_AUTOFILL_OPTIONS;
}
parcel.writeLong(nodeFlags);
if ((nodeFlags & FLAGS_HAS_AUTOFILL_ID) != 0) {
parcel.writeParcelable(mAutofillId, parcelFlags);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_PARENT_ID) != 0) {
parcel.writeParcelable(mParentAutofillId, parcelFlags);
}
if ((nodeFlags & FLAGS_HAS_TEXT) != 0) {
mText.writeToParcel(parcel, (nodeFlags & FLAGS_HAS_COMPLEX_TEXT) == 0);
}
if ((nodeFlags & FLAGS_HAS_CLASSNAME) != 0) {
parcel.writeString(mClassName);
}
if ((nodeFlags & FLAGS_HAS_ID) != 0) {
parcel.writeInt(mId);
if (mId != View.NO_ID) {
parcel.writeString(mIdEntry);
if (mIdEntry != null) {
parcel.writeString(mIdType);
parcel.writeString(mIdPackage);
}
}
}
if ((nodeFlags & FLAGS_HAS_LARGE_COORDS) != 0) {
parcel.writeInt(mX);
parcel.writeInt(mY);
parcel.writeInt(mWidth);
parcel.writeInt(mHeight);
} else {
parcel.writeInt((mY << 16) | mX);
parcel.writeInt((mHeight << 16) | mWidth);
}
if ((nodeFlags & FLAGS_HAS_SCROLL) != 0) {
parcel.writeInt(mScrollX);
parcel.writeInt(mScrollY);
}
if ((nodeFlags & FLAGS_HAS_CONTENT_DESCRIPTION) != 0) {
TextUtils.writeToParcel(mContentDescription, parcel, 0);
}
if ((nodeFlags & FLAGS_HAS_EXTRAS) != 0) {
parcel.writeBundle(mExtras);
}
if ((nodeFlags & FLAGS_HAS_LOCALE_LIST) != 0) {
parcel.writeParcelable(mLocaleList, 0);
}
if ((nodeFlags & FLAGS_HAS_INPUT_TYPE) != 0) {
parcel.writeInt(mInputType);
}
if ((nodeFlags & FLAGS_HAS_MIN_TEXT_EMS) != 0) {
parcel.writeInt(mMinEms);
}
if ((nodeFlags & FLAGS_HAS_MAX_TEXT_EMS) != 0) {
parcel.writeInt(mMaxEms);
}
if ((nodeFlags & FLAGS_HAS_MAX_TEXT_LENGTH) != 0) {
parcel.writeInt(mMaxLength);
}
if ((nodeFlags & FLAGS_HAS_TEXT_ID_ENTRY) != 0) {
parcel.writeString(mTextIdEntry);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_TYPE) != 0) {
parcel.writeInt(mAutofillType);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_HINTS) != 0) {
parcel.writeStringArray(mAutofillHints);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_VALUE) != 0) {
parcel.writeParcelable(mAutofillValue, 0);
}
if ((nodeFlags & FLAGS_HAS_AUTOFILL_OPTIONS) != 0) {
parcel.writeCharSequenceArray(mAutofillOptions);
}
}
/** @hide */
@TestApi
public static void writeToParcel(@NonNull Parcel parcel, @Nullable ViewNode node, int flags) {
if (node == null) {
parcel.writeLong(0);
} else {
node.writeSelfToParcel(parcel, flags);
}
}
/** @hide */
@TestApi
public static @Nullable ViewNode readFromParcel(@NonNull Parcel parcel) {
final long nodeFlags = parcel.readLong();
return nodeFlags == 0 ? null : new ViewNode(nodeFlags, parcel);
}
/** @hide */
@TestApi
public static final class ViewStructureImpl extends ViewStructure {
final ViewNode mNode = new ViewNode();
/** @hide */
@TestApi
public ViewStructureImpl(@NonNull View view) {
mNode.mAutofillId = Preconditions.checkNotNull(view).getAutofillId();
final ViewParent parent = view.getParent();
if (parent instanceof View) {
mNode.mParentAutofillId = ((View) parent).getAutofillId();
}
}
/** @hide */
@TestApi
public ViewStructureImpl(@NonNull AutofillId parentId, long virtualId, int sessionId) {
mNode.mParentAutofillId = Preconditions.checkNotNull(parentId);
mNode.mAutofillId = new AutofillId(parentId, virtualId, sessionId);
}
/** @hide */
@TestApi
public ViewNode getNode() {
return mNode;
}
@Override
public void setId(int id, String packageName, String typeName, String entryName) {
mNode.mId = id;
mNode.mIdPackage = packageName;
mNode.mIdType = typeName;
mNode.mIdEntry = entryName;
}
@Override
public void setDimens(int left, int top, int scrollX, int scrollY, int width, int height) {
mNode.mX = left;
mNode.mY = top;
mNode.mScrollX = scrollX;
mNode.mScrollY = scrollY;
mNode.mWidth = width;
mNode.mHeight = height;
}
@Override
public void setTransformation(Matrix matrix) {
Log.w(TAG, "setTransformation() is not supported");
}
@Override
public void setElevation(float elevation) {
Log.w(TAG, "setElevation() is not supported");
}
@Override
public void setAlpha(float alpha) {
Log.w(TAG, "setAlpha() is not supported");
}
@Override
public void setVisibility(int visibility) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_VISIBILITY_MASK)
| (visibility & FLAGS_VISIBILITY_MASK);
}
@Override
public void setAssistBlocked(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_ASSIST_BLOCKED)
| (state ? FLAGS_ASSIST_BLOCKED : 0);
}
@Override
public void setEnabled(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_DISABLED) | (state ? 0 : FLAGS_DISABLED);
}
@Override
public void setClickable(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_CLICKABLE) | (state ? FLAGS_CLICKABLE : 0);
}
@Override
public void setLongClickable(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_LONG_CLICKABLE)
| (state ? FLAGS_LONG_CLICKABLE : 0);
}
@Override
public void setContextClickable(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_CONTEXT_CLICKABLE)
| (state ? FLAGS_CONTEXT_CLICKABLE : 0);
}
@Override
public void setFocusable(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_FOCUSABLE) | (state ? FLAGS_FOCUSABLE : 0);
}
@Override
public void setFocused(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_FOCUSED) | (state ? FLAGS_FOCUSED : 0);
}
@Override
public void setAccessibilityFocused(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_ACCESSIBILITY_FOCUSED)
| (state ? FLAGS_ACCESSIBILITY_FOCUSED : 0);
}
@Override
public void setCheckable(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_CHECKABLE) | (state ? FLAGS_CHECKABLE : 0);
}
@Override
public void setChecked(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_CHECKED) | (state ? FLAGS_CHECKED : 0);
}
@Override
public void setSelected(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_SELECTED) | (state ? FLAGS_SELECTED : 0);
}
@Override
public void setActivated(boolean state) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_ACTIVATED) | (state ? FLAGS_ACTIVATED : 0);
}
@Override
public void setOpaque(boolean opaque) {
mNode.mFlags = (mNode.mFlags & ~FLAGS_OPAQUE) | (opaque ? FLAGS_OPAQUE : 0);
}
@Override
public void setClassName(String className) {
mNode.mClassName = className;
}
@Override
public void setContentDescription(CharSequence contentDescription) {
mNode.mContentDescription = contentDescription;
}
@Override
public void setText(CharSequence text) {
final ViewNodeText t = getNodeText();
t.mText = TextUtils.trimNoCopySpans(text);
t.mTextSelectionStart = t.mTextSelectionEnd = -1;
}
@Override
public void setText(CharSequence text, int selectionStart, int selectionEnd) {
final ViewNodeText t = getNodeText();
t.mText = TextUtils.trimNoCopySpans(text);
t.mTextSelectionStart = selectionStart;
t.mTextSelectionEnd = selectionEnd;
}
@Override
public void setTextStyle(float size, int fgColor, int bgColor, int style) {
final ViewNodeText t = getNodeText();
t.mTextColor = fgColor;
t.mTextBackgroundColor = bgColor;
t.mTextSize = size;
t.mTextStyle = style;
}
@Override
public void setTextLines(int[] charOffsets, int[] baselines) {
final ViewNodeText t = getNodeText();
t.mLineCharOffsets = charOffsets;
t.mLineBaselines = baselines;
}
@Override
public void setTextIdEntry(String entryName) {
mNode.mTextIdEntry = Preconditions.checkNotNull(entryName);
}
@Override
public void setHint(CharSequence hint) {
getNodeText().mHint = hint != null ? hint.toString() : null;
}
@Override
public CharSequence getText() {
return mNode.getText();
}
@Override
public int getTextSelectionStart() {
return mNode.getTextSelectionStart();
}
@Override
public int getTextSelectionEnd() {
return mNode.getTextSelectionEnd();
}
@Override
public CharSequence getHint() {
return mNode.getHint();
}
@Override
public Bundle getExtras() {
if (mNode.mExtras != null) {
return mNode.mExtras;
}
mNode.mExtras = new Bundle();
return mNode.mExtras;
}
@Override
public boolean hasExtras() {
return mNode.mExtras != null;
}
@Override
public void setChildCount(int num) {
Log.w(TAG, "setChildCount() is not supported");
}
@Override
public int addChildCount(int num) {
Log.w(TAG, "addChildCount() is not supported");
return 0;
}
@Override
public int getChildCount() {
Log.w(TAG, "getChildCount() is not supported");
return 0;
}
@Override
public ViewStructure newChild(int index) {
Log.w(TAG, "newChild() is not supported");
return null;
}
@Override
public ViewStructure asyncNewChild(int index) {
Log.w(TAG, "asyncNewChild() is not supported");
return null;
}
@Override
public AutofillId getAutofillId() {
return mNode.mAutofillId;
}
@Override
public void setAutofillId(AutofillId id) {
mNode.mAutofillId = Preconditions.checkNotNull(id);
}
@Override
public void setAutofillId(AutofillId parentId, int virtualId) {
mNode.mParentAutofillId = Preconditions.checkNotNull(parentId);
mNode.mAutofillId = new AutofillId(parentId, virtualId);
}
@Override
public void setAutofillType(@View.AutofillType int type) {
mNode.mAutofillType = type;
}
@Override
public void setAutofillHints(String[] hints) {
mNode.mAutofillHints = hints;
}
@Override
public void setAutofillValue(AutofillValue value) {
mNode.mAutofillValue = value;
}
@Override
public void setAutofillOptions(CharSequence[] options) {
mNode.mAutofillOptions = options;
}
@Override
public void setInputType(int inputType) {
mNode.mInputType = inputType;
}
@Override
public void setMinTextEms(int minEms) {
mNode.mMinEms = minEms;
}
@Override
public void setMaxTextEms(int maxEms) {
mNode.mMaxEms = maxEms;
}
@Override
public void setMaxTextLength(int maxLength) {
mNode.mMaxLength = maxLength;
}
@Override
public void setDataIsSensitive(boolean sensitive) {
Log.w(TAG, "setDataIsSensitive() is not supported");
}
@Override
public void asyncCommit() {
Log.w(TAG, "asyncCommit() is not supported");
}
@Override
public Rect getTempRect() {
Log.w(TAG, "getTempRect() is not supported");
return null;
}
@Override
public void setWebDomain(String domain) {
Log.w(TAG, "setWebDomain() is not supported");
}
@Override
public void setLocaleList(LocaleList localeList) {
mNode.mLocaleList = localeList;
}
@Override
public Builder newHtmlInfoBuilder(String tagName) {
Log.w(TAG, "newHtmlInfoBuilder() is not supported");
return null;
}
@Override
public void setHtmlInfo(HtmlInfo htmlInfo) {
Log.w(TAG, "setHtmlInfo() is not supported");
}
private ViewNodeText getNodeText() {
if (mNode.mText != null) {
return mNode.mText;
}
mNode.mText = new ViewNodeText();
return mNode.mText;
}
}
//TODO(b/122484602): copied 'as-is' from AssistStructure, except for writeSensitive
static final class ViewNodeText {
CharSequence mText;
float mTextSize;
int mTextStyle;
int mTextColor = ViewNode.TEXT_COLOR_UNDEFINED;
int mTextBackgroundColor = ViewNode.TEXT_COLOR_UNDEFINED;
int mTextSelectionStart;
int mTextSelectionEnd;
int[] mLineCharOffsets;
int[] mLineBaselines;
String mHint;
ViewNodeText() {
}
boolean isSimple() {
return mTextBackgroundColor == ViewNode.TEXT_COLOR_UNDEFINED
&& mTextSelectionStart == 0 && mTextSelectionEnd == 0
&& mLineCharOffsets == null && mLineBaselines == null && mHint == null;
}
ViewNodeText(Parcel in, boolean simple) {
mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
mTextSize = in.readFloat();
mTextStyle = in.readInt();
mTextColor = in.readInt();
if (!simple) {
mTextBackgroundColor = in.readInt();
mTextSelectionStart = in.readInt();
mTextSelectionEnd = in.readInt();
mLineCharOffsets = in.createIntArray();
mLineBaselines = in.createIntArray();
mHint = in.readString();
}
}
void writeToParcel(Parcel out, boolean simple) {
TextUtils.writeToParcel(mText, out, 0);
out.writeFloat(mTextSize);
out.writeInt(mTextStyle);
out.writeInt(mTextColor);
if (!simple) {
out.writeInt(mTextBackgroundColor);
out.writeInt(mTextSelectionStart);
out.writeInt(mTextSelectionEnd);
out.writeIntArray(mLineCharOffsets);
out.writeIntArray(mLineBaselines);
out.writeString(mHint);
}
}
}
}
|