ViewCompat { @SuppressWarnings("TypeParameterUnusedInFormals") @NonNull public static <T extends View> T requireViewById(@NonNull View view, @IdRes int id) { T targetView = view.findViewById(id); if (targetView == null) { throw new IllegalArgumentException("ID does not reference a View inside this View"); } return targetView; } protected  ViewCompat(); @Deprecated static boolean canScrollHorizontally(View view, int direction); @Deprecated static boolean canScrollVertically(View view, int direction); @Deprecated @OverScroll static int getOverScrollMode(View v); @Deprecated static void setOverScrollMode(View v, @OverScroll int overScrollMode); @Deprecated static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event); @Deprecated static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event); static void onInitializeAccessibilityNodeInfo(@NonNull View v,
                                                         AccessibilityNodeInfoCompat info); static void setAccessibilityDelegate(@NonNull View v,
                                                AccessibilityDelegateCompat delegate); static void setAutofillHints(@NonNull View v, @Nullable String... autofillHints); @SuppressLint("InlinedApi") static @AutofillImportance int getImportantForAutofill(@NonNull View v); static void setImportantForAutofill(@NonNull View v, @AutofillImportance int mode); static boolean isImportantForAutofill(@NonNull View v); static boolean hasAccessibilityDelegate(@NonNull View v); static boolean hasTransientState(@NonNull View view); static void setHasTransientState(@NonNull View view, boolean hasTransientState); static void postInvalidateOnAnimation(@NonNull View view); static void postInvalidateOnAnimation(@NonNull View view, int left, int top,
                                                 int right, int bottom); static void postOnAnimation(@NonNull View view, Runnable action); static void postOnAnimationDelayed(@NonNull View view, Runnable action,
                                              long delayMillis); @ImportantForAccessibility static int getImportantForAccessibility(@NonNull View view); static void setImportantForAccessibility(@NonNull View view,
                                                    @ImportantForAccessibility int mode); static boolean isImportantForAccessibility(@NonNull View view); static boolean performAccessibilityAction(@NonNull View view, int action,
                                                     Bundle arguments); static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(@NonNull View view); @Deprecated static float getAlpha(View view); @Deprecated static void setLayerType(View view, @LayerType int layerType, Paint paint); @Deprecated @LayerType static int getLayerType(View view); static int getLabelFor(@NonNull View view); static void setLabelFor(@NonNull View view, @IdRes int labeledId); static void setLayerPaint(@NonNull View view, Paint paint); @ResolvedLayoutDirectionMode static int getLayoutDirection(@NonNull View view); static void setLayoutDirection(@NonNull View view,
                                          @LayoutDirectionMode int layoutDirection); static ViewParent getParentForAccessibility(@NonNull View view); @SuppressWarnings("TypeParameterUnusedInFormals") @NonNull static T requireViewById(@NonNull View view, @IdRes int id); @Deprecated static boolean isOpaque(View view); @Deprecated static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState); @Deprecated static int getMeasuredWidthAndState(View view); @Deprecated static int getMeasuredHeightAndState(View view); @Deprecated static int getMeasuredState(View view); @Deprecated static int combineMeasuredStates(int curState, int newState); @AccessibilityLiveRegion static int getAccessibilityLiveRegion(@NonNull View view); static void setAccessibilityLiveRegion(@NonNull View view,
                                                  @AccessibilityLiveRegion int mode); @Px static int getPaddingStart(@NonNull View view); @Px static int getPaddingEnd(@NonNull View view); static void setPaddingRelative(@NonNull View view, @Px int start, @Px int top,
                                          @Px int end, @Px int bottom); static void dispatchStartTemporaryDetach(@NonNull View view); static void dispatchFinishTemporaryDetach(@NonNull View view); @Deprecated static float getTranslationX(View view); @Deprecated static float getTranslationY(View view); @Deprecated @Nullable static Matrix getMatrix(View view); static int getMinimumWidth(@NonNull View view); static int getMinimumHeight(@NonNull View view); @NonNull static ViewPropertyAnimatorCompat animate(@NonNull View view); @Deprecated static void setTranslationX(View view, float value); @Deprecated static void setTranslationY(View view, float value); @Deprecated static void setAlpha(View view, @FloatRange(from = 0.0, to = 1.0) float value); @Deprecated static void setX(View view, float value); @Deprecated static void setY(View view, float value); @Deprecated static void setRotation(View view, float value); @Deprecated static void setRotationX(View view, float value); @Deprecated static void setRotationY(View view, float value); @Deprecated static void setScaleX(View view, float value); @Deprecated static void setScaleY(View view, float value); @Deprecated static float getPivotX(View view); @Deprecated static void setPivotX(View view, float value); @Deprecated static float getPivotY(View view); @Deprecated static void setPivotY(View view, float value); @Deprecated static float getRotation(View view); @Deprecated static float getRotationX(View view); @Deprecated static float getRotationY(View view); @Deprecated static float getScaleX(View view); @Deprecated static float getScaleY(View view); @Deprecated static float getX(View view); @Deprecated static float getY(View view); static void setElevation(@NonNull View view, float elevation); static float getElevation(@NonNull View view); static void setTranslationZ(@NonNull View view, float translationZ); static float getTranslationZ(@NonNull View view); static void setTransitionName(@NonNull View view, String transitionName); @Nullable static String getTransitionName(@NonNull View view); static int getWindowSystemUiVisibility(@NonNull View view); static void requestApplyInsets(@NonNull View view); @Deprecated static void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled); static boolean getFitsSystemWindows(@NonNull View v); @Deprecated static void setFitsSystemWindows(View view, boolean fitSystemWindows); @Deprecated static void jumpDrawablesToCurrentState(View v); static void setOnApplyWindowInsetsListener(@NonNull View v,
                                                      final OnApplyWindowInsetsListener listener); static WindowInsetsCompat onApplyWindowInsets(@NonNull View view,
                                                         WindowInsetsCompat insets); static WindowInsetsCompat dispatchApplyWindowInsets(@NonNull View view,
                                                               WindowInsetsCompat insets); @Deprecated static void setSaveFromParentEnabled(View v, boolean enabled); @Deprecated static void setActivated(View view, boolean activated); static boolean hasOverlappingRendering(@NonNull View view); static boolean isPaddingRelative(@NonNull View view); static void setBackground(@NonNull View view, @Nullable Drawable background); static ColorStateList getBackgroundTintList(@NonNull View view); static void setBackgroundTintList(@NonNull View view, ColorStateList tintList); static PorterDuff.Mode getBackgroundTintMode(@NonNull View view); static void setBackgroundTintMode(@NonNull View view, PorterDuff.Mode mode); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setNestedScrollingEnabled(@NonNull View view, boolean enabled); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean isNestedScrollingEnabled(@NonNull View view); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean startNestedScroll(@NonNull View view, @ScrollAxis int axes); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void stopNestedScroll(@NonNull View view); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean hasNestedScrollingParent(@NonNull View view); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean dispatchNestedScroll(@NonNull View view, int dxConsumed, int dyConsumed,
                                               int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean dispatchNestedPreScroll(@NonNull View view, int dx, int dy,
                                                  @Nullable int[] consumed, @Nullable int[] offsetInWindow); static boolean startNestedScroll(@NonNull View view, @ScrollAxis int axes,
                                            @NestedScrollType int type); static void stopNestedScroll(@NonNull View view, @NestedScrollType int type); static boolean hasNestedScrollingParent(@NonNull View view, @NestedScrollType int type); static boolean dispatchNestedScroll(@NonNull View view, int dxConsumed, int dyConsumed,
                                               int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow,
                                               @NestedScrollType int type); static boolean dispatchNestedPreScroll(@NonNull View view, int dx, int dy,
                                                  @Nullable int[] consumed, @Nullable int[] offsetInWindow, @NestedScrollType int type); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean dispatchNestedFling(@NonNull View view, float velocityX, float velocityY,
                                              boolean consumed); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static boolean dispatchNestedPreFling(@NonNull View view, float velocityX,
                                                 float velocityY); static boolean isInLayout(@NonNull View view); static boolean isLaidOut(@NonNull View view); static boolean isLayoutDirectionResolved(@NonNull View view); static float getZ(@NonNull View view); static void setZ(@NonNull View view, float z); static void offsetTopAndBottom(@NonNull View view, int offset); static void offsetLeftAndRight(@NonNull View view, int offset); static void setClipBounds(@NonNull View view, Rect clipBounds); @Nullable static Rect getClipBounds(@NonNull View view); static boolean isAttachedToWindow(@NonNull View view); static boolean hasOnClickListeners(@NonNull View view); static void setScrollIndicators(@NonNull View view, @ScrollIndicators int indicators); static void setScrollIndicators(@NonNull View view, @ScrollIndicators int indicators,
                                           @ScrollIndicators int mask); static int getScrollIndicators(@NonNull View view); static void setPointerIcon(@NonNull View view, PointerIconCompat pointerIcon); @Nullable static Display getDisplay(@NonNull View view); static void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText); static boolean startDragAndDrop(@NonNull View v, ClipData data,
                                           View.DragShadowBuilder shadowBuilder, Object localState, int flags); static void cancelDragAndDrop(@NonNull View v); static void updateDragShadow(@NonNull View v, View.DragShadowBuilder shadowBuilder); static int getNextClusterForwardId(@NonNull View view); static void setNextClusterForwardId(@NonNull View view, int nextClusterForwardId); static boolean isKeyboardNavigationCluster(@NonNull View view); static void setKeyboardNavigationCluster(@NonNull View view, boolean isCluster); static boolean isFocusedByDefault(@NonNull View view); static void setFocusedByDefault(@NonNull View view, boolean isFocusedByDefault); static View keyboardNavigationClusterSearch(@NonNull View view, View currentCluster,
                                                       @FocusDirection int direction); static void addKeyboardNavigationClusters(@NonNull View view,
                                                     @NonNull Collection<View> views, int direction); static boolean restoreDefaultFocus(@NonNull View view); static boolean hasExplicitFocusable(@NonNull View view); static int generateViewId(); @Deprecated
    static final int OVER_SCROLL_ALWAYS; @Deprecated
    static final int OVER_SCROLL_IF_CONTENT_SCROLLS; @Deprecated
    static final int OVER_SCROLL_NEVER; static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO; static final int IMPORTANT_FOR_ACCESSIBILITY_YES; static final int IMPORTANT_FOR_ACCESSIBILITY_NO; static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; static final int ACCESSIBILITY_LIVE_REGION_NONE; static final int ACCESSIBILITY_LIVE_REGION_POLITE; static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE; @Deprecated
    static final int LAYER_TYPE_NONE; @Deprecated
    static final int LAYER_TYPE_SOFTWARE; @Deprecated
    static final int LAYER_TYPE_HARDWARE; static final int LAYOUT_DIRECTION_LTR; static final int LAYOUT_DIRECTION_RTL; static final int LAYOUT_DIRECTION_INHERIT; static final int LAYOUT_DIRECTION_LOCALE; @Deprecated
    static final int MEASURED_SIZE_MASK; @Deprecated
    static final int MEASURED_STATE_MASK; @Deprecated
    static final int MEASURED_HEIGHT_STATE_SHIFT; @Deprecated
    static final int MEASURED_STATE_TOO_SMALL; static final int SCROLL_AXIS_NONE; static final int SCROLL_AXIS_HORIZONTAL; static final int SCROLL_AXIS_VERTICAL; static final int TYPE_TOUCH; static final int TYPE_NON_TOUCH; static final int SCROLL_INDICATOR_TOP; static final int SCROLL_INDICATOR_BOTTOM; static final int SCROLL_INDICATOR_LEFT; static final int SCROLL_INDICATOR_RIGHT; static final int SCROLL_INDICATOR_START; static final int SCROLL_INDICATOR_END; }
@Test public void testRequireViewByIdFound() { View container = mActivityTestRule.getActivity().findViewById(R.id.container); assertSame(mView, ViewCompat.requireViewById(container, R.id.view)); }
@Test(expected = IllegalArgumentException.class) public void testRequireViewByIdMissing() { View container = mActivityTestRule.getActivity().findViewById(R.id.container); ViewCompat.requireViewById(container, R.id.action_bar); }
@Test(expected = IllegalArgumentException.class) public void testRequireViewByIdInvalid() { View container = mActivityTestRule.getActivity().findViewById(R.id.container); ViewCompat.requireViewById(container, View.NO_ID); }