ViewCompat.java revision ed27de5fc41d9318c81591e4a483902d9ecb851a
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.graphics.Paint; 20import android.graphics.PixelFormat; 21import android.graphics.Rect; 22import android.graphics.drawable.Drawable; 23import android.os.Bundle; 24import android.support.annotation.IdRes; 25import android.support.annotation.IntDef; 26import android.support.annotation.Nullable; 27import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; 28import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat; 29import android.util.Log; 30import android.view.View; 31import android.view.ViewGroup; 32import android.view.ViewParent; 33import android.view.accessibility.AccessibilityEvent; 34 35import java.lang.annotation.Retention; 36import java.lang.annotation.RetentionPolicy; 37import java.lang.reflect.Field; 38import java.lang.reflect.Method; 39import java.util.WeakHashMap; 40 41/** 42 * Helper for accessing features in {@link View} introduced after API 43 * level 4 in a backwards compatible fashion. 44 */ 45public class ViewCompat { 46 private static final String TAG = "ViewCompat"; 47 48 49 /** @hide */ 50 @IntDef({OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_IF_CONTENT_SCROLLS}) 51 @Retention(RetentionPolicy.SOURCE) 52 private @interface OverScroll {} 53 54 /** 55 * Always allow a user to over-scroll this view, provided it is a 56 * view that can scroll. 57 */ 58 public static final int OVER_SCROLL_ALWAYS = 0; 59 60 /** 61 * Allow a user to over-scroll this view only if the content is large 62 * enough to meaningfully scroll, provided it is a view that can scroll. 63 */ 64 public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; 65 66 /** 67 * Never allow a user to over-scroll this view. 68 */ 69 public static final int OVER_SCROLL_NEVER = 2; 70 71 private static final long FAKE_FRAME_TIME = 10; 72 73 /** @hide */ 74 @IntDef({ 75 IMPORTANT_FOR_ACCESSIBILITY_AUTO, 76 IMPORTANT_FOR_ACCESSIBILITY_YES, 77 IMPORTANT_FOR_ACCESSIBILITY_NO, 78 IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 79 }) 80 @Retention(RetentionPolicy.SOURCE) 81 private @interface ImportantForAccessibility {} 82 83 /** 84 * Automatically determine whether a view is important for accessibility. 85 */ 86 public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; 87 88 /** 89 * The view is important for accessibility. 90 */ 91 public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; 92 93 /** 94 * The view is not important for accessibility. 95 */ 96 public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; 97 98 /** 99 * The view is not important for accessibility, nor are any of its 100 * descendant views. 101 */ 102 public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS = 0x00000004; 103 104 /** @hide */ 105 @IntDef({ 106 ACCESSIBILITY_LIVE_REGION_NONE, 107 ACCESSIBILITY_LIVE_REGION_POLITE, 108 ACCESSIBILITY_LIVE_REGION_ASSERTIVE 109 }) 110 @Retention(RetentionPolicy.SOURCE) 111 private @interface AccessibilityLiveRegion {} 112 113 /** 114 * Live region mode specifying that accessibility services should not 115 * automatically announce changes to this view. This is the default live 116 * region mode for most views. 117 * <p> 118 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 119 */ 120 public static final int ACCESSIBILITY_LIVE_REGION_NONE = 0x00000000; 121 122 /** 123 * Live region mode specifying that accessibility services should announce 124 * changes to this view. 125 * <p> 126 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 127 */ 128 public static final int ACCESSIBILITY_LIVE_REGION_POLITE = 0x00000001; 129 130 /** 131 * Live region mode specifying that accessibility services should interrupt 132 * ongoing speech to immediately announce changes to this view. 133 * <p> 134 * Use with {@link ViewCompat#setAccessibilityLiveRegion(View, int)}. 135 */ 136 public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 0x00000002; 137 138 /** @hide */ 139 @IntDef({LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYER_TYPE_HARDWARE}) 140 @Retention(RetentionPolicy.SOURCE) 141 private @interface LayerType {} 142 143 /** 144 * Indicates that the view does not have a layer. 145 */ 146 public static final int LAYER_TYPE_NONE = 0; 147 148 /** 149 * <p>Indicates that the view has a software layer. A software layer is backed 150 * by a bitmap and causes the view to be rendered using Android's software 151 * rendering pipeline, even if hardware acceleration is enabled.</p> 152 * 153 * <p>Software layers have various usages:</p> 154 * <p>When the application is not using hardware acceleration, a software layer 155 * is useful to apply a specific color filter and/or blending mode and/or 156 * translucency to a view and all its children.</p> 157 * <p>When the application is using hardware acceleration, a software layer 158 * is useful to render drawing primitives not supported by the hardware 159 * accelerated pipeline. It can also be used to cache a complex view tree 160 * into a texture and reduce the complexity of drawing operations. For instance, 161 * when animating a complex view tree with a translation, a software layer can 162 * be used to render the view tree only once.</p> 163 * <p>Software layers should be avoided when the affected view tree updates 164 * often. Every update will require to re-render the software layer, which can 165 * potentially be slow (particularly when hardware acceleration is turned on 166 * since the layer will have to be uploaded into a hardware texture after every 167 * update.)</p> 168 */ 169 public static final int LAYER_TYPE_SOFTWARE = 1; 170 171 /** 172 * <p>Indicates that the view has a hardware layer. A hardware layer is backed 173 * by a hardware specific texture (generally Frame Buffer Objects or FBO on 174 * OpenGL hardware) and causes the view to be rendered using Android's hardware 175 * rendering pipeline, but only if hardware acceleration is turned on for the 176 * view hierarchy. When hardware acceleration is turned off, hardware layers 177 * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> 178 * 179 * <p>A hardware layer is useful to apply a specific color filter and/or 180 * blending mode and/or translucency to a view and all its children.</p> 181 * <p>A hardware layer can be used to cache a complex view tree into a 182 * texture and reduce the complexity of drawing operations. For instance, 183 * when animating a complex view tree with a translation, a hardware layer can 184 * be used to render the view tree only once.</p> 185 * <p>A hardware layer can also be used to increase the rendering quality when 186 * rotation transformations are applied on a view. It can also be used to 187 * prevent potential clipping issues when applying 3D transforms on a view.</p> 188 */ 189 public static final int LAYER_TYPE_HARDWARE = 2; 190 191 /** @hide */ 192 @IntDef({ 193 LAYOUT_DIRECTION_LTR, 194 LAYOUT_DIRECTION_RTL, 195 LAYOUT_DIRECTION_INHERIT, 196 LAYOUT_DIRECTION_LOCALE}) 197 @Retention(RetentionPolicy.SOURCE) 198 private @interface LayoutDirectionMode {} 199 200 /** @hide */ 201 @IntDef({ 202 LAYOUT_DIRECTION_LTR, 203 LAYOUT_DIRECTION_RTL 204 }) 205 @Retention(RetentionPolicy.SOURCE) 206 private @interface ResolvedLayoutDirectionMode {} 207 208 /** 209 * Horizontal layout direction of this view is from Left to Right. 210 */ 211 public static final int LAYOUT_DIRECTION_LTR = 0; 212 213 /** 214 * Horizontal layout direction of this view is from Right to Left. 215 */ 216 public static final int LAYOUT_DIRECTION_RTL = 1; 217 218 /** 219 * Horizontal layout direction of this view is inherited from its parent. 220 * Use with {@link #setLayoutDirection}. 221 */ 222 public static final int LAYOUT_DIRECTION_INHERIT = 2; 223 224 /** 225 * Horizontal layout direction of this view is from deduced from the default language 226 * script for the locale. Use with {@link #setLayoutDirection}. 227 */ 228 public static final int LAYOUT_DIRECTION_LOCALE = 3; 229 230 /** 231 * Bits of {@link #getMeasuredWidthAndState} and 232 * {@link #getMeasuredWidthAndState} that provide the actual measured size. 233 */ 234 public static final int MEASURED_SIZE_MASK = 0x00ffffff; 235 236 /** 237 * Bits of {@link #getMeasuredWidthAndState} and 238 * {@link #getMeasuredWidthAndState} that provide the additional state bits. 239 */ 240 public static final int MEASURED_STATE_MASK = 0xff000000; 241 242 /** 243 * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits 244 * for functions that combine both width and height into a single int, 245 * such as {@link #getMeasuredState} and the childState argument of 246 * {@link #resolveSizeAndState(int, int, int)}. 247 */ 248 public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; 249 250 /** 251 * Bit of {@link #getMeasuredWidthAndState} and 252 * {@link #getMeasuredWidthAndState} that indicates the measured size 253 * is smaller that the space the view would like to have. 254 */ 255 public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; 256 257 interface ViewCompatImpl { 258 public boolean canScrollHorizontally(View v, int direction); 259 public boolean canScrollVertically(View v, int direction); 260 public int getOverScrollMode(View v); 261 public void setOverScrollMode(View v, int mode); 262 public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event); 263 public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event); 264 public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info); 265 public void setAccessibilityDelegate(View v, @Nullable AccessibilityDelegateCompat delegate); 266 public boolean hasAccessibilityDelegate(View v); 267 public boolean hasTransientState(View view); 268 public void setHasTransientState(View view, boolean hasTransientState); 269 public void postInvalidateOnAnimation(View view); 270 public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom); 271 public void postOnAnimation(View view, Runnable action); 272 public void postOnAnimationDelayed(View view, Runnable action, long delayMillis); 273 public int getImportantForAccessibility(View view); 274 public void setImportantForAccessibility(View view, int mode); 275 public boolean performAccessibilityAction(View view, int action, Bundle arguments); 276 public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view); 277 public float getAlpha(View view); 278 public void setLayerType(View view, int layerType, Paint paint); 279 public int getLayerType(View view); 280 public int getLabelFor(View view); 281 public void setLabelFor(View view, int id); 282 public void setLayerPaint(View view, Paint paint); 283 public int getLayoutDirection(View view); 284 public void setLayoutDirection(View view, int layoutDirection); 285 public ViewParent getParentForAccessibility(View view); 286 public boolean isOpaque(View view); 287 public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState); 288 public int getMeasuredWidthAndState(View view); 289 public int getMeasuredHeightAndState(View view); 290 public int getMeasuredState(View view); 291 public int getAccessibilityLiveRegion(View view); 292 public void setAccessibilityLiveRegion(View view, int mode); 293 public int getPaddingStart(View view); 294 public int getPaddingEnd(View view); 295 public void setPaddingRelative(View view, int start, int top, int end, int bottom); 296 public void dispatchStartTemporaryDetach(View view); 297 public void dispatchFinishTemporaryDetach(View view); 298 public float getX(View view); 299 public float getY(View view); 300 public float getRotation(View view); 301 public float getRotationX(View view); 302 public float getRotationY(View view); 303 public float getScaleX(View view); 304 public float getScaleY(View view); 305 public float getTranslationX(View view); 306 public float getTranslationY(View view); 307 public int getMinimumWidth(View view); 308 public int getMinimumHeight(View view); 309 public ViewPropertyAnimatorCompat animate(View view); 310 public void setRotation(View view, float value); 311 public void setRotationX(View view, float value); 312 public void setRotationY(View view, float value); 313 public void setScaleX(View view, float value); 314 public void setScaleY(View view, float value); 315 public void setTranslationX(View view, float value); 316 public void setTranslationY(View view, float value); 317 public void setX(View view, float value); 318 public void setY(View view, float value); 319 public void setAlpha(View view, float value); 320 public void setPivotX(View view, float value); 321 public void setPivotY(View view, float value); 322 public float getPivotX(View view); 323 public float getPivotY(View view); 324 public void setElevation(View view, float elevation); 325 public float getElevation(View view); 326 public void setTranslationZ(View view, float translationZ); 327 public float getTranslationZ(View view); 328 public void setTransitionName(View view, String transitionName); 329 public String getTransitionName(View view); 330 public int getWindowSystemUiVisibility(View view); 331 public void requestApplyInsets(View view); 332 public void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled); 333 public boolean getFitsSystemWindows(View view); 334 void setFitsSystemWindows(View view, boolean fitSystemWindows); 335 void jumpDrawablesToCurrentState(View v); 336 void setOnApplyWindowInsetsListener(View view, OnApplyWindowInsetsListener listener); 337 void setSaveFromParentEnabled(View view, boolean enabled); 338 void setActivated(View view, boolean activated); 339 } 340 341 static class BaseViewCompatImpl implements ViewCompatImpl { 342 private Method mDispatchStartTemporaryDetach; 343 private Method mDispatchFinishTemporaryDetach; 344 private boolean mTempDetachBound; 345 WeakHashMap<View, ViewPropertyAnimatorCompat> mViewPropertyAnimatorCompatMap = null; 346 347 348 public boolean canScrollHorizontally(View v, int direction) { 349 return false; 350 } 351 public boolean canScrollVertically(View v, int direction) { 352 return false; 353 } 354 public int getOverScrollMode(View v) { 355 return OVER_SCROLL_NEVER; 356 } 357 public void setOverScrollMode(View v, int mode) { 358 // Do nothing; API doesn't exist 359 } 360 public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 361 // Do nothing; API doesn't exist 362 } 363 364 @Override 365 public boolean hasAccessibilityDelegate(View v) { 366 return false; 367 } 368 369 public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 370 // Do nothing; API doesn't exist 371 } 372 public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 373 // Do nothing; API doesn't exist 374 } 375 public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 376 // Do nothing; API doesn't exist 377 } 378 public boolean hasTransientState(View view) { 379 // A view can't have transient state if transient state wasn't supported. 380 return false; 381 } 382 public void setHasTransientState(View view, boolean hasTransientState) { 383 // Do nothing; API doesn't exist 384 } 385 public void postInvalidateOnAnimation(View view) { 386 view.invalidate(); 387 } 388 public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 389 view.invalidate(left, top, right, bottom); 390 } 391 public void postOnAnimation(View view, Runnable action) { 392 view.postDelayed(action, getFrameTime()); 393 } 394 public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 395 view.postDelayed(action, getFrameTime() + delayMillis); 396 } 397 long getFrameTime() { 398 return FAKE_FRAME_TIME; 399 } 400 public int getImportantForAccessibility(View view) { 401 return 0; 402 } 403 public void setImportantForAccessibility(View view, int mode) { 404 405 } 406 public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 407 return false; 408 } 409 public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 410 return null; 411 } 412 public float getAlpha(View view) { 413 return 1.0f; 414 } 415 public void setLayerType(View view, int layerType, Paint paint) { 416 // No-op until layers became available (HC) 417 } 418 public int getLayerType(View view) { 419 return LAYER_TYPE_NONE; 420 } 421 public int getLabelFor(View view) { 422 return 0; 423 } 424 public void setLabelFor(View view, int id) { 425 426 } 427 public void setLayerPaint(View view, Paint p) { 428 // No-op until layers became available (HC) 429 } 430 431 @Override 432 public int getLayoutDirection(View view) { 433 return LAYOUT_DIRECTION_LTR; 434 } 435 436 @Override 437 public void setLayoutDirection(View view, int layoutDirection) { 438 // No-op 439 } 440 441 @Override 442 public ViewParent getParentForAccessibility(View view) { 443 return view.getParent(); 444 } 445 446 @Override 447 public boolean isOpaque(View view) { 448 final Drawable bg = view.getBackground(); 449 if (bg != null) { 450 return bg.getOpacity() == PixelFormat.OPAQUE; 451 } 452 return false; 453 } 454 455 public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 456 return View.resolveSize(size, measureSpec); 457 } 458 459 @Override 460 public int getMeasuredWidthAndState(View view) { 461 return view.getMeasuredWidth(); 462 } 463 464 @Override 465 public int getMeasuredHeightAndState(View view) { 466 return view.getMeasuredHeight(); 467 } 468 469 @Override 470 public int getMeasuredState(View view) { 471 return 0; 472 } 473 474 @Override 475 public int getAccessibilityLiveRegion(View view) { 476 return ACCESSIBILITY_LIVE_REGION_NONE; 477 } 478 479 @Override 480 public void setAccessibilityLiveRegion(View view, int mode) { 481 // No-op 482 } 483 484 @Override 485 public int getPaddingStart(View view) { 486 return view.getPaddingLeft(); 487 } 488 489 @Override 490 public int getPaddingEnd(View view) { 491 return view.getPaddingRight(); 492 } 493 494 @Override 495 public void setPaddingRelative(View view, int start, int top, int end, int bottom) { 496 view.setPadding(start, top, end, bottom); 497 } 498 499 @Override 500 public void dispatchStartTemporaryDetach(View view) { 501 if (!mTempDetachBound) { 502 bindTempDetach(); 503 } 504 if (mDispatchStartTemporaryDetach != null) { 505 try { 506 mDispatchStartTemporaryDetach.invoke(view); 507 } catch (Exception e) { 508 Log.d(TAG, "Error calling dispatchStartTemporaryDetach", e); 509 } 510 } else { 511 // Try this instead 512 view.onStartTemporaryDetach(); 513 } 514 } 515 516 @Override 517 public void dispatchFinishTemporaryDetach(View view) { 518 if (!mTempDetachBound) { 519 bindTempDetach(); 520 } 521 if (mDispatchFinishTemporaryDetach != null) { 522 try { 523 mDispatchFinishTemporaryDetach.invoke(view); 524 } catch (Exception e) { 525 Log.d(TAG, "Error calling dispatchFinishTemporaryDetach", e); 526 } 527 } else { 528 // Try this instead 529 view.onFinishTemporaryDetach(); 530 } 531 } 532 533 private void bindTempDetach() { 534 try { 535 mDispatchStartTemporaryDetach = View.class.getDeclaredMethod( 536 "dispatchStartTemporaryDetach"); 537 mDispatchFinishTemporaryDetach = View.class.getDeclaredMethod( 538 "dispatchFinishTemporaryDetach"); 539 } catch (NoSuchMethodException e) { 540 Log.e(TAG, "Couldn't find method", e); 541 } 542 mTempDetachBound = true; 543 } 544 545 @Override 546 public float getTranslationX(View view) { 547 return 0; 548 } 549 550 @Override 551 public float getTranslationY(View view) { 552 return 0; 553 } 554 555 @Override 556 public float getX(View view) { 557 return 0; 558 } 559 560 @Override 561 public float getY(View view) { 562 return 0; 563 } 564 565 @Override 566 public float getRotation(View view) { 567 return 0; 568 } 569 570 @Override 571 public float getRotationX(View view) { 572 return 0; 573 } 574 575 @Override 576 public float getRotationY(View view) { 577 return 0; 578 } 579 580 @Override 581 public float getScaleX(View view) { 582 return 0; 583 } 584 585 @Override 586 public float getScaleY(View view) { 587 return 0; 588 } 589 590 @Override 591 public int getMinimumWidth(View view) { 592 return 0; 593 } 594 595 @Override 596 public int getMinimumHeight(View view) { 597 return 0; 598 } 599 600 @Override 601 public ViewPropertyAnimatorCompat animate(View view) { 602 return new ViewPropertyAnimatorCompat(view); 603 } 604 605 @Override 606 public void setRotation(View view, float value) { 607 // noop 608 } 609 610 @Override 611 public void setTranslationX(View view, float value) { 612 // noop 613 } 614 615 @Override 616 public void setTranslationY(View view, float value) { 617 // noop 618 } 619 620 @Override 621 public void setAlpha(View view, float value) { 622 // noop 623 } 624 625 @Override 626 public void setRotationX(View view, float value) { 627 // noop 628 } 629 630 @Override 631 public void setRotationY(View view, float value) { 632 // noop 633 } 634 635 @Override 636 public void setScaleX(View view, float value) { 637 // noop 638 } 639 640 @Override 641 public void setScaleY(View view, float value) { 642 // noop 643 } 644 645 @Override 646 public void setX(View view, float value) { 647 // noop 648 } 649 650 @Override 651 public void setY(View view, float value) { 652 // noop 653 } 654 655 @Override 656 public void setPivotX(View view, float value) { 657 // noop 658 } 659 660 @Override 661 public void setPivotY(View view, float value) { 662 // noop 663 } 664 665 @Override 666 public float getPivotX(View view) { 667 return 0; 668 } 669 670 @Override 671 public float getPivotY(View view) { 672 return 0; 673 } 674 675 @Override 676 public void setTransitionName(View view, String transitionName) { 677 } 678 679 @Override 680 public String getTransitionName(View view) { 681 return null; 682 } 683 684 @Override 685 public int getWindowSystemUiVisibility(View view) { 686 return 0; 687 } 688 689 @Override 690 public void requestApplyInsets(View view) { 691 } 692 693 @Override 694 public void setElevation(View view, float elevation) { 695 } 696 697 @Override 698 public float getElevation(View view) { 699 return 0f; 700 } 701 702 @Override 703 public void setTranslationZ(View view, float translationZ) { 704 } 705 706 @Override 707 public float getTranslationZ(View view) { 708 return 0f; 709 } 710 711 @Override 712 public void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled) { 713 // noop 714 } 715 716 @Override 717 public boolean getFitsSystemWindows(View view) { 718 return false; 719 } 720 721 @Override 722 public void setFitsSystemWindows(View view, boolean fitSystemWindows) { 723 // noop 724 } 725 726 @Override 727 public void jumpDrawablesToCurrentState(View view) { 728 // Do nothing; API didn't exist. 729 } 730 731 @Override 732 public void setOnApplyWindowInsetsListener(View view, 733 OnApplyWindowInsetsListener listener) { 734 // noop 735 } 736 737 @Override 738 public void setSaveFromParentEnabled(View v, boolean enabled) { 739 // noop 740 } 741 742 @Override 743 public void setActivated(View view, boolean activated) { 744 // noop 745 } 746 } 747 748 static class EclairMr1ViewCompatImpl extends BaseViewCompatImpl { 749 @Override 750 public boolean isOpaque(View view) { 751 return ViewCompatEclairMr1.isOpaque(view); 752 } 753 754 @Override 755 public void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled) { 756 ViewCompatEclairMr1.setChildrenDrawingOrderEnabled(viewGroup, enabled); 757 } 758 } 759 760 static class GBViewCompatImpl extends EclairMr1ViewCompatImpl { 761 @Override 762 public int getOverScrollMode(View v) { 763 return ViewCompatGingerbread.getOverScrollMode(v); 764 } 765 @Override 766 public void setOverScrollMode(View v, int mode) { 767 ViewCompatGingerbread.setOverScrollMode(v, mode); 768 } 769 } 770 771 static class HCViewCompatImpl extends GBViewCompatImpl { 772 @Override 773 long getFrameTime() { 774 return ViewCompatHC.getFrameTime(); 775 } 776 @Override 777 public float getAlpha(View view) { 778 return ViewCompatHC.getAlpha(view); 779 } 780 @Override 781 public void setLayerType(View view, int layerType, Paint paint) { 782 ViewCompatHC.setLayerType(view, layerType, paint); 783 } 784 @Override 785 public int getLayerType(View view) { 786 return ViewCompatHC.getLayerType(view); 787 } 788 @Override 789 public void setLayerPaint(View view, Paint paint) { 790 // Make sure the paint is correct; this will be cheap if it's the same 791 // instance as was used to call setLayerType earlier. 792 setLayerType(view, getLayerType(view), paint); 793 // This is expensive, but the only way to accomplish this before JB-MR1. 794 view.invalidate(); 795 } 796 @Override 797 public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 798 return ViewCompatHC.resolveSizeAndState(size, measureSpec, childMeasuredState); 799 } 800 @Override 801 public int getMeasuredWidthAndState(View view) { 802 return ViewCompatHC.getMeasuredWidthAndState(view); 803 } 804 @Override 805 public int getMeasuredHeightAndState(View view) { 806 return ViewCompatHC.getMeasuredHeightAndState(view); 807 } 808 @Override 809 public int getMeasuredState(View view) { 810 return ViewCompatHC.getMeasuredState(view); 811 } 812 @Override 813 public float getTranslationX(View view) { 814 return ViewCompatHC.getTranslationX(view); 815 } 816 @Override 817 public float getTranslationY(View view) { 818 return ViewCompatHC.getTranslationY(view); 819 } 820 @Override 821 public void setTranslationX(View view, float value) { 822 ViewCompatHC.setTranslationX(view, value); 823 } 824 @Override 825 public void setTranslationY(View view, float value) { 826 ViewCompatHC.setTranslationY(view, value); 827 } 828 @Override 829 public void setAlpha(View view, float value) { 830 ViewCompatHC.setAlpha(view, value); 831 } 832 @Override 833 public void setX(View view, float value) { 834 ViewCompatHC.setX(view, value); 835 } 836 @Override 837 public void setY(View view, float value) { 838 ViewCompatHC.setY(view, value); 839 } 840 @Override 841 public void setRotation(View view, float value) { 842 ViewCompatHC.setRotation(view, value); 843 } 844 @Override 845 public void setRotationX(View view, float value) { 846 ViewCompatHC.setRotationX(view, value); 847 } 848 @Override 849 public void setRotationY(View view, float value) { 850 ViewCompatHC.setRotationY(view, value); 851 } 852 @Override 853 public void setScaleX(View view, float value) { 854 ViewCompatHC.setScaleX(view, value); 855 } 856 @Override 857 public void setScaleY(View view, float value) { 858 ViewCompatHC.setScaleY(view, value); 859 } 860 @Override 861 public void setPivotX(View view, float value) { 862 ViewCompatHC.setPivotX(view, value); 863 } 864 @Override 865 public void setPivotY(View view, float value) { 866 ViewCompatHC.setPivotY(view, value); 867 } 868 @Override 869 public float getX(View view) { 870 return ViewCompatHC.getX(view); 871 } 872 873 @Override 874 public float getY(View view) { 875 return ViewCompatHC.getY(view); 876 } 877 878 @Override 879 public float getRotation(View view) { 880 return ViewCompatHC.getRotation(view); 881 } 882 883 @Override 884 public float getRotationX(View view) { 885 return ViewCompatHC.getRotationX(view); 886 } 887 888 @Override 889 public float getRotationY(View view) { 890 return ViewCompatHC.getRotationY(view); 891 } 892 893 @Override 894 public float getScaleX(View view) { 895 return ViewCompatHC.getScaleX(view); 896 } 897 898 @Override 899 public float getScaleY(View view) { 900 return ViewCompatHC.getScaleY(view); 901 } 902 903 @Override 904 public float getPivotX(View view) { 905 return ViewCompatHC.getPivotX(view); 906 } 907 @Override 908 public float getPivotY(View view) { 909 return ViewCompatHC.getPivotY(view); 910 } 911 @Override 912 public void jumpDrawablesToCurrentState(View view) { 913 ViewCompatHC.jumpDrawablesToCurrentState(view); 914 } 915 916 @Override 917 public void setSaveFromParentEnabled(View view, boolean enabled) { 918 ViewCompatHC.setSaveFromParentEnabled(view, enabled); 919 } 920 921 @Override 922 public void setActivated(View view, boolean activated) { 923 ViewCompatHC.setActivated(view, activated); 924 } 925 } 926 927 static class ICSViewCompatImpl extends HCViewCompatImpl { 928 static Field mAccessibilityDelegateField; 929 static boolean accessibilityDelegateCheckFailed = false; 930 @Override 931 public boolean canScrollHorizontally(View v, int direction) { 932 return ViewCompatICS.canScrollHorizontally(v, direction); 933 } 934 @Override 935 public boolean canScrollVertically(View v, int direction) { 936 return ViewCompatICS.canScrollVertically(v, direction); 937 } 938 @Override 939 public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 940 ViewCompatICS.onPopulateAccessibilityEvent(v, event); 941 } 942 @Override 943 public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 944 ViewCompatICS.onInitializeAccessibilityEvent(v, event); 945 } 946 @Override 947 public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 948 ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo()); 949 } 950 @Override 951 public void setAccessibilityDelegate(View v, 952 @Nullable AccessibilityDelegateCompat delegate) { 953 ViewCompatICS.setAccessibilityDelegate(v, 954 delegate == null ? null : delegate.getBridge()); 955 } 956 957 @Override 958 public boolean hasAccessibilityDelegate(View v) { 959 if (accessibilityDelegateCheckFailed) { 960 return false; // View implementation might have changed. 961 } 962 if (mAccessibilityDelegateField == null) { 963 try { 964 mAccessibilityDelegateField = View.class 965 .getDeclaredField("mAccessibilityDelegate"); 966 mAccessibilityDelegateField.setAccessible(true); 967 } catch (Throwable t) { 968 accessibilityDelegateCheckFailed = true; 969 return false; 970 } 971 } 972 try { 973 return mAccessibilityDelegateField.get(v) != null; 974 } catch (Throwable t) { 975 accessibilityDelegateCheckFailed = true; 976 return false; 977 } 978 } 979 980 @Override 981 public ViewPropertyAnimatorCompat animate(View view) { 982 if (mViewPropertyAnimatorCompatMap == null) { 983 mViewPropertyAnimatorCompatMap = 984 new WeakHashMap<View, ViewPropertyAnimatorCompat>(); 985 } 986 ViewPropertyAnimatorCompat vpa = mViewPropertyAnimatorCompatMap.get(view); 987 if (vpa == null) { 988 vpa = new ViewPropertyAnimatorCompat(view); 989 mViewPropertyAnimatorCompatMap.put(view, vpa); 990 } 991 return vpa; 992 } 993 994 @Override 995 public void setFitsSystemWindows(View view, boolean fitSystemWindows) { 996 ViewCompatICS.setFitsSystemWindows(view, fitSystemWindows); 997 } 998 } 999 1000 static class JBViewCompatImpl extends ICSViewCompatImpl { 1001 @Override 1002 public boolean hasTransientState(View view) { 1003 return ViewCompatJB.hasTransientState(view); 1004 } 1005 @Override 1006 public void setHasTransientState(View view, boolean hasTransientState) { 1007 ViewCompatJB.setHasTransientState(view, hasTransientState); 1008 } 1009 @Override 1010 public void postInvalidateOnAnimation(View view) { 1011 ViewCompatJB.postInvalidateOnAnimation(view); 1012 } 1013 @Override 1014 public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 1015 ViewCompatJB.postInvalidateOnAnimation(view, left, top, right, bottom); 1016 } 1017 @Override 1018 public void postOnAnimation(View view, Runnable action) { 1019 ViewCompatJB.postOnAnimation(view, action); 1020 } 1021 @Override 1022 public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 1023 ViewCompatJB.postOnAnimationDelayed(view, action, delayMillis); 1024 } 1025 @Override 1026 public int getImportantForAccessibility(View view) { 1027 return ViewCompatJB.getImportantForAccessibility(view); 1028 } 1029 @Override 1030 public void setImportantForAccessibility(View view, int mode) { 1031 // IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS is not available 1032 // on this platform so replace with IMPORTANT_FOR_ACCESSIBILITY_NO 1033 // which is closer semantically. 1034 if (mode == IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) { 1035 mode = IMPORTANT_FOR_ACCESSIBILITY_NO; 1036 } 1037 ViewCompatJB.setImportantForAccessibility(view, mode); 1038 } 1039 @Override 1040 public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 1041 return ViewCompatJB.performAccessibilityAction(view, action, arguments); 1042 } 1043 @Override 1044 public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 1045 Object compat = ViewCompatJB.getAccessibilityNodeProvider(view); 1046 if (compat != null) { 1047 return new AccessibilityNodeProviderCompat(compat); 1048 } 1049 return null; 1050 } 1051 1052 @Override 1053 public ViewParent getParentForAccessibility(View view) { 1054 return ViewCompatJB.getParentForAccessibility(view); 1055 } 1056 1057 @Override 1058 public int getMinimumWidth(View view) { 1059 return ViewCompatJB.getMinimumWidth(view); 1060 } 1061 1062 @Override 1063 public int getMinimumHeight(View view) { 1064 return ViewCompatJB.getMinimumHeight(view); 1065 } 1066 1067 @Override 1068 public void requestApplyInsets(View view) { 1069 ViewCompatJB.requestApplyInsets(view); 1070 } 1071 1072 @Override 1073 public boolean getFitsSystemWindows(View view) { 1074 return ViewCompatJB.getFitsSystemWindows(view); 1075 } 1076 } 1077 1078 static class JbMr1ViewCompatImpl extends JBViewCompatImpl { 1079 1080 @Override 1081 public int getLabelFor(View view) { 1082 return ViewCompatJellybeanMr1.getLabelFor(view); 1083 } 1084 1085 @Override 1086 public void setLabelFor(View view, int id) { 1087 ViewCompatJellybeanMr1.setLabelFor(view, id); 1088 } 1089 1090 @Override 1091 public void setLayerPaint(View view, Paint paint) { 1092 ViewCompatJellybeanMr1.setLayerPaint(view, paint); 1093 } 1094 1095 @Override 1096 public int getLayoutDirection(View view) { 1097 return ViewCompatJellybeanMr1.getLayoutDirection(view); 1098 } 1099 1100 @Override 1101 public void setLayoutDirection(View view, int layoutDirection) { 1102 ViewCompatJellybeanMr1.setLayoutDirection(view, layoutDirection); 1103 } 1104 1105 @Override 1106 public int getPaddingStart(View view) { 1107 return ViewCompatJellybeanMr1.getPaddingStart(view); 1108 } 1109 1110 @Override 1111 public int getPaddingEnd(View view) { 1112 return ViewCompatJellybeanMr1.getPaddingEnd(view); 1113 } 1114 1115 @Override 1116 public void setPaddingRelative(View view, int start, int top, int end, int bottom) { 1117 ViewCompatJellybeanMr1.setPaddingRelative(view, start, top, end, bottom); 1118 } 1119 1120 @Override 1121 public int getWindowSystemUiVisibility(View view) { 1122 return ViewCompatJellybeanMr1.getWindowSystemUiVisibility(view); 1123 } 1124 } 1125 1126 static class KitKatViewCompatImpl extends JbMr1ViewCompatImpl { 1127 @Override 1128 public int getAccessibilityLiveRegion(View view) { 1129 return ViewCompatKitKat.getAccessibilityLiveRegion(view); 1130 } 1131 1132 @Override 1133 public void setAccessibilityLiveRegion(View view, int mode) { 1134 ViewCompatKitKat.setAccessibilityLiveRegion(view, mode); 1135 } 1136 1137 @Override 1138 public void setImportantForAccessibility(View view, int mode) { 1139 ViewCompatJB.setImportantForAccessibility(view, mode); 1140 } 1141 } 1142 1143 static class Api21ViewCompatImpl extends KitKatViewCompatImpl { 1144 @Override 1145 public void setTransitionName(View view, String transitionName) { 1146 ViewCompatApi21.setTransitionName(view, transitionName); 1147 } 1148 1149 @Override 1150 public String getTransitionName(View view) { 1151 return ViewCompatApi21.getTransitionName(view); 1152 } 1153 1154 @Override 1155 public void requestApplyInsets(View view) { 1156 ViewCompatApi21.requestApplyInsets(view); 1157 } 1158 1159 @Override 1160 public void setElevation(View view, float elevation) { 1161 ViewCompatApi21.setElevation(view, elevation); 1162 } 1163 1164 @Override 1165 public float getElevation(View view) { 1166 return ViewCompatApi21.getElevation(view); 1167 } 1168 1169 @Override 1170 public void setTranslationZ(View view, float translationZ) { 1171 ViewCompatApi21.setTranslationZ(view, translationZ); 1172 } 1173 1174 @Override 1175 public float getTranslationZ(View view) { 1176 return ViewCompatApi21.getTranslationZ(view); 1177 } 1178 1179 @Override 1180 public void setOnApplyWindowInsetsListener(View view, OnApplyWindowInsetsListener listener) { 1181 ViewCompatApi21.setOnApplyWindowInsetsListener(view, listener); 1182 } 1183 } 1184 1185 static final ViewCompatImpl IMPL; 1186 static { 1187 final int version = android.os.Build.VERSION.SDK_INT; 1188 if (version >= 21) { 1189 IMPL = new Api21ViewCompatImpl(); 1190 } else if (version >= 19) { 1191 IMPL = new KitKatViewCompatImpl(); 1192 } else if (version >= 17) { 1193 IMPL = new JbMr1ViewCompatImpl(); 1194 } else if (version >= 16) { 1195 IMPL = new JBViewCompatImpl(); 1196 } else if (version >= 14) { 1197 IMPL = new ICSViewCompatImpl(); 1198 } else if (version >= 11) { 1199 IMPL = new HCViewCompatImpl(); 1200 } else if (version >= 9) { 1201 IMPL = new GBViewCompatImpl(); 1202 } else if (version >= 7) { 1203 IMPL = new EclairMr1ViewCompatImpl(); 1204 } else { 1205 IMPL = new BaseViewCompatImpl(); 1206 } 1207 } 1208 1209 /** 1210 * Check if this view can be scrolled horizontally in a certain direction. 1211 * 1212 * @param v The View against which to invoke the method. 1213 * @param direction Negative to check scrolling left, positive to check scrolling right. 1214 * @return true if this view can be scrolled in the specified direction, false otherwise. 1215 */ 1216 public static boolean canScrollHorizontally(View v, int direction) { 1217 return IMPL.canScrollHorizontally(v, direction); 1218 } 1219 1220 /** 1221 * Check if this view can be scrolled vertically in a certain direction. 1222 * 1223 * @param v The View against which to invoke the method. 1224 * @param direction Negative to check scrolling up, positive to check scrolling down. 1225 * @return true if this view can be scrolled in the specified direction, false otherwise. 1226 */ 1227 public static boolean canScrollVertically(View v, int direction) { 1228 return IMPL.canScrollVertically(v, direction); 1229 } 1230 1231 /** 1232 * Returns the over-scroll mode for this view. The result will be 1233 * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1234 * (allow over-scrolling only if the view content is larger than the container), 1235 * or {@link #OVER_SCROLL_NEVER}. 1236 * 1237 * @param v The View against which to invoke the method. 1238 * @return This view's over-scroll mode. 1239 */ 1240 @OverScroll 1241 public static int getOverScrollMode(View v) { 1242 return IMPL.getOverScrollMode(v); 1243 } 1244 1245 /** 1246 * Set the over-scroll mode for this view. Valid over-scroll modes are 1247 * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1248 * (allow over-scrolling only if the view content is larger than the container), 1249 * or {@link #OVER_SCROLL_NEVER}. 1250 * 1251 * Setting the over-scroll mode of a view will have an effect only if the 1252 * view is capable of scrolling. 1253 * 1254 * @param v The View against which to invoke the method. 1255 * @param overScrollMode The new over-scroll mode for this view. 1256 */ 1257 public static void setOverScrollMode(View v, @OverScroll int overScrollMode) { 1258 IMPL.setOverScrollMode(v, overScrollMode); 1259 } 1260 1261 /** 1262 * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} 1263 * giving a chance to this View to populate the accessibility event with its 1264 * text content. While this method is free to modify event 1265 * attributes other than text content, doing so should normally be performed in 1266 * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}. 1267 * <p> 1268 * Example: Adding formatted date string to an accessibility event in addition 1269 * to the text added by the super implementation: 1270 * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 1271 * super.onPopulateAccessibilityEvent(event); 1272 * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; 1273 * String selectedDateUtterance = DateUtils.formatDateTime(mContext, 1274 * mCurrentDate.getTimeInMillis(), flags); 1275 * event.getText().add(selectedDateUtterance); 1276 * }</pre> 1277 * <p> 1278 * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 1279 * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 1280 * {@link android.view.View.AccessibilityDelegate#onPopulateAccessibilityEvent(View, 1281 * AccessibilityEvent)} 1282 * is responsible for handling this call. 1283 * </p> 1284 * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 1285 * information to the event, in case the default implementation has basic information to add. 1286 * </p> 1287 * 1288 * @param v The View against which to invoke the method. 1289 * @param event The accessibility event which to populate. 1290 * 1291 * @see View#sendAccessibilityEvent(int) 1292 * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 1293 */ 1294 public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1295 IMPL.onPopulateAccessibilityEvent(v, event); 1296 } 1297 1298 /** 1299 * Initializes an {@link AccessibilityEvent} with information about 1300 * this View which is the event source. In other words, the source of 1301 * an accessibility event is the view whose state change triggered firing 1302 * the event. 1303 * <p> 1304 * Example: Setting the password property of an event in addition 1305 * to properties set by the super implementation: 1306 * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 1307 * super.onInitializeAccessibilityEvent(event); 1308 * event.setPassword(true); 1309 * }</pre> 1310 * <p> 1311 * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 1312 * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 1313 * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityEvent(View, 1314 * AccessibilityEvent)} 1315 * is responsible for handling this call. 1316 * </p> 1317 * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 1318 * information to the event, in case the default implementation has basic information to add. 1319 * </p> 1320 * 1321 * @param v The View against which to invoke the method. 1322 * @param event The event to initialize. 1323 * 1324 * @see View#sendAccessibilityEvent(int) 1325 * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 1326 */ 1327 public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1328 IMPL.onInitializeAccessibilityEvent(v, event); 1329 } 1330 1331 /** 1332 * Initializes an {@link android.view.accessibility.AccessibilityNodeInfo} with information 1333 * about this view. The base implementation sets: 1334 * <ul> 1335 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setParent(View)},</li> 1336 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> 1337 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> 1338 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setPackageName(CharSequence)},</li> 1339 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClassName(CharSequence)},</li> 1340 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> 1341 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setEnabled(boolean)},</li> 1342 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClickable(boolean)},</li> 1343 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocusable(boolean)},</li> 1344 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocused(boolean)},</li> 1345 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setLongClickable(boolean)},</li> 1346 * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setSelected(boolean)},</li> 1347 * </ul> 1348 * <p> 1349 * Subclasses should override this method, call the super implementation, 1350 * and set additional attributes. 1351 * </p> 1352 * <p> 1353 * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 1354 * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 1355 * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, 1356 * android.view.accessibility.AccessibilityNodeInfo)} 1357 * is responsible for handling this call. 1358 * </p> 1359 * 1360 * @param v The View against which to invoke the method. 1361 * @param info The instance to initialize. 1362 */ 1363 public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 1364 IMPL.onInitializeAccessibilityNodeInfo(v, info); 1365 } 1366 1367 /** 1368 * Sets a delegate for implementing accessibility support via compositon as 1369 * opposed to inheritance. The delegate's primary use is for implementing 1370 * backwards compatible widgets. For more details see 1371 * {@link android.view.View.AccessibilityDelegate}. 1372 * 1373 * @param v The View against which to invoke the method. 1374 * @param delegate The delegate instance. 1375 * 1376 * @see android.view.View.AccessibilityDelegate 1377 */ 1378 public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 1379 IMPL.setAccessibilityDelegate(v, delegate); 1380 } 1381 1382 /** 1383 * Checks whether provided View has an accessibility delegate attached to it. 1384 * 1385 * @param v The View instance to check 1386 * @return True if the View has an accessibility delegate 1387 */ 1388 public static boolean hasAccessibilityDelegate(View v) { 1389 return IMPL.hasAccessibilityDelegate(v); 1390 } 1391 1392 /** 1393 * Indicates whether the view is currently tracking transient state that the 1394 * app should not need to concern itself with saving and restoring, but that 1395 * the framework should take special note to preserve when possible. 1396 * 1397 * @param view View to check for transient state 1398 * @return true if the view has transient state 1399 */ 1400 public static boolean hasTransientState(View view) { 1401 return IMPL.hasTransientState(view); 1402 } 1403 1404 /** 1405 * Set whether this view is currently tracking transient state that the 1406 * framework should attempt to preserve when possible. 1407 * 1408 * @param view View tracking transient state 1409 * @param hasTransientState true if this view has transient state 1410 */ 1411 public static void setHasTransientState(View view, boolean hasTransientState) { 1412 IMPL.setHasTransientState(view, hasTransientState); 1413 } 1414 1415 /** 1416 * <p>Cause an invalidate to happen on the next animation time step, typically the 1417 * next display frame.</p> 1418 * 1419 * <p>This method can be invoked from outside of the UI thread 1420 * only when this View is attached to a window.</p> 1421 * 1422 * @param view View to invalidate 1423 */ 1424 public static void postInvalidateOnAnimation(View view) { 1425 IMPL.postInvalidateOnAnimation(view); 1426 } 1427 1428 /** 1429 * <p>Cause an invalidate of the specified area to happen on the next animation 1430 * time step, typically the next display frame.</p> 1431 * 1432 * <p>This method can be invoked from outside of the UI thread 1433 * only when this View is attached to a window.</p> 1434 * 1435 * @param view View to invalidate 1436 * @param left The left coordinate of the rectangle to invalidate. 1437 * @param top The top coordinate of the rectangle to invalidate. 1438 * @param right The right coordinate of the rectangle to invalidate. 1439 * @param bottom The bottom coordinate of the rectangle to invalidate. 1440 */ 1441 public static void postInvalidateOnAnimation(View view, int left, int top, 1442 int right, int bottom) { 1443 IMPL.postInvalidateOnAnimation(view, left, top, right, bottom); 1444 } 1445 1446 /** 1447 * <p>Causes the Runnable to execute on the next animation time step. 1448 * The runnable will be run on the user interface thread.</p> 1449 * 1450 * <p>This method can be invoked from outside of the UI thread 1451 * only when this View is attached to a window.</p> 1452 * 1453 * @param view View to post this Runnable to 1454 * @param action The Runnable that will be executed. 1455 */ 1456 public static void postOnAnimation(View view, Runnable action) { 1457 IMPL.postOnAnimation(view, action); 1458 } 1459 1460 /** 1461 * <p>Causes the Runnable to execute on the next animation time step, 1462 * after the specified amount of time elapses. 1463 * The runnable will be run on the user interface thread.</p> 1464 * 1465 * <p>This method can be invoked from outside of the UI thread 1466 * only when this View is attached to a window.</p> 1467 * 1468 * @param view The view to post this Runnable to 1469 * @param action The Runnable that will be executed. 1470 * @param delayMillis The delay (in milliseconds) until the Runnable 1471 * will be executed. 1472 */ 1473 public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 1474 IMPL.postOnAnimationDelayed(view, action, delayMillis); 1475 } 1476 1477 /** 1478 * Gets the mode for determining whether this View is important for accessibility 1479 * which is if it fires accessibility events and if it is reported to 1480 * accessibility services that query the screen. 1481 * 1482 * @param view The view whose property to get. 1483 * @return The mode for determining whether a View is important for accessibility. 1484 * 1485 * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 1486 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 1487 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 1488 * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 1489 */ 1490 @ImportantForAccessibility 1491 public static int getImportantForAccessibility(View view) { 1492 return IMPL.getImportantForAccessibility(view); 1493 } 1494 1495 /** 1496 * Sets how to determine whether this view is important for accessibility 1497 * which is if it fires accessibility events and if it is reported to 1498 * accessibility services that query the screen. 1499 * <p> 1500 * <em>Note:</em> If the current paltform version does not support the 1501 * {@link #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS} mode, then 1502 * {@link #IMPORTANT_FOR_ACCESSIBILITY_NO} will be used as it is the 1503 * closest terms of semantics. 1504 * </p> 1505 * 1506 * @param view The view whose property to set. 1507 * @param mode How to determine whether this view is important for accessibility. 1508 * 1509 * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 1510 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 1511 * @see #IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS 1512 * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 1513 */ 1514 public static void setImportantForAccessibility(View view, 1515 @ImportantForAccessibility int mode) { 1516 IMPL.setImportantForAccessibility(view, mode); 1517 } 1518 1519 /** 1520 * Performs the specified accessibility action on the view. For 1521 * possible accessibility actions look at {@link AccessibilityNodeInfoCompat}. 1522 * <p> 1523 * If an {@link AccessibilityDelegateCompat} has been specified via calling 1524 * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 1525 * {@link AccessibilityDelegateCompat#performAccessibilityAction(View, int, Bundle)} 1526 * is responsible for handling this call. 1527 * </p> 1528 * 1529 * @param action The action to perform. 1530 * @param arguments Optional action arguments. 1531 * @return Whether the action was performed. 1532 */ 1533 public static boolean performAccessibilityAction(View view, int action, Bundle arguments) { 1534 return IMPL.performAccessibilityAction(view, action, arguments); 1535 } 1536 1537 /** 1538 * Gets the provider for managing a virtual view hierarchy rooted at this View 1539 * and reported to {@link android.accessibilityservice.AccessibilityService}s 1540 * that explore the window content. 1541 * <p> 1542 * If this method returns an instance, this instance is responsible for managing 1543 * {@link AccessibilityNodeInfoCompat}s describing the virtual sub-tree rooted at 1544 * this View including the one representing the View itself. Similarly the returned 1545 * instance is responsible for performing accessibility actions on any virtual 1546 * view or the root view itself. 1547 * </p> 1548 * <p> 1549 * If an {@link AccessibilityDelegateCompat} has been specified via calling 1550 * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 1551 * {@link AccessibilityDelegateCompat#getAccessibilityNodeProvider(View)} 1552 * is responsible for handling this call. 1553 * </p> 1554 * 1555 * @param view The view whose property to get. 1556 * @return The provider. 1557 * 1558 * @see AccessibilityNodeProviderCompat 1559 */ 1560 public static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 1561 return IMPL.getAccessibilityNodeProvider(view); 1562 } 1563 1564 /** 1565 * The opacity of the view. This is a value from 0 to 1, where 0 means the view is 1566 * completely transparent and 1 means the view is completely opaque. 1567 * 1568 * <p>By default this is 1.0f. Prior to API 11, the returned value is always 1.0f. 1569 * @return The opacity of the view. 1570 */ 1571 public static float getAlpha(View view) { 1572 return IMPL.getAlpha(view); 1573 } 1574 1575 /** 1576 * <p>Specifies the type of layer backing this view. The layer can be 1577 * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or 1578 * {@link #LAYER_TYPE_HARDWARE hardware}.</p> 1579 * 1580 * <p>A layer is associated with an optional {@link android.graphics.Paint} 1581 * instance that controls how the layer is composed on screen. The following 1582 * properties of the paint are taken into account when composing the layer:</p> 1583 * <ul> 1584 * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> 1585 * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> 1586 * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> 1587 * </ul> 1588 * 1589 * <p>If this view has an alpha value set to < 1.0 by calling 1590 * setAlpha(float), the alpha value of the layer's paint is replaced by 1591 * this view's alpha value. Calling setAlpha(float) is therefore 1592 * equivalent to setting a hardware layer on this view and providing a paint with 1593 * the desired alpha value.<p> 1594 * 1595 * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, 1596 * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} 1597 * for more information on when and how to use layers.</p> 1598 * 1599 * @param layerType The ype of layer to use with this view, must be one of 1600 * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or 1601 * {@link #LAYER_TYPE_HARDWARE} 1602 * @param paint The paint used to compose the layer. This argument is optional 1603 * and can be null. It is ignored when the layer type is 1604 * {@link #LAYER_TYPE_NONE} 1605 * 1606 * @param view View to set the layer type for 1607 * @param layerType The type of layer to use with this view, must be one of 1608 * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or 1609 * {@link #LAYER_TYPE_HARDWARE} 1610 * @param paint The paint used to compose the layer. This argument is optional 1611 * and can be null. It is ignored when the layer type is 1612 * {@link #LAYER_TYPE_NONE} 1613 */ 1614 public static void setLayerType(View view, @LayerType int layerType, Paint paint) { 1615 IMPL.setLayerType(view, layerType, paint); 1616 } 1617 1618 /** 1619 * Indicates what type of layer is currently associated with this view. By default 1620 * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. 1621 * Refer to the documentation of 1622 * {@link #setLayerType(android.view.View, int, android.graphics.Paint)} 1623 * for more information on the different types of layers. 1624 * 1625 * @param view The view to fetch the layer type from 1626 * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or 1627 * {@link #LAYER_TYPE_HARDWARE} 1628 * 1629 * @see #setLayerType(android.view.View, int, android.graphics.Paint) 1630 * @see #LAYER_TYPE_NONE 1631 * @see #LAYER_TYPE_SOFTWARE 1632 * @see #LAYER_TYPE_HARDWARE 1633 */ 1634 @LayerType 1635 public static int getLayerType(View view) { 1636 return IMPL.getLayerType(view); 1637 } 1638 1639 /** 1640 * Gets the id of a view for which a given view serves as a label for 1641 * accessibility purposes. 1642 * 1643 * @param view The view on which to invoke the corresponding method. 1644 * @return The labeled view id. 1645 */ 1646 public static int getLabelFor(View view) { 1647 return IMPL.getLabelFor(view); 1648 } 1649 1650 /** 1651 * Sets the id of a view for which a given view serves as a label for 1652 * accessibility purposes. 1653 * 1654 * @param view The view on which to invoke the corresponding method. 1655 * @param labeledId The labeled view id. 1656 */ 1657 public static void setLabelFor(View view, @IdRes int labeledId) { 1658 IMPL.setLabelFor(view, labeledId); 1659 } 1660 1661 /** 1662 * Updates the {@link Paint} object used with the current layer (used only if the current 1663 * layer type is not set to {@link #LAYER_TYPE_NONE}). Changed properties of the Paint 1664 * provided to {@link #setLayerType(android.view.View, int, android.graphics.Paint)} 1665 * will be used the next time the View is redrawn, but 1666 * {@link #setLayerPaint(android.view.View, android.graphics.Paint)} 1667 * must be called to ensure that the view gets redrawn immediately. 1668 * 1669 * <p>A layer is associated with an optional {@link android.graphics.Paint} 1670 * instance that controls how the layer is composed on screen. The following 1671 * properties of the paint are taken into account when composing the layer:</p> 1672 * <ul> 1673 * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> 1674 * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> 1675 * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> 1676 * </ul> 1677 * 1678 * <p>If this view has an alpha value set to < 1.0 by calling 1679 * View#setAlpha(float), the alpha value of the layer's paint is replaced by 1680 * this view's alpha value. Calling View#setAlpha(float) is therefore 1681 * equivalent to setting a hardware layer on this view and providing a paint with 1682 * the desired alpha value.</p> 1683 * 1684 * @param view View to set a layer paint for 1685 * @param paint The paint used to compose the layer. This argument is optional 1686 * and can be null. It is ignored when the layer type is 1687 * {@link #LAYER_TYPE_NONE} 1688 * 1689 * @see #setLayerType(View, int, android.graphics.Paint) 1690 */ 1691 public static void setLayerPaint(View view, Paint paint) { 1692 IMPL.setLayerPaint(view, paint); 1693 } 1694 1695 /** 1696 * Returns the resolved layout direction for this view. 1697 * 1698 * @param view View to get layout direction for 1699 * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns 1700 * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. 1701 * 1702 * For compatibility, this will return {@link #LAYOUT_DIRECTION_LTR} if API version 1703 * is lower than Jellybean MR1 (API 17) 1704 */ 1705 @ResolvedLayoutDirectionMode 1706 public static int getLayoutDirection(View view) { 1707 return IMPL.getLayoutDirection(view); 1708 } 1709 1710 /** 1711 * Set the layout direction for this view. This will propagate a reset of layout direction 1712 * resolution to the view's children and resolve layout direction for this view. 1713 * 1714 * @param view View to set layout direction for 1715 * @param layoutDirection the layout direction to set. Should be one of: 1716 * 1717 * {@link #LAYOUT_DIRECTION_LTR}, 1718 * {@link #LAYOUT_DIRECTION_RTL}, 1719 * {@link #LAYOUT_DIRECTION_INHERIT}, 1720 * {@link #LAYOUT_DIRECTION_LOCALE}. 1721 * 1722 * Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution 1723 * proceeds up the parent chain of the view to get the value. If there is no parent, then it 1724 * will return the default {@link #LAYOUT_DIRECTION_LTR}. 1725 */ 1726 public static void setLayoutDirection(View view, @LayoutDirectionMode int layoutDirection) { 1727 IMPL.setLayoutDirection(view, layoutDirection); 1728 } 1729 1730 /** 1731 * Gets the parent for accessibility purposes. Note that the parent for 1732 * accessibility is not necessary the immediate parent. It is the first 1733 * predecessor that is important for accessibility. 1734 * 1735 * @param view View to retrieve parent for 1736 * @return The parent for use in accessibility inspection 1737 */ 1738 public static ViewParent getParentForAccessibility(View view) { 1739 return IMPL.getParentForAccessibility(view); 1740 } 1741 1742 /** 1743 * Indicates whether this View is opaque. An opaque View guarantees that it will 1744 * draw all the pixels overlapping its bounds using a fully opaque color. 1745 * 1746 * On API 7 and above this will call View's true isOpaque method. On previous platform 1747 * versions it will check the opacity of the view's background drawable if present. 1748 * 1749 * @return True if this View is guaranteed to be fully opaque, false otherwise. 1750 */ 1751 public static boolean isOpaque(View view) { 1752 return IMPL.isOpaque(view); 1753 } 1754 1755 /** 1756 * Utility to reconcile a desired size and state, with constraints imposed 1757 * by a MeasureSpec. Will take the desired size, unless a different size 1758 * is imposed by the constraints. The returned value is a compound integer, 1759 * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and 1760 * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting 1761 * size is smaller than the size the view wants to be. 1762 * 1763 * @param size How big the view wants to be 1764 * @param measureSpec Constraints imposed by the parent 1765 * @return Size information bit mask as defined by 1766 * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. 1767 */ 1768 public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { 1769 return IMPL.resolveSizeAndState(size, measureSpec, childMeasuredState); 1770 } 1771 1772 /** 1773 * Return the full width measurement information for this view as computed 1774 * by the most recent call to {@link android.view.View#measure(int, int)}. 1775 * This result is a bit mask as defined by {@link #MEASURED_SIZE_MASK} and 1776 * {@link #MEASURED_STATE_TOO_SMALL}. 1777 * This should be used during measurement and layout calculations only. Use 1778 * {@link android.view.View#getWidth()} to see how wide a view is after layout. 1779 * 1780 * @return The measured width of this view as a bit mask. 1781 */ 1782 public static int getMeasuredWidthAndState(View view) { 1783 return IMPL.getMeasuredWidthAndState(view); 1784 } 1785 1786 /** 1787 * Return the full height measurement information for this view as computed 1788 * by the most recent call to {@link android.view.View#measure(int, int)}. 1789 * This result is a bit mask as defined by {@link #MEASURED_SIZE_MASK} and 1790 * {@link #MEASURED_STATE_TOO_SMALL}. 1791 * This should be used during measurement and layout calculations only. Use 1792 * {@link android.view.View#getHeight()} to see how wide a view is after layout. 1793 * 1794 * @return The measured width of this view as a bit mask. 1795 */ 1796 public static int getMeasuredHeightAndState(View view) { 1797 return IMPL.getMeasuredHeightAndState(view); 1798 } 1799 1800 /** 1801 * Return only the state bits of {@link #getMeasuredWidthAndState} 1802 * and {@link #getMeasuredHeightAndState}, combined into one integer. 1803 * The width component is in the regular bits {@link #MEASURED_STATE_MASK} 1804 * and the height component is at the shifted bits 1805 * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. 1806 */ 1807 public static int getMeasuredState(View view) { 1808 return IMPL.getMeasuredState(view); 1809 } 1810 1811 /** 1812 * Gets the live region mode for the specified View. 1813 * 1814 * @param view The view from which to obtain the live region mode 1815 * @return The live region mode for the view. 1816 * 1817 * @see ViewCompat#setAccessibilityLiveRegion(View, int) 1818 */ 1819 @AccessibilityLiveRegion 1820 public static int getAccessibilityLiveRegion(View view) { 1821 return IMPL.getAccessibilityLiveRegion(view); 1822 } 1823 1824 /** 1825 * Sets the live region mode for the specified view. This indicates to 1826 * accessibility services whether they should automatically notify the user 1827 * about changes to the view's content description or text, or to the 1828 * content descriptions or text of the view's children (where applicable). 1829 * <p> 1830 * For example, in a login screen with a TextView that displays an "incorrect 1831 * password" notification, that view should be marked as a live region with 1832 * mode {@link #ACCESSIBILITY_LIVE_REGION_POLITE}. 1833 * <p> 1834 * To disable change notifications for this view, use 1835 * {@link #ACCESSIBILITY_LIVE_REGION_NONE}. This is the default live region 1836 * mode for most views. 1837 * <p> 1838 * To indicate that the user should be notified of changes, use 1839 * {@link #ACCESSIBILITY_LIVE_REGION_POLITE}. 1840 * <p> 1841 * If the view's changes should interrupt ongoing speech and notify the user 1842 * immediately, use {@link #ACCESSIBILITY_LIVE_REGION_ASSERTIVE}. 1843 * 1844 * @param view The view on which to set the live region mode 1845 * @param mode The live region mode for this view, one of: 1846 * <ul> 1847 * <li>{@link #ACCESSIBILITY_LIVE_REGION_NONE} 1848 * <li>{@link #ACCESSIBILITY_LIVE_REGION_POLITE} 1849 * <li>{@link #ACCESSIBILITY_LIVE_REGION_ASSERTIVE} 1850 * </ul> 1851 */ 1852 public static void setAccessibilityLiveRegion(View view, @AccessibilityLiveRegion int mode) { 1853 IMPL.setAccessibilityLiveRegion(view, mode); 1854 } 1855 1856 /** 1857 * Returns the start padding of the specified view depending on its resolved layout direction. 1858 * If there are inset and enabled scrollbars, this value may include the space 1859 * required to display the scrollbars as well. 1860 * 1861 * @param view The view to get padding for 1862 * @return the start padding in pixels 1863 */ 1864 public static int getPaddingStart(View view) { 1865 return IMPL.getPaddingStart(view); 1866 } 1867 1868 /** 1869 * Returns the end padding of the specified view depending on its resolved layout direction. 1870 * If there are inset and enabled scrollbars, this value may include the space 1871 * required to display the scrollbars as well. 1872 * 1873 * @param view The view to get padding for 1874 * @return the end padding in pixels 1875 */ 1876 public static int getPaddingEnd(View view) { 1877 return IMPL.getPaddingEnd(view); 1878 } 1879 1880 /** 1881 * Sets the relative padding. The view may add on the space required to display 1882 * the scrollbars, depending on the style and visibility of the scrollbars. 1883 * So the values returned from {@link #getPaddingStart}, {@link View#getPaddingTop}, 1884 * {@link #getPaddingEnd} and {@link View#getPaddingBottom} may be different 1885 * from the values set in this call. 1886 * 1887 * @param view The view on which to set relative padding 1888 * @param start the start padding in pixels 1889 * @param top the top padding in pixels 1890 * @param end the end padding in pixels 1891 * @param bottom the bottom padding in pixels 1892 */ 1893 public static void setPaddingRelative(View view, int start, int top, int end, int bottom) { 1894 IMPL.setPaddingRelative(view, start, top, end, bottom); 1895 } 1896 1897 /** 1898 * Notify a view that it is being temporarily detached. 1899 */ 1900 public static void dispatchStartTemporaryDetach(View view) { 1901 IMPL.dispatchStartTemporaryDetach(view); 1902 } 1903 1904 /** 1905 * Notify a view that its temporary detach has ended; the view is now reattached. 1906 */ 1907 public static void dispatchFinishTemporaryDetach(View view) { 1908 IMPL.dispatchFinishTemporaryDetach(view); 1909 } 1910 1911 /** 1912 * The horizontal location of this view relative to its {@link View#getLeft() left} position. 1913 * This position is post-layout, in addition to wherever the object's 1914 * layout placed it. 1915 * 1916 * <p>Prior to API 11 this will return 0.</p> 1917 * 1918 * @return The horizontal position of this view relative to its left position, in pixels. 1919 */ 1920 public static float getTranslationX(View view) { 1921 return IMPL.getTranslationX(view); 1922 } 1923 1924 /** 1925 * The vertical location of this view relative to its {@link View#getTop() left} position. 1926 * This position is post-layout, in addition to wherever the object's 1927 * layout placed it. 1928 * 1929 * <p>Prior to API 11 this will return 0.</p> 1930 * 1931 * @return The vertical position of this view relative to its top position, in pixels. 1932 */ 1933 public static float getTranslationY(View view) { 1934 return IMPL.getTranslationY(view); 1935 } 1936 1937 /** 1938 * Returns the minimum width of the view. 1939 * 1940 * <p>Prior to API 16 this will return 0.</p> 1941 * 1942 * @return the minimum width the view will try to be. 1943 */ 1944 public static int getMinimumWidth(View view) { 1945 return IMPL.getMinimumWidth(view); 1946 } 1947 1948 /** 1949 * Returns the minimum height of the view. 1950 * 1951 * <p>Prior to API 16 this will return 0.</p> 1952 * 1953 * @return the minimum height the view will try to be. 1954 */ 1955 public static int getMinimumHeight(View view) { 1956 return IMPL.getMinimumHeight(view); 1957 } 1958 1959 /** 1960 * This method returns a ViewPropertyAnimator object, which can be used to animate 1961 * specific properties on this View. 1962 * 1963 * <p>Prior to API 14, this method will do nothing.</p> 1964 * 1965 * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. 1966 */ 1967 public static ViewPropertyAnimatorCompat animate(View view) { 1968 return IMPL.animate(view); 1969 } 1970 1971 /** 1972 * Sets the horizontal location of this view relative to its left position. 1973 * This effectively positions the object post-layout, in addition to wherever the object's 1974 * layout placed it. 1975 * 1976 * <p>Prior to API 11 this will have no effect.</p> 1977 * 1978 * @param value The horizontal position of this view relative to its left position, 1979 * in pixels. 1980 */ 1981 public static void setTranslationX(View view, float value) { 1982 IMPL.setTranslationX(view, value); 1983 } 1984 1985 /** 1986 * Sets the vertical location of this view relative to its top position. 1987 * This effectively positions the object post-layout, in addition to wherever the object's 1988 * layout placed it. 1989 * 1990 * <p>Prior to API 11 this will have no effect.</p> 1991 * 1992 * @param value The vertical position of this view relative to its top position, 1993 * in pixels. 1994 * 1995 * @attr ref android.R.styleable#View_translationY 1996 */ 1997 public static void setTranslationY(View view, float value) { 1998 IMPL.setTranslationY(view, value); 1999 } 2000 2001 /** 2002 * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is 2003 * completely transparent and 1 means the view is completely opaque.</p> 2004 * 2005 * <p> Note that setting alpha to a translucent value (0 < alpha < 1) can have significant 2006 * performance implications, especially for large views. It is best to use the alpha property 2007 * sparingly and transiently, as in the case of fading animations.</p> 2008 * 2009 * <p>Prior to API 11 this will have no effect.</p> 2010 * 2011 * @param value The opacity of the view. 2012 */ 2013 public static void setAlpha(View view, float value) { 2014 IMPL.setAlpha(view, value); 2015 } 2016 2017 /** 2018 * Sets the visual x position of this view, in pixels. This is equivalent to setting the 2019 * {@link #setTranslationX(View, float) translationX} property to be the difference between 2020 * the x value passed in and the current left property of the view as determined 2021 * by the layout bounds. 2022 * 2023 * <p>Prior to API 11 this will have no effect.</p> 2024 * 2025 * @param value The visual x position of this view, in pixels. 2026 */ 2027 public static void setX(View view, float value) { 2028 IMPL.setX(view, value); 2029 } 2030 2031 /** 2032 * Sets the visual y position of this view, in pixels. This is equivalent to setting the 2033 * {@link #setTranslationY(View, float) translationY} property to be the difference between 2034 * the y value passed in and the current top property of the view as determined by the 2035 * layout bounds. 2036 * 2037 * <p>Prior to API 11 this will have no effect.</p> 2038 * 2039 * @param value The visual y position of this view, in pixels. 2040 */ 2041 public static void setY(View view, float value) { 2042 IMPL.setY(view, value); 2043 } 2044 2045 /** 2046 * Sets the degrees that the view is rotated around the pivot point. Increasing values 2047 * result in clockwise rotation. 2048 * 2049 * <p>Prior to API 11 this will have no effect.</p> 2050 * 2051 * @param value The degrees of rotation. 2052 */ 2053 public static void setRotation(View view, float value) { 2054 IMPL.setRotation(view, value); 2055 } 2056 2057 /** 2058 * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. 2059 * Increasing values result in clockwise rotation from the viewpoint of looking down the 2060 * x axis. 2061 * 2062 * <p>Prior to API 11 this will have no effect.</p> 2063 * 2064 * @param value The degrees of X rotation. 2065 */ 2066 public static void setRotationX(View view, float value) { 2067 IMPL.setRotationX(view, value); 2068 } 2069 2070 /** 2071 * Sets the degrees that the view is rotated around the vertical axis through the pivot point. 2072 * Increasing values result in counter-clockwise rotation from the viewpoint of looking 2073 * down the y axis. 2074 * 2075 * <p>Prior to API 11 this will have no effect.</p> 2076 * 2077 * @param value The degrees of Y rotation. 2078 */ 2079 public static void setRotationY(View view, float value) { 2080 IMPL.setRotationY(view, value); 2081 } 2082 2083 /** 2084 * Sets the amount that the view is scaled in x around the pivot point, as a proportion of 2085 * the view's unscaled width. A value of 1 means that no scaling is applied. 2086 * 2087 * <p>Prior to API 11 this will have no effect.</p> 2088 * 2089 * @param value The scaling factor. 2090 */ 2091 public static void setScaleX(View view, float value) { 2092 IMPL.setScaleX(view, value); 2093 } 2094 2095 /** 2096 * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of 2097 * the view's unscaled width. A value of 1 means that no scaling is applied. 2098 * 2099 * <p>Prior to API 11 this will have no effect.</p> 2100 * 2101 * @param value The scaling factor. 2102 */ 2103 public static void setScaleY(View view, float value) { 2104 IMPL.setScaleY(view, value); 2105 } 2106 2107 /** 2108 * The x location of the point around which the view is 2109 * {@link #setRotation(View, float) rotated} and {@link #setScaleX(View, float) scaled}. 2110 * 2111 * <p>Prior to API 11 this will have no effect.</p> 2112 * 2113 */ 2114 public static float getPivotX(View view) { 2115 return IMPL.getPivotX(view); 2116 } 2117 2118 /** 2119 * Sets the x location of the point around which the view is 2120 * {@link #setRotation(View, float) rotated} and {@link #setScaleX(View, float) scaled}. 2121 * By default, the pivot point is centered on the object. 2122 * Setting this property disables this behavior and causes the view to use only the 2123 * explicitly set pivotX and pivotY values. 2124 * 2125 * <p>Prior to API 11 this will have no effect.</p> 2126 * 2127 * @param value The x location of the pivot point. 2128 */ 2129 public static void setPivotX(View view, float value) { 2130 IMPL.setPivotX(view, value); 2131 } 2132 2133 /** 2134 * The y location of the point around which the view is {@link #setRotation(View, 2135 * float) rotated} and {@link #setScaleY(View, float) scaled}. 2136 * 2137 * <p>Prior to API 11 this will return 0.</p> 2138 * 2139 * @return The y location of the pivot point. 2140 */ 2141 public static float getPivotY(View view) { 2142 return IMPL.getPivotY(view); 2143 } 2144 2145 /** 2146 * Sets the y location of the point around which the view is 2147 * {@link #setRotation(View, float) rotated} and {@link #setScaleY(View, float) scaled}. 2148 * By default, the pivot point is centered on the object. 2149 * Setting this property disables this behavior and causes the view to use only the 2150 * explicitly set pivotX and pivotY values. 2151 * 2152 * <p>Prior to API 11 this will have no effect.</p> 2153 * 2154 * @param value The y location of the pivot point. 2155 */ 2156 public static void setPivotY(View view, float value) { 2157 IMPL.setPivotX(view, value); 2158 } 2159 2160 public static float getRotation(View view) { 2161 return IMPL.getRotation(view); 2162 } 2163 2164 public static float getRotationX(View view) { 2165 return IMPL.getRotationX(view); 2166 } 2167 2168 public static float getRotationY(View view) { 2169 return IMPL.getRotationY(view); 2170 } 2171 2172 public static float getScaleX(View view) { 2173 return IMPL.getScaleX(view); 2174 } 2175 2176 public static float getScaleY(View view) { 2177 return IMPL.getScaleY(view); 2178 } 2179 2180 public static float getX(View view) { 2181 return IMPL.getX(view); 2182 } 2183 2184 public static float getY(View view) { 2185 return IMPL.getY(view); 2186 } 2187 2188 /** 2189 * Sets the base elevation of this view, in pixels. 2190 */ 2191 public static void setElevation(View view, float elevation) { 2192 IMPL.setElevation(view, elevation); 2193 } 2194 2195 /** 2196 * The base elevation of this view relative to its parent, in pixels. 2197 * 2198 * @return The base depth position of the view, in pixels. 2199 */ 2200 public static float getElevation(View view) { 2201 return IMPL.getElevation(view); 2202 } 2203 2204 /** 2205 * Sets the depth location of this view relative to its {@link #getElevation(View) elevation}. 2206 */ 2207 public static void setTranslationZ(View view, float translationZ) { 2208 IMPL.setTranslationZ(view, translationZ); 2209 } 2210 2211 /** 2212 * The depth location of this view relative to its {@link #getElevation(View) elevation}. 2213 * 2214 * @return The depth of this view relative to its elevation. 2215 */ 2216 public static float getTranslationZ(View view) { 2217 return IMPL.getTranslationZ(view); 2218 } 2219 2220 /** 2221 * Sets the name of the View to be used to identify Views in Transitions. 2222 * Names should be unique in the View hierarchy. 2223 * 2224 * @param view The View against which to invoke the method. 2225 * @param transitionName The name of the View to uniquely identify it for Transitions. 2226 */ 2227 public static void setTransitionName(View view, String transitionName) { 2228 IMPL.setTransitionName(view, transitionName); 2229 } 2230 2231 /** 2232 * Returns the name of the View to be used to identify Views in Transitions. 2233 * Names should be unique in the View hierarchy. 2234 * 2235 * <p>This returns null if the View has not been given a name.</p> 2236 * 2237 * @param view The View against which to invoke the method. 2238 * @return The name used of the View to be used to identify Views in Transitions or null 2239 * if no name has been given. 2240 */ 2241 public static String getTransitionName(View view) { 2242 return IMPL.getTransitionName(view); 2243 } 2244 2245 /** 2246 * Returns the current system UI visibility that is currently set for the entire window. 2247 */ 2248 public static int getWindowSystemUiVisibility(View view) { 2249 return IMPL.getWindowSystemUiVisibility(view); 2250 } 2251 2252 /** 2253 * Ask that a new dispatch of {@code View.onApplyWindowInsets(WindowInsets)} be performed. This 2254 * falls back to {@code View.requestFitSystemWindows()} where available. 2255 */ 2256 public static void requestApplyInsets(View view) { 2257 IMPL.requestApplyInsets(view); 2258 } 2259 2260 /** 2261 * Tells the ViewGroup whether to draw its children in the order defined by the method 2262 * {@code ViewGroup.getChildDrawingOrder(int, int)}. 2263 * 2264 * @param enabled true if the order of the children when drawing is determined by 2265 * {@link ViewGroup#getChildDrawingOrder(int, int)}, false otherwise 2266 * 2267 * <p>Prior to API 7 this will have no effect.</p> 2268 */ 2269 public static void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled) { 2270 IMPL.setChildrenDrawingOrderEnabled(viewGroup, enabled); 2271 } 2272 2273 /** 2274 * Returns true if this view should adapt to fit system window insets. This method will always 2275 * return false before API 16 (Jellybean). 2276 */ 2277 public static boolean getFitsSystemWindows(View v) { 2278 return IMPL.getFitsSystemWindows(v); 2279 } 2280 2281 /** 2282 * Sets whether or not this view should account for system screen decorations 2283 * such as the status bar and inset its content; that is, controlling whether 2284 * the default implementation of {@link View#fitSystemWindows(Rect)} will be 2285 * executed. See that method for more details. 2286 */ 2287 public static void setFitsSystemWindows(View view, boolean fitSystemWindows) { 2288 IMPL.setFitsSystemWindows(view, fitSystemWindows); 2289 } 2290 2291 /** 2292 * On API 11 devices and above, call <code>Drawable.jumpToCurrentState()</code> 2293 * on all Drawable objects associated with this view. 2294 * <p> 2295 * On API 21 and above, also calls <code>StateListAnimator#jumpToCurrentState()</code> 2296 * if there is a StateListAnimator attached to this view. 2297 */ 2298 public static void jumpDrawablesToCurrentState(View v) { 2299 IMPL.jumpDrawablesToCurrentState(v); 2300 } 2301 2302 /** 2303 * Set an {@link OnApplyWindowInsetsListener} to take over the policy for applying 2304 * window insets to this view. This will only take effect on devices with API 21 or above. 2305 */ 2306 public static void setOnApplyWindowInsetsListener(View v, 2307 OnApplyWindowInsetsListener listener) { 2308 IMPL.setOnApplyWindowInsetsListener(v, listener); 2309 } 2310 2311 /** 2312 * Controls whether the entire hierarchy under this view will save its 2313 * state when a state saving traversal occurs from its parent. 2314 * 2315 * @param enabled Set to false to <em>disable</em> state saving, or true 2316 * (the default) to allow it. 2317 */ 2318 public static void setSaveFromParentEnabled(View v, boolean enabled) { 2319 IMPL.setSaveFromParentEnabled(v, enabled); 2320 } 2321 2322 /** 2323 * Changes the activated state of this view. A view can be activated or not. 2324 * Note that activation is not the same as selection. Selection is 2325 * a transient property, representing the view (hierarchy) the user is 2326 * currently interacting with. Activation is a longer-term state that the 2327 * user can move views in and out of. 2328 * 2329 * @param activated true if the view must be activated, false otherwise 2330 */ 2331 public static void setActivated(View view, boolean activated) { 2332 IMPL.setActivated(view, activated); 2333 } 2334 2335 // TODO: getters for various view properties (rotation, etc) 2336} 2337