Skip to content

Commit

Permalink
[Internal] Stop using deprecated androidx.core.view.* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pubiqq committed Apr 24, 2024
1 parent cc125d9 commit 5758dba
Show file tree
Hide file tree
Showing 88 changed files with 369 additions and 506 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -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);

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +80,7 @@ public View onCreateDemoView(

for (FloatingActionButton fab : fabs) {
fab.setRotation(0);
ViewCompat.animate(fab)
fab.animate()
.rotation(360)
.withLayer()
.setDuration(1000)
Expand Down
Expand Up @@ -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();
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
64 changes: 32 additions & 32 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Expand Up @@ -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);
Expand Down Expand Up @@ -353,7 +353,8 @@ private void initializeLiftOnScrollWithColor(
}
}
};
ViewCompat.setBackground(this, background);

setBackground(background);
}

private void initializeLiftOnScrollWithElevation(
Expand All @@ -369,7 +370,8 @@ private void initializeLiftOnScrollWithElevation(
liftOnScrollListener.onUpdate(elevation, background.getResolvedTintColor());
}
};
ViewCompat.setBackground(this, background);

setBackground(background);
}

/**
Expand Down Expand Up @@ -451,12 +453,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();
}
}

Expand Down Expand Up @@ -557,9 +559,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:
Expand All @@ -585,7 +585,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--) {
Expand Down Expand Up @@ -705,7 +705,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());
}

/**
Expand Down Expand Up @@ -792,7 +792,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();
Expand All @@ -801,7 +801,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 {
Expand Down Expand Up @@ -846,15 +846,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());
Expand Down Expand Up @@ -897,7 +897,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 {
Expand All @@ -913,7 +913,7 @@ void onOffsetChanged(int offset) {
currentOffset = offset;

if (!willNotDraw()) {
ViewCompat.postInvalidateOnAnimation(this);
postInvalidateOnAnimation();
}

// Iterate backwards through the list so that most recently added listeners
Expand All @@ -930,7 +930,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;
Expand All @@ -939,7 +939,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;
}
Expand Down Expand Up @@ -1189,15 +1189,15 @@ 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;
}

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;
}
Expand Down Expand Up @@ -1733,19 +1733,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 {
Expand Down Expand Up @@ -1827,7 +1827,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);
}
Expand Down Expand Up @@ -2126,11 +2126,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();
}

Expand Down Expand Up @@ -2168,7 +2168,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
Expand Down Expand Up @@ -2292,7 +2292,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;
}
Expand Down Expand Up @@ -2585,10 +2585,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);
}
Expand Down

0 comments on commit 5758dba

Please sign in to comment.