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 n {
    private final ImageView a;
    private r0 b;
    private r0 c;
    private r0 d;

    public n(ImageView imageView) {
        this.a = imageView;
    }

    private boolean a(Drawable drawable) {
        if (this.d == null) {
            this.d = new r0();
        }
        r0 r0Var = this.d;
        r0Var.a();
        ColorStateList colorStateListA = androidx.core.widget.e.a(this.a);
        if (colorStateListA != null) {
            r0Var.d = true;
            r0Var.a = colorStateListA;
        }
        PorterDuff.Mode modeB = androidx.core.widget.e.b(this.a);
        if (modeB != null) {
            r0Var.c = true;
            r0Var.b = modeB;
        }
        if (!r0Var.d && !r0Var.c) {
            return false;
        }
        j.C(drawable, r0Var, this.a.getDrawableState());
        return true;
    }

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

    void b() {
        Drawable drawable = this.a.getDrawable();
        if (drawable != null) {
            c0.b(drawable);
        }
        if (drawable != null) {
            if (j() && a(drawable)) {
                return;
            }
            r0 r0Var = this.c;
            if (r0Var != null) {
                j.C(drawable, r0Var, this.a.getDrawableState());
                return;
            }
            r0 r0Var2 = this.b;
            if (r0Var2 != null) {
                j.C(drawable, r0Var2, this.a.getDrawableState());
            }
        }
    }

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

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

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

    public void f(AttributeSet attributeSet, int i2) {
        int iM;
        t0 t0VarT = t0.t(this.a.getContext(), attributeSet, g.a.j.AppCompatImageView, i2, 0);
        try {
            Drawable drawable = this.a.getDrawable();
            if (drawable == null && (iM = t0VarT.m(g.a.j.AppCompatImageView_srcCompat, -1)) != -1 && (drawable = g.a.k.a.a.d(this.a.getContext(), iM)) != null) {
                this.a.setImageDrawable(drawable);
            }
            if (drawable != null) {
                c0.b(drawable);
            }
            if (t0VarT.q(g.a.j.AppCompatImageView_tint)) {
                androidx.core.widget.e.c(this.a, t0VarT.c(g.a.j.AppCompatImageView_tint));
            }
            if (t0VarT.q(g.a.j.AppCompatImageView_tintMode)) {
                androidx.core.widget.e.d(this.a, c0.d(t0VarT.j(g.a.j.AppCompatImageView_tintMode, -1), null));
            }
        } finally {
            t0VarT.u();
        }
    }

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

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

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