package androidx.appcompat.widget;

import android.content.Context;
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 f879a;

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

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

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

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

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

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

    private boolean a(Drawable drawable) {
        if (this.f884f == null) {
            this.f884f = new y0();
        }
        y0 y0Var = this.f884f;
        y0Var.a();
        ColorStateList colorStateListU = androidx.core.view.y.u(this.f879a);
        if (colorStateListU != null) {
            y0Var.f1142d = true;
            y0Var.f1139a = colorStateListU;
        }
        PorterDuff.Mode modeV = androidx.core.view.y.v(this.f879a);
        if (modeV != null) {
            y0Var.f1141c = true;
            y0Var.f1140b = modeV;
        }
        if (!y0Var.f1142d && !y0Var.f1141c) {
            return false;
        }
        k.i(drawable, y0Var, this.f879a.getDrawableState());
        return true;
    }

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

    void b() {
        Drawable background = this.f879a.getBackground();
        if (background != null) {
            if (k() && a(background)) {
                return;
            }
            y0 y0Var = this.f883e;
            if (y0Var != null) {
                k.i(background, y0Var, this.f879a.getDrawableState());
                return;
            }
            y0 y0Var2 = this.f882d;
            if (y0Var2 != null) {
                k.i(background, y0Var2, this.f879a.getDrawableState());
            }
        }
    }

    ColorStateList c() {
        y0 y0Var = this.f883e;
        if (y0Var != null) {
            return y0Var.f1139a;
        }
        return null;
    }

    PorterDuff.Mode d() {
        y0 y0Var = this.f883e;
        if (y0Var != null) {
            return y0Var.f1140b;
        }
        return null;
    }

    void e(AttributeSet attributeSet, int i3) {
        Context context = this.f879a.getContext();
        int[] iArr = c.j.r3;
        a1 a1VarV = a1.v(context, attributeSet, iArr, i3, 0);
        View view = this.f879a;
        androidx.core.view.y.p0(view, view.getContext(), iArr, attributeSet, a1VarV.r(), i3, 0);
        try {
            int i4 = c.j.s3;
            if (a1VarV.s(i4)) {
                this.f881c = a1VarV.n(i4, -1);
                ColorStateList colorStateListF = this.f880b.f(this.f879a.getContext(), this.f881c);
                if (colorStateListF != null) {
                    h(colorStateListF);
                }
            }
            int i5 = c.j.t3;
            if (a1VarV.s(i5)) {
                androidx.core.view.y.w0(this.f879a, a1VarV.c(i5));
            }
            int i6 = c.j.u3;
            if (a1VarV.s(i6)) {
                androidx.core.view.y.x0(this.f879a, i0.d(a1VarV.k(i6, -1), null));
            }
        } finally {
            a1VarV.w();
        }
    }

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

    void g(int i3) {
        this.f881c = i3;
        k kVar = this.f880b;
        h(kVar != null ? kVar.f(this.f879a.getContext(), i3) : null);
        b();
    }

    void h(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.f882d == null) {
                this.f882d = new y0();
            }
            y0 y0Var = this.f882d;
            y0Var.f1139a = colorStateList;
            y0Var.f1142d = true;
        } else {
            this.f882d = null;
        }
        b();
    }

    void i(ColorStateList colorStateList) {
        if (this.f883e == null) {
            this.f883e = new y0();
        }
        y0 y0Var = this.f883e;
        y0Var.f1139a = colorStateList;
        y0Var.f1142d = true;
        b();
    }

    void j(PorterDuff.Mode mode) {
        if (this.f883e == null) {
            this.f883e = new y0();
        }
        y0 y0Var = this.f883e;
        y0Var.f1140b = mode;
        y0Var.f1141c = true;
        b();
    }
}
