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

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

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

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

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

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

    private boolean a(Drawable drawable) {
        if (this.f1093d == null) {
            this.f1093d = new r0();
        }
        r0 r0Var = this.f1093d;
        r0Var.a();
        ColorStateList colorStateListA = android.support.v4.widget.g.a(this.f1090a);
        if (colorStateListA != null) {
            r0Var.f1122d = true;
            r0Var.f1119a = colorStateListA;
        }
        PorterDuff.Mode modeB = android.support.v4.widget.g.b(this.f1090a);
        if (modeB != null) {
            r0Var.f1121c = true;
            r0Var.f1120b = modeB;
        }
        if (!r0Var.f1122d && !r0Var.f1121c) {
            return false;
        }
        j.C(drawable, r0Var, this.f1090a.getDrawableState());
        return true;
    }

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

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

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

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

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

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

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

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

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