content: 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;
  import androidx.appcompat.content.res.AppCompatResources;
  import androidx.core.view.ViewCompat;
  import androidx.core.widget.ImageViewCompat;
  
  public class AppCompatImageHelper {
      private TintInfo mImageTint;
      private TintInfo mInternalImageTint;
      private int mLevel = 0;
      private TintInfo mTmpInfo;
      private final ImageView mView;
  
      public AppCompatImageHelper(ImageView view) {
          this.mView = view;
      }
  
      private boolean applyFrameworkTintUsingColorFilter(Drawable imageSource) {
          if (this.mTmpInfo == null) {
              this.mTmpInfo = new TintInfo();
          }
          TintInfo tintInfo = this.mTmpInfo;
          tintInfo.clear();
          ColorStateList imageTintList = ImageViewCompat.getImageTintList(this.mView);
          if (imageTintList != null) {
              tintInfo.mHasTintList = true;
              tintInfo.mTintList = imageTintList;
          }
          PorterDuff.Mode imageTintMode = ImageViewCompat.getImageTintMode(this.mView);
          if (imageTintMode != null) {
              tintInfo.mHasTintMode = true;
              tintInfo.mTintMode = imageTintMode;
          }
          if (!tintInfo.mHasTintList && !tintInfo.mHasTintMode) {
              return false;
          }
          AppCompatDrawableManager.tintDrawable(imageSource, tintInfo, this.mView.getDrawableState());
          return true;
      }
  
      private boolean shouldApplyFrameworkTintUsingColorFilter() {
          int i = Build.VERSION.SDK_INT;
          return i > 21 ? this.mInternalImageTint != null : i == 21;
      }
  
      /* access modifiers changed from: package-private */
      public void applyImageLevel() {
          if (this.mView.getDrawable() != null) {
              this.mView.getDrawable().setLevel(this.mLevel);
          }
      }
  
      /* access modifiers changed from: package-private */
      public void applySupportImageTint() {
          Drawable drawable = this.mView.getDrawable();
          if (drawable != null) {
              DrawableUtils.fixDrawable(drawable);
          }
          if (drawable == null) {
              return;
          }
          if (!shouldApplyFrameworkTintUsingColorFilter() || !applyFrameworkTintUsingColorFilter(drawable)) {
              TintInfo tintInfo = this.mImageTint;
              if (tintInfo != null) {
                  AppCompatDrawableManager.tintDrawable(drawable, tintInfo, this.mView.getDrawableState());
                  return;
              }
              TintInfo tintInfo2 = this.mInternalImageTint;
              if (tintInfo2 != null) {
                  AppCompatDrawableManager.tintDrawable(drawable, tintInfo2, this.mView.getDrawableState());
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public ColorStateList getSupportImageTintList() {
          TintInfo tintInfo = this.mImageTint;
          if (tintInfo != null) {
              return tintInfo.mTintList;
          }
          return null;
      }
  
      /* access modifiers changed from: package-private */
      public PorterDuff.Mode getSupportImageTintMode() {
          TintInfo tintInfo = this.mImageTint;
          if (tintInfo != null) {
              return tintInfo.mTintMode;
          }
          return null;
      }
  
      /* access modifiers changed from: package-private */
      public boolean hasOverlappingRendering() {
          return Build.VERSION.SDK_INT < 21 || !(this.mView.getBackground() instanceof RippleDrawable);
      }
  
      public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
          int resourceId;
          TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(this.mView.getContext(), attrs, R.styleable.AppCompatImageView, defStyleAttr, 0);
          ImageView imageView = this.mView;
          ViewCompat.saveAttributeDataForStyleable(imageView, imageView.getContext(), R.styleable.AppCompatImageView, attrs, obtainStyledAttributes.getWrappedTypeArray(), defStyleAttr, 0);
          try {
              Drawable drawable = this.mView.getDrawable();
              if (!(drawable != null || (resourceId = obtainStyledAttributes.getResourceId(R.styleable.AppCompatImageView_srcCompat, -1)) == -1 || (drawable = AppCompatResources.getDrawable(this.mView.getContext(), resourceId)) == null)) {
                  this.mView.setImageDrawable(drawable);
              }
              if (drawable != null) {
                  DrawableUtils.fixDrawable(drawable);
              }
              if (obtainStyledAttributes.hasValue(R.styleable.AppCompatImageView_tint)) {
                  ImageViewCompat.setImageTintList(this.mView, obtainStyledAttributes.getColorStateList(R.styleable.AppCompatImageView_tint));
              }
              if (obtainStyledAttributes.hasValue(R.styleable.AppCompatImageView_tintMode)) {
                  ImageViewCompat.setImageTintMode(this.mView, DrawableUtils.parseTintMode(obtainStyledAttributes.getInt(R.styleable.AppCompatImageView_tintMode, -1), (PorterDuff.Mode) null));
              }
          } finally {
              obtainStyledAttributes.recycle();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void obtainLevelFromDrawable(Drawable drawable) {
          this.mLevel = drawable.getLevel();
      }
  
      public void setImageResource(int resId) {
          if (resId != 0) {
              Drawable drawable = AppCompatResources.getDrawable(this.mView.getContext(), resId);
              if (drawable != null) {
                  DrawableUtils.fixDrawable(drawable);
              }
              this.mView.setImageDrawable(drawable);
          } else {
              this.mView.setImageDrawable((Drawable) null);
          }
          applySupportImageTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setInternalImageTint(ColorStateList tint) {
          if (tint != null) {
              if (this.mInternalImageTint == null) {
                  this.mInternalImageTint = new TintInfo();
              }
              this.mInternalImageTint.mTintList = tint;
              this.mInternalImageTint.mHasTintList = true;
          } else {
              this.mInternalImageTint = null;
          }
          applySupportImageTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportImageTintList(ColorStateList tint) {
          if (this.mImageTint == null) {
              this.mImageTint = new TintInfo();
          }
          this.mImageTint.mTintList = tint;
          this.mImageTint.mHasTintList = true;
          applySupportImageTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportImageTintMode(PorterDuff.Mode tintMode) {
          if (this.mImageTint == null) {
              this.mImageTint = new TintInfo();
          }
          this.mImageTint.mTintMode = tintMode;
          this.mImageTint.mHasTintMode = true;
          applySupportImageTint();
      }
  }
  