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;
    private r0 d;
    private r0 e;
    private r0 f;
    private int c = -1;
    private final j b = j.n();

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

    private boolean a(Drawable drawable) {
        if (this.f == null) {
            this.f = new r0();
        }
        r0 r0Var = this.f;
        r0Var.a();
        ColorStateList colorStateListD = g.e.j.o.d(this.a);
        if (colorStateListD != null) {
            r0Var.d = true;
            r0Var.a = colorStateListD;
        }
        PorterDuff.Mode modeE = g.e.j.o.e(this.a);
        if (modeE != null) {
            r0Var.c = true;
            r0Var.b = modeE;
        }
        if (!r0Var.d && !r0Var.c) {
            return false;
        }
        j.C(drawable, r0Var, this.a.getDrawableState());
        return true;
    }

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

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

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

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

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

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

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

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

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

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