267 lines
10 KiB
Java
267 lines
10 KiB
Java
|
package androidx.cardview.widget;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.res.ColorStateList;
|
||
|
import android.content.res.TypedArray;
|
||
|
import android.graphics.Color;
|
||
|
import android.graphics.Rect;
|
||
|
import android.graphics.drawable.Drawable;
|
||
|
import android.util.AttributeSet;
|
||
|
import android.view.View;
|
||
|
import android.widget.FrameLayout;
|
||
|
import androidx.annotation.ColorInt;
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.annotation.Nullable;
|
||
|
import androidx.annotation.Px;
|
||
|
import androidx.cardview.R;
|
||
|
public class CardView extends FrameLayout {
|
||
|
private static final int[] COLOR_BACKGROUND_ATTR = {16842801};
|
||
|
private static final CardViewImpl IMPL;
|
||
|
private final CardViewDelegate mCardViewDelegate;
|
||
|
private boolean mCompatPadding;
|
||
|
public final Rect mContentPadding;
|
||
|
private boolean mPreventCornerOverlap;
|
||
|
public final Rect mShadowBounds;
|
||
|
public int mUserSetMinHeight;
|
||
|
public int mUserSetMinWidth;
|
||
|
|
||
|
/* renamed from: androidx.cardview.widget.CardView$1 reason: invalid class name */
|
||
|
public class AnonymousClass1 implements CardViewDelegate {
|
||
|
private Drawable mCardBackground;
|
||
|
|
||
|
public AnonymousClass1() {
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public Drawable getCardBackground() {
|
||
|
return this.mCardBackground;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public View getCardView() {
|
||
|
return CardView.this;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public boolean getPreventCornerOverlap() {
|
||
|
return CardView.this.getPreventCornerOverlap();
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public boolean getUseCompatPadding() {
|
||
|
return CardView.this.getUseCompatPadding();
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public void setCardBackground(Drawable drawable) {
|
||
|
this.mCardBackground = drawable;
|
||
|
CardView.this.setBackgroundDrawable(drawable);
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public void setMinWidthHeightInternal(int i, int i2) {
|
||
|
CardView cardView = CardView.this;
|
||
|
if (i > cardView.mUserSetMinWidth) {
|
||
|
CardView.access$101(cardView, i);
|
||
|
}
|
||
|
CardView cardView2 = CardView.this;
|
||
|
if (i2 > cardView2.mUserSetMinHeight) {
|
||
|
CardView.access$201(cardView2, i2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // androidx.cardview.widget.CardViewDelegate
|
||
|
public void setShadowPadding(int i, int i2, int i3, int i4) {
|
||
|
CardView.this.mShadowBounds.set(i, i2, i3, i4);
|
||
|
CardView cardView = CardView.this;
|
||
|
Rect rect = cardView.mContentPadding;
|
||
|
CardView.access$001(cardView, i + rect.left, i2 + rect.top, i3 + rect.right, i4 + rect.bottom);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static {
|
||
|
CardViewApi21Impl cardViewApi21Impl = new CardViewApi21Impl();
|
||
|
IMPL = cardViewApi21Impl;
|
||
|
cardViewApi21Impl.initStatic();
|
||
|
}
|
||
|
|
||
|
public CardView(@NonNull Context context) {
|
||
|
this(context, null);
|
||
|
}
|
||
|
|
||
|
public CardView(@NonNull Context context, @Nullable AttributeSet attributeSet) {
|
||
|
this(context, attributeSet, R.attr.cardViewStyle);
|
||
|
}
|
||
|
|
||
|
public CardView(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) {
|
||
|
super(context, attributeSet, i);
|
||
|
ColorStateList valueOf;
|
||
|
Rect rect = new Rect();
|
||
|
this.mContentPadding = rect;
|
||
|
this.mShadowBounds = new Rect();
|
||
|
AnonymousClass1 r3 = new AnonymousClass1();
|
||
|
this.mCardViewDelegate = r3;
|
||
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.CardView, i, R.style.CardView);
|
||
|
int i2 = R.styleable.CardView_cardBackgroundColor;
|
||
|
if (obtainStyledAttributes.hasValue(i2)) {
|
||
|
valueOf = obtainStyledAttributes.getColorStateList(i2);
|
||
|
} else {
|
||
|
TypedArray obtainStyledAttributes2 = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR);
|
||
|
int color = obtainStyledAttributes2.getColor(0, 0);
|
||
|
obtainStyledAttributes2.recycle();
|
||
|
float[] fArr = new float[3];
|
||
|
Color.colorToHSV(color, fArr);
|
||
|
valueOf = ColorStateList.valueOf(fArr[2] > 0.5f ? getResources().getColor(R.color.cardview_light_background) : getResources().getColor(R.color.cardview_dark_background));
|
||
|
}
|
||
|
float dimension = obtainStyledAttributes.getDimension(R.styleable.CardView_cardCornerRadius, 0.0f);
|
||
|
float dimension2 = obtainStyledAttributes.getDimension(R.styleable.CardView_cardElevation, 0.0f);
|
||
|
float dimension3 = obtainStyledAttributes.getDimension(R.styleable.CardView_cardMaxElevation, 0.0f);
|
||
|
this.mCompatPadding = obtainStyledAttributes.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
|
||
|
this.mPreventCornerOverlap = obtainStyledAttributes.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
|
||
|
int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
|
||
|
rect.left = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, dimensionPixelSize);
|
||
|
rect.top = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, dimensionPixelSize);
|
||
|
rect.right = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, dimensionPixelSize);
|
||
|
rect.bottom = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, dimensionPixelSize);
|
||
|
float f = dimension2 > dimension3 ? dimension2 : dimension3;
|
||
|
this.mUserSetMinWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_android_minWidth, 0);
|
||
|
this.mUserSetMinHeight = obtainStyledAttributes.getDimensionPixelSize(R.styleable.CardView_android_minHeight, 0);
|
||
|
obtainStyledAttributes.recycle();
|
||
|
IMPL.initialize(r3, context, valueOf, dimension, dimension2, f);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void access$001(CardView cardView, int i, int i2, int i3, int i4) {
|
||
|
super.setPadding(i, i2, i3, i4);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void access$101(CardView cardView, int i) {
|
||
|
super.setMinimumWidth(i);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void access$201(CardView cardView, int i) {
|
||
|
super.setMinimumHeight(i);
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public ColorStateList getCardBackgroundColor() {
|
||
|
return IMPL.getBackgroundColor(this.mCardViewDelegate);
|
||
|
}
|
||
|
|
||
|
public float getCardElevation() {
|
||
|
return IMPL.getElevation(this.mCardViewDelegate);
|
||
|
}
|
||
|
|
||
|
@Px
|
||
|
public int getContentPaddingBottom() {
|
||
|
return this.mContentPadding.bottom;
|
||
|
}
|
||
|
|
||
|
@Px
|
||
|
public int getContentPaddingLeft() {
|
||
|
return this.mContentPadding.left;
|
||
|
}
|
||
|
|
||
|
@Px
|
||
|
public int getContentPaddingRight() {
|
||
|
return this.mContentPadding.right;
|
||
|
}
|
||
|
|
||
|
@Px
|
||
|
public int getContentPaddingTop() {
|
||
|
return this.mContentPadding.top;
|
||
|
}
|
||
|
|
||
|
public float getMaxCardElevation() {
|
||
|
return IMPL.getMaxElevation(this.mCardViewDelegate);
|
||
|
}
|
||
|
|
||
|
public boolean getPreventCornerOverlap() {
|
||
|
return this.mPreventCornerOverlap;
|
||
|
}
|
||
|
|
||
|
public float getRadius() {
|
||
|
return IMPL.getRadius(this.mCardViewDelegate);
|
||
|
}
|
||
|
|
||
|
public boolean getUseCompatPadding() {
|
||
|
return this.mCompatPadding;
|
||
|
}
|
||
|
|
||
|
@Override // android.widget.FrameLayout, android.view.View
|
||
|
public void onMeasure(int i, int i2) {
|
||
|
CardViewImpl cardViewImpl = IMPL;
|
||
|
if (!(cardViewImpl instanceof CardViewApi21Impl)) {
|
||
|
int mode = View.MeasureSpec.getMode(i);
|
||
|
if (mode == Integer.MIN_VALUE || mode == 1073741824) {
|
||
|
i = View.MeasureSpec.makeMeasureSpec(Math.max((int) Math.ceil((double) cardViewImpl.getMinWidth(this.mCardViewDelegate)), View.MeasureSpec.getSize(i)), mode);
|
||
|
}
|
||
|
int mode2 = View.MeasureSpec.getMode(i2);
|
||
|
if (mode2 == Integer.MIN_VALUE || mode2 == 1073741824) {
|
||
|
i2 = View.MeasureSpec.makeMeasureSpec(Math.max((int) Math.ceil((double) cardViewImpl.getMinHeight(this.mCardViewDelegate)), View.MeasureSpec.getSize(i2)), mode2);
|
||
|
}
|
||
|
super.onMeasure(i, i2);
|
||
|
return;
|
||
|
}
|
||
|
super.onMeasure(i, i2);
|
||
|
}
|
||
|
|
||
|
public void setCardBackgroundColor(@ColorInt int i) {
|
||
|
IMPL.setBackgroundColor(this.mCardViewDelegate, ColorStateList.valueOf(i));
|
||
|
}
|
||
|
|
||
|
public void setCardBackgroundColor(@Nullable ColorStateList colorStateList) {
|
||
|
IMPL.setBackgroundColor(this.mCardViewDelegate, colorStateList);
|
||
|
}
|
||
|
|
||
|
public void setCardElevation(float f) {
|
||
|
IMPL.setElevation(this.mCardViewDelegate, f);
|
||
|
}
|
||
|
|
||
|
public void setContentPadding(@Px int i, @Px int i2, @Px int i3, @Px int i4) {
|
||
|
this.mContentPadding.set(i, i2, i3, i4);
|
||
|
IMPL.updatePadding(this.mCardViewDelegate);
|
||
|
}
|
||
|
|
||
|
public void setMaxCardElevation(float f) {
|
||
|
IMPL.setMaxElevation(this.mCardViewDelegate, f);
|
||
|
}
|
||
|
|
||
|
@Override // android.view.View
|
||
|
public void setMinimumHeight(int i) {
|
||
|
this.mUserSetMinHeight = i;
|
||
|
super.setMinimumHeight(i);
|
||
|
}
|
||
|
|
||
|
@Override // android.view.View
|
||
|
public void setMinimumWidth(int i) {
|
||
|
this.mUserSetMinWidth = i;
|
||
|
super.setMinimumWidth(i);
|
||
|
}
|
||
|
|
||
|
@Override // android.view.View
|
||
|
public void setPadding(int i, int i2, int i3, int i4) {
|
||
|
}
|
||
|
|
||
|
@Override // android.view.View
|
||
|
public void setPaddingRelative(int i, int i2, int i3, int i4) {
|
||
|
}
|
||
|
|
||
|
public void setPreventCornerOverlap(boolean z2) {
|
||
|
if (z2 != this.mPreventCornerOverlap) {
|
||
|
this.mPreventCornerOverlap = z2;
|
||
|
IMPL.onPreventCornerOverlapChanged(this.mCardViewDelegate);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setRadius(float f) {
|
||
|
IMPL.setRadius(this.mCardViewDelegate, f);
|
||
|
}
|
||
|
|
||
|
public void setUseCompatPadding(boolean z2) {
|
||
|
if (this.mCompatPadding != z2) {
|
||
|
this.mCompatPadding = z2;
|
||
|
IMPL.onCompatPaddingChanged(this.mCardViewDelegate);
|
||
|
}
|
||
|
}
|
||
|
}
|