package com.google.android.material.imageview;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import com.google.android.material.shape.g0;
import com.google.android.material.shape.k;
import com.google.android.material.shape.s;
import com.google.android.material.shape.t;
import com.google.android.material.shape.w;
import g0.d;
import x8.l;
import x8.m;
import x9.a;

/* JADX INFO: loaded from: classes2.dex */
public class ShapeableImageView extends AppCompatImageView implements g0 {
    public static final int W = l.Widget_MaterialComponents_ShapeableImageView;
    public int Q;
    public int R;
    public int S;
    public int T;
    public int U;
    public boolean V;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final w f22651d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final RectF f22652e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final RectF f22653f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Paint f22654g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Paint f22655h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final Path f22656i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public s f22657j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public float f22658k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final Path f22659l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f22660m;

    @Nullable
    private k shadowDrawable;

    @Nullable
    private ColorStateList strokeColor;

    public ShapeableImageView(Context context) {
        this(context, null, 0);
    }

    public final boolean e() {
        return getLayoutDirection() == 1;
    }

    public final void f(int i10, int i11) {
        RectF rectF = this.f22652e;
        rectF.set(getPaddingLeft(), getPaddingTop(), i10 - getPaddingRight(), i11 - getPaddingBottom());
        s sVar = this.f22657j;
        Path path = this.f22656i;
        this.f22651d.calculatePath(sVar, null, 1.0f, rectF, null, path);
        Path path2 = this.f22659l;
        path2.rewind();
        path2.addPath(path);
        RectF rectF2 = this.f22653f;
        rectF2.set(0.0f, 0.0f, i10, i11);
        path2.addRect(rectF2, Path.Direction.CCW);
    }

    @Dimension
    public int getContentPaddingBottom() {
        return this.S;
    }

    @Dimension
    public final int getContentPaddingEnd() {
        int i10 = this.U;
        return i10 != Integer.MIN_VALUE ? i10 : e() ? this.f22660m : this.R;
    }

    @Dimension
    public int getContentPaddingLeft() {
        int i10;
        int i11;
        if (this.T != Integer.MIN_VALUE || this.U != Integer.MIN_VALUE) {
            if (e() && (i11 = this.U) != Integer.MIN_VALUE) {
                return i11;
            }
            if (!e() && (i10 = this.T) != Integer.MIN_VALUE) {
                return i10;
            }
        }
        return this.f22660m;
    }

    @Dimension
    public int getContentPaddingRight() {
        int i10;
        int i11;
        if (this.T != Integer.MIN_VALUE || this.U != Integer.MIN_VALUE) {
            if (e() && (i11 = this.T) != Integer.MIN_VALUE) {
                return i11;
            }
            if (!e() && (i10 = this.U) != Integer.MIN_VALUE) {
                return i10;
            }
        }
        return this.R;
    }

    @Dimension
    public final int getContentPaddingStart() {
        int i10 = this.T;
        return i10 != Integer.MIN_VALUE ? i10 : e() ? this.R : this.f22660m;
    }

    @Dimension
    public int getContentPaddingTop() {
        return this.Q;
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingBottom() {
        return super.getPaddingBottom() - getContentPaddingBottom();
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingEnd() {
        return super.getPaddingEnd() - getContentPaddingEnd();
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingLeft() {
        return super.getPaddingLeft() - getContentPaddingLeft();
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingRight() {
        return super.getPaddingRight() - getContentPaddingRight();
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingStart() {
        return super.getPaddingStart() - getContentPaddingStart();
    }

    @Override // android.view.View
    @Dimension
    public int getPaddingTop() {
        return super.getPaddingTop() - getContentPaddingTop();
    }

    @NonNull
    public s getShapeAppearanceModel() {
        return this.f22657j;
    }

    @Nullable
    public ColorStateList getStrokeColor() {
        return this.strokeColor;
    }

    @Dimension
    public float getStrokeWidth() {
        return this.f22658k;
    }

    @Override // android.widget.ImageView, android.view.View
    public final void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(this.f22659l, this.f22655h);
        if (this.strokeColor == null) {
            return;
        }
        Paint paint = this.f22654g;
        paint.setStrokeWidth(this.f22658k);
        int colorForState = this.strokeColor.getColorForState(getDrawableState(), this.strokeColor.getDefaultColor());
        if (this.f22658k <= 0.0f || colorForState == 0) {
            return;
        }
        paint.setColor(colorForState);
        canvas.drawPath(this.f22656i, paint);
    }

    @Override // android.widget.ImageView, android.view.View
    public final void onMeasure(int i10, int i11) {
        super.onMeasure(i10, i11);
        if (!this.V && isLayoutDirectionResolved()) {
            this.V = true;
            if (!isPaddingRelative() && this.T == Integer.MIN_VALUE && this.U == Integer.MIN_VALUE) {
                setPadding(super.getPaddingLeft(), super.getPaddingTop(), super.getPaddingRight(), super.getPaddingBottom());
            } else {
                setPaddingRelative(super.getPaddingStart(), super.getPaddingTop(), super.getPaddingEnd(), super.getPaddingBottom());
            }
        }
    }

    @Override // android.view.View
    public final void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        f(i10, i11);
    }

    public void setContentPadding(@Dimension int i10, @Dimension int i11, @Dimension int i12, @Dimension int i13) {
        this.T = Integer.MIN_VALUE;
        this.U = Integer.MIN_VALUE;
        super.setPadding((super.getPaddingLeft() - this.f22660m) + i10, (super.getPaddingTop() - this.Q) + i11, (super.getPaddingRight() - this.R) + i12, (super.getPaddingBottom() - this.S) + i13);
        this.f22660m = i10;
        this.Q = i11;
        this.R = i12;
        this.S = i13;
    }

    public void setContentPaddingRelative(@Dimension int i10, @Dimension int i11, @Dimension int i12, @Dimension int i13) {
        super.setPaddingRelative((super.getPaddingStart() - getContentPaddingStart()) + i10, (super.getPaddingTop() - this.Q) + i11, (super.getPaddingEnd() - getContentPaddingEnd()) + i12, (super.getPaddingBottom() - this.S) + i13);
        this.f22660m = e() ? i12 : i10;
        this.Q = i11;
        if (!e()) {
            i10 = i12;
        }
        this.R = i10;
        this.S = i13;
    }

    @Override // android.view.View
    public void setPadding(@Dimension int i10, @Dimension int i11, @Dimension int i12, @Dimension int i13) {
        super.setPadding(getContentPaddingLeft() + i10, getContentPaddingTop() + i11, getContentPaddingRight() + i12, getContentPaddingBottom() + i13);
    }

    @Override // android.view.View
    public void setPaddingRelative(@Dimension int i10, @Dimension int i11, @Dimension int i12, @Dimension int i13) {
        super.setPaddingRelative(getContentPaddingStart() + i10, getContentPaddingTop() + i11, getContentPaddingEnd() + i12, getContentPaddingBottom() + i13);
    }

    @Override // com.google.android.material.shape.g0
    public void setShapeAppearanceModel(@NonNull s sVar) {
        this.f22657j = sVar;
        k kVar = this.shadowDrawable;
        if (kVar != null) {
            kVar.setShapeAppearanceModel(sVar);
        }
        f(getWidth(), getHeight());
        invalidate();
        invalidateOutline();
    }

    public void setStrokeColor(@Nullable ColorStateList colorStateList) {
        this.strokeColor = colorStateList;
        invalidate();
    }

    public void setStrokeColorResource(@ColorRes int i10) {
        setStrokeColor(d.getColorStateList(getContext(), i10));
    }

    public void setStrokeWidth(@Dimension float f10) {
        if (this.f22658k != f10) {
            this.f22658k = f10;
            invalidate();
        }
    }

    public void setStrokeWidthResource(@DimenRes int i10) {
        setStrokeWidth(getResources().getDimensionPixelSize(i10));
    }

    public ShapeableImageView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public ShapeableImageView(Context context, @Nullable AttributeSet attributeSet, int i10) {
        int i11 = W;
        super(a.wrap(context, attributeSet, i10, i11), attributeSet, i10);
        this.f22651d = t.f23163a;
        this.f22656i = new Path();
        this.V = false;
        Context context2 = getContext();
        Paint paint = new Paint();
        this.f22655h = paint;
        paint.setAntiAlias(true);
        paint.setColor(-1);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        this.f22652e = new RectF();
        this.f22653f = new RectF();
        this.f22659l = new Path();
        TypedArray typedArrayObtainStyledAttributes = context2.obtainStyledAttributes(attributeSet, m.ShapeableImageView, i10, i11);
        setLayerType(2, null);
        this.strokeColor = q9.d.getColorStateList(context2, typedArrayObtainStyledAttributes, m.ShapeableImageView_strokeColor);
        this.f22658k = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_strokeWidth, 0);
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPadding, 0);
        this.f22660m = dimensionPixelSize;
        this.Q = dimensionPixelSize;
        this.R = dimensionPixelSize;
        this.S = dimensionPixelSize;
        this.f22660m = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingLeft, dimensionPixelSize);
        this.Q = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingTop, dimensionPixelSize);
        this.R = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingRight, dimensionPixelSize);
        this.S = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingBottom, dimensionPixelSize);
        this.T = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingStart, Integer.MIN_VALUE);
        this.U = typedArrayObtainStyledAttributes.getDimensionPixelSize(m.ShapeableImageView_contentPaddingEnd, Integer.MIN_VALUE);
        typedArrayObtainStyledAttributes.recycle();
        Paint paint2 = new Paint();
        this.f22654g = paint2;
        paint2.setStyle(Paint.Style.STROKE);
        paint2.setAntiAlias(true);
        this.f22657j = s.c(context2, attributeSet, i10, i11).a();
        setOutlineProvider(new m9.a(this));
    }
}
