package androidx.appcompat.widget;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;

/* JADX INFO: compiled from: AppCompatImageHelper.java */
/* JADX INFO: loaded from: classes.dex */
public class j {

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

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

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

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

    public j(ImageView imageView) {
        this.f608a = imageView;
    }

    private boolean a(Drawable drawable) {
        if (this.f611d == null) {
            this.f611d = new g0();
        }
        g0 g0Var = this.f611d;
        g0Var.a();
        ColorStateList colorStateListA = androidx.core.widget.d.a(this.f608a);
        if (colorStateListA != null) {
            g0Var.f601d = true;
            g0Var.f598a = colorStateListA;
        }
        PorterDuff.Mode modeB = androidx.core.widget.d.b(this.f608a);
        if (modeB != null) {
            g0Var.f600c = true;
            g0Var.f599b = modeB;
        }
        if (!g0Var.f601d && !g0Var.f600c) {
            return false;
        }
        f.B(drawable, g0Var, this.f608a.getDrawableState());
        return true;
    }

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

    void b() {
        Drawable drawable = this.f608a.getDrawable();
        if (drawable != null) {
            r.b(drawable);
        }
        if (drawable != null) {
            if (j() && a(drawable)) {
                return;
            }
            g0 g0Var = this.f610c;
            if (g0Var != null) {
                f.B(drawable, g0Var, this.f608a.getDrawableState());
                return;
            }
            g0 g0Var2 = this.f609b;
            if (g0Var2 != null) {
                f.B(drawable, g0Var2, this.f608a.getDrawableState());
            }
        }
    }

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

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

    boolean e() {
        return Build.VERSION.SDK_INT < 21 || !(this.f608a.getBackground() instanceof RippleDrawable);
    }

    public void f(AttributeSet attributeSet, int i) {
        int iL;
        i0 i0VarS = i0.s(this.f608a.getContext(), attributeSet, a.a.j.T, i, 0);
        try {
            Drawable drawable = this.f608a.getDrawable();
            if (drawable == null && (iL = i0VarS.l(a.a.j.U, -1)) != -1 && (drawable = a.a.k.a.a.d(this.f608a.getContext(), iL)) != null) {
                this.f608a.setImageDrawable(drawable);
            }
            if (drawable != null) {
                r.b(drawable);
            }
            int i2 = a.a.j.V;
            if (i0VarS.p(i2)) {
                androidx.core.widget.d.c(this.f608a, i0VarS.c(i2));
            }
            int i3 = a.a.j.W;
            if (i0VarS.p(i3)) {
                androidx.core.widget.d.d(this.f608a, r.d(i0VarS.i(i3, -1), null));
            }
        } finally {
            i0VarS.t();
        }
    }

    public void g(int i) {
        if (i != 0) {
            Drawable drawableD = a.a.k.a.a.d(this.f608a.getContext(), i);
            if (drawableD != null) {
                r.b(drawableD);
            }
            this.f608a.setImageDrawable(drawableD);
        } else {
            this.f608a.setImageDrawable(null);
        }
        b();
    }

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

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