package androidx.appcompat.widget;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/* JADX INFO: compiled from: AppCompatBackgroundHelper.java */
/* JADX INFO: loaded from: classes.dex */
class e {
    private final View a;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private r0 f392d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private r0 f393e;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f391c = -1;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final j f390b = j.n();

    e(View view) {
        this.a = view;
    }

    private boolean a(Drawable drawable) {
        if (this.f394f == null) {
            this.f394f = new r0();
        }
        r0 r0Var = this.f394f;
        r0Var.a();
        ColorStateList colorStateListL = c.f.l.t.l(this.a);
        if (colorStateListL != null) {
            r0Var.f497d = true;
            r0Var.a = colorStateListL;
        }
        PorterDuff.Mode modeM = c.f.l.t.m(this.a);
        if (modeM != null) {
            r0Var.f496c = true;
            r0Var.f495b = modeM;
        }
        if (!r0Var.f497d && !r0Var.f496c) {
            return false;
        }
        j.C(drawable, r0Var, this.a.getDrawableState());
        return true;
    }

    private boolean k() {
        int i2 = Build.VERSION.SDK_INT;
        return i2 > 21 ? this.f392d != null : i2 == 21;
    }

    void b() {
        Drawable background = this.a.getBackground();
        if (background != null) {
            if (k() && a(background)) {
                return;
            }
            r0 r0Var = this.f393e;
            if (r0Var != null) {
                j.C(background, r0Var, this.a.getDrawableState());
                return;
            }
            r0 r0Var2 = this.f392d;
            if (r0Var2 != null) {
                j.C(background, r0Var2, this.a.getDrawableState());
            }
        }
    }

    ColorStateList c() {
        r0 r0Var = this.f393e;
        if (r0Var != null) {
            return r0Var.a;
        }
        return null;
    }

    PorterDuff.Mode d() {
        r0 r0Var = this.f393e;
        if (r0Var != null) {
            return r0Var.f495b;
        }
        return null;
    }

    void e(AttributeSet attributeSet, int i2) {
        t0 t0VarT = t0.t(this.a.getContext(), attributeSet, c.a.j.ViewBackgroundHelper, i2, 0);
        try {
            if (t0VarT.q(c.a.j.ViewBackgroundHelper_android_background)) {
                this.f391c = t0VarT.m(c.a.j.ViewBackgroundHelper_android_background, -1);
                ColorStateList colorStateListS = this.f390b.s(this.a.getContext(), this.f391c);
                if (colorStateListS != null) {
                    h(colorStateListS);
                }
            }
            if (t0VarT.q(c.a.j.ViewBackgroundHelper_backgroundTint)) {
                c.f.l.t.Y(this.a, t0VarT.c(c.a.j.ViewBackgroundHelper_backgroundTint));
            }
            if (t0VarT.q(c.a.j.ViewBackgroundHelper_backgroundTintMode)) {
                c.f.l.t.Z(this.a, c0.d(t0VarT.j(c.a.j.ViewBackgroundHelper_backgroundTintMode, -1), null));
            }
        } finally {
            t0VarT.u();
        }
    }

    void f(Drawable drawable) {
        this.f391c = -1;
        h(null);
        b();
    }

    void g(int i2) {
        this.f391c = i2;
        j jVar = this.f390b;
        h(jVar != null ? jVar.s(this.a.getContext(), i2) : null);
        b();
    }

    void h(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.f392d == null) {
                this.f392d = new r0();
            }
            r0 r0Var = this.f392d;
            r0Var.a = colorStateList;
            r0Var.f497d = true;
        } else {
            this.f392d = null;
        }
        b();
    }

    void i(ColorStateList colorStateList) {
        if (this.f393e == null) {
            this.f393e = new r0();
        }
        r0 r0Var = this.f393e;
        r0Var.a = colorStateList;
        r0Var.f497d = true;
        b();
    }

    void j(PorterDuff.Mode mode) {
        if (this.f393e == null) {
            this.f393e = new r0();
        }
        r0 r0Var = this.f393e;
        r0Var.f495b = mode;
        r0Var.f496c = true;
        b();
    }
}
