package android.support.v7.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 f1017a;

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

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

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

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

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

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

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

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

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

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

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

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

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

    void g(int i) {
        this.f1019c = i;
        j jVar = this.f1018b;
        h(jVar != null ? jVar.s(this.f1017a.getContext(), i) : null);
        b();
    }

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

    void i(ColorStateList colorStateList) {
        if (this.f1021e == null) {
            this.f1021e = new r0();
        }
        r0 r0Var = this.f1021e;
        r0Var.f1119a = colorStateList;
        r0Var.f1122d = true;
        b();
    }

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