package androidx.appcompat.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.CompoundButton;

/* JADX INFO: compiled from: AppCompatCompoundButtonHelper.java */
/* JADX INFO: loaded from: classes.dex */
class j {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final CompoundButton f944a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private ColorStateList f945b = null;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private PorterDuff.Mode f946c = null;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private boolean f947d = false;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private boolean f948e = false;

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

    j(CompoundButton compoundButton) {
        this.f944a = compoundButton;
    }

    void a() {
        Drawable drawableA = androidx.core.widget.d.a(this.f944a);
        if (drawableA != null) {
            if (this.f947d || this.f948e) {
                Drawable drawableMutate = androidx.core.graphics.drawable.a.r(drawableA).mutate();
                if (this.f947d) {
                    androidx.core.graphics.drawable.a.o(drawableMutate, this.f945b);
                }
                if (this.f948e) {
                    androidx.core.graphics.drawable.a.p(drawableMutate, this.f946c);
                }
                if (drawableMutate.isStateful()) {
                    drawableMutate.setState(this.f944a.getDrawableState());
                }
                this.f944a.setButtonDrawable(drawableMutate);
            }
        }
    }

    int b(int i3) {
        Drawable drawableA;
        return (Build.VERSION.SDK_INT >= 17 || (drawableA = androidx.core.widget.d.a(this.f944a)) == null) ? i3 : i3 + drawableA.getIntrinsicWidth();
    }

    ColorStateList c() {
        return this.f945b;
    }

    PorterDuff.Mode d() {
        return this.f946c;
    }

    void e(AttributeSet attributeSet, int i3) {
        boolean z2;
        int iN;
        int iN2;
        Context context = this.f944a.getContext();
        int[] iArr = c.j.R0;
        a1 a1VarV = a1.v(context, attributeSet, iArr, i3, 0);
        CompoundButton compoundButton = this.f944a;
        androidx.core.view.y.p0(compoundButton, compoundButton.getContext(), iArr, attributeSet, a1VarV.r(), i3, 0);
        try {
            int i4 = c.j.T0;
            if (!a1VarV.s(i4) || (iN2 = a1VarV.n(i4, 0)) == 0) {
                z2 = false;
            } else {
                try {
                    CompoundButton compoundButton2 = this.f944a;
                    compoundButton2.setButtonDrawable(d.a.b(compoundButton2.getContext(), iN2));
                    z2 = true;
                } catch (Resources.NotFoundException unused) {
                    z2 = false;
                }
            }
            if (!z2) {
                int i5 = c.j.S0;
                if (a1VarV.s(i5) && (iN = a1VarV.n(i5, 0)) != 0) {
                    CompoundButton compoundButton3 = this.f944a;
                    compoundButton3.setButtonDrawable(d.a.b(compoundButton3.getContext(), iN));
                }
            }
            int i6 = c.j.U0;
            if (a1VarV.s(i6)) {
                androidx.core.widget.d.c(this.f944a, a1VarV.c(i6));
            }
            int i7 = c.j.V0;
            if (a1VarV.s(i7)) {
                androidx.core.widget.d.d(this.f944a, i0.d(a1VarV.k(i7, -1), null));
            }
        } finally {
            a1VarV.w();
        }
    }

    void f() {
        if (this.f949f) {
            this.f949f = false;
        } else {
            this.f949f = true;
            a();
        }
    }

    void g(ColorStateList colorStateList) {
        this.f945b = colorStateList;
        this.f947d = true;
        a();
    }

    void h(PorterDuff.Mode mode) {
        this.f946c = mode;
        this.f948e = true;
        a();
    }
}
