diff --git a/catalog/java/io/material/catalog/bottomsheet/BottomSheetScrollableContentDemoFragment.java b/catalog/java/io/material/catalog/bottomsheet/BottomSheetScrollableContentDemoFragment.java index 0edc178ce14..d2269661445 100644 --- a/catalog/java/io/material/catalog/bottomsheet/BottomSheetScrollableContentDemoFragment.java +++ b/catalog/java/io/material/catalog/bottomsheet/BottomSheetScrollableContentDemoFragment.java @@ -26,7 +26,6 @@ import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; @@ -74,7 +73,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { // Add the inset in the inner NestedScrollView instead to make the edge-to-edge behavior // consistent - i.e., the extra padding will only show at the bottom of all content, i.e., // only when you can no longer scroll down to show more content. - ViewCompat.setPaddingRelative(bottomSheetContent, + bottomSheetContent.setPaddingRelative( initialPadding.start, initialPadding.top, initialPadding.end, diff --git a/catalog/java/io/material/catalog/elevation/ElevationAnimationDemoFragment.java b/catalog/java/io/material/catalog/elevation/ElevationAnimationDemoFragment.java index 977abef2742..530096233f7 100644 --- a/catalog/java/io/material/catalog/elevation/ElevationAnimationDemoFragment.java +++ b/catalog/java/io/material/catalog/elevation/ElevationAnimationDemoFragment.java @@ -51,7 +51,7 @@ public View onCreateDemoView( MaterialShapeDrawable materialShapeDrawable = MaterialShapeDrawable.createWithElevationOverlay(view.getContext()); - ViewCompat.setBackground(view, materialShapeDrawable); + view.setBackground(materialShapeDrawable); setTranslationZ(view, materialShapeDrawable, maxTranslationZ); startTranslationZAnimation(view, materialShapeDrawable, maxTranslationZ); diff --git a/catalog/java/io/material/catalog/fab/FabMainDemoFragment.java b/catalog/java/io/material/catalog/fab/FabMainDemoFragment.java index 933a005f898..a27f8f23083 100644 --- a/catalog/java/io/material/catalog/fab/FabMainDemoFragment.java +++ b/catalog/java/io/material/catalog/fab/FabMainDemoFragment.java @@ -26,7 +26,6 @@ import android.widget.Button; import androidx.annotation.LayoutRes; import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import io.material.catalog.feature.DemoFragment; @@ -81,7 +80,7 @@ public View onCreateDemoView( for (FloatingActionButton fab : fabs) { fab.setRotation(0); - ViewCompat.animate(fab) + fab.animate() .rotation(360) .withLayer() .setDuration(1000) diff --git a/catalog/java/io/material/catalog/feature/BottomWindowInsetView.java b/catalog/java/io/material/catalog/feature/BottomWindowInsetView.java index 26fc07a3560..66e356eedb1 100644 --- a/catalog/java/io/material/catalog/feature/BottomWindowInsetView.java +++ b/catalog/java/io/material/catalog/feature/BottomWindowInsetView.java @@ -49,7 +49,7 @@ public BottomWindowInsetView(Context context, @Nullable AttributeSet attrs, protected void onAttachedToWindow() { super.onAttachedToWindow(); ViewGroup parent = (ViewGroup) getParent(); - while (parent != null && !ViewCompat.getFitsSystemWindows(parent)) { + while (parent != null && !parent.getFitsSystemWindows()) { parent = (ViewGroup) parent.getParent(); } diff --git a/catalog/java/io/material/catalog/feature/DemoLandingFragment.java b/catalog/java/io/material/catalog/feature/DemoLandingFragment.java index 9c8f20cd600..f44682553c0 100644 --- a/catalog/java/io/material/catalog/feature/DemoLandingFragment.java +++ b/catalog/java/io/material/catalog/feature/DemoLandingFragment.java @@ -44,7 +44,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; -import androidx.core.view.MarginLayoutParamsCompat; import androidx.core.view.MenuItemCompat; import androidx.core.view.ViewCompat; import com.google.android.material.button.MaterialButton; @@ -296,7 +295,7 @@ private boolean isFavoriteLaunch() { private void setMarginStart(View view, @DimenRes int marginResId) { int margin = getResources().getDimensionPixelOffset(marginResId); MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(layoutParams, margin); + layoutParams.setMarginStart(margin); } @Override diff --git a/catalog/java/io/material/catalog/musicplayer/MusicPlayerLibraryDemoFragment.java b/catalog/java/io/material/catalog/musicplayer/MusicPlayerLibraryDemoFragment.java index 3224af25b75..c9c6da87100 100644 --- a/catalog/java/io/material/catalog/musicplayer/MusicPlayerLibraryDemoFragment.java +++ b/catalog/java/io/material/catalog/musicplayer/MusicPlayerLibraryDemoFragment.java @@ -55,7 +55,7 @@ public class MusicPlayerLibraryDemoFragment extends Fragment implements AlbumAdapterListener, OnMenuItemClickListener { private static final int GRID_SPAN_COUNT = 2; - private static final int ALBUM_RECYCLER_VIEW_ID = ViewCompat.generateViewId(); + private static final int ALBUM_RECYCLER_VIEW_ID = View.generateViewId(); private FrameLayout listContainer; private Parcelable listState = null; diff --git a/catalog/java/io/material/catalog/preferences/CatalogPreferencesDialogFragment.java b/catalog/java/io/material/catalog/preferences/CatalogPreferencesDialogFragment.java index 402e168b6c4..ce1cbbd8748 100644 --- a/catalog/java/io/material/catalog/preferences/CatalogPreferencesDialogFragment.java +++ b/catalog/java/io/material/catalog/preferences/CatalogPreferencesDialogFragment.java @@ -29,7 +29,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.button.MaterialButton; import com.google.android.material.button.MaterialButtonToggleGroup; @@ -124,7 +123,7 @@ private MaterialButton createOptionButton( MaterialButton button = (MaterialButton) layoutInflater.inflate( R.layout.mtrl_preferences_dialog_option_button, rootView, false); - int buttonId = ViewCompat.generateViewId(); + int buttonId = View.generateViewId(); buttonIdToOptionId.append(buttonId, option.id); button.setId(buttonId); button.setIconResource(option.icon); diff --git a/catalog/java/io/material/catalog/tableofcontents/GridDividerDecoration.java b/catalog/java/io/material/catalog/tableofcontents/GridDividerDecoration.java index d21042b168f..a50dcfaf992 100644 --- a/catalog/java/io/material/catalog/tableofcontents/GridDividerDecoration.java +++ b/catalog/java/io/material/catalog/tableofcontents/GridDividerDecoration.java @@ -26,7 +26,6 @@ import android.view.View; import androidx.annotation.ColorInt; import androidx.annotation.Px; -import androidx.core.view.ViewCompat; /** * An {@link ItemDecoration} that adds Material-style dividers between grid items. This is meant to @@ -72,8 +71,7 @@ private void drawHorizontal(Canvas canvas, RecyclerView parent) { private void drawVertical(Canvas canvas, RecyclerView parent) { final int childCount = parent.getChildCount(); - final boolean isRTL = - ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRTL = parent.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); diff --git a/lib/java/com/google/android/material/appbar/AppBarLayout.java b/lib/java/com/google/android/material/appbar/AppBarLayout.java index 617db693118..ae3db260dd2 100644 --- a/lib/java/com/google/android/material/appbar/AppBarLayout.java +++ b/lib/java/com/google/android/material/appbar/AppBarLayout.java @@ -254,7 +254,7 @@ public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int ThemeEnforcement.obtainStyledAttributes( context, attrs, R.styleable.AppBarLayout, defStyleAttr, DEF_STYLE_RES); - ViewCompat.setBackground(this, a.getDrawable(R.styleable.AppBarLayout_android_background)); + setBackground(a.getDrawable(R.styleable.AppBarLayout_android_background)); ColorStateList liftOnScrollColor = MaterialResources.getColorStateList(context, a, R.styleable.AppBarLayout_liftOnScrollColor); @@ -354,7 +354,8 @@ private void initializeLiftOnScrollWithColor( } } }; - ViewCompat.setBackground(this, background); + + setBackground(background); } private void initializeLiftOnScrollWithElevation( @@ -370,7 +371,8 @@ private void initializeLiftOnScrollWithElevation( liftOnScrollListener.onUpdate(elevation, background.getResolvedTintColor()); } }; - ViewCompat.setBackground(this, background); + + setBackground(background); } /** @@ -452,12 +454,12 @@ public void setStatusBarForeground(@Nullable Drawable drawable) { if (statusBarForeground.isStateful()) { statusBarForeground.setState(getDrawableState()); } - DrawableCompat.setLayoutDirection(statusBarForeground, ViewCompat.getLayoutDirection(this)); + DrawableCompat.setLayoutDirection(statusBarForeground, getLayoutDirection()); statusBarForeground.setVisible(getVisibility() == VISIBLE, false); statusBarForeground.setCallback(this); } updateWillNotDraw(); - ViewCompat.postInvalidateOnAnimation(this); + postInvalidateOnAnimation(); } } @@ -558,9 +560,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // If we're set to handle system windows but our first child is not, we need to add some // height to ourselves to pad the first child down below the status bar final int heightMode = MeasureSpec.getMode(heightMeasureSpec); - if (heightMode != MeasureSpec.EXACTLY - && ViewCompat.getFitsSystemWindows(this) - && shouldOffsetFirstChild()) { + if (heightMode != MeasureSpec.EXACTLY && getFitsSystemWindows() && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: @@ -586,7 +586,7 @@ && shouldOffsetFirstChild()) { protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); - if (ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { + if (getFitsSystemWindows() && shouldOffsetFirstChild()) { // If we need to offset the first child, we need to offset all of them to make space final int topInset = getTopInset(); for (int z = getChildCount() - 1; z >= 0; z--) { @@ -706,7 +706,7 @@ public void setElevation(float elevation) { * @attr ref com.google.android.material.R.styleable#AppBarLayout_expanded */ public void setExpanded(boolean expanded) { - setExpanded(expanded, ViewCompat.isLaidOut(this)); + setExpanded(expanded, isLaidOut()); } /** @@ -793,7 +793,7 @@ public final int getTotalScrollRange() { // We're set to scroll so add the child's height range += childHeight + lp.topMargin + lp.bottomMargin; - if (i == 0 && ViewCompat.getFitsSystemWindows(child)) { + if (i == 0 && child.getFitsSystemWindows()) { // If this is the first child and it wants to handle system windows, we need to make // sure we don't scroll it past the inset range -= getTopInset(); @@ -802,7 +802,7 @@ public final int getTotalScrollRange() { // For a collapsing scroll, we to take the collapsed height into account. // We also break straight away since later views can't scroll beneath // us - range -= ViewCompat.getMinimumHeight(child); + range -= child.getMinimumHeight(); break; } } else { @@ -847,15 +847,15 @@ int getDownNestedPreScrollRange() { // The view has the quick return flag combination... if ((flags & LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED) != 0) { // If they're set to enter collapsed, use the minimum height - childRange += ViewCompat.getMinimumHeight(child); + childRange += child.getMinimumHeight(); } else if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) != 0) { // Only enter by the amount of the collapsed height - childRange += childHeight - ViewCompat.getMinimumHeight(child); + childRange += childHeight - child.getMinimumHeight(); } else { // Else use the full height childRange += childHeight; } - if (i == 0 && ViewCompat.getFitsSystemWindows(child)) { + if (i == 0 && child.getFitsSystemWindows()) { // If this is the first child and it wants to handle system windows, we need to make // sure we don't scroll past the inset childRange = Math.min(childRange, childHeight - getTopInset()); @@ -898,7 +898,7 @@ int getDownNestedScrollRange() { // For a collapsing exit scroll, we to take the collapsed height into account. // We also break the range straight away since later views can't scroll // beneath us - range -= ViewCompat.getMinimumHeight(child); + range -= child.getMinimumHeight(); break; } } else { @@ -914,7 +914,7 @@ void onOffsetChanged(int offset) { currentOffset = offset; if (!willNotDraw()) { - ViewCompat.postInvalidateOnAnimation(this); + postInvalidateOnAnimation(); } // Iterate backwards through the list so that most recently added listeners @@ -931,7 +931,7 @@ void onOffsetChanged(int offset) { public final int getMinimumHeightForVisibleOverlappingContent() { final int topInset = getTopInset(); - final int minHeight = ViewCompat.getMinimumHeight(this); + final int minHeight = getMinimumHeight(); if (minHeight != 0) { // If this layout has a min height, use it (doubled) return (minHeight * 2) + topInset; @@ -940,7 +940,7 @@ public final int getMinimumHeightForVisibleOverlappingContent() { // Otherwise, we'll use twice the min height of our last child final int childCount = getChildCount(); final int lastChildMinHeight = - childCount >= 1 ? ViewCompat.getMinimumHeight(getChildAt(childCount - 1)) : 0; + childCount >= 1 ? getChildAt(childCount - 1).getMinimumHeight() : 0; if (lastChildMinHeight != 0) { return (lastChildMinHeight * 2) + topInset; } @@ -1190,7 +1190,7 @@ final int getTopInset() { private boolean shouldOffsetFirstChild() { if (getChildCount() > 0) { final View firstChild = getChildAt(0); - return firstChild.getVisibility() != GONE && !ViewCompat.getFitsSystemWindows(firstChild); + return firstChild.getVisibility() != GONE && !firstChild.getFitsSystemWindows(); } return false; } @@ -1198,7 +1198,7 @@ private boolean shouldOffsetFirstChild() { WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; - if (ViewCompat.getFitsSystemWindows(this)) { + if (getFitsSystemWindows()) { // If we're set to fit system windows, keep the insets newInsets = insets; } @@ -1732,19 +1732,19 @@ private void snapToChildIfNeeded(CoordinatorLayout coordinatorLayout, @NonNull T // If the child is set to fit system windows, its top will include the inset area, we need // to minus the inset from snapTop to make the calculation consistent. if (offsetChildIndex == 0 - && ViewCompat.getFitsSystemWindows(abl) - && ViewCompat.getFitsSystemWindows(offsetChild)) { + && abl.getFitsSystemWindows() + && offsetChild.getFitsSystemWindows()) { snapTop -= abl.getTopInset(); } if (checkFlag(flags, LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED)) { // If the view is set only exit until it is collapsed, we'll abide by that - snapBottom += ViewCompat.getMinimumHeight(offsetChild); + snapBottom += offsetChild.getMinimumHeight(); } else if (checkFlag( flags, LayoutParams.FLAG_QUICK_RETURN | LayoutParams.SCROLL_FLAG_ENTER_ALWAYS)) { // If it's set to always enter collapsed, it actually has two states. We // select the state and then snap within the state - final int seam = snapBottom + ViewCompat.getMinimumHeight(offsetChild); + final int seam = snapBottom + offsetChild.getMinimumHeight(); if (offset < seam) { snapTop = seam; } else { @@ -1826,7 +1826,7 @@ public boolean onLayoutChild( View child = abl.getChildAt(savedState.firstVisibleChildIndex); int offset = -child.getBottom(); if (savedState.firstVisibleChildAtMinimumHeight) { - offset += ViewCompat.getMinimumHeight(child) + abl.getTopInset(); + offset += child.getMinimumHeight() + abl.getTopInset(); } else { offset += Math.round(child.getHeight() * savedState.firstVisibleChildPercentageShown); } @@ -2125,11 +2125,11 @@ private int interpolateOffset(@NonNull T layout, final int offset) { if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) != 0) { // For a collapsing scroll, we to take the collapsed height // into account. - childScrollableHeight -= ViewCompat.getMinimumHeight(child); + childScrollableHeight -= child.getMinimumHeight(); } } - if (ViewCompat.getFitsSystemWindows(child)) { + if (child.getFitsSystemWindows()) { childScrollableHeight -= layout.getTopInset(); } @@ -2167,7 +2167,7 @@ private void updateAppBarLayoutDrawableState( final int flags = childLp.getScrollFlags(); if ((flags & LayoutParams.SCROLL_FLAG_SCROLL) != 0) { - final int minHeight = ViewCompat.getMinimumHeight(child); + final int minHeight = child.getMinimumHeight(); if (direction > 0 && (flags @@ -2291,7 +2291,7 @@ SavedState saveScrollState(@Nullable Parcelable superState, @NonNull T abl) { ss.fullyScrolled = !ss.fullyExpanded && -offset >= abl.getTotalScrollRange(); ss.firstVisibleChildIndex = i; ss.firstVisibleChildAtMinimumHeight = - visBottom == (ViewCompat.getMinimumHeight(child) + abl.getTopInset()); + visBottom == (child.getMinimumHeight() + abl.getTopInset()); ss.firstVisibleChildPercentageShown = visBottom / (float) child.getHeight(); return ss; } @@ -2584,10 +2584,10 @@ public void onOffsetChanged( } else { child.setAlpha(1f); } - ViewCompat.setClipBounds(child, ghostRect); + child.setClipBounds(ghostRect); } else { // Reset both the clip bounds and translationY of this view - ViewCompat.setClipBounds(child, null); + child.setClipBounds(null); child.setTranslationY(0); child.setAlpha(1f); } diff --git a/lib/java/com/google/android/material/appbar/CollapsingToolbarLayout.java b/lib/java/com/google/android/material/appbar/CollapsingToolbarLayout.java index 52660890481..3aaf8811a06 100644 --- a/lib/java/com/google/android/material/appbar/CollapsingToolbarLayout.java +++ b/lib/java/com/google/android/material/appbar/CollapsingToolbarLayout.java @@ -57,7 +57,6 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.math.MathUtils; import androidx.core.util.ObjectsCompat; -import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.android.material.animation.AnimationUtils; @@ -226,11 +225,11 @@ public CollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet collapsingTextHelper.setExpandedTextGravity( a.getInt( R.styleable.CollapsingToolbarLayout_expandedTitleGravity, - GravityCompat.START | Gravity.BOTTOM)); + Gravity.START | Gravity.BOTTOM)); collapsingTextHelper.setCollapsedTextGravity( a.getInt( R.styleable.CollapsingToolbarLayout_collapsedTitleGravity, - GravityCompat.START | Gravity.CENTER_VERTICAL)); + Gravity.START | Gravity.CENTER_VERTICAL)); expandedMarginStart = expandedMarginTop = @@ -363,7 +362,7 @@ protected void onAttachedToWindow() { disableLiftOnScrollIfNeeded(appBarLayout); // Copy over from the ABL whether we should fit system windows - ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows(appBarLayout)); + setFitsSystemWindows(appBarLayout.getFitsSystemWindows()); if (onOffsetChangedListener == null) { onOffsetChangedListener = new OffsetUpdateListener(); @@ -389,7 +388,7 @@ protected void onDetachedFromWindow() { WindowInsetsCompat onWindowInsetChanged(@NonNull final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; - if (ViewCompat.getFitsSystemWindows(this)) { + if (getFitsSystemWindows()) { // If we're set to fit system windows, keep the insets newInsets = insets; } @@ -629,7 +628,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto final int insetTop = lastInsets.getSystemWindowInsetTop(); for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); - if (!ViewCompat.getFitsSystemWindows(child)) { + if (!child.getFitsSystemWindows()) { if (child.getTop() < insetTop) { // If the child isn't set to fit system windows but is drawing within // the inset offset it down @@ -662,12 +661,10 @@ private void updateTextBounds( if (collapsingTitleEnabled && dummyView != null) { // We only draw the title if the dummy view is being displayed (Toolbar removes // views if there is no space) - drawCollapsingTitle = - ViewCompat.isAttachedToWindow(dummyView) && dummyView.getVisibility() == VISIBLE; + drawCollapsingTitle = dummyView.isAttachedToWindow() && dummyView.getVisibility() == VISIBLE; if (drawCollapsingTitle || forceRecalculate) { - final boolean isRtl = - ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRtl = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; // Update the collapsed bounds updateCollapsedBounds(isRtl); @@ -898,7 +895,7 @@ private TruncateAt convertEllipsizeToTruncateAt(int ellipsize) { * @see #getContentScrim() */ public void setScrimsShown(boolean shown) { - setScrimsShown(shown, ViewCompat.isLaidOut(this) && !isInEditMode()); + setScrimsShown(shown, isLaidOut() && !isInEditMode()); } /** @@ -949,10 +946,10 @@ void setScrimAlpha(int alpha) { if (alpha != scrimAlpha) { final Drawable contentScrim = this.contentScrim; if (contentScrim != null && toolbar != null) { - ViewCompat.postInvalidateOnAnimation(toolbar); + toolbar.postInvalidateOnAnimation(); } scrimAlpha = alpha; - ViewCompat.postInvalidateOnAnimation(CollapsingToolbarLayout.this); + postInvalidateOnAnimation(); } } @@ -979,7 +976,7 @@ public void setContentScrim(@Nullable Drawable drawable) { contentScrim.setCallback(this); contentScrim.setAlpha(scrimAlpha); } - ViewCompat.postInvalidateOnAnimation(this); + postInvalidateOnAnimation(); } } @@ -1036,12 +1033,12 @@ public void setStatusBarScrim(@Nullable Drawable drawable) { if (statusBarScrim.isStateful()) { statusBarScrim.setState(getDrawableState()); } - DrawableCompat.setLayoutDirection(statusBarScrim, ViewCompat.getLayoutDirection(this)); + DrawableCompat.setLayoutDirection(statusBarScrim, getLayoutDirection()); statusBarScrim.setVisible(getVisibility() == VISIBLE, false); statusBarScrim.setCallback(this); statusBarScrim.setAlpha(scrimAlpha); } - ViewCompat.postInvalidateOnAnimation(this); + postInvalidateOnAnimation(); } } @@ -1564,7 +1561,7 @@ public int getScrimVisibleHeightTrigger() { // Otherwise we'll use the default computed value final int insetTop = lastInsets != null ? lastInsets.getSystemWindowInsetTop() : 0; - final int minHeight = ViewCompat.getMinimumHeight(this); + final int minHeight = getMinimumHeight(); if (minHeight > 0) { // If we have a minHeight set, lets use 2 * minHeight (capped at our height) return Math.min((minHeight * 2) + insetTop, getHeight()); @@ -1794,13 +1791,12 @@ public void onOffsetChanged(AppBarLayout layout, int verticalOffset) { updateScrimVisibility(); if (statusBarScrim != null && insetTop > 0) { - ViewCompat.postInvalidateOnAnimation(CollapsingToolbarLayout.this); + postInvalidateOnAnimation(); } // Update the collapsing text's fraction int height = getHeight(); - final int expandRange = - height - ViewCompat.getMinimumHeight(CollapsingToolbarLayout.this) - insetTop; + final int expandRange = height - getMinimumHeight() - insetTop; final int scrimRange = height - getScrimVisibleHeightTrigger(); collapsingTextHelper.setFadeModeStartFraction( Math.min(1, (float) scrimRange / (float) expandRange)); diff --git a/lib/java/com/google/android/material/appbar/HeaderBehavior.java b/lib/java/com/google/android/material/appbar/HeaderBehavior.java index f922c129bcc..25e9c394882 100644 --- a/lib/java/com/google/android/material/appbar/HeaderBehavior.java +++ b/lib/java/com/google/android/material/appbar/HeaderBehavior.java @@ -28,7 +28,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior; import androidx.core.math.MathUtils; -import androidx.core.view.ViewCompat; /** * The {@link Behavior} for a view that sits vertically above scrolling a view. See {@link @@ -220,7 +219,7 @@ final boolean fling( if (scroller.computeScrollOffset()) { flingRunnable = new FlingRunnable(coordinatorLayout, layout); - ViewCompat.postOnAnimation(layout, flingRunnable); + layout.postOnAnimation(flingRunnable); return true; } else { onFlingFinished(coordinatorLayout, layout); @@ -271,7 +270,7 @@ public void run() { if (scroller.computeScrollOffset()) { setHeaderTopBottomOffset(parent, layout, scroller.getCurrY()); // Post ourselves so that we run on the next animation - ViewCompat.postOnAnimation(layout, this); + layout.postOnAnimation(this); } else { onFlingFinished(parent, layout); } diff --git a/lib/java/com/google/android/material/appbar/HeaderScrollingViewBehavior.java b/lib/java/com/google/android/material/appbar/HeaderScrollingViewBehavior.java index b561622e29f..424b206a2e9 100644 --- a/lib/java/com/google/android/material/appbar/HeaderScrollingViewBehavior.java +++ b/lib/java/com/google/android/material/appbar/HeaderScrollingViewBehavior.java @@ -27,8 +27,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior; import androidx.core.math.MathUtils; -import androidx.core.view.GravityCompat; -import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import java.util.List; @@ -69,7 +67,7 @@ public boolean onMeasureChild( if (header != null) { int availableHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec); if (availableHeight > 0) { - if (ViewCompat.getFitsSystemWindows(header)) { + if (header.getFitsSystemWindows()) { final WindowInsetsCompat parentInsets = parent.getLastWindowInsets(); if (parentInsets != null) { availableHeight += parentInsets.getSystemWindowInsetTop() @@ -125,9 +123,7 @@ protected void layoutChild( parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin); final WindowInsetsCompat parentInsets = parent.getLastWindowInsets(); - if (parentInsets != null - && ViewCompat.getFitsSystemWindows(parent) - && !ViewCompat.getFitsSystemWindows(child)) { + if (parentInsets != null && parent.getFitsSystemWindows() && !child.getFitsSystemWindows()) { // If we're set to handle insets but this child isn't, then it has been measured as // if there are no insets. We need to lay it out to match horizontally. // Top and bottom and already handled in the logic above @@ -136,7 +132,7 @@ protected void layoutChild( } final Rect out = tempRect2; - GravityCompat.apply( + Gravity.apply( resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), @@ -170,7 +166,7 @@ final int getOverlapPixelsForOffset(final View header) { } private static int resolveGravity(int gravity) { - return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity; + return gravity == Gravity.NO_GRAVITY ? Gravity.START | Gravity.TOP : gravity; } @Nullable diff --git a/lib/java/com/google/android/material/appbar/MaterialToolbar.java b/lib/java/com/google/android/material/appbar/MaterialToolbar.java index d18afe6df84..df3629bed3c 100644 --- a/lib/java/com/google/android/material/appbar/MaterialToolbar.java +++ b/lib/java/com/google/android/material/appbar/MaterialToolbar.java @@ -387,7 +387,7 @@ private void initBackground(Context context) { materialShapeDrawable.setFillColor(backgroundColorStateList); materialShapeDrawable.initializeElevationOverlay(context); materialShapeDrawable.setElevation(ViewCompat.getElevation(this)); - ViewCompat.setBackground(this, materialShapeDrawable); + setBackground(materialShapeDrawable); } } diff --git a/lib/java/com/google/android/material/behavior/SwipeDismissBehavior.java b/lib/java/com/google/android/material/behavior/SwipeDismissBehavior.java index d20348a2c8b..9c23c2e41fd 100644 --- a/lib/java/com/google/android/material/behavior/SwipeDismissBehavior.java +++ b/lib/java/com/google/android/material/behavior/SwipeDismissBehavior.java @@ -177,9 +177,8 @@ public void setSensitivity(float sensitivity) { public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull V child, int layoutDirection) { boolean handled = super.onLayoutChild(parent, child, layoutDirection); - if (ViewCompat.getImportantForAccessibility(child) - == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { - ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + if (child.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); updateAccessibilityActions(child); } return handled; @@ -294,7 +293,7 @@ public void onViewReleased(@NonNull View child, float xVelocity, float yVelocity } if (viewDragHelper.settleCapturedViewAt(targetLeft, child.getTop())) { - ViewCompat.postOnAnimation(child, new SettleRunnable(child, dismiss)); + child.postOnAnimation(new SettleRunnable(child, dismiss)); } else if (dismiss && listener != null) { listener.onDismiss(child); } @@ -302,8 +301,7 @@ public void onViewReleased(@NonNull View child, float xVelocity, float yVelocity private boolean shouldDismiss(@NonNull View child, float xVelocity) { if (xVelocity != 0f) { - final boolean isRtl = - ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRtl = child.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; if (swipeDirection == SWIPE_DIRECTION_ANY) { // We don't care about the direction so return true @@ -333,8 +331,7 @@ public int getViewHorizontalDragRange(@NonNull View child) { @Override public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) { - final boolean isRtl = - ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRtl = child.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int min; int max; @@ -408,7 +405,7 @@ private class SettleRunnable implements Runnable { @Override public void run() { if (viewDragHelper != null && viewDragHelper.continueSettling(true)) { - ViewCompat.postOnAnimation(view, this); + view.postOnAnimation(this); } else { if (dismiss && listener != null) { listener.onDismiss(view); @@ -428,8 +425,7 @@ private void updateAccessibilityActions(View child) { @Override public boolean perform(@NonNull View view, @Nullable CommandArguments arguments) { if (canSwipeDismissView(view)) { - final boolean isRtl = - ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRtl = view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; boolean dismissToLeft = (swipeDirection == SWIPE_DIRECTION_START_TO_END && isRtl) || (swipeDirection == SWIPE_DIRECTION_END_TO_START && !isRtl); diff --git a/lib/java/com/google/android/material/bottomappbar/BottomAppBar.java b/lib/java/com/google/android/material/bottomappbar/BottomAppBar.java index 5f0c750703b..3f695d70aaf 100644 --- a/lib/java/com/google/android/material/bottomappbar/BottomAppBar.java +++ b/lib/java/com/google/android/material/bottomappbar/BottomAppBar.java @@ -375,7 +375,7 @@ public BottomAppBar(@NonNull Context context, @Nullable AttributeSet attrs, int materialShapeDrawable.initializeElevationOverlay(context); setElevation(elevation); DrawableCompat.setTintList(materialShapeDrawable, backgroundTint); - ViewCompat.setBackground(this, materialShapeDrawable); + setBackground(materialShapeDrawable); ViewUtils.doOnApplyWindowInsets( this, @@ -820,7 +820,7 @@ void setFabCornerSize(@Dimension float radius) { } private void maybeAnimateModeChange(@FabAlignmentMode int targetMode) { - if (fabAlignmentMode == targetMode || !ViewCompat.isLaidOut(this)) { + if (fabAlignmentMode == targetMode || !isLaidOut()) { return; } @@ -944,7 +944,7 @@ private Drawable maybeTintNavigationIcon(@Nullable Drawable navigationIcon) { } private void maybeAnimateMenuView(@FabAlignmentMode int targetMode, boolean newFabAttached) { - if (!ViewCompat.isLaidOut(this)) { + if (!isLaidOut()) { menuAnimatingWithFabAlignmentMode = false; // If this method is called before the BottomAppBar is laid out and able to animate, make sure // the desired menu is still set even if the animation is skipped. @@ -1201,7 +1201,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { // If the BAB layout has changed, we should alert the fab so that it can // adjust its margins accordingly. View dependentView = findDependentView(); - if (dependentView != null && ViewCompat.isLaidOut(dependentView)) { + if (dependentView != null && dependentView.isLaidOut()) { dependentView.post(() -> dependentView.requestLayout()); } } @@ -1413,7 +1413,7 @@ public boolean onLayoutChild( viewRef = new WeakReference<>(child); View dependentView = child.findDependentView(); - if (dependentView != null && !ViewCompat.isLaidOut(dependentView)) { + if (dependentView != null && !dependentView.isLaidOut()) { // Set the initial position of the FloatingActionButton with the BottomAppBar vertical // offset. updateFabAnchorGravity(child, dependentView); diff --git a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java index 36f50aa3969..1c3c28e2612 100644 --- a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java +++ b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java @@ -29,7 +29,6 @@ import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.RestrictTo; -import androidx.core.view.ViewCompat; import com.google.android.material.navigation.NavigationBarItemView; import com.google.android.material.navigation.NavigationBarMenuView; import java.util.ArrayList; @@ -158,7 +157,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto if (child.getVisibility() == GONE) { continue; } - if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { child.layout(width - used - child.getMeasuredWidth(), 0, width - used, height); } else { child.layout(used, 0, child.getMeasuredWidth() + used, height); diff --git a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java index e698b4d9a3b..61ba2e3c9cd 100644 --- a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java +++ b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java @@ -34,7 +34,6 @@ import androidx.annotation.RestrictTo; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; -import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.android.material.behavior.HideBottomViewOnScrollBehavior; import com.google.android.material.internal.ThemeEnforcement; @@ -154,7 +153,7 @@ public WindowInsetsCompat onApplyWindowInsets( // to dodge the system navigation bar initialPadding.bottom += insets.getSystemWindowInsetBottom(); - boolean isRtl = ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + boolean isRtl = view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int systemWindowInsetLeft = insets.getSystemWindowInsetLeft(); int systemWindowInsetRight = insets.getSystemWindowInsetRight(); initialPadding.start += isRtl ? systemWindowInsetRight : systemWindowInsetLeft; diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java index 9459c6d1217..e9dab872171 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -544,7 +544,7 @@ private int getChildMeasureSpec( @Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull final V child, int layoutDirection) { - if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { + if (parent.getFitsSystemWindows() && !child.getFitsSystemWindows()) { child.setFitsSystemWindows(true); } @@ -559,7 +559,7 @@ public boolean onLayoutChild( // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (materialShapeDrawable != null) { - ViewCompat.setBackground(child, materialShapeDrawable); + child.setBackground(materialShapeDrawable); // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); @@ -567,9 +567,8 @@ public boolean onLayoutChild( ViewCompat.setBackgroundTintList(child, backgroundTint); } updateAccessibilityActions(); - if (ViewCompat.getImportantForAccessibility(child) - == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { - ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + if (child.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } } if (viewDragHelper == null) { @@ -1381,7 +1380,7 @@ private void runAfterLayout(V child, Runnable runnable) { private boolean isLayouting(V child) { ViewParent parent = child.getParent(); - return parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child); + return parent != null && parent.isLayoutRequested() && child.isAttachedToWindow(); } /** @@ -2181,7 +2180,7 @@ void continueSettlingToState(@State int targetState) { } this.targetState = targetState; if (!isContinueSettlingRunnablePosted) { - ViewCompat.postOnAnimation(viewRef.get(), continueSettlingRunnable); + viewRef.get().postOnAnimation(continueSettlingRunnable); isContinueSettlingRunnablePosted = true; } } @@ -2328,15 +2327,14 @@ private void updateImportantForAccessibility(boolean expanded) { // Saves the important for accessibility value of the child view. importantForAccessibilityMap.put(child, child.getImportantForAccessibility()); if (updateImportantForAccessibilityOnSiblings) { - ViewCompat.setImportantForAccessibility( - child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); } } else { if (updateImportantForAccessibilityOnSiblings && importantForAccessibilityMap != null && importantForAccessibilityMap.containsKey(child)) { // Restores the original important for accessibility value of the child view. - ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child)); + child.setImportantForAccessibility(importantForAccessibilityMap.get(child)); } } } diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java index 32757c50f31..a33f23ed16c 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java @@ -165,11 +165,9 @@ private void onBottomSheetStateChanged(@BottomSheetBehavior.State int state) { private void updateInteractableState() { interactable = accessibilityServiceEnabled && bottomSheetBehavior != null; - ViewCompat.setImportantForAccessibility( - this, - bottomSheetBehavior != null - ? ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES - : ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + setImportantForAccessibility(bottomSheetBehavior != null + ? View.IMPORTANT_FOR_ACCESSIBILITY_YES + : View.IMPORTANT_FOR_ACCESSIBILITY_NO); setClickable(interactable); } diff --git a/lib/java/com/google/android/material/button/MaterialButton.java b/lib/java/com/google/android/material/button/MaterialButton.java index 00470e5d24c..f4aef4f992c 100644 --- a/lib/java/com/google/android/material/button/MaterialButton.java +++ b/lib/java/com/google/android/material/button/MaterialButton.java @@ -43,6 +43,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; +import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.Button; @@ -60,7 +61,6 @@ import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import androidx.core.widget.TextViewCompat; import androidx.customview.view.AbsSavedState; import com.google.android.material.internal.ThemeEnforcement; @@ -581,10 +581,10 @@ private void updateIconPosition(int buttonWidth, int buttonHeight) { int localIconSize = iconSize == 0 ? icon.getIntrinsicWidth() : iconSize; int availableWidth = buttonWidth - getTextLayoutWidth() - - ViewCompat.getPaddingEnd(this) + - getPaddingEnd() - localIconSize - iconPadding - - ViewCompat.getPaddingStart(this); + - getPaddingStart(); int newIconLeft = textAlignment == Alignment.ALIGN_CENTER ? availableWidth / 2 : availableWidth; @@ -653,7 +653,7 @@ private int getTextHeight() { } private boolean isLayoutRTL() { - return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; + return getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } /** diff --git a/lib/java/com/google/android/material/button/MaterialButtonHelper.java b/lib/java/com/google/android/material/button/MaterialButtonHelper.java index 0fea6158aeb..a2c5801a988 100644 --- a/lib/java/com/google/android/material/button/MaterialButtonHelper.java +++ b/lib/java/com/google/android/material/button/MaterialButtonHelper.java @@ -37,7 +37,6 @@ import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.color.MaterialColors; import com.google.android.material.internal.ViewUtils; import com.google.android.material.resources.MaterialResources; @@ -122,9 +121,9 @@ void loadFromAttributes(@NonNull TypedArray attributes) { attributes.getBoolean(R.styleable.MaterialButton_toggleCheckedStateOnClick, true); // Store padding before setting background, since background overwrites padding values - int paddingStart = ViewCompat.getPaddingStart(materialButton); + int paddingStart = materialButton.getPaddingStart(); int paddingTop = materialButton.getPaddingTop(); - int paddingEnd = ViewCompat.getPaddingEnd(materialButton); + int paddingEnd = materialButton.getPaddingEnd(); int paddingBottom = materialButton.getPaddingBottom(); // Update materialButton's background without triggering setBackgroundOverwritten() @@ -134,8 +133,7 @@ void loadFromAttributes(@NonNull TypedArray attributes) { updateBackground(); } // Set the stored padding values - ViewCompat.setPaddingRelative( - materialButton, + materialButton.setPaddingRelative( paddingStart + insetLeft, paddingTop + insetTop, paddingEnd + insetRight, @@ -384,14 +382,13 @@ private void updateButtonShape(@NonNull ShapeAppearanceModel shapeAppearanceMode // changing an existing drawable shape. This is a fallback. if (IS_LOLLIPOP && !backgroundOverwritten) { // Store padding before setting background, since background overwrites padding values - int paddingStart = ViewCompat.getPaddingStart(materialButton); + int paddingStart = materialButton.getPaddingStart(); int paddingTop = materialButton.getPaddingTop(); - int paddingEnd = ViewCompat.getPaddingEnd(materialButton); + int paddingEnd = materialButton.getPaddingEnd(); int paddingBottom = materialButton.getPaddingBottom(); updateBackground(); // Set the stored padding values - ViewCompat.setPaddingRelative( - materialButton, paddingStart, paddingTop, paddingEnd, paddingBottom); + materialButton.setPaddingRelative(paddingStart, paddingTop, paddingEnd, paddingBottom); } else { if (getMaterialShapeDrawable() != null) { getMaterialShapeDrawable().setShapeAppearanceModel(shapeAppearanceModel); @@ -443,9 +440,9 @@ public void setInsetTop(@Dimension int newInsetTop) { private void setVerticalInsets(@Dimension int newInsetTop, @Dimension int newInsetBottom) { // Store padding before setting background, since background overwrites padding values - int paddingStart = ViewCompat.getPaddingStart(materialButton); + int paddingStart = materialButton.getPaddingStart(); int paddingTop = materialButton.getPaddingTop(); - int paddingEnd = ViewCompat.getPaddingEnd(materialButton); + int paddingEnd = materialButton.getPaddingEnd(); int paddingBottom = materialButton.getPaddingBottom(); int oldInsetTop = insetTop; int oldInsetBottom = insetBottom; @@ -455,8 +452,7 @@ private void setVerticalInsets(@Dimension int newInsetTop, @Dimension int newIns updateBackground(); } // Set the stored padding values - ViewCompat.setPaddingRelative( - materialButton, + materialButton.setPaddingRelative( paddingStart, paddingTop + newInsetTop - oldInsetTop, paddingEnd, diff --git a/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java b/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java index 6c5aeb9a1eb..4a73c47d500 100644 --- a/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java +++ b/lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java @@ -40,7 +40,6 @@ import androidx.annotation.Px; import androidx.annotation.VisibleForTesting; import androidx.core.view.AccessibilityDelegateCompat; -import androidx.core.view.MarginLayoutParamsCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; @@ -601,8 +600,8 @@ private void resetChildMargins(int childIndex) { return; } - MarginLayoutParamsCompat.setMarginEnd(params, 0); - MarginLayoutParamsCompat.setMarginStart(params, 0); + params.setMarginEnd(0); + params.setMarginStart(0); params.leftMargin = 0; params.rightMargin = 0; } diff --git a/lib/java/com/google/android/material/card/MaterialCardViewHelper.java b/lib/java/com/google/android/material/card/MaterialCardViewHelper.java index 6551583bd1e..ce501137643 100644 --- a/lib/java/com/google/android/material/card/MaterialCardViewHelper.java +++ b/lib/java/com/google/android/material/card/MaterialCardViewHelper.java @@ -49,7 +49,6 @@ import androidx.annotation.StyleRes; import androidx.cardview.widget.CardView; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.card.MaterialCardView.CheckedIconGravity; import com.google.android.material.color.MaterialColors; @@ -501,7 +500,7 @@ void recalculateCheckedIconPosition(int measuredWidth, int measuredHeight) { ? measuredHeight - checkedIconMargin - checkedIconSize - verticalPaddingAdjustment : checkedIconMargin; - if (ViewCompat.getLayoutDirection(materialCardView) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (materialCardView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { // swap left and right int tmp = right; right = left; diff --git a/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java b/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java index b3568fd6ad8..228326189eb 100644 --- a/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java +++ b/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java @@ -54,7 +54,6 @@ import androidx.core.graphics.ColorUtils; import androidx.core.math.MathUtils; import androidx.core.util.Preconditions; -import androidx.core.view.ViewCompat; import com.google.android.material.carousel.CarouselStrategy.StrategyType; import com.google.android.material.carousel.KeylineState.Keyline; import java.lang.annotation.Retention; @@ -1087,7 +1086,7 @@ private int getContainerSize() { } boolean isLayoutRtl() { - return isHorizontal() && getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL; + return isHorizontal() && getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } /** Moves {@code value} towards the start of the container by {@code amount}. */ diff --git a/lib/java/com/google/android/material/chip/Chip.java b/lib/java/com/google/android/material/chip/Chip.java index d9dd5fbf0e7..dba075934e9 100644 --- a/lib/java/com/google/android/material/chip/Chip.java +++ b/lib/java/com/google/android/material/chip/Chip.java @@ -256,7 +256,7 @@ public Chip(Context context, AttributeSet attrs, int defStyleAttr) { if (shouldEnsureMinTouchTargetSize()) { setMinHeight(minTouchTargetSize); } - lastLayoutDirection = ViewCompat.getLayoutDirection(this); + lastLayoutDirection = getLayoutDirection(); super.setOnCheckedChangeListener( (buttonView, isChecked) -> { @@ -367,8 +367,7 @@ private void updatePaddingInternal() { paddingEnd += padding.right; } - ViewCompat.setPaddingRelative( - this, paddingStart, getPaddingTop(), paddingEnd, getPaddingBottom()); + setPaddingRelative(paddingStart, getPaddingTop(), paddingEnd, getPaddingBottom()); } @Override @@ -456,7 +455,7 @@ private void updateBackgroundDrawable() { updateFrameworkRippleBackground(); } else { chipDrawable.setUseCompatRipple(true); - ViewCompat.setBackground(this, getBackgroundDrawable()); + setBackground(getBackgroundDrawable()); updatePaddingInternal(); ensureChipDrawableHasCallback(); } @@ -487,7 +486,7 @@ private void updateFrameworkRippleBackground() { null); chipDrawable.setUseCompatRipple(false); //noinspection NewApi - ViewCompat.setBackground(this, ripple); + setBackground(ripple); updatePaddingInternal(); } diff --git a/lib/java/com/google/android/material/chip/ChipDrawable.java b/lib/java/com/google/android/material/chip/ChipDrawable.java index e925f4a08a5..0f33ccbabc6 100644 --- a/lib/java/com/google/android/material/chip/ChipDrawable.java +++ b/lib/java/com/google/android/material/chip/ChipDrawable.java @@ -67,7 +67,6 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.TintAwareDrawable; import androidx.core.text.BidiFormatter; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.MotionSpec; import com.google.android.material.canvas.CanvasCompat; import com.google.android.material.color.MaterialColors; @@ -831,7 +830,7 @@ private void calculateChipIconBounds(@NonNull Rect bounds, @NonNull RectF outBou float offsetFromStart = chipStartPadding + iconStartPadding; float chipWidth = getCurrentChipIconWidth(); - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { outBounds.left = bounds.left + offsetFromStart; outBounds.right = outBounds.left + chipWidth; } else { @@ -854,7 +853,7 @@ Align calculateTextOriginAndAlignment(@NonNull Rect bounds, @NonNull PointF poin if (text != null) { float offsetFromStart = chipStartPadding + calculateChipIconWidth() + textStartPadding; - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { pointF.x = bounds.left + offsetFromStart; align = Align.LEFT; } else { @@ -896,7 +895,7 @@ private void calculateTextBounds(@NonNull Rect bounds, @NonNull RectF outBounds) float offsetFromStart = chipStartPadding + calculateChipIconWidth() + textStartPadding; float offsetFromEnd = chipEndPadding + calculateCloseIconWidth() + textEndPadding; - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { outBounds.left = bounds.left + offsetFromStart; outBounds.right = bounds.right - offsetFromEnd; } else { @@ -921,7 +920,7 @@ private void calculateCloseIconBounds(@NonNull Rect bounds, @NonNull RectF outBo if (showsCloseIcon()) { float offsetFromEnd = chipEndPadding + closeIconEndPadding; - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { outBounds.right = bounds.right - offsetFromEnd; outBounds.left = outBounds.right - closeIconSize; } else { @@ -945,7 +944,7 @@ private void calculateChipTouchBounds(@NonNull Rect bounds, @NonNull RectF outBo + closeIconStartPadding + textEndPadding; - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { outBounds.right = bounds.right - offsetFromEnd; } else { outBounds.left = bounds.left + offsetFromEnd; @@ -964,7 +963,7 @@ private void calculateCloseIconTouchBounds(@NonNull Rect bounds, @NonNull RectF + closeIconStartPadding + textEndPadding; - if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { + if (DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_LTR) { outBounds.right = bounds.right; outBounds.left = outBounds.right - offsetFromEnd; } else { diff --git a/lib/java/com/google/android/material/chip/ChipGroup.java b/lib/java/com/google/android/material/chip/ChipGroup.java index d3817689692..443498dab58 100644 --- a/lib/java/com/google/android/material/chip/ChipGroup.java +++ b/lib/java/com/google/android/material/chip/ChipGroup.java @@ -33,7 +33,6 @@ import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; import com.google.android.material.internal.CheckableGroup; @@ -171,7 +170,7 @@ public void onCheckedStateChanged(Set checkedIds) { }); super.setOnHierarchyChangeListener(passThroughListener); - ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } @Override @@ -524,7 +523,7 @@ public void onChildViewAdded(View parent, View child) { int id = child.getId(); // generates an id if it's missing if (id == View.NO_ID) { - id = ViewCompat.generateViewId(); + id = View.generateViewId(); child.setId(id); } checkableGroup.addCheckable((Chip) child); diff --git a/lib/java/com/google/android/material/datepicker/CalendarItemStyle.java b/lib/java/com/google/android/material/datepicker/CalendarItemStyle.java index 49112bb7058..57ecc9b867c 100644 --- a/lib/java/com/google/android/material/datepicker/CalendarItemStyle.java +++ b/lib/java/com/google/android/material/datepicker/CalendarItemStyle.java @@ -31,7 +31,6 @@ import androidx.annotation.Nullable; import androidx.annotation.StyleRes; import androidx.core.util.Preconditions; -import androidx.core.view.ViewCompat; import com.google.android.material.resources.MaterialResources; import com.google.android.material.shape.MaterialShapeDrawable; import com.google.android.material.shape.ShapeAppearanceModel; @@ -162,8 +161,7 @@ void styleItem( } else { d = backgroundDrawable; } - ViewCompat.setBackground( - item, new InsetDrawable(d, insets.left, insets.top, insets.right, insets.bottom)); + item.setBackground(new InsetDrawable(d, insets.left, insets.top, insets.right, insets.bottom)); } int getLeftInset() { diff --git a/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java b/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java index 63ff24f5a7d..bf3ecb24869 100644 --- a/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java +++ b/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java @@ -321,8 +321,7 @@ public final View onCreateView( } headerSelectionText = root.findViewById(R.id.mtrl_picker_header_selection_text); - ViewCompat.setAccessibilityLiveRegion( - headerSelectionText, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); + headerSelectionText.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); headerToggleButton = root.findViewById(R.id.mtrl_picker_header_toggle); headerTitleTextView = root.findViewById(R.id.mtrl_picker_title_text); initHeaderToggle(context); diff --git a/lib/java/com/google/android/material/dialog/MaterialAlertDialogBuilder.java b/lib/java/com/google/android/material/dialog/MaterialAlertDialogBuilder.java index 330cdcc6e7c..7d661890b23 100644 --- a/lib/java/com/google/android/material/dialog/MaterialAlertDialogBuilder.java +++ b/lib/java/com/google/android/material/dialog/MaterialAlertDialogBuilder.java @@ -183,7 +183,7 @@ public MaterialAlertDialogBuilder setBackground(@Nullable Drawable background) { @CanIgnoreReturnValue public MaterialAlertDialogBuilder setBackgroundInsetStart(@Px int backgroundInsetStart) { if (getContext().getResources().getConfiguration().getLayoutDirection() - == ViewCompat.LAYOUT_DIRECTION_RTL) { + == View.LAYOUT_DIRECTION_RTL) { backgroundInsets.right = backgroundInsetStart; } else { backgroundInsets.left = backgroundInsetStart; @@ -202,7 +202,7 @@ public MaterialAlertDialogBuilder setBackgroundInsetTop(@Px int backgroundInsetT @CanIgnoreReturnValue public MaterialAlertDialogBuilder setBackgroundInsetEnd(@Px int backgroundInsetEnd) { if (getContext().getResources().getConfiguration().getLayoutDirection() - == ViewCompat.LAYOUT_DIRECTION_RTL) { + == View.LAYOUT_DIRECTION_RTL) { backgroundInsets.left = backgroundInsetEnd; } else { backgroundInsets.right = backgroundInsetEnd; diff --git a/lib/java/com/google/android/material/dialog/MaterialDialogs.java b/lib/java/com/google/android/material/dialog/MaterialDialogs.java index 4943f142efb..f4585f7ffd4 100644 --- a/lib/java/com/google/android/material/dialog/MaterialDialogs.java +++ b/lib/java/com/google/android/material/dialog/MaterialDialogs.java @@ -22,12 +22,12 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; +import android.view.View; import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.annotation.RestrictTo.Scope; -import androidx.core.view.ViewCompat; import com.google.android.material.internal.ThemeEnforcement; /** @@ -90,13 +90,12 @@ public static Rect getDialogBackgroundInsets( attributes.recycle(); - int backgroundInsetLeft = backgroundInsetStart; - int backgroundInsetRight = backgroundInsetEnd; int layoutDirection = context.getResources().getConfiguration().getLayoutDirection(); - if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) { - backgroundInsetLeft = backgroundInsetEnd; - backgroundInsetRight = backgroundInsetStart; - } + int backgroundInsetLeft = + layoutDirection == View.LAYOUT_DIRECTION_RTL ? backgroundInsetEnd : backgroundInsetStart; + + int backgroundInsetRight = + layoutDirection == View.LAYOUT_DIRECTION_RTL ? backgroundInsetStart : backgroundInsetEnd; return new Rect( backgroundInsetLeft, backgroundInsetTop, backgroundInsetRight, backgroundInsetBottom); diff --git a/lib/java/com/google/android/material/divider/MaterialDivider.java b/lib/java/com/google/android/material/divider/MaterialDivider.java index 7c005313765..c8c328abef8 100644 --- a/lib/java/com/google/android/material/divider/MaterialDivider.java +++ b/lib/java/com/google/android/material/divider/MaterialDivider.java @@ -33,7 +33,6 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.core.content.ContextCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.internal.ThemeEnforcement; import com.google.android.material.resources.MaterialResources; import com.google.android.material.shape.MaterialShapeDrawable; @@ -110,7 +109,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); // Apply the insets. - boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; + boolean isRtl = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int left = isRtl ? insetEnd : insetStart; int right = isRtl ? getWidth() - insetStart : getWidth() - insetEnd; dividerDrawable.setBounds(left, 0, right, getBottom() - getTop()); diff --git a/lib/java/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton.java b/lib/java/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton.java index 1bdf64616c0..a2be682108c 100644 --- a/lib/java/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton.java +++ b/lib/java/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton.java @@ -230,8 +230,8 @@ public ExtendedFloatingActionButton( extendStrategyType = a.getInt( R.styleable.ExtendedFloatingActionButton_extendStrategy, EXTEND_STRATEGY_WRAP_CONTENT); - extendedPaddingStart = ViewCompat.getPaddingStart(this); - extendedPaddingEnd = ViewCompat.getPaddingEnd(this); + extendedPaddingStart = getPaddingStart(); + extendedPaddingEnd = getPaddingEnd(); AnimatorTracker changeSizeTracker = new AnimatorTracker(); extendStrategy = @@ -527,8 +527,8 @@ public void setPaddingRelative(int start, int top, int end, int bottom) { public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); if (isExtended && !isTransforming) { - extendedPaddingStart = ViewCompat.getPaddingStart(this); - extendedPaddingEnd = ViewCompat.getPaddingEnd(this); + extendedPaddingStart = getPaddingStart(); + extendedPaddingEnd = getPaddingEnd(); } } @@ -911,8 +911,7 @@ private boolean isOrWillBeHidden() { } private boolean shouldAnimateVisibilityChange() { - return (ViewCompat.isLaidOut(this) || (!isOrWillBeShown() && animateShowBeforeLayout)) - && !isInEditMode(); + return (isLaidOut() || (!isOrWillBeShown() && animateShowBeforeLayout)) && !isInEditMode(); } /** @@ -969,18 +968,17 @@ public Float get(@NonNull View object) { new Property(Float.class, "paddingStart") { @Override public void set(@NonNull View object, @NonNull Float value) { - ViewCompat.setPaddingRelative( - object, + object.setPaddingRelative( value.intValue(), object.getPaddingTop(), - ViewCompat.getPaddingEnd(object), + object.getPaddingEnd(), object.getPaddingBottom()); } @NonNull @Override public Float get(@NonNull View object) { - return (float) ViewCompat.getPaddingStart(object); + return (float) object.getPaddingStart(); } }; @@ -992,9 +990,8 @@ public Float get(@NonNull View object) { new Property(Float.class, "paddingEnd") { @Override public void set(@NonNull View object, @NonNull Float value) { - ViewCompat.setPaddingRelative( - object, - ViewCompat.getPaddingStart(object), + object.setPaddingRelative( + object.getPaddingStart(), object.getPaddingTop(), value.intValue(), object.getPaddingBottom()); @@ -1003,7 +1000,7 @@ public void set(@NonNull View object, @NonNull Float value) { @NonNull @Override public Float get(@NonNull View object) { - return (float) ViewCompat.getPaddingEnd(object); + return (float) object.getPaddingEnd(); } }; @@ -1014,7 +1011,7 @@ public Float get(@NonNull View object) { @VisibleForTesting int getCollapsedSize() { return collapsedSize < 0 - ? min(ViewCompat.getPaddingStart(this), ViewCompat.getPaddingEnd(this)) * 2 + getIconSize() + ? min(getPaddingStart(), getPaddingEnd()) * 2 + getIconSize() : collapsedSize; } @@ -1330,8 +1327,7 @@ public void performNow() { } layoutParams.width = size.getLayoutParams().width; layoutParams.height = size.getLayoutParams().height; - ViewCompat.setPaddingRelative( - ExtendedFloatingActionButton.this, + setPaddingRelative( size.getPaddingStart(), getPaddingTop(), size.getPaddingEnd(), @@ -1377,15 +1373,13 @@ public AnimatorSet createAnimator() { if (spec.hasPropertyValues("paddingStart")) { PropertyValuesHolder[] paddingValues = spec.getPropertyValues("paddingStart"); - paddingValues[0].setFloatValues( - ViewCompat.getPaddingStart(ExtendedFloatingActionButton.this), size.getPaddingStart()); + paddingValues[0].setFloatValues(getPaddingStart(), size.getPaddingStart()); spec.setPropertyValues("paddingStart", paddingValues); } if (spec.hasPropertyValues("paddingEnd")) { PropertyValuesHolder[] paddingValues = spec.getPropertyValues("paddingEnd"); - paddingValues[0].setFloatValues( - ViewCompat.getPaddingEnd(ExtendedFloatingActionButton.this), size.getPaddingEnd()); + paddingValues[0].setFloatValues(getPaddingEnd(), size.getPaddingEnd()); spec.setPropertyValues("paddingEnd", paddingValues); } diff --git a/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java b/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java index 35b114e90f4..8c445629d8c 100644 --- a/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java +++ b/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java @@ -887,7 +887,7 @@ protected void onRestoreInstanceState(Parcelable state) { */ @Deprecated public boolean getContentRect(@NonNull Rect rect) { - if (ViewCompat.isLaidOut(this)) { + if (isLaidOut()) { rect.set(0, 0, getWidth(), getHeight()); offsetRectWithShadow(rect); return true; diff --git a/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImpl.java b/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImpl.java index cb29655e796..d250c38fbdb 100644 --- a/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImpl.java +++ b/lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImpl.java @@ -47,7 +47,6 @@ import androidx.annotation.Nullable; import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.util.Preconditions; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.animation.AnimatorSetCompat; import com.google.android.material.animation.ImageMatrixProperty; @@ -921,7 +920,7 @@ protected float getTargetShadowSize() { } private boolean shouldAnimateVisibilityChange() { - return ViewCompat.isLaidOut(view) && !view.isInEditMode(); + return view.isLaidOut() && !view.isInEditMode(); } void updateFromViewRotation() { diff --git a/lib/java/com/google/android/material/internal/CheckableImageButton.java b/lib/java/com/google/android/material/internal/CheckableImageButton.java index 908cb22a81d..e246c8966a1 100644 --- a/lib/java/com/google/android/material/internal/CheckableImageButton.java +++ b/lib/java/com/google/android/material/internal/CheckableImageButton.java @@ -79,7 +79,7 @@ public void setChecked(boolean checked) { if (checkable && this.checked != checked) { this.checked = checked; refreshDrawableState(); - sendAccessibilityEvent(AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED); + sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); } } diff --git a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java index b48f54e97d3..f20a979f222 100644 --- a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java +++ b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java @@ -51,8 +51,6 @@ import androidx.annotation.RestrictTo; import androidx.core.math.MathUtils; import androidx.core.text.TextDirectionHeuristicsCompat; -import androidx.core.view.GravityCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.color.MaterialColors; import com.google.android.material.internal.StaticLayoutBuilderCompat.StaticLayoutBuilderCompatException; @@ -673,7 +671,7 @@ private void calculateOffsets(final float fraction) { } } - ViewCompat.postInvalidateOnAnimation(view); + view.postInvalidateOnAnimation(); } private float calculateFadeModeTextAlpha(@FloatRange(from = 0.0, to = 1.0) float fraction) { @@ -728,9 +726,9 @@ private void calculateBaseOffsets(boolean forceRecalculate) { collapsedTextWidth = 0; } final int collapsedAbsGravity = - GravityCompat.getAbsoluteGravity( + Gravity.getAbsoluteGravity( collapsedTextGravity, - isRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); + isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: @@ -746,7 +744,7 @@ private void calculateBaseOffsets(boolean forceRecalculate) { break; } - switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { + switch (collapsedAbsGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: collapsedDrawX = collapsedBounds.centerX() - (collapsedTextWidth / 2); break; @@ -770,9 +768,9 @@ private void calculateBaseOffsets(boolean forceRecalculate) { expandedLineCount = textLayout != null ? textLayout.getLineCount() : 0; final int expandedAbsGravity = - GravityCompat.getAbsoluteGravity( + Gravity.getAbsoluteGravity( expandedTextGravity, - isRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); + isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: expandedDrawY = expandedBounds.bottom - expandedTextHeight + textPaint.descent(); @@ -787,7 +785,7 @@ private void calculateBaseOffsets(boolean forceRecalculate) { break; } - switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { + switch (expandedAbsGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: expandedDrawX = expandedBounds.centerX() - (expandedTextWidth / 2); break; @@ -824,12 +822,12 @@ private void interpolateBounds(float fraction) { private void setCollapsedTextBlend(float blend) { collapsedTextBlend = blend; - ViewCompat.postInvalidateOnAnimation(view); + view.postInvalidateOnAnimation(); } private void setExpandedTextBlend(float blend) { expandedTextBlend = blend; - ViewCompat.postInvalidateOnAnimation(view); + view.postInvalidateOnAnimation(); } public void draw(@NonNull Canvas canvas) { @@ -948,7 +946,7 @@ private boolean calculateIsRtl(@NonNull CharSequence text) { } private boolean isDefaultIsRtl() { - return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } private boolean isTextDirectionHeuristicsIsRtl(@NonNull CharSequence text, boolean defaultIsRtl) { @@ -961,7 +959,7 @@ private boolean isTextDirectionHeuristicsIsRtl(@NonNull CharSequence text, boole private void setInterpolatedTextSize(float fraction) { calculateUsingTextSize(fraction); - ViewCompat.postInvalidateOnAnimation(view); + view.postInvalidateOnAnimation(); } private void calculateUsingTextSize(final float fraction) { @@ -1086,9 +1084,9 @@ private StaticLayout createStaticLayout(int maxLines, float availableWidth, bool private Alignment getMultilineTextLayoutAlignment() { int absoluteGravity = - GravityCompat.getAbsoluteGravity( + Gravity.getAbsoluteGravity( expandedTextGravity, - isRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); + isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: return ALIGN_CENTER; diff --git a/lib/java/com/google/android/material/internal/FlowLayout.java b/lib/java/com/google/android/material/internal/FlowLayout.java index 8336f5e5a8d..3d2ed341cf7 100644 --- a/lib/java/com/google/android/material/internal/FlowLayout.java +++ b/lib/java/com/google/android/material/internal/FlowLayout.java @@ -30,8 +30,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; -import androidx.core.view.MarginLayoutParamsCompat; -import androidx.core.view.ViewCompat; /** * Horizontally lay out children until the row is filled and then moved to the next line. Call @@ -194,7 +192,7 @@ protected void onLayout(boolean sizeChanged, int left, int top, int right, int b } rowCount = 1; - boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; + boolean isRtl = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int paddingStart = isRtl ? getPaddingRight() : getPaddingLeft(); int paddingEnd = isRtl ? getPaddingLeft() : getPaddingRight(); int childStart = paddingStart; @@ -217,8 +215,8 @@ protected void onLayout(boolean sizeChanged, int left, int top, int right, int b int endMargin = 0; if (lp instanceof MarginLayoutParams) { MarginLayoutParams marginLp = (MarginLayoutParams) lp; - startMargin = MarginLayoutParamsCompat.getMarginStart(marginLp); - endMargin = MarginLayoutParamsCompat.getMarginEnd(marginLp); + startMargin = marginLp.getMarginStart(); + endMargin = marginLp.getMarginEnd(); } childEnd = childStart + startMargin + child.getMeasuredWidth(); diff --git a/lib/java/com/google/android/material/internal/NavigationMenuItemView.java b/lib/java/com/google/android/material/internal/NavigationMenuItemView.java index d55377a76c1..d37e772e082 100644 --- a/lib/java/com/google/android/material/internal/NavigationMenuItemView.java +++ b/lib/java/com/google/android/material/internal/NavigationMenuItemView.java @@ -36,6 +36,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewStub; +import android.view.accessibility.AccessibilityEvent; import android.widget.CheckedTextView; import android.widget.FrameLayout; import androidx.annotation.Dimension; @@ -46,7 +47,6 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.view.AccessibilityDelegateCompat; import androidx.core.view.ViewCompat; -import androidx.core.view.accessibility.AccessibilityEventCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.widget.TextViewCompat; @@ -116,7 +116,7 @@ public void initialize(@NonNull MenuItemImpl itemData, int menuType) { setVisibility(itemData.isVisible() ? VISIBLE : GONE); if (getBackground() == null) { - ViewCompat.setBackground(this, createDefaultBackground()); + setBackground(createDefaultBackground()); } setCheckable(itemData.isCheckable()); @@ -213,7 +213,7 @@ public void setCheckable(boolean checkable) { if (this.checkable != checkable) { this.checkable = checkable; accessibilityDelegate.sendAccessibilityEvent( - textView, AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED); + textView, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); } } diff --git a/lib/java/com/google/android/material/internal/NavigationMenuPresenter.java b/lib/java/com/google/android/material/internal/NavigationMenuPresenter.java index 84674a9ef28..47890130fe4 100644 --- a/lib/java/com/google/android/material/internal/NavigationMenuPresenter.java +++ b/lib/java/com/google/android/material/internal/NavigationMenuPresenter.java @@ -136,8 +136,7 @@ public MenuView getMenuView(ViewGroup root) { headerLayout = (LinearLayout) layoutInflater.inflate(R.layout.design_navigation_item_header, menuView, false); - ViewCompat.setImportantForAccessibility( - headerLayout, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + headerLayout.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); menuView.setAdapter(adapter); } return menuView; @@ -593,8 +592,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) { if (textColor != null) { itemView.setTextColor(textColor); } - ViewCompat.setBackground( - itemView, + itemView.setBackground( itemBackground != null ? itemBackground.getConstantState().newDrawable() : null); if (itemForeground != null) { itemView.setForeground(itemForeground.getConstantState().newDrawable()); diff --git a/lib/java/com/google/android/material/internal/ScrimInsetsFrameLayout.java b/lib/java/com/google/android/material/internal/ScrimInsetsFrameLayout.java index 204a0eca275..6e1722332e2 100644 --- a/lib/java/com/google/android/material/internal/ScrimInsetsFrameLayout.java +++ b/lib/java/com/google/android/material/internal/ScrimInsetsFrameLayout.java @@ -87,7 +87,7 @@ public WindowInsetsCompat onApplyWindowInsets( insets.getSystemWindowInsetBottom()); onInsetsChanged(insets); setWillNotDraw(!insets.hasSystemWindowInsets() || insetForeground == null); - ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this); + postInvalidateOnAnimation(); return insets.consumeSystemWindowInsets(); } }); diff --git a/lib/java/com/google/android/material/internal/ViewOverlayApi14.java b/lib/java/com/google/android/material/internal/ViewOverlayApi14.java index e789b917a0c..bf502328651 100644 --- a/lib/java/com/google/android/material/internal/ViewOverlayApi14.java +++ b/lib/java/com/google/android/material/internal/ViewOverlayApi14.java @@ -171,7 +171,7 @@ public void add(View child) { ViewGroup parent = (ViewGroup) child.getParent(); if (parent != hostView && parent.getParent() != null - && ViewCompat.isAttachedToWindow(parent)) { + && parent.isAttachedToWindow()) { // Moving to different container; figure out how to position child such that // it is in the same location on the screen int[] parentLocation = new int[2]; diff --git a/lib/java/com/google/android/material/internal/ViewUtils.java b/lib/java/com/google/android/material/internal/ViewUtils.java index 0e07f510fb1..81fad714a27 100644 --- a/lib/java/com/google/android/material/internal/ViewUtils.java +++ b/lib/java/com/google/android/material/internal/ViewUtils.java @@ -181,7 +181,7 @@ public static PorterDuff.Mode parseTintMode(int value, PorterDuff.Mode defaultMo } public static boolean isLayoutRtl(View view) { - return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } public static float dpToPx(@NonNull Context context, @Dimension(unit = Dimension.DP) int dp) { @@ -230,7 +230,7 @@ public RelativePadding(@NonNull RelativePadding other) { /** Applies this relative padding to the view. */ public void applyToView(View view) { - ViewCompat.setPaddingRelative(view, start, top, end, bottom); + view.setPaddingRelative(start, top, end, bottom); } } @@ -310,9 +310,9 @@ public static void doOnApplyWindowInsets( // Create a snapshot of the view's padding state. final RelativePadding initialPadding = new RelativePadding( - ViewCompat.getPaddingStart(view), + view.getPaddingStart(), view.getPaddingTop(), - ViewCompat.getPaddingEnd(view), + view.getPaddingEnd(), view.getPaddingBottom()); // Set an actual OnApplyWindowInsetsListener which proxies to the given callback, also passing // in the original padding state. @@ -330,7 +330,7 @@ public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat inse /** Requests that insets should be applied to this view once it is attached. */ public static void requestApplyInsetsWhenAttached(@NonNull View view) { - if (ViewCompat.isAttachedToWindow(view)) { + if (view.isAttachedToWindow()) { // We're already attached, just request as normal. ViewCompat.requestApplyInsets(view); } else { diff --git a/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java b/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java index b6b56d9410d..aa5eeaffde6 100644 --- a/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java +++ b/lib/java/com/google/android/material/motion/MaterialSideContainerBackHelper.java @@ -37,8 +37,6 @@ import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.annotation.VisibleForTesting; -import androidx.core.view.GravityCompat; -import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import com.google.android.material.animation.AnimationUtils; @@ -179,8 +177,7 @@ public void cancelBackProgress() { } private boolean checkAbsoluteGravity(@GravityInt int gravity, @GravityInt int checkFor) { - int absoluteGravity = - GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(view)); + int absoluteGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()); return (absoluteGravity & checkFor) == checkFor; } diff --git a/lib/java/com/google/android/material/navigation/NavigationBarItemView.java b/lib/java/com/google/android/material/navigation/NavigationBarItemView.java index e32cb63a32d..83e7260512b 100644 --- a/lib/java/com/google/android/material/navigation/NavigationBarItemView.java +++ b/lib/java/com/google/android/material/navigation/NavigationBarItemView.java @@ -151,8 +151,8 @@ public NavigationBarItemView(@NonNull Context context) { // The labels used aren't always visible, so they are unreliable for accessibility. Instead, // the content description of the NavigationBarItemView should be used for accessibility. - ViewCompat.setImportantForAccessibility(smallLabel, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); - ViewCompat.setImportantForAccessibility(largeLabel, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + smallLabel.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); + largeLabel.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); setFocusable(true); calculateTextScaleFactors(smallLabel.getTextSize(), largeLabel.getTextSize()); @@ -337,7 +337,7 @@ private void maybeAnimateActiveIndicatorToProgress( @FloatRange(from = 0F, to = 1F) final float newProgress) { // If the active indicator is disabled or this view is in the process of being initialized, // jump the active indicator to it's final state. - if (!activeIndicatorEnabled || !initialized || !ViewCompat.isAttachedToWindow(this)) { + if (!activeIndicatorEnabled || !initialized || !isAttachedToWindow()) { setActiveIndicatorProgress(newProgress, newProgress); return; } @@ -722,7 +722,7 @@ && getActiveIndicatorDrawable() != null // Remove any padding to avoid the active indicator from from being clipped iconContainer.setPadding(0, 0, 0, 0); iconContainer.setForeground(iconContainerRippleDrawable); - ViewCompat.setBackground(this, itemBackgroundDrawable); + setBackground(itemBackgroundDrawable); if (VERSION.SDK_INT >= VERSION_CODES.O) { setDefaultFocusHighlightEnabled(defaultHighlightEnabled); } diff --git a/lib/java/com/google/android/material/navigation/NavigationBarMenuView.java b/lib/java/com/google/android/material/navigation/NavigationBarMenuView.java index dc6098c36c6..94f1bce63f4 100644 --- a/lib/java/com/google/android/material/navigation/NavigationBarMenuView.java +++ b/lib/java/com/google/android/material/navigation/NavigationBarMenuView.java @@ -42,7 +42,6 @@ import androidx.annotation.RestrictTo; import androidx.annotation.StyleRes; import androidx.core.util.Pools; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; import androidx.transition.AutoTransition; @@ -144,7 +143,7 @@ public void onClick(View v) { } }; - ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } @Override diff --git a/lib/java/com/google/android/material/navigation/NavigationBarView.java b/lib/java/com/google/android/material/navigation/NavigationBarView.java index bb006c0fd93..f706e32864f 100644 --- a/lib/java/com/google/android/material/navigation/NavigationBarView.java +++ b/lib/java/com/google/android/material/navigation/NavigationBarView.java @@ -52,7 +52,6 @@ import androidx.annotation.RestrictTo; import androidx.annotation.StyleRes; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import androidx.customview.view.AbsSavedState; import com.google.android.material.badge.BadgeDrawable; import com.google.android.material.drawable.DrawableUtils; @@ -208,7 +207,7 @@ public NavigationBarView( materialShapeDrawable.setFillColor(backgroundColorStateList); } materialShapeDrawable.initializeElevationOverlay(context); - ViewCompat.setBackground(this, materialShapeDrawable); + setBackground(materialShapeDrawable); } if (attributes.hasValue(R.styleable.NavigationBarView_itemPaddingTop)) { diff --git a/lib/java/com/google/android/material/navigation/NavigationView.java b/lib/java/com/google/android/material/navigation/NavigationView.java index a736b59b5c7..e125fbdfcde 100644 --- a/lib/java/com/google/android/material/navigation/NavigationView.java +++ b/lib/java/com/google/android/material/navigation/NavigationView.java @@ -67,8 +67,6 @@ import androidx.annotation.StyleRes; import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; -import androidx.core.view.GravityCompat; -import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.customview.view.AbsSavedState; import androidx.drawerlayout.widget.DrawerLayout; @@ -195,7 +193,7 @@ public NavigationView(@NonNull Context context, @Nullable AttributeSet attrs, in context, attrs, R.styleable.NavigationView, defStyleAttr, DEF_STYLE_RES); if (a.hasValue(R.styleable.NavigationView_android_background)) { - ViewCompat.setBackground(this, a.getDrawable(R.styleable.NavigationView_android_background)); + setBackground(a.getDrawable(R.styleable.NavigationView_android_background)); } // Get the drawer layout corner size to be used to shape the exposed corners of this view when @@ -219,7 +217,7 @@ public NavigationView(@NonNull Context context, @Nullable AttributeSet attrs, in materialShapeDrawable.setFillColor(backgroundColorStateList); } materialShapeDrawable.initializeElevationOverlay(context); - ViewCompat.setBackground(this, materialShapeDrawable); + setBackground(materialShapeDrawable); } if (a.hasValue(R.styleable.NavigationView_elevation)) { @@ -410,8 +408,7 @@ && getLayoutParams() instanceof DrawerLayout.LayoutParams && getBackground() instanceof MaterialShapeDrawable) { int layoutGravity = ((DrawerLayout.LayoutParams) getLayoutParams()).gravity; boolean isAbsGravityLeft = - GravityCompat.getAbsoluteGravity(layoutGravity, ViewCompat.getLayoutDirection(this)) - == Gravity.LEFT; + Gravity.getAbsoluteGravity(layoutGravity, getLayoutDirection()) == Gravity.LEFT; // Create and set a background to a MaterialShapeDrawable with the gravity edge's corners // set to zero. This is needed in addition to the ShapeableDelegate's clip since the diff --git a/lib/java/com/google/android/material/navigationrail/NavigationRailView.java b/lib/java/com/google/android/material/navigationrail/NavigationRailView.java index 40133b6e91a..fd682e1587d 100644 --- a/lib/java/com/google/android/material/navigationrail/NavigationRailView.java +++ b/lib/java/com/google/android/material/navigationrail/NavigationRailView.java @@ -36,7 +36,6 @@ import androidx.annotation.Px; import androidx.annotation.RestrictTo; import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.internal.ThemeEnforcement; @@ -228,7 +227,7 @@ public WindowInsetsCompat onApplyWindowInsets( * fitsSystemWindow will be used. */ private boolean shouldApplyWindowInsetPadding(Boolean paddingInsetFlag) { - return paddingInsetFlag != null ? paddingInsetFlag : ViewCompat.getFitsSystemWindows(this); + return paddingInsetFlag != null ? paddingInsetFlag : getFitsSystemWindows(); } @Override diff --git a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java index 671967d597c..7918124c6f1 100644 --- a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java +++ b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java @@ -41,7 +41,6 @@ import androidx.annotation.RestrictTo.Scope; import androidx.annotation.StyleRes; import androidx.annotation.VisibleForTesting; -import androidx.core.view.ViewCompat; import androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback; import com.google.android.material.color.MaterialColors; import com.google.android.material.internal.ThemeEnforcement; @@ -448,7 +447,7 @@ public IndeterminateDrawable getIndeterminateDrawable() { * attached to a window and whether it and its ancestors are visible. */ boolean visibleToUser() { - return ViewCompat.isAttachedToWindow(this) + return isAttachedToWindow() && getWindowVisibility() == View.VISIBLE && isEffectivelyVisible(); } diff --git a/lib/java/com/google/android/material/progressindicator/LinearProgressIndicator.java b/lib/java/com/google/android/material/progressindicator/LinearProgressIndicator.java index 7e9aac2e03d..173bd152d75 100644 --- a/lib/java/com/google/android/material/progressindicator/LinearProgressIndicator.java +++ b/lib/java/com/google/android/material/progressindicator/LinearProgressIndicator.java @@ -23,6 +23,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.view.View; import androidx.annotation.AttrRes; import androidx.annotation.IntDef; import androidx.annotation.NonNull; @@ -30,7 +31,6 @@ import androidx.annotation.Px; import androidx.annotation.RestrictTo; import androidx.annotation.RestrictTo.Scope; -import androidx.core.view.ViewCompat; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -109,9 +109,9 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto // In case that layout direction is changed, update the spec. spec.drawHorizontallyInverse = spec.indicatorDirection == INDICATOR_DIRECTION_RIGHT_TO_LEFT - || (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL + || (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL && spec.indicatorDirection == INDICATOR_DIRECTION_START_TO_END) - || (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR + || (getLayoutDirection() == View.LAYOUT_DIRECTION_LTR && spec.indicatorDirection == INDICATOR_DIRECTION_END_TO_START); } @@ -263,9 +263,9 @@ public void setIndicatorDirection(@IndicatorDirection int indicatorDirection) { spec.indicatorDirection = indicatorDirection; spec.drawHorizontallyInverse = indicatorDirection == INDICATOR_DIRECTION_RIGHT_TO_LEFT - || (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL + || (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL && spec.indicatorDirection == INDICATOR_DIRECTION_START_TO_END) - || (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR + || (getLayoutDirection() == View.LAYOUT_DIRECTION_LTR && indicatorDirection == INDICATOR_DIRECTION_END_TO_START); invalidate(); } diff --git a/lib/java/com/google/android/material/search/SearchBar.java b/lib/java/com/google/android/material/search/SearchBar.java index 550d9f3d7ee..54514cd55af 100644 --- a/lib/java/com/google/android/material/search/SearchBar.java +++ b/lib/java/com/google/android/material/search/SearchBar.java @@ -62,7 +62,6 @@ import androidx.annotation.StyleRes; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.MarginLayoutParamsCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityManagerCompat; import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener; @@ -274,10 +273,8 @@ private void initTextView(@StyleRes int textAppearanceResId, String text, String setText(text); setHint(hint); if (getNavigationIcon() == null) { - MarginLayoutParamsCompat.setMarginStart( - (MarginLayoutParams) textView.getLayoutParams(), - getResources() - .getDimensionPixelSize(R.dimen.m3_searchbar_text_margin_start_no_navigation_icon)); + ((MarginLayoutParams) textView.getLayoutParams()).setMarginStart(getResources() + .getDimensionPixelSize(R.dimen.m3_searchbar_text_margin_start_no_navigation_icon)); } } @@ -305,7 +302,7 @@ private void initBackground( background = backgroundShape; } - ViewCompat.setBackground(this, background); + setBackground(background); } private ColorStateList getCompatBackgroundColorStateList( @@ -553,7 +550,7 @@ private void layoutCenterView() { } private void layoutChild(View child, int left, int top, int right, int bottom) { - if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { child.layout(getMeasuredWidth() - right, top, getMeasuredWidth() - left, bottom); } else { child.layout(left, top, right, bottom); diff --git a/lib/java/com/google/android/material/search/SearchBarAnimationHelper.java b/lib/java/com/google/android/material/search/SearchBarAnimationHelper.java index 4cb52bfefee..65dfdd899fd 100644 --- a/lib/java/com/google/android/material/search/SearchBarAnimationHelper.java +++ b/lib/java/com/google/android/material/search/SearchBarAnimationHelper.java @@ -354,7 +354,7 @@ private AnimatorUpdateListener getExpandedViewBackgroundUpdateListener( return valueAnimator -> { expandedViewBackground.setInterpolation(1 - valueAnimator.getAnimatedFraction()); - ViewCompat.setBackground(expandedView, expandedViewBackground); + expandedView.setBackground(expandedViewBackground); // Ensures that the expanded view is visible, in the case where ActionMode is used. expandedView.setAlpha(1); diff --git a/lib/java/com/google/android/material/search/SearchView.java b/lib/java/com/google/android/material/search/SearchView.java index 7555a4df7e0..5180cfd39ba 100644 --- a/lib/java/com/google/android/material/search/SearchView.java +++ b/lib/java/com/google/android/material/search/SearchView.java @@ -979,15 +979,13 @@ private void updateChildImportantForAccessibility(ViewGroup parent, boolean isSe if (childImportantForAccessibilityMap != null && childImportantForAccessibilityMap.containsKey(child)) { // Restores the original important for accessibility value of the child view. - ViewCompat.setImportantForAccessibility( - child, childImportantForAccessibilityMap.get(child)); + child.setImportantForAccessibility(childImportantForAccessibilityMap.get(child)); } } else { // Saves the important for accessibility value of the child view. childImportantForAccessibilityMap.put(child, child.getImportantForAccessibility()); - ViewCompat.setImportantForAccessibility( - child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); } } } diff --git a/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java b/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java index 47bef96050c..5583112eed0 100644 --- a/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java +++ b/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java @@ -42,8 +42,6 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.MarginLayoutParamsCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.internal.ClippableRoundedCornerLayout; import com.google.android.material.internal.FadeThroughDrawable; @@ -566,17 +564,15 @@ private Animator getTranslationAnimator(boolean show, boolean anchoredToStart, V } private int getFromTranslationXStart(View view) { - int marginStart = - MarginLayoutParamsCompat.getMarginStart((MarginLayoutParams) view.getLayoutParams()); - int paddingStart = ViewCompat.getPaddingStart(searchBar); + int marginStart = ((MarginLayoutParams) view.getLayoutParams()).getMarginStart(); + int paddingStart = searchBar.getPaddingStart(); return ViewUtils.isLayoutRtl(searchBar) ? searchBar.getWidth() - searchBar.getRight() + marginStart - paddingStart : searchBar.getLeft() - marginStart + paddingStart; } private int getFromTranslationXEnd(View view) { - int marginEnd = - MarginLayoutParamsCompat.getMarginEnd((MarginLayoutParams) view.getLayoutParams()); + int marginEnd = ((MarginLayoutParams) view.getLayoutParams()).getMarginEnd(); return ViewUtils.isLayoutRtl(searchBar) ? searchBar.getLeft() - marginEnd : searchBar.getRight() - searchView.getWidth() + marginEnd; diff --git a/lib/java/com/google/android/material/sidesheet/SheetDialog.java b/lib/java/com/google/android/material/sidesheet/SheetDialog.java index 93e687704cf..ecdc10be361 100644 --- a/lib/java/com/google/android/material/sidesheet/SheetDialog.java +++ b/lib/java/com/google/android/material/sidesheet/SheetDialog.java @@ -40,7 +40,6 @@ import androidx.annotation.StyleRes; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.AccessibilityDelegateCompat; -import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import com.google.android.material.motion.MaterialBackOrchestrator; @@ -315,7 +314,7 @@ public void setSheetEdge(@GravityInt int gravity) { throw new IllegalStateException( "Sheet view reference is null; sheet edge cannot be changed if the sheet view is null."); } - if (ViewCompat.isLaidOut(sheet)) { + if (sheet.isLaidOut()) { throw new IllegalStateException( "Sheet view has been laid out; sheet edge cannot be changed once the sheet has been laid" + " out."); @@ -335,8 +334,7 @@ private void maybeUpdateWindowAnimationsBasedOnLayoutDirection() { CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) sheet.getLayoutParams(); int absoluteGravity = - GravityCompat.getAbsoluteGravity( - layoutParams.gravity, ViewCompat.getLayoutDirection(sheet)); + Gravity.getAbsoluteGravity(layoutParams.gravity, sheet.getLayoutDirection()); window.setWindowAnimations( absoluteGravity == Gravity.LEFT ? R.style.Animation_Material3_SideSheetDialog_Left diff --git a/lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java b/lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java index 411ff3ab5e5..d425690449b 100644 --- a/lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java +++ b/lib/java/com/google/android/material/sidesheet/SideSheetBehavior.java @@ -52,7 +52,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams; import androidx.core.math.MathUtils; -import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat; @@ -169,7 +168,7 @@ public SideSheetBehavior(@NonNull Context context, @Nullable AttributeSet attrs) private void setSheetEdge(@NonNull V view, int layoutDirection) { LayoutParams params = (LayoutParams) view.getLayoutParams(); - int sheetGravity = GravityCompat.getAbsoluteGravity(params.gravity, layoutDirection); + int sheetGravity = Gravity.getAbsoluteGravity(params.gravity, layoutDirection); setSheetEdge(sheetGravity == Gravity.LEFT ? EDGE_LEFT : EDGE_RIGHT); } @@ -351,7 +350,7 @@ private int getChildMeasureSpec( @Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull final V child, int layoutDirection) { - if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { + if (parent.getFitsSystemWindows() && !child.getFitsSystemWindows()) { child.setFitsSystemWindows(true); } @@ -364,7 +363,7 @@ public boolean onLayoutChild( // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (materialShapeDrawable != null) { - ViewCompat.setBackground(child, materialShapeDrawable); + child.setBackground(materialShapeDrawable); // Use elevation attr if set on side sheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); @@ -374,9 +373,8 @@ public boolean onLayoutChild( updateSheetVisibility(child); updateAccessibilityActions(); - if (ViewCompat.getImportantForAccessibility(child) - == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { - ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + if (child.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } ensureAccessibilityPaneTitleIsSet(child); } @@ -666,7 +664,7 @@ private void runAfterLayout(@NonNull V child, Runnable runnable) { private boolean isLayingOut(@NonNull V child) { ViewParent parent = child.getParent(); - return parent != null && parent.isLayoutRequested() && ViewCompat.isAttachedToWindow(child); + return parent != null && parent.isLayoutRequested() && child.isAttachedToWindow(); } /** @@ -915,7 +913,7 @@ public void setCoplanarSiblingViewId(@IdRes int coplanarSiblingViewId) { // Request layout to find the view and trigger a layout pass. if (viewRef != null) { View view = viewRef.get(); - if (coplanarSiblingViewId != View.NO_ID && ViewCompat.isLaidOut(view)) { + if (coplanarSiblingViewId != View.NO_ID && view.isLaidOut()) { view.requestLayout(); } } @@ -937,7 +935,7 @@ public void setCoplanarSiblingView(@Nullable View coplanarSiblingView) { // Request layout to make the new view take effect. if (viewRef != null) { View view = viewRef.get(); - if (ViewCompat.isLaidOut(view)) { + if (view.isLaidOut()) { view.requestLayout(); } } @@ -1105,7 +1103,7 @@ void continueSettlingToState(@StableSheetState int targetState) { } this.targetState = targetState; if (!isContinueSettlingRunnablePosted) { - ViewCompat.postOnAnimation(viewRef.get(), continueSettlingRunnable); + viewRef.get().postOnAnimation(continueSettlingRunnable); isContinueSettlingRunnablePosted = true; } } diff --git a/lib/java/com/google/android/material/slider/BaseSlider.java b/lib/java/com/google/android/material/slider/BaseSlider.java index 9619ea0046d..d586b700fe9 100644 --- a/lib/java/com/google/android/material/slider/BaseSlider.java +++ b/lib/java/com/google/android/material/slider/BaseSlider.java @@ -567,7 +567,7 @@ private boolean maybeIncreaseTrackSidePadding() { return false; } trackSidePadding = newTrackSidePadding; - if (ViewCompat.isLaidOut(this)) { + if (isLaidOut()) { updateTrackWidth(getWidth()); } return true; @@ -807,7 +807,7 @@ private void createLabelPool() { if (labels.size() > values.size()) { List tooltipDrawables = labels.subList(values.size(), labels.size()); for (TooltipDrawable label : tooltipDrawables) { - if (ViewCompat.isAttachedToWindow(this)) { + if (isAttachedToWindow()) { detachLabelFromContentView(label); } } @@ -821,7 +821,7 @@ private void createLabelPool() { TooltipDrawable tooltipDrawable = TooltipDrawable.createFromAttributes(getContext(), null, 0, labelStyle); labels.add(tooltipDrawable); - if (ViewCompat.isAttachedToWindow(this)) { + if (isAttachedToWindow()) { attachLabelToContentView(tooltipDrawable); } } @@ -2637,7 +2637,7 @@ public void onAnimationUpdate(ValueAnimator animation) { label.setRevealFraction(fraction); } // Ensure the labels are redrawn even if the slider has stopped moving - ViewCompat.postInvalidateOnAnimation(BaseSlider.this); + postInvalidateOnAnimation(); } }); return animator; @@ -2947,7 +2947,7 @@ public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { } final boolean isRtl() { - return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; + return getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } /** diff --git a/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java b/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java index 9416fcaab26..68f18c0e750 100644 --- a/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java +++ b/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java @@ -386,11 +386,11 @@ protected BaseTransientBottomBar( } view.addView(content); - ViewCompat.setAccessibilityLiveRegion(view, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); - ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + view.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); + view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); // Make sure that we fit system windows and have a listener to apply any insets - ViewCompat.setFitsSystemWindows(view, true); + view.setFitsSystemWindows(true); ViewCompat.setOnApplyWindowInsetsListener( view, new OnApplyWindowInsetsListener() { @@ -786,7 +786,7 @@ final void showView() { view.setVisibility(View.INVISIBLE); } - if (ViewCompat.isLaidOut(this.view)) { + if (view.isLaidOut()) { showViewImpl(); return; } @@ -1211,7 +1211,7 @@ protected SnackbarBaseLayout(@NonNull Context context, AttributeSet attrs) { setFocusable(true); if (getBackground() == null) { - ViewCompat.setBackground(this, createThemedBackground()); + setBackground(createThemedBackground()); } } @@ -1469,7 +1469,7 @@ static class Anchor static Anchor anchor( @NonNull BaseTransientBottomBar transientBottomBar, @NonNull View anchorView) { Anchor anchor = new Anchor(transientBottomBar, anchorView); - if (ViewCompat.isAttachedToWindow(anchorView)) { + if (anchorView.isAttachedToWindow()) { ViewUtils.addOnGlobalLayoutListener(anchorView, anchor); } anchorView.addOnAttachStateChangeListener(anchor); diff --git a/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java b/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java index e961875e49c..40dbe9f74b9 100644 --- a/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java +++ b/lib/java/com/google/android/material/snackbar/SnackbarContentLayout.java @@ -30,7 +30,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.color.MaterialColors; import com.google.android.material.motion.MotionUtils; @@ -136,12 +135,11 @@ private boolean updateViewsWithinLayout( private static void updateTopBottomPadding( @NonNull View view, int topPadding, int bottomPadding) { - if (ViewCompat.isPaddingRelative(view)) { - ViewCompat.setPaddingRelative( - view, - ViewCompat.getPaddingStart(view), + if (view.isPaddingRelative()) { + view.setPaddingRelative( + view.getPaddingStart(), topPadding, - ViewCompat.getPaddingEnd(view), + view.getPaddingEnd(), bottomPadding); } else { view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), bottomPadding); diff --git a/lib/java/com/google/android/material/tabs/TabLayout.java b/lib/java/com/google/android/material/tabs/TabLayout.java index a02cf088cbb..fa0609b0fa9 100644 --- a/lib/java/com/google/android/material/tabs/TabLayout.java +++ b/lib/java/com/google/android/material/tabs/TabLayout.java @@ -77,8 +77,6 @@ import androidx.annotation.StringRes; import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.util.Pools; -import androidx.core.view.GravityCompat; -import androidx.core.view.MarginLayoutParamsCompat; import androidx.core.view.PointerIconCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; @@ -551,7 +549,7 @@ public TabLayout(@NonNull Context context, @Nullable AttributeSet attrs, int def materialShapeDrawable.setFillColor(backgroundColorStateList); materialShapeDrawable.initializeElevationOverlay(context); materialShapeDrawable.setElevation(ViewCompat.getElevation(this)); - ViewCompat.setBackground(this, materialShapeDrawable); + setBackground(materialShapeDrawable); } setSelectedTabIndicator( @@ -807,7 +805,7 @@ void setScrollPosition( || (position == getSelectedTabPosition()); // If the layout direction is RTL, the scrollXForPosition and scrollX comparisons are // reversed since scrollX values remain the same in RTL but tab positions go RTL. - if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { toMove = (position < getSelectedTabPosition() && scrollXForPosition <= scrollX) || (position > getSelectedTabPosition() @@ -1192,7 +1190,7 @@ public int getTabGravity() { public void setSelectedTabIndicatorGravity(@TabIndicatorGravity int indicatorGravity) { if (tabIndicatorGravity != indicatorGravity) { tabIndicatorGravity = indicatorGravity; - ViewCompat.postInvalidateOnAnimation(slidingTabIndicator); + slidingTabIndicator.postInvalidateOnAnimation(); } } @@ -1270,7 +1268,7 @@ public int getTabIndicatorAnimationMode() { public void setTabIndicatorFullWidth(boolean tabIndicatorFullWidth) { this.tabIndicatorFullWidth = tabIndicatorFullWidth; slidingTabIndicator.jumpIndicatorToSelectedPosition(); - ViewCompat.postInvalidateOnAnimation(slidingTabIndicator); + slidingTabIndicator.postInvalidateOnAnimation(); } /** @@ -1922,9 +1920,7 @@ private void animateToTab(int newPosition) { return; } - if (getWindowToken() == null - || !ViewCompat.isLaidOut(this) - || slidingTabIndicator.childrenNeedLayout()) { + if (getWindowToken() == null || !isLaidOut() || slidingTabIndicator.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); @@ -2080,7 +2076,7 @@ private int calculateScrollXForTab(int position, float positionOffset) { // offset amount: fraction of the distance between centers of tabs int scrollOffset = (int) ((selectedWidth + nextWidth) * 0.5f * positionOffset); - return (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) + return (getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) ? scrollBase + scrollOffset : scrollBase - scrollOffset; } @@ -2093,7 +2089,7 @@ private void applyModeAndGravity() { // If we're scrollable, or fixed at start, inset using padding paddingStart = Math.max(0, contentInsetStart - tabPaddingStart); } - ViewCompat.setPaddingRelative(slidingTabIndicator, paddingStart, 0, 0, 0); + slidingTabIndicator.setPaddingRelative(paddingStart, 0, 0, 0); switch (mode) { case MODE_AUTO: @@ -2126,7 +2122,7 @@ private void applyGravityForModeScrollable(int tabGravity) { + " instead"); // Fall through case GRAVITY_START: - slidingTabIndicator.setGravity(GravityCompat.START); + slidingTabIndicator.setGravity(Gravity.START); break; default: break; @@ -2549,8 +2545,7 @@ public final class TabView extends LinearLayout { public TabView(@NonNull Context context) { super(context); updateBackgroundDrawable(context); - ViewCompat.setPaddingRelative( - this, tabPaddingStart, tabPaddingTop, tabPaddingEnd, tabPaddingBottom); + setPaddingRelative(tabPaddingStart, tabPaddingTop, tabPaddingEnd, tabPaddingBottom); setGravity(Gravity.CENTER); setOrientation(inlineLabel ? HORIZONTAL : VERTICAL); setClickable(true); @@ -2599,7 +2594,7 @@ private void updateBackgroundDrawable(Context context) { } else { background = contentDrawable; } - ViewCompat.setBackground(this, background); + setBackground(background); TabLayout.this.invalidate(); } @@ -3072,8 +3067,8 @@ private void updateTextAndIcon( iconMargin = (int) ViewUtils.dpToPx(getContext(), DEFAULT_GAP_TEXT_ICON); } if (inlineLabel) { - if (iconMargin != MarginLayoutParamsCompat.getMarginEnd(lp)) { - MarginLayoutParamsCompat.setMarginEnd(lp, iconMargin); + if (iconMargin != lp.getMarginEnd()) { + lp.setMarginEnd(iconMargin); lp.bottomMargin = 0; // Calls resolveLayoutParams(), necessary for layout direction iconView.setLayoutParams(lp); @@ -3082,7 +3077,7 @@ private void updateTextAndIcon( } else { if (iconMargin != lp.bottomMargin) { lp.bottomMargin = iconMargin; - MarginLayoutParamsCompat.setMarginEnd(lp, 0); + lp.setMarginEnd(0); // Calls resolveLayoutParams(), necessary for layout direction iconView.setLayoutParams(lp); iconView.requestLayout(); @@ -3369,7 +3364,7 @@ private void tweenIndicatorPosition(View startTitle, View endTitle, float fracti -1, tabSelectedIndicator.getBounds().top, -1, tabSelectedIndicator.getBounds().bottom); } - ViewCompat.postInvalidateOnAnimation(this); + postInvalidateOnAnimation(); } /** diff --git a/lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java b/lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java index 4407277aab0..14adb0028dd 100644 --- a/lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java +++ b/lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java @@ -19,8 +19,6 @@ import com.google.android.material.R; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_CLICKED; -import static androidx.core.view.ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO; -import static androidx.core.view.ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES; import static com.google.android.material.textfield.EditTextUtils.isEditable; import android.animation.Animator; @@ -44,7 +42,6 @@ import androidx.annotation.ChecksSdkIntAtLeast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityEventCompat; import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; @@ -81,9 +78,8 @@ class DropdownMenuEndIconDelegate extends EndIconDelegate { private final TouchExplorationStateChangeListener touchExplorationStateChangeListener = (boolean enabled) -> { if (autoCompleteTextView != null && !isEditable(autoCompleteTextView)) { - ViewCompat.setImportantForAccessibility( - endIconView, - enabled ? IMPORTANT_FOR_ACCESSIBILITY_NO : IMPORTANT_FOR_ACCESSIBILITY_YES); + endIconView.setImportantForAccessibility( + enabled ? View.IMPORTANT_FOR_ACCESSIBILITY_NO : View.IMPORTANT_FOR_ACCESSIBILITY_YES); } }; @@ -192,7 +188,7 @@ public void onEditTextAttached(@Nullable EditText editText) { setUpDropdownShowHideBehavior(); textInputLayout.setErrorIconDrawable(null); if (!isEditable(editText) && accessibilityManager.isTouchExplorationEnabled()) { - ViewCompat.setImportantForAccessibility(endIconView, IMPORTANT_FOR_ACCESSIBILITY_NO); + endIconView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); } textInputLayout.setEndIconVisible(true); } diff --git a/lib/java/com/google/android/material/textfield/EndCompoundLayout.java b/lib/java/com/google/android/material/textfield/EndCompoundLayout.java index 7465f87e3b1..6e01174b6cb 100644 --- a/lib/java/com/google/android/material/textfield/EndCompoundLayout.java +++ b/lib/java/com/google/android/material/textfield/EndCompoundLayout.java @@ -62,8 +62,6 @@ import androidx.annotation.StringRes; import androidx.annotation.StyleRes; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.MarginLayoutParamsCompat; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityManagerCompat; import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener; import androidx.core.widget.TextViewCompat; @@ -210,7 +208,7 @@ private CheckableImageButton createIconView( if (MaterialResources.isFontScaleAtLeast1_3(getContext())) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) iconView.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(lp, 0); + lp.setMarginStart(0); } return iconView; } @@ -231,8 +229,7 @@ private void initErrorIconView(TintTypedArray a) { } errorIconView.setContentDescription( getResources().getText(R.string.error_icon_content_description)); - ViewCompat.setImportantForAccessibility( - errorIconView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + errorIconView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); errorIconView.setClickable(false); errorIconView.setPressable(false); errorIconView.setFocusable(false); @@ -299,8 +296,7 @@ private void initSuffixTextView(TintTypedArray a) { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM)); - ViewCompat.setAccessibilityLiveRegion( - suffixTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); + suffixTextView.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); setSuffixTextAppearance( a.getResourceId(R.styleable.TextInputLayout_suffixTextAppearance, 0)); @@ -425,7 +421,7 @@ private void tearDownDelegate(@NonNull EndIconDelegate delegate) { private void addTouchExplorationStateChangeListenerIfNeeded() { if (touchExplorationStateChangeListener != null && accessibilityManager != null - && ViewCompat.isAttachedToWindow(this)) { + && isAttachedToWindow()) { AccessibilityManagerCompat.addTouchExplorationStateChangeListener( accessibilityManager, touchExplorationStateChangeListener); } @@ -725,10 +721,8 @@ void updateSuffixTextViewPadding() { return; } int endPadding = - (isEndIconVisible() || isErrorIconVisible()) - ? 0 : ViewCompat.getPaddingEnd(textInputLayout.editText); - ViewCompat.setPaddingRelative( - suffixTextView, + (isEndIconVisible() || isErrorIconVisible()) ? 0 : textInputLayout.editText.getPaddingEnd(); + suffixTextView.setPaddingRelative( getContext() .getResources() .getDimensionPixelSize(R.dimen.material_input_text_to_prefix_suffix_padding), @@ -742,13 +736,12 @@ int getSuffixTextEndOffset() { if (isEndIconVisible() || isErrorIconVisible()) { endIconOffset = endIconView.getMeasuredWidth() - + MarginLayoutParamsCompat.getMarginStart( - (MarginLayoutParams) endIconView.getLayoutParams()); + + ((MarginLayoutParams) endIconView.getLayoutParams()).getMarginStart(); } else { endIconOffset = 0; } - return ViewCompat.getPaddingEnd(this) - + ViewCompat.getPaddingEnd(suffixTextView) + return getPaddingEnd() + + suffixTextView.getPaddingEnd() + endIconOffset; } diff --git a/lib/java/com/google/android/material/textfield/IconHelper.java b/lib/java/com/google/android/material/textfield/IconHelper.java index 4b89871484d..2b699ef04dd 100644 --- a/lib/java/com/google/android/material/textfield/IconHelper.java +++ b/lib/java/com/google/android/material/textfield/IconHelper.java @@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; +import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.ImageView; @@ -30,7 +31,6 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.internal.CheckableImageButton; import com.google.android.material.ripple.RippleUtils; import java.util.Arrays; @@ -55,18 +55,17 @@ static void setIconOnLongClickListener( private static void setIconClickable( @NonNull CheckableImageButton iconView, @Nullable OnLongClickListener onLongClickListener) { - boolean iconClickable = ViewCompat.hasOnClickListeners(iconView); + boolean iconClickable = iconView.hasOnClickListeners(); boolean iconLongClickable = onLongClickListener != null; boolean iconFocusable = iconClickable || iconLongClickable; iconView.setFocusable(iconFocusable); iconView.setClickable(iconClickable); iconView.setPressable(iconClickable); iconView.setLongClickable(iconLongClickable); - ViewCompat.setImportantForAccessibility( - iconView, + iconView.setImportantForAccessibility( iconFocusable - ? ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES - : ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + ? View.IMPORTANT_FOR_ACCESSIBILITY_YES + : View.IMPORTANT_FOR_ACCESSIBILITY_NO); } /** diff --git a/lib/java/com/google/android/material/textfield/IndicatorViewController.java b/lib/java/com/google/android/material/textfield/IndicatorViewController.java index 33db33a0ea0..4f1ea6d3ce3 100644 --- a/lib/java/com/google/android/material/textfield/IndicatorViewController.java +++ b/lib/java/com/google/android/material/textfield/IndicatorViewController.java @@ -46,7 +46,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StyleRes; -import androidx.core.view.ViewCompat; import androidx.core.widget.TextViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.animation.AnimatorSetCompat; @@ -222,7 +221,7 @@ void hideError() { */ private boolean shouldAnimateCaptionView( @Nullable TextView captionView, @NonNull final CharSequence captionText) { - return ViewCompat.isLaidOut(textInputView) + return textInputView.isLaidOut() && textInputView.isEnabled() && (captionToShow != captionDisplayed || captionView == null @@ -400,12 +399,11 @@ void adjustIndicatorPadding() { if (canAdjustIndicatorPadding()) { EditText editText = textInputView.getEditText(); boolean isFontScaleLarge = MaterialResources.isFontScaleAtLeast1_3(context); - ViewCompat.setPaddingRelative( - indicatorArea, + indicatorArea.setPaddingRelative( getIndicatorPadding( isFontScaleLarge, R.dimen.material_helper_text_font_1_3_padding_horizontal, - ViewCompat.getPaddingStart(editText)), + editText.getPaddingStart()), getIndicatorPadding( isFontScaleLarge, R.dimen.material_helper_text_font_1_3_padding_top, @@ -415,7 +413,7 @@ void adjustIndicatorPadding() { getIndicatorPadding( isFontScaleLarge, R.dimen.material_helper_text_font_1_3_padding_horizontal, - ViewCompat.getPaddingEnd(editText)), + editText.getPaddingEnd()), 0); } } @@ -536,8 +534,7 @@ void setHelperTextEnabled(boolean enabled) { helperTextView.setTypeface(typeface); } helperTextView.setVisibility(View.INVISIBLE); - ViewCompat.setAccessibilityLiveRegion( - helperTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); + helperTextView.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); setHelperTextAppearance(helperTextTextAppearance); setHelperTextViewTextColor(helperTextViewTextColor); addIndicator(helperTextView, HELPER_INDEX); @@ -654,7 +651,7 @@ void setErrorContentDescription(@Nullable final CharSequence errorContentDescrip void setErrorAccessibilityLiveRegion(final int accessibilityLiveRegion) { this.errorViewAccessibilityLiveRegion = accessibilityLiveRegion; if (errorView != null) { - ViewCompat.setAccessibilityLiveRegion(errorView, accessibilityLiveRegion); + errorView.setAccessibilityLiveRegion(accessibilityLiveRegion); } } diff --git a/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java b/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java index 1913598d016..642d15a4859 100644 --- a/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java +++ b/lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java @@ -54,7 +54,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; import com.google.android.material.color.MaterialColors; import com.google.android.material.internal.ManufacturerUtils; import com.google.android.material.internal.ThemeEnforcement; @@ -547,7 +546,7 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent) if (view instanceof TextView) { TextView textView = (TextView) view; boolean isSelectedItem = getText().toString().contentEquals(textView.getText()); - ViewCompat.setBackground(textView, isSelectedItem ? getSelectedItemDrawable() : null); + textView.setBackground(isSelectedItem ? getSelectedItemDrawable() : null); } return view; diff --git a/lib/java/com/google/android/material/textfield/StartCompoundLayout.java b/lib/java/com/google/android/material/textfield/StartCompoundLayout.java index 61f0df19299..d04c0e2c909 100644 --- a/lib/java/com/google/android/material/textfield/StartCompoundLayout.java +++ b/lib/java/com/google/android/material/textfield/StartCompoundLayout.java @@ -47,8 +47,6 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.annotation.StyleRes; -import androidx.core.view.MarginLayoutParamsCompat; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.widget.TextViewCompat; import com.google.android.material.internal.CheckableImageButton; @@ -109,7 +107,7 @@ private void initStartIconView(TintTypedArray a) { if (MaterialResources.isFontScaleAtLeast1_3(getContext())) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) startIconView.getLayoutParams(); - MarginLayoutParamsCompat.setMarginEnd(lp, 0); + lp.setMarginEnd(0); } setStartIconOnClickListener(null); setStartIconOnLongClickListener(null); @@ -150,8 +148,7 @@ private void initPrefixTextView(TintTypedArray a) { prefixTextView.setId(R.id.textinput_prefix_text); prefixTextView.setLayoutParams( new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - ViewCompat.setAccessibilityLiveRegion( - prefixTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); + prefixTextView.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); setPrefixTextAppearance(a.getResourceId(R.styleable.TextInputLayout_prefixTextAppearance, 0)); if (a.hasValue(R.styleable.TextInputLayout_prefixTextColor)) { @@ -317,9 +314,8 @@ void updatePrefixTextViewPadding() { if (editText == null) { return; } - int startPadding = isStartIconVisible() ? 0 : ViewCompat.getPaddingStart(editText); - ViewCompat.setPaddingRelative( - prefixTextView, + int startPadding = isStartIconVisible() ? 0 : editText.getPaddingStart(); + prefixTextView.setPaddingRelative( startPadding, editText.getCompoundPaddingTop(), getContext() @@ -333,13 +329,12 @@ int getPrefixTextStartOffset() { if (isStartIconVisible()) { startIconOffset = startIconView.getMeasuredWidth() - + MarginLayoutParamsCompat.getMarginEnd( - (MarginLayoutParams) startIconView.getLayoutParams()); + + ((MarginLayoutParams) startIconView.getLayoutParams()).getMarginEnd(); } else { startIconOffset = 0; } - return ViewCompat.getPaddingStart(this) - + ViewCompat.getPaddingStart(prefixTextView) + return getPaddingStart() + + prefixTextView.getPaddingStart() + startIconOffset; } diff --git a/lib/java/com/google/android/material/textfield/TextInputLayout.java b/lib/java/com/google/android/material/textfield/TextInputLayout.java index 77bf825d398..8071688c59e 100644 --- a/lib/java/com/google/android/material/textfield/TextInputLayout.java +++ b/lib/java/com/google/android/material/textfield/TextInputLayout.java @@ -83,8 +83,6 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.text.BidiFormatter; import androidx.core.view.AccessibilityDelegateCompat; -import androidx.core.view.GravityCompat; -import androidx.core.view.MarginLayoutParamsCompat; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.core.widget.TextViewCompat; @@ -480,7 +478,7 @@ public TextInputLayout(@NonNull Context context, @Nullable AttributeSet attrs, i collapsingTextHelper.setTextSizeInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); collapsingTextHelper.setPositionInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); - collapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START); + collapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | Gravity.START); final TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes( @@ -695,12 +693,12 @@ public TextInputLayout(@NonNull Context context, @Nullable AttributeSet attrs, i // For accessibility, consider TextInputLayout itself to be a simple container for an EditText, // and do not expose it to accessibility services. - ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); // For autofill to work as intended, TextInputLayout needs to pass the hint text to the nested // EditText so marking it as IMPORTANT_FOR_AUTOFILL_YES. if (VERSION.SDK_INT >= VERSION_CODES.O) { - ViewCompat.setImportantForAutofill(this, View.IMPORTANT_FOR_AUTOFILL_YES); + setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_YES); } inputFrame.addView(startLayout); @@ -861,10 +859,10 @@ private void updateEditTextBoxBackground() { int paddingRight = editText.getPaddingRight(); int paddingBottom = editText.getPaddingBottom(); - ViewCompat.setBackground(editText, editTextBoxBackground); + editText.setBackground(editTextBoxBackground); editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } else { - ViewCompat.setBackground(editText, editTextBoxBackground); + editText.setBackground(editTextBoxBackground); } } @@ -1025,21 +1023,19 @@ private void adjustFilledEditTextPaddingForLargeFont() { } // Both dense and default styles end up with the same vertical padding. if (MaterialResources.isFontScaleAtLeast2_0(getContext())) { - ViewCompat.setPaddingRelative( - editText, - ViewCompat.getPaddingStart(editText), + editText.setPaddingRelative( + editText.getPaddingStart(), getResources() .getDimensionPixelSize(R.dimen.material_filled_edittext_font_2_0_padding_top), - ViewCompat.getPaddingEnd(editText), + editText.getPaddingEnd(), getResources() .getDimensionPixelSize(R.dimen.material_filled_edittext_font_2_0_padding_bottom)); } else if (MaterialResources.isFontScaleAtLeast1_3(getContext())) { - ViewCompat.setPaddingRelative( - editText, - ViewCompat.getPaddingStart(editText), + editText.setPaddingRelative( + editText.getPaddingStart(), getResources() .getDimensionPixelSize(R.dimen.material_filled_edittext_font_1_3_padding_top), - ViewCompat.getPaddingEnd(editText), + editText.getPaddingEnd(), getResources() .getDimensionPixelSize(R.dimen.material_filled_edittext_font_1_3_padding_bottom)); } @@ -1560,7 +1556,7 @@ private void setEditText(EditText editText) { Gravity.TOP | (editTextGravity & ~Gravity.VERTICAL_GRAVITY_MASK)); collapsingTextHelper.setExpandedTextGravity(editTextGravity); - originalEditTextMinimumHeight = ViewCompat.getMinimumHeight(editText); + originalEditTextMinimumHeight = editText.getMinimumHeight(); // Add a TextWatcher so that we know when the text input has changed. this.editText.addTextChangedListener( @@ -1579,7 +1575,7 @@ public void afterTextChanged(@NonNull Editable s) { int currentLineCount = editText.getLineCount(); if (currentLineCount != previousLineCount) { if (currentLineCount < previousLineCount - && ViewCompat.getMinimumHeight(editText) != originalEditTextMinimumHeight) { + && editText.getMinimumHeight() != originalEditTextMinimumHeight) { editText.setMinimumHeight(originalEditTextMinimumHeight); } previousLineCount = currentLineCount; @@ -2261,8 +2257,7 @@ public void setCounterEnabled(boolean enabled) { } counterView.setMaxLines(1); indicatorViewController.addIndicator(counterView, COUNTER_INDEX); - MarginLayoutParamsCompat.setMarginStart( - (MarginLayoutParams) counterView.getLayoutParams(), + ((MarginLayoutParams) counterView.getLayoutParams()).setMarginStart( getResources().getDimensionPixelOffset(R.dimen.mtrl_textinput_counter_margin_start)); updateCounterTextAppearanceAndColor(); updateCounter(); @@ -2449,8 +2444,7 @@ public void setPlaceholderText(@Nullable final CharSequence placeholderText) { if (placeholderTextView == null) { placeholderTextView = new AppCompatTextView(getContext()); placeholderTextView.setId(R.id.textinput_placeholder); - ViewCompat.setImportantForAccessibility( - placeholderTextView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + placeholderTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); placeholderFadeIn = createPlaceholderFadeTransition(); placeholderFadeIn.setStartDelay(PLACEHOLDER_START_DELAY); @@ -3252,7 +3246,7 @@ public void setExpandedHintEnabled(boolean enabled) { @Override public void onRtlPropertiesChanged(int layoutDirection) { super.onRtlPropertiesChanged(layoutDirection); - boolean isLayoutDirectionRtl = layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL; + boolean isLayoutDirectionRtl = layoutDirection == View.LAYOUT_DIRECTION_RTL; if (isLayoutDirectionRtl != areCornerRadiiRtl) { // Switch corner radius values from LTR to RTL or vice versa. float boxCornerRadiusTopLeft = @@ -4125,8 +4119,7 @@ boolean updateDummyDrawables() { right = right + iconView.getMeasuredWidth() - + MarginLayoutParamsCompat.getMarginStart( - ((MarginLayoutParams) iconView.getLayoutParams())); + + ((MarginLayoutParams) iconView.getLayoutParams()).getMarginStart(); } final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText); if (endDummyDrawable != null && endDummyDrawableWidth != right) { @@ -4349,7 +4342,7 @@ protected void drawableStateChanged() { // Drawable state has changed so see if we need to update the label if (editText != null) { - updateLabelState(ViewCompat.isLaidOut(this) && isEnabled()); + updateLabelState(isLaidOut() && isEnabled()); } updateEditTextBackground(); updateTextInputBoxState(); diff --git a/lib/java/com/google/android/material/timepicker/ChipTextInputComboView.java b/lib/java/com/google/android/material/timepicker/ChipTextInputComboView.java index 883cf3e4ead..4a4201a584b 100644 --- a/lib/java/com/google/android/material/timepicker/ChipTextInputComboView.java +++ b/lib/java/com/google/android/material/timepicker/ChipTextInputComboView.java @@ -31,6 +31,7 @@ import android.text.TextWatcher; import android.util.AttributeSet; import android.view.LayoutInflater; +import android.view.View; import android.widget.Checkable; import android.widget.EditText; import android.widget.FrameLayout; @@ -81,8 +82,8 @@ public ChipTextInputComboView( addView(chip); addView(textInputLayout); label = findViewById(R.id.material_label); - editText.setId(ViewCompat.generateViewId()); - ViewCompat.setLabelFor(label, editText.getId()); + editText.setId(View.generateViewId()); + label.setLabelFor(editText.getId()); editText.setSaveEnabled(false); editText.setLongClickable(false); } diff --git a/lib/java/com/google/android/material/timepicker/ClockHandView.java b/lib/java/com/google/android/material/timepicker/ClockHandView.java index 9834c4c8c32..af3aa88061c 100644 --- a/lib/java/com/google/android/material/timepicker/ClockHandView.java +++ b/lib/java/com/google/android/material/timepicker/ClockHandView.java @@ -42,7 +42,6 @@ import androidx.annotation.FloatRange; import androidx.annotation.Nullable; import androidx.annotation.Px; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; import com.google.android.material.internal.ViewUtils; import com.google.android.material.math.MathUtils; @@ -132,7 +131,7 @@ public ClockHandView(Context context, @Nullable AttributeSet attrs, int defStyle setHandRotation(0); scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); - ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); a.recycle(); } diff --git a/lib/java/com/google/android/material/timepicker/RadialViewGroup.java b/lib/java/com/google/android/material/timepicker/RadialViewGroup.java index d57db004012..4947f070a86 100644 --- a/lib/java/com/google/android/material/timepicker/RadialViewGroup.java +++ b/lib/java/com/google/android/material/timepicker/RadialViewGroup.java @@ -35,7 +35,6 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; -import androidx.core.view.ViewCompat; import com.google.android.material.shape.MaterialShapeDrawable; import com.google.android.material.shape.RelativeCornerSize; import java.lang.annotation.Retention; @@ -80,7 +79,7 @@ public RadialViewGroup(@NonNull Context context, @Nullable AttributeSet attrs) { public RadialViewGroup(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater.from(context).inflate(R.layout.material_radial_view_group, this); - ViewCompat.setBackground(this, createBackground()); + setBackground(createBackground()); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialViewGroup, defStyleAttr, 0); @@ -106,7 +105,7 @@ public void setBackgroundColor(@ColorInt int color) { public void addView(View child, int index, ViewGroup.LayoutParams params) { super.addView(child, index, params); if (child.getId() == NO_ID) { - child.setId(ViewCompat.generateViewId()); + child.setId(View.generateViewId()); } updateLayoutParamsAsync(); } diff --git a/lib/java/com/google/android/material/timepicker/TimePickerView.java b/lib/java/com/google/android/material/timepicker/TimePickerView.java index 8cfd2212213..7bf914d742d 100644 --- a/lib/java/com/google/android/material/timepicker/TimePickerView.java +++ b/lib/java/com/google/android/material/timepicker/TimePickerView.java @@ -224,11 +224,9 @@ public void setActiveSelection(@ActiveSelection int selection) { private void updateSelection(Chip chip, boolean isSelected) { chip.setChecked(isSelected); - ViewCompat.setAccessibilityLiveRegion( - chip, - isSelected - ? ViewCompat.ACCESSIBILITY_LIVE_REGION_ASSERTIVE - : ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE); + chip.setAccessibilityLiveRegion(isSelected + ? View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE + : View.ACCESSIBILITY_LIVE_REGION_NONE); } public void addOnRotateListener(OnRotateListener onRotateListener) { diff --git a/lib/java/com/google/android/material/transformation/ExpandableBehavior.java b/lib/java/com/google/android/material/transformation/ExpandableBehavior.java index aa312ecfd97..904405bdd23 100644 --- a/lib/java/com/google/android/material/transformation/ExpandableBehavior.java +++ b/lib/java/com/google/android/material/transformation/ExpandableBehavior.java @@ -26,7 +26,6 @@ import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior; -import androidx.core.view.ViewCompat; import com.google.android.material.expandable.ExpandableWidget; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -95,7 +94,7 @@ protected abstract boolean onExpandedStateChange( @Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull final View child, int layoutDirection) { - if (!ViewCompat.isLaidOut(child)) { + if (!child.isLaidOut()) { final ExpandableWidget dep = findExpandableWidget(parent, child); if (dep != null && didStateChange(dep.isExpanded())) { currentState = dep.isExpanded() ? STATE_EXPANDED : STATE_COLLAPSED; diff --git a/lib/java/com/google/android/material/transformation/FabTransformationSheetBehavior.java b/lib/java/com/google/android/material/transformation/FabTransformationSheetBehavior.java index 1ee24d45c50..2a190cae716 100644 --- a/lib/java/com/google/android/material/transformation/FabTransformationSheetBehavior.java +++ b/lib/java/com/google/android/material/transformation/FabTransformationSheetBehavior.java @@ -27,7 +27,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.view.ViewCompat; import com.google.android.material.animation.MotionSpec; import com.google.android.material.animation.Positioning; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -107,14 +106,13 @@ private void updateImportantForAccessibility(@NonNull View sheet, boolean expand if (importantForAccessibilityMap != null && importantForAccessibilityMap.containsKey(child)) { // Restores the original important for accessibility value of the child view. - ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child)); + child.setImportantForAccessibility(importantForAccessibilityMap.get(child)); } } else { // Saves the important for accessibility value of the child view. importantForAccessibilityMap.put(child, child.getImportantForAccessibility()); - ViewCompat.setImportantForAccessibility( - child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); + child.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); } } diff --git a/lib/java/com/google/android/material/transition/MaterialContainerTransform.java b/lib/java/com/google/android/material/transition/MaterialContainerTransform.java index fdf409db4f1..24808be4f7b 100644 --- a/lib/java/com/google/android/material/transition/MaterialContainerTransform.java +++ b/lib/java/com/google/android/material/transition/MaterialContainerTransform.java @@ -826,7 +826,7 @@ private static void captureValues( } View view = transitionValues.view; - if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) { + if (view.isLaidOut() || view.getWidth() != 0 || view.getHeight() != 0) { // Capture location in screen co-ordinates RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationInWindow(view); transitionValues.values.put(PROP_BOUNDS, bounds); diff --git a/lib/java/com/google/android/material/transition/SlideDistanceProvider.java b/lib/java/com/google/android/material/transition/SlideDistanceProvider.java index d76619c5e3d..fe4ec02be13 100644 --- a/lib/java/com/google/android/material/transition/SlideDistanceProvider.java +++ b/lib/java/com/google/android/material/transition/SlideDistanceProvider.java @@ -33,7 +33,6 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.annotation.RestrictTo; -import androidx.core.view.ViewCompat; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -223,6 +222,6 @@ public void onAnimationEnd(Animator animation) { } private static boolean isRtl(View view) { - return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } } diff --git a/lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java b/lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java index f37828f9aac..bca073065f9 100644 --- a/lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java +++ b/lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java @@ -831,7 +831,7 @@ private static void captureValues( } View view = transitionValues.view; - if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) { + if (view.isLaidOut() || view.getWidth() != 0 || view.getHeight() != 0) { // Capture location in screen co-ordinates RectF bounds = view.getParent() == null ? getRelativeBounds(view) : getLocationInWindow(view); transitionValues.values.put(PROP_BOUNDS, bounds); diff --git a/lib/java/com/google/android/material/transition/platform/SlideDistanceProvider.java b/lib/java/com/google/android/material/transition/platform/SlideDistanceProvider.java index f4c0683957a..8ea8dcf25bd 100644 --- a/lib/java/com/google/android/material/transition/platform/SlideDistanceProvider.java +++ b/lib/java/com/google/android/material/transition/platform/SlideDistanceProvider.java @@ -37,7 +37,6 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.annotation.RestrictTo; -import androidx.core.view.ViewCompat; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -228,6 +227,6 @@ public void onAnimationEnd(Animator animation) { } private static boolean isRtl(View view) { - return ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL; + return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } } diff --git a/lib/javatests/com/google/android/material/appbar/AppBarLayoutTest.java b/lib/javatests/com/google/android/material/appbar/AppBarLayoutTest.java index e923b8776ad..e9f45f677a1 100644 --- a/lib/javatests/com/google/android/material/appbar/AppBarLayoutTest.java +++ b/lib/javatests/com/google/android/material/appbar/AppBarLayoutTest.java @@ -24,7 +24,6 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.view.View; -import androidx.core.view.ViewCompat; import com.google.android.material.appbar.AppBarLayout.LayoutParams; import org.junit.Before; import org.junit.Test; @@ -198,13 +197,13 @@ public void testSetScrollEffectCompress() { private static int getChildScrollRange(View child) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); return getChildFullHeight(child, lp) - - (isExitUntilCollapsed(lp) ? ViewCompat.getMinimumHeight(child) : 0); + - (isExitUntilCollapsed(lp) ? child.getMinimumHeight() : 0); } private static int getChildDownNestedPreScrollRange(View child) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isEnterAlwaysCollapsed(lp)) { - return ViewCompat.getMinimumHeight(child) + lp.topMargin + lp.bottomMargin; + return child.getMinimumHeight() + lp.topMargin + lp.bottomMargin; } return getChildScrollRange(child); } diff --git a/lib/javatests/com/google/android/material/bottomsheet/BottomSheetDragHandleTest.java b/lib/javatests/com/google/android/material/bottomsheet/BottomSheetDragHandleTest.java index 6ff2ce7b222..0df20bf7f40 100644 --- a/lib/javatests/com/google/android/material/bottomsheet/BottomSheetDragHandleTest.java +++ b/lib/javatests/com/google/android/material/bottomsheet/BottomSheetDragHandleTest.java @@ -35,7 +35,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat; import androidx.test.core.app.ApplicationProvider; import androidx.test.platform.app.InstrumentationRegistry; @@ -209,7 +208,7 @@ public void test_customActionExpand() { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - ViewCompat.performAccessibilityAction(dragHandleView, ACTION_EXPAND.getId(), /* args= */ null); + dragHandleView.performAccessibilityAction(ACTION_EXPAND.getId(), /* args= */ null); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); @@ -226,8 +225,7 @@ public void test_customActionHalfExpand() { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - ViewCompat.performAccessibilityAction( - dragHandleView, getHalfExpandActionId(), /* args= */ null); + dragHandleView.performAccessibilityAction(getHalfExpandActionId(), /* args= */ null); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); @@ -243,8 +241,7 @@ public void test_customActionCollapse() { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - ViewCompat.performAccessibilityAction( - dragHandleView, ACTION_COLLAPSE.getId(), /* args= */ null); + dragHandleView.performAccessibilityAction(ACTION_COLLAPSE.getId(), /* args= */ null); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); @@ -261,7 +258,7 @@ public void test_customActionDismiss() { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - ViewCompat.performAccessibilityAction(dragHandleView, ACTION_DISMISS.getId(), /* args= */ null); + dragHandleView.performAccessibilityAction(ACTION_DISMISS.getId(), /* args= */ null); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); @@ -337,11 +334,11 @@ private int getHalfExpandActionId() { private void assertImportantForAccessibility(boolean important) { if (important) { - assertThat(ViewCompat.getImportantForAccessibility(dragHandleView)) - .isEqualTo(ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); + assertThat(dragHandleView.getImportantForAccessibility()) + .isEqualTo(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } else { - assertThat(ViewCompat.getImportantForAccessibility(dragHandleView)) - .isEqualTo(ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); + assertThat(dragHandleView.getImportantForAccessibility()) + .isEqualTo(View.IMPORTANT_FOR_ACCESSIBILITY_NO); } } diff --git a/lib/javatests/com/google/android/material/button/MaterialButtonToggleGroupTest.java b/lib/javatests/com/google/android/material/button/MaterialButtonToggleGroupTest.java index fd0be4c3123..9b661da3825 100644 --- a/lib/javatests/com/google/android/material/button/MaterialButtonToggleGroupTest.java +++ b/lib/javatests/com/google/android/material/button/MaterialButtonToggleGroupTest.java @@ -27,14 +27,11 @@ import android.content.Context; import android.graphics.RectF; import android.view.View; +import android.view.accessibility.AccessibilityNodeInfo; import android.widget.Checkable; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.ToggleButton; -import androidx.core.view.ViewCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionItemInfoCompat; import androidx.test.core.app.ApplicationProvider; import com.google.android.material.button.MaterialButtonToggleGroup.OnButtonCheckedListener; import com.google.android.material.shape.ShapeAppearanceModel; @@ -202,19 +199,19 @@ private static void assertShapeAppearance( @Test @Config(sdk = 23) public void onInitializeAccessibilityNodeInfo() { - AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(toggleGroup, groupInfoCompat); + AccessibilityNodeInfo groupInfo = AccessibilityNodeInfo.obtain(); + toggleGroup.onInitializeAccessibilityNodeInfo(groupInfo); - CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); + AccessibilityNodeInfo.CollectionInfo collectionInfo = groupInfo.getCollectionInfo(); assertEquals(3, collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); MaterialButton secondChild = (MaterialButton) toggleGroup.getChildAt(1); secondChild.setChecked(true); - AccessibilityNodeInfoCompat buttonInfoCompat = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, buttonInfoCompat); + AccessibilityNodeInfo buttonInfo = AccessibilityNodeInfo.obtain(); + secondChild.onInitializeAccessibilityNodeInfo(buttonInfo); - CollectionItemInfoCompat itemInfo = buttonInfoCompat.getCollectionItemInfo(); + AccessibilityNodeInfo.CollectionItemInfo itemInfo = buttonInfo.getCollectionItemInfo(); assertEquals(1, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); @@ -262,11 +259,11 @@ public void singleSelection_doesNotMultiSelect_programmatically() { toggleGroup.setSingleSelection(true); View button1 = toggleGroup.getChildAt(0); - int id1 = ViewCompat.generateViewId(); + int id1 = View.generateViewId(); button1.setId(id1); View button2 = toggleGroup.getChildAt(1); - int id2 = ViewCompat.generateViewId(); + int id2 = View.generateViewId(); button2.setId(id2); toggleGroup.check(id1); @@ -281,11 +278,11 @@ public void multiSelection_correctSelectedIds() { toggleGroup.setSingleSelection(false); View button1 = toggleGroup.getChildAt(0); - int id1 = ViewCompat.generateViewId(); + int id1 = View.generateViewId(); button1.setId(id1); View button2 = toggleGroup.getChildAt(1); - int id2 = ViewCompat.generateViewId(); + int id2 = View.generateViewId(); button2.setId(id2); toggleGroup.check(id1); @@ -330,7 +327,7 @@ private int singleSelection_withSelectedRequired_setup() { toggleGroup.setSelectionRequired(true); View child = toggleGroup.getChildAt(1); - int id = ViewCompat.generateViewId(); + int id = View.generateViewId(); child.setId(id); return id; } diff --git a/lib/javatests/com/google/android/material/chip/ChipGroupTest.java b/lib/javatests/com/google/android/material/chip/ChipGroupTest.java index 43f01882dca..3a518ba348e 100644 --- a/lib/javatests/com/google/android/material/chip/ChipGroupTest.java +++ b/lib/javatests/com/google/android/material/chip/ChipGroupTest.java @@ -27,11 +27,8 @@ import android.content.Context; import androidx.appcompat.app.AppCompatActivity; import android.view.View; +import android.view.accessibility.AccessibilityNodeInfo; import android.widget.CompoundButton; -import androidx.core.view.ViewCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat; -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionItemInfoCompat; import androidx.test.core.app.ApplicationProvider; import com.google.android.material.chip.ChipGroup.OnCheckedStateChangeListener; import java.util.List; @@ -244,22 +241,21 @@ public void multiSelection_withSelectionRequired_unSelectsIfTwo() { @Config(minSdk = 23, maxSdk = 28) public void isSingleLine_initializesAccessibilityNodeInfo() { chipgroup.setSingleLine(true); - AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); + AccessibilityNodeInfo groupInfo = AccessibilityNodeInfo.obtain(); // onLayout must be triggered for rowCount chipgroup.layout(0, 0, 100, 100); + chipgroup.onInitializeAccessibilityNodeInfo(groupInfo); - ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); - - CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); + AccessibilityNodeInfo.CollectionInfo collectionInfo = groupInfo.getCollectionInfo(); assertEquals(chipgroup.getChildCount(), collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); Chip secondChild = (Chip) chipgroup.getChildAt(1); secondChild.setChecked(true); - AccessibilityNodeInfoCompat chipInfoCompat = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, chipInfoCompat); + AccessibilityNodeInfo chipInfo = AccessibilityNodeInfo.obtain(); + secondChild.onInitializeAccessibilityNodeInfo(chipInfo); - CollectionItemInfoCompat itemInfo = chipInfoCompat.getCollectionItemInfo(); + AccessibilityNodeInfo.CollectionItemInfo itemInfo = chipInfo.getCollectionItemInfo(); assertEquals(1, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); @@ -270,13 +266,12 @@ public void isSingleLine_initializesAccessibilityNodeInfo() { @Config(minSdk = 23, maxSdk = 28) public void isSingleLine_initializesAccessibilityNodeInfo_invisibleChip() { chipgroup.setSingleLine(true); - AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); + AccessibilityNodeInfo groupInfo = AccessibilityNodeInfo.obtain(); // onLayout must be triggered for rowCount chipgroup.layout(0, 0, 100, 100); + chipgroup.onInitializeAccessibilityNodeInfo(groupInfo); - ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); - - CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); + AccessibilityNodeInfo.CollectionInfo collectionInfo = groupInfo.getCollectionInfo(); assertEquals(chipgroup.getChildCount(), collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); @@ -285,38 +280,38 @@ public void isSingleLine_initializesAccessibilityNodeInfo_invisibleChip() { Chip secondChild = (Chip) chipgroup.getChildAt(1); secondChild.setVisibility(GONE); Chip thirdChild = (Chip) chipgroup.getChildAt(2); - AccessibilityNodeInfoCompat chipInfoCompat = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(thirdChild, chipInfoCompat); + AccessibilityNodeInfo chipInfo = AccessibilityNodeInfo.obtain(); + thirdChild.onInitializeAccessibilityNodeInfo(chipInfo); - CollectionItemInfoCompat itemInfo = chipInfoCompat.getCollectionItemInfo(); + AccessibilityNodeInfo.CollectionItemInfo itemInfo = chipInfo.getCollectionItemInfo(); assertEquals(0, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertEquals(-1, chipgroup.getIndexOfChip(firstChild)); assertEquals(-1, chipgroup.getIndexOfChip(secondChild)); assertEquals(0, chipgroup.getIndexOfChip(thirdChild)); - ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); - assertEquals(1, groupInfoCompat.getCollectionInfo().getColumnCount()); + chipgroup.onInitializeAccessibilityNodeInfo(groupInfo); + assertEquals(1, groupInfo.getCollectionInfo().getColumnCount()); } @Test @Config(minSdk = 23, maxSdk = 28) public void isNotSingleLine_initializesAccessibilityNodeInfo() { - AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); + AccessibilityNodeInfo groupInfo = AccessibilityNodeInfo.obtain(); // onLayout must be triggered for rowCount chipgroup.layout(0, 0, 10, 100); - ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); + chipgroup.onInitializeAccessibilityNodeInfo(groupInfo); - CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); + AccessibilityNodeInfo.CollectionInfo collectionInfo = groupInfo.getCollectionInfo(); assertEquals(-1, collectionInfo.getColumnCount()); assertEquals(2, collectionInfo.getRowCount()); Chip secondChild = (Chip) chipgroup.getChildAt(2); secondChild.setChecked(true); - AccessibilityNodeInfoCompat chipInfoCompat = AccessibilityNodeInfoCompat.obtain(); - ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, chipInfoCompat); + AccessibilityNodeInfo chipInfo = AccessibilityNodeInfo.obtain(); + secondChild.onInitializeAccessibilityNodeInfo(chipInfo); - CollectionItemInfoCompat itemInfo = chipInfoCompat.getCollectionItemInfo(); + AccessibilityNodeInfo.CollectionItemInfo itemInfo = chipInfo.getCollectionItemInfo(); assertEquals(-1, itemInfo.getColumnIndex()); assertEquals(1, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); diff --git a/lib/javatests/com/google/android/material/sidesheet/SideSheetCallbackTest.java b/lib/javatests/com/google/android/material/sidesheet/SideSheetCallbackTest.java index 6f2a61de0a5..20d2554ddfc 100644 --- a/lib/javatests/com/google/android/material/sidesheet/SideSheetCallbackTest.java +++ b/lib/javatests/com/google/android/material/sidesheet/SideSheetCallbackTest.java @@ -29,7 +29,6 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.view.ViewCompat; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -65,7 +64,7 @@ public void test_setSheetRedOnExpandWithCallback_sheetIsRedOnExpand() { @Override public void onStateChanged(@NonNull View sheet, int newState) { if (newState == SideSheetBehavior.STATE_EXPANDED) { - ViewCompat.setBackground(sideSheet, new ColorDrawable(RED)); + sideSheet.setBackground(new ColorDrawable(RED)); } } @@ -85,7 +84,7 @@ public void onSlide(@NonNull View sheet, float slideOffset) {} public void test_removeCallback_callbackIsRemoved() { SideSheetCallback sideSheetCallback = createExpandedRedSideSheetCallback(); // Ensure that side sheet doesn't already have a background. - ViewCompat.setBackground(sideSheet, null); + sideSheet.setBackground(null); sideSheetBehavior.addCallback(sideSheetCallback); sideSheetBehavior.removeCallback(sideSheetCallback); @@ -102,7 +101,7 @@ private SideSheetCallback createExpandedRedSideSheetCallback() { @Override public void onStateChanged(@NonNull View sheet, int newState) { if (newState == SideSheetBehavior.STATE_EXPANDED) { - ViewCompat.setBackground(sideSheet, new ColorDrawable(RED)); + sideSheet.setBackground(new ColorDrawable(RED)); } } diff --git a/lib/javatests/com/google/android/material/slider/SliderHelper.java b/lib/javatests/com/google/android/material/slider/SliderHelper.java index b1cd1579b70..29ebfde74b4 100644 --- a/lib/javatests/com/google/android/material/slider/SliderHelper.java +++ b/lib/javatests/com/google/android/material/slider/SliderHelper.java @@ -24,9 +24,9 @@ import android.os.SystemClock; import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.View; import android.widget.LinearLayout; import androidx.annotation.FloatRange; -import androidx.core.view.ViewCompat; import com.google.android.material.slider.KeyUtils.KeyEventBuilder; public class SliderHelper { @@ -129,7 +129,7 @@ static void touchSliderBetweenValues( static float calculateXPositionFromValue(BaseSlider s, float value) { float x = (value - s.getValueFrom()) * s.getTrackWidth() / (s.getValueTo() - s.getValueFrom()); - if (ViewCompat.getLayoutDirection(s) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (s.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { x = s.getTrackWidth() - x; } return s.getTrackSidePadding() + x; diff --git a/lib/javatests/com/google/android/material/slider/SliderStateTest.java b/lib/javatests/com/google/android/material/slider/SliderStateTest.java index 49493b1637a..0470e0b2f38 100644 --- a/lib/javatests/com/google/android/material/slider/SliderStateTest.java +++ b/lib/javatests/com/google/android/material/slider/SliderStateTest.java @@ -23,8 +23,8 @@ import android.os.Bundle; import android.os.Parcel; import androidx.appcompat.app.AppCompatActivity; +import android.view.View; import android.view.ViewGroup; -import androidx.core.view.ViewCompat; import androidx.test.core.app.ApplicationProvider; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,7 +58,7 @@ public void testValues() { private Slider addSlider(ActivityController controller) { Slider slider = new Slider(controller.get()); - slider.setId(ViewCompat.generateViewId()); + slider.setId(View.generateViewId()); ViewGroup content = controller.get().findViewById(android.R.id.content); content.addView(slider); return slider;