package androidx.appcompat.widget;

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

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f1055e = 0;

    public q(ImageView imageView) {
        this.f1051a = imageView;
    }

    private boolean a(Drawable drawable) {
        if (this.f1054d == null) {
            this.f1054d = new y0();
        }
        y0 y0Var = this.f1054d;
        y0Var.a();
        ColorStateList colorStateListA = androidx.core.widget.f.a(this.f1051a);
        if (colorStateListA != null) {
            y0Var.f1142d = true;
            y0Var.f1139a = colorStateListA;
        }
        PorterDuff.Mode modeB = androidx.core.widget.f.b(this.f1051a);
        if (modeB != null) {
            y0Var.f1141c = true;
            y0Var.f1140b = modeB;
        }
        if (!y0Var.f1142d && !y0Var.f1141c) {
            return false;
        }
        k.i(drawable, y0Var, this.f1051a.getDrawableState());
        return true;
    }

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

    void b() {
        if (this.f1051a.getDrawable() != null) {
            this.f1051a.getDrawable().setLevel(this.f1055e);
        }
    }

    void c() {
        Drawable drawable = this.f1051a.getDrawable();
        if (drawable != null) {
            i0.b(drawable);
        }
        if (drawable != null) {
            if (l() && a(drawable)) {
                return;
            }
            y0 y0Var = this.f1053c;
            if (y0Var != null) {
                k.i(drawable, y0Var, this.f1051a.getDrawableState());
                return;
            }
            y0 y0Var2 = this.f1052b;
            if (y0Var2 != null) {
                k.i(drawable, y0Var2, this.f1051a.getDrawableState());
            }
        }
    }

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

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

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

    public void g(AttributeSet attributeSet, int i3) {
        int iN;
        Context context = this.f1051a.getContext();
        int[] iArr = c.j.M;
        a1 a1VarV = a1.v(context, attributeSet, iArr, i3, 0);
        ImageView imageView = this.f1051a;
        androidx.core.view.y.p0(imageView, imageView.getContext(), iArr, attributeSet, a1VarV.r(), i3, 0);
        try {
            Drawable drawable = this.f1051a.getDrawable();
            if (drawable == null && (iN = a1VarV.n(c.j.N, -1)) != -1 && (drawable = d.a.b(this.f1051a.getContext(), iN)) != null) {
                this.f1051a.setImageDrawable(drawable);
            }
            if (drawable != null) {
                i0.b(drawable);
            }
            int i4 = c.j.O;
            if (a1VarV.s(i4)) {
                androidx.core.widget.f.c(this.f1051a, a1VarV.c(i4));
            }
            int i5 = c.j.P;
            if (a1VarV.s(i5)) {
                androidx.core.widget.f.d(this.f1051a, i0.d(a1VarV.k(i5, -1), null));
            }
        } finally {
            a1VarV.w();
        }
    }

    void h(Drawable drawable) {
        this.f1055e = drawable.getLevel();
    }

    public void i(int i3) {
        if (i3 != 0) {
            Drawable drawableB = d.a.b(this.f1051a.getContext(), i3);
            if (drawableB != null) {
                i0.b(drawableB);
            }
            this.f1051a.setImageDrawable(drawableB);
        } else {
            this.f1051a.setImageDrawable(null);
        }
        c();
    }

    void j(ColorStateList colorStateList) {
        if (this.f1053c == null) {
            this.f1053c = new y0();
        }
        y0 y0Var = this.f1053c;
        y0Var.f1139a = colorStateList;
        y0Var.f1142d = true;
        c();
    }

    void k(PorterDuff.Mode mode) {
        if (this.f1053c == null) {
            this.f1053c = new y0();
        }
        y0 y0Var = this.f1053c;
        y0Var.f1140b = mode;
        y0Var.f1141c = true;
        c();
    }
}
