| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; |
| 20 |
import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE; |
| 21 |
import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_STOP; |
| 22 |
|
| 23 |
import android.animation.LayoutTransition; |
| 24 |
import android.annotation.CallSuper; |
| 25 |
import android.annotation.IdRes; |
| 26 |
import android.annotation.NonNull; |
| 27 |
import android.annotation.Nullable; |
| 28 |
import android.annotation.TestApi; |
| 29 |
import android.annotation.UiThread; |
| 30 |
import android.compat.annotation.UnsupportedAppUsage; |
| 31 |
import android.content.ClipData; |
| 32 |
import android.content.Context; |
| 33 |
import android.content.Intent; |
| 34 |
import android.content.pm.PackageManager; |
| 35 |
import android.content.res.Configuration; |
| 36 |
import android.content.res.TypedArray; |
| 37 |
import android.graphics.Bitmap; |
| 38 |
import android.graphics.Canvas; |
| 39 |
import android.graphics.Color; |
| 40 |
import android.graphics.Insets; |
| 41 |
import android.graphics.Matrix; |
| 42 |
import android.graphics.Paint; |
| 43 |
import android.graphics.Point; |
| 44 |
import android.graphics.PointF; |
| 45 |
import android.graphics.Rect; |
| 46 |
import android.graphics.RectF; |
| 47 |
import android.graphics.Region; |
| 48 |
import android.os.Build; |
| 49 |
import android.os.Bundle; |
| 50 |
import android.os.Parcelable; |
| 51 |
import android.os.SystemClock; |
| 52 |
import android.util.AttributeSet; |
| 53 |
import android.util.IntArray; |
| 54 |
import android.util.Log; |
| 55 |
import android.util.Pools; |
| 56 |
import android.util.Pools.SynchronizedPool; |
| 57 |
import android.util.SparseArray; |
| 58 |
import android.util.SparseBooleanArray; |
| 59 |
import android.view.WindowInsetsAnimation.Bounds; |
| 60 |
import android.view.WindowInsetsAnimation.Callback.DispatchMode; |
| 61 |
import android.view.accessibility.AccessibilityEvent; |
| 62 |
import android.view.accessibility.AccessibilityManager; |
| 63 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 64 |
import android.view.animation.Animation; |
| 65 |
import android.view.animation.AnimationUtils; |
| 66 |
import android.view.animation.LayoutAnimationController; |
| 67 |
import android.view.animation.Transformation; |
| 68 |
import android.view.autofill.AutofillId; |
| 69 |
import android.view.autofill.Helper; |
| 70 |
import android.view.inspector.InspectableProperty; |
| 71 |
import android.view.inspector.InspectableProperty.EnumEntry; |
| 72 |
import android.view.translation.TranslationCapability; |
| 73 |
import android.view.translation.TranslationSpec.DataFormat; |
| 74 |
import android.view.translation.ViewTranslationRequest; |
| 75 |
import android.window.OnBackInvokedDispatcher; |
| 76 |
|
| 77 |
import com.android.internal.R; |
| 78 |
|
| 79 |
import java.util.ArrayList; |
| 80 |
import java.util.Collection; |
| 81 |
import java.util.Collections; |
| 82 |
import java.util.HashSet; |
| 83 |
import java.util.List; |
| 84 |
import java.util.Map; |
| 85 |
import java.util.function.Consumer; |
| 86 |
import java.util.function.Predicate; |
| 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 |
@UiThread |
| 136 |
public abstract class ViewGroup extends View implements ViewParent, ViewManager { |
| 137 |
private static final String TAG = "ViewGroup"; |
| 138 |
|
| 139 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 140 |
private static final boolean DBG = false; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
@UnsupportedAppUsage |
| 149 |
protected ArrayList<View> mDisappearingChildren; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768704) |
| 158 |
protected OnHierarchyChangeListener mOnHierarchyChangeListener; |
| 159 |
|
| 160 |
|
| 161 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 162 |
private View mFocused; |
| 163 |
|
| 164 |
|
| 165 |
private View mDefaultFocus; |
| 166 |
|
| 167 |
View mFocusedInCluster; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
private Transformation mChildTransformation; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
RectF mInvalidateRegion; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
Transformation mInvalidationTransformation; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
private View mCurrentDragChild; |
| 189 |
|
| 190 |
|
| 191 |
private DragEvent mCurrentDragStartEvent; |
| 192 |
private boolean mIsInterestedInDrag; |
| 193 |
private HashSet<View> mChildrenInterestedInDrag; |
| 194 |
|
| 195 |
|
| 196 |
private PointF mLocalPoint; |
| 197 |
|
| 198 |
|
| 199 |
private float[] mTempPosition; |
| 200 |
|
| 201 |
|
| 202 |
private Point mTempPoint; |
| 203 |
|
| 204 |
|
| 205 |
private Rect mTempRect; |
| 206 |
|
| 207 |
|
| 208 |
private int[] mTempLocation; |
| 209 |
|
| 210 |
|
| 211 |
private LayoutAnimationController mLayoutAnimationController; |
| 212 |
private Animation.AnimationListener mAnimationListener; |
| 213 |
|
| 214 |
|
| 215 |
@UnsupportedAppUsage |
| 216 |
private TouchTarget mFirstTouchTarget; |
| 217 |
|
| 218 |
|
| 219 |
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
| 220 |
@ViewDebug.ExportedProperty(category = "events") |
| 221 |
private long mLastTouchDownTime; |
| 222 |
@ViewDebug.ExportedProperty(category = "events") |
| 223 |
private int mLastTouchDownIndex = -1; |
| 224 |
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
| 225 |
@ViewDebug.ExportedProperty(category = "events") |
| 226 |
private float mLastTouchDownX; |
| 227 |
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
| 228 |
@ViewDebug.ExportedProperty(category = "events") |
| 229 |
private float mLastTouchDownY; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
private HoverTarget mFirstHoverTarget; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
private boolean mHoveredSelf; |
| 241 |
|
| 242 |
|
| 243 |
private View mTooltipHoverTarget; |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
private boolean mTooltipHoveredSelf; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
@ViewDebug.ExportedProperty(flagMapping = { |
| 256 |
@ViewDebug.FlagToString(mask = FLAG_CLIP_CHILDREN, equals = FLAG_CLIP_CHILDREN, |
| 257 |
name = "CLIP_CHILDREN"), |
| 258 |
@ViewDebug.FlagToString(mask = FLAG_CLIP_TO_PADDING, equals = FLAG_CLIP_TO_PADDING, |
| 259 |
name = "CLIP_TO_PADDING"), |
| 260 |
@ViewDebug.FlagToString(mask = FLAG_PADDING_NOT_NULL, equals = FLAG_PADDING_NOT_NULL, |
| 261 |
name = "PADDING_NOT_NULL") |
| 262 |
}, formatToHexString = true) |
| 263 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769411) |
| 264 |
protected int mGroupFlags; |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
private int mLayoutMode = LAYOUT_MODE_UNDEFINED; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
static final int FLAG_CLIP_CHILDREN = 0x1; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
private static final int FLAG_CLIP_TO_PADDING = 0x2; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
static final int FLAG_INVALIDATE_REQUIRED = 0x4; |
| 287 |
|
| 288 |
|
| 289 |
private static final int FLAG_RUN_ANIMATION = 0x8; |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
static final int FLAG_ANIMATION_DONE = 0x10; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
private static final int FLAG_PADDING_NOT_NULL = 0x20; |
| 299 |
|
| 300 |
|
| 301 |
@Deprecated |
| 302 |
private static final int FLAG_ANIMATION_CACHE = 0x40; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
static final int FLAG_OPTIMIZE_INVALIDATE = 0x80; |
| 309 |
|
| 310 |
|
| 311 |
static final int FLAG_CLEAR_TRANSFORMATION = 0x100; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
private static final int FLAG_NOTIFY_ANIMATION_LISTENER = 0x200; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769377) |
| 325 |
protected static final int FLAG_USE_CHILD_DRAWING_ORDER = 0x400; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769647) |
| 339 |
protected static final int FLAG_SUPPORT_STATIC_TRANSFORMATIONS = 0x800; |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
private static final int FLAG_ADD_STATES_FROM_CHILDREN = 0x2000; |
| 348 |
|
| 349 |
|
| 350 |
@Deprecated |
| 351 |
private static final int FLAG_ALWAYS_DRAWN_WITH_CACHE = 0x4000; |
| 352 |
|
| 353 |
|
| 354 |
@Deprecated |
| 355 |
private static final int FLAG_CHILDREN_DRAWN_WITH_CACHE = 0x8000; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
private static final int FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE = 0x10000; |
| 362 |
|
| 363 |
private static final int FLAG_MASK_FOCUSABILITY = 0x60000; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
public static final int FOCUS_BEFORE_DESCENDANTS = 0x20000; |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
public static final int FOCUS_AFTER_DESCENDANTS = 0x40000; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public static final int FOCUS_BLOCK_DESCENDANTS = 0x60000; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
private static final int[] DESCENDANT_FOCUSABILITY_FLAGS = |
| 385 |
{FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, |
| 386 |
FOCUS_BLOCK_DESCENDANTS}; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123983692) |
| 393 |
protected static final int FLAG_DISALLOW_INTERCEPT = 0x80000; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
private static final int FLAG_SPLIT_MOTION_EVENTS = 0x200000; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
private static final int FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW = 0x400000; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
private static final int FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET = 0x800000; |
| 414 |
|
| 415 |
static final int FLAG_IS_TRANSITION_GROUP = 0x1000000; |
| 416 |
|
| 417 |
static final int FLAG_IS_TRANSITION_GROUP_SET = 0x2000000; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
static final int FLAG_TOUCHSCREEN_BLOCKS_FOCUS = 0x4000000; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
private static final int FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED = 0x8000000; |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
private static final int FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED = 0x10000000; |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
private static final int FLAG_SHOW_CONTEXT_MENU_WITH_COORDS = 0x20000000; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
@UnsupportedAppUsage |
| 456 |
protected int mPersistentDrawingCache; |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
@Deprecated |
| 475 |
public static final int PERSISTENT_NO_CACHE = 0x0; |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
@Deprecated |
| 494 |
public static final int PERSISTENT_ANIMATION_CACHE = 0x1; |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
@Deprecated |
| 513 |
public static final int PERSISTENT_SCROLLING_CACHE = 0x2; |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
@Deprecated |
| 532 |
public static final int PERSISTENT_ALL_CACHES = 0x3; |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
private static final int LAYOUT_MODE_UNDEFINED = -1; |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
public static final int LAYOUT_MODE_CLIP_BOUNDS = 0; |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
public static final int LAYOUT_MODE_OPTICAL_BOUNDS = 1; |
| 552 |
|
| 553 |
|
| 554 |
public static int LAYOUT_MODE_DEFAULT = LAYOUT_MODE_CLIP_BOUNDS; |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
protected static final int CLIP_TO_PADDING_MASK = FLAG_CLIP_TO_PADDING | FLAG_PADDING_NOT_NULL; |
| 561 |
|
| 562 |
|
| 563 |
private static final int CHILD_LEFT_INDEX = 0; |
| 564 |
|
| 565 |
private static final int CHILD_TOP_INDEX = 1; |
| 566 |
|
| 567 |
|
| 568 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 569 |
private View[] mChildren; |
| 570 |
|
| 571 |
|
| 572 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 573 |
private int mChildrenCount; |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
boolean mSuppressLayout = false; |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
private boolean mLayoutCalledWhileSuppressed = false; |
| 583 |
|
| 584 |
private static final int ARRAY_INITIAL_CAPACITY = 12; |
| 585 |
private static final int ARRAY_CAPACITY_INCREMENT = 12; |
| 586 |
|
| 587 |
private static float[] sDebugLines; |
| 588 |
|
| 589 |
|
| 590 |
Paint mCachePaint; |
| 591 |
|
| 592 |
|
| 593 |
private LayoutTransition mTransition; |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
private ArrayList<View> mTransitioningViews; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
private ArrayList<View> mVisibilityChangingChildren; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
private ArrayList<View> mPreSortedChildren; |
| 607 |
|
| 608 |
|
| 609 |
@ViewDebug.ExportedProperty(category = "layout") |
| 610 |
private int mChildCountWithTransientState = 0; |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
private int mNestedScrollAxes; |
| 618 |
|
| 619 |
|
| 620 |
private IntArray mTransientIndices = null; |
| 621 |
private List<View> mTransientViews = null; |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
int mChildUnhandledKeyListeners = 0; |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
private @DispatchMode int mInsetsAnimationDispatchMode = DISPATCH_MODE_CONTINUE_ON_SUBTREE; |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
private static final ActionMode SENTINEL_ACTION_MODE = new ActionMode() { |
| 643 |
@Override |
| 644 |
public void setTitle(CharSequence title) {} |
| 645 |
|
| 646 |
@Override |
| 647 |
public void setTitle(int resId) {} |
| 648 |
|
| 649 |
@Override |
| 650 |
public void setSubtitle(CharSequence subtitle) {} |
| 651 |
|
| 652 |
@Override |
| 653 |
public void setSubtitle(int resId) {} |
| 654 |
|
| 655 |
@Override |
| 656 |
public void setCustomView(View view) {} |
| 657 |
|
| 658 |
@Override |
| 659 |
public void invalidate() {} |
| 660 |
|
| 661 |
@Override |
| 662 |
public void finish() {} |
| 663 |
|
| 664 |
@Override |
| 665 |
public Menu getMenu() { |
| 666 |
return null; |
| 667 |
} |
| 668 |
|
| 669 |
@Override |
| 670 |
public CharSequence getTitle() { |
| 671 |
return null; |
| 672 |
} |
| 673 |
|
| 674 |
@Override |
| 675 |
public CharSequence getSubtitle() { |
| 676 |
return null; |
| 677 |
} |
| 678 |
|
| 679 |
@Override |
| 680 |
public View getCustomView() { |
| 681 |
return null; |
| 682 |
} |
| 683 |
|
| 684 |
@Override |
| 685 |
public MenuInflater getMenuInflater() { |
| 686 |
return null; |
| 687 |
} |
| 688 |
}; |
| 689 |
|
| 690 |
public ViewGroup(Context context) { |
| 691 |
this(context, null); |
| 692 |
} |
| 693 |
|
| 694 |
public ViewGroup(Context context, AttributeSet attrs) { |
| 695 |
this(context, attrs, 0); |
| 696 |
} |
| 697 |
|
| 698 |
public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr) { |
| 699 |
this(context, attrs, defStyleAttr, 0); |
| 700 |
} |
| 701 |
|
| 702 |
public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 703 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 704 |
|
| 705 |
initViewGroup(); |
| 706 |
initFromAttributes(context, attrs, defStyleAttr, defStyleRes); |
| 707 |
} |
| 708 |
|
| 709 |
private void initViewGroup() { |
| 710 |
|
| 711 |
if (!isShowingLayoutBounds()) { |
| 712 |
setFlags(WILL_NOT_DRAW, DRAW_MASK); |
| 713 |
} |
| 714 |
mGroupFlags |= FLAG_CLIP_CHILDREN; |
| 715 |
mGroupFlags |= FLAG_CLIP_TO_PADDING; |
| 716 |
mGroupFlags |= FLAG_ANIMATION_DONE; |
| 717 |
mGroupFlags |= FLAG_ANIMATION_CACHE; |
| 718 |
mGroupFlags |= FLAG_ALWAYS_DRAWN_WITH_CACHE; |
| 719 |
|
| 720 |
if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
| 721 |
mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS; |
| 722 |
} |
| 723 |
|
| 724 |
setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS); |
| 725 |
|
| 726 |
mChildren = new View[ARRAY_INITIAL_CAPACITY]; |
| 727 |
mChildrenCount = 0; |
| 728 |
|
| 729 |
mPersistentDrawingCache = PERSISTENT_SCROLLING_CACHE; |
| 730 |
} |
| 731 |
|
| 732 |
private void initFromAttributes( |
| 733 |
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 734 |
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup, |
| 735 |
defStyleAttr, defStyleRes); |
| 736 |
saveAttributeDataForStyleable(context, R.styleable.ViewGroup, attrs, a, defStyleAttr, |
| 737 |
defStyleRes); |
| 738 |
|
| 739 |
final int N = a.getIndexCount(); |
| 740 |
for (int i = 0; i < N; i++) { |
| 741 |
int attr = a.getIndex(i); |
| 742 |
switch (attr) { |
| 743 |
case R.styleable.ViewGroup_clipChildren: |
| 744 |
setClipChildren(a.getBoolean(attr, true)); |
| 745 |
break; |
| 746 |
case R.styleable.ViewGroup_clipToPadding: |
| 747 |
setClipToPadding(a.getBoolean(attr, true)); |
| 748 |
break; |
| 749 |
case R.styleable.ViewGroup_animationCache: |
| 750 |
setAnimationCacheEnabled(a.getBoolean(attr, true)); |
| 751 |
break; |
| 752 |
case R.styleable.ViewGroup_persistentDrawingCache: |
| 753 |
setPersistentDrawingCache(a.getInt(attr, PERSISTENT_SCROLLING_CACHE)); |
| 754 |
break; |
| 755 |
case R.styleable.ViewGroup_addStatesFromChildren: |
| 756 |
setAddStatesFromChildren(a.getBoolean(attr, false)); |
| 757 |
break; |
| 758 |
case R.styleable.ViewGroup_alwaysDrawnWithCache: |
| 759 |
setAlwaysDrawnWithCacheEnabled(a.getBoolean(attr, true)); |
| 760 |
break; |
| 761 |
case R.styleable.ViewGroup_layoutAnimation: |
| 762 |
int id = a.getResourceId(attr, -1); |
| 763 |
if (id > 0) { |
| 764 |
setLayoutAnimation(AnimationUtils.loadLayoutAnimation(mContext, id)); |
| 765 |
} |
| 766 |
break; |
| 767 |
case R.styleable.ViewGroup_descendantFocusability: |
| 768 |
setDescendantFocusability(DESCENDANT_FOCUSABILITY_FLAGS[a.getInt(attr, 0)]); |
| 769 |
break; |
| 770 |
case R.styleable.ViewGroup_splitMotionEvents: |
| 771 |
setMotionEventSplittingEnabled(a.getBoolean(attr, false)); |
| 772 |
break; |
| 773 |
case R.styleable.ViewGroup_animateLayoutChanges: |
| 774 |
boolean animateLayoutChanges = a.getBoolean(attr, false); |
| 775 |
if (animateLayoutChanges) { |
| 776 |
setLayoutTransition(new LayoutTransition()); |
| 777 |
} |
| 778 |
break; |
| 779 |
case R.styleable.ViewGroup_layoutMode: |
| 780 |
setLayoutMode(a.getInt(attr, LAYOUT_MODE_UNDEFINED)); |
| 781 |
break; |
| 782 |
case R.styleable.ViewGroup_transitionGroup: |
| 783 |
setTransitionGroup(a.getBoolean(attr, false)); |
| 784 |
break; |
| 785 |
case R.styleable.ViewGroup_touchscreenBlocksFocus: |
| 786 |
setTouchscreenBlocksFocus(a.getBoolean(attr, false)); |
| 787 |
break; |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
a.recycle(); |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
@ViewDebug.ExportedProperty(category = "focus", mapping = { |
| 804 |
@ViewDebug.IntToString(from = FOCUS_BEFORE_DESCENDANTS, to = "FOCUS_BEFORE_DESCENDANTS"), |
| 805 |
@ViewDebug.IntToString(from = FOCUS_AFTER_DESCENDANTS, to = "FOCUS_AFTER_DESCENDANTS"), |
| 806 |
@ViewDebug.IntToString(from = FOCUS_BLOCK_DESCENDANTS, to = "FOCUS_BLOCK_DESCENDANTS") |
| 807 |
}) |
| 808 |
@InspectableProperty(enumMapping = { |
| 809 |
@EnumEntry(value = FOCUS_BEFORE_DESCENDANTS, name = "beforeDescendants"), |
| 810 |
@EnumEntry(value = FOCUS_AFTER_DESCENDANTS, name = "afterDescendants"), |
| 811 |
@EnumEntry(value = FOCUS_BLOCK_DESCENDANTS, name = "blocksDescendants") |
| 812 |
}) |
| 813 |
public int getDescendantFocusability() { |
| 814 |
return mGroupFlags & FLAG_MASK_FOCUSABILITY; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
public void setDescendantFocusability(int focusability) { |
| 826 |
switch (focusability) { |
| 827 |
case FOCUS_BEFORE_DESCENDANTS: |
| 828 |
case FOCUS_AFTER_DESCENDANTS: |
| 829 |
case FOCUS_BLOCK_DESCENDANTS: |
| 830 |
break; |
| 831 |
default: |
| 832 |
throw new IllegalArgumentException("must be one of FOCUS_BEFORE_DESCENDANTS, " |
| 833 |
+ "FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS"); |
| 834 |
} |
| 835 |
mGroupFlags &= ~FLAG_MASK_FOCUSABILITY; |
| 836 |
mGroupFlags |= (focusability & FLAG_MASK_FOCUSABILITY); |
| 837 |
} |
| 838 |
|
| 839 |
@Override |
| 840 |
void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 841 |
if (mFocused != null) { |
| 842 |
mFocused.unFocus(this); |
| 843 |
mFocused = null; |
| 844 |
mFocusedInCluster = null; |
| 845 |
} |
| 846 |
super.handleFocusGainInternal(direction, previouslyFocusedRect); |
| 847 |
} |
| 848 |
|
| 849 |
@Override |
| 850 |
public void requestChildFocus(View child, View focused) { |
| 851 |
if (DBG) { |
| 852 |
System.out.println(this + " requestChildFocus()"); |
| 853 |
} |
| 854 |
if (getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS) { |
| 855 |
return; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
super.unFocus(focused); |
| 860 |
|
| 861 |
|
| 862 |
if (mFocused != child) { |
| 863 |
if (mFocused != null) { |
| 864 |
mFocused.unFocus(focused); |
| 865 |
} |
| 866 |
|
| 867 |
mFocused = child; |
| 868 |
} |
| 869 |
if (mParent != null) { |
| 870 |
mParent.requestChildFocus(this, focused); |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
void setDefaultFocus(View child) { |
| 875 |
|
| 876 |
if (mDefaultFocus != null && mDefaultFocus.isFocusedByDefault()) { |
| 877 |
return; |
| 878 |
} |
| 879 |
|
| 880 |
mDefaultFocus = child; |
| 881 |
|
| 882 |
if (mParent instanceof ViewGroup) { |
| 883 |
((ViewGroup) mParent).setDefaultFocus(this); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
void clearDefaultFocus(View child) { |
| 894 |
|
| 895 |
if (mDefaultFocus != child && mDefaultFocus != null |
| 896 |
&& mDefaultFocus.isFocusedByDefault()) { |
| 897 |
return; |
| 898 |
} |
| 899 |
|
| 900 |
mDefaultFocus = null; |
| 901 |
|
| 902 |
|
| 903 |
for (int i = 0; i < mChildrenCount; ++i) { |
| 904 |
View sibling = mChildren[i]; |
| 905 |
if (sibling.isFocusedByDefault()) { |
| 906 |
mDefaultFocus = sibling; |
| 907 |
return; |
| 908 |
} else if (mDefaultFocus == null && sibling.hasDefaultFocus()) { |
| 909 |
mDefaultFocus = sibling; |
| 910 |
} |
| 911 |
} |
| 912 |
|
| 913 |
if (mParent instanceof ViewGroup) { |
| 914 |
((ViewGroup) mParent).clearDefaultFocus(this); |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
@Override |
| 919 |
boolean hasDefaultFocus() { |
| 920 |
return mDefaultFocus != null || super.hasDefaultFocus(); |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
void clearFocusedInCluster(View child) { |
| 931 |
if (mFocusedInCluster != child) { |
| 932 |
return; |
| 933 |
} |
| 934 |
clearFocusedInCluster(); |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
void clearFocusedInCluster() { |
| 941 |
View top = findKeyboardNavigationCluster(); |
| 942 |
ViewParent parent = this; |
| 943 |
do { |
| 944 |
((ViewGroup) parent).mFocusedInCluster = null; |
| 945 |
if (parent == top) { |
| 946 |
break; |
| 947 |
} |
| 948 |
parent = parent.getParent(); |
| 949 |
} while (parent instanceof ViewGroup); |
| 950 |
} |
| 951 |
|
| 952 |
@Override |
| 953 |
public void focusableViewAvailable(View v) { |
| 954 |
if (mParent != null |
| 955 |
|
| 956 |
|
| 957 |
&& (getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS) |
| 958 |
&& ((mViewFlags & VISIBILITY_MASK) == VISIBLE) |
| 959 |
&& (isFocusableInTouchMode() || !shouldBlockFocusForTouchscreen()) |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
&& !(isFocused() && getDescendantFocusability() != FOCUS_AFTER_DESCENDANTS)) { |
| 968 |
mParent.focusableViewAvailable(v); |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
@Override |
| 973 |
public boolean showContextMenuForChild(View originalView) { |
| 974 |
if (isShowingContextMenuWithCoords()) { |
| 975 |
|
| 976 |
|
| 977 |
return false; |
| 978 |
} |
| 979 |
return mParent != null && mParent.showContextMenuForChild(originalView); |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
public final boolean isShowingContextMenuWithCoords() { |
| 986 |
return (mGroupFlags & FLAG_SHOW_CONTEXT_MENU_WITH_COORDS) != 0; |
| 987 |
} |
| 988 |
|
| 989 |
@Override |
| 990 |
public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 991 |
try { |
| 992 |
mGroupFlags |= FLAG_SHOW_CONTEXT_MENU_WITH_COORDS; |
| 993 |
if (showContextMenuForChild(originalView)) { |
| 994 |
return true; |
| 995 |
} |
| 996 |
} finally { |
| 997 |
mGroupFlags &= ~FLAG_SHOW_CONTEXT_MENU_WITH_COORDS; |
| 998 |
} |
| 999 |
return mParent != null && mParent.showContextMenuForChild(originalView, x, y); |
| 1000 |
} |
| 1001 |
|
| 1002 |
@Override |
| 1003 |
public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 1004 |
if ((mGroupFlags & FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED) == 0) { |
| 1005 |
|
| 1006 |
try { |
| 1007 |
mGroupFlags |= FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED; |
| 1008 |
return startActionModeForChild(originalView, callback, ActionMode.TYPE_PRIMARY); |
| 1009 |
} finally { |
| 1010 |
mGroupFlags &= ~FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED; |
| 1011 |
} |
| 1012 |
} else { |
| 1013 |
|
| 1014 |
return SENTINEL_ACTION_MODE; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
@Override |
| 1019 |
public ActionMode startActionModeForChild( |
| 1020 |
View originalView, ActionMode.Callback callback, int type) { |
| 1021 |
if ((mGroupFlags & FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED) == 0 |
| 1022 |
&& type == ActionMode.TYPE_PRIMARY) { |
| 1023 |
ActionMode mode; |
| 1024 |
try { |
| 1025 |
mGroupFlags |= FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED; |
| 1026 |
mode = startActionModeForChild(originalView, callback); |
| 1027 |
} finally { |
| 1028 |
mGroupFlags &= ~FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED; |
| 1029 |
} |
| 1030 |
if (mode != SENTINEL_ACTION_MODE) { |
| 1031 |
return mode; |
| 1032 |
} |
| 1033 |
} |
| 1034 |
if (mParent != null) { |
| 1035 |
try { |
| 1036 |
return mParent.startActionModeForChild(originalView, callback, type); |
| 1037 |
} catch (AbstractMethodError ame) { |
| 1038 |
|
| 1039 |
return mParent.startActionModeForChild(originalView, callback); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
return null; |
| 1043 |
} |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
@Override |
| 1049 |
public boolean dispatchActivityResult( |
| 1050 |
String who, int requestCode, int resultCode, Intent data) { |
| 1051 |
if (super.dispatchActivityResult(who, requestCode, resultCode, data)) { |
| 1052 |
return true; |
| 1053 |
} |
| 1054 |
int childCount = getChildCount(); |
| 1055 |
for (int i = 0; i < childCount; i++) { |
| 1056 |
View child = getChildAt(i); |
| 1057 |
if (child.dispatchActivityResult(who, requestCode, resultCode, data)) { |
| 1058 |
return true; |
| 1059 |
} |
| 1060 |
} |
| 1061 |
return false; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
@Override |
| 1073 |
public View focusSearch(View focused, int direction) { |
| 1074 |
if (isRootNamespace()) { |
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
return FocusFinder.getInstance().findNextFocus(this, focused, direction); |
| 1079 |
} else if (mParent != null) { |
| 1080 |
return mParent.focusSearch(focused, direction); |
| 1081 |
} |
| 1082 |
return null; |
| 1083 |
} |
| 1084 |
|
| 1085 |
@Override |
| 1086 |
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
| 1087 |
return false; |
| 1088 |
} |
| 1089 |
|
| 1090 |
@Override |
| 1091 |
public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 1092 |
ViewParent parent = mParent; |
| 1093 |
if (parent == null) { |
| 1094 |
return false; |
| 1095 |
} |
| 1096 |
final boolean propagate = onRequestSendAccessibilityEvent(child, event); |
| 1097 |
if (!propagate) { |
| 1098 |
return false; |
| 1099 |
} |
| 1100 |
return parent.requestSendAccessibilityEvent(this, event); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 1120 |
if (mAccessibilityDelegate != null) { |
| 1121 |
return mAccessibilityDelegate.onRequestSendAccessibilityEvent(this, child, event); |
| 1122 |
} else { |
| 1123 |
return onRequestSendAccessibilityEventInternal(child, event); |
| 1124 |
} |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 1135 |
return true; |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
@Override |
| 1142 |
public void childHasTransientStateChanged(View child, boolean childHasTransientState) { |
| 1143 |
final boolean oldHasTransientState = hasTransientState(); |
| 1144 |
if (childHasTransientState) { |
| 1145 |
mChildCountWithTransientState++; |
| 1146 |
} else { |
| 1147 |
mChildCountWithTransientState--; |
| 1148 |
} |
| 1149 |
|
| 1150 |
final boolean newHasTransientState = hasTransientState(); |
| 1151 |
if (mParent != null && oldHasTransientState != newHasTransientState) { |
| 1152 |
try { |
| 1153 |
mParent.childHasTransientStateChanged(this, newHasTransientState); |
| 1154 |
} catch (AbstractMethodError e) { |
| 1155 |
Log.e(TAG, mParent.getClass().getSimpleName() + |
| 1156 |
" does not fully implement ViewParent", e); |
| 1157 |
} |
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
@Override |
| 1162 |
public boolean hasTransientState() { |
| 1163 |
return mChildCountWithTransientState > 0 || super.hasTransientState(); |
| 1164 |
} |
| 1165 |
|
| 1166 |
@Override |
| 1167 |
public boolean dispatchUnhandledMove(View focused, int direction) { |
| 1168 |
return mFocused != null && |
| 1169 |
mFocused.dispatchUnhandledMove(focused, direction); |
| 1170 |
} |
| 1171 |
|
| 1172 |
@Override |
| 1173 |
public void clearChildFocus(View child) { |
| 1174 |
if (DBG) { |
| 1175 |
System.out.println(this + " clearChildFocus()"); |
| 1176 |
} |
| 1177 |
|
| 1178 |
mFocused = null; |
| 1179 |
if (mParent != null) { |
| 1180 |
mParent.clearChildFocus(this); |
| 1181 |
} |
| 1182 |
} |
| 1183 |
|
| 1184 |
@Override |
| 1185 |
public void clearFocus() { |
| 1186 |
if (DBG) { |
| 1187 |
System.out.println(this + " clearFocus()"); |
| 1188 |
} |
| 1189 |
if (mFocused == null) { |
| 1190 |
super.clearFocus(); |
| 1191 |
} else { |
| 1192 |
View focused = mFocused; |
| 1193 |
mFocused = null; |
| 1194 |
focused.clearFocus(); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
@Override |
| 1199 |
void unFocus(View focused) { |
| 1200 |
if (DBG) { |
| 1201 |
System.out.println(this + " unFocus()"); |
| 1202 |
} |
| 1203 |
if (mFocused == null) { |
| 1204 |
super.unFocus(focused); |
| 1205 |
} else { |
| 1206 |
mFocused.unFocus(focused); |
| 1207 |
mFocused = null; |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
public View getFocusedChild() { |
| 1218 |
return mFocused; |
| 1219 |
} |
| 1220 |
|
| 1221 |
View getDeepestFocusedChild() { |
| 1222 |
View v = this; |
| 1223 |
while (v != null) { |
| 1224 |
if (v.isFocused()) { |
| 1225 |
return v; |
| 1226 |
} |
| 1227 |
v = v instanceof ViewGroup ? ((ViewGroup) v).getFocusedChild() : null; |
| 1228 |
} |
| 1229 |
return null; |
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
@Override |
| 1238 |
public boolean hasFocus() { |
| 1239 |
return (mPrivateFlags & PFLAG_FOCUSED) != 0 || mFocused != null; |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
@Override |
| 1248 |
public View findFocus() { |
| 1249 |
if (DBG) { |
| 1250 |
System.out.println("Find focus in " + this + ": flags=" |
| 1251 |
+ isFocused() + ", child=" + mFocused); |
| 1252 |
} |
| 1253 |
|
| 1254 |
if (isFocused()) { |
| 1255 |
return this; |
| 1256 |
} |
| 1257 |
|
| 1258 |
if (mFocused != null) { |
| 1259 |
return mFocused.findFocus(); |
| 1260 |
} |
| 1261 |
return null; |
| 1262 |
} |
| 1263 |
|
| 1264 |
@Override |
| 1265 |
boolean hasFocusable(boolean allowAutoFocus, boolean dispatchExplicit) { |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 1272 |
return false; |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
if ((allowAutoFocus || getFocusable() != FOCUSABLE_AUTO) && isFocusable()) { |
| 1277 |
return true; |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
final int descendantFocusability = getDescendantFocusability(); |
| 1282 |
if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { |
| 1283 |
return hasFocusableChild(dispatchExplicit); |
| 1284 |
} |
| 1285 |
|
| 1286 |
return false; |
| 1287 |
} |
| 1288 |
|
| 1289 |
boolean hasFocusableChild(boolean dispatchExplicit) { |
| 1290 |
|
| 1291 |
final int count = mChildrenCount; |
| 1292 |
final View[] children = mChildren; |
| 1293 |
|
| 1294 |
for (int i = 0; i < count; i++) { |
| 1295 |
final View child = children[i]; |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
if ((dispatchExplicit && child.hasExplicitFocusable()) |
| 1300 |
|| (!dispatchExplicit && child.hasFocusable())) { |
| 1301 |
return true; |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
return false; |
| 1306 |
} |
| 1307 |
|
| 1308 |
@Override |
| 1309 |
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 1310 |
final int focusableCount = views.size(); |
| 1311 |
|
| 1312 |
final int descendantFocusability = getDescendantFocusability(); |
| 1313 |
final boolean blockFocusForTouchscreen = shouldBlockFocusForTouchscreen(); |
| 1314 |
final boolean focusSelf = (isFocusableInTouchMode() || !blockFocusForTouchscreen); |
| 1315 |
|
| 1316 |
if (descendantFocusability == FOCUS_BLOCK_DESCENDANTS) { |
| 1317 |
if (focusSelf) { |
| 1318 |
super.addFocusables(views, direction, focusableMode); |
| 1319 |
} |
| 1320 |
return; |
| 1321 |
} |
| 1322 |
|
| 1323 |
if (blockFocusForTouchscreen) { |
| 1324 |
focusableMode |= FOCUSABLES_TOUCH_MODE; |
| 1325 |
} |
| 1326 |
|
| 1327 |
if ((descendantFocusability == FOCUS_BEFORE_DESCENDANTS) && focusSelf) { |
| 1328 |
super.addFocusables(views, direction, focusableMode); |
| 1329 |
} |
| 1330 |
|
| 1331 |
int count = 0; |
| 1332 |
final View[] children = new View[mChildrenCount]; |
| 1333 |
for (int i = 0; i < mChildrenCount; ++i) { |
| 1334 |
View child = mChildren[i]; |
| 1335 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 1336 |
children[count++] = child; |
| 1337 |
} |
| 1338 |
} |
| 1339 |
FocusFinder.sort(children, 0, count, this, isLayoutRtl()); |
| 1340 |
for (int i = 0; i < count; ++i) { |
| 1341 |
children[i].addFocusables(views, direction, focusableMode); |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
if ((descendantFocusability == FOCUS_AFTER_DESCENDANTS) && focusSelf |
| 1349 |
&& focusableCount == views.size()) { |
| 1350 |
super.addFocusables(views, direction, focusableMode); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
@Override |
| 1355 |
public void addKeyboardNavigationClusters(Collection<View> views, int direction) { |
| 1356 |
final int focusableCount = views.size(); |
| 1357 |
|
| 1358 |
if (isKeyboardNavigationCluster()) { |
| 1359 |
|
| 1360 |
|
| 1361 |
final boolean blockedFocus = getTouchscreenBlocksFocus(); |
| 1362 |
try { |
| 1363 |
setTouchscreenBlocksFocusNoRefocus(false); |
| 1364 |
super.addKeyboardNavigationClusters(views, direction); |
| 1365 |
} finally { |
| 1366 |
setTouchscreenBlocksFocusNoRefocus(blockedFocus); |
| 1367 |
} |
| 1368 |
} else { |
| 1369 |
super.addKeyboardNavigationClusters(views, direction); |
| 1370 |
} |
| 1371 |
|
| 1372 |
if (focusableCount != views.size()) { |
| 1373 |
|
| 1374 |
return; |
| 1375 |
} |
| 1376 |
|
| 1377 |
if (getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS) { |
| 1378 |
return; |
| 1379 |
} |
| 1380 |
|
| 1381 |
int count = 0; |
| 1382 |
final View[] visibleChildren = new View[mChildrenCount]; |
| 1383 |
for (int i = 0; i < mChildrenCount; ++i) { |
| 1384 |
final View child = mChildren[i]; |
| 1385 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 1386 |
visibleChildren[count++] = child; |
| 1387 |
} |
| 1388 |
} |
| 1389 |
FocusFinder.sort(visibleChildren, 0, count, this, isLayoutRtl()); |
| 1390 |
for (int i = 0; i < count; ++i) { |
| 1391 |
visibleChildren[i].addKeyboardNavigationClusters(views, direction); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
public void setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus) { |
| 1403 |
if (touchscreenBlocksFocus) { |
| 1404 |
mGroupFlags |= FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1405 |
if (hasFocus() && !isKeyboardNavigationCluster()) { |
| 1406 |
final View focusedChild = getDeepestFocusedChild(); |
| 1407 |
if (!focusedChild.isFocusableInTouchMode()) { |
| 1408 |
final View newFocus = focusSearch(FOCUS_FORWARD); |
| 1409 |
if (newFocus != null) { |
| 1410 |
newFocus.requestFocus(); |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} |
| 1414 |
} else { |
| 1415 |
mGroupFlags &= ~FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
|
| 1419 |
private void setTouchscreenBlocksFocusNoRefocus(boolean touchscreenBlocksFocus) { |
| 1420 |
if (touchscreenBlocksFocus) { |
| 1421 |
mGroupFlags |= FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1422 |
} else { |
| 1423 |
mGroupFlags &= ~FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
@ViewDebug.ExportedProperty(category = "focus") |
| 1431 |
@InspectableProperty |
| 1432 |
public boolean getTouchscreenBlocksFocus() { |
| 1433 |
return (mGroupFlags & FLAG_TOUCHSCREEN_BLOCKS_FOCUS) != 0; |
| 1434 |
} |
| 1435 |
|
| 1436 |
boolean shouldBlockFocusForTouchscreen() { |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
return getTouchscreenBlocksFocus() && |
| 1441 |
mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN) |
| 1442 |
&& !(isKeyboardNavigationCluster() |
| 1443 |
&& (hasFocus() || (findKeyboardNavigationCluster() != this))); |
| 1444 |
} |
| 1445 |
|
| 1446 |
@Override |
| 1447 |
public void findViewsWithText(ArrayList<View> outViews, CharSequence text, int flags) { |
| 1448 |
super.findViewsWithText(outViews, text, flags); |
| 1449 |
final int childrenCount = mChildrenCount; |
| 1450 |
final View[] children = mChildren; |
| 1451 |
for (int i = 0; i < childrenCount; i++) { |
| 1452 |
View child = children[i]; |
| 1453 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE |
| 1454 |
&& (child.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
| 1455 |
child.findViewsWithText(outViews, text, flags); |
| 1456 |
} |
| 1457 |
} |
| 1458 |
} |
| 1459 |
|
| 1460 |
|
| 1461 |
@Override |
| 1462 |
public View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 1463 |
View foundView = super.findViewByAccessibilityIdTraversal(accessibilityId); |
| 1464 |
if (foundView != null) { |
| 1465 |
return foundView; |
| 1466 |
} |
| 1467 |
|
| 1468 |
if (getAccessibilityNodeProvider() != null) { |
| 1469 |
return null; |
| 1470 |
} |
| 1471 |
|
| 1472 |
final int childrenCount = mChildrenCount; |
| 1473 |
final View[] children = mChildren; |
| 1474 |
for (int i = 0; i < childrenCount; i++) { |
| 1475 |
View child = children[i]; |
| 1476 |
foundView = child.findViewByAccessibilityIdTraversal(accessibilityId); |
| 1477 |
if (foundView != null) { |
| 1478 |
return foundView; |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
return null; |
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
@Override |
| 1487 |
public View findViewByAutofillIdTraversal(int autofillId) { |
| 1488 |
View foundView = super.findViewByAutofillIdTraversal(autofillId); |
| 1489 |
if (foundView != null) { |
| 1490 |
return foundView; |
| 1491 |
} |
| 1492 |
|
| 1493 |
final int childrenCount = mChildrenCount; |
| 1494 |
final View[] children = mChildren; |
| 1495 |
for (int i = 0; i < childrenCount; i++) { |
| 1496 |
View child = children[i]; |
| 1497 |
foundView = child.findViewByAutofillIdTraversal(autofillId); |
| 1498 |
if (foundView != null) { |
| 1499 |
return foundView; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
|
| 1503 |
return null; |
| 1504 |
} |
| 1505 |
|
| 1506 |
@Override |
| 1507 |
public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 1508 |
super.dispatchWindowFocusChanged(hasFocus); |
| 1509 |
final int count = mChildrenCount; |
| 1510 |
final View[] children = mChildren; |
| 1511 |
for (int i = 0; i < count; i++) { |
| 1512 |
children[i].dispatchWindowFocusChanged(hasFocus); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
|
| 1516 |
@Override |
| 1517 |
public void addTouchables(ArrayList<View> views) { |
| 1518 |
super.addTouchables(views); |
| 1519 |
|
| 1520 |
final int count = mChildrenCount; |
| 1521 |
final View[] children = mChildren; |
| 1522 |
|
| 1523 |
for (int i = 0; i < count; i++) { |
| 1524 |
final View child = children[i]; |
| 1525 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 1526 |
child.addTouchables(views); |
| 1527 |
} |
| 1528 |
} |
| 1529 |
} |
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
@Override |
| 1535 |
@UnsupportedAppUsage |
| 1536 |
public void makeOptionalFitsSystemWindows() { |
| 1537 |
super.makeOptionalFitsSystemWindows(); |
| 1538 |
final int count = mChildrenCount; |
| 1539 |
final View[] children = mChildren; |
| 1540 |
for (int i = 0; i < count; i++) { |
| 1541 |
children[i].makeOptionalFitsSystemWindows(); |
| 1542 |
} |
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
@Override |
| 1549 |
public void makeFrameworkOptionalFitsSystemWindows() { |
| 1550 |
super.makeFrameworkOptionalFitsSystemWindows(); |
| 1551 |
final int count = mChildrenCount; |
| 1552 |
final View[] children = mChildren; |
| 1553 |
for (int i = 0; i < count; i++) { |
| 1554 |
children[i].makeFrameworkOptionalFitsSystemWindows(); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
@Override |
| 1559 |
public void dispatchDisplayHint(int hint) { |
| 1560 |
super.dispatchDisplayHint(hint); |
| 1561 |
final int count = mChildrenCount; |
| 1562 |
final View[] children = mChildren; |
| 1563 |
for (int i = 0; i < count; i++) { |
| 1564 |
children[i].dispatchDisplayHint(hint); |
| 1565 |
} |
| 1566 |
} |
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
@UnsupportedAppUsage |
| 1578 |
protected void onChildVisibilityChanged(View child, int oldVisibility, int newVisibility) { |
| 1579 |
if (mTransition != null) { |
| 1580 |
if (newVisibility == VISIBLE) { |
| 1581 |
mTransition.showChild(this, child, oldVisibility); |
| 1582 |
} else { |
| 1583 |
mTransition.hideChild(this, child, newVisibility); |
| 1584 |
if (mTransitioningViews != null && mTransitioningViews.contains(child)) { |
| 1585 |
|
| 1586 |
|
| 1587 |
if (mVisibilityChangingChildren == null) { |
| 1588 |
mVisibilityChangingChildren = new ArrayList<View>(); |
| 1589 |
} |
| 1590 |
mVisibilityChangingChildren.add(child); |
| 1591 |
addDisappearingView(child); |
| 1592 |
} |
| 1593 |
} |
| 1594 |
} |
| 1595 |
|
| 1596 |
|
| 1597 |
if (newVisibility == VISIBLE && mCurrentDragStartEvent != null) { |
| 1598 |
if (!mChildrenInterestedInDrag.contains(child)) { |
| 1599 |
notifyChildOfDragStart(child); |
| 1600 |
} |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
@Override |
| 1605 |
protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 1606 |
super.dispatchVisibilityChanged(changedView, visibility); |
| 1607 |
final int count = mChildrenCount; |
| 1608 |
final View[] children = mChildren; |
| 1609 |
for (int i = 0; i < count; i++) { |
| 1610 |
children[i].dispatchVisibilityChanged(changedView, visibility); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
|
| 1614 |
@Override |
| 1615 |
public void dispatchWindowVisibilityChanged(int visibility) { |
| 1616 |
super.dispatchWindowVisibilityChanged(visibility); |
| 1617 |
final int count = mChildrenCount; |
| 1618 |
final View[] children = mChildren; |
| 1619 |
for (int i = 0; i < count; i++) { |
| 1620 |
children[i].dispatchWindowVisibilityChanged(visibility); |
| 1621 |
} |
| 1622 |
} |
| 1623 |
|
| 1624 |
@Override |
| 1625 |
boolean dispatchVisibilityAggregated(boolean isVisible) { |
| 1626 |
isVisible = super.dispatchVisibilityAggregated(isVisible); |
| 1627 |
final int count = mChildrenCount; |
| 1628 |
final View[] children = mChildren; |
| 1629 |
for (int i = 0; i < count; i++) { |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
if (children[i].getVisibility() == VISIBLE) { |
| 1634 |
children[i].dispatchVisibilityAggregated(isVisible); |
| 1635 |
} |
| 1636 |
} |
| 1637 |
return isVisible; |
| 1638 |
} |
| 1639 |
|
| 1640 |
@Override |
| 1641 |
public void dispatchConfigurationChanged(Configuration newConfig) { |
| 1642 |
super.dispatchConfigurationChanged(newConfig); |
| 1643 |
final int count = mChildrenCount; |
| 1644 |
final View[] children = mChildren; |
| 1645 |
for (int i = 0; i < count; i++) { |
| 1646 |
children[i].dispatchConfigurationChanged(newConfig); |
| 1647 |
} |
| 1648 |
} |
| 1649 |
|
| 1650 |
@Override |
| 1651 |
public void recomputeViewAttributes(View child) { |
| 1652 |
if (mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 1653 |
ViewParent parent = mParent; |
| 1654 |
if (parent != null) parent.recomputeViewAttributes(this); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
@Override |
| 1659 |
void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 1660 |
if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
| 1661 |
super.dispatchCollectViewAttributes(attachInfo, visibility); |
| 1662 |
final int count = mChildrenCount; |
| 1663 |
final View[] children = mChildren; |
| 1664 |
for (int i = 0; i < count; i++) { |
| 1665 |
final View child = children[i]; |
| 1666 |
child.dispatchCollectViewAttributes(attachInfo, |
| 1667 |
visibility | (child.mViewFlags&VISIBILITY_MASK)); |
| 1668 |
} |
| 1669 |
} |
| 1670 |
} |
| 1671 |
|
| 1672 |
@Override |
| 1673 |
public void bringChildToFront(View child) { |
| 1674 |
final int index = indexOfChild(child); |
| 1675 |
if (index >= 0) { |
| 1676 |
removeFromArray(index); |
| 1677 |
addInArray(child, mChildrenCount); |
| 1678 |
child.mParent = this; |
| 1679 |
requestLayout(); |
| 1680 |
invalidate(); |
| 1681 |
} |
| 1682 |
} |
| 1683 |
|
| 1684 |
private PointF getLocalPoint() { |
| 1685 |
if (mLocalPoint == null) mLocalPoint = new PointF(); |
| 1686 |
return mLocalPoint; |
| 1687 |
} |
| 1688 |
|
| 1689 |
@Override |
| 1690 |
boolean dispatchDragEnterExitInPreN(DragEvent event) { |
| 1691 |
if (event.mAction == DragEvent.ACTION_DRAG_EXITED && mCurrentDragChild != null) { |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
mCurrentDragChild.dispatchDragEnterExitInPreN(event); |
| 1698 |
mCurrentDragChild = null; |
| 1699 |
} |
| 1700 |
return mIsInterestedInDrag && super.dispatchDragEnterExitInPreN(event); |
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
@Override |
| 1705 |
public boolean dispatchDragEvent(DragEvent event) { |
| 1706 |
boolean retval = false; |
| 1707 |
final float tx = event.mX; |
| 1708 |
final float ty = event.mY; |
| 1709 |
final ClipData td = event.mClipData; |
| 1710 |
|
| 1711 |
|
| 1712 |
final PointF localPoint = getLocalPoint(); |
| 1713 |
|
| 1714 |
switch (event.mAction) { |
| 1715 |
case DragEvent.ACTION_DRAG_STARTED: { |
| 1716 |
|
| 1717 |
mCurrentDragChild = null; |
| 1718 |
|
| 1719 |
|
| 1720 |
mCurrentDragStartEvent = DragEvent.obtain(event); |
| 1721 |
if (mChildrenInterestedInDrag == null) { |
| 1722 |
mChildrenInterestedInDrag = new HashSet<View>(); |
| 1723 |
} else { |
| 1724 |
mChildrenInterestedInDrag.clear(); |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
final int count = mChildrenCount; |
| 1729 |
final View[] children = mChildren; |
| 1730 |
for (int i = 0; i < count; i++) { |
| 1731 |
final View child = children[i]; |
| 1732 |
child.mPrivateFlags2 &= ~View.DRAG_MASK; |
| 1733 |
if (child.getVisibility() == VISIBLE) { |
| 1734 |
if (notifyChildOfDragStart(children[i])) { |
| 1735 |
retval = true; |
| 1736 |
} |
| 1737 |
} |
| 1738 |
} |
| 1739 |
|
| 1740 |
|
| 1741 |
mIsInterestedInDrag = super.dispatchDragEvent(event); |
| 1742 |
if (mIsInterestedInDrag) { |
| 1743 |
retval = true; |
| 1744 |
} |
| 1745 |
|
| 1746 |
if (!retval) { |
| 1747 |
|
| 1748 |
|
| 1749 |
mCurrentDragStartEvent.recycle(); |
| 1750 |
mCurrentDragStartEvent = null; |
| 1751 |
} |
| 1752 |
} break; |
| 1753 |
|
| 1754 |
case DragEvent.ACTION_DRAG_ENDED: { |
| 1755 |
|
| 1756 |
final HashSet<View> childrenInterestedInDrag = mChildrenInterestedInDrag; |
| 1757 |
if (childrenInterestedInDrag != null) { |
| 1758 |
for (View child : childrenInterestedInDrag) { |
| 1759 |
|
| 1760 |
if (child.dispatchDragEvent(event)) { |
| 1761 |
retval = true; |
| 1762 |
} |
| 1763 |
} |
| 1764 |
childrenInterestedInDrag.clear(); |
| 1765 |
} |
| 1766 |
if (mCurrentDragStartEvent != null) { |
| 1767 |
mCurrentDragStartEvent.recycle(); |
| 1768 |
mCurrentDragStartEvent = null; |
| 1769 |
} |
| 1770 |
|
| 1771 |
if (mIsInterestedInDrag) { |
| 1772 |
if (super.dispatchDragEvent(event)) { |
| 1773 |
retval = true; |
| 1774 |
} |
| 1775 |
mIsInterestedInDrag = false; |
| 1776 |
} |
| 1777 |
} break; |
| 1778 |
|
| 1779 |
case DragEvent.ACTION_DRAG_LOCATION: |
| 1780 |
case DragEvent.ACTION_DROP: { |
| 1781 |
|
| 1782 |
View target = findFrontmostDroppableChildAt(event.mX, event.mY, localPoint); |
| 1783 |
|
| 1784 |
if (target != mCurrentDragChild) { |
| 1785 |
if (sCascadedDragDrop) { |
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
final int action = event.mAction; |
| 1791 |
|
| 1792 |
|
| 1793 |
event.mX = 0; |
| 1794 |
event.mY = 0; |
| 1795 |
event.mClipData = null; |
| 1796 |
|
| 1797 |
if (mCurrentDragChild != null) { |
| 1798 |
event.mAction = DragEvent.ACTION_DRAG_EXITED; |
| 1799 |
mCurrentDragChild.dispatchDragEnterExitInPreN(event); |
| 1800 |
} |
| 1801 |
|
| 1802 |
if (target != null) { |
| 1803 |
event.mAction = DragEvent.ACTION_DRAG_ENTERED; |
| 1804 |
target.dispatchDragEnterExitInPreN(event); |
| 1805 |
} |
| 1806 |
|
| 1807 |
event.mAction = action; |
| 1808 |
event.mX = tx; |
| 1809 |
event.mY = ty; |
| 1810 |
event.mClipData = td; |
| 1811 |
} |
| 1812 |
mCurrentDragChild = target; |
| 1813 |
} |
| 1814 |
|
| 1815 |
if (target == null && mIsInterestedInDrag) { |
| 1816 |
target = this; |
| 1817 |
} |
| 1818 |
|
| 1819 |
|
| 1820 |
if (target != null) { |
| 1821 |
if (target != this) { |
| 1822 |
event.mX = localPoint.x; |
| 1823 |
event.mY = localPoint.y; |
| 1824 |
|
| 1825 |
retval = target.dispatchDragEvent(event); |
| 1826 |
|
| 1827 |
event.mX = tx; |
| 1828 |
event.mY = ty; |
| 1829 |
|
| 1830 |
if (mIsInterestedInDrag) { |
| 1831 |
final boolean eventWasConsumed; |
| 1832 |
if (sCascadedDragDrop) { |
| 1833 |
eventWasConsumed = retval; |
| 1834 |
} else { |
| 1835 |
eventWasConsumed = event.mEventHandlerWasCalled; |
| 1836 |
} |
| 1837 |
|
| 1838 |
if (!eventWasConsumed) { |
| 1839 |
retval = super.dispatchDragEvent(event); |
| 1840 |
} |
| 1841 |
} |
| 1842 |
} else { |
| 1843 |
retval = super.dispatchDragEvent(event); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
} break; |
| 1847 |
} |
| 1848 |
|
| 1849 |
return retval; |
| 1850 |
} |
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
View findFrontmostDroppableChildAt(float x, float y, PointF outLocalPoint) { |
| 1855 |
final int count = mChildrenCount; |
| 1856 |
final View[] children = mChildren; |
| 1857 |
for (int i = count - 1; i >= 0; i--) { |
| 1858 |
final View child = children[i]; |
| 1859 |
if (!child.canAcceptDrag()) { |
| 1860 |
continue; |
| 1861 |
} |
| 1862 |
|
| 1863 |
if (isTransformedTouchPointInView(x, y, child, outLocalPoint)) { |
| 1864 |
return child; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
return null; |
| 1868 |
} |
| 1869 |
|
| 1870 |
boolean notifyChildOfDragStart(View child) { |
| 1871 |
|
| 1872 |
|
| 1873 |
if (ViewDebug.DEBUG_DRAG) { |
| 1874 |
Log.d(View.VIEW_LOG_TAG, "Sending drag-started to view: " + child); |
| 1875 |
} |
| 1876 |
|
| 1877 |
final float tx = mCurrentDragStartEvent.mX; |
| 1878 |
final float ty = mCurrentDragStartEvent.mY; |
| 1879 |
|
| 1880 |
final float[] point = getTempLocationF(); |
| 1881 |
point[0] = tx; |
| 1882 |
point[1] = ty; |
| 1883 |
transformPointToViewLocal(point, child); |
| 1884 |
|
| 1885 |
mCurrentDragStartEvent.mX = point[0]; |
| 1886 |
mCurrentDragStartEvent.mY = point[1]; |
| 1887 |
final boolean canAccept = child.dispatchDragEvent(mCurrentDragStartEvent); |
| 1888 |
mCurrentDragStartEvent.mX = tx; |
| 1889 |
mCurrentDragStartEvent.mY = ty; |
| 1890 |
mCurrentDragStartEvent.mEventHandlerWasCalled = false; |
| 1891 |
if (canAccept) { |
| 1892 |
mChildrenInterestedInDrag.add(child); |
| 1893 |
if (!child.canAcceptDrag()) { |
| 1894 |
child.mPrivateFlags2 |= View.PFLAG2_DRAG_CAN_ACCEPT; |
| 1895 |
child.refreshDrawableState(); |
| 1896 |
} |
| 1897 |
} |
| 1898 |
return canAccept; |
| 1899 |
} |
| 1900 |
|
| 1901 |
@Override |
| 1902 |
@Deprecated |
| 1903 |
public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 1904 |
super.dispatchWindowSystemUiVisiblityChanged(visible); |
| 1905 |
|
| 1906 |
final int count = mChildrenCount; |
| 1907 |
final View[] children = mChildren; |
| 1908 |
for (int i=0; i <count; i++) { |
| 1909 |
final View child = children[i]; |
| 1910 |
child.dispatchWindowSystemUiVisiblityChanged(visible); |
| 1911 |
} |
| 1912 |
} |
| 1913 |
|
| 1914 |
@Override |
| 1915 |
@Deprecated |
| 1916 |
public void dispatchSystemUiVisibilityChanged(int visible) { |
| 1917 |
super.dispatchSystemUiVisibilityChanged(visible); |
| 1918 |
|
| 1919 |
final int count = mChildrenCount; |
| 1920 |
final View[] children = mChildren; |
| 1921 |
for (int i=0; i <count; i++) { |
| 1922 |
final View child = children[i]; |
| 1923 |
child.dispatchSystemUiVisibilityChanged(visible); |
| 1924 |
} |
| 1925 |
} |
| 1926 |
|
| 1927 |
@Override |
| 1928 |
boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 1929 |
boolean changed = super.updateLocalSystemUiVisibility(localValue, localChanges); |
| 1930 |
|
| 1931 |
final int count = mChildrenCount; |
| 1932 |
final View[] children = mChildren; |
| 1933 |
for (int i=0; i <count; i++) { |
| 1934 |
final View child = children[i]; |
| 1935 |
changed |= child.updateLocalSystemUiVisibility(localValue, localChanges); |
| 1936 |
} |
| 1937 |
return changed; |
| 1938 |
} |
| 1939 |
|
| 1940 |
@Override |
| 1941 |
public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 1942 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1943 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 1944 |
return super.dispatchKeyEventPreIme(event); |
| 1945 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1946 |
== PFLAG_HAS_BOUNDS) { |
| 1947 |
return mFocused.dispatchKeyEventPreIme(event); |
| 1948 |
} |
| 1949 |
return false; |
| 1950 |
} |
| 1951 |
|
| 1952 |
@Override |
| 1953 |
public boolean dispatchKeyEvent(KeyEvent event) { |
| 1954 |
if (mInputEventConsistencyVerifier != null) { |
| 1955 |
mInputEventConsistencyVerifier.onKeyEvent(event, 1); |
| 1956 |
} |
| 1957 |
|
| 1958 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1959 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 1960 |
if (super.dispatchKeyEvent(event)) { |
| 1961 |
return true; |
| 1962 |
} |
| 1963 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1964 |
== PFLAG_HAS_BOUNDS) { |
| 1965 |
if (mFocused.dispatchKeyEvent(event)) { |
| 1966 |
return true; |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
if (mInputEventConsistencyVerifier != null) { |
| 1971 |
mInputEventConsistencyVerifier.onUnhandledEvent(event, 1); |
| 1972 |
} |
| 1973 |
return false; |
| 1974 |
} |
| 1975 |
|
| 1976 |
@Override |
| 1977 |
public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 1978 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1979 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 1980 |
return super.dispatchKeyShortcutEvent(event); |
| 1981 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1982 |
== PFLAG_HAS_BOUNDS) { |
| 1983 |
return mFocused.dispatchKeyShortcutEvent(event); |
| 1984 |
} |
| 1985 |
return false; |
| 1986 |
} |
| 1987 |
|
| 1988 |
@Override |
| 1989 |
public boolean dispatchTrackballEvent(MotionEvent event) { |
| 1990 |
if (mInputEventConsistencyVerifier != null) { |
| 1991 |
mInputEventConsistencyVerifier.onTrackballEvent(event, 1); |
| 1992 |
} |
| 1993 |
|
| 1994 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1995 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 1996 |
if (super.dispatchTrackballEvent(event)) { |
| 1997 |
return true; |
| 1998 |
} |
| 1999 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 2000 |
== PFLAG_HAS_BOUNDS) { |
| 2001 |
if (mFocused.dispatchTrackballEvent(event)) { |
| 2002 |
return true; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
if (mInputEventConsistencyVerifier != null) { |
| 2007 |
mInputEventConsistencyVerifier.onUnhandledEvent(event, 1); |
| 2008 |
} |
| 2009 |
return false; |
| 2010 |
} |
| 2011 |
|
| 2012 |
@Override |
| 2013 |
public boolean dispatchCapturedPointerEvent(MotionEvent event) { |
| 2014 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 2015 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 2016 |
if (super.dispatchCapturedPointerEvent(event)) { |
| 2017 |
return true; |
| 2018 |
} |
| 2019 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 2020 |
== PFLAG_HAS_BOUNDS) { |
| 2021 |
if (mFocused.dispatchCapturedPointerEvent(event)) { |
| 2022 |
return true; |
| 2023 |
} |
| 2024 |
} |
| 2025 |
return false; |
| 2026 |
} |
| 2027 |
|
| 2028 |
@Override |
| 2029 |
public void dispatchPointerCaptureChanged(boolean hasCapture) { |
| 2030 |
exitHoverTargets(); |
| 2031 |
|
| 2032 |
super.dispatchPointerCaptureChanged(hasCapture); |
| 2033 |
final int count = mChildrenCount; |
| 2034 |
final View[] children = mChildren; |
| 2035 |
for (int i = 0; i < count; i++) { |
| 2036 |
children[i].dispatchPointerCaptureChanged(hasCapture); |
| 2037 |
} |
| 2038 |
} |
| 2039 |
|
| 2040 |
@Override |
| 2041 |
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) { |
| 2042 |
final float x = event.getX(pointerIndex); |
| 2043 |
final float y = event.getY(pointerIndex); |
| 2044 |
if (isOnScrollbarThumb(x, y) || isDraggingScrollBar()) { |
| 2045 |
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_ARROW); |
| 2046 |
} |
| 2047 |
|
| 2048 |
final int childrenCount = mChildrenCount; |
| 2049 |
if (childrenCount != 0) { |
| 2050 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2051 |
final boolean customOrder = preorderedList == null |
| 2052 |
&& isChildrenDrawingOrderEnabled(); |
| 2053 |
final View[] children = mChildren; |
| 2054 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 2055 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2056 |
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 2057 |
|
| 2058 |
if (!child.canReceivePointerEvents() |
| 2059 |
|| !isTransformedTouchPointInView(x, y, child, null)) { |
| 2060 |
continue; |
| 2061 |
} |
| 2062 |
final PointerIcon pointerIcon = |
| 2063 |
dispatchResolvePointerIcon(event, pointerIndex, child); |
| 2064 |
if (pointerIcon != null) { |
| 2065 |
if (preorderedList != null) preorderedList.clear(); |
| 2066 |
return pointerIcon; |
| 2067 |
} |
| 2068 |
} |
| 2069 |
if (preorderedList != null) preorderedList.clear(); |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
return super.onResolvePointerIcon(event, pointerIndex); |
| 2075 |
} |
| 2076 |
|
| 2077 |
private PointerIcon dispatchResolvePointerIcon(MotionEvent event, int pointerIndex, |
| 2078 |
View child) { |
| 2079 |
final PointerIcon pointerIcon; |
| 2080 |
if (!child.hasIdentityMatrix()) { |
| 2081 |
MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
| 2082 |
pointerIcon = child.onResolvePointerIcon(transformedEvent, pointerIndex); |
| 2083 |
transformedEvent.recycle(); |
| 2084 |
} else { |
| 2085 |
final float offsetX = mScrollX - child.mLeft; |
| 2086 |
final float offsetY = mScrollY - child.mTop; |
| 2087 |
event.offsetLocation(offsetX, offsetY); |
| 2088 |
pointerIcon = child.onResolvePointerIcon(event, pointerIndex); |
| 2089 |
event.offsetLocation(-offsetX, -offsetY); |
| 2090 |
} |
| 2091 |
return pointerIcon; |
| 2092 |
} |
| 2093 |
|
| 2094 |
private int getAndVerifyPreorderedIndex(int childrenCount, int i, boolean customOrder) { |
| 2095 |
final int childIndex; |
| 2096 |
if (customOrder) { |
| 2097 |
final int childIndex1 = getChildDrawingOrder(childrenCount, i); |
| 2098 |
if (childIndex1 >= childrenCount) { |
| 2099 |
throw new IndexOutOfBoundsException("getChildDrawingOrder() " |
| 2100 |
+ "returned invalid index " + childIndex1 |
| 2101 |
+ " (child count is " + childrenCount + ")"); |
| 2102 |
} |
| 2103 |
childIndex = childIndex1; |
| 2104 |
} else { |
| 2105 |
childIndex = i; |
| 2106 |
} |
| 2107 |
return childIndex; |
| 2108 |
} |
| 2109 |
|
| 2110 |
@SuppressWarnings({"ConstantConditions"}) |
| 2111 |
@Override |
| 2112 |
protected boolean dispatchHoverEvent(MotionEvent event) { |
| 2113 |
final int action = event.getAction(); |
| 2114 |
|
| 2115 |
|
| 2116 |
final boolean interceptHover = onInterceptHoverEvent(event); |
| 2117 |
event.setAction(action); |
| 2118 |
|
| 2119 |
MotionEvent eventNoHistory = event; |
| 2120 |
boolean handled = false; |
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
HoverTarget firstOldHoverTarget = mFirstHoverTarget; |
| 2125 |
mFirstHoverTarget = null; |
| 2126 |
if (!interceptHover && action != MotionEvent.ACTION_HOVER_EXIT) { |
| 2127 |
final float x = event.getX(); |
| 2128 |
final float y = event.getY(); |
| 2129 |
final int childrenCount = mChildrenCount; |
| 2130 |
if (childrenCount != 0) { |
| 2131 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2132 |
final boolean customOrder = preorderedList == null |
| 2133 |
&& isChildrenDrawingOrderEnabled(); |
| 2134 |
final View[] children = mChildren; |
| 2135 |
HoverTarget lastHoverTarget = null; |
| 2136 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 2137 |
final int childIndex = getAndVerifyPreorderedIndex( |
| 2138 |
childrenCount, i, customOrder); |
| 2139 |
final View child = getAndVerifyPreorderedView( |
| 2140 |
preorderedList, children, childIndex); |
| 2141 |
if (!child.canReceivePointerEvents() |
| 2142 |
|| !isTransformedTouchPointInView(x, y, child, null)) { |
| 2143 |
continue; |
| 2144 |
} |
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
HoverTarget hoverTarget = firstOldHoverTarget; |
| 2149 |
final boolean wasHovered; |
| 2150 |
for (HoverTarget predecessor = null; ;) { |
| 2151 |
if (hoverTarget == null) { |
| 2152 |
hoverTarget = HoverTarget.obtain(child); |
| 2153 |
wasHovered = false; |
| 2154 |
break; |
| 2155 |
} |
| 2156 |
|
| 2157 |
if (hoverTarget.child == child) { |
| 2158 |
if (predecessor != null) { |
| 2159 |
predecessor.next = hoverTarget.next; |
| 2160 |
} else { |
| 2161 |
firstOldHoverTarget = hoverTarget.next; |
| 2162 |
} |
| 2163 |
hoverTarget.next = null; |
| 2164 |
wasHovered = true; |
| 2165 |
break; |
| 2166 |
} |
| 2167 |
|
| 2168 |
predecessor = hoverTarget; |
| 2169 |
hoverTarget = hoverTarget.next; |
| 2170 |
} |
| 2171 |
|
| 2172 |
|
| 2173 |
if (lastHoverTarget != null) { |
| 2174 |
lastHoverTarget.next = hoverTarget; |
| 2175 |
} else { |
| 2176 |
mFirstHoverTarget = hoverTarget; |
| 2177 |
} |
| 2178 |
lastHoverTarget = hoverTarget; |
| 2179 |
|
| 2180 |
|
| 2181 |
if (action == MotionEvent.ACTION_HOVER_ENTER) { |
| 2182 |
if (!wasHovered) { |
| 2183 |
|
| 2184 |
handled |= dispatchTransformedGenericPointerEvent( |
| 2185 |
event, child); |
| 2186 |
} |
| 2187 |
} else if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2188 |
if (!wasHovered) { |
| 2189 |
|
| 2190 |
eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2191 |
eventNoHistory.setAction(MotionEvent.ACTION_HOVER_ENTER); |
| 2192 |
handled |= dispatchTransformedGenericPointerEvent( |
| 2193 |
eventNoHistory, child); |
| 2194 |
eventNoHistory.setAction(action); |
| 2195 |
|
| 2196 |
handled |= dispatchTransformedGenericPointerEvent( |
| 2197 |
eventNoHistory, child); |
| 2198 |
} else { |
| 2199 |
|
| 2200 |
handled |= dispatchTransformedGenericPointerEvent(event, child); |
| 2201 |
} |
| 2202 |
} |
| 2203 |
if (handled) { |
| 2204 |
break; |
| 2205 |
} |
| 2206 |
} |
| 2207 |
if (preorderedList != null) preorderedList.clear(); |
| 2208 |
} |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
while (firstOldHoverTarget != null) { |
| 2213 |
final View child = firstOldHoverTarget.child; |
| 2214 |
|
| 2215 |
|
| 2216 |
if (action == MotionEvent.ACTION_HOVER_EXIT) { |
| 2217 |
|
| 2218 |
handled |= dispatchTransformedGenericPointerEvent( |
| 2219 |
event, child); |
| 2220 |
} else { |
| 2221 |
|
| 2222 |
|
| 2223 |
if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2224 |
final boolean hoverExitPending = event.isHoverExitPending(); |
| 2225 |
event.setHoverExitPending(true); |
| 2226 |
dispatchTransformedGenericPointerEvent( |
| 2227 |
event, child); |
| 2228 |
event.setHoverExitPending(hoverExitPending); |
| 2229 |
} |
| 2230 |
eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2231 |
eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2232 |
dispatchTransformedGenericPointerEvent( |
| 2233 |
eventNoHistory, child); |
| 2234 |
eventNoHistory.setAction(action); |
| 2235 |
} |
| 2236 |
|
| 2237 |
final HoverTarget nextOldHoverTarget = firstOldHoverTarget.next; |
| 2238 |
firstOldHoverTarget.recycle(); |
| 2239 |
firstOldHoverTarget = nextOldHoverTarget; |
| 2240 |
} |
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
boolean newHoveredSelf = !handled && |
| 2245 |
(action != MotionEvent.ACTION_HOVER_EXIT) && !event.isHoverExitPending(); |
| 2246 |
if (newHoveredSelf == mHoveredSelf) { |
| 2247 |
if (newHoveredSelf) { |
| 2248 |
|
| 2249 |
handled |= super.dispatchHoverEvent(event); |
| 2250 |
} |
| 2251 |
} else { |
| 2252 |
if (mHoveredSelf) { |
| 2253 |
|
| 2254 |
if (action == MotionEvent.ACTION_HOVER_EXIT) { |
| 2255 |
|
| 2256 |
handled |= super.dispatchHoverEvent(event); |
| 2257 |
} else { |
| 2258 |
|
| 2259 |
|
| 2260 |
if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2261 |
super.dispatchHoverEvent(event); |
| 2262 |
} |
| 2263 |
eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2264 |
eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2265 |
super.dispatchHoverEvent(eventNoHistory); |
| 2266 |
eventNoHistory.setAction(action); |
| 2267 |
} |
| 2268 |
mHoveredSelf = false; |
| 2269 |
} |
| 2270 |
|
| 2271 |
if (newHoveredSelf) { |
| 2272 |
|
| 2273 |
if (action == MotionEvent.ACTION_HOVER_ENTER) { |
| 2274 |
|
| 2275 |
handled |= super.dispatchHoverEvent(event); |
| 2276 |
mHoveredSelf = true; |
| 2277 |
} else if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2278 |
|
| 2279 |
eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2280 |
eventNoHistory.setAction(MotionEvent.ACTION_HOVER_ENTER); |
| 2281 |
handled |= super.dispatchHoverEvent(eventNoHistory); |
| 2282 |
eventNoHistory.setAction(action); |
| 2283 |
|
| 2284 |
handled |= super.dispatchHoverEvent(eventNoHistory); |
| 2285 |
mHoveredSelf = true; |
| 2286 |
} |
| 2287 |
} |
| 2288 |
} |
| 2289 |
|
| 2290 |
|
| 2291 |
if (eventNoHistory != event) { |
| 2292 |
eventNoHistory.recycle(); |
| 2293 |
} |
| 2294 |
|
| 2295 |
|
| 2296 |
return handled; |
| 2297 |
} |
| 2298 |
|
| 2299 |
private void exitHoverTargets() { |
| 2300 |
if (mHoveredSelf || mFirstHoverTarget != null) { |
| 2301 |
final long now = SystemClock.uptimeMillis(); |
| 2302 |
MotionEvent event = MotionEvent.obtain(now, now, |
| 2303 |
MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2304 |
event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2305 |
dispatchHoverEvent(event); |
| 2306 |
event.recycle(); |
| 2307 |
} |
| 2308 |
} |
| 2309 |
|
| 2310 |
private void cancelHoverTarget(View view) { |
| 2311 |
HoverTarget predecessor = null; |
| 2312 |
HoverTarget target = mFirstHoverTarget; |
| 2313 |
while (target != null) { |
| 2314 |
final HoverTarget next = target.next; |
| 2315 |
if (target.child == view) { |
| 2316 |
if (predecessor == null) { |
| 2317 |
mFirstHoverTarget = next; |
| 2318 |
} else { |
| 2319 |
predecessor.next = next; |
| 2320 |
} |
| 2321 |
target.recycle(); |
| 2322 |
|
| 2323 |
final long now = SystemClock.uptimeMillis(); |
| 2324 |
MotionEvent event = MotionEvent.obtain(now, now, |
| 2325 |
MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2326 |
event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2327 |
view.dispatchHoverEvent(event); |
| 2328 |
event.recycle(); |
| 2329 |
return; |
| 2330 |
} |
| 2331 |
predecessor = target; |
| 2332 |
target = next; |
| 2333 |
} |
| 2334 |
} |
| 2335 |
|
| 2336 |
@Override |
| 2337 |
boolean dispatchTooltipHoverEvent(MotionEvent event) { |
| 2338 |
final int action = event.getAction(); |
| 2339 |
switch (action) { |
| 2340 |
case MotionEvent.ACTION_HOVER_ENTER: |
| 2341 |
break; |
| 2342 |
|
| 2343 |
case MotionEvent.ACTION_HOVER_MOVE: |
| 2344 |
View newTarget = null; |
| 2345 |
|
| 2346 |
|
| 2347 |
final int childrenCount = mChildrenCount; |
| 2348 |
if (childrenCount != 0) { |
| 2349 |
final float x = event.getX(); |
| 2350 |
final float y = event.getY(); |
| 2351 |
|
| 2352 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2353 |
final boolean customOrder = preorderedList == null |
| 2354 |
&& isChildrenDrawingOrderEnabled(); |
| 2355 |
final View[] children = mChildren; |
| 2356 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 2357 |
final int childIndex = |
| 2358 |
getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2359 |
final View child = |
| 2360 |
getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 2361 |
if (!child.canReceivePointerEvents() |
| 2362 |
|| !isTransformedTouchPointInView(x, y, child, null)) { |
| 2363 |
continue; |
| 2364 |
} |
| 2365 |
if (dispatchTooltipHoverEvent(event, child)) { |
| 2366 |
newTarget = child; |
| 2367 |
break; |
| 2368 |
} |
| 2369 |
} |
| 2370 |
if (preorderedList != null) preorderedList.clear(); |
| 2371 |
} |
| 2372 |
|
| 2373 |
if (mTooltipHoverTarget != newTarget) { |
| 2374 |
if (mTooltipHoverTarget != null) { |
| 2375 |
event.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2376 |
mTooltipHoverTarget.dispatchTooltipHoverEvent(event); |
| 2377 |
event.setAction(action); |
| 2378 |
} |
| 2379 |
mTooltipHoverTarget = newTarget; |
| 2380 |
} |
| 2381 |
|
| 2382 |
if (mTooltipHoverTarget != null) { |
| 2383 |
if (mTooltipHoveredSelf) { |
| 2384 |
mTooltipHoveredSelf = false; |
| 2385 |
event.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2386 |
super.dispatchTooltipHoverEvent(event); |
| 2387 |
event.setAction(action); |
| 2388 |
} |
| 2389 |
return true; |
| 2390 |
} |
| 2391 |
|
| 2392 |
mTooltipHoveredSelf = super.dispatchTooltipHoverEvent(event); |
| 2393 |
return mTooltipHoveredSelf; |
| 2394 |
|
| 2395 |
case MotionEvent.ACTION_HOVER_EXIT: |
| 2396 |
if (mTooltipHoverTarget != null) { |
| 2397 |
mTooltipHoverTarget.dispatchTooltipHoverEvent(event); |
| 2398 |
mTooltipHoverTarget = null; |
| 2399 |
} else if (mTooltipHoveredSelf) { |
| 2400 |
super.dispatchTooltipHoverEvent(event); |
| 2401 |
mTooltipHoveredSelf = false; |
| 2402 |
} |
| 2403 |
break; |
| 2404 |
} |
| 2405 |
return false; |
| 2406 |
} |
| 2407 |
|
| 2408 |
private boolean dispatchTooltipHoverEvent(MotionEvent event, View child) { |
| 2409 |
final boolean result; |
| 2410 |
if (!child.hasIdentityMatrix()) { |
| 2411 |
MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
| 2412 |
result = child.dispatchTooltipHoverEvent(transformedEvent); |
| 2413 |
transformedEvent.recycle(); |
| 2414 |
} else { |
| 2415 |
final float offsetX = mScrollX - child.mLeft; |
| 2416 |
final float offsetY = mScrollY - child.mTop; |
| 2417 |
event.offsetLocation(offsetX, offsetY); |
| 2418 |
result = child.dispatchTooltipHoverEvent(event); |
| 2419 |
event.offsetLocation(-offsetX, -offsetY); |
| 2420 |
} |
| 2421 |
return result; |
| 2422 |
} |
| 2423 |
|
| 2424 |
private void exitTooltipHoverTargets() { |
| 2425 |
if (mTooltipHoveredSelf || mTooltipHoverTarget != null) { |
| 2426 |
final long now = SystemClock.uptimeMillis(); |
| 2427 |
MotionEvent event = MotionEvent.obtain(now, now, |
| 2428 |
MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2429 |
event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2430 |
dispatchTooltipHoverEvent(event); |
| 2431 |
event.recycle(); |
| 2432 |
} |
| 2433 |
} |
| 2434 |
|
| 2435 |
|
| 2436 |
@Override |
| 2437 |
protected boolean hasHoveredChild() { |
| 2438 |
return mFirstHoverTarget != null; |
| 2439 |
} |
| 2440 |
|
| 2441 |
|
| 2442 |
@Override |
| 2443 |
protected boolean pointInHoveredChild(MotionEvent event) { |
| 2444 |
if (mFirstHoverTarget != null) { |
| 2445 |
return isTransformedTouchPointInView(event.getX(), event.getY(), |
| 2446 |
mFirstHoverTarget.child, null); |
| 2447 |
} |
| 2448 |
return false; |
| 2449 |
} |
| 2450 |
|
| 2451 |
@Override |
| 2452 |
public void addChildrenForAccessibility(ArrayList<View> outChildren) { |
| 2453 |
if (getAccessibilityNodeProvider() != null) { |
| 2454 |
return; |
| 2455 |
} |
| 2456 |
ChildListForAccessibility children = ChildListForAccessibility.obtain(this, true); |
| 2457 |
try { |
| 2458 |
final int childrenCount = children.getChildCount(); |
| 2459 |
for (int i = 0; i < childrenCount; i++) { |
| 2460 |
View child = children.getChildAt(i); |
| 2461 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 2462 |
if (child.includeForAccessibility()) { |
| 2463 |
outChildren.add(child); |
| 2464 |
} else { |
| 2465 |
child.addChildrenForAccessibility(outChildren); |
| 2466 |
} |
| 2467 |
} |
| 2468 |
} |
| 2469 |
} finally { |
| 2470 |
children.recycle(); |
| 2471 |
} |
| 2472 |
} |
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
public boolean onInterceptHoverEvent(MotionEvent event) { |
| 2513 |
if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 2514 |
final int action = event.getAction(); |
| 2515 |
final float x = event.getX(); |
| 2516 |
final float y = event.getY(); |
| 2517 |
if ((action == MotionEvent.ACTION_HOVER_MOVE |
| 2518 |
|| action == MotionEvent.ACTION_HOVER_ENTER) && isOnScrollbar(x, y)) { |
| 2519 |
return true; |
| 2520 |
} |
| 2521 |
} |
| 2522 |
return false; |
| 2523 |
} |
| 2524 |
|
| 2525 |
private static MotionEvent obtainMotionEventNoHistoryOrSelf(MotionEvent event) { |
| 2526 |
if (event.getHistorySize() == 0) { |
| 2527 |
return event; |
| 2528 |
} |
| 2529 |
return MotionEvent.obtainNoHistory(event); |
| 2530 |
} |
| 2531 |
|
| 2532 |
@Override |
| 2533 |
protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 2534 |
|
| 2535 |
final int childrenCount = mChildrenCount; |
| 2536 |
if (childrenCount != 0) { |
| 2537 |
final float x = event.getX(); |
| 2538 |
final float y = event.getY(); |
| 2539 |
|
| 2540 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2541 |
final boolean customOrder = preorderedList == null |
| 2542 |
&& isChildrenDrawingOrderEnabled(); |
| 2543 |
final View[] children = mChildren; |
| 2544 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 2545 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2546 |
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 2547 |
if (!child.canReceivePointerEvents() |
| 2548 |
|| !isTransformedTouchPointInView(x, y, child, null)) { |
| 2549 |
continue; |
| 2550 |
} |
| 2551 |
|
| 2552 |
if (dispatchTransformedGenericPointerEvent(event, child)) { |
| 2553 |
if (preorderedList != null) preorderedList.clear(); |
| 2554 |
return true; |
| 2555 |
} |
| 2556 |
} |
| 2557 |
if (preorderedList != null) preorderedList.clear(); |
| 2558 |
} |
| 2559 |
|
| 2560 |
|
| 2561 |
return super.dispatchGenericPointerEvent(event); |
| 2562 |
} |
| 2563 |
|
| 2564 |
@Override |
| 2565 |
protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 2566 |
|
| 2567 |
if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 2568 |
== (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 2569 |
return super.dispatchGenericFocusedEvent(event); |
| 2570 |
} else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 2571 |
== PFLAG_HAS_BOUNDS) { |
| 2572 |
return mFocused.dispatchGenericMotionEvent(event); |
| 2573 |
} |
| 2574 |
return false; |
| 2575 |
} |
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
private boolean dispatchTransformedGenericPointerEvent(MotionEvent event, View child) { |
| 2586 |
boolean handled; |
| 2587 |
if (!child.hasIdentityMatrix()) { |
| 2588 |
MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
| 2589 |
handled = child.dispatchGenericMotionEvent(transformedEvent); |
| 2590 |
transformedEvent.recycle(); |
| 2591 |
} else { |
| 2592 |
final float offsetX = mScrollX - child.mLeft; |
| 2593 |
final float offsetY = mScrollY - child.mTop; |
| 2594 |
event.offsetLocation(offsetX, offsetY); |
| 2595 |
handled = child.dispatchGenericMotionEvent(event); |
| 2596 |
event.offsetLocation(-offsetX, -offsetY); |
| 2597 |
} |
| 2598 |
return handled; |
| 2599 |
} |
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
private MotionEvent getTransformedMotionEvent(MotionEvent event, View child) { |
| 2611 |
final float offsetX = mScrollX - child.mLeft; |
| 2612 |
final float offsetY = mScrollY - child.mTop; |
| 2613 |
final MotionEvent transformedEvent = MotionEvent.obtain(event); |
| 2614 |
transformedEvent.offsetLocation(offsetX, offsetY); |
| 2615 |
if (!child.hasIdentityMatrix()) { |
| 2616 |
transformedEvent.transform(child.getInverseMatrix()); |
| 2617 |
} |
| 2618 |
return transformedEvent; |
| 2619 |
} |
| 2620 |
|
| 2621 |
@Override |
| 2622 |
public boolean dispatchTouchEvent(MotionEvent ev) { |
| 2623 |
if (mInputEventConsistencyVerifier != null) { |
| 2624 |
mInputEventConsistencyVerifier.onTouchEvent(ev, 1); |
| 2625 |
} |
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
if (ev.isTargetAccessibilityFocus() && isAccessibilityFocusedViewOrHost()) { |
| 2630 |
ev.setTargetAccessibilityFocus(false); |
| 2631 |
} |
| 2632 |
|
| 2633 |
boolean handled = false; |
| 2634 |
if (onFilterTouchEventForSecurity(ev)) { |
| 2635 |
final int action = ev.getAction(); |
| 2636 |
final int actionMasked = action & MotionEvent.ACTION_MASK; |
| 2637 |
|
| 2638 |
|
| 2639 |
if (actionMasked == MotionEvent.ACTION_DOWN) { |
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
cancelAndClearTouchTargets(ev); |
| 2644 |
resetTouchState(); |
| 2645 |
} |
| 2646 |
|
| 2647 |
|
| 2648 |
final boolean intercepted; |
| 2649 |
if (actionMasked == MotionEvent.ACTION_DOWN |
| 2650 |
|| mFirstTouchTarget != null) { |
| 2651 |
final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0; |
| 2652 |
if (!disallowIntercept) { |
| 2653 |
intercepted = onInterceptTouchEvent(ev); |
| 2654 |
ev.setAction(action); |
| 2655 |
} else { |
| 2656 |
intercepted = false; |
| 2657 |
} |
| 2658 |
} else { |
| 2659 |
|
| 2660 |
|
| 2661 |
intercepted = true; |
| 2662 |
} |
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
if (intercepted || mFirstTouchTarget != null) { |
| 2667 |
ev.setTargetAccessibilityFocus(false); |
| 2668 |
} |
| 2669 |
|
| 2670 |
|
| 2671 |
final boolean canceled = resetCancelNextUpFlag(this) |
| 2672 |
|| actionMasked == MotionEvent.ACTION_CANCEL; |
| 2673 |
|
| 2674 |
|
| 2675 |
final boolean isMouseEvent = ev.getSource() == InputDevice.SOURCE_MOUSE; |
| 2676 |
final boolean split = (mGroupFlags & FLAG_SPLIT_MOTION_EVENTS) != 0 |
| 2677 |
&& !isMouseEvent; |
| 2678 |
TouchTarget newTouchTarget = null; |
| 2679 |
boolean alreadyDispatchedToNewTouchTarget = false; |
| 2680 |
if (!canceled && !intercepted) { |
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
View childWithAccessibilityFocus = ev.isTargetAccessibilityFocus() |
| 2687 |
? findChildWithAccessibilityFocus() : null; |
| 2688 |
|
| 2689 |
if (actionMasked == MotionEvent.ACTION_DOWN |
| 2690 |
|| (split && actionMasked == MotionEvent.ACTION_POINTER_DOWN) |
| 2691 |
|| actionMasked == MotionEvent.ACTION_HOVER_MOVE) { |
| 2692 |
final int actionIndex = ev.getActionIndex(); |
| 2693 |
final int idBitsToAssign = split ? 1 << ev.getPointerId(actionIndex) |
| 2694 |
: TouchTarget.ALL_POINTER_IDS; |
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
removePointersFromTouchTargets(idBitsToAssign); |
| 2699 |
|
| 2700 |
final int childrenCount = mChildrenCount; |
| 2701 |
if (newTouchTarget == null && childrenCount != 0) { |
| 2702 |
final float x = |
| 2703 |
isMouseEvent ? ev.getXCursorPosition() : ev.getX(actionIndex); |
| 2704 |
final float y = |
| 2705 |
isMouseEvent ? ev.getYCursorPosition() : ev.getY(actionIndex); |
| 2706 |
|
| 2707 |
|
| 2708 |
final ArrayList<View> preorderedList = buildTouchDispatchChildList(); |
| 2709 |
final boolean customOrder = preorderedList == null |
| 2710 |
&& isChildrenDrawingOrderEnabled(); |
| 2711 |
final View[] children = mChildren; |
| 2712 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 2713 |
final int childIndex = getAndVerifyPreorderedIndex( |
| 2714 |
childrenCount, i, customOrder); |
| 2715 |
final View child = getAndVerifyPreorderedView( |
| 2716 |
preorderedList, children, childIndex); |
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
if (childWithAccessibilityFocus != null) { |
| 2723 |
if (childWithAccessibilityFocus != child) { |
| 2724 |
continue; |
| 2725 |
} |
| 2726 |
childWithAccessibilityFocus = null; |
| 2727 |
i = childrenCount; |
| 2728 |
} |
| 2729 |
|
| 2730 |
if (!child.canReceivePointerEvents() |
| 2731 |
|| !isTransformedTouchPointInView(x, y, child, null)) { |
| 2732 |
ev.setTargetAccessibilityFocus(false); |
| 2733 |
continue; |
| 2734 |
} |
| 2735 |
|
| 2736 |
newTouchTarget = getTouchTarget(child); |
| 2737 |
if (newTouchTarget != null) { |
| 2738 |
|
| 2739 |
|
| 2740 |
newTouchTarget.pointerIdBits |= idBitsToAssign; |
| 2741 |
break; |
| 2742 |
} |
| 2743 |
|
| 2744 |
resetCancelNextUpFlag(child); |
| 2745 |
if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) { |
| 2746 |
|
| 2747 |
mLastTouchDownTime = ev.getDownTime(); |
| 2748 |
if (preorderedList != null) { |
| 2749 |
|
| 2750 |
for (int j = 0; j < childrenCount; j++) { |
| 2751 |
if (children[childIndex] == mChildren[j]) { |
| 2752 |
mLastTouchDownIndex = j; |
| 2753 |
break; |
| 2754 |
} |
| 2755 |
} |
| 2756 |
} else { |
| 2757 |
mLastTouchDownIndex = childIndex; |
| 2758 |
} |
| 2759 |
mLastTouchDownX = ev.getX(); |
| 2760 |
mLastTouchDownY = ev.getY(); |
| 2761 |
newTouchTarget = addTouchTarget(child, idBitsToAssign); |
| 2762 |
alreadyDispatchedToNewTouchTarget = true; |
| 2763 |
break; |
| 2764 |
} |
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
ev.setTargetAccessibilityFocus(false); |
| 2769 |
} |
| 2770 |
if (preorderedList != null) preorderedList.clear(); |
| 2771 |
} |
| 2772 |
|
| 2773 |
if (newTouchTarget == null && mFirstTouchTarget != null) { |
| 2774 |
|
| 2775 |
|
| 2776 |
newTouchTarget = mFirstTouchTarget; |
| 2777 |
while (newTouchTarget.next != null) { |
| 2778 |
newTouchTarget = newTouchTarget.next; |
| 2779 |
} |
| 2780 |
newTouchTarget.pointerIdBits |= idBitsToAssign; |
| 2781 |
} |
| 2782 |
} |
| 2783 |
} |
| 2784 |
|
| 2785 |
|
| 2786 |
if (mFirstTouchTarget == null) { |
| 2787 |
|
| 2788 |
handled = dispatchTransformedTouchEvent(ev, canceled, null, |
| 2789 |
TouchTarget.ALL_POINTER_IDS); |
| 2790 |
} else { |
| 2791 |
|
| 2792 |
|
| 2793 |
TouchTarget predecessor = null; |
| 2794 |
TouchTarget target = mFirstTouchTarget; |
| 2795 |
while (target != null) { |
| 2796 |
final TouchTarget next = target.next; |
| 2797 |
if (alreadyDispatchedToNewTouchTarget && target == newTouchTarget) { |
| 2798 |
handled = true; |
| 2799 |
} else { |
| 2800 |
final boolean cancelChild = resetCancelNextUpFlag(target.child) |
| 2801 |
|| intercepted; |
| 2802 |
if (dispatchTransformedTouchEvent(ev, cancelChild, |
| 2803 |
target.child, target.pointerIdBits)) { |
| 2804 |
handled = true; |
| 2805 |
} |
| 2806 |
if (cancelChild) { |
| 2807 |
if (predecessor == null) { |
| 2808 |
mFirstTouchTarget = next; |
| 2809 |
} else { |
| 2810 |
predecessor.next = next; |
| 2811 |
} |
| 2812 |
target.recycle(); |
| 2813 |
target = next; |
| 2814 |
continue; |
| 2815 |
} |
| 2816 |
} |
| 2817 |
predecessor = target; |
| 2818 |
target = next; |
| 2819 |
} |
| 2820 |
} |
| 2821 |
|
| 2822 |
|
| 2823 |
if (canceled |
| 2824 |
|| actionMasked == MotionEvent.ACTION_UP |
| 2825 |
|| actionMasked == MotionEvent.ACTION_HOVER_MOVE) { |
| 2826 |
resetTouchState(); |
| 2827 |
} else if (split && actionMasked == MotionEvent.ACTION_POINTER_UP) { |
| 2828 |
final int actionIndex = ev.getActionIndex(); |
| 2829 |
final int idBitsToRemove = 1 << ev.getPointerId(actionIndex); |
| 2830 |
removePointersFromTouchTargets(idBitsToRemove); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
|
| 2834 |
if (!handled && mInputEventConsistencyVerifier != null) { |
| 2835 |
mInputEventConsistencyVerifier.onUnhandledEvent(ev, 1); |
| 2836 |
} |
| 2837 |
return handled; |
| 2838 |
} |
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
public ArrayList<View> buildTouchDispatchChildList() { |
| 2849 |
return buildOrderedChildList(); |
| 2850 |
} |
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
private View findChildWithAccessibilityFocus() { |
| 2858 |
ViewRootImpl viewRoot = getViewRootImpl(); |
| 2859 |
if (viewRoot == null) { |
| 2860 |
return null; |
| 2861 |
} |
| 2862 |
|
| 2863 |
View current = viewRoot.getAccessibilityFocusedHost(); |
| 2864 |
if (current == null) { |
| 2865 |
return null; |
| 2866 |
} |
| 2867 |
|
| 2868 |
ViewParent parent = current.getParent(); |
| 2869 |
while (parent instanceof View) { |
| 2870 |
if (parent == this) { |
| 2871 |
return current; |
| 2872 |
} |
| 2873 |
current = (View) parent; |
| 2874 |
parent = current.getParent(); |
| 2875 |
} |
| 2876 |
|
| 2877 |
return null; |
| 2878 |
} |
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
private void resetTouchState() { |
| 2884 |
clearTouchTargets(); |
| 2885 |
resetCancelNextUpFlag(this); |
| 2886 |
mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT; |
| 2887 |
mNestedScrollAxes = SCROLL_AXIS_NONE; |
| 2888 |
} |
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
private static boolean resetCancelNextUpFlag(@NonNull View view) { |
| 2895 |
if ((view.mPrivateFlags & PFLAG_CANCEL_NEXT_UP_EVENT) != 0) { |
| 2896 |
view.mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
| 2897 |
return true; |
| 2898 |
} |
| 2899 |
return false; |
| 2900 |
} |
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
private void clearTouchTargets() { |
| 2906 |
TouchTarget target = mFirstTouchTarget; |
| 2907 |
if (target != null) { |
| 2908 |
do { |
| 2909 |
TouchTarget next = target.next; |
| 2910 |
target.recycle(); |
| 2911 |
target = next; |
| 2912 |
} while (target != null); |
| 2913 |
mFirstTouchTarget = null; |
| 2914 |
} |
| 2915 |
} |
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
private void cancelAndClearTouchTargets(MotionEvent event) { |
| 2921 |
if (mFirstTouchTarget != null) { |
| 2922 |
boolean syntheticEvent = false; |
| 2923 |
if (event == null) { |
| 2924 |
final long now = SystemClock.uptimeMillis(); |
| 2925 |
event = MotionEvent.obtain(now, now, |
| 2926 |
MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
| 2927 |
event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2928 |
syntheticEvent = true; |
| 2929 |
} |
| 2930 |
|
| 2931 |
for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) { |
| 2932 |
resetCancelNextUpFlag(target.child); |
| 2933 |
dispatchTransformedTouchEvent(event, true, target.child, target.pointerIdBits); |
| 2934 |
} |
| 2935 |
clearTouchTargets(); |
| 2936 |
|
| 2937 |
if (syntheticEvent) { |
| 2938 |
event.recycle(); |
| 2939 |
} |
| 2940 |
} |
| 2941 |
} |
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
private TouchTarget getTouchTarget(@NonNull View child) { |
| 2948 |
for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) { |
| 2949 |
if (target.child == child) { |
| 2950 |
return target; |
| 2951 |
} |
| 2952 |
} |
| 2953 |
return null; |
| 2954 |
} |
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
private TouchTarget addTouchTarget(@NonNull View child, int pointerIdBits) { |
| 2961 |
final TouchTarget target = TouchTarget.obtain(child, pointerIdBits); |
| 2962 |
target.next = mFirstTouchTarget; |
| 2963 |
mFirstTouchTarget = target; |
| 2964 |
return target; |
| 2965 |
} |
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
private void removePointersFromTouchTargets(int pointerIdBits) { |
| 2971 |
TouchTarget predecessor = null; |
| 2972 |
TouchTarget target = mFirstTouchTarget; |
| 2973 |
while (target != null) { |
| 2974 |
final TouchTarget next = target.next; |
| 2975 |
if ((target.pointerIdBits & pointerIdBits) != 0) { |
| 2976 |
target.pointerIdBits &= ~pointerIdBits; |
| 2977 |
if (target.pointerIdBits == 0) { |
| 2978 |
if (predecessor == null) { |
| 2979 |
mFirstTouchTarget = next; |
| 2980 |
} else { |
| 2981 |
predecessor.next = next; |
| 2982 |
} |
| 2983 |
target.recycle(); |
| 2984 |
target = next; |
| 2985 |
continue; |
| 2986 |
} |
| 2987 |
} |
| 2988 |
predecessor = target; |
| 2989 |
target = next; |
| 2990 |
} |
| 2991 |
} |
| 2992 |
|
| 2993 |
@UnsupportedAppUsage |
| 2994 |
private void cancelTouchTarget(View view) { |
| 2995 |
TouchTarget predecessor = null; |
| 2996 |
TouchTarget target = mFirstTouchTarget; |
| 2997 |
while (target != null) { |
| 2998 |
final TouchTarget next = target.next; |
| 2999 |
if (target.child == view) { |
| 3000 |
if (predecessor == null) { |
| 3001 |
mFirstTouchTarget = next; |
| 3002 |
} else { |
| 3003 |
predecessor.next = next; |
| 3004 |
} |
| 3005 |
target.recycle(); |
| 3006 |
|
| 3007 |
final long now = SystemClock.uptimeMillis(); |
| 3008 |
MotionEvent event = MotionEvent.obtain(now, now, |
| 3009 |
MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
| 3010 |
event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 3011 |
view.dispatchTouchEvent(event); |
| 3012 |
event.recycle(); |
| 3013 |
return; |
| 3014 |
} |
| 3015 |
predecessor = target; |
| 3016 |
target = next; |
| 3017 |
} |
| 3018 |
} |
| 3019 |
|
| 3020 |
private Rect getTempRect() { |
| 3021 |
if (mTempRect == null) { |
| 3022 |
mTempRect = new Rect(); |
| 3023 |
} |
| 3024 |
return mTempRect; |
| 3025 |
} |
| 3026 |
|
| 3027 |
private float[] getTempLocationF() { |
| 3028 |
if (mTempPosition == null) { |
| 3029 |
mTempPosition = new float[2]; |
| 3030 |
} |
| 3031 |
return mTempPosition; |
| 3032 |
} |
| 3033 |
|
| 3034 |
private Point getTempPoint() { |
| 3035 |
if (mTempPoint == null) { |
| 3036 |
mTempPoint = new Point(); |
| 3037 |
} |
| 3038 |
return mTempPoint; |
| 3039 |
} |
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
@UnsupportedAppUsage |
| 3048 |
protected boolean isTransformedTouchPointInView(float x, float y, View child, |
| 3049 |
PointF outLocalPoint) { |
| 3050 |
final float[] point = getTempLocationF(); |
| 3051 |
point[0] = x; |
| 3052 |
point[1] = y; |
| 3053 |
transformPointToViewLocal(point, child); |
| 3054 |
final boolean isInView = child.pointInView(point[0], point[1]); |
| 3055 |
if (isInView && outLocalPoint != null) { |
| 3056 |
outLocalPoint.set(point[0], point[1]); |
| 3057 |
} |
| 3058 |
return isInView; |
| 3059 |
} |
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 3065 |
public void transformPointToViewLocal(float[] point, View child) { |
| 3066 |
point[0] += mScrollX - child.mLeft; |
| 3067 |
point[1] += mScrollY - child.mTop; |
| 3068 |
|
| 3069 |
if (!child.hasIdentityMatrix()) { |
| 3070 |
child.getInverseMatrix().mapPoints(point); |
| 3071 |
} |
| 3072 |
} |
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
private boolean dispatchTransformedTouchEvent(MotionEvent event, boolean cancel, |
| 3080 |
View child, int desiredPointerIdBits) { |
| 3081 |
final boolean handled; |
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
final int oldAction = event.getAction(); |
| 3086 |
if (cancel || oldAction == MotionEvent.ACTION_CANCEL) { |
| 3087 |
event.setAction(MotionEvent.ACTION_CANCEL); |
| 3088 |
if (child == null) { |
| 3089 |
handled = super.dispatchTouchEvent(event); |
| 3090 |
} else { |
| 3091 |
handled = child.dispatchTouchEvent(event); |
| 3092 |
} |
| 3093 |
event.setAction(oldAction); |
| 3094 |
return handled; |
| 3095 |
} |
| 3096 |
|
| 3097 |
|
| 3098 |
final int oldPointerIdBits = event.getPointerIdBits(); |
| 3099 |
final int newPointerIdBits = oldPointerIdBits & desiredPointerIdBits; |
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
if (newPointerIdBits == 0) { |
| 3104 |
return false; |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
final MotionEvent transformedEvent; |
| 3112 |
if (newPointerIdBits == oldPointerIdBits) { |
| 3113 |
if (child == null || child.hasIdentityMatrix()) { |
| 3114 |
if (child == null) { |
| 3115 |
handled = super.dispatchTouchEvent(event); |
| 3116 |
} else { |
| 3117 |
final float offsetX = mScrollX - child.mLeft; |
| 3118 |
final float offsetY = mScrollY - child.mTop; |
| 3119 |
event.offsetLocation(offsetX, offsetY); |
| 3120 |
|
| 3121 |
handled = child.dispatchTouchEvent(event); |
| 3122 |
|
| 3123 |
event.offsetLocation(-offsetX, -offsetY); |
| 3124 |
} |
| 3125 |
return handled; |
| 3126 |
} |
| 3127 |
transformedEvent = MotionEvent.obtain(event); |
| 3128 |
} else { |
| 3129 |
transformedEvent = event.split(newPointerIdBits); |
| 3130 |
} |
| 3131 |
|
| 3132 |
|
| 3133 |
if (child == null) { |
| 3134 |
handled = super.dispatchTouchEvent(transformedEvent); |
| 3135 |
} else { |
| 3136 |
final float offsetX = mScrollX - child.mLeft; |
| 3137 |
final float offsetY = mScrollY - child.mTop; |
| 3138 |
transformedEvent.offsetLocation(offsetX, offsetY); |
| 3139 |
if (! child.hasIdentityMatrix()) { |
| 3140 |
transformedEvent.transform(child.getInverseMatrix()); |
| 3141 |
} |
| 3142 |
|
| 3143 |
handled = child.dispatchTouchEvent(transformedEvent); |
| 3144 |
} |
| 3145 |
|
| 3146 |
|
| 3147 |
transformedEvent.recycle(); |
| 3148 |
return handled; |
| 3149 |
} |
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
public void setMotionEventSplittingEnabled(boolean split) { |
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
if (split) { |
| 3171 |
mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS; |
| 3172 |
} else { |
| 3173 |
mGroupFlags &= ~FLAG_SPLIT_MOTION_EVENTS; |
| 3174 |
} |
| 3175 |
} |
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
@InspectableProperty(name = "splitMotionEvents") |
| 3182 |
public boolean isMotionEventSplittingEnabled() { |
| 3183 |
return (mGroupFlags & FLAG_SPLIT_MOTION_EVENTS) == FLAG_SPLIT_MOTION_EVENTS; |
| 3184 |
} |
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
@InspectableProperty |
| 3199 |
public boolean isTransitionGroup() { |
| 3200 |
if ((mGroupFlags & FLAG_IS_TRANSITION_GROUP_SET) != 0) { |
| 3201 |
return ((mGroupFlags & FLAG_IS_TRANSITION_GROUP) != 0); |
| 3202 |
} else { |
| 3203 |
final ViewOutlineProvider outlineProvider = getOutlineProvider(); |
| 3204 |
return getBackground() != null || getTransitionName() != null || |
| 3205 |
(outlineProvider != null && outlineProvider != ViewOutlineProvider.BACKGROUND); |
| 3206 |
} |
| 3207 |
} |
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
public void setTransitionGroup(boolean isTransitionGroup) { |
| 3220 |
mGroupFlags |= FLAG_IS_TRANSITION_GROUP_SET; |
| 3221 |
if (isTransitionGroup) { |
| 3222 |
mGroupFlags |= FLAG_IS_TRANSITION_GROUP; |
| 3223 |
} else { |
| 3224 |
mGroupFlags &= ~FLAG_IS_TRANSITION_GROUP; |
| 3225 |
} |
| 3226 |
} |
| 3227 |
|
| 3228 |
@Override |
| 3229 |
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 3230 |
|
| 3231 |
if (disallowIntercept == ((mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0)) { |
| 3232 |
|
| 3233 |
return; |
| 3234 |
} |
| 3235 |
|
| 3236 |
if (disallowIntercept) { |
| 3237 |
mGroupFlags |= FLAG_DISALLOW_INTERCEPT; |
| 3238 |
} else { |
| 3239 |
mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT; |
| 3240 |
} |
| 3241 |
|
| 3242 |
|
| 3243 |
if (mParent != null) { |
| 3244 |
mParent.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3245 |
} |
| 3246 |
} |
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 3286 |
if (ev.isFromSource(InputDevice.SOURCE_MOUSE) |
| 3287 |
&& ev.getAction() == MotionEvent.ACTION_DOWN |
| 3288 |
&& ev.isButtonPressed(MotionEvent.BUTTON_PRIMARY) |
| 3289 |
&& isOnScrollbarThumb(ev.getX(), ev.getY())) { |
| 3290 |
return true; |
| 3291 |
} |
| 3292 |
return false; |
| 3293 |
} |
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
@Override |
| 3310 |
public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 3311 |
if (DBG) { |
| 3312 |
System.out.println(this + " ViewGroup.requestFocus direction=" |
| 3313 |
+ direction); |
| 3314 |
} |
| 3315 |
int descendantFocusability = getDescendantFocusability(); |
| 3316 |
|
| 3317 |
boolean result; |
| 3318 |
switch (descendantFocusability) { |
| 3319 |
case FOCUS_BLOCK_DESCENDANTS: |
| 3320 |
result = super.requestFocus(direction, previouslyFocusedRect); |
| 3321 |
break; |
| 3322 |
case FOCUS_BEFORE_DESCENDANTS: { |
| 3323 |
final boolean took = super.requestFocus(direction, previouslyFocusedRect); |
| 3324 |
result = took ? took : onRequestFocusInDescendants(direction, |
| 3325 |
previouslyFocusedRect); |
| 3326 |
break; |
| 3327 |
} |
| 3328 |
case FOCUS_AFTER_DESCENDANTS: { |
| 3329 |
final boolean took = onRequestFocusInDescendants(direction, previouslyFocusedRect); |
| 3330 |
result = took ? took : super.requestFocus(direction, previouslyFocusedRect); |
| 3331 |
break; |
| 3332 |
} |
| 3333 |
default: |
| 3334 |
throw new IllegalStateException("descendant focusability must be " |
| 3335 |
+ "one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS " |
| 3336 |
+ "but is " + descendantFocusability); |
| 3337 |
} |
| 3338 |
if (result && !isLayoutValid() && ((mPrivateFlags & PFLAG_WANTS_FOCUS) == 0)) { |
| 3339 |
mPrivateFlags |= PFLAG_WANTS_FOCUS; |
| 3340 |
} |
| 3341 |
return result; |
| 3342 |
} |
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
@SuppressWarnings({"ConstantConditions"}) |
| 3356 |
protected boolean onRequestFocusInDescendants(int direction, |
| 3357 |
Rect previouslyFocusedRect) { |
| 3358 |
int index; |
| 3359 |
int increment; |
| 3360 |
int end; |
| 3361 |
int count = mChildrenCount; |
| 3362 |
if ((direction & FOCUS_FORWARD) != 0) { |
| 3363 |
index = 0; |
| 3364 |
increment = 1; |
| 3365 |
end = count; |
| 3366 |
} else { |
| 3367 |
index = count - 1; |
| 3368 |
increment = -1; |
| 3369 |
end = -1; |
| 3370 |
} |
| 3371 |
final View[] children = mChildren; |
| 3372 |
for (int i = index; i != end; i += increment) { |
| 3373 |
View child = children[i]; |
| 3374 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 3375 |
if (child.requestFocus(direction, previouslyFocusedRect)) { |
| 3376 |
return true; |
| 3377 |
} |
| 3378 |
} |
| 3379 |
} |
| 3380 |
return false; |
| 3381 |
} |
| 3382 |
|
| 3383 |
@Override |
| 3384 |
public boolean restoreDefaultFocus() { |
| 3385 |
if (mDefaultFocus != null |
| 3386 |
&& getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS |
| 3387 |
&& (mDefaultFocus.mViewFlags & VISIBILITY_MASK) == VISIBLE |
| 3388 |
&& mDefaultFocus.restoreDefaultFocus()) { |
| 3389 |
return true; |
| 3390 |
} |
| 3391 |
return super.restoreDefaultFocus(); |
| 3392 |
} |
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
|
| 3397 |
@TestApi |
| 3398 |
@Override |
| 3399 |
public boolean restoreFocusInCluster(@FocusRealDirection int direction) { |
| 3400 |
|
| 3401 |
if (isKeyboardNavigationCluster()) { |
| 3402 |
final boolean blockedFocus = getTouchscreenBlocksFocus(); |
| 3403 |
try { |
| 3404 |
setTouchscreenBlocksFocusNoRefocus(false); |
| 3405 |
return restoreFocusInClusterInternal(direction); |
| 3406 |
} finally { |
| 3407 |
setTouchscreenBlocksFocusNoRefocus(blockedFocus); |
| 3408 |
} |
| 3409 |
} else { |
| 3410 |
return restoreFocusInClusterInternal(direction); |
| 3411 |
} |
| 3412 |
} |
| 3413 |
|
| 3414 |
private boolean restoreFocusInClusterInternal(@FocusRealDirection int direction) { |
| 3415 |
if (mFocusedInCluster != null && getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS |
| 3416 |
&& (mFocusedInCluster.mViewFlags & VISIBILITY_MASK) == VISIBLE |
| 3417 |
&& mFocusedInCluster.restoreFocusInCluster(direction)) { |
| 3418 |
return true; |
| 3419 |
} |
| 3420 |
return super.restoreFocusInCluster(direction); |
| 3421 |
} |
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
@Override |
| 3427 |
public boolean restoreFocusNotInCluster() { |
| 3428 |
if (mFocusedInCluster != null) { |
| 3429 |
|
| 3430 |
|
| 3431 |
return restoreFocusInCluster(View.FOCUS_DOWN); |
| 3432 |
} |
| 3433 |
if (isKeyboardNavigationCluster() || (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 3434 |
return false; |
| 3435 |
} |
| 3436 |
int descendentFocusability = getDescendantFocusability(); |
| 3437 |
if (descendentFocusability == FOCUS_BLOCK_DESCENDANTS) { |
| 3438 |
return super.requestFocus(FOCUS_DOWN, null); |
| 3439 |
} |
| 3440 |
if (descendentFocusability == FOCUS_BEFORE_DESCENDANTS |
| 3441 |
&& super.requestFocus(FOCUS_DOWN, null)) { |
| 3442 |
return true; |
| 3443 |
} |
| 3444 |
for (int i = 0; i < mChildrenCount; ++i) { |
| 3445 |
View child = mChildren[i]; |
| 3446 |
if (!child.isKeyboardNavigationCluster() |
| 3447 |
&& child.restoreFocusNotInCluster()) { |
| 3448 |
return true; |
| 3449 |
} |
| 3450 |
} |
| 3451 |
if (descendentFocusability == FOCUS_AFTER_DESCENDANTS && !hasFocusableChild(false)) { |
| 3452 |
return super.requestFocus(FOCUS_DOWN, null); |
| 3453 |
} |
| 3454 |
return false; |
| 3455 |
} |
| 3456 |
|
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
|
| 3461 |
|
| 3462 |
@Override |
| 3463 |
public void dispatchStartTemporaryDetach() { |
| 3464 |
super.dispatchStartTemporaryDetach(); |
| 3465 |
final int count = mChildrenCount; |
| 3466 |
final View[] children = mChildren; |
| 3467 |
for (int i = 0; i < count; i++) { |
| 3468 |
children[i].dispatchStartTemporaryDetach(); |
| 3469 |
} |
| 3470 |
} |
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
@Override |
| 3478 |
public void dispatchFinishTemporaryDetach() { |
| 3479 |
super.dispatchFinishTemporaryDetach(); |
| 3480 |
final int count = mChildrenCount; |
| 3481 |
final View[] children = mChildren; |
| 3482 |
for (int i = 0; i < count; i++) { |
| 3483 |
children[i].dispatchFinishTemporaryDetach(); |
| 3484 |
} |
| 3485 |
} |
| 3486 |
|
| 3487 |
@Override |
| 3488 |
@UnsupportedAppUsage |
| 3489 |
void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 3490 |
mGroupFlags |= FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW; |
| 3491 |
super.dispatchAttachedToWindow(info, visibility); |
| 3492 |
mGroupFlags &= ~FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW; |
| 3493 |
|
| 3494 |
final int count = mChildrenCount; |
| 3495 |
final View[] children = mChildren; |
| 3496 |
for (int i = 0; i < count; i++) { |
| 3497 |
final View child = children[i]; |
| 3498 |
child.dispatchAttachedToWindow(info, |
| 3499 |
combineVisibility(visibility, child.getVisibility())); |
| 3500 |
} |
| 3501 |
final int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 3502 |
for (int i = 0; i < transientCount; ++i) { |
| 3503 |
View view = mTransientViews.get(i); |
| 3504 |
view.dispatchAttachedToWindow(info, |
| 3505 |
combineVisibility(visibility, view.getVisibility())); |
| 3506 |
} |
| 3507 |
} |
| 3508 |
|
| 3509 |
@Override |
| 3510 |
void dispatchScreenStateChanged(int screenState) { |
| 3511 |
super.dispatchScreenStateChanged(screenState); |
| 3512 |
|
| 3513 |
final int count = mChildrenCount; |
| 3514 |
final View[] children = mChildren; |
| 3515 |
for (int i = 0; i < count; i++) { |
| 3516 |
children[i].dispatchScreenStateChanged(screenState); |
| 3517 |
} |
| 3518 |
} |
| 3519 |
|
| 3520 |
@Override |
| 3521 |
void dispatchMovedToDisplay(Display display, Configuration config) { |
| 3522 |
super.dispatchMovedToDisplay(display, config); |
| 3523 |
|
| 3524 |
final int count = mChildrenCount; |
| 3525 |
final View[] children = mChildren; |
| 3526 |
for (int i = 0; i < count; i++) { |
| 3527 |
children[i].dispatchMovedToDisplay(display, config); |
| 3528 |
} |
| 3529 |
} |
| 3530 |
|
| 3531 |
|
| 3532 |
@Override |
| 3533 |
public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 3534 |
boolean handled = false; |
| 3535 |
if (includeForAccessibility()) { |
| 3536 |
handled = super.dispatchPopulateAccessibilityEventInternal(event); |
| 3537 |
if (handled) { |
| 3538 |
return handled; |
| 3539 |
} |
| 3540 |
} |
| 3541 |
|
| 3542 |
ChildListForAccessibility children = ChildListForAccessibility.obtain(this, true); |
| 3543 |
try { |
| 3544 |
final int childCount = children.getChildCount(); |
| 3545 |
for (int i = 0; i < childCount; i++) { |
| 3546 |
View child = children.getChildAt(i); |
| 3547 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 3548 |
handled = child.dispatchPopulateAccessibilityEvent(event); |
| 3549 |
if (handled) { |
| 3550 |
return handled; |
| 3551 |
} |
| 3552 |
} |
| 3553 |
} |
| 3554 |
} finally { |
| 3555 |
children.recycle(); |
| 3556 |
} |
| 3557 |
return false; |
| 3558 |
} |
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
@Override |
| 3566 |
public void dispatchProvideStructure(ViewStructure structure) { |
| 3567 |
super.dispatchProvideStructure(structure); |
| 3568 |
if (isAssistBlocked() || structure.getChildCount() != 0) { |
| 3569 |
return; |
| 3570 |
} |
| 3571 |
final int childrenCount = mChildrenCount; |
| 3572 |
if (childrenCount <= 0) { |
| 3573 |
return; |
| 3574 |
} |
| 3575 |
|
| 3576 |
if (!isLaidOut()) { |
| 3577 |
if (Helper.sVerbose) { |
| 3578 |
Log.v(VIEW_LOG_TAG, "dispatchProvideStructure(): not laid out, ignoring " |
| 3579 |
+ childrenCount + " children of " + getAccessibilityViewId()); |
| 3580 |
} |
| 3581 |
return; |
| 3582 |
} |
| 3583 |
|
| 3584 |
structure.setChildCount(childrenCount); |
| 3585 |
ArrayList<View> tempPreorderedList = buildOrderedChildList(); |
| 3586 |
ArrayList<View> preorderedList = |
| 3587 |
tempPreorderedList != null ? new ArrayList<>(tempPreorderedList) : null; |
| 3588 |
boolean customOrder = preorderedList == null |
| 3589 |
&& isChildrenDrawingOrderEnabled(); |
| 3590 |
for (int i = 0; i < childrenCount; i++) { |
| 3591 |
int childIndex; |
| 3592 |
try { |
| 3593 |
childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 3594 |
} catch (IndexOutOfBoundsException e) { |
| 3595 |
childIndex = i; |
| 3596 |
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.M) { |
| 3597 |
Log.w(TAG, "Bad getChildDrawingOrder while collecting assist @ " |
| 3598 |
+ i + " of " + childrenCount, e); |
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
customOrder = false; |
| 3603 |
if (i > 0) { |
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
int[] permutation = new int[childrenCount]; |
| 3611 |
SparseBooleanArray usedIndices = new SparseBooleanArray(); |
| 3612 |
|
| 3613 |
for (int j = 0; j < i; j++) { |
| 3614 |
permutation[j] = getChildDrawingOrder(childrenCount, j); |
| 3615 |
usedIndices.put(permutation[j], true); |
| 3616 |
} |
| 3617 |
|
| 3618 |
|
| 3619 |
int nextIndex = 0; |
| 3620 |
for (int j = i; j < childrenCount; j++) { |
| 3621 |
while (usedIndices.get(nextIndex, false)) { |
| 3622 |
nextIndex++; |
| 3623 |
} |
| 3624 |
permutation[j] = nextIndex; |
| 3625 |
nextIndex++; |
| 3626 |
} |
| 3627 |
|
| 3628 |
preorderedList = new ArrayList<>(childrenCount); |
| 3629 |
for (int j = 0; j < childrenCount; j++) { |
| 3630 |
final int index = permutation[j]; |
| 3631 |
final View child = mChildren[index]; |
| 3632 |
preorderedList.add(child); |
| 3633 |
} |
| 3634 |
} |
| 3635 |
} else { |
| 3636 |
throw e; |
| 3637 |
} |
| 3638 |
} |
| 3639 |
final View child = getAndVerifyPreorderedView(preorderedList, mChildren, |
| 3640 |
childIndex); |
| 3641 |
final ViewStructure cstructure = structure.newChild(i); |
| 3642 |
child.dispatchProvideStructure(cstructure); |
| 3643 |
} |
| 3644 |
if (preorderedList != null) { |
| 3645 |
preorderedList.clear(); |
| 3646 |
} |
| 3647 |
} |
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
@Override |
| 3656 |
public void dispatchProvideAutofillStructure(ViewStructure structure, |
| 3657 |
@AutofillFlags int flags) { |
| 3658 |
super.dispatchProvideAutofillStructure(structure, flags); |
| 3659 |
|
| 3660 |
if (structure.getChildCount() != 0) { |
| 3661 |
return; |
| 3662 |
} |
| 3663 |
|
| 3664 |
if (!isLaidOut()) { |
| 3665 |
if (Helper.sVerbose) { |
| 3666 |
Log.v(VIEW_LOG_TAG, "dispatchProvideAutofillStructure(): not laid out, ignoring " |
| 3667 |
+ mChildrenCount + " children of " + getAutofillId()); |
| 3668 |
} |
| 3669 |
return; |
| 3670 |
} |
| 3671 |
|
| 3672 |
final ChildListForAutoFillOrContentCapture children = getChildrenForAutofill(flags); |
| 3673 |
final int childrenCount = children.size(); |
| 3674 |
structure.setChildCount(childrenCount); |
| 3675 |
for (int i = 0; i < childrenCount; i++) { |
| 3676 |
final View child = children.get(i); |
| 3677 |
final ViewStructure cstructure = structure.newChild(i); |
| 3678 |
child.dispatchProvideAutofillStructure(cstructure, flags); |
| 3679 |
} |
| 3680 |
children.recycle(); |
| 3681 |
} |
| 3682 |
|
| 3683 |
|
| 3684 |
@Override |
| 3685 |
public void dispatchProvideContentCaptureStructure() { |
| 3686 |
super.dispatchProvideContentCaptureStructure(); |
| 3687 |
|
| 3688 |
if (!isLaidOut()) return; |
| 3689 |
|
| 3690 |
final ChildListForAutoFillOrContentCapture children = getChildrenForContentCapture(); |
| 3691 |
final int childrenCount = children.size(); |
| 3692 |
for (int i = 0; i < childrenCount; i++) { |
| 3693 |
final View child = children.get(i); |
| 3694 |
child.dispatchProvideContentCaptureStructure(); |
| 3695 |
} |
| 3696 |
children.recycle(); |
| 3697 |
} |
| 3698 |
|
| 3699 |
|
| 3700 |
|
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
private @NonNull ChildListForAutoFillOrContentCapture getChildrenForAutofill( |
| 3705 |
@AutofillFlags int flags) { |
| 3706 |
final ChildListForAutoFillOrContentCapture children = ChildListForAutoFillOrContentCapture |
| 3707 |
.obtain(); |
| 3708 |
populateChildrenForAutofill(children, flags); |
| 3709 |
return children; |
| 3710 |
} |
| 3711 |
|
| 3712 |
|
| 3713 |
private void populateChildrenForAutofill(ArrayList<View> list, @AutofillFlags int flags) { |
| 3714 |
final int childrenCount = mChildrenCount; |
| 3715 |
if (childrenCount <= 0) { |
| 3716 |
return; |
| 3717 |
} |
| 3718 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 3719 |
final boolean customOrder = preorderedList == null |
| 3720 |
&& isChildrenDrawingOrderEnabled(); |
| 3721 |
for (int i = 0; i < childrenCount; i++) { |
| 3722 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 3723 |
final View child = (preorderedList == null) |
| 3724 |
? mChildren[childIndex] : preorderedList.get(childIndex); |
| 3725 |
if ((flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0 |
| 3726 |
|| child.isImportantForAutofill()) { |
| 3727 |
list.add(child); |
| 3728 |
} else if (child instanceof ViewGroup) { |
| 3729 |
((ViewGroup) child).populateChildrenForAutofill(list, flags); |
| 3730 |
} |
| 3731 |
} |
| 3732 |
} |
| 3733 |
|
| 3734 |
private @NonNull ChildListForAutoFillOrContentCapture getChildrenForContentCapture() { |
| 3735 |
final ChildListForAutoFillOrContentCapture children = ChildListForAutoFillOrContentCapture |
| 3736 |
.obtain(); |
| 3737 |
populateChildrenForContentCapture(children); |
| 3738 |
return children; |
| 3739 |
} |
| 3740 |
|
| 3741 |
|
| 3742 |
private void populateChildrenForContentCapture(ArrayList<View> list) { |
| 3743 |
final int childrenCount = mChildrenCount; |
| 3744 |
if (childrenCount <= 0) { |
| 3745 |
return; |
| 3746 |
} |
| 3747 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 3748 |
final boolean customOrder = preorderedList == null |
| 3749 |
&& isChildrenDrawingOrderEnabled(); |
| 3750 |
for (int i = 0; i < childrenCount; i++) { |
| 3751 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 3752 |
final View child = (preorderedList == null) |
| 3753 |
? mChildren[childIndex] : preorderedList.get(childIndex); |
| 3754 |
if (child.isImportantForContentCapture()) { |
| 3755 |
list.add(child); |
| 3756 |
} else if (child instanceof ViewGroup) { |
| 3757 |
((ViewGroup) child).populateChildrenForContentCapture(list); |
| 3758 |
} |
| 3759 |
} |
| 3760 |
} |
| 3761 |
|
| 3762 |
private static View getAndVerifyPreorderedView(ArrayList<View> preorderedList, View[] children, |
| 3763 |
int childIndex) { |
| 3764 |
final View child; |
| 3765 |
if (preorderedList != null) { |
| 3766 |
child = preorderedList.get(childIndex); |
| 3767 |
if (child == null) { |
| 3768 |
throw new RuntimeException("Invalid preorderedList contained null child at index " |
| 3769 |
+ childIndex); |
| 3770 |
} |
| 3771 |
} else { |
| 3772 |
child = children[childIndex]; |
| 3773 |
} |
| 3774 |
return child; |
| 3775 |
} |
| 3776 |
|
| 3777 |
|
| 3778 |
@Override |
| 3779 |
public void resetSubtreeAutofillIds() { |
| 3780 |
super.resetSubtreeAutofillIds(); |
| 3781 |
View[] children = mChildren; |
| 3782 |
final int childCount = mChildrenCount; |
| 3783 |
for (int i = 0; i < childCount; i++) { |
| 3784 |
children[i].resetSubtreeAutofillIds(); |
| 3785 |
} |
| 3786 |
} |
| 3787 |
|
| 3788 |
|
| 3789 |
@Override |
| 3790 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 3791 |
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 3792 |
super.onInitializeAccessibilityNodeInfoInternal(info); |
| 3793 |
if (getAccessibilityNodeProvider() != null) { |
| 3794 |
return; |
| 3795 |
} |
| 3796 |
if (mAttachInfo != null) { |
| 3797 |
final ArrayList<View> childrenForAccessibility = mAttachInfo.mTempArrayList; |
| 3798 |
childrenForAccessibility.clear(); |
| 3799 |
addChildrenForAccessibility(childrenForAccessibility); |
| 3800 |
final int childrenForAccessibilityCount = childrenForAccessibility.size(); |
| 3801 |
for (int i = 0; i < childrenForAccessibilityCount; i++) { |
| 3802 |
final View child = childrenForAccessibility.get(i); |
| 3803 |
info.addChildUnchecked(child); |
| 3804 |
} |
| 3805 |
childrenForAccessibility.clear(); |
| 3806 |
} |
| 3807 |
info.setAvailableExtraData(Collections.singletonList( |
| 3808 |
AccessibilityNodeInfo.EXTRA_DATA_RENDERING_INFO_KEY)); |
| 3809 |
} |
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
@Override |
| 3824 |
public void addExtraDataToAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info, |
| 3825 |
@NonNull String extraDataKey, @Nullable Bundle arguments) { |
| 3826 |
if (extraDataKey.equals(AccessibilityNodeInfo.EXTRA_DATA_RENDERING_INFO_KEY)) { |
| 3827 |
final AccessibilityNodeInfo.ExtraRenderingInfo extraRenderingInfo = |
| 3828 |
AccessibilityNodeInfo.ExtraRenderingInfo.obtain(); |
| 3829 |
extraRenderingInfo.setLayoutSize(getLayoutParams().width, getLayoutParams().height); |
| 3830 |
info.setExtraRenderingInfo(extraRenderingInfo); |
| 3831 |
} |
| 3832 |
} |
| 3833 |
|
| 3834 |
@Override |
| 3835 |
public CharSequence getAccessibilityClassName() { |
| 3836 |
return ViewGroup.class.getName(); |
| 3837 |
} |
| 3838 |
|
| 3839 |
@Override |
| 3840 |
public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 3841 |
|
| 3842 |
|
| 3843 |
if (getAccessibilityLiveRegion() != ACCESSIBILITY_LIVE_REGION_NONE) { |
| 3844 |
notifyViewAccessibilityStateChangedIfNeeded( |
| 3845 |
AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE); |
| 3846 |
} else if (mParent != null) { |
| 3847 |
try { |
| 3848 |
mParent.notifySubtreeAccessibilityStateChanged(this, source, changeType); |
| 3849 |
} catch (AbstractMethodError e) { |
| 3850 |
Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 3851 |
" does not fully implement ViewParent", e); |
| 3852 |
} |
| 3853 |
} |
| 3854 |
} |
| 3855 |
|
| 3856 |
|
| 3857 |
@Override |
| 3858 |
public void notifySubtreeAccessibilityStateChangedIfNeeded() { |
| 3859 |
if (!AccessibilityManager.getInstance(mContext).isEnabled() || mAttachInfo == null) { |
| 3860 |
return; |
| 3861 |
} |
| 3862 |
|
| 3863 |
|
| 3864 |
if ((getImportantForAccessibility() != IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) |
| 3865 |
&& !isImportantForAccessibility() && (getChildCount() > 0)) { |
| 3866 |
ViewParent a11yParent = getParentForAccessibility(); |
| 3867 |
if (a11yParent instanceof View) { |
| 3868 |
((View) a11yParent).notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 3869 |
return; |
| 3870 |
} |
| 3871 |
} |
| 3872 |
super.notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 3873 |
} |
| 3874 |
|
| 3875 |
@Override |
| 3876 |
void resetSubtreeAccessibilityStateChanged() { |
| 3877 |
super.resetSubtreeAccessibilityStateChanged(); |
| 3878 |
View[] children = mChildren; |
| 3879 |
final int childCount = mChildrenCount; |
| 3880 |
for (int i = 0; i < childCount; i++) { |
| 3881 |
children[i].resetSubtreeAccessibilityStateChanged(); |
| 3882 |
} |
| 3883 |
} |
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
int getNumChildrenForAccessibility() { |
| 3892 |
int numChildrenForAccessibility = 0; |
| 3893 |
for (int i = 0; i < getChildCount(); i++) { |
| 3894 |
View child = getChildAt(i); |
| 3895 |
if (child.includeForAccessibility()) { |
| 3896 |
numChildrenForAccessibility++; |
| 3897 |
} else if (child instanceof ViewGroup) { |
| 3898 |
numChildrenForAccessibility += ((ViewGroup) child) |
| 3899 |
.getNumChildrenForAccessibility(); |
| 3900 |
} |
| 3901 |
} |
| 3902 |
return numChildrenForAccessibility; |
| 3903 |
} |
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
|
| 3908 |
|
| 3909 |
|
| 3910 |
|
| 3911 |
|
| 3912 |
|
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
@Override |
| 3917 |
public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 3918 |
return false; |
| 3919 |
} |
| 3920 |
|
| 3921 |
@Override |
| 3922 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 3923 |
void dispatchDetachedFromWindow() { |
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
cancelAndClearTouchTargets(null); |
| 3930 |
|
| 3931 |
|
| 3932 |
exitHoverTargets(); |
| 3933 |
exitTooltipHoverTargets(); |
| 3934 |
|
| 3935 |
|
| 3936 |
mLayoutCalledWhileSuppressed = false; |
| 3937 |
|
| 3938 |
|
| 3939 |
mChildrenInterestedInDrag = null; |
| 3940 |
mIsInterestedInDrag = false; |
| 3941 |
if (mCurrentDragStartEvent != null) { |
| 3942 |
mCurrentDragStartEvent.recycle(); |
| 3943 |
mCurrentDragStartEvent = null; |
| 3944 |
} |
| 3945 |
|
| 3946 |
final int count = mChildrenCount; |
| 3947 |
final View[] children = mChildren; |
| 3948 |
for (int i = 0; i < count; i++) { |
| 3949 |
children[i].dispatchDetachedFromWindow(); |
| 3950 |
} |
| 3951 |
clearDisappearingChildren(); |
| 3952 |
final int transientCount = mTransientViews == null ? 0 : mTransientIndices.size(); |
| 3953 |
for (int i = 0; i < transientCount; ++i) { |
| 3954 |
View view = mTransientViews.get(i); |
| 3955 |
view.dispatchDetachedFromWindow(); |
| 3956 |
} |
| 3957 |
super.dispatchDetachedFromWindow(); |
| 3958 |
} |
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
|
| 3963 |
@Override |
| 3964 |
protected void internalSetPadding(int left, int top, int right, int bottom) { |
| 3965 |
super.internalSetPadding(left, top, right, bottom); |
| 3966 |
|
| 3967 |
if ((mPaddingLeft | mPaddingTop | mPaddingRight | mPaddingBottom) != 0) { |
| 3968 |
mGroupFlags |= FLAG_PADDING_NOT_NULL; |
| 3969 |
} else { |
| 3970 |
mGroupFlags &= ~FLAG_PADDING_NOT_NULL; |
| 3971 |
} |
| 3972 |
} |
| 3973 |
|
| 3974 |
@Override |
| 3975 |
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 3976 |
super.dispatchSaveInstanceState(container); |
| 3977 |
final int count = mChildrenCount; |
| 3978 |
final View[] children = mChildren; |
| 3979 |
for (int i = 0; i < count; i++) { |
| 3980 |
View c = children[i]; |
| 3981 |
if ((c.mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED) { |
| 3982 |
c.dispatchSaveInstanceState(container); |
| 3983 |
} |
| 3984 |
} |
| 3985 |
} |
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
protected void dispatchFreezeSelfOnly(SparseArray<Parcelable> container) { |
| 3996 |
super.dispatchSaveInstanceState(container); |
| 3997 |
} |
| 3998 |
|
| 3999 |
@Override |
| 4000 |
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 4001 |
super.dispatchRestoreInstanceState(container); |
| 4002 |
final int count = mChildrenCount; |
| 4003 |
final View[] children = mChildren; |
| 4004 |
for (int i = 0; i < count; i++) { |
| 4005 |
View c = children[i]; |
| 4006 |
if ((c.mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED) { |
| 4007 |
c.dispatchRestoreInstanceState(container); |
| 4008 |
} |
| 4009 |
} |
| 4010 |
} |
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
protected void dispatchThawSelfOnly(SparseArray<Parcelable> container) { |
| 4021 |
super.dispatchRestoreInstanceState(container); |
| 4022 |
} |
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
|
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
@Deprecated |
| 4043 |
protected void setChildrenDrawingCacheEnabled(boolean enabled) { |
| 4044 |
if (enabled || (mPersistentDrawingCache & PERSISTENT_ALL_CACHES) != PERSISTENT_ALL_CACHES) { |
| 4045 |
final View[] children = mChildren; |
| 4046 |
final int count = mChildrenCount; |
| 4047 |
for (int i = 0; i < count; i++) { |
| 4048 |
children[i].setDrawingCacheEnabled(enabled); |
| 4049 |
} |
| 4050 |
} |
| 4051 |
} |
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
@Override |
| 4057 |
public Bitmap createSnapshot(ViewDebug.CanvasProvider canvasProvider, boolean skipChildren) { |
| 4058 |
int count = mChildrenCount; |
| 4059 |
int[] visibilities = null; |
| 4060 |
|
| 4061 |
if (skipChildren) { |
| 4062 |
visibilities = new int[count]; |
| 4063 |
for (int i = 0; i < count; i++) { |
| 4064 |
View child = getChildAt(i); |
| 4065 |
visibilities[i] = child.getVisibility(); |
| 4066 |
if (visibilities[i] == View.VISIBLE) { |
| 4067 |
child.mViewFlags = (child.mViewFlags & ~View.VISIBILITY_MASK) |
| 4068 |
| (View.INVISIBLE & View.VISIBILITY_MASK); |
| 4069 |
} |
| 4070 |
} |
| 4071 |
} |
| 4072 |
|
| 4073 |
try { |
| 4074 |
return super.createSnapshot(canvasProvider, skipChildren); |
| 4075 |
} finally { |
| 4076 |
if (skipChildren) { |
| 4077 |
for (int i = 0; i < count; i++) { |
| 4078 |
View child = getChildAt(i); |
| 4079 |
child.mViewFlags = (child.mViewFlags & ~View.VISIBILITY_MASK) |
| 4080 |
| (visibilities[i] & View.VISIBILITY_MASK); |
| 4081 |
} |
| 4082 |
} |
| 4083 |
} |
| 4084 |
} |
| 4085 |
|
| 4086 |
|
| 4087 |
boolean isLayoutModeOptical() { |
| 4088 |
return mLayoutMode == LAYOUT_MODE_OPTICAL_BOUNDS; |
| 4089 |
} |
| 4090 |
|
| 4091 |
@Override |
| 4092 |
Insets computeOpticalInsets() { |
| 4093 |
if (isLayoutModeOptical()) { |
| 4094 |
int left = 0; |
| 4095 |
int top = 0; |
| 4096 |
int right = 0; |
| 4097 |
int bottom = 0; |
| 4098 |
for (int i = 0; i < mChildrenCount; i++) { |
| 4099 |
View child = getChildAt(i); |
| 4100 |
if (child.getVisibility() == VISIBLE) { |
| 4101 |
Insets insets = child.getOpticalInsets(); |
| 4102 |
left = Math.max(left, insets.left); |
| 4103 |
top = Math.max(top, insets.top); |
| 4104 |
right = Math.max(right, insets.right); |
| 4105 |
bottom = Math.max(bottom, insets.bottom); |
| 4106 |
} |
| 4107 |
} |
| 4108 |
return Insets.of(left, top, right, bottom); |
| 4109 |
} else { |
| 4110 |
return Insets.NONE; |
| 4111 |
} |
| 4112 |
} |
| 4113 |
|
| 4114 |
private static void fillRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { |
| 4115 |
if (x1 != x2 && y1 != y2) { |
| 4116 |
if (x1 > x2) { |
| 4117 |
int tmp = x1; x1 = x2; x2 = tmp; |
| 4118 |
} |
| 4119 |
if (y1 > y2) { |
| 4120 |
int tmp = y1; y1 = y2; y2 = tmp; |
| 4121 |
} |
| 4122 |
canvas.drawRect(x1, y1, x2, y2, paint); |
| 4123 |
} |
| 4124 |
} |
| 4125 |
|
| 4126 |
private static int sign(int x) { |
| 4127 |
return (x >= 0) ? 1 : -1; |
| 4128 |
} |
| 4129 |
|
| 4130 |
private static void drawCorner(Canvas c, Paint paint, int x1, int y1, int dx, int dy, int lw) { |
| 4131 |
fillRect(c, paint, x1, y1, x1 + dx, y1 + lw * sign(dy)); |
| 4132 |
fillRect(c, paint, x1, y1, x1 + lw * sign(dx), y1 + dy); |
| 4133 |
} |
| 4134 |
|
| 4135 |
private static void drawRectCorners(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint, |
| 4136 |
int lineLength, int lineWidth) { |
| 4137 |
drawCorner(canvas, paint, x1, y1, lineLength, lineLength, lineWidth); |
| 4138 |
drawCorner(canvas, paint, x1, y2, lineLength, -lineLength, lineWidth); |
| 4139 |
drawCorner(canvas, paint, x2, y1, -lineLength, lineLength, lineWidth); |
| 4140 |
drawCorner(canvas, paint, x2, y2, -lineLength, -lineLength, lineWidth); |
| 4141 |
} |
| 4142 |
|
| 4143 |
private static void fillDifference(Canvas canvas, |
| 4144 |
int x2, int y2, int x3, int y3, |
| 4145 |
int dx1, int dy1, int dx2, int dy2, Paint paint) { |
| 4146 |
int x1 = x2 - dx1; |
| 4147 |
int y1 = y2 - dy1; |
| 4148 |
|
| 4149 |
int x4 = x3 + dx2; |
| 4150 |
int y4 = y3 + dy2; |
| 4151 |
|
| 4152 |
fillRect(canvas, paint, x1, y1, x4, y2); |
| 4153 |
fillRect(canvas, paint, x1, y2, x2, y3); |
| 4154 |
fillRect(canvas, paint, x3, y2, x4, y3); |
| 4155 |
fillRect(canvas, paint, x1, y3, x4, y4); |
| 4156 |
} |
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
protected void onDebugDrawMargins(Canvas canvas, Paint paint) { |
| 4162 |
for (int i = 0; i < getChildCount(); i++) { |
| 4163 |
View c = getChildAt(i); |
| 4164 |
c.getLayoutParams().onDebugDraw(c, canvas, paint); |
| 4165 |
} |
| 4166 |
} |
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
protected void onDebugDraw(Canvas canvas) { |
| 4172 |
Paint paint = getDebugPaint(); |
| 4173 |
|
| 4174 |
|
| 4175 |
{ |
| 4176 |
paint.setColor(Color.RED); |
| 4177 |
paint.setStyle(Paint.Style.STROKE); |
| 4178 |
|
| 4179 |
for (int i = 0; i < getChildCount(); i++) { |
| 4180 |
View c = getChildAt(i); |
| 4181 |
if (c.getVisibility() != View.GONE) { |
| 4182 |
Insets insets = c.getOpticalInsets(); |
| 4183 |
|
| 4184 |
drawRect(canvas, paint, |
| 4185 |
c.getLeft() + insets.left, |
| 4186 |
c.getTop() + insets.top, |
| 4187 |
c.getRight() - insets.right - 1, |
| 4188 |
c.getBottom() - insets.bottom - 1); |
| 4189 |
} |
| 4190 |
} |
| 4191 |
} |
| 4192 |
|
| 4193 |
|
| 4194 |
{ |
| 4195 |
paint.setColor(Color.argb(63, 255, 0, 255)); |
| 4196 |
paint.setStyle(Paint.Style.FILL); |
| 4197 |
|
| 4198 |
onDebugDrawMargins(canvas, paint); |
| 4199 |
} |
| 4200 |
|
| 4201 |
|
| 4202 |
{ |
| 4203 |
paint.setColor(DEBUG_CORNERS_COLOR); |
| 4204 |
paint.setStyle(Paint.Style.FILL); |
| 4205 |
|
| 4206 |
int lineLength = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); |
| 4207 |
int lineWidth = dipsToPixels(1); |
| 4208 |
for (int i = 0; i < getChildCount(); i++) { |
| 4209 |
View c = getChildAt(i); |
| 4210 |
if (c.getVisibility() != View.GONE) { |
| 4211 |
drawRectCorners(canvas, c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), |
| 4212 |
paint, lineLength, lineWidth); |
| 4213 |
} |
| 4214 |
} |
| 4215 |
} |
| 4216 |
} |
| 4217 |
|
| 4218 |
@Override |
| 4219 |
protected void dispatchDraw(Canvas canvas) { |
| 4220 |
final int childrenCount = mChildrenCount; |
| 4221 |
final View[] children = mChildren; |
| 4222 |
int flags = mGroupFlags; |
| 4223 |
|
| 4224 |
if ((flags & FLAG_RUN_ANIMATION) != 0 && canAnimate()) { |
| 4225 |
for (int i = 0; i < childrenCount; i++) { |
| 4226 |
final View child = children[i]; |
| 4227 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 4228 |
final LayoutParams params = child.getLayoutParams(); |
| 4229 |
attachLayoutAnimationParameters(child, params, i, childrenCount); |
| 4230 |
bindLayoutAnimation(child); |
| 4231 |
} |
| 4232 |
} |
| 4233 |
|
| 4234 |
final LayoutAnimationController controller = mLayoutAnimationController; |
| 4235 |
if (controller.willOverlap()) { |
| 4236 |
mGroupFlags |= FLAG_OPTIMIZE_INVALIDATE; |
| 4237 |
} |
| 4238 |
|
| 4239 |
controller.start(); |
| 4240 |
|
| 4241 |
mGroupFlags &= ~FLAG_RUN_ANIMATION; |
| 4242 |
mGroupFlags &= ~FLAG_ANIMATION_DONE; |
| 4243 |
|
| 4244 |
if (mAnimationListener != null) { |
| 4245 |
mAnimationListener.onAnimationStart(controller.getAnimation()); |
| 4246 |
} |
| 4247 |
} |
| 4248 |
|
| 4249 |
int clipSaveCount = 0; |
| 4250 |
final boolean clipToPadding = (flags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK; |
| 4251 |
if (clipToPadding) { |
| 4252 |
clipSaveCount = canvas.save(Canvas.CLIP_SAVE_FLAG); |
| 4253 |
canvas.clipRect(mScrollX + mPaddingLeft, mScrollY + mPaddingTop, |
| 4254 |
mScrollX + mRight - mLeft - mPaddingRight, |
| 4255 |
mScrollY + mBottom - mTop - mPaddingBottom); |
| 4256 |
} |
| 4257 |
|
| 4258 |
|
| 4259 |
mPrivateFlags &= ~PFLAG_DRAW_ANIMATION; |
| 4260 |
mGroupFlags &= ~FLAG_INVALIDATE_REQUIRED; |
| 4261 |
|
| 4262 |
boolean more = false; |
| 4263 |
final long drawingTime = getDrawingTime(); |
| 4264 |
|
| 4265 |
canvas.enableZ(); |
| 4266 |
final int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 4267 |
int transientIndex = transientCount != 0 ? 0 : -1; |
| 4268 |
|
| 4269 |
|
| 4270 |
final ArrayList<View> preorderedList = drawsWithRenderNode(canvas) |
| 4271 |
? null : buildOrderedChildList(); |
| 4272 |
final boolean customOrder = preorderedList == null |
| 4273 |
&& isChildrenDrawingOrderEnabled(); |
| 4274 |
for (int i = 0; i < childrenCount; i++) { |
| 4275 |
while (transientIndex >= 0 && mTransientIndices.get(transientIndex) == i) { |
| 4276 |
final View transientChild = mTransientViews.get(transientIndex); |
| 4277 |
if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE || |
| 4278 |
transientChild.getAnimation() != null) { |
| 4279 |
more |= drawChild(canvas, transientChild, drawingTime); |
| 4280 |
} |
| 4281 |
transientIndex++; |
| 4282 |
if (transientIndex >= transientCount) { |
| 4283 |
transientIndex = -1; |
| 4284 |
} |
| 4285 |
} |
| 4286 |
|
| 4287 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 4288 |
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 4289 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) { |
| 4290 |
more |= drawChild(canvas, child, drawingTime); |
| 4291 |
} |
| 4292 |
} |
| 4293 |
while (transientIndex >= 0) { |
| 4294 |
|
| 4295 |
final View transientChild = mTransientViews.get(transientIndex); |
| 4296 |
if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE || |
| 4297 |
transientChild.getAnimation() != null) { |
| 4298 |
more |= drawChild(canvas, transientChild, drawingTime); |
| 4299 |
} |
| 4300 |
transientIndex++; |
| 4301 |
if (transientIndex >= transientCount) { |
| 4302 |
break; |
| 4303 |
} |
| 4304 |
} |
| 4305 |
if (preorderedList != null) preorderedList.clear(); |
| 4306 |
|
| 4307 |
|
| 4308 |
if (mDisappearingChildren != null) { |
| 4309 |
final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 4310 |
final int disappearingCount = disappearingChildren.size() - 1; |
| 4311 |
|
| 4312 |
for (int i = disappearingCount; i >= 0; i--) { |
| 4313 |
final View child = disappearingChildren.get(i); |
| 4314 |
more |= drawChild(canvas, child, drawingTime); |
| 4315 |
} |
| 4316 |
} |
| 4317 |
canvas.disableZ(); |
| 4318 |
|
| 4319 |
if (isShowingLayoutBounds()) { |
| 4320 |
onDebugDraw(canvas); |
| 4321 |
} |
| 4322 |
|
| 4323 |
if (clipToPadding) { |
| 4324 |
canvas.restoreToCount(clipSaveCount); |
| 4325 |
} |
| 4326 |
|
| 4327 |
|
| 4328 |
flags = mGroupFlags; |
| 4329 |
|
| 4330 |
if ((flags & FLAG_INVALIDATE_REQUIRED) == FLAG_INVALIDATE_REQUIRED) { |
| 4331 |
invalidate(true); |
| 4332 |
} |
| 4333 |
|
| 4334 |
if ((flags & FLAG_ANIMATION_DONE) == 0 && (flags & FLAG_NOTIFY_ANIMATION_LISTENER) == 0 && |
| 4335 |
mLayoutAnimationController.isDone() && !more) { |
| 4336 |
|
| 4337 |
|
| 4338 |
|
| 4339 |
mGroupFlags |= FLAG_NOTIFY_ANIMATION_LISTENER; |
| 4340 |
final Runnable end = new Runnable() { |
| 4341 |
@Override |
| 4342 |
public void run() { |
| 4343 |
notifyAnimationListener(); |
| 4344 |
} |
| 4345 |
}; |
| 4346 |
post(end); |
| 4347 |
} |
| 4348 |
} |
| 4349 |
|
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
@Override |
| 4367 |
public ViewGroupOverlay getOverlay() { |
| 4368 |
if (mOverlay == null) { |
| 4369 |
mOverlay = new ViewGroupOverlay(mContext, this); |
| 4370 |
} |
| 4371 |
return (ViewGroupOverlay) mOverlay; |
| 4372 |
} |
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
protected int getChildDrawingOrder(int childCount, int drawingPosition) { |
| 4389 |
return drawingPosition; |
| 4390 |
} |
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
|
| 4405 |
public final int getChildDrawingOrder(int drawingPosition) { |
| 4406 |
return getChildDrawingOrder(getChildCount(), drawingPosition); |
| 4407 |
} |
| 4408 |
|
| 4409 |
private boolean hasChildWithZ() { |
| 4410 |
for (int i = 0; i < mChildrenCount; i++) { |
| 4411 |
if (mChildren[i].getZ() != 0) return true; |
| 4412 |
} |
| 4413 |
return false; |
| 4414 |
} |
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
ArrayList<View> buildOrderedChildList() { |
| 4425 |
final int childrenCount = mChildrenCount; |
| 4426 |
if (childrenCount <= 1 || !hasChildWithZ()) return null; |
| 4427 |
|
| 4428 |
if (mPreSortedChildren == null) { |
| 4429 |
mPreSortedChildren = new ArrayList<>(childrenCount); |
| 4430 |
} else { |
| 4431 |
|
| 4432 |
mPreSortedChildren.clear(); |
| 4433 |
mPreSortedChildren.ensureCapacity(childrenCount); |
| 4434 |
} |
| 4435 |
|
| 4436 |
final boolean customOrder = isChildrenDrawingOrderEnabled(); |
| 4437 |
for (int i = 0; i < childrenCount; i++) { |
| 4438 |
|
| 4439 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 4440 |
final View nextChild = mChildren[childIndex]; |
| 4441 |
final float currentZ = nextChild.getZ(); |
| 4442 |
|
| 4443 |
|
| 4444 |
int insertIndex = i; |
| 4445 |
while (insertIndex > 0 && mPreSortedChildren.get(insertIndex - 1).getZ() > currentZ) { |
| 4446 |
insertIndex--; |
| 4447 |
} |
| 4448 |
mPreSortedChildren.add(insertIndex, nextChild); |
| 4449 |
} |
| 4450 |
return mPreSortedChildren; |
| 4451 |
} |
| 4452 |
|
| 4453 |
private void notifyAnimationListener() { |
| 4454 |
mGroupFlags &= ~FLAG_NOTIFY_ANIMATION_LISTENER; |
| 4455 |
mGroupFlags |= FLAG_ANIMATION_DONE; |
| 4456 |
|
| 4457 |
if (mAnimationListener != null) { |
| 4458 |
final Runnable end = new Runnable() { |
| 4459 |
@Override |
| 4460 |
public void run() { |
| 4461 |
mAnimationListener.onAnimationEnd(mLayoutAnimationController.getAnimation()); |
| 4462 |
} |
| 4463 |
}; |
| 4464 |
post(end); |
| 4465 |
} |
| 4466 |
|
| 4467 |
invalidate(true); |
| 4468 |
} |
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
@Override |
| 4479 |
@UnsupportedAppUsage |
| 4480 |
protected void dispatchGetDisplayList() { |
| 4481 |
final int count = mChildrenCount; |
| 4482 |
final View[] children = mChildren; |
| 4483 |
for (int i = 0; i < count; i++) { |
| 4484 |
final View child = children[i]; |
| 4485 |
if (((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null)) { |
| 4486 |
recreateChildDisplayList(child); |
| 4487 |
} |
| 4488 |
} |
| 4489 |
final int transientCount = mTransientViews == null ? 0 : mTransientIndices.size(); |
| 4490 |
for (int i = 0; i < transientCount; ++i) { |
| 4491 |
View child = mTransientViews.get(i); |
| 4492 |
if (((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null)) { |
| 4493 |
recreateChildDisplayList(child); |
| 4494 |
} |
| 4495 |
} |
| 4496 |
if (mOverlay != null) { |
| 4497 |
View overlayView = mOverlay.getOverlayView(); |
| 4498 |
recreateChildDisplayList(overlayView); |
| 4499 |
} |
| 4500 |
if (mDisappearingChildren != null) { |
| 4501 |
final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 4502 |
final int disappearingCount = disappearingChildren.size(); |
| 4503 |
for (int i = 0; i < disappearingCount; ++i) { |
| 4504 |
final View child = disappearingChildren.get(i); |
| 4505 |
recreateChildDisplayList(child); |
| 4506 |
} |
| 4507 |
} |
| 4508 |
} |
| 4509 |
|
| 4510 |
private void recreateChildDisplayList(View child) { |
| 4511 |
child.mRecreateDisplayList = (child.mPrivateFlags & PFLAG_INVALIDATED) != 0; |
| 4512 |
child.mPrivateFlags &= ~PFLAG_INVALIDATED; |
| 4513 |
child.updateDisplayListIfDirty(); |
| 4514 |
child.mRecreateDisplayList = false; |
| 4515 |
} |
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
| 4529 |
return child.draw(canvas, this, drawingTime); |
| 4530 |
} |
| 4531 |
|
| 4532 |
@Override |
| 4533 |
void getScrollIndicatorBounds(@NonNull Rect out) { |
| 4534 |
super.getScrollIndicatorBounds(out); |
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
final boolean clipToPadding = (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK; |
| 4539 |
if (clipToPadding) { |
| 4540 |
out.left += mPaddingLeft; |
| 4541 |
out.right -= mPaddingRight; |
| 4542 |
out.top += mPaddingTop; |
| 4543 |
out.bottom -= mPaddingBottom; |
| 4544 |
} |
| 4545 |
} |
| 4546 |
|
| 4547 |
|
| 4548 |
|
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
@ViewDebug.ExportedProperty(category = "drawing") |
| 4556 |
@InspectableProperty |
| 4557 |
public boolean getClipChildren() { |
| 4558 |
return ((mGroupFlags & FLAG_CLIP_CHILDREN) != 0); |
| 4559 |
} |
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
|
| 4567 |
|
| 4568 |
|
| 4569 |
public void setClipChildren(boolean clipChildren) { |
| 4570 |
boolean previousValue = (mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN; |
| 4571 |
if (clipChildren != previousValue) { |
| 4572 |
setBooleanFlag(FLAG_CLIP_CHILDREN, clipChildren); |
| 4573 |
for (int i = 0; i < mChildrenCount; ++i) { |
| 4574 |
View child = getChildAt(i); |
| 4575 |
if (child.mRenderNode != null) { |
| 4576 |
child.mRenderNode.setClipToBounds(clipChildren); |
| 4577 |
} |
| 4578 |
} |
| 4579 |
invalidate(true); |
| 4580 |
} |
| 4581 |
} |
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
public void setClipToPadding(boolean clipToPadding) { |
| 4595 |
if (hasBooleanFlag(FLAG_CLIP_TO_PADDING) != clipToPadding) { |
| 4596 |
setBooleanFlag(FLAG_CLIP_TO_PADDING, clipToPadding); |
| 4597 |
invalidate(true); |
| 4598 |
} |
| 4599 |
} |
| 4600 |
|
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
@ViewDebug.ExportedProperty(category = "drawing") |
| 4614 |
@InspectableProperty |
| 4615 |
public boolean getClipToPadding() { |
| 4616 |
return hasBooleanFlag(FLAG_CLIP_TO_PADDING); |
| 4617 |
} |
| 4618 |
|
| 4619 |
@Override |
| 4620 |
public void dispatchSetSelected(boolean selected) { |
| 4621 |
final View[] children = mChildren; |
| 4622 |
final int count = mChildrenCount; |
| 4623 |
for (int i = 0; i < count; i++) { |
| 4624 |
children[i].setSelected(selected); |
| 4625 |
} |
| 4626 |
} |
| 4627 |
|
| 4628 |
@Override |
| 4629 |
public void dispatchSetActivated(boolean activated) { |
| 4630 |
final View[] children = mChildren; |
| 4631 |
final int count = mChildrenCount; |
| 4632 |
for (int i = 0; i < count; i++) { |
| 4633 |
children[i].setActivated(activated); |
| 4634 |
} |
| 4635 |
} |
| 4636 |
|
| 4637 |
@Override |
| 4638 |
protected void dispatchSetPressed(boolean pressed) { |
| 4639 |
final View[] children = mChildren; |
| 4640 |
final int count = mChildrenCount; |
| 4641 |
for (int i = 0; i < count; i++) { |
| 4642 |
final View child = children[i]; |
| 4643 |
|
| 4644 |
|
| 4645 |
|
| 4646 |
if (!pressed || (!child.isClickable() && !child.isLongClickable())) { |
| 4647 |
child.setPressed(pressed); |
| 4648 |
} |
| 4649 |
} |
| 4650 |
} |
| 4651 |
|
| 4652 |
|
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
|
| 4665 |
|
| 4666 |
@Override |
| 4667 |
public void dispatchDrawableHotspotChanged(float x, float y) { |
| 4668 |
final int count = mChildrenCount; |
| 4669 |
if (count == 0) { |
| 4670 |
return; |
| 4671 |
} |
| 4672 |
|
| 4673 |
final View[] children = mChildren; |
| 4674 |
for (int i = 0; i < count; i++) { |
| 4675 |
final View child = children[i]; |
| 4676 |
|
| 4677 |
|
| 4678 |
final boolean nonActionable = !child.isClickable() && !child.isLongClickable(); |
| 4679 |
final boolean duplicatesState = (child.mViewFlags & DUPLICATE_PARENT_STATE) != 0; |
| 4680 |
if (nonActionable || duplicatesState) { |
| 4681 |
final float[] point = getTempLocationF(); |
| 4682 |
point[0] = x; |
| 4683 |
point[1] = y; |
| 4684 |
transformPointToViewLocal(point, child); |
| 4685 |
child.drawableHotspotChanged(point[0], point[1]); |
| 4686 |
} |
| 4687 |
} |
| 4688 |
} |
| 4689 |
|
| 4690 |
@Override |
| 4691 |
void dispatchCancelPendingInputEvents() { |
| 4692 |
super.dispatchCancelPendingInputEvents(); |
| 4693 |
|
| 4694 |
final View[] children = mChildren; |
| 4695 |
final int count = mChildrenCount; |
| 4696 |
for (int i = 0; i < count; i++) { |
| 4697 |
children[i].dispatchCancelPendingInputEvents(); |
| 4698 |
} |
| 4699 |
} |
| 4700 |
|
| 4701 |
|
| 4702 |
|
| 4703 |
|
| 4704 |
|
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
protected void setStaticTransformationsEnabled(boolean enabled) { |
| 4716 |
setBooleanFlag(FLAG_SUPPORT_STATIC_TRANSFORMATIONS, enabled); |
| 4717 |
} |
| 4718 |
|
| 4719 |
|
| 4720 |
|
| 4721 |
|
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
protected boolean getChildStaticTransformation(View child, Transformation t) { |
| 4732 |
return false; |
| 4733 |
} |
| 4734 |
|
| 4735 |
Transformation getChildTransformation() { |
| 4736 |
if (mChildTransformation == null) { |
| 4737 |
mChildTransformation = new Transformation(); |
| 4738 |
} |
| 4739 |
return mChildTransformation; |
| 4740 |
} |
| 4741 |
|
| 4742 |
|
| 4743 |
|
| 4744 |
|
| 4745 |
@Override |
| 4746 |
protected <T extends View> T findViewTraversal(@IdRes int id) { |
| 4747 |
if (id == mID) { |
| 4748 |
return (T) this; |
| 4749 |
} |
| 4750 |
|
| 4751 |
final View[] where = mChildren; |
| 4752 |
final int len = mChildrenCount; |
| 4753 |
|
| 4754 |
for (int i = 0; i < len; i++) { |
| 4755 |
View v = where[i]; |
| 4756 |
|
| 4757 |
if ((v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
| 4758 |
v = v.findViewById(id); |
| 4759 |
|
| 4760 |
if (v != null) { |
| 4761 |
return (T) v; |
| 4762 |
} |
| 4763 |
} |
| 4764 |
} |
| 4765 |
|
| 4766 |
return null; |
| 4767 |
} |
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
@Override |
| 4773 |
protected <T extends View> T findViewWithTagTraversal(Object tag) { |
| 4774 |
if (tag != null && tag.equals(mTag)) { |
| 4775 |
return (T) this; |
| 4776 |
} |
| 4777 |
|
| 4778 |
final View[] where = mChildren; |
| 4779 |
final int len = mChildrenCount; |
| 4780 |
|
| 4781 |
for (int i = 0; i < len; i++) { |
| 4782 |
View v = where[i]; |
| 4783 |
|
| 4784 |
if ((v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
| 4785 |
v = v.findViewWithTag(tag); |
| 4786 |
|
| 4787 |
if (v != null) { |
| 4788 |
return (T) v; |
| 4789 |
} |
| 4790 |
} |
| 4791 |
} |
| 4792 |
|
| 4793 |
return null; |
| 4794 |
} |
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
|
| 4799 |
@Override |
| 4800 |
protected <T extends View> T findViewByPredicateTraversal(Predicate<View> predicate, |
| 4801 |
View childToSkip) { |
| 4802 |
if (predicate.test(this)) { |
| 4803 |
return (T) this; |
| 4804 |
} |
| 4805 |
|
| 4806 |
final View[] where = mChildren; |
| 4807 |
final int len = mChildrenCount; |
| 4808 |
|
| 4809 |
for (int i = 0; i < len; i++) { |
| 4810 |
View v = where[i]; |
| 4811 |
|
| 4812 |
if (v != childToSkip && (v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
| 4813 |
v = v.findViewByPredicate(predicate); |
| 4814 |
|
| 4815 |
if (v != null) { |
| 4816 |
return (T) v; |
| 4817 |
} |
| 4818 |
} |
| 4819 |
} |
| 4820 |
|
| 4821 |
return null; |
| 4822 |
} |
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
|
| 4830 |
|
| 4831 |
|
| 4832 |
|
| 4833 |
|
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
|
| 4842 |
|
| 4843 |
|
| 4844 |
|
| 4845 |
|
| 4846 |
|
| 4847 |
|
| 4848 |
|
| 4849 |
|
| 4850 |
|
| 4851 |
|
| 4852 |
|
| 4853 |
|
| 4854 |
|
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
@UnsupportedAppUsage |
| 4862 |
public void addTransientView(View view, int index) { |
| 4863 |
if (index < 0 || view == null) { |
| 4864 |
return; |
| 4865 |
} |
| 4866 |
if (view.mParent != null) { |
| 4867 |
throw new IllegalStateException("The specified view already has a parent " |
| 4868 |
+ view.mParent); |
| 4869 |
} |
| 4870 |
|
| 4871 |
if (mTransientIndices == null) { |
| 4872 |
mTransientIndices = new IntArray(); |
| 4873 |
mTransientViews = new ArrayList<View>(); |
| 4874 |
} |
| 4875 |
final int oldSize = mTransientIndices.size(); |
| 4876 |
if (oldSize > 0) { |
| 4877 |
int insertionIndex; |
| 4878 |
for (insertionIndex = 0; insertionIndex < oldSize; ++insertionIndex) { |
| 4879 |
if (index < mTransientIndices.get(insertionIndex)) { |
| 4880 |
break; |
| 4881 |
} |
| 4882 |
} |
| 4883 |
mTransientIndices.add(insertionIndex, index); |
| 4884 |
mTransientViews.add(insertionIndex, view); |
| 4885 |
} else { |
| 4886 |
mTransientIndices.add(index); |
| 4887 |
mTransientViews.add(view); |
| 4888 |
} |
| 4889 |
view.mParent = this; |
| 4890 |
if (mAttachInfo != null) { |
| 4891 |
view.dispatchAttachedToWindow(mAttachInfo, (mViewFlags & VISIBILITY_MASK)); |
| 4892 |
} |
| 4893 |
invalidate(true); |
| 4894 |
} |
| 4895 |
|
| 4896 |
|
| 4897 |
|
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
|
| 4903 |
|
| 4904 |
@UnsupportedAppUsage |
| 4905 |
public void removeTransientView(View view) { |
| 4906 |
if (mTransientViews == null) { |
| 4907 |
return; |
| 4908 |
} |
| 4909 |
final int size = mTransientViews.size(); |
| 4910 |
for (int i = 0; i < size; ++i) { |
| 4911 |
if (view == mTransientViews.get(i)) { |
| 4912 |
mTransientViews.remove(i); |
| 4913 |
mTransientIndices.remove(i); |
| 4914 |
view.mParent = null; |
| 4915 |
if (view.mAttachInfo != null) { |
| 4916 |
view.dispatchDetachedFromWindow(); |
| 4917 |
} |
| 4918 |
invalidate(true); |
| 4919 |
return; |
| 4920 |
} |
| 4921 |
} |
| 4922 |
} |
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
|
| 4928 |
|
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
@UnsupportedAppUsage |
| 4935 |
public int getTransientViewCount() { |
| 4936 |
return mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 4937 |
} |
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
public int getTransientViewIndex(int position) { |
| 4951 |
if (position < 0 || mTransientIndices == null || position >= mTransientIndices.size()) { |
| 4952 |
return -1; |
| 4953 |
} |
| 4954 |
return mTransientIndices.get(position); |
| 4955 |
} |
| 4956 |
|
| 4957 |
|
| 4958 |
|
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
|
| 4965 |
|
| 4966 |
|
| 4967 |
|
| 4968 |
@UnsupportedAppUsage |
| 4969 |
public View getTransientView(int position) { |
| 4970 |
if (mTransientViews == null || position >= mTransientViews.size()) { |
| 4971 |
return null; |
| 4972 |
} |
| 4973 |
return mTransientViews.get(position); |
| 4974 |
} |
| 4975 |
|
| 4976 |
|
| 4977 |
|
| 4978 |
|
| 4979 |
|
| 4980 |
|
| 4981 |
|
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
public void addView(View child) { |
| 4989 |
addView(child, -1); |
| 4990 |
} |
| 4991 |
|
| 4992 |
|
| 4993 |
|
| 4994 |
|
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
|
| 4999 |
|
| 5000 |
|
| 5001 |
|
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
public void addView(View child, int index) { |
| 5006 |
if (child == null) { |
| 5007 |
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 5008 |
} |
| 5009 |
LayoutParams params = child.getLayoutParams(); |
| 5010 |
if (params == null) { |
| 5011 |
params = generateDefaultLayoutParams(); |
| 5012 |
if (params == null) { |
| 5013 |
throw new IllegalArgumentException( |
| 5014 |
"generateDefaultLayoutParams() cannot return null "); |
| 5015 |
} |
| 5016 |
} |
| 5017 |
addView(child, index, params); |
| 5018 |
} |
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
|
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
public void addView(View child, int width, int height) { |
| 5031 |
final LayoutParams params = generateDefaultLayoutParams(); |
| 5032 |
params.width = width; |
| 5033 |
params.height = height; |
| 5034 |
addView(child, -1, params); |
| 5035 |
} |
| 5036 |
|
| 5037 |
|
| 5038 |
|
| 5039 |
|
| 5040 |
|
| 5041 |
|
| 5042 |
|
| 5043 |
|
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
@Override |
| 5048 |
public void addView(View child, LayoutParams params) { |
| 5049 |
addView(child, -1, params); |
| 5050 |
} |
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
|
| 5061 |
|
| 5062 |
|
| 5063 |
public void addView(View child, int index, LayoutParams params) { |
| 5064 |
if (DBG) { |
| 5065 |
System.out.println(this + " addView"); |
| 5066 |
} |
| 5067 |
|
| 5068 |
if (child == null) { |
| 5069 |
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 5070 |
} |
| 5071 |
|
| 5072 |
|
| 5073 |
|
| 5074 |
|
| 5075 |
requestLayout(); |
| 5076 |
invalidate(true); |
| 5077 |
addViewInner(child, index, params, false); |
| 5078 |
} |
| 5079 |
|
| 5080 |
@Override |
| 5081 |
public void updateViewLayout(View view, ViewGroup.LayoutParams params) { |
| 5082 |
if (!checkLayoutParams(params)) { |
| 5083 |
throw new IllegalArgumentException("Invalid LayoutParams supplied to " + this); |
| 5084 |
} |
| 5085 |
if (view.mParent != this) { |
| 5086 |
throw new IllegalArgumentException("Given view not a child of " + this); |
| 5087 |
} |
| 5088 |
view.setLayoutParams(params); |
| 5089 |
} |
| 5090 |
|
| 5091 |
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { |
| 5092 |
return p != null; |
| 5093 |
} |
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
public interface OnHierarchyChangeListener { |
| 5101 |
|
| 5102 |
|
| 5103 |
|
| 5104 |
|
| 5105 |
|
| 5106 |
|
| 5107 |
void onChildViewAdded(View parent, View child); |
| 5108 |
|
| 5109 |
|
| 5110 |
|
| 5111 |
|
| 5112 |
|
| 5113 |
|
| 5114 |
|
| 5115 |
void onChildViewRemoved(View parent, View child); |
| 5116 |
} |
| 5117 |
|
| 5118 |
|
| 5119 |
|
| 5120 |
|
| 5121 |
|
| 5122 |
|
| 5123 |
|
| 5124 |
public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener) { |
| 5125 |
mOnHierarchyChangeListener = listener; |
| 5126 |
} |
| 5127 |
|
| 5128 |
@UnsupportedAppUsage |
| 5129 |
void dispatchViewAdded(View child) { |
| 5130 |
onViewAdded(child); |
| 5131 |
if (mOnHierarchyChangeListener != null) { |
| 5132 |
mOnHierarchyChangeListener.onChildViewAdded(this, child); |
| 5133 |
} |
| 5134 |
} |
| 5135 |
|
| 5136 |
|
| 5137 |
|
| 5138 |
|
| 5139 |
|
| 5140 |
|
| 5141 |
|
| 5142 |
public void onViewAdded(View child) { |
| 5143 |
} |
| 5144 |
|
| 5145 |
@UnsupportedAppUsage |
| 5146 |
void dispatchViewRemoved(View child) { |
| 5147 |
onViewRemoved(child); |
| 5148 |
if (mOnHierarchyChangeListener != null) { |
| 5149 |
mOnHierarchyChangeListener.onChildViewRemoved(this, child); |
| 5150 |
} |
| 5151 |
} |
| 5152 |
|
| 5153 |
|
| 5154 |
|
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
public void onViewRemoved(View child) { |
| 5160 |
} |
| 5161 |
|
| 5162 |
private void clearCachedLayoutMode() { |
| 5163 |
if (!hasBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET)) { |
| 5164 |
mLayoutMode = LAYOUT_MODE_UNDEFINED; |
| 5165 |
} |
| 5166 |
} |
| 5167 |
|
| 5168 |
@Override |
| 5169 |
protected void onAttachedToWindow() { |
| 5170 |
super.onAttachedToWindow(); |
| 5171 |
clearCachedLayoutMode(); |
| 5172 |
} |
| 5173 |
|
| 5174 |
@Override |
| 5175 |
protected void onDetachedFromWindow() { |
| 5176 |
super.onDetachedFromWindow(); |
| 5177 |
clearCachedLayoutMode(); |
| 5178 |
} |
| 5179 |
|
| 5180 |
|
| 5181 |
@Override |
| 5182 |
protected void destroyHardwareResources() { |
| 5183 |
super.destroyHardwareResources(); |
| 5184 |
int count = getChildCount(); |
| 5185 |
for (int i = 0; i < count; i++) { |
| 5186 |
getChildAt(i).destroyHardwareResources(); |
| 5187 |
} |
| 5188 |
} |
| 5189 |
|
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
|
| 5195 |
|
| 5196 |
|
| 5197 |
|
| 5198 |
|
| 5199 |
|
| 5200 |
|
| 5201 |
protected boolean addViewInLayout(View child, int index, LayoutParams params) { |
| 5202 |
return addViewInLayout(child, index, params, false); |
| 5203 |
} |
| 5204 |
|
| 5205 |
|
| 5206 |
|
| 5207 |
|
| 5208 |
|
| 5209 |
|
| 5210 |
|
| 5211 |
|
| 5212 |
|
| 5213 |
|
| 5214 |
|
| 5215 |
|
| 5216 |
|
| 5217 |
|
| 5218 |
protected boolean addViewInLayout(View child, int index, LayoutParams params, |
| 5219 |
boolean preventRequestLayout) { |
| 5220 |
if (child == null) { |
| 5221 |
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 5222 |
} |
| 5223 |
child.mParent = null; |
| 5224 |
addViewInner(child, index, params, preventRequestLayout); |
| 5225 |
child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
| 5226 |
return true; |
| 5227 |
} |
| 5228 |
|
| 5229 |
|
| 5230 |
|
| 5231 |
|
| 5232 |
|
| 5233 |
|
| 5234 |
protected void cleanupLayoutState(View child) { |
| 5235 |
child.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 5236 |
} |
| 5237 |
|
| 5238 |
private void addViewInner(View child, int index, LayoutParams params, |
| 5239 |
boolean preventRequestLayout) { |
| 5240 |
|
| 5241 |
if (mTransition != null) { |
| 5242 |
|
| 5243 |
|
| 5244 |
mTransition.cancel(LayoutTransition.DISAPPEARING); |
| 5245 |
} |
| 5246 |
|
| 5247 |
if (child.getParent() != null) { |
| 5248 |
throw new IllegalStateException("The specified child already has a parent. " + |
| 5249 |
"You must call removeView() on the child's parent first."); |
| 5250 |
} |
| 5251 |
|
| 5252 |
if (mTransition != null) { |
| 5253 |
mTransition.addChild(this, child); |
| 5254 |
} |
| 5255 |
|
| 5256 |
if (!checkLayoutParams(params)) { |
| 5257 |
params = generateLayoutParams(params); |
| 5258 |
} |
| 5259 |
|
| 5260 |
if (preventRequestLayout) { |
| 5261 |
child.mLayoutParams = params; |
| 5262 |
} else { |
| 5263 |
child.setLayoutParams(params); |
| 5264 |
} |
| 5265 |
|
| 5266 |
if (index < 0) { |
| 5267 |
index = mChildrenCount; |
| 5268 |
} |
| 5269 |
|
| 5270 |
addInArray(child, index); |
| 5271 |
|
| 5272 |
|
| 5273 |
if (preventRequestLayout) { |
| 5274 |
child.assignParent(this); |
| 5275 |
} else { |
| 5276 |
child.mParent = this; |
| 5277 |
} |
| 5278 |
if (child.hasUnhandledKeyListener()) { |
| 5279 |
incrementChildUnhandledKeyListeners(); |
| 5280 |
} |
| 5281 |
|
| 5282 |
final boolean childHasFocus = child.hasFocus(); |
| 5283 |
if (childHasFocus) { |
| 5284 |
requestChildFocus(child, child.findFocus()); |
| 5285 |
} |
| 5286 |
|
| 5287 |
AttachInfo ai = mAttachInfo; |
| 5288 |
if (ai != null && (mGroupFlags & FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW) == 0) { |
| 5289 |
boolean lastKeepOn = ai.mKeepScreenOn; |
| 5290 |
ai.mKeepScreenOn = false; |
| 5291 |
child.dispatchAttachedToWindow(mAttachInfo, (mViewFlags&VISIBILITY_MASK)); |
| 5292 |
if (ai.mKeepScreenOn) { |
| 5293 |
needGlobalAttributesUpdate(true); |
| 5294 |
} |
| 5295 |
ai.mKeepScreenOn = lastKeepOn; |
| 5296 |
} |
| 5297 |
|
| 5298 |
if (child.isLayoutDirectionInherited()) { |
| 5299 |
child.resetRtlProperties(); |
| 5300 |
} |
| 5301 |
|
| 5302 |
dispatchViewAdded(child); |
| 5303 |
|
| 5304 |
if ((child.mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE) { |
| 5305 |
mGroupFlags |= FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE; |
| 5306 |
} |
| 5307 |
|
| 5308 |
if (child.hasTransientState()) { |
| 5309 |
childHasTransientStateChanged(child, true); |
| 5310 |
} |
| 5311 |
|
| 5312 |
if (child.getVisibility() != View.GONE) { |
| 5313 |
notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 5314 |
} |
| 5315 |
|
| 5316 |
if (mTransientIndices != null) { |
| 5317 |
final int transientCount = mTransientIndices.size(); |
| 5318 |
for (int i = 0; i < transientCount; ++i) { |
| 5319 |
final int oldIndex = mTransientIndices.get(i); |
| 5320 |
if (index <= oldIndex) { |
| 5321 |
mTransientIndices.set(i, oldIndex + 1); |
| 5322 |
} |
| 5323 |
} |
| 5324 |
} |
| 5325 |
|
| 5326 |
if (mCurrentDragStartEvent != null && child.getVisibility() == VISIBLE) { |
| 5327 |
notifyChildOfDragStart(child); |
| 5328 |
} |
| 5329 |
|
| 5330 |
if (child.hasDefaultFocus()) { |
| 5331 |
|
| 5332 |
|
| 5333 |
setDefaultFocus(child); |
| 5334 |
} |
| 5335 |
|
| 5336 |
touchAccessibilityNodeProviderIfNeeded(child); |
| 5337 |
} |
| 5338 |
|
| 5339 |
|
| 5340 |
|
| 5341 |
|
| 5342 |
|
| 5343 |
|
| 5344 |
|
| 5345 |
private void touchAccessibilityNodeProviderIfNeeded(View child) { |
| 5346 |
if (mContext.isAutofillCompatibilityEnabled()) { |
| 5347 |
child.getAccessibilityNodeProvider(); |
| 5348 |
} |
| 5349 |
} |
| 5350 |
|
| 5351 |
private void addInArray(View child, int index) { |
| 5352 |
View[] children = mChildren; |
| 5353 |
final int count = mChildrenCount; |
| 5354 |
final int size = children.length; |
| 5355 |
if (index == count) { |
| 5356 |
if (size == count) { |
| 5357 |
mChildren = new View[size + ARRAY_CAPACITY_INCREMENT]; |
| 5358 |
System.arraycopy(children, 0, mChildren, 0, size); |
| 5359 |
children = mChildren; |
| 5360 |
} |
| 5361 |
children[mChildrenCount++] = child; |
| 5362 |
} else if (index < count) { |
| 5363 |
if (size == count) { |
| 5364 |
mChildren = new View[size + ARRAY_CAPACITY_INCREMENT]; |
| 5365 |
System.arraycopy(children, 0, mChildren, 0, index); |
| 5366 |
System.arraycopy(children, index, mChildren, index + 1, count - index); |
| 5367 |
children = mChildren; |
| 5368 |
} else { |
| 5369 |
System.arraycopy(children, index, children, index + 1, count - index); |
| 5370 |
} |
| 5371 |
children[index] = child; |
| 5372 |
mChildrenCount++; |
| 5373 |
if (mLastTouchDownIndex >= index) { |
| 5374 |
mLastTouchDownIndex++; |
| 5375 |
} |
| 5376 |
} else { |
| 5377 |
throw new IndexOutOfBoundsException("index=" + index + " count=" + count); |
| 5378 |
} |
| 5379 |
} |
| 5380 |
|
| 5381 |
|
| 5382 |
private void removeFromArray(int index) { |
| 5383 |
final View[] children = mChildren; |
| 5384 |
if (!(mTransitioningViews != null && mTransitioningViews.contains(children[index]))) { |
| 5385 |
children[index].mParent = null; |
| 5386 |
} |
| 5387 |
final int count = mChildrenCount; |
| 5388 |
if (index == count - 1) { |
| 5389 |
children[--mChildrenCount] = null; |
| 5390 |
} else if (index >= 0 && index < count) { |
| 5391 |
System.arraycopy(children, index + 1, children, index, count - index - 1); |
| 5392 |
children[--mChildrenCount] = null; |
| 5393 |
} else { |
| 5394 |
throw new IndexOutOfBoundsException(); |
| 5395 |
} |
| 5396 |
if (mLastTouchDownIndex == index) { |
| 5397 |
mLastTouchDownTime = 0; |
| 5398 |
mLastTouchDownIndex = -1; |
| 5399 |
} else if (mLastTouchDownIndex > index) { |
| 5400 |
mLastTouchDownIndex--; |
| 5401 |
} |
| 5402 |
} |
| 5403 |
|
| 5404 |
|
| 5405 |
private void removeFromArray(int start, int count) { |
| 5406 |
final View[] children = mChildren; |
| 5407 |
final int childrenCount = mChildrenCount; |
| 5408 |
|
| 5409 |
start = Math.max(0, start); |
| 5410 |
final int end = Math.min(childrenCount, start + count); |
| 5411 |
|
| 5412 |
if (start == end) { |
| 5413 |
return; |
| 5414 |
} |
| 5415 |
|
| 5416 |
if (end == childrenCount) { |
| 5417 |
for (int i = start; i < end; i++) { |
| 5418 |
children[i].mParent = null; |
| 5419 |
children[i] = null; |
| 5420 |
} |
| 5421 |
} else { |
| 5422 |
for (int i = start; i < end; i++) { |
| 5423 |
children[i].mParent = null; |
| 5424 |
} |
| 5425 |
|
| 5426 |
|
| 5427 |
|
| 5428 |
System.arraycopy(children, end, children, start, childrenCount - end); |
| 5429 |
|
| 5430 |
for (int i = childrenCount - (end - start); i < childrenCount; i++) { |
| 5431 |
children[i] = null; |
| 5432 |
} |
| 5433 |
} |
| 5434 |
|
| 5435 |
mChildrenCount -= (end - start); |
| 5436 |
} |
| 5437 |
|
| 5438 |
private void bindLayoutAnimation(View child) { |
| 5439 |
Animation a = mLayoutAnimationController.getAnimationForView(child); |
| 5440 |
child.setAnimation(a); |
| 5441 |
} |
| 5442 |
|
| 5443 |
|
| 5444 |
|
| 5445 |
|
| 5446 |
|
| 5447 |
|
| 5448 |
|
| 5449 |
|
| 5450 |
|
| 5451 |
|
| 5452 |
|
| 5453 |
protected void attachLayoutAnimationParameters(View child, |
| 5454 |
LayoutParams params, int index, int count) { |
| 5455 |
LayoutAnimationController.AnimationParameters animationParams = |
| 5456 |
params.layoutAnimationParameters; |
| 5457 |
if (animationParams == null) { |
| 5458 |
animationParams = new LayoutAnimationController.AnimationParameters(); |
| 5459 |
params.layoutAnimationParameters = animationParams; |
| 5460 |
} |
| 5461 |
|
| 5462 |
animationParams.count = count; |
| 5463 |
animationParams.index = index; |
| 5464 |
} |
| 5465 |
|
| 5466 |
|
| 5467 |
|
| 5468 |
|
| 5469 |
|
| 5470 |
|
| 5471 |
|
| 5472 |
|
| 5473 |
@Override |
| 5474 |
public void removeView(View view) { |
| 5475 |
if (removeViewInternal(view)) { |
| 5476 |
requestLayout(); |
| 5477 |
invalidate(true); |
| 5478 |
} |
| 5479 |
} |
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
|
| 5485 |
|
| 5486 |
|
| 5487 |
|
| 5488 |
|
| 5489 |
|
| 5490 |
|
| 5491 |
public void removeViewInLayout(View view) { |
| 5492 |
removeViewInternal(view); |
| 5493 |
} |
| 5494 |
|
| 5495 |
|
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
|
| 5500 |
|
| 5501 |
|
| 5502 |
|
| 5503 |
|
| 5504 |
|
| 5505 |
|
| 5506 |
public void removeViewsInLayout(int start, int count) { |
| 5507 |
removeViewsInternal(start, count); |
| 5508 |
} |
| 5509 |
|
| 5510 |
|
| 5511 |
|
| 5512 |
|
| 5513 |
|
| 5514 |
|
| 5515 |
|
| 5516 |
|
| 5517 |
|
| 5518 |
|
| 5519 |
public void removeViewAt(int index) { |
| 5520 |
removeViewInternal(index, getChildAt(index)); |
| 5521 |
requestLayout(); |
| 5522 |
invalidate(true); |
| 5523 |
} |
| 5524 |
|
| 5525 |
|
| 5526 |
|
| 5527 |
|
| 5528 |
|
| 5529 |
|
| 5530 |
|
| 5531 |
|
| 5532 |
|
| 5533 |
|
| 5534 |
|
| 5535 |
public void removeViews(int start, int count) { |
| 5536 |
removeViewsInternal(start, count); |
| 5537 |
requestLayout(); |
| 5538 |
invalidate(true); |
| 5539 |
} |
| 5540 |
|
| 5541 |
private boolean removeViewInternal(View view) { |
| 5542 |
final int index = indexOfChild(view); |
| 5543 |
if (index >= 0) { |
| 5544 |
removeViewInternal(index, view); |
| 5545 |
return true; |
| 5546 |
} |
| 5547 |
return false; |
| 5548 |
} |
| 5549 |
|
| 5550 |
private void removeViewInternal(int index, View view) { |
| 5551 |
if (mTransition != null) { |
| 5552 |
mTransition.removeChild(this, view); |
| 5553 |
} |
| 5554 |
|
| 5555 |
boolean clearChildFocus = false; |
| 5556 |
if (view == mFocused) { |
| 5557 |
view.unFocus(null); |
| 5558 |
clearChildFocus = true; |
| 5559 |
} |
| 5560 |
if (view == mFocusedInCluster) { |
| 5561 |
clearFocusedInCluster(view); |
| 5562 |
} |
| 5563 |
|
| 5564 |
view.clearAccessibilityFocus(); |
| 5565 |
|
| 5566 |
cancelTouchTarget(view); |
| 5567 |
cancelHoverTarget(view); |
| 5568 |
|
| 5569 |
if (view.getAnimation() != null || |
| 5570 |
(mTransitioningViews != null && mTransitioningViews.contains(view))) { |
| 5571 |
addDisappearingView(view); |
| 5572 |
} else if (view.mAttachInfo != null) { |
| 5573 |
view.dispatchDetachedFromWindow(); |
| 5574 |
} |
| 5575 |
|
| 5576 |
if (view.hasTransientState()) { |
| 5577 |
childHasTransientStateChanged(view, false); |
| 5578 |
} |
| 5579 |
|
| 5580 |
needGlobalAttributesUpdate(false); |
| 5581 |
|
| 5582 |
removeFromArray(index); |
| 5583 |
|
| 5584 |
if (view.hasUnhandledKeyListener()) { |
| 5585 |
decrementChildUnhandledKeyListeners(); |
| 5586 |
} |
| 5587 |
|
| 5588 |
if (view == mDefaultFocus) { |
| 5589 |
clearDefaultFocus(view); |
| 5590 |
} |
| 5591 |
if (clearChildFocus) { |
| 5592 |
clearChildFocus(view); |
| 5593 |
if (!rootViewRequestFocus()) { |
| 5594 |
notifyGlobalFocusCleared(this); |
| 5595 |
} |
| 5596 |
} |
| 5597 |
|
| 5598 |
dispatchViewRemoved(view); |
| 5599 |
|
| 5600 |
if (view.getVisibility() != View.GONE) { |
| 5601 |
notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 5602 |
} |
| 5603 |
|
| 5604 |
int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 5605 |
for (int i = 0; i < transientCount; ++i) { |
| 5606 |
final int oldIndex = mTransientIndices.get(i); |
| 5607 |
if (index < oldIndex) { |
| 5608 |
mTransientIndices.set(i, oldIndex - 1); |
| 5609 |
} |
| 5610 |
} |
| 5611 |
|
| 5612 |
if (mCurrentDragStartEvent != null) { |
| 5613 |
mChildrenInterestedInDrag.remove(view); |
| 5614 |
} |
| 5615 |
} |
| 5616 |
|
| 5617 |
|
| 5618 |
|
| 5619 |
|
| 5620 |
|
| 5621 |
|
| 5622 |
|
| 5623 |
|
| 5624 |
|
| 5625 |
|
| 5626 |
|
| 5627 |
|
| 5628 |
|
| 5629 |
|
| 5630 |
|
| 5631 |
public void setLayoutTransition(LayoutTransition transition) { |
| 5632 |
if (mTransition != null) { |
| 5633 |
LayoutTransition previousTransition = mTransition; |
| 5634 |
previousTransition.cancel(); |
| 5635 |
previousTransition.removeTransitionListener(mLayoutTransitionListener); |
| 5636 |
} |
| 5637 |
mTransition = transition; |
| 5638 |
if (mTransition != null) { |
| 5639 |
mTransition.addTransitionListener(mLayoutTransitionListener); |
| 5640 |
} |
| 5641 |
} |
| 5642 |
|
| 5643 |
|
| 5644 |
|
| 5645 |
|
| 5646 |
|
| 5647 |
|
| 5648 |
|
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
public LayoutTransition getLayoutTransition() { |
| 5653 |
return mTransition; |
| 5654 |
} |
| 5655 |
|
| 5656 |
private void removeViewsInternal(int start, int count) { |
| 5657 |
final int end = start + count; |
| 5658 |
|
| 5659 |
if (start < 0 || count < 0 || end > mChildrenCount) { |
| 5660 |
throw new IndexOutOfBoundsException(); |
| 5661 |
} |
| 5662 |
|
| 5663 |
final View focused = mFocused; |
| 5664 |
final boolean detach = mAttachInfo != null; |
| 5665 |
boolean clearChildFocus = false; |
| 5666 |
View clearDefaultFocus = null; |
| 5667 |
|
| 5668 |
final View[] children = mChildren; |
| 5669 |
|
| 5670 |
for (int i = start; i < end; i++) { |
| 5671 |
final View view = children[i]; |
| 5672 |
|
| 5673 |
if (mTransition != null) { |
| 5674 |
mTransition.removeChild(this, view); |
| 5675 |
} |
| 5676 |
|
| 5677 |
if (view == focused) { |
| 5678 |
view.unFocus(null); |
| 5679 |
clearChildFocus = true; |
| 5680 |
} |
| 5681 |
if (view == mDefaultFocus) { |
| 5682 |
clearDefaultFocus = view; |
| 5683 |
} |
| 5684 |
if (view == mFocusedInCluster) { |
| 5685 |
clearFocusedInCluster(view); |
| 5686 |
} |
| 5687 |
|
| 5688 |
view.clearAccessibilityFocus(); |
| 5689 |
|
| 5690 |
cancelTouchTarget(view); |
| 5691 |
cancelHoverTarget(view); |
| 5692 |
|
| 5693 |
if (view.getAnimation() != null || |
| 5694 |
(mTransitioningViews != null && mTransitioningViews.contains(view))) { |
| 5695 |
addDisappearingView(view); |
| 5696 |
} else if (detach) { |
| 5697 |
view.dispatchDetachedFromWindow(); |
| 5698 |
} |
| 5699 |
|
| 5700 |
if (view.hasTransientState()) { |
| 5701 |
childHasTransientStateChanged(view, false); |
| 5702 |
} |
| 5703 |
|
| 5704 |
needGlobalAttributesUpdate(false); |
| 5705 |
|
| 5706 |
dispatchViewRemoved(view); |
| 5707 |
} |
| 5708 |
|
| 5709 |
removeFromArray(start, count); |
| 5710 |
|
| 5711 |
if (clearDefaultFocus != null) { |
| 5712 |
clearDefaultFocus(clearDefaultFocus); |
| 5713 |
} |
| 5714 |
if (clearChildFocus) { |
| 5715 |
clearChildFocus(focused); |
| 5716 |
if (!rootViewRequestFocus()) { |
| 5717 |
notifyGlobalFocusCleared(focused); |
| 5718 |
} |
| 5719 |
} |
| 5720 |
} |
| 5721 |
|
| 5722 |
|
| 5723 |
|
| 5724 |
|
| 5725 |
|
| 5726 |
|
| 5727 |
|
| 5728 |
|
| 5729 |
|
| 5730 |
public void removeAllViews() { |
| 5731 |
removeAllViewsInLayout(); |
| 5732 |
requestLayout(); |
| 5733 |
invalidate(true); |
| 5734 |
} |
| 5735 |
|
| 5736 |
|
| 5737 |
|
| 5738 |
|
| 5739 |
|
| 5740 |
|
| 5741 |
|
| 5742 |
|
| 5743 |
|
| 5744 |
|
| 5745 |
|
| 5746 |
|
| 5747 |
|
| 5748 |
|
| 5749 |
public void removeAllViewsInLayout() { |
| 5750 |
final int count = mChildrenCount; |
| 5751 |
if (count <= 0) { |
| 5752 |
return; |
| 5753 |
} |
| 5754 |
|
| 5755 |
final View[] children = mChildren; |
| 5756 |
mChildrenCount = 0; |
| 5757 |
|
| 5758 |
final View focused = mFocused; |
| 5759 |
final boolean detach = mAttachInfo != null; |
| 5760 |
boolean clearChildFocus = false; |
| 5761 |
|
| 5762 |
needGlobalAttributesUpdate(false); |
| 5763 |
|
| 5764 |
for (int i = count - 1; i >= 0; i--) { |
| 5765 |
final View view = children[i]; |
| 5766 |
|
| 5767 |
if (mTransition != null) { |
| 5768 |
mTransition.removeChild(this, view); |
| 5769 |
} |
| 5770 |
|
| 5771 |
if (view == focused) { |
| 5772 |
view.unFocus(null); |
| 5773 |
clearChildFocus = true; |
| 5774 |
} |
| 5775 |
|
| 5776 |
view.clearAccessibilityFocus(); |
| 5777 |
|
| 5778 |
cancelTouchTarget(view); |
| 5779 |
cancelHoverTarget(view); |
| 5780 |
|
| 5781 |
if (view.getAnimation() != null || |
| 5782 |
(mTransitioningViews != null && mTransitioningViews.contains(view))) { |
| 5783 |
addDisappearingView(view); |
| 5784 |
} else if (detach) { |
| 5785 |
view.dispatchDetachedFromWindow(); |
| 5786 |
} |
| 5787 |
|
| 5788 |
if (view.hasTransientState()) { |
| 5789 |
childHasTransientStateChanged(view, false); |
| 5790 |
} |
| 5791 |
|
| 5792 |
dispatchViewRemoved(view); |
| 5793 |
|
| 5794 |
view.mParent = null; |
| 5795 |
children[i] = null; |
| 5796 |
} |
| 5797 |
|
| 5798 |
if (mDefaultFocus != null) { |
| 5799 |
clearDefaultFocus(mDefaultFocus); |
| 5800 |
} |
| 5801 |
if (mFocusedInCluster != null) { |
| 5802 |
clearFocusedInCluster(mFocusedInCluster); |
| 5803 |
} |
| 5804 |
if (clearChildFocus) { |
| 5805 |
clearChildFocus(focused); |
| 5806 |
if (!rootViewRequestFocus()) { |
| 5807 |
notifyGlobalFocusCleared(focused); |
| 5808 |
} |
| 5809 |
} |
| 5810 |
} |
| 5811 |
|
| 5812 |
|
| 5813 |
|
| 5814 |
|
| 5815 |
|
| 5816 |
|
| 5817 |
|
| 5818 |
|
| 5819 |
|
| 5820 |
|
| 5821 |
|
| 5822 |
|
| 5823 |
|
| 5824 |
|
| 5825 |
|
| 5826 |
|
| 5827 |
|
| 5828 |
|
| 5829 |
|
| 5830 |
|
| 5831 |
|
| 5832 |
protected void removeDetachedView(View child, boolean animate) { |
| 5833 |
if (mTransition != null) { |
| 5834 |
mTransition.removeChild(this, child); |
| 5835 |
} |
| 5836 |
|
| 5837 |
if (child == mFocused) { |
| 5838 |
child.clearFocus(); |
| 5839 |
} |
| 5840 |
if (child == mDefaultFocus) { |
| 5841 |
clearDefaultFocus(child); |
| 5842 |
} |
| 5843 |
if (child == mFocusedInCluster) { |
| 5844 |
clearFocusedInCluster(child); |
| 5845 |
} |
| 5846 |
|
| 5847 |
child.clearAccessibilityFocus(); |
| 5848 |
|
| 5849 |
cancelTouchTarget(child); |
| 5850 |
cancelHoverTarget(child); |
| 5851 |
|
| 5852 |
if ((animate && child.getAnimation() != null) || |
| 5853 |
(mTransitioningViews != null && mTransitioningViews.contains(child))) { |
| 5854 |
addDisappearingView(child); |
| 5855 |
} else if (child.mAttachInfo != null) { |
| 5856 |
child.dispatchDetachedFromWindow(); |
| 5857 |
} |
| 5858 |
|
| 5859 |
if (child.hasTransientState()) { |
| 5860 |
childHasTransientStateChanged(child, false); |
| 5861 |
} |
| 5862 |
|
| 5863 |
dispatchViewRemoved(child); |
| 5864 |
} |
| 5865 |
|
| 5866 |
|
| 5867 |
|
| 5868 |
|
| 5869 |
|
| 5870 |
|
| 5871 |
|
| 5872 |
|
| 5873 |
|
| 5874 |
|
| 5875 |
|
| 5876 |
|
| 5877 |
|
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
|
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
|
| 5888 |
|
| 5889 |
protected void attachViewToParent(View child, int index, LayoutParams params) { |
| 5890 |
child.mLayoutParams = params; |
| 5891 |
|
| 5892 |
if (index < 0) { |
| 5893 |
index = mChildrenCount; |
| 5894 |
} |
| 5895 |
|
| 5896 |
addInArray(child, index); |
| 5897 |
|
| 5898 |
child.mParent = this; |
| 5899 |
child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK |
| 5900 |
& ~PFLAG_DRAWING_CACHE_VALID) |
| 5901 |
| PFLAG_DRAWN | PFLAG_INVALIDATED; |
| 5902 |
child.setDetached(false); |
| 5903 |
this.mPrivateFlags |= PFLAG_INVALIDATED; |
| 5904 |
|
| 5905 |
if (child.hasFocus()) { |
| 5906 |
requestChildFocus(child, child.findFocus()); |
| 5907 |
} |
| 5908 |
dispatchVisibilityAggregated(isAttachedToWindow() && getWindowVisibility() == VISIBLE |
| 5909 |
&& isShown()); |
| 5910 |
notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 5911 |
} |
| 5912 |
|
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
|
| 5917 |
|
| 5918 |
|
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
|
| 5924 |
|
| 5925 |
|
| 5926 |
|
| 5927 |
|
| 5928 |
|
| 5929 |
|
| 5930 |
protected void detachViewFromParent(View child) { |
| 5931 |
child.setDetached(true); |
| 5932 |
removeFromArray(indexOfChild(child)); |
| 5933 |
} |
| 5934 |
|
| 5935 |
|
| 5936 |
|
| 5937 |
|
| 5938 |
|
| 5939 |
|
| 5940 |
|
| 5941 |
|
| 5942 |
|
| 5943 |
|
| 5944 |
|
| 5945 |
|
| 5946 |
|
| 5947 |
|
| 5948 |
|
| 5949 |
|
| 5950 |
|
| 5951 |
|
| 5952 |
protected void detachViewFromParent(int index) { |
| 5953 |
if (index >= 0 && index < mChildrenCount) { |
| 5954 |
mChildren[index].setDetached(true); |
| 5955 |
} |
| 5956 |
removeFromArray(index); |
| 5957 |
} |
| 5958 |
|
| 5959 |
|
| 5960 |
|
| 5961 |
|
| 5962 |
|
| 5963 |
|
| 5964 |
|
| 5965 |
|
| 5966 |
|
| 5967 |
|
| 5968 |
|
| 5969 |
|
| 5970 |
|
| 5971 |
|
| 5972 |
|
| 5973 |
|
| 5974 |
|
| 5975 |
|
| 5976 |
|
| 5977 |
protected void detachViewsFromParent(int start, int count) { |
| 5978 |
start = Math.max(0, start); |
| 5979 |
final int end = Math.min(mChildrenCount, start + count); |
| 5980 |
for (int i = start; i < end; i++) { |
| 5981 |
mChildren[i].setDetached(true); |
| 5982 |
} |
| 5983 |
removeFromArray(start, count); |
| 5984 |
} |
| 5985 |
|
| 5986 |
|
| 5987 |
|
| 5988 |
|
| 5989 |
|
| 5990 |
|
| 5991 |
|
| 5992 |
|
| 5993 |
|
| 5994 |
|
| 5995 |
|
| 5996 |
|
| 5997 |
|
| 5998 |
|
| 5999 |
|
| 6000 |
|
| 6001 |
protected void detachAllViewsFromParent() { |
| 6002 |
final int count = mChildrenCount; |
| 6003 |
if (count <= 0) { |
| 6004 |
return; |
| 6005 |
} |
| 6006 |
|
| 6007 |
final View[] children = mChildren; |
| 6008 |
mChildrenCount = 0; |
| 6009 |
|
| 6010 |
for (int i = count - 1; i >= 0; i--) { |
| 6011 |
children[i].mParent = null; |
| 6012 |
children[i].setDetached(true); |
| 6013 |
children[i] = null; |
| 6014 |
} |
| 6015 |
} |
| 6016 |
|
| 6017 |
@Override |
| 6018 |
@CallSuper |
| 6019 |
public void onDescendantInvalidated(@NonNull View child, @NonNull View target) { |
| 6020 |
|
| 6021 |
|
| 6022 |
|
| 6023 |
|
| 6024 |
|
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
mPrivateFlags |= (target.mPrivateFlags & PFLAG_DRAW_ANIMATION); |
| 6029 |
|
| 6030 |
if ((target.mPrivateFlags & ~PFLAG_DIRTY_MASK) != 0) { |
| 6031 |
|
| 6032 |
|
| 6033 |
mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DIRTY; |
| 6034 |
|
| 6035 |
|
| 6036 |
mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 6037 |
} |
| 6038 |
|
| 6039 |
|
| 6040 |
if (mLayerType == LAYER_TYPE_SOFTWARE) { |
| 6041 |
|
| 6042 |
|
| 6043 |
mPrivateFlags |= PFLAG_INVALIDATED | PFLAG_DIRTY; |
| 6044 |
target = this; |
| 6045 |
} |
| 6046 |
|
| 6047 |
if (mParent != null) { |
| 6048 |
mParent.onDescendantInvalidated(this, target); |
| 6049 |
} |
| 6050 |
} |
| 6051 |
|
| 6052 |
|
| 6053 |
|
| 6054 |
|
| 6055 |
|
| 6056 |
|
| 6057 |
|
| 6058 |
|
| 6059 |
|
| 6060 |
@Deprecated |
| 6061 |
@Override |
| 6062 |
public final void invalidateChild(View child, final Rect dirty) { |
| 6063 |
final AttachInfo attachInfo = mAttachInfo; |
| 6064 |
if (attachInfo != null && attachInfo.mHardwareAccelerated) { |
| 6065 |
|
| 6066 |
onDescendantInvalidated(child, child); |
| 6067 |
return; |
| 6068 |
} |
| 6069 |
|
| 6070 |
ViewParent parent = this; |
| 6071 |
if (attachInfo != null) { |
| 6072 |
|
| 6073 |
|
| 6074 |
|
| 6075 |
final boolean drawAnimation = (child.mPrivateFlags & PFLAG_DRAW_ANIMATION) != 0; |
| 6076 |
|
| 6077 |
|
| 6078 |
|
| 6079 |
|
| 6080 |
Matrix childMatrix = child.getMatrix(); |
| 6081 |
|
| 6082 |
|
| 6083 |
|
| 6084 |
if (child.mLayerType != LAYER_TYPE_NONE) { |
| 6085 |
mPrivateFlags |= PFLAG_INVALIDATED; |
| 6086 |
mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 6087 |
} |
| 6088 |
|
| 6089 |
final int[] location = attachInfo.mInvalidateChildLocation; |
| 6090 |
location[CHILD_LEFT_INDEX] = child.mLeft; |
| 6091 |
location[CHILD_TOP_INDEX] = child.mTop; |
| 6092 |
if (!childMatrix.isIdentity() || |
| 6093 |
(mGroupFlags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 6094 |
RectF boundingRect = attachInfo.mTmpTransformRect; |
| 6095 |
boundingRect.set(dirty); |
| 6096 |
Matrix transformMatrix; |
| 6097 |
if ((mGroupFlags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 6098 |
Transformation t = attachInfo.mTmpTransformation; |
| 6099 |
boolean transformed = getChildStaticTransformation(child, t); |
| 6100 |
if (transformed) { |
| 6101 |
transformMatrix = attachInfo.mTmpMatrix; |
| 6102 |
transformMatrix.set(t.getMatrix()); |
| 6103 |
if (!childMatrix.isIdentity()) { |
| 6104 |
transformMatrix.preConcat(childMatrix); |
| 6105 |
} |
| 6106 |
} else { |
| 6107 |
transformMatrix = childMatrix; |
| 6108 |
} |
| 6109 |
} else { |
| 6110 |
transformMatrix = childMatrix; |
| 6111 |
} |
| 6112 |
transformMatrix.mapRect(boundingRect); |
| 6113 |
dirty.set((int) Math.floor(boundingRect.left), |
| 6114 |
(int) Math.floor(boundingRect.top), |
| 6115 |
(int) Math.ceil(boundingRect.right), |
| 6116 |
(int) Math.ceil(boundingRect.bottom)); |
| 6117 |
} |
| 6118 |
|
| 6119 |
do { |
| 6120 |
View view = null; |
| 6121 |
if (parent instanceof View) { |
| 6122 |
view = (View) parent; |
| 6123 |
} |
| 6124 |
|
| 6125 |
if (drawAnimation) { |
| 6126 |
if (view != null) { |
| 6127 |
view.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
| 6128 |
} else if (parent instanceof ViewRootImpl) { |
| 6129 |
((ViewRootImpl) parent).mIsAnimating = true; |
| 6130 |
} |
| 6131 |
} |
| 6132 |
|
| 6133 |
|
| 6134 |
|
| 6135 |
if (view != null) { |
| 6136 |
if ((view.mPrivateFlags & PFLAG_DIRTY_MASK) != PFLAG_DIRTY) { |
| 6137 |
view.mPrivateFlags = (view.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DIRTY; |
| 6138 |
} |
| 6139 |
} |
| 6140 |
|
| 6141 |
parent = parent.invalidateChildInParent(location, dirty); |
| 6142 |
if (view != null) { |
| 6143 |
|
| 6144 |
Matrix m = view.getMatrix(); |
| 6145 |
if (!m.isIdentity()) { |
| 6146 |
RectF boundingRect = attachInfo.mTmpTransformRect; |
| 6147 |
boundingRect.set(dirty); |
| 6148 |
m.mapRect(boundingRect); |
| 6149 |
dirty.set((int) Math.floor(boundingRect.left), |
| 6150 |
(int) Math.floor(boundingRect.top), |
| 6151 |
(int) Math.ceil(boundingRect.right), |
| 6152 |
(int) Math.ceil(boundingRect.bottom)); |
| 6153 |
} |
| 6154 |
} |
| 6155 |
} while (parent != null); |
| 6156 |
} |
| 6157 |
} |
| 6158 |
|
| 6159 |
|
| 6160 |
|
| 6161 |
|
| 6162 |
|
| 6163 |
|
| 6164 |
|
| 6165 |
|
| 6166 |
|
| 6167 |
|
| 6168 |
|
| 6169 |
|
| 6170 |
@Deprecated |
| 6171 |
@Override |
| 6172 |
public ViewParent invalidateChildInParent(final int[] location, final Rect dirty) { |
| 6173 |
if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID)) != 0) { |
| 6174 |
|
| 6175 |
if ((mGroupFlags & (FLAG_OPTIMIZE_INVALIDATE | FLAG_ANIMATION_DONE)) |
| 6176 |
!= FLAG_OPTIMIZE_INVALIDATE) { |
| 6177 |
dirty.offset(location[CHILD_LEFT_INDEX] - mScrollX, |
| 6178 |
location[CHILD_TOP_INDEX] - mScrollY); |
| 6179 |
if ((mGroupFlags & FLAG_CLIP_CHILDREN) == 0) { |
| 6180 |
dirty.union(0, 0, mRight - mLeft, mBottom - mTop); |
| 6181 |
} |
| 6182 |
|
| 6183 |
final int left = mLeft; |
| 6184 |
final int top = mTop; |
| 6185 |
|
| 6186 |
if ((mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN) { |
| 6187 |
if (!dirty.intersect(0, 0, mRight - left, mBottom - top)) { |
| 6188 |
dirty.setEmpty(); |
| 6189 |
} |
| 6190 |
} |
| 6191 |
|
| 6192 |
location[CHILD_LEFT_INDEX] = left; |
| 6193 |
location[CHILD_TOP_INDEX] = top; |
| 6194 |
} else { |
| 6195 |
|
| 6196 |
if ((mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN) { |
| 6197 |
dirty.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 6198 |
} else { |
| 6199 |
|
| 6200 |
dirty.union(0, 0, mRight - mLeft, mBottom - mTop); |
| 6201 |
} |
| 6202 |
location[CHILD_LEFT_INDEX] = mLeft; |
| 6203 |
location[CHILD_TOP_INDEX] = mTop; |
| 6204 |
|
| 6205 |
mPrivateFlags &= ~PFLAG_DRAWN; |
| 6206 |
} |
| 6207 |
mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 6208 |
if (mLayerType != LAYER_TYPE_NONE) { |
| 6209 |
mPrivateFlags |= PFLAG_INVALIDATED; |
| 6210 |
} |
| 6211 |
|
| 6212 |
return mParent; |
| 6213 |
} |
| 6214 |
|
| 6215 |
return null; |
| 6216 |
} |
| 6217 |
|
| 6218 |
|
| 6219 |
|
| 6220 |
|
| 6221 |
|
| 6222 |
|
| 6223 |
|
| 6224 |
public final void offsetDescendantRectToMyCoords(View descendant, Rect rect) { |
| 6225 |
offsetRectBetweenParentAndChild(descendant, rect, true, false); |
| 6226 |
} |
| 6227 |
|
| 6228 |
|
| 6229 |
|
| 6230 |
|
| 6231 |
|
| 6232 |
|
| 6233 |
|
| 6234 |
public final void offsetRectIntoDescendantCoords(View descendant, Rect rect) { |
| 6235 |
offsetRectBetweenParentAndChild(descendant, rect, false, false); |
| 6236 |
} |
| 6237 |
|
| 6238 |
|
| 6239 |
|
| 6240 |
|
| 6241 |
|
| 6242 |
void offsetRectBetweenParentAndChild(View descendant, Rect rect, |
| 6243 |
boolean offsetFromChildToParent, boolean clipToBounds) { |
| 6244 |
|
| 6245 |
|
| 6246 |
if (descendant == this) { |
| 6247 |
return; |
| 6248 |
} |
| 6249 |
|
| 6250 |
ViewParent theParent = descendant.mParent; |
| 6251 |
|
| 6252 |
|
| 6253 |
while ((theParent != null) |
| 6254 |
&& (theParent instanceof View) |
| 6255 |
&& (theParent != this)) { |
| 6256 |
|
| 6257 |
if (offsetFromChildToParent) { |
| 6258 |
rect.offset(descendant.mLeft - descendant.mScrollX, |
| 6259 |
descendant.mTop - descendant.mScrollY); |
| 6260 |
if (clipToBounds) { |
| 6261 |
View p = (View) theParent; |
| 6262 |
boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft, |
| 6263 |
p.mBottom - p.mTop); |
| 6264 |
if (!intersected) { |
| 6265 |
rect.setEmpty(); |
| 6266 |
} |
| 6267 |
} |
| 6268 |
} else { |
| 6269 |
if (clipToBounds) { |
| 6270 |
View p = (View) theParent; |
| 6271 |
boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft, |
| 6272 |
p.mBottom - p.mTop); |
| 6273 |
if (!intersected) { |
| 6274 |
rect.setEmpty(); |
| 6275 |
} |
| 6276 |
} |
| 6277 |
rect.offset(descendant.mScrollX - descendant.mLeft, |
| 6278 |
descendant.mScrollY - descendant.mTop); |
| 6279 |
} |
| 6280 |
|
| 6281 |
descendant = (View) theParent; |
| 6282 |
theParent = descendant.mParent; |
| 6283 |
} |
| 6284 |
|
| 6285 |
|
| 6286 |
|
| 6287 |
if (theParent == this) { |
| 6288 |
if (offsetFromChildToParent) { |
| 6289 |
rect.offset(descendant.mLeft - descendant.mScrollX, |
| 6290 |
descendant.mTop - descendant.mScrollY); |
| 6291 |
} else { |
| 6292 |
rect.offset(descendant.mScrollX - descendant.mLeft, |
| 6293 |
descendant.mScrollY - descendant.mTop); |
| 6294 |
} |
| 6295 |
} else { |
| 6296 |
throw new IllegalArgumentException("parameter must be a descendant of this view"); |
| 6297 |
} |
| 6298 |
} |
| 6299 |
|
| 6300 |
|
| 6301 |
|
| 6302 |
|
| 6303 |
|
| 6304 |
|
| 6305 |
|
| 6306 |
|
| 6307 |
@UnsupportedAppUsage |
| 6308 |
public void offsetChildrenTopAndBottom(int offset) { |
| 6309 |
final int count = mChildrenCount; |
| 6310 |
final View[] children = mChildren; |
| 6311 |
boolean invalidate = false; |
| 6312 |
|
| 6313 |
for (int i = 0; i < count; i++) { |
| 6314 |
final View v = children[i]; |
| 6315 |
v.mTop += offset; |
| 6316 |
v.mBottom += offset; |
| 6317 |
if (v.mRenderNode != null) { |
| 6318 |
invalidate = true; |
| 6319 |
v.mRenderNode.offsetTopAndBottom(offset); |
| 6320 |
} |
| 6321 |
} |
| 6322 |
|
| 6323 |
if (invalidate) { |
| 6324 |
invalidateViewProperty(false, false); |
| 6325 |
} |
| 6326 |
notifySubtreeAccessibilityStateChangedIfNeeded(); |
| 6327 |
} |
| 6328 |
|
| 6329 |
@Override |
| 6330 |
public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { |
| 6331 |
return getChildVisibleRect(child, r, offset, false); |
| 6332 |
} |
| 6333 |
|
| 6334 |
|
| 6335 |
|
| 6336 |
|
| 6337 |
|
| 6338 |
|
| 6339 |
|
| 6340 |
public boolean getChildVisibleRect( |
| 6341 |
View child, Rect r, android.graphics.Point offset, boolean forceParentCheck) { |
| 6342 |
|
| 6343 |
|
| 6344 |
|
| 6345 |
final RectF rect = mAttachInfo != null ? mAttachInfo.mTmpTransformRect : new RectF(); |
| 6346 |
rect.set(r); |
| 6347 |
|
| 6348 |
if (!child.hasIdentityMatrix()) { |
| 6349 |
child.getMatrix().mapRect(rect); |
| 6350 |
} |
| 6351 |
|
| 6352 |
final int dx = child.mLeft - mScrollX; |
| 6353 |
final int dy = child.mTop - mScrollY; |
| 6354 |
|
| 6355 |
rect.offset(dx, dy); |
| 6356 |
|
| 6357 |
if (offset != null) { |
| 6358 |
if (!child.hasIdentityMatrix()) { |
| 6359 |
float[] position = mAttachInfo != null ? mAttachInfo.mTmpTransformLocation |
| 6360 |
: new float[2]; |
| 6361 |
position[0] = offset.x; |
| 6362 |
position[1] = offset.y; |
| 6363 |
child.getMatrix().mapPoints(position); |
| 6364 |
offset.x = Math.round(position[0]); |
| 6365 |
offset.y = Math.round(position[1]); |
| 6366 |
} |
| 6367 |
offset.x += dx; |
| 6368 |
offset.y += dy; |
| 6369 |
} |
| 6370 |
|
| 6371 |
final int width = mRight - mLeft; |
| 6372 |
final int height = mBottom - mTop; |
| 6373 |
|
| 6374 |
boolean rectIsVisible = true; |
| 6375 |
if (mParent == null || |
| 6376 |
(mParent instanceof ViewGroup && ((ViewGroup) mParent).getClipChildren())) { |
| 6377 |
|
| 6378 |
rectIsVisible = rect.intersect(0, 0, width, height); |
| 6379 |
} |
| 6380 |
|
| 6381 |
if ((forceParentCheck || rectIsVisible) |
| 6382 |
&& (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK) { |
| 6383 |
|
| 6384 |
rectIsVisible = rect.intersect(mPaddingLeft, mPaddingTop, |
| 6385 |
width - mPaddingRight, height - mPaddingBottom); |
| 6386 |
} |
| 6387 |
|
| 6388 |
if ((forceParentCheck || rectIsVisible) && mClipBounds != null) { |
| 6389 |
|
| 6390 |
rectIsVisible = rect.intersect(mClipBounds.left, mClipBounds.top, mClipBounds.right, |
| 6391 |
mClipBounds.bottom); |
| 6392 |
} |
| 6393 |
r.set((int) Math.floor(rect.left), (int) Math.floor(rect.top), |
| 6394 |
(int) Math.ceil(rect.right), (int) Math.ceil(rect.bottom)); |
| 6395 |
|
| 6396 |
if ((forceParentCheck || rectIsVisible) && mParent != null) { |
| 6397 |
if (mParent instanceof ViewGroup) { |
| 6398 |
rectIsVisible = ((ViewGroup) mParent) |
| 6399 |
.getChildVisibleRect(this, r, offset, forceParentCheck); |
| 6400 |
} else { |
| 6401 |
rectIsVisible = mParent.getChildVisibleRect(this, r, offset); |
| 6402 |
} |
| 6403 |
} |
| 6404 |
return rectIsVisible; |
| 6405 |
} |
| 6406 |
|
| 6407 |
@Override |
| 6408 |
public final void layout(int l, int t, int r, int b) { |
| 6409 |
if (!mSuppressLayout && (mTransition == null || !mTransition.isChangingLayout())) { |
| 6410 |
if (mTransition != null) { |
| 6411 |
mTransition.layoutChange(this); |
| 6412 |
} |
| 6413 |
super.layout(l, t, r, b); |
| 6414 |
} else { |
| 6415 |
|
| 6416 |
mLayoutCalledWhileSuppressed = true; |
| 6417 |
} |
| 6418 |
} |
| 6419 |
|
| 6420 |
@Override |
| 6421 |
protected abstract void onLayout(boolean changed, |
| 6422 |
int l, int t, int r, int b); |
| 6423 |
|
| 6424 |
|
| 6425 |
|
| 6426 |
|
| 6427 |
|
| 6428 |
|
| 6429 |
|
| 6430 |
protected boolean canAnimate() { |
| 6431 |
return mLayoutAnimationController != null; |
| 6432 |
} |
| 6433 |
|
| 6434 |
|
| 6435 |
|
| 6436 |
|
| 6437 |
|
| 6438 |
public void startLayoutAnimation() { |
| 6439 |
if (mLayoutAnimationController != null) { |
| 6440 |
mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6441 |
requestLayout(); |
| 6442 |
} |
| 6443 |
} |
| 6444 |
|
| 6445 |
|
| 6446 |
|
| 6447 |
|
| 6448 |
|
| 6449 |
|
| 6450 |
|
| 6451 |
public void scheduleLayoutAnimation() { |
| 6452 |
mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6453 |
} |
| 6454 |
|
| 6455 |
|
| 6456 |
|
| 6457 |
|
| 6458 |
|
| 6459 |
|
| 6460 |
|
| 6461 |
public void setLayoutAnimation(LayoutAnimationController controller) { |
| 6462 |
mLayoutAnimationController = controller; |
| 6463 |
if (mLayoutAnimationController != null) { |
| 6464 |
mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6465 |
} |
| 6466 |
} |
| 6467 |
|
| 6468 |
|
| 6469 |
|
| 6470 |
|
| 6471 |
|
| 6472 |
|
| 6473 |
|
| 6474 |
@InspectableProperty |
| 6475 |
public LayoutAnimationController getLayoutAnimation() { |
| 6476 |
return mLayoutAnimationController; |
| 6477 |
} |
| 6478 |
|
| 6479 |
|
| 6480 |
|
| 6481 |
|
| 6482 |
|
| 6483 |
|
| 6484 |
|
| 6485 |
|
| 6486 |
|
| 6487 |
|
| 6488 |
|
| 6489 |
|
| 6490 |
|
| 6491 |
|
| 6492 |
|
| 6493 |
@Deprecated |
| 6494 |
@InspectableProperty(name = "animationCache") |
| 6495 |
public boolean isAnimationCacheEnabled() { |
| 6496 |
return (mGroupFlags & FLAG_ANIMATION_CACHE) == FLAG_ANIMATION_CACHE; |
| 6497 |
} |
| 6498 |
|
| 6499 |
|
| 6500 |
|
| 6501 |
|
| 6502 |
|
| 6503 |
|
| 6504 |
|
| 6505 |
|
| 6506 |
|
| 6507 |
|
| 6508 |
|
| 6509 |
|
| 6510 |
|
| 6511 |
|
| 6512 |
|
| 6513 |
@Deprecated |
| 6514 |
public void setAnimationCacheEnabled(boolean enabled) { |
| 6515 |
setBooleanFlag(FLAG_ANIMATION_CACHE, enabled); |
| 6516 |
} |
| 6517 |
|
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
|
| 6522 |
|
| 6523 |
|
| 6524 |
|
| 6525 |
|
| 6526 |
|
| 6527 |
|
| 6528 |
|
| 6529 |
|
| 6530 |
|
| 6531 |
@Deprecated |
| 6532 |
@InspectableProperty(name = "alwaysDrawnWithCache") |
| 6533 |
public boolean isAlwaysDrawnWithCacheEnabled() { |
| 6534 |
return (mGroupFlags & FLAG_ALWAYS_DRAWN_WITH_CACHE) == FLAG_ALWAYS_DRAWN_WITH_CACHE; |
| 6535 |
} |
| 6536 |
|
| 6537 |
|
| 6538 |
|
| 6539 |
|
| 6540 |
|
| 6541 |
|
| 6542 |
|
| 6543 |
|
| 6544 |
|
| 6545 |
|
| 6546 |
|
| 6547 |
|
| 6548 |
|
| 6549 |
|
| 6550 |
|
| 6551 |
|
| 6552 |
|
| 6553 |
|
| 6554 |
|
| 6555 |
|
| 6556 |
|
| 6557 |
@Deprecated |
| 6558 |
public void setAlwaysDrawnWithCacheEnabled(boolean always) { |
| 6559 |
setBooleanFlag(FLAG_ALWAYS_DRAWN_WITH_CACHE, always); |
| 6560 |
} |
| 6561 |
|
| 6562 |
|
| 6563 |
|
| 6564 |
|
| 6565 |
|
| 6566 |
|
| 6567 |
|
| 6568 |
|
| 6569 |
|
| 6570 |
|
| 6571 |
|
| 6572 |
|
| 6573 |
|
| 6574 |
|
| 6575 |
@Deprecated |
| 6576 |
protected boolean isChildrenDrawnWithCacheEnabled() { |
| 6577 |
return (mGroupFlags & FLAG_CHILDREN_DRAWN_WITH_CACHE) == FLAG_CHILDREN_DRAWN_WITH_CACHE; |
| 6578 |
} |
| 6579 |
|
| 6580 |
|
| 6581 |
|
| 6582 |
|
| 6583 |
|
| 6584 |
|
| 6585 |
|
| 6586 |
|
| 6587 |
|
| 6588 |
|
| 6589 |
|
| 6590 |
|
| 6591 |
|
| 6592 |
|
| 6593 |
|
| 6594 |
|
| 6595 |
|
| 6596 |
|
| 6597 |
@Deprecated |
| 6598 |
protected void setChildrenDrawnWithCacheEnabled(boolean enabled) { |
| 6599 |
setBooleanFlag(FLAG_CHILDREN_DRAWN_WITH_CACHE, enabled); |
| 6600 |
} |
| 6601 |
|
| 6602 |
|
| 6603 |
|
| 6604 |
|
| 6605 |
|
| 6606 |
|
| 6607 |
|
| 6608 |
|
| 6609 |
|
| 6610 |
|
| 6611 |
|
| 6612 |
@ViewDebug.ExportedProperty(category = "drawing") |
| 6613 |
protected boolean isChildrenDrawingOrderEnabled() { |
| 6614 |
return (mGroupFlags & FLAG_USE_CHILD_DRAWING_ORDER) == FLAG_USE_CHILD_DRAWING_ORDER; |
| 6615 |
} |
| 6616 |
|
| 6617 |
|
| 6618 |
|
| 6619 |
|
| 6620 |
|
| 6621 |
|
| 6622 |
|
| 6623 |
|
| 6624 |
|
| 6625 |
|
| 6626 |
|
| 6627 |
|
| 6628 |
|
| 6629 |
|
| 6630 |
protected void setChildrenDrawingOrderEnabled(boolean enabled) { |
| 6631 |
setBooleanFlag(FLAG_USE_CHILD_DRAWING_ORDER, enabled); |
| 6632 |
} |
| 6633 |
|
| 6634 |
private boolean hasBooleanFlag(int flag) { |
| 6635 |
return (mGroupFlags & flag) == flag; |
| 6636 |
} |
| 6637 |
|
| 6638 |
private void setBooleanFlag(int flag, boolean value) { |
| 6639 |
if (value) { |
| 6640 |
mGroupFlags |= flag; |
| 6641 |
} else { |
| 6642 |
mGroupFlags &= ~flag; |
| 6643 |
} |
| 6644 |
} |
| 6645 |
|
| 6646 |
|
| 6647 |
|
| 6648 |
|
| 6649 |
|
| 6650 |
|
| 6651 |
|
| 6652 |
|
| 6653 |
|
| 6654 |
|
| 6655 |
|
| 6656 |
|
| 6657 |
|
| 6658 |
|
| 6659 |
|
| 6660 |
|
| 6661 |
|
| 6662 |
|
| 6663 |
|
| 6664 |
|
| 6665 |
|
| 6666 |
|
| 6667 |
|
| 6668 |
|
| 6669 |
@Deprecated |
| 6670 |
@ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 6671 |
@ViewDebug.IntToString(from = PERSISTENT_NO_CACHE, to = "NONE"), |
| 6672 |
@ViewDebug.IntToString(from = PERSISTENT_ANIMATION_CACHE, to = "ANIMATION"), |
| 6673 |
@ViewDebug.IntToString(from = PERSISTENT_SCROLLING_CACHE, to = "SCROLLING"), |
| 6674 |
@ViewDebug.IntToString(from = PERSISTENT_ALL_CACHES, to = "ALL") |
| 6675 |
}) |
| 6676 |
@InspectableProperty(enumMapping = { |
| 6677 |
@EnumEntry(value = PERSISTENT_NO_CACHE, name = "none"), |
| 6678 |
@EnumEntry(value = PERSISTENT_ANIMATION_CACHE, name = "animation"), |
| 6679 |
@EnumEntry(value = PERSISTENT_SCROLLING_CACHE, name = "scrolling"), |
| 6680 |
@EnumEntry(value = PERSISTENT_ALL_CACHES, name = "all"), |
| 6681 |
}) |
| 6682 |
public int getPersistentDrawingCache() { |
| 6683 |
return mPersistentDrawingCache; |
| 6684 |
} |
| 6685 |
|
| 6686 |
|
| 6687 |
|
| 6688 |
|
| 6689 |
|
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
|
| 6695 |
|
| 6696 |
|
| 6697 |
|
| 6698 |
|
| 6699 |
|
| 6700 |
|
| 6701 |
|
| 6702 |
|
| 6703 |
|
| 6704 |
|
| 6705 |
|
| 6706 |
|
| 6707 |
|
| 6708 |
|
| 6709 |
|
| 6710 |
@Deprecated |
| 6711 |
public void setPersistentDrawingCache(int drawingCacheToKeep) { |
| 6712 |
mPersistentDrawingCache = drawingCacheToKeep & PERSISTENT_ALL_CACHES; |
| 6713 |
} |
| 6714 |
|
| 6715 |
private void setLayoutMode(int layoutMode, boolean explicitly) { |
| 6716 |
mLayoutMode = layoutMode; |
| 6717 |
setBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET, explicitly); |
| 6718 |
} |
| 6719 |
|
| 6720 |
|
| 6721 |
|
| 6722 |
|
| 6723 |
|
| 6724 |
|
| 6725 |
|
| 6726 |
|
| 6727 |
|
| 6728 |
|
| 6729 |
|
| 6730 |
|
| 6731 |
|
| 6732 |
@Override |
| 6733 |
void invalidateInheritedLayoutMode(int layoutModeOfRoot) { |
| 6734 |
if (mLayoutMode == LAYOUT_MODE_UNDEFINED || |
| 6735 |
mLayoutMode == layoutModeOfRoot || |
| 6736 |
hasBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET)) { |
| 6737 |
return; |
| 6738 |
} |
| 6739 |
setLayoutMode(LAYOUT_MODE_UNDEFINED, false); |
| 6740 |
|
| 6741 |
|
| 6742 |
for (int i = 0, N = getChildCount(); i < N; i++) { |
| 6743 |
getChildAt(i).invalidateInheritedLayoutMode(layoutModeOfRoot); |
| 6744 |
} |
| 6745 |
} |
| 6746 |
|
| 6747 |
|
| 6748 |
|
| 6749 |
|
| 6750 |
|
| 6751 |
|
| 6752 |
|
| 6753 |
|
| 6754 |
|
| 6755 |
|
| 6756 |
|
| 6757 |
|
| 6758 |
|
| 6759 |
@InspectableProperty(enumMapping = { |
| 6760 |
@EnumEntry(value = LAYOUT_MODE_CLIP_BOUNDS, name = "clipBounds"), |
| 6761 |
@EnumEntry(value = LAYOUT_MODE_OPTICAL_BOUNDS, name = "opticalBounds") |
| 6762 |
}) |
| 6763 |
public int getLayoutMode() { |
| 6764 |
if (mLayoutMode == LAYOUT_MODE_UNDEFINED) { |
| 6765 |
int inheritedLayoutMode = (mParent instanceof ViewGroup) ? |
| 6766 |
((ViewGroup) mParent).getLayoutMode() : LAYOUT_MODE_DEFAULT; |
| 6767 |
setLayoutMode(inheritedLayoutMode, false); |
| 6768 |
} |
| 6769 |
return mLayoutMode; |
| 6770 |
} |
| 6771 |
|
| 6772 |
|
| 6773 |
|
| 6774 |
|
| 6775 |
|
| 6776 |
|
| 6777 |
|
| 6778 |
|
| 6779 |
|
| 6780 |
|
| 6781 |
|
| 6782 |
public void setLayoutMode(int layoutMode) { |
| 6783 |
if (mLayoutMode != layoutMode) { |
| 6784 |
invalidateInheritedLayoutMode(layoutMode); |
| 6785 |
setLayoutMode(layoutMode, layoutMode != LAYOUT_MODE_UNDEFINED); |
| 6786 |
requestLayout(); |
| 6787 |
} |
| 6788 |
} |
| 6789 |
|
| 6790 |
|
| 6791 |
|
| 6792 |
|
| 6793 |
|
| 6794 |
|
| 6795 |
|
| 6796 |
|
| 6797 |
|
| 6798 |
public LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 6799 |
return new LayoutParams(getContext(), attrs); |
| 6800 |
} |
| 6801 |
|
| 6802 |
|
| 6803 |
|
| 6804 |
|
| 6805 |
|
| 6806 |
|
| 6807 |
|
| 6808 |
|
| 6809 |
|
| 6810 |
|
| 6811 |
|
| 6812 |
|
| 6813 |
|
| 6814 |
|
| 6815 |
|
| 6816 |
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { |
| 6817 |
return p; |
| 6818 |
} |
| 6819 |
|
| 6820 |
|
| 6821 |
|
| 6822 |
|
| 6823 |
|
| 6824 |
|
| 6825 |
|
| 6826 |
|
| 6827 |
protected LayoutParams generateDefaultLayoutParams() { |
| 6828 |
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
| 6829 |
} |
| 6830 |
|
| 6831 |
@Override |
| 6832 |
protected void debug(int depth) { |
| 6833 |
super.debug(depth); |
| 6834 |
String output; |
| 6835 |
|
| 6836 |
if (mFocused != null) { |
| 6837 |
output = debugIndent(depth); |
| 6838 |
output += "mFocused"; |
| 6839 |
Log.d(VIEW_LOG_TAG, output); |
| 6840 |
mFocused.debug(depth + 1); |
| 6841 |
} |
| 6842 |
if (mDefaultFocus != null) { |
| 6843 |
output = debugIndent(depth); |
| 6844 |
output += "mDefaultFocus"; |
| 6845 |
Log.d(VIEW_LOG_TAG, output); |
| 6846 |
mDefaultFocus.debug(depth + 1); |
| 6847 |
} |
| 6848 |
if (mFocusedInCluster != null) { |
| 6849 |
output = debugIndent(depth); |
| 6850 |
output += "mFocusedInCluster"; |
| 6851 |
Log.d(VIEW_LOG_TAG, output); |
| 6852 |
mFocusedInCluster.debug(depth + 1); |
| 6853 |
} |
| 6854 |
if (mChildrenCount != 0) { |
| 6855 |
output = debugIndent(depth); |
| 6856 |
output += "{"; |
| 6857 |
Log.d(VIEW_LOG_TAG, output); |
| 6858 |
} |
| 6859 |
int count = mChildrenCount; |
| 6860 |
for (int i = 0; i < count; i++) { |
| 6861 |
View child = mChildren[i]; |
| 6862 |
child.debug(depth + 1); |
| 6863 |
} |
| 6864 |
|
| 6865 |
if (mChildrenCount != 0) { |
| 6866 |
output = debugIndent(depth); |
| 6867 |
output += "}"; |
| 6868 |
Log.d(VIEW_LOG_TAG, output); |
| 6869 |
} |
| 6870 |
} |
| 6871 |
|
| 6872 |
|
| 6873 |
|
| 6874 |
|
| 6875 |
|
| 6876 |
|
| 6877 |
|
| 6878 |
|
| 6879 |
public int indexOfChild(View child) { |
| 6880 |
final int count = mChildrenCount; |
| 6881 |
final View[] children = mChildren; |
| 6882 |
for (int i = 0; i < count; i++) { |
| 6883 |
if (children[i] == child) { |
| 6884 |
return i; |
| 6885 |
} |
| 6886 |
} |
| 6887 |
return -1; |
| 6888 |
} |
| 6889 |
|
| 6890 |
|
| 6891 |
|
| 6892 |
|
| 6893 |
|
| 6894 |
|
| 6895 |
|
| 6896 |
public int getChildCount() { |
| 6897 |
return mChildrenCount; |
| 6898 |
} |
| 6899 |
|
| 6900 |
|
| 6901 |
|
| 6902 |
|
| 6903 |
|
| 6904 |
|
| 6905 |
|
| 6906 |
|
| 6907 |
public View getChildAt(int index) { |
| 6908 |
if (index < 0 || index >= mChildrenCount) { |
| 6909 |
return null; |
| 6910 |
} |
| 6911 |
return mChildren[index]; |
| 6912 |
} |
| 6913 |
|
| 6914 |
|
| 6915 |
|
| 6916 |
|
| 6917 |
|
| 6918 |
|
| 6919 |
|
| 6920 |
|
| 6921 |
|
| 6922 |
|
| 6923 |
protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec) { |
| 6924 |
final int size = mChildrenCount; |
| 6925 |
final View[] children = mChildren; |
| 6926 |
for (int i = 0; i < size; ++i) { |
| 6927 |
final View child = children[i]; |
| 6928 |
if ((child.mViewFlags & VISIBILITY_MASK) != GONE) { |
| 6929 |
measureChild(child, widthMeasureSpec, heightMeasureSpec); |
| 6930 |
} |
| 6931 |
} |
| 6932 |
} |
| 6933 |
|
| 6934 |
|
| 6935 |
|
| 6936 |
|
| 6937 |
|
| 6938 |
|
| 6939 |
|
| 6940 |
|
| 6941 |
|
| 6942 |
|
| 6943 |
protected void measureChild(View child, int parentWidthMeasureSpec, |
| 6944 |
int parentHeightMeasureSpec) { |
| 6945 |
final LayoutParams lp = child.getLayoutParams(); |
| 6946 |
|
| 6947 |
final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, |
| 6948 |
mPaddingLeft + mPaddingRight, lp.width); |
| 6949 |
final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, |
| 6950 |
mPaddingTop + mPaddingBottom, lp.height); |
| 6951 |
|
| 6952 |
child.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 6953 |
} |
| 6954 |
|
| 6955 |
|
| 6956 |
|
| 6957 |
|
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
|
| 6962 |
|
| 6963 |
|
| 6964 |
|
| 6965 |
|
| 6966 |
|
| 6967 |
|
| 6968 |
|
| 6969 |
protected void measureChildWithMargins(View child, |
| 6970 |
int parentWidthMeasureSpec, int widthUsed, |
| 6971 |
int parentHeightMeasureSpec, int heightUsed) { |
| 6972 |
final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); |
| 6973 |
|
| 6974 |
final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, |
| 6975 |
mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin |
| 6976 |
+ widthUsed, lp.width); |
| 6977 |
final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, |
| 6978 |
mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin |
| 6979 |
+ heightUsed, lp.height); |
| 6980 |
|
| 6981 |
child.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 6982 |
} |
| 6983 |
|
| 6984 |
|
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
|
| 6991 |
|
| 6992 |
|
| 6993 |
|
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
|
| 6999 |
|
| 7000 |
|
| 7001 |
|
| 7002 |
|
| 7003 |
public static int getChildMeasureSpec(int spec, int padding, int childDimension) { |
| 7004 |
int specMode = MeasureSpec.getMode(spec); |
| 7005 |
int specSize = MeasureSpec.getSize(spec); |
| 7006 |
|
| 7007 |
int size = Math.max(0, specSize - padding); |
| 7008 |
|
| 7009 |
int resultSize = 0; |
| 7010 |
int resultMode = 0; |
| 7011 |
|
| 7012 |
switch (specMode) { |
| 7013 |
|
| 7014 |
case MeasureSpec.EXACTLY: |
| 7015 |
if (childDimension >= 0) { |
| 7016 |
resultSize = childDimension; |
| 7017 |
resultMode = MeasureSpec.EXACTLY; |
| 7018 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 7019 |
|
| 7020 |
resultSize = size; |
| 7021 |
resultMode = MeasureSpec.EXACTLY; |
| 7022 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 7023 |
|
| 7024 |
|
| 7025 |
resultSize = size; |
| 7026 |
resultMode = MeasureSpec.AT_MOST; |
| 7027 |
} |
| 7028 |
break; |
| 7029 |
|
| 7030 |
|
| 7031 |
case MeasureSpec.AT_MOST: |
| 7032 |
if (childDimension >= 0) { |
| 7033 |
|
| 7034 |
resultSize = childDimension; |
| 7035 |
resultMode = MeasureSpec.EXACTLY; |
| 7036 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 7037 |
|
| 7038 |
|
| 7039 |
resultSize = size; |
| 7040 |
resultMode = MeasureSpec.AT_MOST; |
| 7041 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 7042 |
|
| 7043 |
|
| 7044 |
resultSize = size; |
| 7045 |
resultMode = MeasureSpec.AT_MOST; |
| 7046 |
} |
| 7047 |
break; |
| 7048 |
|
| 7049 |
|
| 7050 |
case MeasureSpec.UNSPECIFIED: |
| 7051 |
if (childDimension >= 0) { |
| 7052 |
|
| 7053 |
resultSize = childDimension; |
| 7054 |
resultMode = MeasureSpec.EXACTLY; |
| 7055 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 7056 |
|
| 7057 |
|
| 7058 |
resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; |
| 7059 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 7060 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 7061 |
|
| 7062 |
|
| 7063 |
resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; |
| 7064 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 7065 |
} |
| 7066 |
break; |
| 7067 |
} |
| 7068 |
|
| 7069 |
return MeasureSpec.makeMeasureSpec(resultSize, resultMode); |
| 7070 |
} |
| 7071 |
|
| 7072 |
|
| 7073 |
|
| 7074 |
|
| 7075 |
|
| 7076 |
|
| 7077 |
public void clearDisappearingChildren() { |
| 7078 |
final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 7079 |
if (disappearingChildren != null) { |
| 7080 |
final int count = disappearingChildren.size(); |
| 7081 |
for (int i = 0; i < count; i++) { |
| 7082 |
final View view = disappearingChildren.get(i); |
| 7083 |
if (view.mAttachInfo != null) { |
| 7084 |
view.dispatchDetachedFromWindow(); |
| 7085 |
} |
| 7086 |
view.clearAnimation(); |
| 7087 |
} |
| 7088 |
disappearingChildren.clear(); |
| 7089 |
invalidate(); |
| 7090 |
} |
| 7091 |
} |
| 7092 |
|
| 7093 |
|
| 7094 |
|
| 7095 |
|
| 7096 |
|
| 7097 |
|
| 7098 |
private void addDisappearingView(View v) { |
| 7099 |
ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 7100 |
|
| 7101 |
if (disappearingChildren == null) { |
| 7102 |
disappearingChildren = mDisappearingChildren = new ArrayList<View>(); |
| 7103 |
} |
| 7104 |
|
| 7105 |
disappearingChildren.add(v); |
| 7106 |
} |
| 7107 |
|
| 7108 |
|
| 7109 |
|
| 7110 |
|
| 7111 |
|
| 7112 |
|
| 7113 |
|
| 7114 |
|
| 7115 |
void finishAnimatingView(final View view, Animation animation) { |
| 7116 |
final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 7117 |
if (disappearingChildren != null) { |
| 7118 |
if (disappearingChildren.contains(view)) { |
| 7119 |
disappearingChildren.remove(view); |
| 7120 |
|
| 7121 |
if (view.mAttachInfo != null) { |
| 7122 |
view.dispatchDetachedFromWindow(); |
| 7123 |
} |
| 7124 |
|
| 7125 |
view.clearAnimation(); |
| 7126 |
mGroupFlags |= FLAG_INVALIDATE_REQUIRED; |
| 7127 |
} |
| 7128 |
} |
| 7129 |
|
| 7130 |
if (animation != null && !animation.getFillAfter()) { |
| 7131 |
view.clearAnimation(); |
| 7132 |
} |
| 7133 |
|
| 7134 |
if ((view.mPrivateFlags & PFLAG_ANIMATION_STARTED) == PFLAG_ANIMATION_STARTED) { |
| 7135 |
view.onAnimationEnd(); |
| 7136 |
|
| 7137 |
|
| 7138 |
view.mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
| 7139 |
|
| 7140 |
mGroupFlags |= FLAG_INVALIDATE_REQUIRED; |
| 7141 |
} |
| 7142 |
} |
| 7143 |
|
| 7144 |
|
| 7145 |
|
| 7146 |
|
| 7147 |
|
| 7148 |
|
| 7149 |
boolean isViewTransitioning(View view) { |
| 7150 |
return (mTransitioningViews != null && mTransitioningViews.contains(view)); |
| 7151 |
} |
| 7152 |
|
| 7153 |
|
| 7154 |
|
| 7155 |
|
| 7156 |
|
| 7157 |
|
| 7158 |
|
| 7159 |
|
| 7160 |
|
| 7161 |
|
| 7162 |
|
| 7163 |
|
| 7164 |
|
| 7165 |
public void startViewTransition(View view) { |
| 7166 |
if (view.mParent == this) { |
| 7167 |
if (mTransitioningViews == null) { |
| 7168 |
mTransitioningViews = new ArrayList<View>(); |
| 7169 |
} |
| 7170 |
mTransitioningViews.add(view); |
| 7171 |
} |
| 7172 |
} |
| 7173 |
|
| 7174 |
|
| 7175 |
|
| 7176 |
|
| 7177 |
|
| 7178 |
|
| 7179 |
|
| 7180 |
|
| 7181 |
|
| 7182 |
|
| 7183 |
|
| 7184 |
public void endViewTransition(View view) { |
| 7185 |
if (mTransitioningViews != null) { |
| 7186 |
mTransitioningViews.remove(view); |
| 7187 |
final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 7188 |
if (disappearingChildren != null && disappearingChildren.contains(view)) { |
| 7189 |
disappearingChildren.remove(view); |
| 7190 |
if (mVisibilityChangingChildren != null && |
| 7191 |
mVisibilityChangingChildren.contains(view)) { |
| 7192 |
mVisibilityChangingChildren.remove(view); |
| 7193 |
} else { |
| 7194 |
if (view.mAttachInfo != null) { |
| 7195 |
view.dispatchDetachedFromWindow(); |
| 7196 |
} |
| 7197 |
if (view.mParent != null) { |
| 7198 |
view.mParent = null; |
| 7199 |
} |
| 7200 |
} |
| 7201 |
invalidate(); |
| 7202 |
} |
| 7203 |
} |
| 7204 |
} |
| 7205 |
|
| 7206 |
private LayoutTransition.TransitionListener mLayoutTransitionListener = |
| 7207 |
new LayoutTransition.TransitionListener() { |
| 7208 |
@Override |
| 7209 |
public void startTransition(LayoutTransition transition, ViewGroup container, |
| 7210 |
View view, int transitionType) { |
| 7211 |
|
| 7212 |
|
| 7213 |
if (transitionType == LayoutTransition.DISAPPEARING) { |
| 7214 |
startViewTransition(view); |
| 7215 |
} |
| 7216 |
} |
| 7217 |
|
| 7218 |
@Override |
| 7219 |
public void endTransition(LayoutTransition transition, ViewGroup container, |
| 7220 |
View view, int transitionType) { |
| 7221 |
if (mLayoutCalledWhileSuppressed && !transition.isChangingLayout()) { |
| 7222 |
requestLayout(); |
| 7223 |
mLayoutCalledWhileSuppressed = false; |
| 7224 |
} |
| 7225 |
if (transitionType == LayoutTransition.DISAPPEARING && mTransitioningViews != null) { |
| 7226 |
endViewTransition(view); |
| 7227 |
} |
| 7228 |
} |
| 7229 |
}; |
| 7230 |
|
| 7231 |
|
| 7232 |
|
| 7233 |
|
| 7234 |
|
| 7235 |
|
| 7236 |
|
| 7237 |
public void suppressLayout(boolean suppress) { |
| 7238 |
mSuppressLayout = suppress; |
| 7239 |
if (!suppress) { |
| 7240 |
if (mLayoutCalledWhileSuppressed) { |
| 7241 |
requestLayout(); |
| 7242 |
mLayoutCalledWhileSuppressed = false; |
| 7243 |
} |
| 7244 |
} |
| 7245 |
} |
| 7246 |
|
| 7247 |
|
| 7248 |
|
| 7249 |
|
| 7250 |
|
| 7251 |
|
| 7252 |
|
| 7253 |
public boolean isLayoutSuppressed() { |
| 7254 |
return mSuppressLayout; |
| 7255 |
} |
| 7256 |
|
| 7257 |
@Override |
| 7258 |
public boolean gatherTransparentRegion(Region region) { |
| 7259 |
|
| 7260 |
final boolean meOpaque = (mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0; |
| 7261 |
if (meOpaque && region == null) { |
| 7262 |
|
| 7263 |
return true; |
| 7264 |
} |
| 7265 |
super.gatherTransparentRegion(region); |
| 7266 |
|
| 7267 |
|
| 7268 |
|
| 7269 |
|
| 7270 |
|
| 7271 |
final int childrenCount = mChildrenCount; |
| 7272 |
boolean noneOfTheChildrenAreTransparent = true; |
| 7273 |
if (childrenCount > 0) { |
| 7274 |
final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 7275 |
final boolean customOrder = preorderedList == null |
| 7276 |
&& isChildrenDrawingOrderEnabled(); |
| 7277 |
final View[] children = mChildren; |
| 7278 |
for (int i = 0; i < childrenCount; i++) { |
| 7279 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 7280 |
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 7281 |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) { |
| 7282 |
if (!child.gatherTransparentRegion(region)) { |
| 7283 |
noneOfTheChildrenAreTransparent = false; |
| 7284 |
} |
| 7285 |
} |
| 7286 |
} |
| 7287 |
if (preorderedList != null) preorderedList.clear(); |
| 7288 |
} |
| 7289 |
return meOpaque || noneOfTheChildrenAreTransparent; |
| 7290 |
} |
| 7291 |
|
| 7292 |
@Override |
| 7293 |
public void requestTransparentRegion(View child) { |
| 7294 |
if (child != null) { |
| 7295 |
child.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
| 7296 |
if (mParent != null) { |
| 7297 |
mParent.requestTransparentRegion(this); |
| 7298 |
} |
| 7299 |
} |
| 7300 |
} |
| 7301 |
|
| 7302 |
|
| 7303 |
|
| 7304 |
|
| 7305 |
@Override |
| 7306 |
public void subtractObscuredTouchableRegion(Region touchableRegion, View view) { |
| 7307 |
final int childrenCount = mChildrenCount; |
| 7308 |
final ArrayList<View> preorderedList = buildTouchDispatchChildList(); |
| 7309 |
final boolean customOrder = preorderedList == null && isChildrenDrawingOrderEnabled(); |
| 7310 |
final View[] children = mChildren; |
| 7311 |
for (int i = childrenCount - 1; i >= 0; i--) { |
| 7312 |
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 7313 |
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 7314 |
if (child == view) { |
| 7315 |
|
| 7316 |
break; |
| 7317 |
} |
| 7318 |
if (!child.canReceivePointerEvents()) { |
| 7319 |
|
| 7320 |
continue; |
| 7321 |
} |
| 7322 |
applyOpToRegionByBounds(touchableRegion, child, Region.Op.DIFFERENCE); |
| 7323 |
} |
| 7324 |
|
| 7325 |
|
| 7326 |
applyOpToRegionByBounds(touchableRegion, this, Region.Op.INTERSECT); |
| 7327 |
|
| 7328 |
final ViewParent parent = getParent(); |
| 7329 |
if (parent != null) { |
| 7330 |
parent.subtractObscuredTouchableRegion(touchableRegion, this); |
| 7331 |
} |
| 7332 |
} |
| 7333 |
|
| 7334 |
private static void applyOpToRegionByBounds(Region region, View view, Region.Op op) { |
| 7335 |
final int[] locationInWindow = new int[2]; |
| 7336 |
view.getLocationInWindow(locationInWindow); |
| 7337 |
final int x = locationInWindow[0]; |
| 7338 |
final int y = locationInWindow[1]; |
| 7339 |
region.op(x, y, x + view.getWidth(), y + view.getHeight(), op); |
| 7340 |
} |
| 7341 |
|
| 7342 |
@Override |
| 7343 |
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { |
| 7344 |
insets = super.dispatchApplyWindowInsets(insets); |
| 7345 |
if (insets.isConsumed()) { |
| 7346 |
return insets; |
| 7347 |
} |
| 7348 |
if (View.sBrokenInsetsDispatch) { |
| 7349 |
return brokenDispatchApplyWindowInsets(insets); |
| 7350 |
} else { |
| 7351 |
return newDispatchApplyWindowInsets(insets); |
| 7352 |
} |
| 7353 |
} |
| 7354 |
|
| 7355 |
private WindowInsets brokenDispatchApplyWindowInsets(WindowInsets insets) { |
| 7356 |
final int count = getChildCount(); |
| 7357 |
for (int i = 0; i < count; i++) { |
| 7358 |
insets = getChildAt(i).dispatchApplyWindowInsets(insets); |
| 7359 |
if (insets.isConsumed()) { |
| 7360 |
break; |
| 7361 |
} |
| 7362 |
} |
| 7363 |
return insets; |
| 7364 |
} |
| 7365 |
|
| 7366 |
private WindowInsets newDispatchApplyWindowInsets(WindowInsets insets) { |
| 7367 |
final int count = getChildCount(); |
| 7368 |
for (int i = 0; i < count; i++) { |
| 7369 |
getChildAt(i).dispatchApplyWindowInsets(insets); |
| 7370 |
} |
| 7371 |
return insets; |
| 7372 |
} |
| 7373 |
|
| 7374 |
@Override |
| 7375 |
public void setWindowInsetsAnimationCallback( |
| 7376 |
@Nullable WindowInsetsAnimation.Callback callback) { |
| 7377 |
super.setWindowInsetsAnimationCallback(callback); |
| 7378 |
mInsetsAnimationDispatchMode = callback != null |
| 7379 |
? callback.getDispatchMode() |
| 7380 |
: DISPATCH_MODE_CONTINUE_ON_SUBTREE; |
| 7381 |
} |
| 7382 |
|
| 7383 |
|
| 7384 |
|
| 7385 |
|
| 7386 |
@Override |
| 7387 |
public boolean hasWindowInsetsAnimationCallback() { |
| 7388 |
if (super.hasWindowInsetsAnimationCallback()) { |
| 7389 |
return true; |
| 7390 |
} |
| 7391 |
|
| 7392 |
|
| 7393 |
|
| 7394 |
|
| 7395 |
boolean isOptionalFitSystemWindows = (mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) != 0 |
| 7396 |
|| isFrameworkOptionalFitsSystemWindows(); |
| 7397 |
if (isOptionalFitSystemWindows && mAttachInfo != null |
| 7398 |
&& mAttachInfo.mContentOnApplyWindowInsetsListener != null |
| 7399 |
&& (getWindowSystemUiVisibility() & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 7400 |
return false; |
| 7401 |
} |
| 7402 |
|
| 7403 |
final int count = getChildCount(); |
| 7404 |
for (int i = 0; i < count; i++) { |
| 7405 |
if (getChildAt(i).hasWindowInsetsAnimationCallback()) { |
| 7406 |
return true; |
| 7407 |
} |
| 7408 |
} |
| 7409 |
return false; |
| 7410 |
} |
| 7411 |
|
| 7412 |
@Override |
| 7413 |
public void dispatchWindowInsetsAnimationPrepare( |
| 7414 |
@NonNull WindowInsetsAnimation animation) { |
| 7415 |
super.dispatchWindowInsetsAnimationPrepare(animation); |
| 7416 |
|
| 7417 |
|
| 7418 |
|
| 7419 |
boolean isOptionalFitSystemWindows = (mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) != 0 |
| 7420 |
|| isFrameworkOptionalFitsSystemWindows(); |
| 7421 |
if (isOptionalFitSystemWindows && mAttachInfo != null |
| 7422 |
&& getListenerInfo().mWindowInsetsAnimationCallback == null |
| 7423 |
&& mAttachInfo.mContentOnApplyWindowInsetsListener != null |
| 7424 |
&& (getWindowSystemUiVisibility() & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 7425 |
mInsetsAnimationDispatchMode = DISPATCH_MODE_STOP; |
| 7426 |
return; |
| 7427 |
} |
| 7428 |
|
| 7429 |
if (mInsetsAnimationDispatchMode == DISPATCH_MODE_STOP) { |
| 7430 |
return; |
| 7431 |
} |
| 7432 |
final int count = getChildCount(); |
| 7433 |
for (int i = 0; i < count; i++) { |
| 7434 |
getChildAt(i).dispatchWindowInsetsAnimationPrepare(animation); |
| 7435 |
} |
| 7436 |
} |
| 7437 |
|
| 7438 |
@Override |
| 7439 |
@NonNull |
| 7440 |
public Bounds dispatchWindowInsetsAnimationStart( |
| 7441 |
@NonNull WindowInsetsAnimation animation, @NonNull Bounds bounds) { |
| 7442 |
bounds = super.dispatchWindowInsetsAnimationStart(animation, bounds); |
| 7443 |
if (mInsetsAnimationDispatchMode == DISPATCH_MODE_STOP) { |
| 7444 |
return bounds; |
| 7445 |
} |
| 7446 |
final int count = getChildCount(); |
| 7447 |
for (int i = 0; i < count; i++) { |
| 7448 |
getChildAt(i).dispatchWindowInsetsAnimationStart(animation, bounds); |
| 7449 |
} |
| 7450 |
return bounds; |
| 7451 |
} |
| 7452 |
|
| 7453 |
@Override |
| 7454 |
@NonNull |
| 7455 |
public WindowInsets dispatchWindowInsetsAnimationProgress(@NonNull WindowInsets insets, |
| 7456 |
@NonNull List<WindowInsetsAnimation> runningAnimations) { |
| 7457 |
insets = super.dispatchWindowInsetsAnimationProgress(insets, runningAnimations); |
| 7458 |
if (mInsetsAnimationDispatchMode == DISPATCH_MODE_STOP) { |
| 7459 |
return insets; |
| 7460 |
} |
| 7461 |
final int count = getChildCount(); |
| 7462 |
for (int i = 0; i < count; i++) { |
| 7463 |
getChildAt(i).dispatchWindowInsetsAnimationProgress(insets, runningAnimations); |
| 7464 |
} |
| 7465 |
return insets; |
| 7466 |
} |
| 7467 |
|
| 7468 |
@Override |
| 7469 |
public void dispatchWindowInsetsAnimationEnd(@NonNull WindowInsetsAnimation animation) { |
| 7470 |
super.dispatchWindowInsetsAnimationEnd(animation); |
| 7471 |
if (mInsetsAnimationDispatchMode == DISPATCH_MODE_STOP) { |
| 7472 |
return; |
| 7473 |
} |
| 7474 |
final int count = getChildCount(); |
| 7475 |
for (int i = 0; i < count; i++) { |
| 7476 |
getChildAt(i).dispatchWindowInsetsAnimationEnd(animation); |
| 7477 |
} |
| 7478 |
} |
| 7479 |
|
| 7480 |
|
| 7481 |
|
| 7482 |
|
| 7483 |
|
| 7484 |
|
| 7485 |
|
| 7486 |
|
| 7487 |
|
| 7488 |
|
| 7489 |
|
| 7490 |
|
| 7491 |
@Override |
| 7492 |
public void dispatchScrollCaptureSearch( |
| 7493 |
@NonNull Rect localVisibleRect, @NonNull Point windowOffset, |
| 7494 |
@NonNull Consumer<ScrollCaptureTarget> targets) { |
| 7495 |
|
| 7496 |
if (getClipToPadding() && !localVisibleRect.intersect(mPaddingLeft, mPaddingTop, |
| 7497 |
(mRight - mLeft) - mPaddingRight, (mBottom - mTop) - mPaddingBottom)) { |
| 7498 |
return; |
| 7499 |
} |
| 7500 |
|
| 7501 |
|
| 7502 |
super.dispatchScrollCaptureSearch(localVisibleRect, windowOffset, targets); |
| 7503 |
|
| 7504 |
|
| 7505 |
if ((getScrollCaptureHint() & SCROLL_CAPTURE_HINT_EXCLUDE_DESCENDANTS) != 0) { |
| 7506 |
return; |
| 7507 |
} |
| 7508 |
|
| 7509 |
final Rect tmpRect = getTempRect(); |
| 7510 |
final int childCount = getChildCount(); |
| 7511 |
for (int i = 0; i < childCount; i++) { |
| 7512 |
View child = getChildAt(i); |
| 7513 |
|
| 7514 |
if (child.getVisibility() != View.VISIBLE) { |
| 7515 |
continue; |
| 7516 |
} |
| 7517 |
|
| 7518 |
|
| 7519 |
|
| 7520 |
|
| 7521 |
|
| 7522 |
tmpRect.set(localVisibleRect); |
| 7523 |
|
| 7524 |
|
| 7525 |
final Point childWindowOffset = getTempPoint(); |
| 7526 |
childWindowOffset.set(windowOffset.x, windowOffset.y); |
| 7527 |
|
| 7528 |
final int dx = child.mLeft - mScrollX; |
| 7529 |
final int dy = child.mTop - mScrollY; |
| 7530 |
|
| 7531 |
tmpRect.offset(-dx, -dy); |
| 7532 |
childWindowOffset.offset(dx, dy); |
| 7533 |
|
| 7534 |
boolean rectIsVisible = true; |
| 7535 |
|
| 7536 |
|
| 7537 |
if (getClipChildren()) { |
| 7538 |
rectIsVisible = tmpRect.intersect(0, 0, child.getWidth(), child.getHeight()); |
| 7539 |
} |
| 7540 |
|
| 7541 |
if (rectIsVisible) { |
| 7542 |
child.dispatchScrollCaptureSearch(tmpRect, childWindowOffset, targets); |
| 7543 |
} |
| 7544 |
} |
| 7545 |
} |
| 7546 |
|
| 7547 |
|
| 7548 |
|
| 7549 |
|
| 7550 |
|
| 7551 |
|
| 7552 |
|
| 7553 |
public Animation.AnimationListener getLayoutAnimationListener() { |
| 7554 |
return mAnimationListener; |
| 7555 |
} |
| 7556 |
|
| 7557 |
@Override |
| 7558 |
protected void drawableStateChanged() { |
| 7559 |
super.drawableStateChanged(); |
| 7560 |
|
| 7561 |
if ((mGroupFlags & FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE) != 0) { |
| 7562 |
if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0) { |
| 7563 |
throw new IllegalStateException("addStateFromChildren cannot be enabled if a" |
| 7564 |
+ " child has duplicateParentState set to true"); |
| 7565 |
} |
| 7566 |
|
| 7567 |
final View[] children = mChildren; |
| 7568 |
final int count = mChildrenCount; |
| 7569 |
|
| 7570 |
for (int i = 0; i < count; i++) { |
| 7571 |
final View child = children[i]; |
| 7572 |
if ((child.mViewFlags & DUPLICATE_PARENT_STATE) != 0) { |
| 7573 |
child.refreshDrawableState(); |
| 7574 |
} |
| 7575 |
} |
| 7576 |
} |
| 7577 |
} |
| 7578 |
|
| 7579 |
@Override |
| 7580 |
public void jumpDrawablesToCurrentState() { |
| 7581 |
super.jumpDrawablesToCurrentState(); |
| 7582 |
final View[] children = mChildren; |
| 7583 |
final int count = mChildrenCount; |
| 7584 |
for (int i = 0; i < count; i++) { |
| 7585 |
children[i].jumpDrawablesToCurrentState(); |
| 7586 |
} |
| 7587 |
} |
| 7588 |
|
| 7589 |
@Override |
| 7590 |
protected int[] onCreateDrawableState(int extraSpace) { |
| 7591 |
if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) == 0) { |
| 7592 |
return super.onCreateDrawableState(extraSpace); |
| 7593 |
} |
| 7594 |
|
| 7595 |
int need = 0; |
| 7596 |
int n = getChildCount(); |
| 7597 |
for (int i = 0; i < n; i++) { |
| 7598 |
int[] childState = getChildAt(i).getDrawableState(); |
| 7599 |
|
| 7600 |
if (childState != null) { |
| 7601 |
need += childState.length; |
| 7602 |
} |
| 7603 |
} |
| 7604 |
|
| 7605 |
int[] state = super.onCreateDrawableState(extraSpace + need); |
| 7606 |
|
| 7607 |
for (int i = 0; i < n; i++) { |
| 7608 |
int[] childState = getChildAt(i).getDrawableState(); |
| 7609 |
|
| 7610 |
if (childState != null) { |
| 7611 |
state = mergeDrawableStates(state, childState); |
| 7612 |
} |
| 7613 |
} |
| 7614 |
|
| 7615 |
return state; |
| 7616 |
} |
| 7617 |
|
| 7618 |
|
| 7619 |
|
| 7620 |
|
| 7621 |
|
| 7622 |
|
| 7623 |
|
| 7624 |
public void setAddStatesFromChildren(boolean addsStates) { |
| 7625 |
if (addsStates) { |
| 7626 |
mGroupFlags |= FLAG_ADD_STATES_FROM_CHILDREN; |
| 7627 |
} else { |
| 7628 |
mGroupFlags &= ~FLAG_ADD_STATES_FROM_CHILDREN; |
| 7629 |
} |
| 7630 |
|
| 7631 |
refreshDrawableState(); |
| 7632 |
} |
| 7633 |
|
| 7634 |
|
| 7635 |
|
| 7636 |
|
| 7637 |
|
| 7638 |
|
| 7639 |
|
| 7640 |
@InspectableProperty |
| 7641 |
public boolean addStatesFromChildren() { |
| 7642 |
return (mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0; |
| 7643 |
} |
| 7644 |
|
| 7645 |
|
| 7646 |
|
| 7647 |
|
| 7648 |
|
| 7649 |
@Override |
| 7650 |
public void childDrawableStateChanged(View child) { |
| 7651 |
if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0) { |
| 7652 |
refreshDrawableState(); |
| 7653 |
} |
| 7654 |
} |
| 7655 |
|
| 7656 |
|
| 7657 |
|
| 7658 |
|
| 7659 |
|
| 7660 |
|
| 7661 |
|
| 7662 |
|
| 7663 |
|
| 7664 |
|
| 7665 |
|
| 7666 |
public void setLayoutAnimationListener(Animation.AnimationListener animationListener) { |
| 7667 |
mAnimationListener = animationListener; |
| 7668 |
} |
| 7669 |
|
| 7670 |
|
| 7671 |
|
| 7672 |
|
| 7673 |
|
| 7674 |
|
| 7675 |
|
| 7676 |
|
| 7677 |
|
| 7678 |
|
| 7679 |
public void requestTransitionStart(LayoutTransition transition) { |
| 7680 |
ViewRootImpl viewAncestor = getViewRootImpl(); |
| 7681 |
if (viewAncestor != null) { |
| 7682 |
viewAncestor.requestTransitionStart(transition); |
| 7683 |
} |
| 7684 |
} |
| 7685 |
|
| 7686 |
|
| 7687 |
|
| 7688 |
|
| 7689 |
@Override |
| 7690 |
public boolean resolveRtlPropertiesIfNeeded() { |
| 7691 |
final boolean result = super.resolveRtlPropertiesIfNeeded(); |
| 7692 |
|
| 7693 |
if (result) { |
| 7694 |
int count = getChildCount(); |
| 7695 |
for (int i = 0; i < count; i++) { |
| 7696 |
final View child = getChildAt(i); |
| 7697 |
if (child.isLayoutDirectionInherited()) { |
| 7698 |
child.resolveRtlPropertiesIfNeeded(); |
| 7699 |
} |
| 7700 |
} |
| 7701 |
} |
| 7702 |
return result; |
| 7703 |
} |
| 7704 |
|
| 7705 |
|
| 7706 |
|
| 7707 |
|
| 7708 |
@Override |
| 7709 |
public boolean resolveLayoutDirection() { |
| 7710 |
final boolean result = super.resolveLayoutDirection(); |
| 7711 |
if (result) { |
| 7712 |
int count = getChildCount(); |
| 7713 |
for (int i = 0; i < count; i++) { |
| 7714 |
final View child = getChildAt(i); |
| 7715 |
if (child.isLayoutDirectionInherited()) { |
| 7716 |
child.resolveLayoutDirection(); |
| 7717 |
} |
| 7718 |
} |
| 7719 |
} |
| 7720 |
return result; |
| 7721 |
} |
| 7722 |
|
| 7723 |
|
| 7724 |
|
| 7725 |
|
| 7726 |
@Override |
| 7727 |
public boolean resolveTextDirection() { |
| 7728 |
final boolean result = super.resolveTextDirection(); |
| 7729 |
if (result) { |
| 7730 |
int count = getChildCount(); |
| 7731 |
for (int i = 0; i < count; i++) { |
| 7732 |
final View child = getChildAt(i); |
| 7733 |
if (child.isTextDirectionInherited()) { |
| 7734 |
child.resolveTextDirection(); |
| 7735 |
} |
| 7736 |
} |
| 7737 |
} |
| 7738 |
return result; |
| 7739 |
} |
| 7740 |
|
| 7741 |
|
| 7742 |
|
| 7743 |
|
| 7744 |
@Override |
| 7745 |
public boolean resolveTextAlignment() { |
| 7746 |
final boolean result = super.resolveTextAlignment(); |
| 7747 |
if (result) { |
| 7748 |
int count = getChildCount(); |
| 7749 |
for (int i = 0; i < count; i++) { |
| 7750 |
final View child = getChildAt(i); |
| 7751 |
if (child.isTextAlignmentInherited()) { |
| 7752 |
child.resolveTextAlignment(); |
| 7753 |
} |
| 7754 |
} |
| 7755 |
} |
| 7756 |
return result; |
| 7757 |
} |
| 7758 |
|
| 7759 |
|
| 7760 |
|
| 7761 |
|
| 7762 |
@Override |
| 7763 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 7764 |
public void resolvePadding() { |
| 7765 |
super.resolvePadding(); |
| 7766 |
int count = getChildCount(); |
| 7767 |
for (int i = 0; i < count; i++) { |
| 7768 |
final View child = getChildAt(i); |
| 7769 |
if (child.isLayoutDirectionInherited() && !child.isPaddingResolved()) { |
| 7770 |
child.resolvePadding(); |
| 7771 |
} |
| 7772 |
} |
| 7773 |
} |
| 7774 |
|
| 7775 |
|
| 7776 |
|
| 7777 |
|
| 7778 |
@Override |
| 7779 |
protected void resolveDrawables() { |
| 7780 |
super.resolveDrawables(); |
| 7781 |
int count = getChildCount(); |
| 7782 |
for (int i = 0; i < count; i++) { |
| 7783 |
final View child = getChildAt(i); |
| 7784 |
if (child.isLayoutDirectionInherited() && !child.areDrawablesResolved()) { |
| 7785 |
child.resolveDrawables(); |
| 7786 |
} |
| 7787 |
} |
| 7788 |
} |
| 7789 |
|
| 7790 |
|
| 7791 |
|
| 7792 |
|
| 7793 |
@Override |
| 7794 |
public void resolveLayoutParams() { |
| 7795 |
super.resolveLayoutParams(); |
| 7796 |
int count = getChildCount(); |
| 7797 |
for (int i = 0; i < count; i++) { |
| 7798 |
final View child = getChildAt(i); |
| 7799 |
child.resolveLayoutParams(); |
| 7800 |
} |
| 7801 |
} |
| 7802 |
|
| 7803 |
|
| 7804 |
|
| 7805 |
|
| 7806 |
@TestApi |
| 7807 |
@Override |
| 7808 |
public void resetResolvedLayoutDirection() { |
| 7809 |
super.resetResolvedLayoutDirection(); |
| 7810 |
|
| 7811 |
int count = getChildCount(); |
| 7812 |
for (int i = 0; i < count; i++) { |
| 7813 |
final View child = getChildAt(i); |
| 7814 |
if (child.isLayoutDirectionInherited()) { |
| 7815 |
child.resetResolvedLayoutDirection(); |
| 7816 |
} |
| 7817 |
} |
| 7818 |
} |
| 7819 |
|
| 7820 |
|
| 7821 |
|
| 7822 |
|
| 7823 |
@TestApi |
| 7824 |
@Override |
| 7825 |
public void resetResolvedTextDirection() { |
| 7826 |
super.resetResolvedTextDirection(); |
| 7827 |
|
| 7828 |
int count = getChildCount(); |
| 7829 |
for (int i = 0; i < count; i++) { |
| 7830 |
final View child = getChildAt(i); |
| 7831 |
if (child.isTextDirectionInherited()) { |
| 7832 |
child.resetResolvedTextDirection(); |
| 7833 |
} |
| 7834 |
} |
| 7835 |
} |
| 7836 |
|
| 7837 |
|
| 7838 |
|
| 7839 |
|
| 7840 |
@TestApi |
| 7841 |
@Override |
| 7842 |
public void resetResolvedTextAlignment() { |
| 7843 |
super.resetResolvedTextAlignment(); |
| 7844 |
|
| 7845 |
int count = getChildCount(); |
| 7846 |
for (int i = 0; i < count; i++) { |
| 7847 |
final View child = getChildAt(i); |
| 7848 |
if (child.isTextAlignmentInherited()) { |
| 7849 |
child.resetResolvedTextAlignment(); |
| 7850 |
} |
| 7851 |
} |
| 7852 |
} |
| 7853 |
|
| 7854 |
|
| 7855 |
|
| 7856 |
|
| 7857 |
@TestApi |
| 7858 |
@Override |
| 7859 |
public void resetResolvedPadding() { |
| 7860 |
super.resetResolvedPadding(); |
| 7861 |
|
| 7862 |
int count = getChildCount(); |
| 7863 |
for (int i = 0; i < count; i++) { |
| 7864 |
final View child = getChildAt(i); |
| 7865 |
if (child.isLayoutDirectionInherited()) { |
| 7866 |
child.resetResolvedPadding(); |
| 7867 |
} |
| 7868 |
} |
| 7869 |
} |
| 7870 |
|
| 7871 |
|
| 7872 |
|
| 7873 |
|
| 7874 |
@TestApi |
| 7875 |
@Override |
| 7876 |
protected void resetResolvedDrawables() { |
| 7877 |
super.resetResolvedDrawables(); |
| 7878 |
|
| 7879 |
int count = getChildCount(); |
| 7880 |
for (int i = 0; i < count; i++) { |
| 7881 |
final View child = getChildAt(i); |
| 7882 |
if (child.isLayoutDirectionInherited()) { |
| 7883 |
child.resetResolvedDrawables(); |
| 7884 |
} |
| 7885 |
} |
| 7886 |
} |
| 7887 |
|
| 7888 |
|
| 7889 |
|
| 7890 |
|
| 7891 |
|
| 7892 |
|
| 7893 |
|
| 7894 |
|
| 7895 |
|
| 7896 |
|
| 7897 |
public boolean shouldDelayChildPressedState() { |
| 7898 |
return true; |
| 7899 |
} |
| 7900 |
|
| 7901 |
|
| 7902 |
|
| 7903 |
|
| 7904 |
@Override |
| 7905 |
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 7906 |
return false; |
| 7907 |
} |
| 7908 |
|
| 7909 |
|
| 7910 |
|
| 7911 |
|
| 7912 |
@Override |
| 7913 |
public void onNestedScrollAccepted(View child, View target, int axes) { |
| 7914 |
mNestedScrollAxes = axes; |
| 7915 |
} |
| 7916 |
|
| 7917 |
|
| 7918 |
|
| 7919 |
|
| 7920 |
|
| 7921 |
|
| 7922 |
|
| 7923 |
@Override |
| 7924 |
public void onStopNestedScroll(View child) { |
| 7925 |
|
| 7926 |
stopNestedScroll(); |
| 7927 |
mNestedScrollAxes = 0; |
| 7928 |
} |
| 7929 |
|
| 7930 |
|
| 7931 |
|
| 7932 |
|
| 7933 |
@Override |
| 7934 |
public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 7935 |
int dxUnconsumed, int dyUnconsumed) { |
| 7936 |
|
| 7937 |
dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null); |
| 7938 |
} |
| 7939 |
|
| 7940 |
|
| 7941 |
|
| 7942 |
|
| 7943 |
@Override |
| 7944 |
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 7945 |
|
| 7946 |
dispatchNestedPreScroll(dx, dy, consumed, null); |
| 7947 |
} |
| 7948 |
|
| 7949 |
|
| 7950 |
|
| 7951 |
|
| 7952 |
@Override |
| 7953 |
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
| 7954 |
|
| 7955 |
return dispatchNestedFling(velocityX, velocityY, consumed); |
| 7956 |
} |
| 7957 |
|
| 7958 |
|
| 7959 |
|
| 7960 |
|
| 7961 |
@Override |
| 7962 |
public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 7963 |
|
| 7964 |
return dispatchNestedPreFling(velocityX, velocityY); |
| 7965 |
} |
| 7966 |
|
| 7967 |
|
| 7968 |
|
| 7969 |
|
| 7970 |
|
| 7971 |
|
| 7972 |
|
| 7973 |
|
| 7974 |
|
| 7975 |
|
| 7976 |
|
| 7977 |
|
| 7978 |
public int getNestedScrollAxes() { |
| 7979 |
return mNestedScrollAxes; |
| 7980 |
} |
| 7981 |
|
| 7982 |
|
| 7983 |
protected void onSetLayoutParams(View child, LayoutParams layoutParams) { |
| 7984 |
requestLayout(); |
| 7985 |
} |
| 7986 |
|
| 7987 |
|
| 7988 |
@Override |
| 7989 |
public void captureTransitioningViews(List<View> transitioningViews) { |
| 7990 |
if (getVisibility() != View.VISIBLE) { |
| 7991 |
return; |
| 7992 |
} |
| 7993 |
if (isTransitionGroup()) { |
| 7994 |
transitioningViews.add(this); |
| 7995 |
} else { |
| 7996 |
int count = getChildCount(); |
| 7997 |
for (int i = 0; i < count; i++) { |
| 7998 |
View child = getChildAt(i); |
| 7999 |
child.captureTransitioningViews(transitioningViews); |
| 8000 |
} |
| 8001 |
} |
| 8002 |
} |
| 8003 |
|
| 8004 |
|
| 8005 |
@Override |
| 8006 |
public void findNamedViews(Map<String, View> namedElements) { |
| 8007 |
if (getVisibility() != VISIBLE && mGhostView == null) { |
| 8008 |
return; |
| 8009 |
} |
| 8010 |
super.findNamedViews(namedElements); |
| 8011 |
int count = getChildCount(); |
| 8012 |
for (int i = 0; i < count; i++) { |
| 8013 |
View child = getChildAt(i); |
| 8014 |
child.findNamedViews(namedElements); |
| 8015 |
} |
| 8016 |
} |
| 8017 |
|
| 8018 |
@Override |
| 8019 |
boolean hasUnhandledKeyListener() { |
| 8020 |
return (mChildUnhandledKeyListeners > 0) || super.hasUnhandledKeyListener(); |
| 8021 |
} |
| 8022 |
|
| 8023 |
void incrementChildUnhandledKeyListeners() { |
| 8024 |
mChildUnhandledKeyListeners += 1; |
| 8025 |
if (mChildUnhandledKeyListeners == 1) { |
| 8026 |
if (mParent instanceof ViewGroup) { |
| 8027 |
((ViewGroup) mParent).incrementChildUnhandledKeyListeners(); |
| 8028 |
} |
| 8029 |
} |
| 8030 |
} |
| 8031 |
|
| 8032 |
void decrementChildUnhandledKeyListeners() { |
| 8033 |
mChildUnhandledKeyListeners -= 1; |
| 8034 |
if (mChildUnhandledKeyListeners == 0) { |
| 8035 |
if (mParent instanceof ViewGroup) { |
| 8036 |
((ViewGroup) mParent).decrementChildUnhandledKeyListeners(); |
| 8037 |
} |
| 8038 |
} |
| 8039 |
} |
| 8040 |
|
| 8041 |
@Override |
| 8042 |
View dispatchUnhandledKeyEvent(KeyEvent evt) { |
| 8043 |
if (!hasUnhandledKeyListener()) { |
| 8044 |
return null; |
| 8045 |
} |
| 8046 |
ArrayList<View> orderedViews = buildOrderedChildList(); |
| 8047 |
if (orderedViews != null) { |
| 8048 |
try { |
| 8049 |
for (int i = orderedViews.size() - 1; i >= 0; --i) { |
| 8050 |
View v = orderedViews.get(i); |
| 8051 |
View consumer = v.dispatchUnhandledKeyEvent(evt); |
| 8052 |
if (consumer != null) { |
| 8053 |
return consumer; |
| 8054 |
} |
| 8055 |
} |
| 8056 |
} finally { |
| 8057 |
orderedViews.clear(); |
| 8058 |
} |
| 8059 |
} else { |
| 8060 |
for (int i = getChildCount() - 1; i >= 0; --i) { |
| 8061 |
View v = getChildAt(i); |
| 8062 |
View consumer = v.dispatchUnhandledKeyEvent(evt); |
| 8063 |
if (consumer != null) { |
| 8064 |
return consumer; |
| 8065 |
} |
| 8066 |
} |
| 8067 |
} |
| 8068 |
if (onUnhandledKeyEvent(evt)) { |
| 8069 |
return this; |
| 8070 |
} |
| 8071 |
return null; |
| 8072 |
} |
| 8073 |
|
| 8074 |
|
| 8075 |
|
| 8076 |
|
| 8077 |
|
| 8078 |
|
| 8079 |
|
| 8080 |
|
| 8081 |
|
| 8082 |
|
| 8083 |
|
| 8084 |
|
| 8085 |
|
| 8086 |
|
| 8087 |
|
| 8088 |
|
| 8089 |
|
| 8090 |
|
| 8091 |
|
| 8092 |
|
| 8093 |
|
| 8094 |
|
| 8095 |
|
| 8096 |
|
| 8097 |
|
| 8098 |
|
| 8099 |
|
| 8100 |
|
| 8101 |
|
| 8102 |
|
| 8103 |
public static class LayoutParams { |
| 8104 |
|
| 8105 |
|
| 8106 |
|
| 8107 |
|
| 8108 |
|
| 8109 |
|
| 8110 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 8111 |
@Deprecated |
| 8112 |
public static final int FILL_PARENT = -1; |
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
|
| 8117 |
|
| 8118 |
|
| 8119 |
public static final int MATCH_PARENT = -1; |
| 8120 |
|
| 8121 |
|
| 8122 |
|
| 8123 |
|
| 8124 |
|
| 8125 |
|
| 8126 |
public static final int WRAP_CONTENT = -2; |
| 8127 |
|
| 8128 |
|
| 8129 |
|
| 8130 |
|
| 8131 |
|
| 8132 |
|
| 8133 |
@ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 8134 |
@ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"), |
| 8135 |
@ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT") |
| 8136 |
}) |
| 8137 |
@InspectableProperty(name = "layout_width", enumMapping = { |
| 8138 |
@EnumEntry(name = "match_parent", value = MATCH_PARENT), |
| 8139 |
@EnumEntry(name = "wrap_content", value = WRAP_CONTENT) |
| 8140 |
}) |
| 8141 |
public int width; |
| 8142 |
|
| 8143 |
|
| 8144 |
|
| 8145 |
|
| 8146 |
|
| 8147 |
|
| 8148 |
@ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 8149 |
@ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"), |
| 8150 |
@ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT") |
| 8151 |
}) |
| 8152 |
@InspectableProperty(name = "layout_height", enumMapping = { |
| 8153 |
@EnumEntry(name = "match_parent", value = MATCH_PARENT), |
| 8154 |
@EnumEntry(name = "wrap_content", value = WRAP_CONTENT) |
| 8155 |
}) |
| 8156 |
public int height; |
| 8157 |
|
| 8158 |
|
| 8159 |
|
| 8160 |
|
| 8161 |
public LayoutAnimationController.AnimationParameters layoutAnimationParameters; |
| 8162 |
|
| 8163 |
|
| 8164 |
|
| 8165 |
|
| 8166 |
|
| 8167 |
|
| 8168 |
|
| 8169 |
|
| 8170 |
|
| 8171 |
|
| 8172 |
|
| 8173 |
|
| 8174 |
|
| 8175 |
|
| 8176 |
|
| 8177 |
|
| 8178 |
|
| 8179 |
|
| 8180 |
|
| 8181 |
public LayoutParams(Context c, AttributeSet attrs) { |
| 8182 |
TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_Layout); |
| 8183 |
setBaseAttributes(a, |
| 8184 |
R.styleable.ViewGroup_Layout_layout_width, |
| 8185 |
R.styleable.ViewGroup_Layout_layout_height); |
| 8186 |
a.recycle(); |
| 8187 |
} |
| 8188 |
|
| 8189 |
|
| 8190 |
|
| 8191 |
|
| 8192 |
|
| 8193 |
|
| 8194 |
|
| 8195 |
|
| 8196 |
|
| 8197 |
|
| 8198 |
|
| 8199 |
|
| 8200 |
public LayoutParams(int width, int height) { |
| 8201 |
this.width = width; |
| 8202 |
this.height = height; |
| 8203 |
} |
| 8204 |
|
| 8205 |
|
| 8206 |
|
| 8207 |
|
| 8208 |
|
| 8209 |
|
| 8210 |
public LayoutParams(LayoutParams source) { |
| 8211 |
this.width = source.width; |
| 8212 |
this.height = source.height; |
| 8213 |
} |
| 8214 |
|
| 8215 |
|
| 8216 |
|
| 8217 |
|
| 8218 |
|
| 8219 |
@UnsupportedAppUsage |
| 8220 |
LayoutParams() { |
| 8221 |
} |
| 8222 |
|
| 8223 |
|
| 8224 |
|
| 8225 |
|
| 8226 |
|
| 8227 |
|
| 8228 |
|
| 8229 |
|
| 8230 |
protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) { |
| 8231 |
width = a.getLayoutDimension(widthAttr, "layout_width"); |
| 8232 |
height = a.getLayoutDimension(heightAttr, "layout_height"); |
| 8233 |
} |
| 8234 |
|
| 8235 |
|
| 8236 |
|
| 8237 |
|
| 8238 |
|
| 8239 |
|
| 8240 |
|
| 8241 |
|
| 8242 |
|
| 8243 |
|
| 8244 |
|
| 8245 |
public void resolveLayoutDirection(int layoutDirection) { |
| 8246 |
} |
| 8247 |
|
| 8248 |
|
| 8249 |
|
| 8250 |
|
| 8251 |
|
| 8252 |
|
| 8253 |
|
| 8254 |
|
| 8255 |
|
| 8256 |
|
| 8257 |
public String debug(String output) { |
| 8258 |
return output + "ViewGroup.LayoutParams={ width=" |
| 8259 |
+ sizeToString(width) + ", height=" + sizeToString(height) + " }"; |
| 8260 |
} |
| 8261 |
|
| 8262 |
|
| 8263 |
|
| 8264 |
|
| 8265 |
|
| 8266 |
|
| 8267 |
|
| 8268 |
|
| 8269 |
|
| 8270 |
public void onDebugDraw(View view, Canvas canvas, Paint paint) { |
| 8271 |
} |
| 8272 |
|
| 8273 |
|
| 8274 |
|
| 8275 |
|
| 8276 |
|
| 8277 |
|
| 8278 |
|
| 8279 |
|
| 8280 |
|
| 8281 |
protected static String sizeToString(int size) { |
| 8282 |
if (size == WRAP_CONTENT) { |
| 8283 |
return "wrap-content"; |
| 8284 |
} |
| 8285 |
if (size == MATCH_PARENT) { |
| 8286 |
return "match-parent"; |
| 8287 |
} |
| 8288 |
return String.valueOf(size); |
| 8289 |
} |
| 8290 |
|
| 8291 |
|
| 8292 |
void encode(@NonNull ViewHierarchyEncoder encoder) { |
| 8293 |
encoder.beginObject(this); |
| 8294 |
encodeProperties(encoder); |
| 8295 |
encoder.endObject(); |
| 8296 |
} |
| 8297 |
|
| 8298 |
|
| 8299 |
protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 8300 |
encoder.addProperty("width", width); |
| 8301 |
encoder.addProperty("height", height); |
| 8302 |
} |
| 8303 |
} |
| 8304 |
|
| 8305 |
|
| 8306 |
|
| 8307 |
|
| 8308 |
|
| 8309 |
|
| 8310 |
|
| 8311 |
|
| 8312 |
|
| 8313 |
|
| 8314 |
|
| 8315 |
|
| 8316 |
|
| 8317 |
|
| 8318 |
|
| 8319 |
|
| 8320 |
|
| 8321 |
public static class MarginLayoutParams extends ViewGroup.LayoutParams { |
| 8322 |
|
| 8323 |
|
| 8324 |
|
| 8325 |
|
| 8326 |
|
| 8327 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8328 |
@InspectableProperty(name = "layout_marginLeft") |
| 8329 |
public int leftMargin; |
| 8330 |
|
| 8331 |
|
| 8332 |
|
| 8333 |
|
| 8334 |
|
| 8335 |
|
| 8336 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8337 |
@InspectableProperty(name = "layout_marginTop") |
| 8338 |
public int topMargin; |
| 8339 |
|
| 8340 |
|
| 8341 |
|
| 8342 |
|
| 8343 |
|
| 8344 |
|
| 8345 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8346 |
@InspectableProperty(name = "layout_marginRight") |
| 8347 |
public int rightMargin; |
| 8348 |
|
| 8349 |
|
| 8350 |
|
| 8351 |
|
| 8352 |
|
| 8353 |
|
| 8354 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8355 |
@InspectableProperty(name = "layout_marginBottom") |
| 8356 |
public int bottomMargin; |
| 8357 |
|
| 8358 |
|
| 8359 |
|
| 8360 |
|
| 8361 |
|
| 8362 |
|
| 8363 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8364 |
@UnsupportedAppUsage |
| 8365 |
private int startMargin = DEFAULT_MARGIN_RELATIVE; |
| 8366 |
|
| 8367 |
|
| 8368 |
|
| 8369 |
|
| 8370 |
|
| 8371 |
|
| 8372 |
@ViewDebug.ExportedProperty(category = "layout") |
| 8373 |
@UnsupportedAppUsage |
| 8374 |
private int endMargin = DEFAULT_MARGIN_RELATIVE; |
| 8375 |
|
| 8376 |
|
| 8377 |
|
| 8378 |
|
| 8379 |
|
| 8380 |
public static final int DEFAULT_MARGIN_RELATIVE = Integer.MIN_VALUE; |
| 8381 |
|
| 8382 |
|
| 8383 |
|
| 8384 |
|
| 8385 |
|
| 8386 |
|
| 8387 |
|
| 8388 |
|
| 8389 |
|
| 8390 |
|
| 8391 |
|
| 8392 |
|
| 8393 |
|
| 8394 |
@ViewDebug.ExportedProperty(category = "layout", flagMapping = { |
| 8395 |
@ViewDebug.FlagToString(mask = LAYOUT_DIRECTION_MASK, |
| 8396 |
equals = LAYOUT_DIRECTION_MASK, name = "LAYOUT_DIRECTION"), |
| 8397 |
@ViewDebug.FlagToString(mask = LEFT_MARGIN_UNDEFINED_MASK, |
| 8398 |
equals = LEFT_MARGIN_UNDEFINED_MASK, name = "LEFT_MARGIN_UNDEFINED_MASK"), |
| 8399 |
@ViewDebug.FlagToString(mask = RIGHT_MARGIN_UNDEFINED_MASK, |
| 8400 |
equals = RIGHT_MARGIN_UNDEFINED_MASK, name = "RIGHT_MARGIN_UNDEFINED_MASK"), |
| 8401 |
@ViewDebug.FlagToString(mask = RTL_COMPATIBILITY_MODE_MASK, |
| 8402 |
equals = RTL_COMPATIBILITY_MODE_MASK, name = "RTL_COMPATIBILITY_MODE_MASK"), |
| 8403 |
@ViewDebug.FlagToString(mask = NEED_RESOLUTION_MASK, |
| 8404 |
equals = NEED_RESOLUTION_MASK, name = "NEED_RESOLUTION_MASK") |
| 8405 |
}, formatToHexString = true) |
| 8406 |
byte mMarginFlags; |
| 8407 |
|
| 8408 |
private static final int LAYOUT_DIRECTION_MASK = 0x00000003; |
| 8409 |
private static final int LEFT_MARGIN_UNDEFINED_MASK = 0x00000004; |
| 8410 |
private static final int RIGHT_MARGIN_UNDEFINED_MASK = 0x00000008; |
| 8411 |
private static final int RTL_COMPATIBILITY_MODE_MASK = 0x00000010; |
| 8412 |
private static final int NEED_RESOLUTION_MASK = 0x00000020; |
| 8413 |
|
| 8414 |
private static final int DEFAULT_MARGIN_RESOLVED = 0; |
| 8415 |
private static final int UNDEFINED_MARGIN = DEFAULT_MARGIN_RELATIVE; |
| 8416 |
|
| 8417 |
|
| 8418 |
|
| 8419 |
|
| 8420 |
|
| 8421 |
|
| 8422 |
|
| 8423 |
|
| 8424 |
|
| 8425 |
public MarginLayoutParams(Context c, AttributeSet attrs) { |
| 8426 |
super(); |
| 8427 |
|
| 8428 |
TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_MarginLayout); |
| 8429 |
setBaseAttributes(a, |
| 8430 |
R.styleable.ViewGroup_MarginLayout_layout_width, |
| 8431 |
R.styleable.ViewGroup_MarginLayout_layout_height); |
| 8432 |
|
| 8433 |
int margin = a.getDimensionPixelSize( |
| 8434 |
com.android.internal.R.styleable.ViewGroup_MarginLayout_layout_margin, -1); |
| 8435 |
if (margin >= 0) { |
| 8436 |
leftMargin = margin; |
| 8437 |
topMargin = margin; |
| 8438 |
rightMargin= margin; |
| 8439 |
bottomMargin = margin; |
| 8440 |
} else { |
| 8441 |
int horizontalMargin = a.getDimensionPixelSize( |
| 8442 |
R.styleable.ViewGroup_MarginLayout_layout_marginHorizontal, -1); |
| 8443 |
int verticalMargin = a.getDimensionPixelSize( |
| 8444 |
R.styleable.ViewGroup_MarginLayout_layout_marginVertical, -1); |
| 8445 |
|
| 8446 |
if (horizontalMargin >= 0) { |
| 8447 |
leftMargin = horizontalMargin; |
| 8448 |
rightMargin = horizontalMargin; |
| 8449 |
} else { |
| 8450 |
leftMargin = a.getDimensionPixelSize( |
| 8451 |
R.styleable.ViewGroup_MarginLayout_layout_marginLeft, |
| 8452 |
UNDEFINED_MARGIN); |
| 8453 |
if (leftMargin == UNDEFINED_MARGIN) { |
| 8454 |
mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8455 |
leftMargin = DEFAULT_MARGIN_RESOLVED; |
| 8456 |
} |
| 8457 |
rightMargin = a.getDimensionPixelSize( |
| 8458 |
R.styleable.ViewGroup_MarginLayout_layout_marginRight, |
| 8459 |
UNDEFINED_MARGIN); |
| 8460 |
if (rightMargin == UNDEFINED_MARGIN) { |
| 8461 |
mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
| 8462 |
rightMargin = DEFAULT_MARGIN_RESOLVED; |
| 8463 |
} |
| 8464 |
} |
| 8465 |
|
| 8466 |
startMargin = a.getDimensionPixelSize( |
| 8467 |
R.styleable.ViewGroup_MarginLayout_layout_marginStart, |
| 8468 |
DEFAULT_MARGIN_RELATIVE); |
| 8469 |
endMargin = a.getDimensionPixelSize( |
| 8470 |
R.styleable.ViewGroup_MarginLayout_layout_marginEnd, |
| 8471 |
DEFAULT_MARGIN_RELATIVE); |
| 8472 |
|
| 8473 |
if (verticalMargin >= 0) { |
| 8474 |
topMargin = verticalMargin; |
| 8475 |
bottomMargin = verticalMargin; |
| 8476 |
} else { |
| 8477 |
topMargin = a.getDimensionPixelSize( |
| 8478 |
R.styleable.ViewGroup_MarginLayout_layout_marginTop, |
| 8479 |
DEFAULT_MARGIN_RESOLVED); |
| 8480 |
bottomMargin = a.getDimensionPixelSize( |
| 8481 |
R.styleable.ViewGroup_MarginLayout_layout_marginBottom, |
| 8482 |
DEFAULT_MARGIN_RESOLVED); |
| 8483 |
} |
| 8484 |
|
| 8485 |
if (isMarginRelative()) { |
| 8486 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8487 |
} |
| 8488 |
} |
| 8489 |
|
| 8490 |
final boolean hasRtlSupport = c.getApplicationInfo().hasRtlSupport(); |
| 8491 |
final int targetSdkVersion = c.getApplicationInfo().targetSdkVersion; |
| 8492 |
if (targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport) { |
| 8493 |
mMarginFlags |= RTL_COMPATIBILITY_MODE_MASK; |
| 8494 |
} |
| 8495 |
|
| 8496 |
|
| 8497 |
mMarginFlags |= LAYOUT_DIRECTION_LTR; |
| 8498 |
|
| 8499 |
a.recycle(); |
| 8500 |
} |
| 8501 |
|
| 8502 |
public MarginLayoutParams(int width, int height) { |
| 8503 |
super(width, height); |
| 8504 |
|
| 8505 |
mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8506 |
mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
| 8507 |
|
| 8508 |
mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8509 |
mMarginFlags &= ~RTL_COMPATIBILITY_MODE_MASK; |
| 8510 |
} |
| 8511 |
|
| 8512 |
|
| 8513 |
|
| 8514 |
|
| 8515 |
|
| 8516 |
|
| 8517 |
public MarginLayoutParams(MarginLayoutParams source) { |
| 8518 |
this.width = source.width; |
| 8519 |
this.height = source.height; |
| 8520 |
|
| 8521 |
this.leftMargin = source.leftMargin; |
| 8522 |
this.topMargin = source.topMargin; |
| 8523 |
this.rightMargin = source.rightMargin; |
| 8524 |
this.bottomMargin = source.bottomMargin; |
| 8525 |
this.startMargin = source.startMargin; |
| 8526 |
this.endMargin = source.endMargin; |
| 8527 |
|
| 8528 |
this.mMarginFlags = source.mMarginFlags; |
| 8529 |
} |
| 8530 |
|
| 8531 |
public MarginLayoutParams(LayoutParams source) { |
| 8532 |
super(source); |
| 8533 |
|
| 8534 |
mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8535 |
mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
| 8536 |
|
| 8537 |
mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8538 |
mMarginFlags &= ~RTL_COMPATIBILITY_MODE_MASK; |
| 8539 |
} |
| 8540 |
|
| 8541 |
|
| 8542 |
|
| 8543 |
|
| 8544 |
public final void copyMarginsFrom(MarginLayoutParams source) { |
| 8545 |
this.leftMargin = source.leftMargin; |
| 8546 |
this.topMargin = source.topMargin; |
| 8547 |
this.rightMargin = source.rightMargin; |
| 8548 |
this.bottomMargin = source.bottomMargin; |
| 8549 |
this.startMargin = source.startMargin; |
| 8550 |
this.endMargin = source.endMargin; |
| 8551 |
|
| 8552 |
this.mMarginFlags = source.mMarginFlags; |
| 8553 |
} |
| 8554 |
|
| 8555 |
|
| 8556 |
|
| 8557 |
|
| 8558 |
|
| 8559 |
|
| 8560 |
|
| 8561 |
|
| 8562 |
|
| 8563 |
|
| 8564 |
|
| 8565 |
|
| 8566 |
|
| 8567 |
|
| 8568 |
|
| 8569 |
|
| 8570 |
|
| 8571 |
public void setMargins(int left, int top, int right, int bottom) { |
| 8572 |
leftMargin = left; |
| 8573 |
topMargin = top; |
| 8574 |
rightMargin = right; |
| 8575 |
bottomMargin = bottom; |
| 8576 |
mMarginFlags &= ~LEFT_MARGIN_UNDEFINED_MASK; |
| 8577 |
mMarginFlags &= ~RIGHT_MARGIN_UNDEFINED_MASK; |
| 8578 |
if (isMarginRelative()) { |
| 8579 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8580 |
} else { |
| 8581 |
mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8582 |
} |
| 8583 |
} |
| 8584 |
|
| 8585 |
|
| 8586 |
|
| 8587 |
|
| 8588 |
|
| 8589 |
|
| 8590 |
|
| 8591 |
|
| 8592 |
|
| 8593 |
|
| 8594 |
|
| 8595 |
|
| 8596 |
|
| 8597 |
|
| 8598 |
|
| 8599 |
|
| 8600 |
|
| 8601 |
|
| 8602 |
|
| 8603 |
@UnsupportedAppUsage |
| 8604 |
public void setMarginsRelative(int start, int top, int end, int bottom) { |
| 8605 |
startMargin = start; |
| 8606 |
topMargin = top; |
| 8607 |
endMargin = end; |
| 8608 |
bottomMargin = bottom; |
| 8609 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8610 |
} |
| 8611 |
|
| 8612 |
|
| 8613 |
|
| 8614 |
|
| 8615 |
|
| 8616 |
|
| 8617 |
|
| 8618 |
|
| 8619 |
public void setMarginStart(int start) { |
| 8620 |
startMargin = start; |
| 8621 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8622 |
} |
| 8623 |
|
| 8624 |
|
| 8625 |
|
| 8626 |
|
| 8627 |
|
| 8628 |
|
| 8629 |
|
| 8630 |
|
| 8631 |
public int getMarginStart() { |
| 8632 |
if (startMargin != DEFAULT_MARGIN_RELATIVE) return startMargin; |
| 8633 |
if ((mMarginFlags & NEED_RESOLUTION_MASK) == NEED_RESOLUTION_MASK) { |
| 8634 |
doResolveMargins(); |
| 8635 |
} |
| 8636 |
switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
| 8637 |
case View.LAYOUT_DIRECTION_RTL: |
| 8638 |
return rightMargin; |
| 8639 |
case View.LAYOUT_DIRECTION_LTR: |
| 8640 |
default: |
| 8641 |
return leftMargin; |
| 8642 |
} |
| 8643 |
} |
| 8644 |
|
| 8645 |
|
| 8646 |
|
| 8647 |
|
| 8648 |
|
| 8649 |
|
| 8650 |
|
| 8651 |
|
| 8652 |
public void setMarginEnd(int end) { |
| 8653 |
endMargin = end; |
| 8654 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8655 |
} |
| 8656 |
|
| 8657 |
|
| 8658 |
|
| 8659 |
|
| 8660 |
|
| 8661 |
|
| 8662 |
|
| 8663 |
|
| 8664 |
public int getMarginEnd() { |
| 8665 |
if (endMargin != DEFAULT_MARGIN_RELATIVE) return endMargin; |
| 8666 |
if ((mMarginFlags & NEED_RESOLUTION_MASK) == NEED_RESOLUTION_MASK) { |
| 8667 |
doResolveMargins(); |
| 8668 |
} |
| 8669 |
switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
| 8670 |
case View.LAYOUT_DIRECTION_RTL: |
| 8671 |
return leftMargin; |
| 8672 |
case View.LAYOUT_DIRECTION_LTR: |
| 8673 |
default: |
| 8674 |
return rightMargin; |
| 8675 |
} |
| 8676 |
} |
| 8677 |
|
| 8678 |
|
| 8679 |
|
| 8680 |
|
| 8681 |
|
| 8682 |
|
| 8683 |
|
| 8684 |
|
| 8685 |
|
| 8686 |
public boolean isMarginRelative() { |
| 8687 |
return (startMargin != DEFAULT_MARGIN_RELATIVE || endMargin != DEFAULT_MARGIN_RELATIVE); |
| 8688 |
} |
| 8689 |
|
| 8690 |
|
| 8691 |
|
| 8692 |
|
| 8693 |
|
| 8694 |
|
| 8695 |
|
| 8696 |
public void setLayoutDirection(int layoutDirection) { |
| 8697 |
if (layoutDirection != View.LAYOUT_DIRECTION_LTR && |
| 8698 |
layoutDirection != View.LAYOUT_DIRECTION_RTL) return; |
| 8699 |
if (layoutDirection != (mMarginFlags & LAYOUT_DIRECTION_MASK)) { |
| 8700 |
mMarginFlags &= ~LAYOUT_DIRECTION_MASK; |
| 8701 |
mMarginFlags |= (layoutDirection & LAYOUT_DIRECTION_MASK); |
| 8702 |
if (isMarginRelative()) { |
| 8703 |
mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8704 |
} else { |
| 8705 |
mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8706 |
} |
| 8707 |
} |
| 8708 |
} |
| 8709 |
|
| 8710 |
|
| 8711 |
|
| 8712 |
|
| 8713 |
|
| 8714 |
|
| 8715 |
|
| 8716 |
public int getLayoutDirection() { |
| 8717 |
return (mMarginFlags & LAYOUT_DIRECTION_MASK); |
| 8718 |
} |
| 8719 |
|
| 8720 |
|
| 8721 |
|
| 8722 |
|
| 8723 |
|
| 8724 |
@Override |
| 8725 |
public void resolveLayoutDirection(int layoutDirection) { |
| 8726 |
setLayoutDirection(layoutDirection); |
| 8727 |
|
| 8728 |
|
| 8729 |
|
| 8730 |
if (!isMarginRelative() || |
| 8731 |
(mMarginFlags & NEED_RESOLUTION_MASK) != NEED_RESOLUTION_MASK) return; |
| 8732 |
|
| 8733 |
|
| 8734 |
doResolveMargins(); |
| 8735 |
} |
| 8736 |
|
| 8737 |
private void doResolveMargins() { |
| 8738 |
if ((mMarginFlags & RTL_COMPATIBILITY_MODE_MASK) == RTL_COMPATIBILITY_MODE_MASK) { |
| 8739 |
|
| 8740 |
|
| 8741 |
if ((mMarginFlags & LEFT_MARGIN_UNDEFINED_MASK) == LEFT_MARGIN_UNDEFINED_MASK |
| 8742 |
&& startMargin > DEFAULT_MARGIN_RELATIVE) { |
| 8743 |
leftMargin = startMargin; |
| 8744 |
} |
| 8745 |
if ((mMarginFlags & RIGHT_MARGIN_UNDEFINED_MASK) == RIGHT_MARGIN_UNDEFINED_MASK |
| 8746 |
&& endMargin > DEFAULT_MARGIN_RELATIVE) { |
| 8747 |
rightMargin = endMargin; |
| 8748 |
} |
| 8749 |
} else { |
| 8750 |
|
| 8751 |
|
| 8752 |
|
| 8753 |
switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
| 8754 |
case View.LAYOUT_DIRECTION_RTL: |
| 8755 |
leftMargin = (endMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8756 |
endMargin : DEFAULT_MARGIN_RESOLVED; |
| 8757 |
rightMargin = (startMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8758 |
startMargin : DEFAULT_MARGIN_RESOLVED; |
| 8759 |
break; |
| 8760 |
case View.LAYOUT_DIRECTION_LTR: |
| 8761 |
default: |
| 8762 |
leftMargin = (startMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8763 |
startMargin : DEFAULT_MARGIN_RESOLVED; |
| 8764 |
rightMargin = (endMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8765 |
endMargin : DEFAULT_MARGIN_RESOLVED; |
| 8766 |
break; |
| 8767 |
} |
| 8768 |
} |
| 8769 |
mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8770 |
} |
| 8771 |
|
| 8772 |
|
| 8773 |
|
| 8774 |
|
| 8775 |
public boolean isLayoutRtl() { |
| 8776 |
return ((mMarginFlags & LAYOUT_DIRECTION_MASK) == View.LAYOUT_DIRECTION_RTL); |
| 8777 |
} |
| 8778 |
|
| 8779 |
|
| 8780 |
|
| 8781 |
|
| 8782 |
@Override |
| 8783 |
public void onDebugDraw(View view, Canvas canvas, Paint paint) { |
| 8784 |
Insets oi = isLayoutModeOptical(view.mParent) ? view.getOpticalInsets() : Insets.NONE; |
| 8785 |
|
| 8786 |
fillDifference(canvas, |
| 8787 |
view.getLeft() + oi.left, |
| 8788 |
view.getTop() + oi.top, |
| 8789 |
view.getRight() - oi.right, |
| 8790 |
view.getBottom() - oi.bottom, |
| 8791 |
leftMargin, |
| 8792 |
topMargin, |
| 8793 |
rightMargin, |
| 8794 |
bottomMargin, |
| 8795 |
paint); |
| 8796 |
} |
| 8797 |
|
| 8798 |
|
| 8799 |
@Override |
| 8800 |
protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 8801 |
super.encodeProperties(encoder); |
| 8802 |
encoder.addProperty("leftMargin", leftMargin); |
| 8803 |
encoder.addProperty("topMargin", topMargin); |
| 8804 |
encoder.addProperty("rightMargin", rightMargin); |
| 8805 |
encoder.addProperty("bottomMargin", bottomMargin); |
| 8806 |
encoder.addProperty("startMargin", startMargin); |
| 8807 |
encoder.addProperty("endMargin", endMargin); |
| 8808 |
} |
| 8809 |
} |
| 8810 |
|
| 8811 |
|
| 8812 |
|
| 8813 |
|
| 8814 |
|
| 8815 |
|
| 8816 |
|
| 8817 |
|
| 8818 |
private static final class TouchTarget { |
| 8819 |
private static final int MAX_RECYCLED = 32; |
| 8820 |
private static final Object sRecycleLock = new Object[0]; |
| 8821 |
private static TouchTarget sRecycleBin; |
| 8822 |
private static int sRecycledCount; |
| 8823 |
|
| 8824 |
public static final int ALL_POINTER_IDS = -1; |
| 8825 |
|
| 8826 |
|
| 8827 |
@UnsupportedAppUsage |
| 8828 |
public View child; |
| 8829 |
|
| 8830 |
|
| 8831 |
public int pointerIdBits; |
| 8832 |
|
| 8833 |
|
| 8834 |
public TouchTarget next; |
| 8835 |
|
| 8836 |
@UnsupportedAppUsage |
| 8837 |
private TouchTarget() { |
| 8838 |
} |
| 8839 |
|
| 8840 |
public static TouchTarget obtain(@NonNull View child, int pointerIdBits) { |
| 8841 |
if (child == null) { |
| 8842 |
throw new IllegalArgumentException("child must be non-null"); |
| 8843 |
} |
| 8844 |
|
| 8845 |
final TouchTarget target; |
| 8846 |
synchronized (sRecycleLock) { |
| 8847 |
if (sRecycleBin == null) { |
| 8848 |
target = new TouchTarget(); |
| 8849 |
} else { |
| 8850 |
target = sRecycleBin; |
| 8851 |
sRecycleBin = target.next; |
| 8852 |
sRecycledCount--; |
| 8853 |
target.next = null; |
| 8854 |
} |
| 8855 |
} |
| 8856 |
target.child = child; |
| 8857 |
target.pointerIdBits = pointerIdBits; |
| 8858 |
return target; |
| 8859 |
} |
| 8860 |
|
| 8861 |
public void recycle() { |
| 8862 |
if (child == null) { |
| 8863 |
throw new IllegalStateException("already recycled once"); |
| 8864 |
} |
| 8865 |
|
| 8866 |
synchronized (sRecycleLock) { |
| 8867 |
if (sRecycledCount < MAX_RECYCLED) { |
| 8868 |
next = sRecycleBin; |
| 8869 |
sRecycleBin = this; |
| 8870 |
sRecycledCount += 1; |
| 8871 |
} else { |
| 8872 |
next = null; |
| 8873 |
} |
| 8874 |
child = null; |
| 8875 |
} |
| 8876 |
} |
| 8877 |
} |
| 8878 |
|
| 8879 |
|
| 8880 |
private static final class HoverTarget { |
| 8881 |
private static final int MAX_RECYCLED = 32; |
| 8882 |
private static final Object sRecycleLock = new Object[0]; |
| 8883 |
private static HoverTarget sRecycleBin; |
| 8884 |
private static int sRecycledCount; |
| 8885 |
|
| 8886 |
|
| 8887 |
public View child; |
| 8888 |
|
| 8889 |
|
| 8890 |
public HoverTarget next; |
| 8891 |
|
| 8892 |
private HoverTarget() { |
| 8893 |
} |
| 8894 |
|
| 8895 |
public static HoverTarget obtain(@NonNull View child) { |
| 8896 |
if (child == null) { |
| 8897 |
throw new IllegalArgumentException("child must be non-null"); |
| 8898 |
} |
| 8899 |
|
| 8900 |
final HoverTarget target; |
| 8901 |
synchronized (sRecycleLock) { |
| 8902 |
if (sRecycleBin == null) { |
| 8903 |
target = new HoverTarget(); |
| 8904 |
} else { |
| 8905 |
target = sRecycleBin; |
| 8906 |
sRecycleBin = target.next; |
| 8907 |
sRecycledCount--; |
| 8908 |
target.next = null; |
| 8909 |
} |
| 8910 |
} |
| 8911 |
target.child = child; |
| 8912 |
return target; |
| 8913 |
} |
| 8914 |
|
| 8915 |
public void recycle() { |
| 8916 |
if (child == null) { |
| 8917 |
throw new IllegalStateException("already recycled once"); |
| 8918 |
} |
| 8919 |
|
| 8920 |
synchronized (sRecycleLock) { |
| 8921 |
if (sRecycledCount < MAX_RECYCLED) { |
| 8922 |
next = sRecycleBin; |
| 8923 |
sRecycleBin = this; |
| 8924 |
sRecycledCount += 1; |
| 8925 |
} else { |
| 8926 |
next = null; |
| 8927 |
} |
| 8928 |
child = null; |
| 8929 |
} |
| 8930 |
} |
| 8931 |
} |
| 8932 |
|
| 8933 |
|
| 8934 |
|
| 8935 |
|
| 8936 |
private static class ChildListForAutoFillOrContentCapture extends ArrayList<View> { |
| 8937 |
private static final int MAX_POOL_SIZE = 32; |
| 8938 |
|
| 8939 |
private static final Pools.SimplePool<ChildListForAutoFillOrContentCapture> sPool = |
| 8940 |
new Pools.SimplePool<>(MAX_POOL_SIZE); |
| 8941 |
|
| 8942 |
public static ChildListForAutoFillOrContentCapture obtain() { |
| 8943 |
ChildListForAutoFillOrContentCapture list = sPool.acquire(); |
| 8944 |
if (list == null) { |
| 8945 |
list = new ChildListForAutoFillOrContentCapture(); |
| 8946 |
} |
| 8947 |
return list; |
| 8948 |
} |
| 8949 |
|
| 8950 |
public void recycle() { |
| 8951 |
clear(); |
| 8952 |
sPool.release(this); |
| 8953 |
} |
| 8954 |
} |
| 8955 |
|
| 8956 |
|
| 8957 |
|
| 8958 |
|
| 8959 |
|
| 8960 |
static class ChildListForAccessibility { |
| 8961 |
|
| 8962 |
private static final int MAX_POOL_SIZE = 32; |
| 8963 |
|
| 8964 |
private static final SynchronizedPool<ChildListForAccessibility> sPool = |
| 8965 |
new SynchronizedPool<ChildListForAccessibility>(MAX_POOL_SIZE); |
| 8966 |
|
| 8967 |
private final ArrayList<View> mChildren = new ArrayList<View>(); |
| 8968 |
|
| 8969 |
private final ArrayList<ViewLocationHolder> mHolders = new ArrayList<ViewLocationHolder>(); |
| 8970 |
|
| 8971 |
public static ChildListForAccessibility obtain(ViewGroup parent, boolean sort) { |
| 8972 |
ChildListForAccessibility list = sPool.acquire(); |
| 8973 |
if (list == null) { |
| 8974 |
list = new ChildListForAccessibility(); |
| 8975 |
} |
| 8976 |
list.init(parent, sort); |
| 8977 |
return list; |
| 8978 |
} |
| 8979 |
|
| 8980 |
public void recycle() { |
| 8981 |
clear(); |
| 8982 |
sPool.release(this); |
| 8983 |
} |
| 8984 |
|
| 8985 |
public int getChildCount() { |
| 8986 |
return mChildren.size(); |
| 8987 |
} |
| 8988 |
|
| 8989 |
public View getChildAt(int index) { |
| 8990 |
return mChildren.get(index); |
| 8991 |
} |
| 8992 |
|
| 8993 |
private void init(ViewGroup parent, boolean sort) { |
| 8994 |
ArrayList<View> children = mChildren; |
| 8995 |
final int childCount = parent.getChildCount(); |
| 8996 |
for (int i = 0; i < childCount; i++) { |
| 8997 |
View child = parent.getChildAt(i); |
| 8998 |
children.add(child); |
| 8999 |
} |
| 9000 |
if (sort) { |
| 9001 |
ArrayList<ViewLocationHolder> holders = mHolders; |
| 9002 |
for (int i = 0; i < childCount; i++) { |
| 9003 |
View child = children.get(i); |
| 9004 |
ViewLocationHolder holder = ViewLocationHolder.obtain(parent, child); |
| 9005 |
holders.add(holder); |
| 9006 |
} |
| 9007 |
sort(holders); |
| 9008 |
for (int i = 0; i < childCount; i++) { |
| 9009 |
ViewLocationHolder holder = holders.get(i); |
| 9010 |
children.set(i, holder.mView); |
| 9011 |
holder.recycle(); |
| 9012 |
} |
| 9013 |
holders.clear(); |
| 9014 |
} |
| 9015 |
} |
| 9016 |
|
| 9017 |
private void sort(ArrayList<ViewLocationHolder> holders) { |
| 9018 |
|
| 9019 |
|
| 9020 |
|
| 9021 |
try { |
| 9022 |
ViewLocationHolder.setComparisonStrategy( |
| 9023 |
ViewLocationHolder.COMPARISON_STRATEGY_STRIPE); |
| 9024 |
Collections.sort(holders); |
| 9025 |
} catch (IllegalArgumentException iae) { |
| 9026 |
|
| 9027 |
|
| 9028 |
ViewLocationHolder.setComparisonStrategy( |
| 9029 |
ViewLocationHolder.COMPARISON_STRATEGY_LOCATION); |
| 9030 |
Collections.sort(holders); |
| 9031 |
} |
| 9032 |
} |
| 9033 |
|
| 9034 |
private void clear() { |
| 9035 |
mChildren.clear(); |
| 9036 |
} |
| 9037 |
} |
| 9038 |
|
| 9039 |
|
| 9040 |
|
| 9041 |
|
| 9042 |
|
| 9043 |
|
| 9044 |
|
| 9045 |
static class ViewLocationHolder implements Comparable<ViewLocationHolder> { |
| 9046 |
|
| 9047 |
private static final int MAX_POOL_SIZE = 32; |
| 9048 |
|
| 9049 |
private static final SynchronizedPool<ViewLocationHolder> sPool = |
| 9050 |
new SynchronizedPool<ViewLocationHolder>(MAX_POOL_SIZE); |
| 9051 |
|
| 9052 |
public static final int COMPARISON_STRATEGY_STRIPE = 1; |
| 9053 |
|
| 9054 |
public static final int COMPARISON_STRATEGY_LOCATION = 2; |
| 9055 |
|
| 9056 |
private static int sComparisonStrategy = COMPARISON_STRATEGY_STRIPE; |
| 9057 |
|
| 9058 |
private final Rect mLocation = new Rect(); |
| 9059 |
|
| 9060 |
private ViewGroup mRoot; |
| 9061 |
|
| 9062 |
public View mView; |
| 9063 |
|
| 9064 |
private int mLayoutDirection; |
| 9065 |
|
| 9066 |
public static ViewLocationHolder obtain(ViewGroup root, View view) { |
| 9067 |
ViewLocationHolder holder = sPool.acquire(); |
| 9068 |
if (holder == null) { |
| 9069 |
holder = new ViewLocationHolder(); |
| 9070 |
} |
| 9071 |
holder.init(root, view); |
| 9072 |
return holder; |
| 9073 |
} |
| 9074 |
|
| 9075 |
public static void setComparisonStrategy(int strategy) { |
| 9076 |
sComparisonStrategy = strategy; |
| 9077 |
} |
| 9078 |
|
| 9079 |
public void recycle() { |
| 9080 |
clear(); |
| 9081 |
sPool.release(this); |
| 9082 |
} |
| 9083 |
|
| 9084 |
@Override |
| 9085 |
public int compareTo(ViewLocationHolder another) { |
| 9086 |
|
| 9087 |
if (another == null) { |
| 9088 |
return 1; |
| 9089 |
} |
| 9090 |
|
| 9091 |
int boundsResult = compareBoundsOfTree(this, another); |
| 9092 |
if (boundsResult != 0) { |
| 9093 |
return boundsResult; |
| 9094 |
} |
| 9095 |
|
| 9096 |
|
| 9097 |
|
| 9098 |
return mView.getAccessibilityViewId() - another.mView.getAccessibilityViewId(); |
| 9099 |
} |
| 9100 |
|
| 9101 |
|
| 9102 |
|
| 9103 |
|
| 9104 |
|
| 9105 |
|
| 9106 |
|
| 9107 |
|
| 9108 |
private static int compareBoundsOfTree( |
| 9109 |
ViewLocationHolder holder1, ViewLocationHolder holder2) { |
| 9110 |
if (sComparisonStrategy == COMPARISON_STRATEGY_STRIPE) { |
| 9111 |
|
| 9112 |
if (holder1.mLocation.bottom - holder2.mLocation.top <= 0) { |
| 9113 |
return -1; |
| 9114 |
} |
| 9115 |
|
| 9116 |
if (holder1.mLocation.top - holder2.mLocation.bottom >= 0) { |
| 9117 |
return 1; |
| 9118 |
} |
| 9119 |
} |
| 9120 |
|
| 9121 |
|
| 9122 |
if (holder1.mLayoutDirection == LAYOUT_DIRECTION_LTR) { |
| 9123 |
final int leftDifference = holder1.mLocation.left - holder2.mLocation.left; |
| 9124 |
if (leftDifference != 0) { |
| 9125 |
return leftDifference; |
| 9126 |
} |
| 9127 |
} else { |
| 9128 |
final int rightDifference = holder1.mLocation.right - holder2.mLocation.right; |
| 9129 |
if (rightDifference != 0) { |
| 9130 |
return -rightDifference; |
| 9131 |
} |
| 9132 |
} |
| 9133 |
|
| 9134 |
final int topDifference = holder1.mLocation.top - holder2.mLocation.top; |
| 9135 |
if (topDifference != 0) { |
| 9136 |
return topDifference; |
| 9137 |
} |
| 9138 |
|
| 9139 |
final int heightDiference = holder1.mLocation.height() - holder2.mLocation.height(); |
| 9140 |
if (heightDiference != 0) { |
| 9141 |
return -heightDiference; |
| 9142 |
} |
| 9143 |
|
| 9144 |
final int widthDifference = holder1.mLocation.width() - holder2.mLocation.width(); |
| 9145 |
if (widthDifference != 0) { |
| 9146 |
return -widthDifference; |
| 9147 |
} |
| 9148 |
|
| 9149 |
|
| 9150 |
final Rect view1Bounds = new Rect(); |
| 9151 |
final Rect view2Bounds = new Rect(); |
| 9152 |
final Rect tempRect = new Rect(); |
| 9153 |
holder1.mView.getBoundsOnScreen(view1Bounds, true); |
| 9154 |
holder2.mView.getBoundsOnScreen(view2Bounds, true); |
| 9155 |
final View child1 = holder1.mView.findViewByPredicateTraversal((view) -> { |
| 9156 |
view.getBoundsOnScreen(tempRect, true); |
| 9157 |
return !tempRect.equals(view1Bounds); |
| 9158 |
}, null); |
| 9159 |
final View child2 = holder2.mView.findViewByPredicateTraversal((view) -> { |
| 9160 |
view.getBoundsOnScreen(tempRect, true); |
| 9161 |
return !tempRect.equals(view2Bounds); |
| 9162 |
}, null); |
| 9163 |
|
| 9164 |
|
| 9165 |
|
| 9166 |
if ((child1 != null) && (child2 != null)) { |
| 9167 |
final ViewLocationHolder childHolder1 = |
| 9168 |
ViewLocationHolder.obtain(holder1.mRoot, child1); |
| 9169 |
final ViewLocationHolder childHolder2 = |
| 9170 |
ViewLocationHolder.obtain(holder1.mRoot, child2); |
| 9171 |
return compareBoundsOfTree(childHolder1, childHolder2); |
| 9172 |
} |
| 9173 |
|
| 9174 |
|
| 9175 |
if (child1 != null) { |
| 9176 |
return 1; |
| 9177 |
} |
| 9178 |
|
| 9179 |
if (child2 != null) { |
| 9180 |
return -1; |
| 9181 |
} |
| 9182 |
|
| 9183 |
|
| 9184 |
return 0; |
| 9185 |
} |
| 9186 |
|
| 9187 |
private void init(ViewGroup root, View view) { |
| 9188 |
Rect viewLocation = mLocation; |
| 9189 |
view.getDrawingRect(viewLocation); |
| 9190 |
root.offsetDescendantRectToMyCoords(view, viewLocation); |
| 9191 |
mView = view; |
| 9192 |
mRoot = root; |
| 9193 |
mLayoutDirection = root.getLayoutDirection(); |
| 9194 |
} |
| 9195 |
|
| 9196 |
private void clear() { |
| 9197 |
mView = null; |
| 9198 |
mRoot = null; |
| 9199 |
mLocation.set(0, 0, 0, 0); |
| 9200 |
} |
| 9201 |
} |
| 9202 |
|
| 9203 |
private static void drawRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { |
| 9204 |
if (sDebugLines== null) { |
| 9205 |
|
| 9206 |
sDebugLines = new float[16]; |
| 9207 |
} |
| 9208 |
|
| 9209 |
sDebugLines[0] = x1; |
| 9210 |
sDebugLines[1] = y1; |
| 9211 |
sDebugLines[2] = x2; |
| 9212 |
sDebugLines[3] = y1; |
| 9213 |
|
| 9214 |
sDebugLines[4] = x2; |
| 9215 |
sDebugLines[5] = y1; |
| 9216 |
sDebugLines[6] = x2; |
| 9217 |
sDebugLines[7] = y2; |
| 9218 |
|
| 9219 |
sDebugLines[8] = x2; |
| 9220 |
sDebugLines[9] = y2; |
| 9221 |
sDebugLines[10] = x1; |
| 9222 |
sDebugLines[11] = y2; |
| 9223 |
|
| 9224 |
sDebugLines[12] = x1; |
| 9225 |
sDebugLines[13] = y2; |
| 9226 |
sDebugLines[14] = x1; |
| 9227 |
sDebugLines[15] = y1; |
| 9228 |
|
| 9229 |
canvas.drawLines(sDebugLines, paint); |
| 9230 |
} |
| 9231 |
|
| 9232 |
|
| 9233 |
@Override |
| 9234 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 9235 |
protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 9236 |
super.encodeProperties(encoder); |
| 9237 |
|
| 9238 |
encoder.addProperty("focus:descendantFocusability", getDescendantFocusability()); |
| 9239 |
encoder.addProperty("drawing:clipChildren", getClipChildren()); |
| 9240 |
encoder.addProperty("drawing:clipToPadding", getClipToPadding()); |
| 9241 |
encoder.addProperty("drawing:childrenDrawingOrderEnabled", isChildrenDrawingOrderEnabled()); |
| 9242 |
encoder.addProperty("drawing:persistentDrawingCache", getPersistentDrawingCache()); |
| 9243 |
|
| 9244 |
int n = getChildCount(); |
| 9245 |
encoder.addProperty("meta:__childCount__", (short)n); |
| 9246 |
for (int i = 0; i < n; i++) { |
| 9247 |
encoder.addPropertyKey("meta:__child__" + i); |
| 9248 |
getChildAt(i).encode(encoder); |
| 9249 |
} |
| 9250 |
} |
| 9251 |
|
| 9252 |
|
| 9253 |
@Override |
| 9254 |
public final void onDescendantUnbufferedRequested() { |
| 9255 |
|
| 9256 |
int focusedChildNonPointerSource = InputDevice.SOURCE_CLASS_NONE; |
| 9257 |
if (mFocused != null) { |
| 9258 |
focusedChildNonPointerSource = mFocused.mUnbufferedInputSource |
| 9259 |
& (~InputDevice.SOURCE_CLASS_POINTER); |
| 9260 |
} |
| 9261 |
mUnbufferedInputSource = focusedChildNonPointerSource; |
| 9262 |
|
| 9263 |
|
| 9264 |
|
| 9265 |
|
| 9266 |
for (int i = 0; i < mChildrenCount; i++) { |
| 9267 |
final View child = mChildren[i]; |
| 9268 |
if ((child.mUnbufferedInputSource & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 9269 |
mUnbufferedInputSource |= InputDevice.SOURCE_CLASS_POINTER; |
| 9270 |
break; |
| 9271 |
} |
| 9272 |
} |
| 9273 |
if (mParent != null) { |
| 9274 |
mParent.onDescendantUnbufferedRequested(); |
| 9275 |
} |
| 9276 |
} |
| 9277 |
|
| 9278 |
|
| 9279 |
|
| 9280 |
|
| 9281 |
|
| 9282 |
|
| 9283 |
|
| 9284 |
@Override |
| 9285 |
public void dispatchCreateViewTranslationRequest(@NonNull Map<AutofillId, long[]> viewIds, |
| 9286 |
@NonNull @DataFormat int[] supportedFormats, |
| 9287 |
@Nullable TranslationCapability capability, |
| 9288 |
@NonNull List<ViewTranslationRequest> requests) { |
| 9289 |
super.dispatchCreateViewTranslationRequest(viewIds, supportedFormats, capability, requests); |
| 9290 |
final int childCount = getChildCount(); |
| 9291 |
if (childCount == 0) { |
| 9292 |
return; |
| 9293 |
} |
| 9294 |
for (int i = 0; i < childCount; ++i) { |
| 9295 |
final View child = getChildAt(i); |
| 9296 |
child.dispatchCreateViewTranslationRequest(viewIds, supportedFormats, capability, |
| 9297 |
requests); |
| 9298 |
} |
| 9299 |
} |
| 9300 |
|
| 9301 |
|
| 9302 |
|
| 9303 |
|
| 9304 |
|
| 9305 |
|
| 9306 |
|
| 9307 |
|
| 9308 |
|
| 9309 |
|
| 9310 |
|
| 9311 |
@Nullable |
| 9312 |
@Override |
| 9313 |
public OnBackInvokedDispatcher findOnBackInvokedDispatcherForChild(@NonNull View child, |
| 9314 |
@NonNull View requester) { |
| 9315 |
ViewParent parent = getParent(); |
| 9316 |
if (parent != null) { |
| 9317 |
return parent.findOnBackInvokedDispatcherForChild(this, requester); |
| 9318 |
} |
| 9319 |
return null; |
| 9320 |
} |
| 9321 |
} |