package androidx.cardview.widget; import android.R; 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.os.Build; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import androidx.cardview.R$attr; import androidx.cardview.R$color; import androidx.cardview.R$style; import androidx.cardview.R$styleable; /* loaded from: classes.dex */ public class CardView extends FrameLayout { private static final int[] h = {R.attr.colorBackground}; private static final CardViewImpl i; private boolean a; private boolean b; int c; int d; final Rect e; final Rect f; private final CardViewDelegate g; static { int i2 = Build.VERSION.SDK_INT; if (i2 >= 21) { i = new CardViewApi21Impl(); } else if (i2 >= 17) { i = new CardViewApi17Impl(); } else { i = new CardViewBaseImpl(); } i.a(); } public CardView(Context context) { this(context, null); } public ColorStateList getCardBackgroundColor() { return i.e(this.g); } public float getCardElevation() { return i.a(this.g); } public int getContentPaddingBottom() { return this.e.bottom; } public int getContentPaddingLeft() { return this.e.left; } public int getContentPaddingRight() { return this.e.right; } public int getContentPaddingTop() { return this.e.top; } public float getMaxCardElevation() { return i.d(this.g); } public boolean getPreventCornerOverlap() { return this.b; } public float getRadius() { return i.b(this.g); } public boolean getUseCompatPadding() { return this.a; } @Override // android.widget.FrameLayout, android.view.View protected void onMeasure(int i2, int i3) { if (i instanceof CardViewApi21Impl) { super.onMeasure(i2, i3); return; } int mode = View.MeasureSpec.getMode(i2); if (mode == Integer.MIN_VALUE || mode == 1073741824) { i2 = View.MeasureSpec.makeMeasureSpec(Math.max((int) Math.ceil(i.g(this.g)), View.MeasureSpec.getSize(i2)), mode); } int mode2 = View.MeasureSpec.getMode(i3); if (mode2 == Integer.MIN_VALUE || mode2 == 1073741824) { i3 = View.MeasureSpec.makeMeasureSpec(Math.max((int) Math.ceil(i.f(this.g)), View.MeasureSpec.getSize(i3)), mode2); } super.onMeasure(i2, i3); } public void setCardBackgroundColor(int i2) { i.a(this.g, ColorStateList.valueOf(i2)); } public void setCardElevation(float f) { i.b(this.g, f); } public void setMaxCardElevation(float f) { i.c(this.g, f); } @Override // android.view.View public void setMinimumHeight(int i2) { this.d = i2; super.setMinimumHeight(i2); } @Override // android.view.View public void setMinimumWidth(int i2) { this.c = i2; super.setMinimumWidth(i2); } @Override // android.view.View public void setPadding(int i2, int i3, int i4, int i5) { } @Override // android.view.View public void setPaddingRelative(int i2, int i3, int i4, int i5) { } public void setPreventCornerOverlap(boolean z) { if (z != this.b) { this.b = z; i.h(this.g); } } public void setRadius(float f) { i.a(this.g, f); } public void setUseCompatPadding(boolean z) { if (this.a != z) { this.a = z; i.c(this.g); } } public CardView(Context context, AttributeSet attributeSet) { this(context, attributeSet, R$attr.cardViewStyle); } public void setCardBackgroundColor(ColorStateList colorStateList) { i.a(this.g, colorStateList); } public CardView(Context context, AttributeSet attributeSet, int i2) { super(context, attributeSet, i2); int color; ColorStateList valueOf; this.e = new Rect(); this.f = new Rect(); this.g = new CardViewDelegate() { // from class: androidx.cardview.widget.CardView.1 private Drawable a; @Override // androidx.cardview.widget.CardViewDelegate public void a(Drawable drawable) { this.a = drawable; CardView.this.setBackgroundDrawable(drawable); } @Override // androidx.cardview.widget.CardViewDelegate public boolean b() { return CardView.this.getUseCompatPadding(); } @Override // androidx.cardview.widget.CardViewDelegate public Drawable c() { return this.a; } @Override // androidx.cardview.widget.CardViewDelegate public View d() { return CardView.this; } @Override // androidx.cardview.widget.CardViewDelegate public boolean a() { return CardView.this.getPreventCornerOverlap(); } @Override // androidx.cardview.widget.CardViewDelegate public void a(int i3, int i4, int i5, int i6) { CardView.this.f.set(i3, i4, i5, i6); CardView cardView = CardView.this; Rect rect = cardView.e; CardView.super.setPadding(i3 + rect.left, i4 + rect.top, i5 + rect.right, i6 + rect.bottom); } @Override // androidx.cardview.widget.CardViewDelegate public void a(int i3, int i4) { CardView cardView = CardView.this; if (i3 > cardView.c) { CardView.super.setMinimumWidth(i3); } CardView cardView2 = CardView.this; if (i4 > cardView2.d) { CardView.super.setMinimumHeight(i4); } } }; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.CardView, i2, R$style.CardView); if (obtainStyledAttributes.hasValue(R$styleable.CardView_cardBackgroundColor)) { valueOf = obtainStyledAttributes.getColorStateList(R$styleable.CardView_cardBackgroundColor); } else { TypedArray obtainStyledAttributes2 = getContext().obtainStyledAttributes(h); int color2 = obtainStyledAttributes2.getColor(0, 0); obtainStyledAttributes2.recycle(); float[] fArr = new float[3]; Color.colorToHSV(color2, fArr); if (fArr[2] > 0.5f) { color = getResources().getColor(R$color.cardview_light_background); } else { color = getResources().getColor(R$color.cardview_dark_background); } valueOf = ColorStateList.valueOf(color); } ColorStateList colorStateList = valueOf; 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.a = obtainStyledAttributes.getBoolean(R$styleable.CardView_cardUseCompatPadding, false); this.b = obtainStyledAttributes.getBoolean(R$styleable.CardView_cardPreventCornerOverlap, true); int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_contentPadding, 0); this.e.left = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_contentPaddingLeft, dimensionPixelSize); this.e.top = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_contentPaddingTop, dimensionPixelSize); this.e.right = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_contentPaddingRight, dimensionPixelSize); this.e.bottom = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_contentPaddingBottom, dimensionPixelSize); float f = dimension2 > dimension3 ? dimension2 : dimension3; this.c = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_android_minWidth, 0); this.d = obtainStyledAttributes.getDimensionPixelSize(R$styleable.CardView_android_minHeight, 0); obtainStyledAttributes.recycle(); i.a(this.g, context, colorStateList, dimension, dimension2, f); } }