package androidx.appcompat.widget;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
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 i {
    private final CompoundButton a;
    private ColorStateList b = null;
    private PorterDuff.Mode c = null;
    private boolean d = false;
    private boolean e = false;
    private boolean f;

    i(CompoundButton compoundButton) {
        this.a = compoundButton;
    }

    void a() {
        Drawable drawableA = androidx.core.widget.c.a(this.a);
        if (drawableA != null) {
            if (this.d || this.e) {
                Drawable drawableMutate = androidx.core.graphics.drawable.a.p(drawableA).mutate();
                if (this.d) {
                    androidx.core.graphics.drawable.a.n(drawableMutate, this.b);
                }
                if (this.e) {
                    androidx.core.graphics.drawable.a.o(drawableMutate, this.c);
                }
                if (drawableMutate.isStateful()) {
                    drawableMutate.setState(this.a.getDrawableState());
                }
                this.a.setButtonDrawable(drawableMutate);
            }
        }
    }

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

    ColorStateList c() {
        return this.b;
    }

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

    void e(AttributeSet attributeSet, int i2) {
        int resourceId;
        TypedArray typedArrayObtainStyledAttributes = this.a.getContext().obtainStyledAttributes(attributeSet, g.a.j.CompoundButton, i2, 0);
        try {
            if (typedArrayObtainStyledAttributes.hasValue(g.a.j.CompoundButton_android_button) && (resourceId = typedArrayObtainStyledAttributes.getResourceId(g.a.j.CompoundButton_android_button, 0)) != 0) {
                this.a.setButtonDrawable(g.a.k.a.a.d(this.a.getContext(), resourceId));
            }
            if (typedArrayObtainStyledAttributes.hasValue(g.a.j.CompoundButton_buttonTint)) {
                androidx.core.widget.c.b(this.a, typedArrayObtainStyledAttributes.getColorStateList(g.a.j.CompoundButton_buttonTint));
            }
            if (typedArrayObtainStyledAttributes.hasValue(g.a.j.CompoundButton_buttonTintMode)) {
                androidx.core.widget.c.c(this.a, c0.d(typedArrayObtainStyledAttributes.getInt(g.a.j.CompoundButton_buttonTintMode, -1), null));
            }
        } finally {
            typedArrayObtainStyledAttributes.recycle();
        }
    }

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

    void g(ColorStateList colorStateList) {
        this.b = colorStateList;
        this.d = true;
        a();
    }

    void h(PorterDuff.Mode mode) {
        this.c = mode;
        this.e = true;
        a();
    }
}
