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 {

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

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

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

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

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

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

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

    private boolean a(Drawable drawable) {
        if (this.f584f == null) {
            this.f584f = new g0();
        }
        g0 g0Var = this.f584f;
        g0Var.a();
        ColorStateList colorStateListA = a.c.i.l.a(this.f579a);
        if (colorStateListA != null) {
            g0Var.f601d = true;
            g0Var.f598a = colorStateListA;
        }
        PorterDuff.Mode modeB = a.c.i.l.b(this.f579a);
        if (modeB != null) {
            g0Var.f600c = true;
            g0Var.f599b = modeB;
        }
        if (!g0Var.f601d && !g0Var.f600c) {
            return false;
        }
        f.B(drawable, g0Var, this.f579a.getDrawableState());
        return true;
    }

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

    void b() {
        Drawable background = this.f579a.getBackground();
        if (background != null) {
            if (k() && a(background)) {
                return;
            }
            g0 g0Var = this.f583e;
            if (g0Var != null) {
                f.B(background, g0Var, this.f579a.getDrawableState());
                return;
            }
            g0 g0Var2 = this.f582d;
            if (g0Var2 != null) {
                f.B(background, g0Var2, this.f579a.getDrawableState());
            }
        }
    }

    ColorStateList c() {
        g0 g0Var = this.f583e;
        if (g0Var != null) {
            return g0Var.f598a;
        }
        return null;
    }

    PorterDuff.Mode d() {
        g0 g0Var = this.f583e;
        if (g0Var != null) {
            return g0Var.f599b;
        }
        return null;
    }

    void e(AttributeSet attributeSet, int i) {
        i0 i0VarS = i0.s(this.f579a.getContext(), attributeSet, a.a.j.X2, i, 0);
        try {
            int i2 = a.a.j.Y2;
            if (i0VarS.p(i2)) {
                this.f581c = i0VarS.l(i2, -1);
                ColorStateList colorStateListS = this.f580b.s(this.f579a.getContext(), this.f581c);
                if (colorStateListS != null) {
                    h(colorStateListS);
                }
            }
            int i3 = a.a.j.Z2;
            if (i0VarS.p(i3)) {
                a.c.i.l.m(this.f579a, i0VarS.c(i3));
            }
            int i4 = a.a.j.a3;
            if (i0VarS.p(i4)) {
                a.c.i.l.n(this.f579a, r.d(i0VarS.i(i4, -1), null));
            }
        } finally {
            i0VarS.t();
        }
    }

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

    void g(int i) {
        this.f581c = i;
        f fVar = this.f580b;
        h(fVar != null ? fVar.s(this.f579a.getContext(), i) : null);
        b();
    }

    void h(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.f582d == null) {
                this.f582d = new g0();
            }
            g0 g0Var = this.f582d;
            g0Var.f598a = colorStateList;
            g0Var.f601d = true;
        } else {
            this.f582d = null;
        }
        b();
    }

    void i(ColorStateList colorStateList) {
        if (this.f583e == null) {
            this.f583e = new g0();
        }
        g0 g0Var = this.f583e;
        g0Var.f598a = colorStateList;
        g0Var.f601d = true;
        b();
    }

    void j(PorterDuff.Mode mode) {
        if (this.f583e == null) {
            this.f583e = new g0();
        }
        g0 g0Var = this.f583e;
        g0Var.f599b = mode;
        g0Var.f600c = true;
        b();
    }
}
