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