content: package androidx.appcompat.widget;
  
  import android.content.res.ColorStateList;
  import android.graphics.PorterDuff;
  import android.graphics.drawable.Drawable;
  import android.os.Build;
  import android.util.AttributeSet;
  import android.view.View;
  import androidx.appcompat.R;
  import androidx.core.view.ViewCompat;
  
  class AppCompatBackgroundHelper {
      private int mBackgroundResId = -1;
      private TintInfo mBackgroundTint;
      private final AppCompatDrawableManager mDrawableManager;
      private TintInfo mInternalBackgroundTint;
      private TintInfo mTmpInfo;
      private final View mView;
  
      AppCompatBackgroundHelper(View view) {
          this.mView = view;
          this.mDrawableManager = AppCompatDrawableManager.get();
      }
  
      private boolean applyFrameworkTintUsingColorFilter(Drawable background) {
          if (this.mTmpInfo == null) {
              this.mTmpInfo = new TintInfo();
          }
          TintInfo tintInfo = this.mTmpInfo;
          tintInfo.clear();
          ColorStateList backgroundTintList = ViewCompat.getBackgroundTintList(this.mView);
          if (backgroundTintList != null) {
              tintInfo.mHasTintList = true;
              tintInfo.mTintList = backgroundTintList;
          }
          PorterDuff.Mode backgroundTintMode = ViewCompat.getBackgroundTintMode(this.mView);
          if (backgroundTintMode != null) {
              tintInfo.mHasTintMode = true;
              tintInfo.mTintMode = backgroundTintMode;
          }
          if (!tintInfo.mHasTintList && !tintInfo.mHasTintMode) {
              return false;
          }
          AppCompatDrawableManager.tintDrawable(background, tintInfo, this.mView.getDrawableState());
          return true;
      }
  
      private boolean shouldApplyFrameworkTintUsingColorFilter() {
          int i = Build.VERSION.SDK_INT;
          return i > 21 ? this.mInternalBackgroundTint != null : i == 21;
      }
  
      /* access modifiers changed from: package-private */
      public void applySupportBackgroundTint() {
          Drawable background = this.mView.getBackground();
          if (background == null) {
              return;
          }
          if (!shouldApplyFrameworkTintUsingColorFilter() || !applyFrameworkTintUsingColorFilter(background)) {
              TintInfo tintInfo = this.mBackgroundTint;
              if (tintInfo != null) {
                  AppCompatDrawableManager.tintDrawable(background, tintInfo, this.mView.getDrawableState());
                  return;
              }
              TintInfo tintInfo2 = this.mInternalBackgroundTint;
              if (tintInfo2 != null) {
                  AppCompatDrawableManager.tintDrawable(background, tintInfo2, this.mView.getDrawableState());
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public ColorStateList getSupportBackgroundTintList() {
          TintInfo tintInfo = this.mBackgroundTint;
          if (tintInfo != null) {
              return tintInfo.mTintList;
          }
          return null;
      }
  
      /* access modifiers changed from: package-private */
      public PorterDuff.Mode getSupportBackgroundTintMode() {
          TintInfo tintInfo = this.mBackgroundTint;
          if (tintInfo != null) {
              return tintInfo.mTintMode;
          }
          return null;
      }
  
      /* access modifiers changed from: package-private */
      public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
          TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(this.mView.getContext(), attrs, R.styleable.ViewBackgroundHelper, defStyleAttr, 0);
          View view = this.mView;
          ViewCompat.saveAttributeDataForStyleable(view, view.getContext(), R.styleable.ViewBackgroundHelper, attrs, obtainStyledAttributes.getWrappedTypeArray(), defStyleAttr, 0);
          try {
              if (obtainStyledAttributes.hasValue(R.styleable.ViewBackgroundHelper_android_background)) {
                  this.mBackgroundResId = obtainStyledAttributes.getResourceId(R.styleable.ViewBackgroundHelper_android_background, -1);
                  ColorStateList tintList = this.mDrawableManager.getTintList(this.mView.getContext(), this.mBackgroundResId);
                  if (tintList != null) {
                      setInternalBackgroundTint(tintList);
                  }
              }
              if (obtainStyledAttributes.hasValue(R.styleable.ViewBackgroundHelper_backgroundTint)) {
                  ViewCompat.setBackgroundTintList(this.mView, obtainStyledAttributes.getColorStateList(R.styleable.ViewBackgroundHelper_backgroundTint));
              }
              if (obtainStyledAttributes.hasValue(R.styleable.ViewBackgroundHelper_backgroundTintMode)) {
                  ViewCompat.setBackgroundTintMode(this.mView, DrawableUtils.parseTintMode(obtainStyledAttributes.getInt(R.styleable.ViewBackgroundHelper_backgroundTintMode, -1), (PorterDuff.Mode) null));
              }
          } finally {
              obtainStyledAttributes.recycle();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void onSetBackgroundDrawable(Drawable background) {
          this.mBackgroundResId = -1;
          setInternalBackgroundTint((ColorStateList) null);
          applySupportBackgroundTint();
      }
  
      /* access modifiers changed from: package-private */
      public void onSetBackgroundResource(int resId) {
          this.mBackgroundResId = resId;
          AppCompatDrawableManager appCompatDrawableManager = this.mDrawableManager;
          setInternalBackgroundTint(appCompatDrawableManager != null ? appCompatDrawableManager.getTintList(this.mView.getContext(), resId) : null);
          applySupportBackgroundTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setInternalBackgroundTint(ColorStateList tint) {
          if (tint != null) {
              if (this.mInternalBackgroundTint == null) {
                  this.mInternalBackgroundTint = new TintInfo();
              }
              this.mInternalBackgroundTint.mTintList = tint;
              this.mInternalBackgroundTint.mHasTintList = true;
          } else {
              this.mInternalBackgroundTint = null;
          }
          applySupportBackgroundTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportBackgroundTintList(ColorStateList tint) {
          if (this.mBackgroundTint == null) {
              this.mBackgroundTint = new TintInfo();
          }
          this.mBackgroundTint.mTintList = tint;
          this.mBackgroundTint.mHasTintList = true;
          applySupportBackgroundTint();
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportBackgroundTintMode(PorterDuff.Mode tintMode) {
          if (this.mBackgroundTint == null) {
              this.mBackgroundTint = new TintInfo();
          }
          this.mBackgroundTint.mTintMode = tintMode;
          this.mBackgroundTint.mHasTintMode = true;
          applySupportBackgroundTint();
      }
  }
  