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; import androidx.appcompat.R$styleable; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.widget.ImageViewCompat; /* loaded from: classes.dex */ public class AppCompatImageHelper { private final ImageView a; private TintInfo b; private TintInfo c; private TintInfo d; public AppCompatImageHelper(ImageView imageView) { this.a = imageView; } private boolean e() { int i = Build.VERSION.SDK_INT; return i > 21 ? this.b != null : i == 21; } public void a(AttributeSet attributeSet, int i) { int g; TintTypedArray a = TintTypedArray.a(this.a.getContext(), attributeSet, R$styleable.AppCompatImageView, i, 0); try { Drawable drawable = this.a.getDrawable(); if (drawable == null && (g = a.g(R$styleable.AppCompatImageView_srcCompat, -1)) != -1 && (drawable = AppCompatResources.c(this.a.getContext(), g)) != null) { this.a.setImageDrawable(drawable); } if (drawable != null) { DrawableUtils.b(drawable); } if (a.g(R$styleable.AppCompatImageView_tint)) { ImageViewCompat.a(this.a, a.a(R$styleable.AppCompatImageView_tint)); } if (a.g(R$styleable.AppCompatImageView_tintMode)) { ImageViewCompat.a(this.a, DrawableUtils.a(a.d(R$styleable.AppCompatImageView_tintMode, -1), null)); } } finally { a.a(); } } ColorStateList b() { TintInfo tintInfo = this.c; if (tintInfo != null) { return tintInfo.a; } return null; } PorterDuff.Mode c() { TintInfo tintInfo = this.c; if (tintInfo != null) { return tintInfo.b; } return null; } boolean d() { return Build.VERSION.SDK_INT < 21 || !(this.a.getBackground() instanceof RippleDrawable); } public void a(int i) { if (i != 0) { Drawable c = AppCompatResources.c(this.a.getContext(), i); if (c != null) { DrawableUtils.b(c); } this.a.setImageDrawable(c); } else { this.a.setImageDrawable(null); } a(); } void a(ColorStateList colorStateList) { if (this.c == null) { this.c = new TintInfo(); } TintInfo tintInfo = this.c; tintInfo.a = colorStateList; tintInfo.d = true; a(); } void a(PorterDuff.Mode mode) { if (this.c == null) { this.c = new TintInfo(); } TintInfo tintInfo = this.c; tintInfo.b = mode; tintInfo.c = true; a(); } void a() { Drawable drawable = this.a.getDrawable(); if (drawable != null) { DrawableUtils.b(drawable); } if (drawable != null) { if (e() && a(drawable)) { return; } TintInfo tintInfo = this.c; if (tintInfo != null) { AppCompatDrawableManager.a(drawable, tintInfo, this.a.getDrawableState()); return; } TintInfo tintInfo2 = this.b; if (tintInfo2 != null) { AppCompatDrawableManager.a(drawable, tintInfo2, this.a.getDrawableState()); } } } private boolean a(Drawable drawable) { if (this.d == null) { this.d = new TintInfo(); } TintInfo tintInfo = this.d; tintInfo.a(); ColorStateList a = ImageViewCompat.a(this.a); if (a != null) { tintInfo.d = true; tintInfo.a = a; } PorterDuff.Mode b = ImageViewCompat.b(this.a); if (b != null) { tintInfo.c = true; tintInfo.b = b; } if (!tintInfo.d && !tintInfo.c) { return false; } AppCompatDrawableManager.a(drawable, tintInfo, this.a.getDrawableState()); return true; } }