package com.google.android.material.chip;

import a1.b;
import android.R;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import c1.g;
import com.google.android.material.internal.k;
import com.google.android.material.internal.m;
import com.google.android.material.internal.o;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import m0.h;
import z0.c;
import z0.d;

/* JADX INFO: compiled from: ChipDrawable.java */
/* JADX INFO: loaded from: classes.dex */
public class a extends g implements Drawable.Callback, k.b {
    private static final int[] N0 = {R.attr.state_enabled};
    private static final ShapeDrawable O0 = new ShapeDrawable(new OvalShape());
    private int A0;
    private ColorFilter B0;
    private PorterDuffColorFilter C0;
    private ColorStateList D;
    private ColorStateList D0;
    private ColorStateList E;
    private PorterDuff.Mode E0;
    private float F;
    private int[] F0;
    private float G;
    private boolean G0;
    private ColorStateList H;
    private ColorStateList H0;
    private float I;
    private WeakReference<InterfaceC0047a> I0;
    private ColorStateList J;
    private TextUtils.TruncateAt J0;
    private CharSequence K;
    private boolean K0;
    private boolean L;
    private int L0;
    private Drawable M;
    private boolean M0;
    private ColorStateList N;
    private float O;
    private boolean P;
    private boolean Q;
    private Drawable R;
    private Drawable S;
    private ColorStateList T;
    private float U;
    private CharSequence V;
    private boolean W;
    private boolean X;
    private Drawable Y;
    private ColorStateList Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    private h f3790a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    private h f3791b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    private float f3792c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    private float f3793d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    private float f3794e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    private float f3795f0;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    private float f3796g0;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    private float f3797h0;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    private float f3798i0;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    private float f3799j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    private final Context f3800k0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    private final Paint f3801l0;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    private final Paint f3802m0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    private final Paint.FontMetrics f3803n0;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    private final RectF f3804o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    private final PointF f3805p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    private final Path f3806q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    private final k f3807r0;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    private int f3808s0;

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    private int f3809t0;

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    private int f3810u0;

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    private int f3811v0;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    private int f3812w0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    private int f3813x0;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    private boolean f3814y0;

    /* JADX INFO: renamed from: z0, reason: collision with root package name */
    private int f3815z0;

    /* JADX INFO: renamed from: com.google.android.material.chip.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: ChipDrawable.java */
    public interface InterfaceC0047a {
        void a();
    }

    private a(Context context, AttributeSet attributeSet, int i3, int i4) {
        super(context, attributeSet, i3, i4);
        this.G = -1.0f;
        this.f3801l0 = new Paint(1);
        this.f3803n0 = new Paint.FontMetrics();
        this.f3804o0 = new RectF();
        this.f3805p0 = new PointF();
        this.f3806q0 = new Path();
        this.A0 = 255;
        this.E0 = PorterDuff.Mode.SRC_IN;
        this.I0 = new WeakReference<>(null);
        N(context);
        this.f3800k0 = context;
        k kVar = new k(this);
        this.f3807r0 = kVar;
        this.K = "";
        kVar.e().density = context.getResources().getDisplayMetrics().density;
        this.f3802m0 = null;
        int[] iArr = N0;
        setState(iArr);
        k2(iArr);
        this.K0 = true;
        if (b.f21a) {
            O0.setTint(-1);
        }
    }

    private void A0(Canvas canvas, Rect rect) {
        if (N2()) {
            n0(rect, this.f3804o0);
            RectF rectF = this.f3804o0;
            float f3 = rectF.left;
            float f4 = rectF.top;
            canvas.translate(f3, f4);
            this.R.setBounds(0, 0, (int) this.f3804o0.width(), (int) this.f3804o0.height());
            if (b.f21a) {
                this.S.setBounds(this.R.getBounds());
                this.S.jumpToCurrentState();
                this.S.draw(canvas);
            } else {
                this.R.draw(canvas);
            }
            canvas.translate(-f3, -f4);
        }
    }

    private void B0(Canvas canvas, Rect rect) {
        this.f3801l0.setColor(this.f3812w0);
        this.f3801l0.setStyle(Paint.Style.FILL);
        this.f3804o0.set(rect);
        if (!this.M0) {
            canvas.drawRoundRect(this.f3804o0, H0(), H0(), this.f3801l0);
        } else {
            h(new RectF(rect), this.f3806q0);
            super.p(canvas, this.f3801l0, this.f3806q0, u());
        }
    }

    private void C0(Canvas canvas, Rect rect) {
        Paint paint = this.f3802m0;
        if (paint != null) {
            paint.setColor(androidx.core.graphics.a.j(-16777216, 127));
            canvas.drawRect(rect, this.f3802m0);
            if (M2() || L2()) {
                k0(rect, this.f3804o0);
                canvas.drawRect(this.f3804o0, this.f3802m0);
            }
            if (this.K != null) {
                canvas.drawLine(rect.left, rect.exactCenterY(), rect.right, rect.exactCenterY(), this.f3802m0);
            }
            if (N2()) {
                n0(rect, this.f3804o0);
                canvas.drawRect(this.f3804o0, this.f3802m0);
            }
            this.f3802m0.setColor(androidx.core.graphics.a.j(-65536, 127));
            m0(rect, this.f3804o0);
            canvas.drawRect(this.f3804o0, this.f3802m0);
            this.f3802m0.setColor(androidx.core.graphics.a.j(-16711936, 127));
            o0(rect, this.f3804o0);
            canvas.drawRect(this.f3804o0, this.f3802m0);
        }
    }

    private void D0(Canvas canvas, Rect rect) {
        if (this.K != null) {
            Paint.Align alignS0 = s0(rect, this.f3805p0);
            q0(rect, this.f3804o0);
            if (this.f3807r0.d() != null) {
                this.f3807r0.e().drawableState = getState();
                this.f3807r0.j(this.f3800k0);
            }
            this.f3807r0.e().setTextAlign(alignS0);
            int iSave = 0;
            boolean z2 = Math.round(this.f3807r0.f(g1().toString())) > Math.round(this.f3804o0.width());
            if (z2) {
                iSave = canvas.save();
                canvas.clipRect(this.f3804o0);
            }
            CharSequence charSequenceEllipsize = this.K;
            if (z2 && this.J0 != null) {
                charSequenceEllipsize = TextUtils.ellipsize(charSequenceEllipsize, this.f3807r0.e(), this.f3804o0.width(), this.J0);
            }
            CharSequence charSequence = charSequenceEllipsize;
            int length = charSequence.length();
            PointF pointF = this.f3805p0;
            canvas.drawText(charSequence, 0, length, pointF.x, pointF.y, this.f3807r0.e());
            if (z2) {
                canvas.restoreToCount(iSave);
            }
        }
    }

    private boolean L2() {
        return this.X && this.Y != null && this.f3814y0;
    }

    private boolean M2() {
        return this.L && this.M != null;
    }

    private boolean N2() {
        return this.Q && this.R != null;
    }

    private void O2(Drawable drawable) {
        if (drawable != null) {
            drawable.setCallback(null);
        }
    }

    private void P2() {
        this.H0 = this.G0 ? b.a(this.J) : null;
    }

    @TargetApi(21)
    private void Q2() {
        this.S = new RippleDrawable(b.a(e1()), this.R, O0);
    }

    private float Y0() {
        Drawable drawable = this.f3814y0 ? this.Y : this.M;
        float f3 = this.O;
        if (f3 > 0.0f || drawable == null) {
            return f3;
        }
        float fCeil = (float) Math.ceil(o.b(this.f3800k0, 24));
        return ((float) drawable.getIntrinsicHeight()) <= fCeil ? drawable.getIntrinsicHeight() : fCeil;
    }

    private float Z0() {
        Drawable drawable = this.f3814y0 ? this.Y : this.M;
        float f3 = this.O;
        return (f3 > 0.0f || drawable == null) ? f3 : drawable.getIntrinsicWidth();
    }

    private void a2(ColorStateList colorStateList) {
        if (this.D != colorStateList) {
            this.D = colorStateList;
            onStateChange(getState());
        }
    }

    private void j0(Drawable drawable) {
        if (drawable == null) {
            return;
        }
        drawable.setCallback(this);
        androidx.core.graphics.drawable.a.m(drawable, androidx.core.graphics.drawable.a.f(this));
        drawable.setLevel(getLevel());
        drawable.setVisible(isVisible(), false);
        if (drawable == this.R) {
            if (drawable.isStateful()) {
                drawable.setState(V0());
            }
            androidx.core.graphics.drawable.a.o(drawable, this.T);
            return;
        }
        Drawable drawable2 = this.M;
        if (drawable == drawable2 && this.P) {
            androidx.core.graphics.drawable.a.o(drawable2, this.N);
        }
        if (drawable.isStateful()) {
            drawable.setState(getState());
        }
    }

    private void k0(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (M2() || L2()) {
            float f3 = this.f3792c0 + this.f3793d0;
            float fZ0 = Z0();
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                float f4 = rect.left + f3;
                rectF.left = f4;
                rectF.right = f4 + fZ0;
            } else {
                float f5 = rect.right - f3;
                rectF.right = f5;
                rectF.left = f5 - fZ0;
            }
            float fY0 = Y0();
            float fExactCenterY = rect.exactCenterY() - (fY0 / 2.0f);
            rectF.top = fExactCenterY;
            rectF.bottom = fExactCenterY + fY0;
        }
    }

    private ColorFilter k1() {
        ColorFilter colorFilter = this.B0;
        return colorFilter != null ? colorFilter : this.C0;
    }

    private void m0(Rect rect, RectF rectF) {
        rectF.set(rect);
        if (N2()) {
            float f3 = this.f3799j0 + this.f3798i0 + this.U + this.f3797h0 + this.f3796g0;
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                rectF.right = rect.right - f3;
            } else {
                rectF.left = rect.left + f3;
            }
        }
    }

    private static boolean m1(int[] iArr, int i3) {
        if (iArr == null) {
            return false;
        }
        for (int i4 : iArr) {
            if (i4 == i3) {
                return true;
            }
        }
        return false;
    }

    private void n0(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (N2()) {
            float f3 = this.f3799j0 + this.f3798i0;
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                float f4 = rect.right - f3;
                rectF.right = f4;
                rectF.left = f4 - this.U;
            } else {
                float f5 = rect.left + f3;
                rectF.left = f5;
                rectF.right = f5 + this.U;
            }
            float fExactCenterY = rect.exactCenterY();
            float f6 = this.U;
            float f7 = fExactCenterY - (f6 / 2.0f);
            rectF.top = f7;
            rectF.bottom = f7 + f6;
        }
    }

    private void o0(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (N2()) {
            float f3 = this.f3799j0 + this.f3798i0 + this.U + this.f3797h0 + this.f3796g0;
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                float f4 = rect.right;
                rectF.right = f4;
                rectF.left = f4 - f3;
            } else {
                int i3 = rect.left;
                rectF.left = i3;
                rectF.right = i3 + f3;
            }
            rectF.top = rect.top;
            rectF.bottom = rect.bottom;
        }
    }

    private void q0(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (this.K != null) {
            float fL0 = this.f3792c0 + l0() + this.f3795f0;
            float fP0 = this.f3799j0 + p0() + this.f3796g0;
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                rectF.left = rect.left + fL0;
                rectF.right = rect.right - fP0;
            } else {
                rectF.left = rect.left + fP0;
                rectF.right = rect.right - fL0;
            }
            rectF.top = rect.top;
            rectF.bottom = rect.bottom;
        }
    }

    private static boolean q1(ColorStateList colorStateList) {
        return colorStateList != null && colorStateList.isStateful();
    }

    private float r0() {
        this.f3807r0.e().getFontMetrics(this.f3803n0);
        Paint.FontMetrics fontMetrics = this.f3803n0;
        return (fontMetrics.descent + fontMetrics.ascent) / 2.0f;
    }

    private static boolean r1(Drawable drawable) {
        return drawable != null && drawable.isStateful();
    }

    private static boolean s1(d dVar) {
        return (dVar == null || dVar.i() == null || !dVar.i().isStateful()) ? false : true;
    }

    private boolean t0() {
        return this.X && this.Y != null && this.W;
    }

    private void t1(AttributeSet attributeSet, int i3, int i4) {
        TypedArray typedArrayH = m.h(this.f3800k0, attributeSet, l0.k.A, i3, i4, new int[0]);
        this.M0 = typedArrayH.hasValue(l0.k.f5508m0);
        a2(c.a(this.f3800k0, typedArrayH, l0.k.Z));
        E1(c.a(this.f3800k0, typedArrayH, l0.k.M));
        S1(typedArrayH.getDimension(l0.k.U, 0.0f));
        int i5 = l0.k.N;
        if (typedArrayH.hasValue(i5)) {
            G1(typedArrayH.getDimension(i5, 0.0f));
        }
        W1(c.a(this.f3800k0, typedArrayH, l0.k.X));
        Y1(typedArrayH.getDimension(l0.k.Y, 0.0f));
        x2(c.a(this.f3800k0, typedArrayH, l0.k.f5505l0));
        C2(typedArrayH.getText(l0.k.G));
        d dVarF = c.f(this.f3800k0, typedArrayH, l0.k.B);
        dVarF.l(typedArrayH.getDimension(l0.k.C, dVarF.j()));
        if (Build.VERSION.SDK_INT < 23) {
            dVarF.k(c.a(this.f3800k0, typedArrayH, l0.k.D));
        }
        D2(dVarF);
        int i6 = typedArrayH.getInt(l0.k.E, 0);
        if (i6 == 1) {
            p2(TextUtils.TruncateAt.START);
        } else if (i6 == 2) {
            p2(TextUtils.TruncateAt.MIDDLE);
        } else if (i6 == 3) {
            p2(TextUtils.TruncateAt.END);
        }
        R1(typedArrayH.getBoolean(l0.k.T, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "chipIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "chipIconVisible") == null) {
            R1(typedArrayH.getBoolean(l0.k.Q, false));
        }
        K1(c.d(this.f3800k0, typedArrayH, l0.k.P));
        int i7 = l0.k.S;
        if (typedArrayH.hasValue(i7)) {
            O1(c.a(this.f3800k0, typedArrayH, i7));
        }
        M1(typedArrayH.getDimension(l0.k.R, -1.0f));
        n2(typedArrayH.getBoolean(l0.k.f5485g0, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "closeIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "closeIconVisible") == null) {
            n2(typedArrayH.getBoolean(l0.k.f5465b0, false));
        }
        b2(c.d(this.f3800k0, typedArrayH, l0.k.f5461a0));
        l2(c.a(this.f3800k0, typedArrayH, l0.k.f5481f0));
        g2(typedArrayH.getDimension(l0.k.f5473d0, 0.0f));
        w1(typedArrayH.getBoolean(l0.k.H, false));
        D1(typedArrayH.getBoolean(l0.k.L, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "checkedIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "checkedIconVisible") == null) {
            D1(typedArrayH.getBoolean(l0.k.J, false));
        }
        y1(c.d(this.f3800k0, typedArrayH, l0.k.I));
        int i8 = l0.k.K;
        if (typedArrayH.hasValue(i8)) {
            A1(c.a(this.f3800k0, typedArrayH, i8));
        }
        A2(h.b(this.f3800k0, typedArrayH, l0.k.f5511n0));
        q2(h.b(this.f3800k0, typedArrayH, l0.k.f5493i0));
        U1(typedArrayH.getDimension(l0.k.W, 0.0f));
        u2(typedArrayH.getDimension(l0.k.f5501k0, 0.0f));
        s2(typedArrayH.getDimension(l0.k.f5497j0, 0.0f));
        H2(typedArrayH.getDimension(l0.k.f5517p0, 0.0f));
        F2(typedArrayH.getDimension(l0.k.f5514o0, 0.0f));
        i2(typedArrayH.getDimension(l0.k.f5477e0, 0.0f));
        d2(typedArrayH.getDimension(l0.k.f5469c0, 0.0f));
        I1(typedArrayH.getDimension(l0.k.O, 0.0f));
        w2(typedArrayH.getDimensionPixelSize(l0.k.F, Integer.MAX_VALUE));
        typedArrayH.recycle();
    }

    public static a u0(Context context, AttributeSet attributeSet, int i3, int i4) {
        a aVar = new a(context, attributeSet, i3, i4);
        aVar.t1(attributeSet, i3, i4);
        return aVar;
    }

    private void v0(Canvas canvas, Rect rect) {
        if (L2()) {
            k0(rect, this.f3804o0);
            RectF rectF = this.f3804o0;
            float f3 = rectF.left;
            float f4 = rectF.top;
            canvas.translate(f3, f4);
            this.Y.setBounds(0, 0, (int) this.f3804o0.width(), (int) this.f3804o0.height());
            this.Y.draw(canvas);
            canvas.translate(-f3, -f4);
        }
    }

    private boolean v1(int[] iArr, int[] iArr2) {
        boolean z2;
        boolean zOnStateChange = super.onStateChange(iArr);
        ColorStateList colorStateList = this.D;
        int iL = l(colorStateList != null ? colorStateList.getColorForState(iArr, this.f3808s0) : 0);
        boolean state = true;
        if (this.f3808s0 != iL) {
            this.f3808s0 = iL;
            zOnStateChange = true;
        }
        ColorStateList colorStateList2 = this.E;
        int iL2 = l(colorStateList2 != null ? colorStateList2.getColorForState(iArr, this.f3809t0) : 0);
        if (this.f3809t0 != iL2) {
            this.f3809t0 = iL2;
            zOnStateChange = true;
        }
        int iG = r0.a.g(iL, iL2);
        if ((this.f3810u0 != iG) | (x() == null)) {
            this.f3810u0 = iG;
            X(ColorStateList.valueOf(iG));
            zOnStateChange = true;
        }
        ColorStateList colorStateList3 = this.H;
        int colorForState = colorStateList3 != null ? colorStateList3.getColorForState(iArr, this.f3811v0) : 0;
        if (this.f3811v0 != colorForState) {
            this.f3811v0 = colorForState;
            zOnStateChange = true;
        }
        int colorForState2 = (this.H0 == null || !b.b(iArr)) ? 0 : this.H0.getColorForState(iArr, this.f3812w0);
        if (this.f3812w0 != colorForState2) {
            this.f3812w0 = colorForState2;
            if (this.G0) {
                zOnStateChange = true;
            }
        }
        int colorForState3 = (this.f3807r0.d() == null || this.f3807r0.d().i() == null) ? 0 : this.f3807r0.d().i().getColorForState(iArr, this.f3813x0);
        if (this.f3813x0 != colorForState3) {
            this.f3813x0 = colorForState3;
            zOnStateChange = true;
        }
        boolean z3 = m1(getState(), R.attr.state_checked) && this.W;
        if (this.f3814y0 == z3 || this.Y == null) {
            z2 = false;
        } else {
            float fL0 = l0();
            this.f3814y0 = z3;
            if (fL0 != l0()) {
                zOnStateChange = true;
                z2 = true;
            } else {
                z2 = false;
                zOnStateChange = true;
            }
        }
        ColorStateList colorStateList4 = this.D0;
        int colorForState4 = colorStateList4 != null ? colorStateList4.getColorForState(iArr, this.f3815z0) : 0;
        if (this.f3815z0 != colorForState4) {
            this.f3815z0 = colorForState4;
            this.C0 = t0.a.a(this, this.D0, this.E0);
        } else {
            state = zOnStateChange;
        }
        if (r1(this.M)) {
            state |= this.M.setState(iArr);
        }
        if (r1(this.Y)) {
            state |= this.Y.setState(iArr);
        }
        if (r1(this.R)) {
            int[] iArr3 = new int[iArr.length + iArr2.length];
            System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
            System.arraycopy(iArr2, 0, iArr3, iArr.length, iArr2.length);
            state |= this.R.setState(iArr3);
        }
        if (b.f21a && r1(this.S)) {
            state |= this.S.setState(iArr2);
        }
        if (state) {
            invalidateSelf();
        }
        if (z2) {
            u1();
        }
        return state;
    }

    private void w0(Canvas canvas, Rect rect) {
        if (this.M0) {
            return;
        }
        this.f3801l0.setColor(this.f3809t0);
        this.f3801l0.setStyle(Paint.Style.FILL);
        this.f3801l0.setColorFilter(k1());
        this.f3804o0.set(rect);
        canvas.drawRoundRect(this.f3804o0, H0(), H0(), this.f3801l0);
    }

    private void x0(Canvas canvas, Rect rect) {
        if (M2()) {
            k0(rect, this.f3804o0);
            RectF rectF = this.f3804o0;
            float f3 = rectF.left;
            float f4 = rectF.top;
            canvas.translate(f3, f4);
            this.M.setBounds(0, 0, (int) this.f3804o0.width(), (int) this.f3804o0.height());
            this.M.draw(canvas);
            canvas.translate(-f3, -f4);
        }
    }

    private void y0(Canvas canvas, Rect rect) {
        if (this.I <= 0.0f || this.M0) {
            return;
        }
        this.f3801l0.setColor(this.f3811v0);
        this.f3801l0.setStyle(Paint.Style.STROKE);
        if (!this.M0) {
            this.f3801l0.setColorFilter(k1());
        }
        RectF rectF = this.f3804o0;
        float f3 = rect.left;
        float f4 = this.I;
        rectF.set(f3 + (f4 / 2.0f), rect.top + (f4 / 2.0f), rect.right - (f4 / 2.0f), rect.bottom - (f4 / 2.0f));
        float f5 = this.G - (this.I / 2.0f);
        canvas.drawRoundRect(this.f3804o0, f5, f5, this.f3801l0);
    }

    private void z0(Canvas canvas, Rect rect) {
        if (this.M0) {
            return;
        }
        this.f3801l0.setColor(this.f3808s0);
        this.f3801l0.setStyle(Paint.Style.FILL);
        this.f3804o0.set(rect);
        canvas.drawRoundRect(this.f3804o0, H0(), H0(), this.f3801l0);
    }

    public void A1(ColorStateList colorStateList) {
        if (this.Z != colorStateList) {
            this.Z = colorStateList;
            if (t0()) {
                androidx.core.graphics.drawable.a.o(this.Y, colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void A2(h hVar) {
        this.f3790a0 = hVar;
    }

    public void B1(int i3) {
        A1(d.a.a(this.f3800k0, i3));
    }

    public void B2(int i3) {
        A2(h.c(this.f3800k0, i3));
    }

    public void C1(int i3) {
        D1(this.f3800k0.getResources().getBoolean(i3));
    }

    public void C2(CharSequence charSequence) {
        if (charSequence == null) {
            charSequence = "";
        }
        if (TextUtils.equals(this.K, charSequence)) {
            return;
        }
        this.K = charSequence;
        this.f3807r0.i(true);
        invalidateSelf();
        u1();
    }

    public void D1(boolean z2) {
        if (this.X != z2) {
            boolean zL2 = L2();
            this.X = z2;
            boolean zL22 = L2();
            if (zL2 != zL22) {
                if (zL22) {
                    j0(this.Y);
                } else {
                    O2(this.Y);
                }
                invalidateSelf();
                u1();
            }
        }
    }

    public void D2(d dVar) {
        this.f3807r0.h(dVar, this.f3800k0);
    }

    public Drawable E0() {
        return this.Y;
    }

    public void E1(ColorStateList colorStateList) {
        if (this.E != colorStateList) {
            this.E = colorStateList;
            onStateChange(getState());
        }
    }

    public void E2(int i3) {
        D2(new d(this.f3800k0, i3));
    }

    public ColorStateList F0() {
        return this.Z;
    }

    public void F1(int i3) {
        E1(d.a.a(this.f3800k0, i3));
    }

    public void F2(float f3) {
        if (this.f3796g0 != f3) {
            this.f3796g0 = f3;
            invalidateSelf();
            u1();
        }
    }

    public ColorStateList G0() {
        return this.E;
    }

    @Deprecated
    public void G1(float f3) {
        if (this.G != f3) {
            this.G = f3;
            setShapeAppearanceModel(D().w(f3));
        }
    }

    public void G2(int i3) {
        F2(this.f3800k0.getResources().getDimension(i3));
    }

    public float H0() {
        return this.M0 ? G() : this.G;
    }

    @Deprecated
    public void H1(int i3) {
        G1(this.f3800k0.getResources().getDimension(i3));
    }

    public void H2(float f3) {
        if (this.f3795f0 != f3) {
            this.f3795f0 = f3;
            invalidateSelf();
            u1();
        }
    }

    public float I0() {
        return this.f3799j0;
    }

    public void I1(float f3) {
        if (this.f3799j0 != f3) {
            this.f3799j0 = f3;
            invalidateSelf();
            u1();
        }
    }

    public void I2(int i3) {
        H2(this.f3800k0.getResources().getDimension(i3));
    }

    public Drawable J0() {
        Drawable drawable = this.M;
        if (drawable != null) {
            return androidx.core.graphics.drawable.a.q(drawable);
        }
        return null;
    }

    public void J1(int i3) {
        I1(this.f3800k0.getResources().getDimension(i3));
    }

    public void J2(boolean z2) {
        if (this.G0 != z2) {
            this.G0 = z2;
            P2();
            onStateChange(getState());
        }
    }

    public float K0() {
        return this.O;
    }

    public void K1(Drawable drawable) {
        Drawable drawableJ0 = J0();
        if (drawableJ0 != drawable) {
            float fL0 = l0();
            this.M = drawable != null ? androidx.core.graphics.drawable.a.r(drawable).mutate() : null;
            float fL02 = l0();
            O2(drawableJ0);
            if (M2()) {
                j0(this.M);
            }
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    boolean K2() {
        return this.K0;
    }

    public ColorStateList L0() {
        return this.N;
    }

    public void L1(int i3) {
        K1(d.a.b(this.f3800k0, i3));
    }

    public float M0() {
        return this.F;
    }

    public void M1(float f3) {
        if (this.O != f3) {
            float fL0 = l0();
            this.O = f3;
            float fL02 = l0();
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    public float N0() {
        return this.f3792c0;
    }

    public void N1(int i3) {
        M1(this.f3800k0.getResources().getDimension(i3));
    }

    public ColorStateList O0() {
        return this.H;
    }

    public void O1(ColorStateList colorStateList) {
        this.P = true;
        if (this.N != colorStateList) {
            this.N = colorStateList;
            if (M2()) {
                androidx.core.graphics.drawable.a.o(this.M, colorStateList);
            }
            onStateChange(getState());
        }
    }

    public float P0() {
        return this.I;
    }

    public void P1(int i3) {
        O1(d.a.a(this.f3800k0, i3));
    }

    public Drawable Q0() {
        Drawable drawable = this.R;
        if (drawable != null) {
            return androidx.core.graphics.drawable.a.q(drawable);
        }
        return null;
    }

    public void Q1(int i3) {
        R1(this.f3800k0.getResources().getBoolean(i3));
    }

    public CharSequence R0() {
        return this.V;
    }

    public void R1(boolean z2) {
        if (this.L != z2) {
            boolean zM2 = M2();
            this.L = z2;
            boolean zM22 = M2();
            if (zM2 != zM22) {
                if (zM22) {
                    j0(this.M);
                } else {
                    O2(this.M);
                }
                invalidateSelf();
                u1();
            }
        }
    }

    public float S0() {
        return this.f3798i0;
    }

    public void S1(float f3) {
        if (this.F != f3) {
            this.F = f3;
            invalidateSelf();
            u1();
        }
    }

    public float T0() {
        return this.U;
    }

    public void T1(int i3) {
        S1(this.f3800k0.getResources().getDimension(i3));
    }

    public float U0() {
        return this.f3797h0;
    }

    public void U1(float f3) {
        if (this.f3792c0 != f3) {
            this.f3792c0 = f3;
            invalidateSelf();
            u1();
        }
    }

    public int[] V0() {
        return this.F0;
    }

    public void V1(int i3) {
        U1(this.f3800k0.getResources().getDimension(i3));
    }

    public ColorStateList W0() {
        return this.T;
    }

    public void W1(ColorStateList colorStateList) {
        if (this.H != colorStateList) {
            this.H = colorStateList;
            if (this.M0) {
                e0(colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void X0(RectF rectF) {
        o0(getBounds(), rectF);
    }

    public void X1(int i3) {
        W1(d.a.a(this.f3800k0, i3));
    }

    public void Y1(float f3) {
        if (this.I != f3) {
            this.I = f3;
            this.f3801l0.setStrokeWidth(f3);
            if (this.M0) {
                super.f0(f3);
            }
            invalidateSelf();
        }
    }

    public void Z1(int i3) {
        Y1(this.f3800k0.getResources().getDimension(i3));
    }

    @Override // com.google.android.material.internal.k.b
    public void a() {
        u1();
        invalidateSelf();
    }

    public TextUtils.TruncateAt a1() {
        return this.J0;
    }

    public h b1() {
        return this.f3791b0;
    }

    public void b2(Drawable drawable) {
        Drawable drawableQ0 = Q0();
        if (drawableQ0 != drawable) {
            float fP0 = p0();
            this.R = drawable != null ? androidx.core.graphics.drawable.a.r(drawable).mutate() : null;
            if (b.f21a) {
                Q2();
            }
            float fP02 = p0();
            O2(drawableQ0);
            if (N2()) {
                j0(this.R);
            }
            invalidateSelf();
            if (fP0 != fP02) {
                u1();
            }
        }
    }

    public float c1() {
        return this.f3794e0;
    }

    public void c2(CharSequence charSequence) {
        if (this.V != charSequence) {
            this.V = androidx.core.text.a.c().h(charSequence);
            invalidateSelf();
        }
    }

    public float d1() {
        return this.f3793d0;
    }

    public void d2(float f3) {
        if (this.f3798i0 != f3) {
            this.f3798i0 = f3;
            invalidateSelf();
            if (N2()) {
                u1();
            }
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        Rect bounds = getBounds();
        if (bounds.isEmpty() || getAlpha() == 0) {
            return;
        }
        int i3 = this.A0;
        int iA = i3 < 255 ? n0.a.a(canvas, bounds.left, bounds.top, bounds.right, bounds.bottom, i3) : 0;
        z0(canvas, bounds);
        w0(canvas, bounds);
        if (this.M0) {
            super.draw(canvas);
        }
        y0(canvas, bounds);
        B0(canvas, bounds);
        x0(canvas, bounds);
        v0(canvas, bounds);
        if (this.K0) {
            D0(canvas, bounds);
        }
        A0(canvas, bounds);
        C0(canvas, bounds);
        if (this.A0 < 255) {
            canvas.restoreToCount(iA);
        }
    }

    public ColorStateList e1() {
        return this.J;
    }

    public void e2(int i3) {
        d2(this.f3800k0.getResources().getDimension(i3));
    }

    public h f1() {
        return this.f3790a0;
    }

    public void f2(int i3) {
        b2(d.a.b(this.f3800k0, i3));
    }

    public CharSequence g1() {
        return this.K;
    }

    public void g2(float f3) {
        if (this.U != f3) {
            this.U = f3;
            invalidateSelf();
            if (N2()) {
                u1();
            }
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public int getAlpha() {
        return this.A0;
    }

    @Override // android.graphics.drawable.Drawable
    public ColorFilter getColorFilter() {
        return this.B0;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicHeight() {
        return (int) this.F;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicWidth() {
        return Math.min(Math.round(this.f3792c0 + l0() + this.f3795f0 + this.f3807r0.f(g1().toString()) + this.f3796g0 + p0() + this.f3799j0), this.L0);
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public int getOpacity() {
        return -3;
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    @TargetApi(21)
    public void getOutline(Outline outline) {
        if (this.M0) {
            super.getOutline(outline);
            return;
        }
        Rect bounds = getBounds();
        if (bounds.isEmpty()) {
            outline.setRoundRect(0, 0, getIntrinsicWidth(), getIntrinsicHeight(), this.G);
        } else {
            outline.setRoundRect(bounds, this.G);
        }
        outline.setAlpha(getAlpha() / 255.0f);
    }

    public d h1() {
        return this.f3807r0.d();
    }

    public void h2(int i3) {
        g2(this.f3800k0.getResources().getDimension(i3));
    }

    public float i1() {
        return this.f3796g0;
    }

    public void i2(float f3) {
        if (this.f3797h0 != f3) {
            this.f3797h0 = f3;
            invalidateSelf();
            if (N2()) {
                u1();
            }
        }
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public void invalidateDrawable(Drawable drawable) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.invalidateDrawable(this);
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public boolean isStateful() {
        return q1(this.D) || q1(this.E) || q1(this.H) || (this.G0 && q1(this.H0)) || s1(this.f3807r0.d()) || t0() || r1(this.M) || r1(this.Y) || q1(this.D0);
    }

    public float j1() {
        return this.f3795f0;
    }

    public void j2(int i3) {
        i2(this.f3800k0.getResources().getDimension(i3));
    }

    public boolean k2(int[] iArr) {
        if (Arrays.equals(this.F0, iArr)) {
            return false;
        }
        this.F0 = iArr;
        if (N2()) {
            return v1(getState(), iArr);
        }
        return false;
    }

    float l0() {
        if (M2() || L2()) {
            return this.f3793d0 + Z0() + this.f3794e0;
        }
        return 0.0f;
    }

    public boolean l1() {
        return this.G0;
    }

    public void l2(ColorStateList colorStateList) {
        if (this.T != colorStateList) {
            this.T = colorStateList;
            if (N2()) {
                androidx.core.graphics.drawable.a.o(this.R, colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void m2(int i3) {
        l2(d.a.a(this.f3800k0, i3));
    }

    public boolean n1() {
        return this.W;
    }

    public void n2(boolean z2) {
        if (this.Q != z2) {
            boolean zN2 = N2();
            this.Q = z2;
            boolean zN22 = N2();
            if (zN2 != zN22) {
                if (zN22) {
                    j0(this.R);
                } else {
                    O2(this.R);
                }
                invalidateSelf();
                u1();
            }
        }
    }

    public boolean o1() {
        return r1(this.R);
    }

    public void o2(InterfaceC0047a interfaceC0047a) {
        this.I0 = new WeakReference<>(interfaceC0047a);
    }

    @Override // android.graphics.drawable.Drawable
    public boolean onLayoutDirectionChanged(int i3) {
        boolean zOnLayoutDirectionChanged = super.onLayoutDirectionChanged(i3);
        if (M2()) {
            zOnLayoutDirectionChanged |= androidx.core.graphics.drawable.a.m(this.M, i3);
        }
        if (L2()) {
            zOnLayoutDirectionChanged |= androidx.core.graphics.drawable.a.m(this.Y, i3);
        }
        if (N2()) {
            zOnLayoutDirectionChanged |= androidx.core.graphics.drawable.a.m(this.R, i3);
        }
        if (!zOnLayoutDirectionChanged) {
            return true;
        }
        invalidateSelf();
        return true;
    }

    @Override // android.graphics.drawable.Drawable
    protected boolean onLevelChange(int i3) {
        boolean zOnLevelChange = super.onLevelChange(i3);
        if (M2()) {
            zOnLevelChange |= this.M.setLevel(i3);
        }
        if (L2()) {
            zOnLevelChange |= this.Y.setLevel(i3);
        }
        if (N2()) {
            zOnLevelChange |= this.R.setLevel(i3);
        }
        if (zOnLevelChange) {
            invalidateSelf();
        }
        return zOnLevelChange;
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        if (this.M0) {
            super.onStateChange(iArr);
        }
        return v1(iArr, V0());
    }

    float p0() {
        if (N2()) {
            return this.f3797h0 + this.U + this.f3798i0;
        }
        return 0.0f;
    }

    public boolean p1() {
        return this.Q;
    }

    public void p2(TextUtils.TruncateAt truncateAt) {
        this.J0 = truncateAt;
    }

    public void q2(h hVar) {
        this.f3791b0 = hVar;
    }

    public void r2(int i3) {
        q2(h.c(this.f3800k0, i3));
    }

    Paint.Align s0(Rect rect, PointF pointF) {
        pointF.set(0.0f, 0.0f);
        Paint.Align align = Paint.Align.LEFT;
        if (this.K != null) {
            float fL0 = this.f3792c0 + l0() + this.f3795f0;
            if (androidx.core.graphics.drawable.a.f(this) == 0) {
                pointF.x = rect.left + fL0;
                align = Paint.Align.LEFT;
            } else {
                pointF.x = rect.right - fL0;
                align = Paint.Align.RIGHT;
            }
            pointF.y = rect.centerY() - r0();
        }
        return align;
    }

    public void s2(float f3) {
        if (this.f3794e0 != f3) {
            float fL0 = l0();
            this.f3794e0 = f3;
            float fL02 = l0();
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public void scheduleDrawable(Drawable drawable, Runnable runnable, long j3) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.scheduleDrawable(this, runnable, j3);
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public void setAlpha(int i3) {
        if (this.A0 != i3) {
            this.A0 = i3;
            invalidateSelf();
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        if (this.B0 != colorFilter) {
            this.B0 = colorFilter;
            invalidateSelf();
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable, androidx.core.graphics.drawable.b
    public void setTintList(ColorStateList colorStateList) {
        if (this.D0 != colorStateList) {
            this.D0 = colorStateList;
            onStateChange(getState());
        }
    }

    @Override // c1.g, android.graphics.drawable.Drawable, androidx.core.graphics.drawable.b
    public void setTintMode(PorterDuff.Mode mode) {
        if (this.E0 != mode) {
            this.E0 = mode;
            this.C0 = t0.a.a(this, this.D0, mode);
            invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public boolean setVisible(boolean z2, boolean z3) {
        boolean visible = super.setVisible(z2, z3);
        if (M2()) {
            visible |= this.M.setVisible(z2, z3);
        }
        if (L2()) {
            visible |= this.Y.setVisible(z2, z3);
        }
        if (N2()) {
            visible |= this.R.setVisible(z2, z3);
        }
        if (visible) {
            invalidateSelf();
        }
        return visible;
    }

    public void t2(int i3) {
        s2(this.f3800k0.getResources().getDimension(i3));
    }

    protected void u1() {
        InterfaceC0047a interfaceC0047a = this.I0.get();
        if (interfaceC0047a != null) {
            interfaceC0047a.a();
        }
    }

    public void u2(float f3) {
        if (this.f3793d0 != f3) {
            float fL0 = l0();
            this.f3793d0 = f3;
            float fL02 = l0();
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public void unscheduleDrawable(Drawable drawable, Runnable runnable) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.unscheduleDrawable(this, runnable);
        }
    }

    public void v2(int i3) {
        u2(this.f3800k0.getResources().getDimension(i3));
    }

    public void w1(boolean z2) {
        if (this.W != z2) {
            this.W = z2;
            float fL0 = l0();
            if (!z2 && this.f3814y0) {
                this.f3814y0 = false;
            }
            float fL02 = l0();
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    public void w2(int i3) {
        this.L0 = i3;
    }

    public void x1(int i3) {
        w1(this.f3800k0.getResources().getBoolean(i3));
    }

    public void x2(ColorStateList colorStateList) {
        if (this.J != colorStateList) {
            this.J = colorStateList;
            P2();
            onStateChange(getState());
        }
    }

    public void y1(Drawable drawable) {
        if (this.Y != drawable) {
            float fL0 = l0();
            this.Y = drawable;
            float fL02 = l0();
            O2(this.Y);
            j0(this.Y);
            invalidateSelf();
            if (fL0 != fL02) {
                u1();
            }
        }
    }

    public void y2(int i3) {
        x2(d.a.a(this.f3800k0, i3));
    }

    public void z1(int i3) {
        y1(d.a.b(this.f3800k0, i3));
    }

    void z2(boolean z2) {
        this.K0 = z2;
    }
}
