ViewCompat.java revision 79a141a3eaca2b69ae043c1c6b7a61c7db90d644
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.v4.view; 18 19import android.content.res.ColorStateList; 20import android.graphics.Matrix; 21import android.graphics.Paint; 22import android.graphics.PixelFormat; 23import android.graphics.PorterDuff; 24import android.graphics.Rect; 25import android.graphics.drawable.Drawable; 26import android.os.Bundle; 27import android.support.annotation.FloatRange; 28import android.support.annotation.IdRes; 29import android.support.annotation.IntDef; 30import android.support.annotation.NonNull; 31import android.support.annotation.Nullable; 32import android.support.v4.os.BuildCompat; 33import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; 34import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat; 35import android.util.Log; 36import android.view.MotionEvent; 37import android.view.VelocityTracker; 38import android.view.View; 39import android.view.ViewConfiguration; 40import android.view.ViewGroup; 41import android.view.ViewParent; 42import android.view.accessibility.AccessibilityEvent; 43 44import java.lang.annotation.Retention; 45import java.lang.annotation.RetentionPolicy; 46import java.lang.reflect.Field; 47import java.lang.reflect.InvocationTargetException; 48import java.lang.reflect.Method; 49import java.util.WeakHashMap; 50 51/** 52 * Helper for accessing features in {@link View} introduced after API 53 * level 4 in a backwards compatible fashion. 54 */ 55public class ViewCompat { 56 private static final String TAG = "ViewCompat"; 57 58 /** @hide */ 59 @IntDef({View.FOCUS_LEFT, View.FOCUS_UP, View.FOCUS_RIGHT, View.FOCUS_DOWN, 60 View.FOCUS_FORWARD, View.FOCUS_BACKWARD}) 61 @Retention(RetentionPolicy.SOURCE) 62 public @interface FocusDirection {} 63 64 /** @hide */ 65 @IntDef({View.FOCUS_LEFT, View.FOCUS_UP, View.FOCUS_RIGHT, View.FOCUS_DOWN}) 66 @Retention(RetentionPolicy.SOURCE) 67 public @interface FocusRealDirection {} 68 69 /** @hide */ 70 @IntDef({View.FOCUS_FORWARD, View.FOCUS_BACKWARD}) 71 @Retention(RetentionPolicy.SOURCE) 72 public @interface FocusRelativeDirection {} 73 74 /** @hide */ 75 @IntDef({OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER}) 76 @Retention(RetentionPolicy.SOURCE) 77 private @interface OverScroll {} 78 79 /** 80 * Always allow a user to over-scroll this view, provided it is a 81 * view that can scroll. 82 */ 83 public static final int OVER_SCROLL_ALWAYS = 0; 84 85 /** 86 * Allow a user to over-scroll this view only if the content is large 87 * enough to meaningfully scroll, provided it is a view that can scroll. 88 */ 89 public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; 90 91 /** 92 * Never allow a user to over-scroll this view. 93 */ 94 public static final int OVER_SCROLL_NEVER = 2; 95 96 private static final long FAKE_FRAME_TIME = 10; 97 98 /** @hide */ 99 @IntDef({ 100 IMPORTANT_FOR_ACCESSIBILITY_AUTO, 101 IMPORTANT_FOR_ACCESSIBILITY_YES, 102 IMPORTANT_FOR_ACCESSIBILITY_NO, 103 IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 104 }) 105 @Retention(RetentionPolicy.SOURCE) 106 private @interface ImportantForAccessibility {} 107 108 /** 109 * Automatically determine whether a view is important for accessibility. 110 */ 111 public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; 112 113 /** 114 * The view is important for accessibility. 115 */ 116 public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; 117 118 /** 119 * The view is not important for accessibility. 120 */ 121 public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; 122 123 /** 124 * The view is not important for accessibility, nor are any of its 125 * descendant views. 126 */ 127 public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS = 0x00000004; 128 129 /** @hide */ 130 @IntDef({ 131 ACCESSIBILITY_LIVE_REGION_NONE, 132 ACCESSIBILITY_LIVE_REGION_POLITE, 133 ACCESSIBILITY_LIVE_REGION_ASSERTIVE 134 }) 135 @Retention(RetentionPolicy.SOURCE) 136 private @interface AccessibilityLiveRegion {} 137 138 /** 139 * Live region mode specifying that accessibility services should not 140 * automatically announce changes to this view. This is the default live 141 * region mode for most views. 142 * <p> 143 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 144 */ 145 public static final int ACCESSIBILITY_LIVE_REGION_NONE = 0x00000000; 146 147 /** 148 * Live region mode specifying that accessibility services should announce 149 * changes to this view. 150 * <p> 151 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 152 */ 153 public static final int ACCESSIBILITY_LIVE_REGION_POLITE = 0x00000001; 154 155 /** 156 * Live region mode specifying that accessibility services should interrupt 157 * ongoing speech to immediately announce changes to this view. 158 * <p> 159 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 160 */ 161 public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 0x00000002; 162 163 /** @hide */ 164 @IntDef({LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYER_TYPE_HARDWARE}) 165 @Retention(RetentionPolicy.SOURCE) 166 private @interface LayerType {} 167 168 /** 169 * Indicates that the view does not have a layer. 170 */ 171 public static final int LAYER_TYPE_NONE = 0; 172 173 /** 174 * <p>Indicates that the view has a software layer. A software layer is backed 175 * by a bitmap and causes the view to be rendered using Android's software 176 * rendering pipeline, even if hardware acceleration is enabled.</p> 177 * 178 * <p>Software layers have various usages:</p> 179 * <p>When the application is not using hardware acceleration, a software layer 180 * is useful to apply a specific color filter and/or blending mode and/or 181 * translucency to a view and all its children.</p> 182 * <p>When the application is using hardware acceleration, a software layer 183 * is useful to render drawing primitives not supported by the hardware 184 * accelerated pipeline. It can also be used to cache a complex view tree 185 * into a texture and reduce the complexity of drawing operations. For instance, 186 * when animating a complex view tree with a translation, a software layer can 187 * be used to render the view tree only once.</p> 188 * <p>Software layers should be avoided when the affected view tree updates 189 * often. Every update will require to re-render the software layer, which can 190 * potentially be slow (particularly when hardware acceleration is turned on 191 * since the layer will have to be uploaded into a hardware texture after every 192 * update.)</p> 193 */ 194 public static final int LAYER_TYPE_SOFTWARE = 1; 195 196 /** 197 * <p>Indicates that the view has a hardware layer. A hardware layer is backed 198 * by a hardware specific texture (generally Frame Buffer Objects or FBO on 199 * OpenGL hardware) and causes the view to be rendered using Android's hardware 200 * rendering pipeline, but only if hardware acceleration is turned on for the 201 * view hierarchy. When hardware acceleration is turned off, hardware layers 202 * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> 203 * 204 * <p>A hardware layer is useful to apply a specific color filter and/or 205 * blending mode and/or translucency to a view and all its children.</p> 206 * <p>A hardware layer can be used to cache a complex view tree into a 207 * texture and reduce the complexity of drawing operations. For instance, 208 * when animating a complex view tree with a translation, a hardware layer can 209 * be used to render the view tree only once.</p> 210 * <p>A hardware layer can also be used to increase the rendering quality when 211 * rotation transformations are applied on a view. It can also be used to 212 * prevent potential clipping issues when applying 3D transforms on a view.</p> 213 */ 214 public static final int LAYER_TYPE_HARDWARE = 2; 215 216 /** @hide */ 217 @IntDef({ 218 LAYOUT_DIRECTION_LTR, 219 LAYOUT_DIRECTION_RTL, 220 LAYOUT_DIRECTION_INHERIT, 221 LAYOUT_DIRECTION_LOCALE}) 222 @Retention(RetentionPolicy.SOURCE) 223 private @interface LayoutDirectionMode {} 224 225 /** @hide */ 226 @IntDef({ 227 LAYOUT_DIRECTION_LTR, 228 LAYOUT_DIRECTION_RTL 229 }) 230 @Retention(RetentionPolicy.SOURCE) 231 private @interface ResolvedLayoutDirectionMode {} 232 233 /** 234 * Horizontal layout direction of this view is from Left to Right. 235 */ 236 public static final int LAYOUT_DIRECTION_LTR = 0; 237 238 /** 239 * Horizontal layout direction of this view is from Right to Left. 240 */ 241 public static final int LAYOUT_DIRECTION_RTL = 1; 242 243 /** 244 * Horizontal layout direction of this view is inherited from its parent. 245 * Use with {@link #setLayoutDirection}. 246 */ 247 public static final int LAYOUT_DIRECTION_INHERIT = 2; 248 249 /** 250 * Horizontal layout direction of this view is from deduced from the default language 251 * script for the locale. Use with {@link #setLayoutDirection}. 252 */ 253 public static final int LAYOUT_DIRECTION_LOCALE = 3; 254 255 /** 256 * Bits of {@link #getMeasuredWidthAndState} and 257 * {@link #getMeasuredWidthAndState} that provide the actual measured size. 258 */ 259 public static final int MEASURED_SIZE_MASK = 0x00ffffff; 260 261 /** 262 * Bits of {@link #getMeasuredWidthAndState} and 263 * {@link #getMeasuredWidthAndState} that provide the additional state bits. 264 */ 265 public static final int MEASURED_STATE_MASK = 0xff000000; 266 267 /** 268 * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits 269 * for functions that combine both width and height into a single int, 270 * such as {@link #getMeasuredState} and the childState argument of 271 * {@link #resolveSizeAndState(int, int, int)}. 272 */ 273 public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; 274 275 /** 276 * Bit of {@link #getMeasuredWidthAndState} and 277 * {@link #getMeasuredWidthAndState} that indicates the measured size 278 * is smaller that the space the view would like to have. 279 */ 280 public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; 281 282 /** 283 * Indicates no axis of view scrolling. 284 */ 285 public static final int SCROLL_AXIS_NONE = 0; 286 287 /** 288 * Indicates scrolling along the horizontal axis. 289 */ 290 public static final int SCROLL_AXIS_HORIZONTAL = 1 << 0; 291 292 /** 293 * Indicates scrolling along the vertical axis. 294 */ 295 public static final int SCROLL_AXIS_VERTICAL = 1 << 1; 296 297 /** @hide */ 298 @Retention(RetentionPolicy.SOURCE) 299 @IntDef(flag = true, 300 value = { 301 SCROLL_INDICATOR_TOP, 302 SCROLL_INDICATOR_BOTTOM, 303 SCROLL_INDICATOR_LEFT, 304 SCROLL_INDICATOR_RIGHT, 305 SCROLL_INDICATOR_START, 306 SCROLL_INDICATOR_END, 307 }) 308 public @interface ScrollIndicators {} 309 310 /** 311 * Scroll indicator direction for the top edge of the view. 312 * 313 * @see #setScrollIndicators(View, int) 314 * @see #setScrollIndicators(View, int, int) 315 * @see #getScrollIndicators(View) 316 */ 317 public static final int SCROLL_INDICATOR_TOP = 0x1; 318 319 /** 320 * Scroll indicator direction for the bottom edge of the view. 321 * 322 * @see #setScrollIndicators(View, int) 323 * @see #setScrollIndicators(View, int, int) 324 * @see #getScrollIndicators(View) 325 */ 326 public static final int SCROLL_INDICATOR_BOTTOM = 0x2; 327 328 /** 329 * Scroll indicator direction for the left edge of the view. 330 * 331 * @see #setScrollIndicators(View, int) 332 * @see #setScrollIndicators(View, int, int) 333 * @see #getScrollIndicators(View) 334 */ 335 public static final int SCROLL_INDICATOR_LEFT = 0x4; 336 337 /** 338 * Scroll indicator direction for the right edge of the view. 339 * 340 * @see #setScrollIndicators(View, int) 341 * @see #setScrollIndicators(View, int, int) 342 * @see #getScrollIndicators(View) 343 */ 344 public static final int SCROLL_INDICATOR_RIGHT = 0x8; 345 346 /** 347 * Scroll indicator direction for the starting edge of the view. 348 * 349 * @see #setScrollIndicators(View, int) 350 * @see #setScrollIndicators(View, int, int) 351 * @see #getScrollIndicators(View) 352 */ 353 public static final int SCROLL_INDICATOR_START = 0x10; 354 355 /** 356 * Scroll indicator direction for the ending edge of the view. 357 * 358 * @see #setScrollIndicators(View, int) 359 * @see #setScrollIndicators(View, int, int) 360 * @see #getScrollIndicators(View) 361 */ 362 public static final int SCROLL_INDICATOR_END = 0x20; 363 364 interface ViewCompatImpl { 365 boolean canScrollHorizontally(View v, int direction); 366 boolean canScrollVertically(View v, int direction); 367 void onInitializeAccessibilityEvent(View v, AccessibilityEvent event); 368 void onPopulateAccessibilityEvent(View v, AccessibilityEvent event); 369 void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info); 370 void setAccessibilityDelegate(View v, @Nullable AccessibilityDelegateCompat delegate); 371 boolean hasAccessibilityDelegate(View v); 372 boolean hasTransientState(View view); 373 void setHasTransientState(View view, boolean hasTransientState); 374 void postInvalidateOnAnimation(View view); 375 void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom); 376 void postOnAnimation(View view, Runnable action); 377 void postOnAnimationDelayed(View view, Runnable action, long delayMillis); 378 int getImportantForAccessibility(View view); 379 void setImportantForAccessibility(View view, int mode); 380 boolean isImportantForAccessibility(View view); 381 boolean performAccessibilityAction(View view, int action, Bundle arguments); 382 AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view); 383 float getAlpha(View view); 384 void setLayerType(View view, int layerType, Paint paint); 385 int getLayerType(View view); 386 int getLabelFor(View view); 387 void setLabelFor(View view, int id); 388 void setLayerPaint(View view, Paint paint); 389 int getLayoutDirection(View view); 390 void setLayoutDirection(View view, int layoutDirection); 391 ViewParent getParentForAccessibility(View view); 392 int resolveSizeAndState(int size, int measureSpec, int childMeasuredState); 393 int getMeasuredWidthAndState(View view); 394 int getMeasuredHeightAndState(View view); 395 int getMeasuredState(View view); 396 int getAccessibilityLiveRegion(View view); 397 void setAccessibilityLiveRegion(View view, int mode); 398 int getPaddingStart(View view); 399 int getPaddingEnd(View view); 400 void setPaddingRelative(View view, int start, int top, int end, int bottom); 401 void dispatchStartTemporaryDetach(View view); 402 void dispatchFinishTemporaryDetach(View view); 403 float getX(View view); 404 float getY(View view); 405 float getRotation(View view); 406 float getRotationX(View view); 407 float getRotationY(View view); 408 float getScaleX(View view); 409 float getScaleY(View view); 410 float getTranslationX(View view); 411 float getTranslationY(View view); 412 @Nullable Matrix getMatrix(View view); 413 int getMinimumWidth(View view); 414 int getMinimumHeight(View view); 415 ViewPropertyAnimatorCompat animate(View view); 416 void setRotation(View view, float value); 417 void setRotationX(View view, float value); 418 void setRotationY(View view, float value); 419 void setScaleX(View view, float value); 420 void setScaleY(View view, float value); 421 void setTranslationX(View view, float value); 422 void setTranslationY(View view, float value); 423 void setX(View view, float value); 424 void setY(View view, float value); 425 void setAlpha(View view, float value); 426 void setPivotX(View view, float value); 427 void setPivotY(View view, float value); 428 float getPivotX(View view); 429 float getPivotY(View view); 430 void setElevation(View view, float elevation); 431 float getElevation(View view); 432 void setTranslationZ(View view, float translationZ); 433 float getTranslationZ(View view); 434 void setClipBounds(View view, Rect clipBounds); 435 Rect getClipBounds(View view); 436 void setTransitionName(View view, String transitionName); 437 String getTransitionName(View view); 438 int getWindowSystemUiVisibility(View view); 439 void requestApplyInsets(View view); 440 void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled); 441 boolean getFitsSystemWindows(View view); 442 boolean hasOverlappingRendering(View view); 443 void setFitsSystemWindows(View view, boolean fitSystemWindows); 444 void jumpDrawablesToCurrentState(View v); 445 void setOnApplyWindowInsetsListener(View view, OnApplyWindowInsetsListener listener); 446 WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets); 447 WindowInsetsCompat dispatchApplyWindowInsets(View v, WindowInsetsCompat insets); 448 void setSaveFromParentEnabled(View view, boolean enabled); 449 void setActivated(View view, boolean activated); 450 boolean isPaddingRelative(View view); 451 ColorStateList getBackgroundTintList(View view); 452 void setBackgroundTintList(View view, ColorStateList tintList); 453 PorterDuff.Mode getBackgroundTintMode(View view); 454 void setBackgroundTintMode(View view, PorterDuff.Mode mode); 455 void setNestedScrollingEnabled(View view, boolean enabled); 456 boolean isNestedScrollingEnabled(View view); 457 boolean startNestedScroll(View view, int axes); 458 void stopNestedScroll(View view); 459 boolean hasNestedScrollingParent(View view); 460 boolean dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, int dxUnconsumed, 461 int dyUnconsumed, int[] offsetInWindow); 462 boolean dispatchNestedPreScroll(View view, int dx, int dy, int[] consumed, 463 int[] offsetInWindow); 464 boolean dispatchNestedFling(View view, float velocityX, float velocityY, boolean consumed); 465 boolean dispatchNestedPreFling(View view, float velocityX, float velocityY); 466 boolean isInLayout(View view); 467 boolean isLaidOut(View view); 468 boolean isLayoutDirectionResolved(View view); 469 int combineMeasuredStates(int curState, int newState); 470 float getZ(View view); 471 void setZ(View view, float z); 472 boolean isAttachedToWindow(View view); 473 boolean hasOnClickListeners(View view); 474 void setScrollIndicators(View view, int indicators); 475 void setScrollIndicators(View view, int indicators, int mask); 476 int getScrollIndicators(View view); 477 void offsetTopAndBottom(View view, int offset); 478 void offsetLeftAndRight(View view, int offset); 479 void setPointerIcon(View view, PointerIconCompat pointerIcon); 480 } 481 482 static class BaseViewCompatImpl implements ViewCompatImpl { 483 private Method mDispatchStartTemporaryDetach; 484 private Method mDispatchFinishTemporaryDetach; 485 private boolean mTempDetachBound; 486 WeakHashMap<View, ViewPropertyAnimatorCompat> mViewPropertyAnimatorCompatMap = null; 487 private static Method sChildrenDrawingOrderMethod; 488 489 @Override 490 public boolean canScrollHorizontally(View v, int direction) { 491 return (v instanceof ScrollingView) && 492 canScrollingViewScrollHorizontally((ScrollingView) v, direction); 493 } 494 @Override 495 public boolean canScrollVertically(View v, int direction) { 496 return (v instanceof ScrollingView) && 497 canScrollingViewScrollVertically((ScrollingView) v, direction); 498 } 499 500 @Override 501 public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 502 // Do nothing; API doesn't exist 503 } 504 505 @Override 506 public boolean hasAccessibilityDelegate(View v) { 507 return false; 508 } 509 510 @Override 511 public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 512 // Do nothing; API doesn't exist 513 } 514 @Override 515 public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 516 // Do nothing; API doesn't exist 517 } 518 @Override 519 public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 520 // Do nothing; API doesn't exist 521 } 522 @Override 523 public boolean hasTransientState(View view) { 524 // A view can't have transient state if transient state wasn't supported. 525 return false; 526 } 527 @Override 528 public void setHasTransientState(View view, boolean hasTransientState) { 529 // Do nothing; API doesn't exist 530 } 531 @Override 532 public void postInvalidateOnAnimation(View view) { 533 view.invalidate(); 534 } 535 @Override 536 public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 537 view.invalidate(left, top, right, bottom); 538 } 539 @Override 540 public void postOnAnimation(View view, Runnable action) { 541 view.postDelayed(action, getFrameTime()); 542 } 543 @Override 544 public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 545 view.postDelayed(action, getFrameTime() + delayMillis); 546 } 547 long getFrameTime() { 548 return FAKE_FRAME_TIME; 549 } 550 @Override 551 public int getImportantForAccessibility(View view) { 552 return 0; 553 } 554 @Override 555 public void setImportantForAccessibility(View view, int mode) { 556 557 } 558 @Override 559 public boolean isImportantForAccessibility(View view) { 560 return true; 561 } 562 @Override 563 public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 564 return false; 565 } 566 @Override 567 public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 568 return null; 569 } 570 @Override 571 public float getAlpha(View view) { 572 return 1.0f; 573 } 574 @Override 575 public void setLayerType(View view, int layerType, Paint paint) { 576 // No-op until layers became available (HC) 577 } 578 @Override 579 public int getLayerType(View view) { 580 return LAYER_TYPE_NONE; 581 } 582 @Override 583 public int getLabelFor(View view) { 584 return 0; 585 } 586 @Override 587 public void setLabelFor(View view, int id) { 588 589 } 590 @Override 591 public void setLayerPaint(View view, Paint p) { 592 // No-op until layers became available (HC) 593 } 594 595 @Override 596 public int getLayoutDirection(View view) { 597 return LAYOUT_DIRECTION_LTR; 598 } 599 600 @Override 601 public void setLayoutDirection(View view, int layoutDirection) { 602 // No-op 603 } 604 605 @Override 606 public ViewParent getParentForAccessibility(View view) { 607 return view.getParent(); 608 } 609 610 @Override 611 public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 612 return View.resolveSize(size, measureSpec); 613 } 614 615 @Override 616 public int getMeasuredWidthAndState(View view) { 617 return view.getMeasuredWidth(); 618 } 619 620 @Override 621 public int getMeasuredHeightAndState(View view) { 622 return view.getMeasuredHeight(); 623 } 624 625 @Override 626 public int getMeasuredState(View view) { 627 return 0; 628 } 629 630 @Override 631 public int getAccessibilityLiveRegion(View view) { 632 return ACCESSIBILITY_LIVE_REGION_NONE; 633 } 634 635 @Override 636 public void setAccessibilityLiveRegion(View view, int mode) { 637 // No-op 638 } 639 640 @Override 641 public int getPaddingStart(View view) { 642 return view.getPaddingLeft(); 643 } 644 645 @Override 646 public int getPaddingEnd(View view) { 647 return view.getPaddingRight(); 648 } 649 650 @Override 651 public void setPaddingRelative(View view, int start, int top, int end, int bottom) { 652 view.setPadding(start, top, end, bottom); 653 } 654 655 @Override 656 public void dispatchStartTemporaryDetach(View view) { 657 if (!mTempDetachBound) { 658 bindTempDetach(); 659 } 660 if (mDispatchStartTemporaryDetach != null) { 661 try { 662 mDispatchStartTemporaryDetach.invoke(view); 663 } catch (Exception e) { 664 Log.d(TAG, "Error calling dispatchStartTemporaryDetach", e); 665 } 666 } else { 667 // Try this instead 668 view.onStartTemporaryDetach(); 669 } 670 } 671 672 @Override 673 public void dispatchFinishTemporaryDetach(View view) { 674 if (!mTempDetachBound) { 675 bindTempDetach(); 676 } 677 if (mDispatchFinishTemporaryDetach != null) { 678 try { 679 mDispatchFinishTemporaryDetach.invoke(view); 680 } catch (Exception e) { 681 Log.d(TAG, "Error calling dispatchFinishTemporaryDetach", e); 682 } 683 } else { 684 // Try this instead 685 view.onFinishTemporaryDetach(); 686 } 687 } 688 689 @Override 690 public boolean hasOverlappingRendering(View view) { 691 return true; 692 } 693 694 private void bindTempDetach() { 695 try { 696 mDispatchStartTemporaryDetach = View.class.getDeclaredMethod( 697 "dispatchStartTemporaryDetach"); 698 mDispatchFinishTemporaryDetach = View.class.getDeclaredMethod( 699 "dispatchFinishTemporaryDetach"); 700 } catch (NoSuchMethodException e) { 701 Log.e(TAG, "Couldn't find method", e); 702 } 703 mTempDetachBound = true; 704 } 705 706 @Override 707 public float getTranslationX(View view) { 708 return 0; 709 } 710 711 @Override 712 public float getTranslationY(View view) { 713 return 0; 714 } 715 716 @Override 717 public float getX(View view) { 718 return 0; 719 } 720 721 @Override 722 public float getY(View view) { 723 return 0; 724 } 725 726 @Override 727 public float getRotation(View view) { 728 return 0; 729 } 730 731 @Override 732 public float getRotationX(View view) { 733 return 0; 734 } 735 736 @Override 737 public float getRotationY(View view) { 738 return 0; 739 } 740 741 @Override 742 public float getScaleX(View view) { 743 return 0; 744 } 745 746 @Override 747 public float getScaleY(View view) { 748 return 0; 749 } 750 751 @Override 752 public Matrix getMatrix(View view) { 753 return null; 754 } 755 756 @Override 757 public int getMinimumWidth(View view) { 758 return ViewCompatBase.getMinimumWidth(view); 759 } 760 761 @Override 762 public int getMinimumHeight(View view) { 763 return ViewCompatBase.getMinimumHeight(view); 764 } 765 766 @Override 767 public ViewPropertyAnimatorCompat animate(View view) { 768 return new ViewPropertyAnimatorCompat(view); 769 } 770 771 @Override 772 public void setRotation(View view, float value) { 773 // noop 774 } 775 776 @Override 777 public void setTranslationX(View view, float value) { 778 // noop 779 } 780 781 @Override 782 public void setTranslationY(View view, float value) { 783 // noop 784 } 785 786 @Override 787 public void setAlpha(View view, float value) { 788 // noop 789 } 790 791 @Override 792 public void setRotationX(View view, float value) { 793 // noop 794 } 795 796 @Override 797 public void setRotationY(View view, float value) { 798 // noop 799 } 800 801 @Override 802 public void setScaleX(View view, float value) { 803 // noop 804 } 805 806 @Override 807 public void setScaleY(View view, float value) { 808 // noop 809 } 810 811 @Override 812 public void setX(View view, float value) { 813 // noop 814 } 815 816 @Override 817 public void setY(View view, float value) { 818 // noop 819 } 820 821 @Override 822 public void setPivotX(View view, float value) { 823 // noop 824 } 825 826 @Override 827 public void setPivotY(View view, float value) { 828 // noop 829 } 830 831 @Override 832 public float getPivotX(View view) { 833 return 0; 834 } 835 836 @Override 837 public float getPivotY(View view) { 838 return 0; 839 } 840 841 @Override 842 public void setTransitionName(View view, String transitionName) { 843 } 844 845 @Override 846 public String getTransitionName(View view) { 847 return null; 848 } 849 850 @Override 851 public int getWindowSystemUiVisibility(View view) { 852 return 0; 853 } 854 855 @Override 856 public void requestApplyInsets(View view) { 857 } 858 859 @Override 860 public void setElevation(View view, float elevation) { 861 } 862 863 @Override 864 public float getElevation(View view) { 865 return 0f; 866 } 867 868 @Override 869 public void setTranslationZ(View view, float translationZ) { 870 } 871 872 @Override 873 public float getTranslationZ(View view) { 874 return 0f; 875 } 876 877 @Override 878 public void setClipBounds(View view, Rect clipBounds) { 879 } 880 881 @Override 882 public Rect getClipBounds(View view) { 883 return null; 884 } 885 886 @Override 887 public void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled) { 888 if (sChildrenDrawingOrderMethod == null) { 889 try { 890 sChildrenDrawingOrderMethod = ViewGroup.class 891 .getDeclaredMethod("setChildrenDrawingOrderEnabled", boolean.class); 892 } catch (NoSuchMethodException e) { 893 Log.e(TAG, "Unable to find childrenDrawingOrderEnabled", e); 894 } 895 sChildrenDrawingOrderMethod.setAccessible(true); 896 } 897 try { 898 sChildrenDrawingOrderMethod.invoke(viewGroup, enabled); 899 } catch (IllegalAccessException e) { 900 Log.e(TAG, "Unable to invoke childrenDrawingOrderEnabled", e); 901 } catch (IllegalArgumentException e) { 902 Log.e(TAG, "Unable to invoke childrenDrawingOrderEnabled", e); 903 } catch (InvocationTargetException e) { 904 Log.e(TAG, "Unable to invoke childrenDrawingOrderEnabled", e); 905 } 906 } 907 908 @Override 909 public boolean getFitsSystemWindows(View view) { 910 return false; 911 } 912 913 @Override 914 public void setFitsSystemWindows(View view, boolean fitSystemWindows) { 915 // noop 916 } 917 918 @Override 919 public void jumpDrawablesToCurrentState(View view) { 920 // Do nothing; API didn't exist. 921 } 922 923 @Override 924 public void setOnApplyWindowInsetsListener(View view, 925 OnApplyWindowInsetsListener listener) { 926 // noop 927 } 928 929 @Override 930 public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { 931 return insets; 932 } 933 934 @Override 935 public WindowInsetsCompat dispatchApplyWindowInsets(View v, WindowInsetsCompat insets) { 936 return insets; 937 } 938 939 @Override 940 public void setSaveFromParentEnabled(View v, boolean enabled) { 941 // noop 942 } 943 944 @Override 945 public void setActivated(View view, boolean activated) { 946 // noop 947 } 948 949 @Override 950 public boolean isPaddingRelative(View view) { 951 return false; 952 } 953 954 @Override 955 public void setNestedScrollingEnabled(View view, boolean enabled) { 956 if (view instanceof NestedScrollingChild) { 957 ((NestedScrollingChild) view).setNestedScrollingEnabled(enabled); 958 } 959 } 960 961 @Override 962 public boolean isNestedScrollingEnabled(View view) { 963 if (view instanceof NestedScrollingChild) { 964 return ((NestedScrollingChild) view).isNestedScrollingEnabled(); 965 } 966 return false; 967 } 968 969 @Override 970 public ColorStateList getBackgroundTintList(View view) { 971 return ViewCompatBase.getBackgroundTintList(view); 972 } 973 974 @Override 975 public void setBackgroundTintList(View view, ColorStateList tintList) { 976 ViewCompatBase.setBackgroundTintList(view, tintList); 977 } 978 979 @Override 980 public void setBackgroundTintMode(View view, PorterDuff.Mode mode) { 981 ViewCompatBase.setBackgroundTintMode(view, mode); 982 } 983 984 @Override 985 public PorterDuff.Mode getBackgroundTintMode(View view) { 986 return ViewCompatBase.getBackgroundTintMode(view); 987 } 988 989 private boolean canScrollingViewScrollHorizontally(ScrollingView view, int direction) { 990 final int offset = view.computeHorizontalScrollOffset(); 991 final int range = view.computeHorizontalScrollRange() - 992 view.computeHorizontalScrollExtent(); 993 if (range == 0) return false; 994 if (direction < 0) { 995 return offset > 0; 996 } else { 997 return offset < range - 1; 998 } 999 } 1000 1001 private boolean canScrollingViewScrollVertically(ScrollingView view, int direction) { 1002 final int offset = view.computeVerticalScrollOffset(); 1003 final int range = view.computeVerticalScrollRange() - 1004 view.computeVerticalScrollExtent(); 1005 if (range == 0) return false; 1006 if (direction < 0) { 1007 return offset > 0; 1008 } else { 1009 return offset < range - 1; 1010 } 1011 } 1012 1013 @Override 1014 public boolean startNestedScroll(View view, int axes) { 1015 if (view instanceof NestedScrollingChild) { 1016 return ((NestedScrollingChild) view).startNestedScroll(axes); 1017 } 1018 return false; 1019 } 1020 1021 @Override 1022 public void stopNestedScroll(View view) { 1023 if (view instanceof NestedScrollingChild) { 1024 ((NestedScrollingChild) view).stopNestedScroll(); 1025 } 1026 } 1027 1028 @Override 1029 public boolean hasNestedScrollingParent(View view) { 1030 if (view instanceof NestedScrollingChild) { 1031 return ((NestedScrollingChild) view).hasNestedScrollingParent(); 1032 } 1033 return false; 1034 } 1035 1036 @Override 1037 public boolean dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, 1038 int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) { 1039 if (view instanceof NestedScrollingChild) { 1040 return ((NestedScrollingChild) view).dispatchNestedScroll(dxConsumed, dyConsumed, 1041 dxUnconsumed, dyUnconsumed, offsetInWindow); 1042 } 1043 return false; 1044 } 1045 1046 @Override 1047 public boolean dispatchNestedPreScroll(View view, int dx, int dy, 1048 int[] consumed, int[] offsetInWindow) { 1049 if (view instanceof NestedScrollingChild) { 1050 return ((NestedScrollingChild) view).dispatchNestedPreScroll(dx, dy, consumed, 1051 offsetInWindow); 1052 } 1053 return false; 1054 } 1055 1056 @Override 1057 public boolean dispatchNestedFling(View view, float velocityX, float velocityY, 1058 boolean consumed) { 1059 if (view instanceof NestedScrollingChild) { 1060 return ((NestedScrollingChild) view).dispatchNestedFling(velocityX, velocityY, 1061 consumed); 1062 } 1063 return false; 1064 } 1065 1066 @Override 1067 public boolean dispatchNestedPreFling(View view, float velocityX, float velocityY) { 1068 if (view instanceof NestedScrollingChild) { 1069 return ((NestedScrollingChild) view).dispatchNestedPreFling(velocityX, velocityY); 1070 } 1071 return false; 1072 } 1073 1074 @Override 1075 public boolean isInLayout(View view) { 1076 return false; 1077 } 1078 1079 @Override 1080 public boolean isLaidOut(View view) { 1081 return ViewCompatBase.isLaidOut(view); 1082 } 1083 1084 @Override 1085 public boolean isLayoutDirectionResolved(View view) { 1086 return false; 1087 } 1088 1089 @Override 1090 public int combineMeasuredStates(int curState, int newState) { 1091 return curState | newState; 1092 } 1093 1094 @Override 1095 public float getZ(View view) { 1096 return getTranslationZ(view) + getElevation(view); 1097 } 1098 1099 @Override 1100 public void setZ(View view, float z) { 1101 // no-op 1102 } 1103 1104 @Override 1105 public boolean isAttachedToWindow(View view) { 1106 return ViewCompatBase.isAttachedToWindow(view); 1107 } 1108 1109 @Override 1110 public boolean hasOnClickListeners(View view) { 1111 return false; 1112 } 1113 1114 @Override 1115 public int getScrollIndicators(View view) { 1116 return 0; 1117 } 1118 1119 @Override 1120 public void setScrollIndicators(View view, int indicators) { 1121 // no-op 1122 } 1123 1124 @Override 1125 public void setScrollIndicators(View view, int indicators, int mask) { 1126 // no-op 1127 } 1128 1129 @Override 1130 public void offsetLeftAndRight(View view, int offset) { 1131 ViewCompatBase.offsetLeftAndRight(view, offset); 1132 } 1133 1134 @Override 1135 public void offsetTopAndBottom(View view, int offset) { 1136 ViewCompatBase.offsetTopAndBottom(view, offset); 1137 } 1138 1139 @Override 1140 public void setPointerIcon(View view, PointerIconCompat pointerIcon) { 1141 // no-op 1142 } 1143 } 1144 1145 static class HCViewCompatImpl extends BaseViewCompatImpl { 1146 @Override 1147 long getFrameTime() { 1148 return ViewCompatHC.getFrameTime(); 1149 } 1150 @Override 1151 public float getAlpha(View view) { 1152 return ViewCompatHC.getAlpha(view); 1153 } 1154 @Override 1155 public void setLayerType(View view, int layerType, Paint paint) { 1156 ViewCompatHC.setLayerType(view, layerType, paint); 1157 } 1158 @Override 1159 public int getLayerType(View view) { 1160 return ViewCompatHC.getLayerType(view); 1161 } 1162 @Override 1163 public void setLayerPaint(View view, Paint paint) { 1164 // Make sure the paint is correct; this will be cheap if it's the same 1165 // instance as was used to call setLayerType earlier. 1166 setLayerType(view, getLayerType(view), paint); 1167 // This is expensive, but the only way to accomplish this before JB-MR1. 1168 view.invalidate(); 1169 } 1170 @Override 1171 public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 1172 return ViewCompatHC.resolveSizeAndState(size, measureSpec, childMeasuredState); 1173 } 1174 @Override 1175 public int getMeasuredWidthAndState(View view) { 1176 return ViewCompatHC.getMeasuredWidthAndState(view); 1177 } 1178 @Override 1179 public int getMeasuredHeightAndState(View view) { 1180 return ViewCompatHC.getMeasuredHeightAndState(view); 1181 } 1182 @Override 1183 public int getMeasuredState(View view) { 1184 return ViewCompatHC.getMeasuredState(view); 1185 } 1186 @Override 1187 public float getTranslationX(View view) { 1188 return ViewCompatHC.getTranslationX(view); 1189 } 1190 @Override 1191 public float getTranslationY(View view) { 1192 return ViewCompatHC.getTranslationY(view); 1193 } 1194 1195 @Override 1196 public Matrix getMatrix(View view) { 1197 return ViewCompatHC.getMatrix(view); 1198 } 1199 1200 @Override 1201 public void setTranslationX(View view, float value) { 1202 ViewCompatHC.setTranslationX(view, value); 1203 } 1204 @Override 1205 public void setTranslationY(View view, float value) { 1206 ViewCompatHC.setTranslationY(view, value); 1207 } 1208 @Override 1209 public void setAlpha(View view, float value) { 1210 ViewCompatHC.setAlpha(view, value); 1211 } 1212 @Override 1213 public void setX(View view, float value) { 1214 ViewCompatHC.setX(view, value); 1215 } 1216 @Override 1217 public void setY(View view, float value) { 1218 ViewCompatHC.setY(view, value); 1219 } 1220 @Override 1221 public void setRotation(View view, float value) { 1222 ViewCompatHC.setRotation(view, value); 1223 } 1224 @Override 1225 public void setRotationX(View view, float value) { 1226 ViewCompatHC.setRotationX(view, value); 1227 } 1228 @Override 1229 public void setRotationY(View view, float value) { 1230 ViewCompatHC.setRotationY(view, value); 1231 } 1232 @Override 1233 public void setScaleX(View view, float value) { 1234 ViewCompatHC.setScaleX(view, value); 1235 } 1236 @Override 1237 public void setScaleY(View view, float value) { 1238 ViewCompatHC.setScaleY(view, value); 1239 } 1240 @Override 1241 public void setPivotX(View view, float value) { 1242 ViewCompatHC.setPivotX(view, value); 1243 } 1244 @Override 1245 public void setPivotY(View view, float value) { 1246 ViewCompatHC.setPivotY(view, value); 1247 } 1248 @Override 1249 public float getX(View view) { 1250 return ViewCompatHC.getX(view); 1251 } 1252 1253 @Override 1254 public float getY(View view) { 1255 return ViewCompatHC.getY(view); 1256 } 1257 1258 @Override 1259 public float getRotation(View view) { 1260 return ViewCompatHC.getRotation(view); 1261 } 1262 1263 @Override 1264 public float getRotationX(View view) { 1265 return ViewCompatHC.getRotationX(view); 1266 } 1267 1268 @Override 1269 public float getRotationY(View view) { 1270 return ViewCompatHC.getRotationY(view); 1271 } 1272 1273 @Override 1274 public float getScaleX(View view) { 1275 return ViewCompatHC.getScaleX(view); 1276 } 1277 1278 @Override 1279 public float getScaleY(View view) { 1280 return ViewCompatHC.getScaleY(view); 1281 } 1282 1283 @Override 1284 public float getPivotX(View view) { 1285 return ViewCompatHC.getPivotX(view); 1286 } 1287 @Override 1288 public float getPivotY(View view) { 1289 return ViewCompatHC.getPivotY(view); 1290 } 1291 @Override 1292 public void jumpDrawablesToCurrentState(View view) { 1293 ViewCompatHC.jumpDrawablesToCurrentState(view); 1294 } 1295 1296 @Override 1297 public void setSaveFromParentEnabled(View view, boolean enabled) { 1298 ViewCompatHC.setSaveFromParentEnabled(view, enabled); 1299 } 1300 1301 @Override 1302 public void setActivated(View view, boolean activated) { 1303 ViewCompatHC.setActivated(view, activated); 1304 } 1305 1306 @Override 1307 public int combineMeasuredStates(int curState, int newState) { 1308 return ViewCompatHC.combineMeasuredStates(curState, newState); 1309 } 1310 1311 @Override 1312 public void offsetLeftAndRight(View view, int offset) { 1313 ViewCompatHC.offsetLeftAndRight(view, offset); 1314 } 1315 1316 @Override 1317 public void offsetTopAndBottom(View view, int offset) { 1318 ViewCompatHC.offsetTopAndBottom(view, offset); 1319 } 1320 } 1321 1322 static class ICSViewCompatImpl extends HCViewCompatImpl { 1323 static Field mAccessibilityDelegateField; 1324 static boolean accessibilityDelegateCheckFailed = false; 1325 @Override 1326 public boolean canScrollHorizontally(View v, int direction) { 1327 return ViewCompatICS.canScrollHorizontally(v, direction); 1328 } 1329 @Override 1330 public boolean canScrollVertically(View v, int direction) { 1331 return ViewCompatICS.canScrollVertically(v, direction); 1332 } 1333 @Override 1334 public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1335 ViewCompatICS.onPopulateAccessibilityEvent(v, event); 1336 } 1337 @Override 1338 public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1339 ViewCompatICS.onInitializeAccessibilityEvent(v, event); 1340 } 1341 @Override 1342 public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 1343 ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo()); 1344 } 1345 @Override 1346 public void setAccessibilityDelegate(View v, 1347 @Nullable AccessibilityDelegateCompat delegate) { 1348 ViewCompatICS.setAccessibilityDelegate(v, 1349 delegate == null ? null : delegate.getBridge()); 1350 } 1351 1352 @Override 1353 public boolean hasAccessibilityDelegate(View v) { 1354 if (accessibilityDelegateCheckFailed) { 1355 return false; // View implementation might have changed. 1356 } 1357 if (mAccessibilityDelegateField == null) { 1358 try { 1359 mAccessibilityDelegateField = View.class 1360 .getDeclaredField("mAccessibilityDelegate"); 1361 mAccessibilityDelegateField.setAccessible(true); 1362 } catch (Throwable t) { 1363 accessibilityDelegateCheckFailed = true; 1364 return false; 1365 } 1366 } 1367 try { 1368 return mAccessibilityDelegateField.get(v) != null; 1369 } catch (Throwable t) { 1370 accessibilityDelegateCheckFailed = true; 1371 return false; 1372 } 1373 } 1374 1375 @Override 1376 public ViewPropertyAnimatorCompat animate(View view) { 1377 if (mViewPropertyAnimatorCompatMap == null) { 1378 mViewPropertyAnimatorCompatMap = new WeakHashMap<>(); 1379 } 1380 ViewPropertyAnimatorCompat vpa = mViewPropertyAnimatorCompatMap.get(view); 1381 if (vpa == null) { 1382 vpa = new ViewPropertyAnimatorCompat(view); 1383 mViewPropertyAnimatorCompatMap.put(view, vpa); 1384 } 1385 return vpa; 1386 } 1387 1388 @Override 1389 public void setFitsSystemWindows(View view, boolean fitSystemWindows) { 1390 ViewCompatICS.setFitsSystemWindows(view, fitSystemWindows); 1391 } 1392 } 1393 1394 static class ICSMr1ViewCompatImpl extends ICSViewCompatImpl { 1395 @Override 1396 public boolean hasOnClickListeners(View view) { 1397 return ViewCompatICSMr1.hasOnClickListeners(view); 1398 } 1399 } 1400 1401 static class JBViewCompatImpl extends ICSMr1ViewCompatImpl { 1402 @Override 1403 public boolean hasTransientState(View view) { 1404 return ViewCompatJB.hasTransientState(view); 1405 } 1406 @Override 1407 public void setHasTransientState(View view, boolean hasTransientState) { 1408 ViewCompatJB.setHasTransientState(view, hasTransientState); 1409 } 1410 @Override 1411 public void postInvalidateOnAnimation(View view) { 1412 ViewCompatJB.postInvalidateOnAnimation(view); 1413 } 1414 @Override 1415 public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 1416 ViewCompatJB.postInvalidateOnAnimation(view, left, top, right, bottom); 1417 } 1418 @Override 1419 public void postOnAnimation(View view, Runnable action) { 1420 ViewCompatJB.postOnAnimation(view, action); 1421 } 1422 @Override 1423 public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 1424 ViewCompatJB.postOnAnimationDelayed(view, action, delayMillis); 1425 } 1426 @Override 1427 public int getImportantForAccessibility(View view) { 1428 return ViewCompatJB.getImportantForAccessibility(view); 1429 } 1430 @Override 1431 public void setImportantForAccessibility(View view, int mode) { 1432 // IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS is not available 1433 // on this platform so replace with IMPORTANT_FOR_ACCESSIBILITY_NO 1434 // which is closer semantically. 1435 if (mode == IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) { 1436 mode = IMPORTANT_FOR_ACCESSIBILITY_NO; 1437 } 1438 ViewCompatJB.setImportantForAccessibility(view, mode); 1439 } 1440 @Override 1441 public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 1442 return ViewCompatJB.performAccessibilityAction(view, action, arguments); 1443 } 1444 @Override 1445 public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 1446 Object compat = ViewCompatJB.getAccessibilityNodeProvider(view); 1447 if (compat != null) { 1448 return new AccessibilityNodeProviderCompat(compat); 1449 } 1450 return null; 1451 } 1452 1453 @Override 1454 public ViewParent getParentForAccessibility(View view) { 1455 return ViewCompatJB.getParentForAccessibility(view); 1456 } 1457 1458 @Override 1459 public int getMinimumWidth(View view) { 1460 return ViewCompatJB.getMinimumWidth(view); 1461 } 1462 1463 @Override 1464 public int getMinimumHeight(View view) { 1465 return ViewCompatJB.getMinimumHeight(view); 1466 } 1467 1468 @Override 1469 public void requestApplyInsets(View view) { 1470 ViewCompatJB.requestApplyInsets(view); 1471 } 1472 1473 @Override 1474 public boolean getFitsSystemWindows(View view) { 1475 return ViewCompatJB.getFitsSystemWindows(view); 1476 } 1477 1478 @Override 1479 public boolean hasOverlappingRendering(View view) { 1480 return ViewCompatJB.hasOverlappingRendering(view); 1481 } 1482 } 1483 1484 static class JbMr1ViewCompatImpl extends JBViewCompatImpl { 1485 1486 @Override 1487 public int getLabelFor(View view) { 1488 return ViewCompatJellybeanMr1.getLabelFor(view); 1489 } 1490 1491 @Override 1492 public void setLabelFor(View view, int id) { 1493 ViewCompatJellybeanMr1.setLabelFor(view, id); 1494 } 1495 1496 @Override 1497 public void setLayerPaint(View view, Paint paint) { 1498 ViewCompatJellybeanMr1.setLayerPaint(view, paint); 1499 } 1500 1501 @Override 1502 public int getLayoutDirection(View view) { 1503 return ViewCompatJellybeanMr1.getLayoutDirection(view); 1504 } 1505 1506 @Override 1507 public void setLayoutDirection(View view, int layoutDirection) { 1508 ViewCompatJellybeanMr1.setLayoutDirection(view, layoutDirection); 1509 } 1510 1511 @Override 1512 public int getPaddingStart(View view) { 1513 return ViewCompatJellybeanMr1.getPaddingStart(view); 1514 } 1515 1516 @Override 1517 public int getPaddingEnd(View view) { 1518 return ViewCompatJellybeanMr1.getPaddingEnd(view); 1519 } 1520 1521 @Override 1522 public void setPaddingRelative(View view, int start, int top, int end, int bottom) { 1523 ViewCompatJellybeanMr1.setPaddingRelative(view, start, top, end, bottom); 1524 } 1525 1526 @Override 1527 public int getWindowSystemUiVisibility(View view) { 1528 return ViewCompatJellybeanMr1.getWindowSystemUiVisibility(view); 1529 } 1530 1531 @Override 1532 public boolean isPaddingRelative(View view) { 1533 return ViewCompatJellybeanMr1.isPaddingRelative(view); 1534 } 1535 } 1536 1537 static class JbMr2ViewCompatImpl extends JbMr1ViewCompatImpl { 1538 @Override 1539 public void setClipBounds(View view, Rect clipBounds) { 1540 ViewCompatJellybeanMr2.setClipBounds(view, clipBounds); 1541 } 1542 1543 @Override 1544 public Rect getClipBounds(View view) { 1545 return ViewCompatJellybeanMr2.getClipBounds(view); 1546 } 1547 1548 @Override 1549 public boolean isInLayout(View view) { 1550 return ViewCompatJellybeanMr2.isInLayout(view); 1551 } 1552 } 1553 1554 static class KitKatViewCompatImpl extends JbMr2ViewCompatImpl { 1555 @Override 1556 public int getAccessibilityLiveRegion(View view) { 1557 return ViewCompatKitKat.getAccessibilityLiveRegion(view); 1558 } 1559 1560 @Override 1561 public void setAccessibilityLiveRegion(View view, int mode) { 1562 ViewCompatKitKat.setAccessibilityLiveRegion(view, mode); 1563 } 1564 1565 @Override 1566 public void setImportantForAccessibility(View view, int mode) { 1567 ViewCompatJB.setImportantForAccessibility(view, mode); 1568 } 1569 1570 @Override 1571 public boolean isLaidOut(View view) { 1572 return ViewCompatKitKat.isLaidOut(view); 1573 } 1574 1575 @Override 1576 public boolean isLayoutDirectionResolved(View view) { 1577 return ViewCompatKitKat.isLayoutDirectionResolved(view); 1578 } 1579 1580 @Override 1581 public boolean isAttachedToWindow(View view) { 1582 return ViewCompatKitKat.isAttachedToWindow(view); 1583 } 1584 } 1585 1586 static class LollipopViewCompatImpl extends KitKatViewCompatImpl { 1587 @Override 1588 public void setTransitionName(View view, String transitionName) { 1589 ViewCompatLollipop.setTransitionName(view, transitionName); 1590 } 1591 1592 @Override 1593 public String getTransitionName(View view) { 1594 return ViewCompatLollipop.getTransitionName(view); 1595 } 1596 1597 @Override 1598 public void requestApplyInsets(View view) { 1599 ViewCompatLollipop.requestApplyInsets(view); 1600 } 1601 1602 @Override 1603 public void setElevation(View view, float elevation) { 1604 ViewCompatLollipop.setElevation(view, elevation); 1605 } 1606 1607 @Override 1608 public float getElevation(View view) { 1609 return ViewCompatLollipop.getElevation(view); 1610 } 1611 1612 @Override 1613 public void setTranslationZ(View view, float translationZ) { 1614 ViewCompatLollipop.setTranslationZ(view, translationZ); 1615 } 1616 1617 @Override 1618 public float getTranslationZ(View view) { 1619 return ViewCompatLollipop.getTranslationZ(view); 1620 } 1621 1622 @Override 1623 public void setOnApplyWindowInsetsListener(View view, 1624 final OnApplyWindowInsetsListener listener) { 1625 ViewCompatLollipop.OnApplyWindowInsetsListenerBridge bridge = 1626 new ViewCompatLollipop.OnApplyWindowInsetsListenerBridge() { 1627 @Override 1628 public Object onApplyWindowInsets(View v, Object insets) { 1629 WindowInsetsCompat compatInsets = WindowInsetsCompat.wrap(insets); 1630 compatInsets = listener.onApplyWindowInsets(v, compatInsets); 1631 return WindowInsetsCompat.unwrap(compatInsets); 1632 } 1633 }; 1634 ViewCompatLollipop.setOnApplyWindowInsetsListener(view, bridge); 1635 } 1636 1637 @Override 1638 public void setNestedScrollingEnabled(View view, boolean enabled) { 1639 ViewCompatLollipop.setNestedScrollingEnabled(view, enabled); 1640 } 1641 1642 @Override 1643 public boolean isNestedScrollingEnabled(View view) { 1644 return ViewCompatLollipop.isNestedScrollingEnabled(view); 1645 } 1646 1647 @Override 1648 public boolean startNestedScroll(View view, int axes) { 1649 return ViewCompatLollipop.startNestedScroll(view, axes); 1650 } 1651 1652 @Override 1653 public void stopNestedScroll(View view) { 1654 ViewCompatLollipop.stopNestedScroll(view); 1655 } 1656 1657 @Override 1658 public boolean hasNestedScrollingParent(View view) { 1659 return ViewCompatLollipop.hasNestedScrollingParent(view); 1660 } 1661 1662 @Override 1663 public boolean dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, 1664 int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) { 1665 return ViewCompatLollipop.dispatchNestedScroll(view, dxConsumed, dyConsumed, 1666 dxUnconsumed, dyUnconsumed, offsetInWindow); 1667 } 1668 1669 @Override 1670 public boolean dispatchNestedPreScroll(View view, int dx, int dy, 1671 int[] consumed, int[] offsetInWindow) { 1672 return ViewCompatLollipop.dispatchNestedPreScroll(view, dx, dy, consumed, 1673 offsetInWindow); 1674 } 1675 1676 @Override 1677 public boolean dispatchNestedFling(View view, float velocityX, float velocityY, 1678 boolean consumed) { 1679 return ViewCompatLollipop.dispatchNestedFling(view, velocityX, velocityY, consumed); 1680 } 1681 1682 @Override 1683 public boolean dispatchNestedPreFling(View view, float velocityX, float velocityY) { 1684 return ViewCompatLollipop.dispatchNestedPreFling(view, velocityX, velocityY); 1685 } 1686 1687 @Override 1688 public boolean isImportantForAccessibility(View view) { 1689 return ViewCompatLollipop.isImportantForAccessibility(view); 1690 } 1691 1692 @Override 1693 public ColorStateList getBackgroundTintList(View view) { 1694 return ViewCompatLollipop.getBackgroundTintList(view); 1695 } 1696 1697 @Override 1698 public void setBackgroundTintList(View view, ColorStateList tintList) { 1699 ViewCompatLollipop.setBackgroundTintList(view, tintList); 1700 } 1701 1702 @Override 1703 public void setBackgroundTintMode(View view, PorterDuff.Mode mode) { 1704 ViewCompatLollipop.setBackgroundTintMode(view, mode); 1705 } 1706 1707 @Override 1708 public PorterDuff.Mode getBackgroundTintMode(View view) { 1709 return ViewCompatLollipop.getBackgroundTintMode(view); 1710 } 1711 1712 @Override 1713 public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { 1714 return WindowInsetsCompat.wrap( 1715 ViewCompatLollipop.onApplyWindowInsets(v, WindowInsetsCompat.unwrap(insets))); 1716 } 1717 1718 @Override 1719 public WindowInsetsCompat dispatchApplyWindowInsets(View v, WindowInsetsCompat insets) { 1720 return WindowInsetsCompat.wrap( 1721 ViewCompatLollipop.dispatchApplyWindowInsets( 1722 v, WindowInsetsCompat.unwrap(insets))); 1723 } 1724 1725 @Override 1726 public float getZ(View view) { 1727 return ViewCompatLollipop.getZ(view); 1728 } 1729 1730 @Override 1731 public void setZ(View view, float z) { 1732 ViewCompatLollipop.setZ(view, z); 1733 } 1734 1735 @Override 1736 public void offsetLeftAndRight(View view, int offset) { 1737 ViewCompatLollipop.offsetLeftAndRight(view, offset); 1738 } 1739 1740 @Override 1741 public void offsetTopAndBottom(View view, int offset) { 1742 ViewCompatLollipop.offsetTopAndBottom(view, offset); 1743 } 1744 } 1745 1746 static class MarshmallowViewCompatImpl extends LollipopViewCompatImpl { 1747 @Override 1748 public void setScrollIndicators(View view, int indicators) { 1749 ViewCompatMarshmallow.setScrollIndicators(view, indicators); 1750 } 1751 1752 @Override 1753 public void setScrollIndicators(View view, int indicators, int mask) { 1754 ViewCompatMarshmallow.setScrollIndicators(view, indicators, mask); 1755 } 1756 1757 @Override 1758 public int getScrollIndicators(View view) { 1759 return ViewCompatMarshmallow.getScrollIndicators(view); 1760 } 1761 1762 1763 @Override 1764 public void offsetLeftAndRight(View view, int offset) { 1765 ViewCompatMarshmallow.offsetLeftAndRight(view, offset); 1766 } 1767 1768 @Override 1769 public void offsetTopAndBottom(View view, int offset) { 1770 ViewCompatMarshmallow.offsetTopAndBottom(view, offset); 1771 } 1772 } 1773 1774 static class Api24ViewCompatImpl extends MarshmallowViewCompatImpl { 1775 @Override 1776 public void setPointerIcon(View view, PointerIconCompat pointerIconCompat) { 1777 ViewCompatApi24.setPointerIcon(view, pointerIconCompat.getPointerIcon()); 1778 } 1779 } 1780 1781 static final ViewCompatImpl IMPL; 1782 static { 1783 final int version = android.os.Build.VERSION.SDK_INT; 1784 if (BuildCompat.isAtLeastN()) { 1785 IMPL = new Api24ViewCompatImpl(); 1786 } else if (version >= 23) { 1787 IMPL = new MarshmallowViewCompatImpl(); 1788 } else if (version >= 21) { 1789 IMPL = new LollipopViewCompatImpl(); 1790 } else if (version >= 19) { 1791 IMPL = new KitKatViewCompatImpl(); 1792 } else if (version >= 18) { 1793 IMPL = new JbMr2ViewCompatImpl(); 1794 } else if (version >= 17) { 1795 IMPL = new JbMr1ViewCompatImpl(); 1796 } else if (version >= 16) { 1797 IMPL = new JBViewCompatImpl(); 1798 } else if (version >= 15) { 1799 IMPL = new ICSMr1ViewCompatImpl(); 1800 } else if (version >= 14) { 1801 IMPL = new ICSViewCompatImpl(); 1802 } else if (version >= 11) { 1803 IMPL = new HCViewCompatImpl(); 1804 } else { 1805 IMPL = new BaseViewCompatImpl(); 1806 } 1807 } 1808 1809 /** 1810 * Check if this view can be scrolled horizontally in a certain direction. 1811 * 1812 * @param v The View against which to invoke the method. 1813 * @param direction Negative to check scrolling left, positive to check scrolling right. 1814 * @return true if this view can be scrolled in the specified direction, false otherwise. 1815 */ 1816 public static boolean canScrollHorizontally(View v, int direction) { 1817 return IMPL.canScrollHorizontally(v, direction); 1818 } 1819 1820 /** 1821 * Check if this view can be scrolled vertically in a certain direction. 1822 * 1823 * @param v The View against which to invoke the method. 1824 * @param direction Negative to check scrolling up, positive to check scrolling down. 1825 * @return true if this view can be scrolled in the specified direction, false otherwise. 1826 */ 1827 public static boolean canScrollVertically(View v, int direction) { 1828 return IMPL.canScrollVertically(v, direction); 1829 } 1830 1831 /** 1832 * Returns the over-scroll mode for this view. The result will be 1833 * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1834 * (allow over-scrolling only if the view content is larger than the container), 1835 * or {@link #OVER_SCROLL_NEVER}. 1836 * 1837 * @param v The View against which to invoke the method. 1838 * @return This view's over-scroll mode. 1839 * @deprecated Call {@link View#getOverScrollMode()} directly. 1840 */ 1841 @Deprecated 1842 @OverScroll 1843 public static int getOverScrollMode(View v) { 1844 //noinspection ResourceType 1845 return v.getOverScrollMode(); 1846 } 1847 1848 /** 1849 * Set the over-scroll mode for this view. Valid over-scroll modes are 1850 * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1851 * (allow over-scrolling only if the view content is larger than the container), 1852 * or {@link #OVER_SCROLL_NEVER}. 1853 * 1854 * Setting the over-scroll mode of a view will have an effect only if the 1855 * view is capable of scrolling. 1856 * 1857 * @param v The View against which to invoke the method. 1858 * @param overScrollMode The new over-scroll mode for this view. 1859 * @deprecated Call {@link View#setOverScrollMode(int)} directly. 1860 */ 1861 @Deprecated 1862 public static void setOverScrollMode(View v, @OverScroll int overScrollMode) { 1863 v.setOverScrollMode(overScrollMode); 1864 } 1865 1866 /** 1867 * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} 1868 * giving a chance to this View to populate the accessibility event with its 1869 * text content. While this method is free to modify event 1870 * attributes other than text content, doing so should normally be performed in 1871 * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}. 1872 * <p> 1873 * Example: Adding formatted date string to an accessibility event in addition 1874 * to the text added by the super implementation: 1875 * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 1876 * super.onPopulateAccessibilityEvent(event); 1877 * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; 1878 * String selectedDateUtterance = DateUtils.formatDateTime(mContext, 1879 * mCurrentDate.getTimeInMillis(), flags); 1880 * event.getText().add(selectedDateUtterance); 1881 * }</pre> 1882 * <p> 1883 * If an {@link AccessibilityDelegateCompat} has been specified via calling 1884 * {@link ViewCompat#setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 1885 * {@link AccessibilityDelegateCompat#onPopulateAccessibilityEvent(View, AccessibilityEvent)} 1886 * is responsible for handling this call. 1887 * </p> 1888 * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 1889 * information to the event, in case the default implementation has basic information to add. 1890 * </p> 1891 * 1892 * @param v The View against which to invoke the method. 1893 * @param event The accessibility event which to populate. 1894 * 1895 * @see View#sendAccessibilityEvent(int) 1896 * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 1897 */ 1898 public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1899 IMPL.onPopulateAccessibilityEvent(v, event); 1900 } 1901 1902 /** 1903 * Initializes an {@link AccessibilityEvent} with information about 1904 * this View which is the event source. In other words, the source of 1905 * an accessibility event is the view whose state change triggered firing 1906 * the event. 1907 * <p> 1908 * Example: Setting the password property of an event in addition 1909 * to properties set by the super implementation: 1910 * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 1911 * super.onInitializeAccessibilityEvent(event); 1912 * event.setPassword(true); 1913 * }</pre> 1914 * <p> 1915 * If an {@link AccessibilityDelegateCompat} has been specified via calling 1916 * {@link ViewCompat#setAccessibilityDelegate(View, AccessibilityDelegateCompat)}, its 1917 * {@link AccessibilityDelegateCompat#onInitializeAccessibilityEvent(View, AccessibilityEvent)} 1918 * is responsible for handling this call. 1919 * 1920 * @param v The View against which to invoke the method. 1921 * @param event The event to initialize. 1922 * 1923 * @see View#sendAccessibilityEvent(int) 1924 * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 1925 */ 1926 public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1927 IMPL.onInitializeAccessibilityEvent(v, event); 1928 } 1929 1930 /** 1931 * Initializes an {@link AccessibilityNodeInfoCompat} with information 1932 * about this view. The base implementation sets: 1933 * <ul> 1934 * <li>{@link AccessibilityNodeInfoCompat#setParent(View)},</li> 1935 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInParent(Rect)},</li> 1936 * <li>{@link AccessibilityNodeInfoCompat#setBoundsInScreen(Rect)},</li> 1937 * <li>{@link AccessibilityNodeInfoCompat#setPackageName(CharSequence)},</li> 1938 * <li>{@link AccessibilityNodeInfoCompat#setClassName(CharSequence)},</li> 1939 * <li>{@link AccessibilityNodeInfoCompat#setContentDescription(CharSequence)},</li> 1940 * <li>{@link AccessibilityNodeInfoCompat#setEnabled(boolean)},</li> 1941 * <li>{@link AccessibilityNodeInfoCompat#setClickable(boolean)},</li> 1942 * <li>{@link AccessibilityNodeInfoCompat#setFocusable(boolean)},</li> 1943 * <li>{@link AccessibilityNodeInfoCompat#setFocused(boolean)},</li> 1944 * <li>{@link AccessibilityNodeInfoCompat#setLongClickable(boolean)},</li> 1945 * <li>{@link AccessibilityNodeInfoCompat#setSelected(boolean)},</li> 1946 * </ul> 1947 * <p> 1948 * If an {@link AccessibilityDelegateCompat} has been specified via calling 1949 * {@link ViewCompat#setAccessibilityDelegate(View, AccessibilityDelegateCompat)}, its 1950 * {@link AccessibilityDelegateCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat)} 1951 * method is responsible for handling this call. 1952 * 1953 * @param v The View against which to invoke the method. 1954 * @param info The instance to initialize. 1955 */ 1956 public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 1957 IMPL.onInitializeAccessibilityNodeInfo(v, info); 1958 } 1959 1960 /** 1961 * Sets a delegate for implementing accessibility support via composition 1962 * (as opposed to inheritance). For more details, see 1963 * {@link AccessibilityDelegateCompat}. 1964 * <p> 1965 * On platform versions prior to API 14, this method is a no-op. 1966 * <p> 1967 * <strong>Note:</strong> On platform versions prior to 1968 * {@link android.os.Build.VERSION_CODES#M API 23}, delegate methods on 1969 * views in the {@code android.widget.*} package are called <i>before</i> 1970 * host methods. This prevents certain properties such as class name from 1971 * being modified by overriding 1972 * {@link AccessibilityDelegateCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat)}, 1973 * as any changes will be overwritten by the host class. 1974 * <p> 1975 * Starting in {@link android.os.Build.VERSION_CODES#M API 23}, delegate 1976 * methods are called <i>after</i> host methods, which all properties to be 1977 * modified without being overwritten by the host class. 1978 * 1979 * @param delegate the object to which accessibility method calls should be 1980 * delegated 1981 * @see AccessibilityDelegateCompat 1982 */ 1983 public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 1984 IMPL.setAccessibilityDelegate(v, delegate); 1985 } 1986 1987 /** 1988 * Checks whether provided View has an accessibility delegate attached to it. 1989 * 1990 * @param v The View instance to check 1991 * @return True if the View has an accessibility delegate 1992 */ 1993 public static boolean hasAccessibilityDelegate(View v) { 1994 return IMPL.hasAccessibilityDelegate(v); 1995 } 1996 1997 /** 1998 * Indicates whether the view is currently tracking transient state that the 1999 * app should not need to concern itself with saving and restoring, but that 2000 * the framework should take special note to preserve when possible. 2001 * 2002 * @param view View to check for transient state 2003 * @return true if the view has transient state 2004 */ 2005 public static boolean hasTransientState(View view) { 2006 return IMPL.hasTransientState(view); 2007 } 2008 2009 /** 2010 * Set whether this view is currently tracking transient state that the 2011 * framework should attempt to preserve when possible. 2012 * 2013 * @param view View tracking transient state 2014 * @param hasTransientState true if this view has transient state 2015 */ 2016 public static void setHasTransientState(View view, boolean hasTransientState) { 2017 IMPL.setHasTransientState(view, hasTransientState); 2018 } 2019 2020 /** 2021 * <p>Cause an invalidate to happen on the next animation time step, typically the 2022 * next display frame.</p> 2023 * 2024 * <p>This method can be invoked from outside of the UI thread 2025 * only when this View is attached to a window.</p> 2026 * 2027 * @param view View to invalidate 2028 */ 2029 public static void postInvalidateOnAnimation(View view) { 2030 IMPL.postInvalidateOnAnimation(view); 2031 } 2032 2033 /** 2034 * <p>Cause an invalidate of the specified area to happen on the next animation 2035 * time step, typically the next display frame.</p> 2036 * 2037 * <p>This method can be invoked from outside of the UI thread 2038 * only when this View is attached to a window.</p> 2039 * 2040 * @param view View to invalidate 2041 * @param left The left coordinate of the rectangle to invalidate. 2042 * @param top The top coordinate of the rectangle to invalidate. 2043 * @param right The right coordinate of the rectangle to invalidate. 2044 * @param bottom The bottom coordinate of the rectangle to invalidate. 2045 */ 2046 public static void postInvalidateOnAnimation(View view, int left, int top, 2047 int right, int bottom) { 2048 IMPL.postInvalidateOnAnimation(view, left, top, right, bottom); 2049 } 2050 2051 /** 2052 * <p>Causes the Runnable to execute on the next animation time step. 2053 * The runnable will be run on the user interface thread.</p> 2054 * 2055 * <p>This method can be invoked from outside of the UI thread 2056 * only when this View is attached to a window.</p> 2057 * 2058 * @param view View to post this Runnable to 2059 * @param action The Runnable that will be executed. 2060 */ 2061 public static void postOnAnimation(View view, Runnable action) { 2062 IMPL.postOnAnimation(view, action); 2063 } 2064 2065 /** 2066 * <p>Causes the Runnable to execute on the next animation time step, 2067 * after the specified amount of time elapses. 2068 * The runnable will be run on the user interface thread.</p> 2069 * 2070 * <p>This method can be invoked from outside of the UI thread 2071 * only when this View is attached to a window.</p> 2072 * 2073 * @param view The view to post this Runnable to 2074 * @param action The Runnable that will be executed. 2075 * @param delayMillis The delay (in milliseconds) until the Runnable 2076 * will be executed. 2077 */ 2078 public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 2079 IMPL.postOnAnimationDelayed(view, action, delayMillis); 2080 } 2081 2082 /** 2083 * Gets the mode for determining whether this View is important for accessibility 2084 * which is if it fires accessibility events and if it is reported to 2085 * accessibility services that query the screen. 2086 * 2087 * @param view The view whose property to get. 2088 * @return The mode for determining whether a View is important for accessibility. 2089 * 2090 * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 2091 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 2092 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 2093 * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 2094 */ 2095 @ImportantForAccessibility 2096 public static int getImportantForAccessibility(View view) { 2097 //noinspection ResourceType 2098 return IMPL.getImportantForAccessibility(view); 2099 } 2100 2101 /** 2102 * Sets how to determine whether this view is important for accessibility 2103 * which is if it fires accessibility events and if it is reported to 2104 * accessibility services that query the screen. 2105 * <p> 2106 * <em>Note:</em> If the current paltform version does not support the 2107 * {@link #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS} mode, then 2108 * {@link #IMPORTANT_FOR_ACCESSIBILITY_NO} will be used as it is the 2109 * closest terms of semantics. 2110 * </p> 2111 * 2112 * @param view The view whose property to set. 2113 * @param mode How to determine whether this view is important for accessibility. 2114 * 2115 * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 2116 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 2117 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 2118 * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 2119 */ 2120 public static void setImportantForAccessibility(View view, 2121 @ImportantForAccessibility int mode) { 2122 IMPL.setImportantForAccessibility(view, mode); 2123 } 2124 2125 /** 2126 * Performs the specified accessibility action on the view. For 2127 * possible accessibility actions look at {@link AccessibilityNodeInfoCompat}. 2128 * <p> 2129 * If an {@link AccessibilityDelegateCompat} has been specified via calling 2130 * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 2131 * {@link AccessibilityDelegateCompat#performAccessibilityAction(View, int, Bundle)} 2132 * is responsible for handling this call. 2133 * </p> 2134 * 2135 * @param action The action to perform. 2136 * @param arguments Optional action arguments. 2137 * @return Whether the action was performed. 2138 */ 2139 public static boolean performAccessibilityAction(View view, int action, Bundle arguments) { 2140 return IMPL.performAccessibilityAction(view, action, arguments); 2141 } 2142 2143 /** 2144 * Gets the provider for managing a virtual view hierarchy rooted at this View 2145 * and reported to {@link android.accessibilityservice.AccessibilityService}s 2146 * that explore the window content. 2147 * <p> 2148 * If this method returns an instance, this instance is responsible for managing 2149 * {@link AccessibilityNodeInfoCompat}s describing the virtual sub-tree rooted at 2150 * this View including the one representing the View itself. Similarly the returned 2151 * instance is responsible for performing accessibility actions on any virtual 2152 * view or the root view itself. 2153 * </p> 2154 * <p> 2155 * If an {@link AccessibilityDelegateCompat} has been specified via calling 2156 * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 2157 * {@link AccessibilityDelegateCompat#getAccessibilityNodeProvider(View)} 2158 * is responsible for handling this call. 2159 * </p> 2160 * 2161 * @param view The view whose property to get. 2162 * @return The provider. 2163 * 2164 * @see AccessibilityNodeProviderCompat 2165 */ 2166 public static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 2167 return IMPL.getAccessibilityNodeProvider(view); 2168 } 2169 2170 /** 2171 * The opacity of the view. This is a value from 0 to 1, where 0 means the view is 2172 * completely transparent and 1 means the view is completely opaque. 2173 * 2174 * <p>By default this is 1.0f. Prior to API 11, the returned value is always 1.0f. 2175 * @return The opacity of the view. 2176 */ 2177 public static float getAlpha(View view) { 2178 return IMPL.getAlpha(view); 2179 } 2180 2181 /** 2182 * <p>Specifies the type of layer backing this view. The layer can be 2183 * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or 2184 * {@link #LAYER_TYPE_HARDWARE hardware}.</p> 2185 * 2186 * <p>A layer is associated with an optional {@link android.graphics.Paint} 2187 * instance that controls how the layer is composed on screen. The following 2188 * properties of the paint are taken into account when composing the layer:</p> 2189 * <ul> 2190 * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> 2191 * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> 2192 * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> 2193 * </ul> 2194 * 2195 * <p>If this view has an alpha value set to < 1.0 by calling 2196 * setAlpha(float), the alpha value of the layer's paint is replaced by 2197 * this view's alpha value. Calling setAlpha(float) is therefore 2198 * equivalent to setting a hardware layer on this view and providing a paint with 2199 * the desired alpha value.<p> 2200 * 2201 * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, 2202 * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} 2203 * for more information on when and how to use layers.</p> 2204 * 2205 * @param view View to set the layer type for 2206 * @param layerType The type of layer to use with this view, must be one of 2207 * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or 2208 * {@link #LAYER_TYPE_HARDWARE} 2209 * @param paint The paint used to compose the layer. This argument is optional 2210 * and can be null. It is ignored when the layer type is 2211 * {@link #LAYER_TYPE_NONE} 2212 */ 2213 public static void setLayerType(View view, @LayerType int layerType, Paint paint) { 2214 IMPL.setLayerType(view, layerType, paint); 2215 } 2216 2217 /** 2218 * Indicates what type of layer is currently associated with this view. By default 2219 * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. 2220 * Refer to the documentation of 2221 * {@link #setLayerType(android.view.View, int, android.graphics.Paint)} 2222 * for more information on the different types of layers. 2223 * 2224 * @param view The view to fetch the layer type from 2225 * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or 2226 * {@link #LAYER_TYPE_HARDWARE} 2227 * 2228 * @see #setLayerType(android.view.View, int, android.graphics.Paint) 2229 * @see #LAYER_TYPE_NONE 2230 * @see #LAYER_TYPE_SOFTWARE 2231 * @see #LAYER_TYPE_HARDWARE 2232 */ 2233 @LayerType 2234 public static int getLayerType(View view) { 2235 //noinspection ResourceType 2236 return IMPL.getLayerType(view); 2237 } 2238 2239 /** 2240 * Gets the id of a view for which a given view serves as a label for 2241 * accessibility purposes. 2242 * 2243 * @param view The view on which to invoke the corresponding method. 2244 * @return The labeled view id. 2245 */ 2246 public static int getLabelFor(View view) { 2247 return IMPL.getLabelFor(view); 2248 } 2249 2250 /** 2251 * Sets the id of a view for which a given view serves as a label for 2252 * accessibility purposes. 2253 * 2254 * @param view The view on which to invoke the corresponding method. 2255 * @param labeledId The labeled view id. 2256 */ 2257 public static void setLabelFor(View view, @IdRes int labeledId) { 2258 IMPL.setLabelFor(view, labeledId); 2259 } 2260 2261 /** 2262 * Updates the {@link Paint} object used with the current layer (used only if the current 2263 * layer type is not set to {@link #LAYER_TYPE_NONE}). Changed properties of the Paint 2264 * provided to {@link #setLayerType(android.view.View, int, android.graphics.Paint)} 2265 * will be used the next time the View is redrawn, but 2266 * {@link #setLayerPaint(android.view.View, android.graphics.Paint)} 2267 * must be called to ensure that the view gets redrawn immediately. 2268 * 2269 * <p>A layer is associated with an optional {@link android.graphics.Paint} 2270 * instance that controls how the layer is composed on screen. The following 2271 * properties of the paint are taken into account when composing the layer:</p> 2272 * <ul> 2273 * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> 2274 * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> 2275 * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> 2276 * </ul> 2277 * 2278 * <p>If this view has an alpha value set to < 1.0 by calling 2279 * View#setAlpha(float), the alpha value of the layer's paint is replaced by 2280 * this view's alpha value. Calling View#setAlpha(float) is therefore 2281 * equivalent to setting a hardware layer on this view and providing a paint with 2282 * the desired alpha value.</p> 2283 * 2284 * @param view View to set a layer paint for 2285 * @param paint The paint used to compose the layer. This argument is optional 2286 * and can be null. It is ignored when the layer type is 2287 * {@link #LAYER_TYPE_NONE} 2288 * 2289 * @see #setLayerType(View, int, android.graphics.Paint) 2290 */ 2291 public static void setLayerPaint(View view, Paint paint) { 2292 IMPL.setLayerPaint(view, paint); 2293 } 2294 2295 /** 2296 * Returns the resolved layout direction for this view. 2297 * 2298 * @param view View to get layout direction for 2299 * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns 2300 * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. 2301 * 2302 * For compatibility, this will return {@link #LAYOUT_DIRECTION_LTR} if API version 2303 * is lower than Jellybean MR1 (API 17) 2304 */ 2305 @ResolvedLayoutDirectionMode 2306 public static int getLayoutDirection(View view) { 2307 //noinspection ResourceType 2308 return IMPL.getLayoutDirection(view); 2309 } 2310 2311 /** 2312 * Set the layout direction for this view. This will propagate a reset of layout direction 2313 * resolution to the view's children and resolve layout direction for this view. 2314 * 2315 * @param view View to set layout direction for 2316 * @param layoutDirection the layout direction to set. Should be one of: 2317 * 2318 * {@link #LAYOUT_DIRECTION_LTR}, 2319 * {@link #LAYOUT_DIRECTION_RTL}, 2320 * {@link #LAYOUT_DIRECTION_INHERIT}, 2321 * {@link #LAYOUT_DIRECTION_LOCALE}. 2322 * 2323 * Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution 2324 * proceeds up the parent chain of the view to get the value. If there is no parent, then it 2325 * will return the default {@link #LAYOUT_DIRECTION_LTR}. 2326 */ 2327 public static void setLayoutDirection(View view, @LayoutDirectionMode int layoutDirection) { 2328 IMPL.setLayoutDirection(view, layoutDirection); 2329 } 2330 2331 /** 2332 * Gets the parent for accessibility purposes. Note that the parent for 2333 * accessibility is not necessary the immediate parent. It is the first 2334 * predecessor that is important for accessibility. 2335 * 2336 * @param view View to retrieve parent for 2337 * @return The parent for use in accessibility inspection 2338 */ 2339 public static ViewParent getParentForAccessibility(View view) { 2340 return IMPL.getParentForAccessibility(view); 2341 } 2342 2343 /** 2344 * Indicates whether this View is opaque. An opaque View guarantees that it will 2345 * draw all the pixels overlapping its bounds using a fully opaque color. 2346 * 2347 * @return True if this View is guaranteed to be fully opaque, false otherwise. 2348 * @deprecated Use {@link View#isOpaque()} directly. 2349 */ 2350 @Deprecated 2351 public static boolean isOpaque(View view) { 2352 return view.isOpaque(); 2353 } 2354 2355 /** 2356 * Utility to reconcile a desired size and state, with constraints imposed 2357 * by a MeasureSpec. Will take the desired size, unless a different size 2358 * is imposed by the constraints. The returned value is a compound integer, 2359 * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and 2360 * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting 2361 * size is smaller than the size the view wants to be. 2362 * 2363 * @param size How big the view wants to be 2364 * @param measureSpec Constraints imposed by the parent 2365 * @return Size information bit mask as defined by 2366 * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. 2367 */ 2368 public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 2369 return IMPL.resolveSizeAndState(size, measureSpec, childMeasuredState); 2370 } 2371 2372 /** 2373 * Return the full width measurement information for this view as computed 2374 * by the most recent call to {@link android.view.View#measure(int, int)}. 2375 * This result is a bit mask as defined by {@link #MEASURED_SIZE_MASK} and 2376 * {@link #MEASURED_STATE_TOO_SMALL}. 2377 * This should be used during measurement and layout calculations only. Use 2378 * {@link android.view.View#getWidth()} to see how wide a view is after layout. 2379 * 2380 * @return The measured width of this view as a bit mask. 2381 */ 2382 public static int getMeasuredWidthAndState(View view) { 2383 return IMPL.getMeasuredWidthAndState(view); 2384 } 2385 2386 /** 2387 * Return the full height measurement information for this view as computed 2388 * by the most recent call to {@link android.view.View#measure(int, int)}. 2389 * This result is a bit mask as defined by {@link #MEASURED_SIZE_MASK} and 2390 * {@link #MEASURED_STATE_TOO_SMALL}. 2391 * This should be used during measurement and layout calculations only. Use 2392 * {@link android.view.View#getHeight()} to see how wide a view is after layout. 2393 * 2394 * @return The measured width of this view as a bit mask. 2395 */ 2396 public static int getMeasuredHeightAndState(View view) { 2397 return IMPL.getMeasuredHeightAndState(view); 2398 } 2399 2400 /** 2401 * Return only the state bits of {@link #getMeasuredWidthAndState} 2402 * and {@link #getMeasuredHeightAndState}, combined into one integer. 2403 * The width component is in the regular bits {@link #MEASURED_STATE_MASK} 2404 * and the height component is at the shifted bits 2405 * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. 2406 */ 2407 public static int getMeasuredState(View view) { 2408 return IMPL.getMeasuredState(view); 2409 } 2410 2411 /** 2412 * Merge two states as returned by {@link #getMeasuredState(View)}. 2413 * @param curState The current state as returned from a view or the result 2414 * of combining multiple views. 2415 * @param newState The new view state to combine. 2416 * @return Returns a new integer reflecting the combination of the two 2417 * states. 2418 */ 2419 public static int combineMeasuredStates(int curState, int newState) { 2420 return IMPL.combineMeasuredStates(curState, newState); 2421 } 2422 2423 /** 2424 * Gets the live region mode for the specified View. 2425 * 2426 * @param view The view from which to obtain the live region mode 2427 * @return The live region mode for the view. 2428 * 2429 * @see ViewCompat#setAccessibilityLiveRegion(View, int) 2430 */ 2431 @AccessibilityLiveRegion 2432 public static int getAccessibilityLiveRegion(View view) { 2433 //noinspection ResourceType 2434 return IMPL.getAccessibilityLiveRegion(view); 2435 } 2436 2437 /** 2438 * Sets the live region mode for the specified view. This indicates to 2439 * accessibility services whether they should automatically notify the user 2440 * about changes to the view's content description or text, or to the 2441 * content descriptions or text of the view's children (where applicable). 2442 * <p> 2443 * For example, in a login screen with a TextView that displays an "incorrect 2444 * password" notification, that view should be marked as a live region with 2445 * mode {@link #ACCESSIBILITY_LIVE_REGION_POLITE}. 2446 * <p> 2447 * To disable change notifications for this view, use 2448 * {@link #ACCESSIBILITY_LIVE_REGION_NONE}. This is the default live region 2449 * mode for most views. 2450 * <p> 2451 * To indicate that the user should be notified of changes, use 2452 * {@link #ACCESSIBILITY_LIVE_REGION_POLITE}. 2453 * <p> 2454 * If the view's changes should interrupt ongoing speech and notify the user 2455 * immediately, use {@link #ACCESSIBILITY_LIVE_REGION_ASSERTIVE}. 2456 * 2457 * @param view The view on which to set the live region mode 2458 * @param mode The live region mode for this view, one of: 2459 * <ul> 2460 * <li>{@link #ACCESSIBILITY_LIVE_REGION_NONE} 2461 * <li>{@link #ACCESSIBILITY_LIVE_REGION_POLITE} 2462 * <li>{@link #ACCESSIBILITY_LIVE_REGION_ASSERTIVE} 2463 * </ul> 2464 */ 2465 public static void setAccessibilityLiveRegion(View view, @AccessibilityLiveRegion int mode) { 2466 IMPL.setAccessibilityLiveRegion(view, mode); 2467 } 2468 2469 /** 2470 * Returns the start padding of the specified view depending on its resolved layout direction. 2471 * If there are inset and enabled scrollbars, this value may include the space 2472 * required to display the scrollbars as well. 2473 * 2474 * @param view The view to get padding for 2475 * @return the start padding in pixels 2476 */ 2477 public static int getPaddingStart(View view) { 2478 return IMPL.getPaddingStart(view); 2479 } 2480 2481 /** 2482 * Returns the end padding of the specified view depending on its resolved layout direction. 2483 * If there are inset and enabled scrollbars, this value may include the space 2484 * required to display the scrollbars as well. 2485 * 2486 * @param view The view to get padding for 2487 * @return the end padding in pixels 2488 */ 2489 public static int getPaddingEnd(View view) { 2490 return IMPL.getPaddingEnd(view); 2491 } 2492 2493 /** 2494 * Sets the relative padding. The view may add on the space required to display 2495 * the scrollbars, depending on the style and visibility of the scrollbars. 2496 * So the values returned from {@link #getPaddingStart}, {@link View#getPaddingTop}, 2497 * {@link #getPaddingEnd} and {@link View#getPaddingBottom} may be different 2498 * from the values set in this call. 2499 * 2500 * @param view The view on which to set relative padding 2501 * @param start the start padding in pixels 2502 * @param top the top padding in pixels 2503 * @param end the end padding in pixels 2504 * @param bottom the bottom padding in pixels 2505 */ 2506 public static void setPaddingRelative(View view, int start, int top, int end, int bottom) { 2507 IMPL.setPaddingRelative(view, start, top, end, bottom); 2508 } 2509 2510 /** 2511 * Notify a view that it is being temporarily detached. 2512 */ 2513 public static void dispatchStartTemporaryDetach(View view) { 2514 IMPL.dispatchStartTemporaryDetach(view); 2515 } 2516 2517 /** 2518 * Notify a view that its temporary detach has ended; the view is now reattached. 2519 */ 2520 public static void dispatchFinishTemporaryDetach(View view) { 2521 IMPL.dispatchFinishTemporaryDetach(view); 2522 } 2523 2524 /** 2525 * The horizontal location of this view relative to its {@link View#getLeft() left} position. 2526 * This position is post-layout, in addition to wherever the object's 2527 * layout placed it. 2528 * 2529 * <p>Prior to API 11 this will return 0.</p> 2530 * 2531 * @return The horizontal position of this view relative to its left position, in pixels. 2532 */ 2533 public static float getTranslationX(View view) { 2534 return IMPL.getTranslationX(view); 2535 } 2536 2537 /** 2538 * The vertical location of this view relative to its {@link View#getTop() top} position. 2539 * This position is post-layout, in addition to wherever the object's 2540 * layout placed it. 2541 * 2542 * <p>Prior to API 11 this will return 0.</p> 2543 * 2544 * @return The vertical position of this view relative to its top position, in pixels. 2545 */ 2546 public static float getTranslationY(View view) { 2547 return IMPL.getTranslationY(view); 2548 } 2549 2550 /** 2551 * The transform matrix of this view, which is calculated based on the current 2552 * rotation, scale, and pivot properties. 2553 * <p> 2554 * Prior to 11, this method will return {@code null}. 2555 * 2556 * @param view The view whose Matrix will be returned 2557 * @return The current transform matrix for the view 2558 * 2559 * @see #getRotation(View) 2560 * @see #getScaleX(View) 2561 * @see #getScaleY(View) 2562 * @see #getPivotX(View) 2563 * @see #getPivotY(View) 2564 */ 2565 @Nullable 2566 public static Matrix getMatrix(View view) { 2567 return IMPL.getMatrix(view); 2568 } 2569 2570 /** 2571 * Returns the minimum width of the view. 2572 * 2573 * <p>Prior to API 16 this will return 0.</p> 2574 * 2575 * @return the minimum width the view will try to be. 2576 */ 2577 public static int getMinimumWidth(View view) { 2578 return IMPL.getMinimumWidth(view); 2579 } 2580 2581 /** 2582 * Returns the minimum height of the view. 2583 * 2584 * <p>Prior to API 16 this will return 0.</p> 2585 * 2586 * @return the minimum height the view will try to be. 2587 */ 2588 public static int getMinimumHeight(View view) { 2589 return IMPL.getMinimumHeight(view); 2590 } 2591 2592 /** 2593 * This method returns a ViewPropertyAnimator object, which can be used to animate 2594 * specific properties on this View. 2595 * 2596 * <p>Prior to API 14, this method will do nothing.</p> 2597 * 2598 * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. 2599 */ 2600 public static ViewPropertyAnimatorCompat animate(View view) { 2601 return IMPL.animate(view); 2602 } 2603 2604 /** 2605 * Sets the horizontal location of this view relative to its left position. 2606 * This effectively positions the object post-layout, in addition to wherever the object's 2607 * layout placed it. 2608 * 2609 * <p>Prior to API 11 this will have no effect.</p> 2610 * 2611 * @param value The horizontal position of this view relative to its left position, 2612 * in pixels. 2613 */ 2614 public static void setTranslationX(View view, float value) { 2615 IMPL.setTranslationX(view, value); 2616 } 2617 2618 /** 2619 * Sets the vertical location of this view relative to its top position. 2620 * This effectively positions the object post-layout, in addition to wherever the object's 2621 * layout placed it. 2622 * 2623 * <p>Prior to API 11 this will have no effect.</p> 2624 * 2625 * @param value The vertical position of this view relative to its top position, 2626 * in pixels. 2627 * 2628 * @attr name android:translationY 2629 */ 2630 public static void setTranslationY(View view, float value) { 2631 IMPL.setTranslationY(view, value); 2632 } 2633 2634 /** 2635 * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is 2636 * completely transparent and 1 means the view is completely opaque.</p> 2637 * 2638 * <p> Note that setting alpha to a translucent value (0 < alpha < 1) can have significant 2639 * performance implications, especially for large views. It is best to use the alpha property 2640 * sparingly and transiently, as in the case of fading animations.</p> 2641 * 2642 * <p>Prior to API 11 this will have no effect.</p> 2643 * 2644 * @param value The opacity of the view. 2645 */ 2646 public static void setAlpha(View view, @FloatRange(from=0.0, to=1.0) float value) { 2647 IMPL.setAlpha(view, value); 2648 } 2649 2650 /** 2651 * Sets the visual x position of this view, in pixels. This is equivalent to setting the 2652 * {@link #setTranslationX(View, float) translationX} property to be the difference between 2653 * the x value passed in and the current left property of the view as determined 2654 * by the layout bounds. 2655 * 2656 * <p>Prior to API 11 this will have no effect.</p> 2657 * 2658 * @param value The visual x position of this view, in pixels. 2659 */ 2660 public static void setX(View view, float value) { 2661 IMPL.setX(view, value); 2662 } 2663 2664 /** 2665 * Sets the visual y position of this view, in pixels. This is equivalent to setting the 2666 * {@link #setTranslationY(View, float) translationY} property to be the difference between 2667 * the y value passed in and the current top property of the view as determined by the 2668 * layout bounds. 2669 * 2670 * <p>Prior to API 11 this will have no effect.</p> 2671 * 2672 * @param value The visual y position of this view, in pixels. 2673 */ 2674 public static void setY(View view, float value) { 2675 IMPL.setY(view, value); 2676 } 2677 2678 /** 2679 * Sets the degrees that the view is rotated around the pivot point. Increasing values 2680 * result in clockwise rotation. 2681 * 2682 * <p>Prior to API 11 this will have no effect.</p> 2683 * 2684 * @param value The degrees of rotation. 2685 */ 2686 public static void setRotation(View view, float value) { 2687 IMPL.setRotation(view, value); 2688 } 2689 2690 /** 2691 * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. 2692 * Increasing values result in clockwise rotation from the viewpoint of looking down the 2693 * x axis. 2694 * 2695 * <p>Prior to API 11 this will have no effect.</p> 2696 * 2697 * @param value The degrees of X rotation. 2698 */ 2699 public static void setRotationX(View view, float value) { 2700 IMPL.setRotationX(view, value); 2701 } 2702 2703 /** 2704 * Sets the degrees that the view is rotated around the vertical axis through the pivot point. 2705 * Increasing values result in counter-clockwise rotation from the viewpoint of looking 2706 * down the y axis. 2707 * 2708 * <p>Prior to API 11 this will have no effect.</p> 2709 * 2710 * @param value The degrees of Y rotation. 2711 */ 2712 public static void setRotationY(View view, float value) { 2713 IMPL.setRotationY(view, value); 2714 } 2715 2716 /** 2717 * Sets the amount that the view is scaled in x around the pivot point, as a proportion of 2718 * the view's unscaled width. A value of 1 means that no scaling is applied. 2719 * 2720 * <p>Prior to API 11 this will have no effect.</p> 2721 * 2722 * @param value The scaling factor. 2723 */ 2724 public static void setScaleX(View view, float value) { 2725 IMPL.setScaleX(view, value); 2726 } 2727 2728 /** 2729 * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of 2730 * the view's unscaled width. A value of 1 means that no scaling is applied. 2731 * 2732 * <p>Prior to API 11 this will have no effect.</p> 2733 * 2734 * @param value The scaling factor. 2735 */ 2736 public static void setScaleY(View view, float value) { 2737 IMPL.setScaleY(view, value); 2738 } 2739 2740 /** 2741 * The x location of the point around which the view is 2742 * {@link #setRotation(View, float) rotated} and {@link #setScaleX(View, float) scaled}. 2743 * 2744 * <p>Prior to API 11 this will have no effect.</p> 2745 * 2746 */ 2747 public static float getPivotX(View view) { 2748 return IMPL.getPivotX(view); 2749 } 2750 2751 /** 2752 * Sets the x location of the point around which the view is 2753 * {@link #setRotation(View, float) rotated} and {@link #setScaleX(View, float) scaled}. 2754 * By default, the pivot point is centered on the object. 2755 * Setting this property disables this behavior and causes the view to use only the 2756 * explicitly set pivotX and pivotY values. 2757 * 2758 * <p>Prior to API 11 this will have no effect.</p> 2759 * 2760 * @param value The x location of the pivot point. 2761 */ 2762 public static void setPivotX(View view, float value) { 2763 IMPL.setPivotX(view, value); 2764 } 2765 2766 /** 2767 * The y location of the point around which the view is {@link #setRotation(View, 2768 * float) rotated} and {@link #setScaleY(View, float) scaled}. 2769 * 2770 * <p>Prior to API 11 this will return 0.</p> 2771 * 2772 * @return The y location of the pivot point. 2773 */ 2774 public static float getPivotY(View view) { 2775 return IMPL.getPivotY(view); 2776 } 2777 2778 /** 2779 * Sets the y location of the point around which the view is 2780 * {@link #setRotation(View, float) rotated} and {@link #setScaleY(View, float) scaled}. 2781 * By default, the pivot point is centered on the object. 2782 * Setting this property disables this behavior and causes the view to use only the 2783 * explicitly set pivotX and pivotY values. 2784 * 2785 * <p>Prior to API 11 this will have no effect.</p> 2786 * 2787 * @param value The y location of the pivot point. 2788 */ 2789 public static void setPivotY(View view, float value) { 2790 IMPL.setPivotY(view, value); 2791 } 2792 2793 public static float getRotation(View view) { 2794 return IMPL.getRotation(view); 2795 } 2796 2797 public static float getRotationX(View view) { 2798 return IMPL.getRotationX(view); 2799 } 2800 2801 public static float getRotationY(View view) { 2802 return IMPL.getRotationY(view); 2803 } 2804 2805 public static float getScaleX(View view) { 2806 return IMPL.getScaleX(view); 2807 } 2808 2809 public static float getScaleY(View view) { 2810 return IMPL.getScaleY(view); 2811 } 2812 2813 public static float getX(View view) { 2814 return IMPL.getX(view); 2815 } 2816 2817 public static float getY(View view) { 2818 return IMPL.getY(view); 2819 } 2820 2821 /** 2822 * Sets the base elevation of this view, in pixels. 2823 */ 2824 public static void setElevation(View view, float elevation) { 2825 IMPL.setElevation(view, elevation); 2826 } 2827 2828 /** 2829 * The base elevation of this view relative to its parent, in pixels. 2830 * 2831 * @return The base depth position of the view, in pixels. 2832 */ 2833 public static float getElevation(View view) { 2834 return IMPL.getElevation(view); 2835 } 2836 2837 /** 2838 * Sets the depth location of this view relative to its {@link #getElevation(View) elevation}. 2839 */ 2840 public static void setTranslationZ(View view, float translationZ) { 2841 IMPL.setTranslationZ(view, translationZ); 2842 } 2843 2844 /** 2845 * The depth location of this view relative to its {@link #getElevation(View) elevation}. 2846 * 2847 * @return The depth of this view relative to its elevation. 2848 */ 2849 public static float getTranslationZ(View view) { 2850 return IMPL.getTranslationZ(view); 2851 } 2852 2853 /** 2854 * Sets the name of the View to be used to identify Views in Transitions. 2855 * Names should be unique in the View hierarchy. 2856 * 2857 * @param view The View against which to invoke the method. 2858 * @param transitionName The name of the View to uniquely identify it for Transitions. 2859 */ 2860 public static void setTransitionName(View view, String transitionName) { 2861 IMPL.setTransitionName(view, transitionName); 2862 } 2863 2864 /** 2865 * Returns the name of the View to be used to identify Views in Transitions. 2866 * Names should be unique in the View hierarchy. 2867 * 2868 * <p>This returns null if the View has not been given a name.</p> 2869 * 2870 * @param view The View against which to invoke the method. 2871 * @return The name used of the View to be used to identify Views in Transitions or null 2872 * if no name has been given. 2873 */ 2874 public static String getTransitionName(View view) { 2875 return IMPL.getTransitionName(view); 2876 } 2877 2878 /** 2879 * Returns the current system UI visibility that is currently set for the entire window. 2880 */ 2881 public static int getWindowSystemUiVisibility(View view) { 2882 return IMPL.getWindowSystemUiVisibility(view); 2883 } 2884 2885 /** 2886 * Ask that a new dispatch of {@code View.onApplyWindowInsets(WindowInsets)} be performed. This 2887 * falls back to {@code View.requestFitSystemWindows()} where available. 2888 */ 2889 public static void requestApplyInsets(View view) { 2890 IMPL.requestApplyInsets(view); 2891 } 2892 2893 /** 2894 * Tells the ViewGroup whether to draw its children in the order defined by the method 2895 * {@code ViewGroup.getChildDrawingOrder(int, int)}. 2896 * 2897 * @param enabled true if the order of the children when drawing is determined by 2898 * {@link ViewGroup#getChildDrawingOrder(int, int)}, false otherwise 2899 * 2900 * <p>Prior to API 7 this will have no effect.</p> 2901 */ 2902 public static void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled) { 2903 IMPL.setChildrenDrawingOrderEnabled(viewGroup, enabled); 2904 } 2905 2906 /** 2907 * Returns true if this view should adapt to fit system window insets. This method will always 2908 * return false before API 16 (Jellybean). 2909 */ 2910 public static boolean getFitsSystemWindows(View v) { 2911 return IMPL.getFitsSystemWindows(v); 2912 } 2913 2914 /** 2915 * Sets whether or not this view should account for system screen decorations 2916 * such as the status bar and inset its content; that is, controlling whether 2917 * the default implementation of {@link View#fitSystemWindows(Rect)} will be 2918 * executed. See that method for more details. 2919 */ 2920 public static void setFitsSystemWindows(View view, boolean fitSystemWindows) { 2921 IMPL.setFitsSystemWindows(view, fitSystemWindows); 2922 } 2923 2924 /** 2925 * On API 11 devices and above, call <code>Drawable.jumpToCurrentState()</code> 2926 * on all Drawable objects associated with this view. 2927 * <p> 2928 * On API 21 and above, also calls <code>StateListAnimator#jumpToCurrentState()</code> 2929 * if there is a StateListAnimator attached to this view. 2930 */ 2931 public static void jumpDrawablesToCurrentState(View v) { 2932 IMPL.jumpDrawablesToCurrentState(v); 2933 } 2934 2935 /** 2936 * Set an {@link OnApplyWindowInsetsListener} to take over the policy for applying 2937 * window insets to this view. This will only take effect on devices with API 21 or above. 2938 */ 2939 public static void setOnApplyWindowInsetsListener(View v, 2940 OnApplyWindowInsetsListener listener) { 2941 IMPL.setOnApplyWindowInsetsListener(v, listener); 2942 } 2943 2944 /** 2945 * Called when the view should apply {@link WindowInsetsCompat} according to its internal policy. 2946 * 2947 * <p>Clients may supply an {@link OnApplyWindowInsetsListener} to a view. If one is set 2948 * it will be called during dispatch instead of this method. The listener may optionally 2949 * call this method from its own implementation if it wishes to apply the view's default 2950 * insets policy in addition to its own.</p> 2951 * 2952 * @param view The View against which to invoke the method. 2953 * @param insets Insets to apply 2954 * @return The supplied insets with any applied insets consumed 2955 */ 2956 public static WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat insets) { 2957 return IMPL.onApplyWindowInsets(view, insets); 2958 } 2959 2960 /** 2961 * Request to apply the given window insets to this view or another view in its subtree. 2962 * 2963 * <p>This method should be called by clients wishing to apply insets corresponding to areas 2964 * obscured by window decorations or overlays. This can include the status and navigation bars, 2965 * action bars, input methods and more. New inset categories may be added in the future. 2966 * The method returns the insets provided minus any that were applied by this view or its 2967 * children.</p> 2968 * 2969 * @param insets Insets to apply 2970 * @return The provided insets minus the insets that were consumed 2971 */ 2972 public static WindowInsetsCompat dispatchApplyWindowInsets(View view, 2973 WindowInsetsCompat insets) { 2974 return IMPL.dispatchApplyWindowInsets(view, insets); 2975 } 2976 2977 /** 2978 * Controls whether the entire hierarchy under this view will save its 2979 * state when a state saving traversal occurs from its parent. 2980 * 2981 * @param enabled Set to false to <em>disable</em> state saving, or true 2982 * (the default) to allow it. 2983 */ 2984 public static void setSaveFromParentEnabled(View v, boolean enabled) { 2985 IMPL.setSaveFromParentEnabled(v, enabled); 2986 } 2987 2988 /** 2989 * Changes the activated state of this view. A view can be activated or not. 2990 * Note that activation is not the same as selection. Selection is 2991 * a transient property, representing the view (hierarchy) the user is 2992 * currently interacting with. Activation is a longer-term state that the 2993 * user can move views in and out of. 2994 * 2995 * @param activated true if the view must be activated, false otherwise 2996 */ 2997 public static void setActivated(View view, boolean activated) { 2998 IMPL.setActivated(view, activated); 2999 } 3000 3001 /** 3002 * Returns whether this View has content which overlaps. 3003 * 3004 * <p>This function, intended to be overridden by specific View types, is an optimization when 3005 * alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to 3006 * an offscreen buffer and then composited into place, which can be expensive. If the view has 3007 * no overlapping rendering, the view can draw each primitive with the appropriate alpha value 3008 * directly. An example of overlapping rendering is a TextView with a background image, such as 3009 * a Button. An example of non-overlapping rendering is a TextView with no background, or an 3010 * ImageView with only the foreground image. The default implementation returns true; subclasses 3011 * should override if they have cases which can be optimized.</p> 3012 * 3013 * @return true if the content in this view might overlap, false otherwise. 3014 */ 3015 public static boolean hasOverlappingRendering(View view) { 3016 return IMPL.hasOverlappingRendering(view); 3017 } 3018 3019 /** 3020 * Return if the padding as been set through relative values 3021 * {@code View.setPaddingRelative(int, int, int, int)} or thru 3022 * 3023 * @return true if the padding is relative or false if it is not. 3024 */ 3025 public static boolean isPaddingRelative(View view) { 3026 return IMPL.isPaddingRelative(view); 3027 } 3028 3029 /** 3030 * Return the tint applied to the background drawable, if specified. 3031 * <p> 3032 * Only returns meaningful info when running on API v21 or newer, or if {@code view} 3033 * implements the {@code TintableBackgroundView} interface. 3034 */ 3035 public static ColorStateList getBackgroundTintList(View view) { 3036 return IMPL.getBackgroundTintList(view); 3037 } 3038 3039 /** 3040 * Applies a tint to the background drawable. 3041 * <p> 3042 * This will always take effect when running on API v21 or newer. When running on platforms 3043 * previous to API v21, it will only take effect if {@code view} implement the 3044 * {@code TintableBackgroundView} interface. 3045 */ 3046 public static void setBackgroundTintList(View view, ColorStateList tintList) { 3047 IMPL.setBackgroundTintList(view, tintList); 3048 } 3049 3050 /** 3051 * Return the blending mode used to apply the tint to the background 3052 * drawable, if specified. 3053 * <p> 3054 * Only returns meaningful info when running on API v21 or newer, or if {@code view} 3055 * implements the {@code TintableBackgroundView} interface. 3056 */ 3057 public static PorterDuff.Mode getBackgroundTintMode(View view) { 3058 return IMPL.getBackgroundTintMode(view); 3059 } 3060 3061 /** 3062 * Specifies the blending mode used to apply the tint specified by 3063 * {@link #setBackgroundTintList(android.view.View, android.content.res.ColorStateList)} to 3064 * the background drawable. The default mode is {@link PorterDuff.Mode#SRC_IN}. 3065 * <p> 3066 * This will always take effect when running on API v21 or newer. When running on platforms 3067 * previous to API v21, it will only take effect if {@code view} implement the 3068 * {@code TintableBackgroundView} interface. 3069 */ 3070 public static void setBackgroundTintMode(View view, PorterDuff.Mode mode) { 3071 IMPL.setBackgroundTintMode(view, mode); 3072 } 3073 // TODO: getters for various view properties (rotation, etc) 3074 3075 /** 3076 * Enable or disable nested scrolling for this view. 3077 * 3078 * <p>If this property is set to true the view will be permitted to initiate nested 3079 * scrolling operations with a compatible parent view in the current hierarchy. If this 3080 * view does not implement nested scrolling this will have no effect. Disabling nested scrolling 3081 * while a nested scroll is in progress has the effect of 3082 * {@link #stopNestedScroll(View) stopping} the nested scroll.</p> 3083 * 3084 * @param enabled true to enable nested scrolling, false to disable 3085 * 3086 * @see #isNestedScrollingEnabled(View) 3087 */ 3088 public static void setNestedScrollingEnabled(View view, boolean enabled) { 3089 IMPL.setNestedScrollingEnabled(view, enabled); 3090 } 3091 3092 /** 3093 * Returns true if nested scrolling is enabled for this view. 3094 * 3095 * <p>If nested scrolling is enabled and this View class implementation supports it, 3096 * this view will act as a nested scrolling child view when applicable, forwarding data 3097 * about the scroll operation in progress to a compatible and cooperating nested scrolling 3098 * parent.</p> 3099 * 3100 * @return true if nested scrolling is enabled 3101 * 3102 * @see #setNestedScrollingEnabled(View, boolean) 3103 */ 3104 public static boolean isNestedScrollingEnabled(View view) { 3105 return IMPL.isNestedScrollingEnabled(view); 3106 } 3107 3108 /** 3109 * Begin a nestable scroll operation along the given axes. 3110 * 3111 * <p>A view starting a nested scroll promises to abide by the following contract:</p> 3112 * 3113 * <p>The view will call startNestedScroll upon initiating a scroll operation. In the case 3114 * of a touch scroll this corresponds to the initial {@link MotionEvent#ACTION_DOWN}. 3115 * In the case of touch scrolling the nested scroll will be terminated automatically in 3116 * the same manner as {@link ViewParent#requestDisallowInterceptTouchEvent(boolean)}. 3117 * In the event of programmatic scrolling the caller must explicitly call 3118 * {@link #stopNestedScroll(View)} to indicate the end of the nested scroll.</p> 3119 * 3120 * <p>If <code>startNestedScroll</code> returns true, a cooperative parent was found. 3121 * If it returns false the caller may ignore the rest of this contract until the next scroll. 3122 * Calling startNestedScroll while a nested scroll is already in progress will return true.</p> 3123 * 3124 * <p>At each incremental step of the scroll the caller should invoke 3125 * {@link #dispatchNestedPreScroll(View, int, int, int[], int[]) dispatchNestedPreScroll} 3126 * once it has calculated the requested scrolling delta. If it returns true the nested scrolling 3127 * parent at least partially consumed the scroll and the caller should adjust the amount it 3128 * scrolls by.</p> 3129 * 3130 * <p>After applying the remainder of the scroll delta the caller should invoke 3131 * {@link #dispatchNestedScroll(View, int, int, int, int, int[]) dispatchNestedScroll}, passing 3132 * both the delta consumed and the delta unconsumed. A nested scrolling parent may treat 3133 * these values differently. See 3134 * {@link NestedScrollingParent#onNestedScroll(View, int, int, int, int)}. 3135 * </p> 3136 * 3137 * @param axes Flags consisting of a combination of {@link ViewCompat#SCROLL_AXIS_HORIZONTAL} 3138 * and/or {@link ViewCompat#SCROLL_AXIS_VERTICAL}. 3139 * @return true if a cooperative parent was found and nested scrolling has been enabled for 3140 * the current gesture. 3141 * 3142 * @see #stopNestedScroll(View) 3143 * @see #dispatchNestedPreScroll(View, int, int, int[], int[]) 3144 * @see #dispatchNestedScroll(View, int, int, int, int, int[]) 3145 */ 3146 public static boolean startNestedScroll(View view, int axes) { 3147 return IMPL.startNestedScroll(view, axes); 3148 } 3149 3150 /** 3151 * Stop a nested scroll in progress. 3152 * 3153 * <p>Calling this method when a nested scroll is not currently in progress is harmless.</p> 3154 * 3155 * @see #startNestedScroll(View, int) 3156 */ 3157 public static void stopNestedScroll(View view) { 3158 IMPL.stopNestedScroll(view); 3159 } 3160 3161 /** 3162 * Returns true if this view has a nested scrolling parent. 3163 * 3164 * <p>The presence of a nested scrolling parent indicates that this view has initiated 3165 * a nested scroll and it was accepted by an ancestor view further up the view hierarchy.</p> 3166 * 3167 * @return whether this view has a nested scrolling parent 3168 */ 3169 public static boolean hasNestedScrollingParent(View view) { 3170 return IMPL.hasNestedScrollingParent(view); 3171 } 3172 3173 /** 3174 * Dispatch one step of a nested scroll in progress. 3175 * 3176 * <p>Implementations of views that support nested scrolling should call this to report 3177 * info about a scroll in progress to the current nested scrolling parent. If a nested scroll 3178 * is not currently in progress or nested scrolling is not 3179 * {@link #isNestedScrollingEnabled(View) enabled} for this view this method does nothing.</p> 3180 * 3181 * <p>Compatible View implementations should also call 3182 * {@link #dispatchNestedPreScroll(View, int, int, int[], int[]) dispatchNestedPreScroll} before 3183 * consuming a component of the scroll event themselves.</p> 3184 * 3185 * @param dxConsumed Horizontal distance in pixels consumed by this view during this scroll step 3186 * @param dyConsumed Vertical distance in pixels consumed by this view during this scroll step 3187 * @param dxUnconsumed Horizontal scroll distance in pixels not consumed by this view 3188 * @param dyUnconsumed Horizontal scroll distance in pixels not consumed by this view 3189 * @param offsetInWindow Optional. If not null, on return this will contain the offset 3190 * in local view coordinates of this view from before this operation 3191 * to after it completes. View implementations may use this to adjust 3192 * expected input coordinate tracking. 3193 * @return true if the event was dispatched, false if it could not be dispatched. 3194 * @see #dispatchNestedPreScroll(View, int, int, int[], int[]) 3195 */ 3196 public static boolean dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, 3197 int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) { 3198 return IMPL.dispatchNestedScroll(view, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, 3199 offsetInWindow); 3200 } 3201 3202 /** 3203 * Dispatch one step of a nested scroll in progress before this view consumes any portion of it. 3204 * 3205 * <p>Nested pre-scroll events are to nested scroll events what touch intercept is to touch. 3206 * <code>dispatchNestedPreScroll</code> offers an opportunity for the parent view in a nested 3207 * scrolling operation to consume some or all of the scroll operation before the child view 3208 * consumes it.</p> 3209 * 3210 * @param dx Horizontal scroll distance in pixels 3211 * @param dy Vertical scroll distance in pixels 3212 * @param consumed Output. If not null, consumed[0] will contain the consumed component of dx 3213 * and consumed[1] the consumed dy. 3214 * @param offsetInWindow Optional. If not null, on return this will contain the offset 3215 * in local view coordinates of this view from before this operation 3216 * to after it completes. View implementations may use this to adjust 3217 * expected input coordinate tracking. 3218 * @return true if the parent consumed some or all of the scroll delta 3219 * @see #dispatchNestedScroll(View, int, int, int, int, int[]) 3220 */ 3221 public static boolean dispatchNestedPreScroll(View view, int dx, int dy, int[] consumed, 3222 int[] offsetInWindow) { 3223 return IMPL.dispatchNestedPreScroll(view, dx, dy, consumed, offsetInWindow); 3224 } 3225 3226 /** 3227 * Dispatch a fling to a nested scrolling parent. 3228 * 3229 * <p>This method should be used to indicate that a nested scrolling child has detected 3230 * suitable conditions for a fling. Generally this means that a touch scroll has ended with a 3231 * {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds 3232 * the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity} 3233 * along a scrollable axis.</p> 3234 * 3235 * <p>If a nested scrolling child view would normally fling but it is at the edge of 3236 * its own content, it can use this method to delegate the fling to its nested scrolling 3237 * parent instead. The parent may optionally consume the fling or observe a child fling.</p> 3238 * 3239 * @param velocityX Horizontal fling velocity in pixels per second 3240 * @param velocityY Vertical fling velocity in pixels per second 3241 * @param consumed true if the child consumed the fling, false otherwise 3242 * @return true if the nested scrolling parent consumed or otherwise reacted to the fling 3243 */ 3244 public static boolean dispatchNestedFling(View view, float velocityX, float velocityY, 3245 boolean consumed) { 3246 return IMPL.dispatchNestedFling(view, velocityX, velocityY, consumed); 3247 } 3248 3249 /** 3250 * Dispatch a fling to a nested scrolling parent before it is processed by this view. 3251 * 3252 * <p>Nested pre-fling events are to nested fling events what touch intercept is to touch 3253 * and what nested pre-scroll is to nested scroll. <code>dispatchNestedPreFling</code> 3254 * offsets an opportunity for the parent view in a nested fling to fully consume the fling 3255 * before the child view consumes it. If this method returns <code>true</code>, a nested 3256 * parent view consumed the fling and this view should not scroll as a result.</p> 3257 * 3258 * <p>For a better user experience, only one view in a nested scrolling chain should consume 3259 * the fling at a time. If a parent view consumed the fling this method will return false. 3260 * Custom view implementations should account for this in two ways:</p> 3261 * 3262 * <ul> 3263 * <li>If a custom view is paged and needs to settle to a fixed page-point, do not 3264 * call <code>dispatchNestedPreFling</code>; consume the fling and settle to a valid 3265 * position regardless.</li> 3266 * <li>If a nested parent does consume the fling, this view should not scroll at all, 3267 * even to settle back to a valid idle position.</li> 3268 * </ul> 3269 * 3270 * <p>Views should also not offer fling velocities to nested parent views along an axis 3271 * where scrolling is not currently supported; a {@link android.widget.ScrollView ScrollView} 3272 * should not offer a horizontal fling velocity to its parents since scrolling along that 3273 * axis is not permitted and carrying velocity along that motion does not make sense.</p> 3274 * 3275 * @param velocityX Horizontal fling velocity in pixels per second 3276 * @param velocityY Vertical fling velocity in pixels per second 3277 * @return true if a nested scrolling parent consumed the fling 3278 */ 3279 public static boolean dispatchNestedPreFling(View view, float velocityX, float velocityY) { 3280 return IMPL.dispatchNestedPreFling(view, velocityX, velocityY); 3281 } 3282 3283 /** 3284 * Returns whether the view hierarchy is currently undergoing a layout pass. This 3285 * information is useful to avoid situations such as calling {@link View#requestLayout()} 3286 * during a layout pass. 3287 * <p> 3288 * Compatibility: 3289 * <ul> 3290 * <li>API < 18: Always returns {@code false}</li> 3291 * </ul> 3292 * 3293 * @return whether the view hierarchy is currently undergoing a layout pass 3294 */ 3295 public static boolean isInLayout(View view) { 3296 return IMPL.isInLayout(view); 3297 } 3298 3299 /** 3300 * Returns true if {@code view} has been through at least one layout since it 3301 * was last attached to or detached from a window. 3302 */ 3303 public static boolean isLaidOut(View view) { 3304 return IMPL.isLaidOut(view); 3305 } 3306 3307 /** 3308 * Returns whether layout direction has been resolved. 3309 * <p> 3310 * Compatibility: 3311 * <ul> 3312 * <li>API < 19: Always returns {@code false}</li> 3313 * </ul> 3314 * 3315 * @return true if layout direction has been resolved. 3316 */ 3317 public static boolean isLayoutDirectionResolved(View view) { 3318 return IMPL.isLayoutDirectionResolved(view); 3319 } 3320 3321 /** 3322 * The visual z position of this view, in pixels. This is equivalent to the 3323 * {@link #setTranslationZ(View, float) translationZ} property plus the current 3324 * {@link #getElevation(View) elevation} property. 3325 * 3326 * @return The visual z position of this view, in pixels. 3327 */ 3328 public static float getZ(View view) { 3329 return IMPL.getZ(view); 3330 } 3331 3332 /** 3333 * Sets the visual z position of this view, in pixels. This is equivalent to setting the 3334 * {@link #setTranslationZ(View, float) translationZ} property to be the difference between 3335 * the x value passed in and the current {@link #getElevation(View) elevation} property. 3336 * <p> 3337 * Compatibility: 3338 * <ul> 3339 * <li>API < 21: No-op 3340 * </ul> 3341 * 3342 * @param z The visual z position of this view, in pixels. 3343 */ 3344 public static void setZ(View view, float z) { 3345 IMPL.setZ(view, z); 3346 } 3347 3348 /** 3349 * Offset this view's vertical location by the specified number of pixels. 3350 * 3351 * @param offset the number of pixels to offset the view by 3352 */ 3353 public static void offsetTopAndBottom(View view, int offset) { 3354 IMPL.offsetTopAndBottom(view, offset); 3355 } 3356 3357 /** 3358 * Offset this view's horizontal location by the specified amount of pixels. 3359 * 3360 * @param offset the number of pixels to offset the view by 3361 */ 3362 public static void offsetLeftAndRight(View view, int offset) { 3363 IMPL.offsetLeftAndRight(view, offset); 3364 } 3365 3366 /** 3367 * Sets a rectangular area on this view to which the view will be clipped 3368 * when it is drawn. Setting the value to null will remove the clip bounds 3369 * and the view will draw normally, using its full bounds. 3370 * 3371 * <p>Prior to API 18 this does nothing.</p> 3372 * 3373 * @param view The view to set clipBounds. 3374 * @param clipBounds The rectangular area, in the local coordinates of 3375 * this view, to which future drawing operations will be clipped. 3376 */ 3377 public static void setClipBounds(View view, Rect clipBounds) { 3378 IMPL.setClipBounds(view, clipBounds); 3379 } 3380 3381 /** 3382 * Returns a copy of the current {@link #setClipBounds(View, Rect)}. 3383 * 3384 * <p>Prior to API 18 this will return null.</p> 3385 * 3386 * @return A copy of the current clip bounds if clip bounds are set, 3387 * otherwise null. 3388 */ 3389 public static Rect getClipBounds(View view) { 3390 return IMPL.getClipBounds(view); 3391 } 3392 3393 /** 3394 * Returns true if the provided view is currently attached to a window. 3395 */ 3396 public static boolean isAttachedToWindow(View view) { 3397 return IMPL.isAttachedToWindow(view); 3398 } 3399 3400 /** 3401 * Returns whether the provided view has an attached {@link View.OnClickListener}. 3402 * 3403 * @return true if there is a listener, false if there is none. 3404 */ 3405 public static boolean hasOnClickListeners(View view) { 3406 return IMPL.hasOnClickListeners(view); 3407 } 3408 3409 /** 3410 * Sets the state of all scroll indicators. 3411 * <p> 3412 * See {@link #setScrollIndicators(View, int, int)} for usage information. 3413 * 3414 * @param indicators a bitmask of indicators that should be enabled, or 3415 * {@code 0} to disable all indicators 3416 * 3417 * @see #setScrollIndicators(View, int, int) 3418 * @see #getScrollIndicators(View) 3419 */ 3420 public static void setScrollIndicators(@NonNull View view, @ScrollIndicators int indicators) { 3421 IMPL.setScrollIndicators(view, indicators); 3422 } 3423 3424 /** 3425 * Sets the state of the scroll indicators specified by the mask. To change 3426 * all scroll indicators at once, see {@link #setScrollIndicators(View, int)}. 3427 * <p> 3428 * When a scroll indicator is enabled, it will be displayed if the view 3429 * can scroll in the direction of the indicator. 3430 * <p> 3431 * Multiple indicator types may be enabled or disabled by passing the 3432 * logical OR of the desired types. If multiple types are specified, they 3433 * will all be set to the same enabled state. 3434 * <p> 3435 * For example, to enable the top scroll indicatorExample: {@code setScrollIndicators} 3436 * 3437 * @param indicators the indicator direction, or the logical OR of multiple 3438 * indicator directions. One or more of: 3439 * <ul> 3440 * <li>{@link #SCROLL_INDICATOR_TOP}</li> 3441 * <li>{@link #SCROLL_INDICATOR_BOTTOM}</li> 3442 * <li>{@link #SCROLL_INDICATOR_LEFT}</li> 3443 * <li>{@link #SCROLL_INDICATOR_RIGHT}</li> 3444 * <li>{@link #SCROLL_INDICATOR_START}</li> 3445 * <li>{@link #SCROLL_INDICATOR_END}</li> 3446 * </ul> 3447 * 3448 * @see #setScrollIndicators(View, int) 3449 * @see #getScrollIndicators(View) 3450 */ 3451 public static void setScrollIndicators(@NonNull View view, @ScrollIndicators int indicators, 3452 @ScrollIndicators int mask) { 3453 IMPL.setScrollIndicators(view, indicators, mask); 3454 } 3455 3456 /** 3457 * Returns a bitmask representing the enabled scroll indicators. 3458 * <p> 3459 * For example, if the top and left scroll indicators are enabled and all 3460 * other indicators are disabled, the return value will be 3461 * {@code ViewCompat.SCROLL_INDICATOR_TOP | ViewCompat.SCROLL_INDICATOR_LEFT}. 3462 * <p> 3463 * To check whether the bottom scroll indicator is enabled, use the value 3464 * of {@code (ViewCompat.getScrollIndicators(view) & ViewCompat.SCROLL_INDICATOR_BOTTOM) != 0}. 3465 * 3466 * @return a bitmask representing the enabled scroll indicators 3467 */ 3468 public static int getScrollIndicators(@NonNull View view) { 3469 return IMPL.getScrollIndicators(view); 3470 } 3471 3472 /** 3473 * Set the pointer icon for the current view. 3474 * @param pointerIcon A PointerIconCompat instance which will be shown when the mouse hovers. 3475 */ 3476 public static void setPointerIcon(@NonNull View view, PointerIconCompat pointerIcon) { 3477 IMPL.setPointerIcon(view, pointerIcon); 3478 } 3479 3480 protected ViewCompat() {} 3481} 3482