content: package com.google.android.material.button;
  
  import android.content.res.ColorStateList;
  import android.content.res.TypedArray;
  import android.graphics.PorterDuff;
  import android.graphics.drawable.Drawable;
  import android.graphics.drawable.InsetDrawable;
  import android.graphics.drawable.LayerDrawable;
  import android.graphics.drawable.RippleDrawable;
  import android.os.Build;
  import androidx.core.graphics.drawable.DrawableCompat;
  import androidx.core.view.ViewCompat;
  import com.google.android.material.R;
  import com.google.android.material.color.MaterialColors;
  import com.google.android.material.internal.ViewUtils;
  import com.google.android.material.resources.MaterialResources;
  import com.google.android.material.ripple.RippleDrawableCompat;
  import com.google.android.material.ripple.RippleUtils;
  import com.google.android.material.shape.MaterialShapeDrawable;
  import com.google.android.material.shape.ShapeAppearanceModel;
  import com.google.android.material.shape.Shapeable;
  
  class MaterialButtonHelper {
      private static final boolean IS_LOLLIPOP;
      private static final boolean IS_MIN_LOLLIPOP = (Build.VERSION.SDK_INT >= 21);
      private boolean backgroundOverwritten = false;
      private ColorStateList backgroundTint;
      private PorterDuff.Mode backgroundTintMode;
      private boolean checkable;
      private int cornerRadius;
      private boolean cornerRadiusSet = false;
      private int elevation;
      private int insetBottom;
      private int insetLeft;
      private int insetRight;
      private int insetTop;
      private Drawable maskDrawable;
      private final MaterialButton materialButton;
      private ColorStateList rippleColor;
      private LayerDrawable rippleDrawable;
      private ShapeAppearanceModel shapeAppearanceModel;
      private boolean shouldDrawSurfaceColorStroke = false;
      private ColorStateList strokeColor;
      private int strokeWidth;
  
      static {
          boolean z = true;
          if (Build.VERSION.SDK_INT < 21 || Build.VERSION.SDK_INT > 22) {
              z = false;
          }
          IS_LOLLIPOP = z;
      }
  
      MaterialButtonHelper(MaterialButton button, ShapeAppearanceModel shapeAppearanceModel2) {
          this.materialButton = button;
          this.shapeAppearanceModel = shapeAppearanceModel2;
      }
  
      private Drawable createBackground() {
          MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable(this.shapeAppearanceModel);
          materialShapeDrawable.initializeElevationOverlay(this.materialButton.getContext());
          DrawableCompat.setTintList(materialShapeDrawable, this.backgroundTint);
          PorterDuff.Mode mode = this.backgroundTintMode;
          if (mode != null) {
              DrawableCompat.setTintMode(materialShapeDrawable, mode);
          }
          materialShapeDrawable.setStroke((float) this.strokeWidth, this.strokeColor);
          MaterialShapeDrawable materialShapeDrawable2 = new MaterialShapeDrawable(this.shapeAppearanceModel);
          materialShapeDrawable2.setTint(0);
          materialShapeDrawable2.setStroke((float) this.strokeWidth, this.shouldDrawSurfaceColorStroke ? MaterialColors.getColor(this.materialButton, R.attr.colorSurface) : 0);
          if (IS_MIN_LOLLIPOP) {
              MaterialShapeDrawable materialShapeDrawable3 = new MaterialShapeDrawable(this.shapeAppearanceModel);
              this.maskDrawable = materialShapeDrawable3;
              DrawableCompat.setTint(materialShapeDrawable3, -1);
              RippleDrawable rippleDrawable2 = new RippleDrawable(RippleUtils.sanitizeRippleDrawableColor(this.rippleColor), wrapDrawableWithInset(new LayerDrawable(new Drawable[]{materialShapeDrawable2, materialShapeDrawable})), this.maskDrawable);
              this.rippleDrawable = rippleDrawable2;
              return rippleDrawable2;
          }
          RippleDrawableCompat rippleDrawableCompat = new RippleDrawableCompat(this.shapeAppearanceModel);
          this.maskDrawable = rippleDrawableCompat;
          DrawableCompat.setTintList(rippleDrawableCompat, RippleUtils.sanitizeRippleDrawableColor(this.rippleColor));
          LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{materialShapeDrawable2, materialShapeDrawable, this.maskDrawable});
          this.rippleDrawable = layerDrawable;
          return wrapDrawableWithInset(layerDrawable);
      }
  
      private MaterialShapeDrawable getMaterialShapeDrawable(boolean getSurfaceColorStrokeDrawable) {
          LayerDrawable layerDrawable = this.rippleDrawable;
          if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 0) {
              return null;
          }
          return IS_MIN_LOLLIPOP ? (MaterialShapeDrawable) ((LayerDrawable) ((InsetDrawable) this.rippleDrawable.getDrawable(0)).getDrawable()).getDrawable(getSurfaceColorStrokeDrawable ^ true ? 1 : 0) : (MaterialShapeDrawable) this.rippleDrawable.getDrawable(getSurfaceColorStrokeDrawable ^ true ? 1 : 0);
      }
  
      private MaterialShapeDrawable getSurfaceColorStrokeDrawable() {
          return getMaterialShapeDrawable(true);
      }
  
      private void setVerticalInsets(int newInsetTop, int newInsetBottom) {
          int paddingStart = ViewCompat.getPaddingStart(this.materialButton);
          int paddingTop = this.materialButton.getPaddingTop();
          int paddingEnd = ViewCompat.getPaddingEnd(this.materialButton);
          int paddingBottom = this.materialButton.getPaddingBottom();
          int i = this.insetTop;
          int i2 = this.insetBottom;
          this.insetBottom = newInsetBottom;
          this.insetTop = newInsetTop;
          if (!this.backgroundOverwritten) {
              updateBackground();
          }
          ViewCompat.setPaddingRelative(this.materialButton, paddingStart, (paddingTop + newInsetTop) - i, paddingEnd, (paddingBottom + newInsetBottom) - i2);
      }
  
      private void updateBackground() {
          this.materialButton.setInternalBackground(createBackground());
          MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
          if (materialShapeDrawable != null) {
              materialShapeDrawable.setElevation((float) this.elevation);
          }
      }
  
      private void updateButtonShape(ShapeAppearanceModel shapeAppearanceModel2) {
          if (!IS_LOLLIPOP || this.backgroundOverwritten) {
              if (getMaterialShapeDrawable() != null) {
                  getMaterialShapeDrawable().setShapeAppearanceModel(shapeAppearanceModel2);
              }
              if (getSurfaceColorStrokeDrawable() != null) {
                  getSurfaceColorStrokeDrawable().setShapeAppearanceModel(shapeAppearanceModel2);
              }
              if (getMaskDrawable() != null) {
                  getMaskDrawable().setShapeAppearanceModel(shapeAppearanceModel2);
                  return;
              }
              return;
          }
          int paddingStart = ViewCompat.getPaddingStart(this.materialButton);
          int paddingTop = this.materialButton.getPaddingTop();
          int paddingEnd = ViewCompat.getPaddingEnd(this.materialButton);
          int paddingBottom = this.materialButton.getPaddingBottom();
          updateBackground();
          ViewCompat.setPaddingRelative(this.materialButton, paddingStart, paddingTop, paddingEnd, paddingBottom);
      }
  
      private void updateStroke() {
          MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
          MaterialShapeDrawable surfaceColorStrokeDrawable = getSurfaceColorStrokeDrawable();
          if (materialShapeDrawable != null) {
              materialShapeDrawable.setStroke((float) this.strokeWidth, this.strokeColor);
              if (surfaceColorStrokeDrawable != null) {
                  surfaceColorStrokeDrawable.setStroke((float) this.strokeWidth, this.shouldDrawSurfaceColorStroke ? MaterialColors.getColor(this.materialButton, R.attr.colorSurface) : 0);
              }
          }
      }
  
      private InsetDrawable wrapDrawableWithInset(Drawable drawable) {
          return new InsetDrawable(drawable, this.insetLeft, this.insetTop, this.insetRight, this.insetBottom);
      }
  
      /* access modifiers changed from: package-private */
      public int getCornerRadius() {
          return this.cornerRadius;
      }
  
      public int getInsetBottom() {
          return this.insetBottom;
      }
  
      public int getInsetTop() {
          return this.insetTop;
      }
  
      public Shapeable getMaskDrawable() {
          LayerDrawable layerDrawable = this.rippleDrawable;
          if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 1) {
              return null;
          }
          return this.rippleDrawable.getNumberOfLayers() > 2 ? (Shapeable) this.rippleDrawable.getDrawable(2) : (Shapeable) this.rippleDrawable.getDrawable(1);
      }
  
      /* access modifiers changed from: package-private */
      public MaterialShapeDrawable getMaterialShapeDrawable() {
          return getMaterialShapeDrawable(false);
      }
  
      /* access modifiers changed from: package-private */
      public ColorStateList getRippleColor() {
          return this.rippleColor;
      }
  
      /* access modifiers changed from: package-private */
      public ShapeAppearanceModel getShapeAppearanceModel() {
          return this.shapeAppearanceModel;
      }
  
      /* access modifiers changed from: package-private */
      public ColorStateList getStrokeColor() {
          return this.strokeColor;
      }
  
      /* access modifiers changed from: package-private */
      public int getStrokeWidth() {
          return this.strokeWidth;
      }
  
      /* access modifiers changed from: package-private */
      public ColorStateList getSupportBackgroundTintList() {
          return this.backgroundTint;
      }
  
      /* access modifiers changed from: package-private */
      public PorterDuff.Mode getSupportBackgroundTintMode() {
          return this.backgroundTintMode;
      }
  
      /* access modifiers changed from: package-private */
      public boolean isBackgroundOverwritten() {
          return this.backgroundOverwritten;
      }
  
      /* access modifiers changed from: package-private */
      public boolean isCheckable() {
          return this.checkable;
      }
  
      /* access modifiers changed from: package-private */
      public void loadFromAttributes(TypedArray attributes) {
          this.insetLeft = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetLeft, 0);
          this.insetRight = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetRight, 0);
          this.insetTop = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetTop, 0);
          this.insetBottom = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetBottom, 0);
          if (attributes.hasValue(R.styleable.MaterialButton_cornerRadius)) {
              int dimensionPixelSize = attributes.getDimensionPixelSize(R.styleable.MaterialButton_cornerRadius, -1);
              this.cornerRadius = dimensionPixelSize;
              setShapeAppearanceModel(this.shapeAppearanceModel.withCornerSize((float) dimensionPixelSize));
              this.cornerRadiusSet = true;
          }
          this.strokeWidth = attributes.getDimensionPixelSize(R.styleable.MaterialButton_strokeWidth, 0);
          this.backgroundTintMode = ViewUtils.parseTintMode(attributes.getInt(R.styleable.MaterialButton_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN);
          this.backgroundTint = MaterialResources.getColorStateList(this.materialButton.getContext(), attributes, R.styleable.MaterialButton_backgroundTint);
          this.strokeColor = MaterialResources.getColorStateList(this.materialButton.getContext(), attributes, R.styleable.MaterialButton_strokeColor);
          this.rippleColor = MaterialResources.getColorStateList(this.materialButton.getContext(), attributes, R.styleable.MaterialButton_rippleColor);
          this.checkable = attributes.getBoolean(R.styleable.MaterialButton_android_checkable, false);
          this.elevation = attributes.getDimensionPixelSize(R.styleable.MaterialButton_elevation, 0);
          int paddingStart = ViewCompat.getPaddingStart(this.materialButton);
          int paddingTop = this.materialButton.getPaddingTop();
          int paddingEnd = ViewCompat.getPaddingEnd(this.materialButton);
          int paddingBottom = this.materialButton.getPaddingBottom();
          if (attributes.hasValue(R.styleable.MaterialButton_android_background)) {
              setBackgroundOverwritten();
          } else {
              updateBackground();
          }
          ViewCompat.setPaddingRelative(this.materialButton, this.insetLeft + paddingStart, this.insetTop + paddingTop, this.insetRight + paddingEnd, this.insetBottom + paddingBottom);
      }
  
      /* access modifiers changed from: package-private */
      public void setBackgroundColor(int color) {
          if (getMaterialShapeDrawable() != null) {
              getMaterialShapeDrawable().setTint(color);
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setBackgroundOverwritten() {
          this.backgroundOverwritten = true;
          this.materialButton.setSupportBackgroundTintList(this.backgroundTint);
          this.materialButton.setSupportBackgroundTintMode(this.backgroundTintMode);
      }
  
      /* access modifiers changed from: package-private */
      public void setCheckable(boolean checkable2) {
          this.checkable = checkable2;
      }
  
      /* access modifiers changed from: package-private */
      public void setCornerRadius(int cornerRadius2) {
          if (!this.cornerRadiusSet || this.cornerRadius != cornerRadius2) {
              this.cornerRadius = cornerRadius2;
              this.cornerRadiusSet = true;
              setShapeAppearanceModel(this.shapeAppearanceModel.withCornerSize((float) cornerRadius2));
          }
      }
  
      public void setInsetBottom(int newInsetBottom) {
          setVerticalInsets(this.insetTop, newInsetBottom);
      }
  
      public void setInsetTop(int newInsetTop) {
          setVerticalInsets(newInsetTop, this.insetBottom);
      }
  
      /* access modifiers changed from: package-private */
      public void setRippleColor(ColorStateList rippleColor2) {
          if (this.rippleColor != rippleColor2) {
              this.rippleColor = rippleColor2;
              boolean z = IS_MIN_LOLLIPOP;
              if (z && (this.materialButton.getBackground() instanceof RippleDrawable)) {
                  ((RippleDrawable) this.materialButton.getBackground()).setColor(RippleUtils.sanitizeRippleDrawableColor(rippleColor2));
              } else if (!z && (this.materialButton.getBackground() instanceof RippleDrawableCompat)) {
                  ((RippleDrawableCompat) this.materialButton.getBackground()).setTintList(RippleUtils.sanitizeRippleDrawableColor(rippleColor2));
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel2) {
          this.shapeAppearanceModel = shapeAppearanceModel2;
          updateButtonShape(shapeAppearanceModel2);
      }
  
      /* access modifiers changed from: package-private */
      public void setShouldDrawSurfaceColorStroke(boolean shouldDrawSurfaceColorStroke2) {
          this.shouldDrawSurfaceColorStroke = shouldDrawSurfaceColorStroke2;
          updateStroke();
      }
  
      /* access modifiers changed from: package-private */
      public void setStrokeColor(ColorStateList strokeColor2) {
          if (this.strokeColor != strokeColor2) {
              this.strokeColor = strokeColor2;
              updateStroke();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setStrokeWidth(int strokeWidth2) {
          if (this.strokeWidth != strokeWidth2) {
              this.strokeWidth = strokeWidth2;
              updateStroke();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportBackgroundTintList(ColorStateList tintList) {
          if (this.backgroundTint != tintList) {
              this.backgroundTint = tintList;
              if (getMaterialShapeDrawable() != null) {
                  DrawableCompat.setTintList(getMaterialShapeDrawable(), this.backgroundTint);
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
          if (this.backgroundTintMode != mode) {
              this.backgroundTintMode = mode;
              if (getMaterialShapeDrawable() != null && this.backgroundTintMode != null) {
                  DrawableCompat.setTintMode(getMaterialShapeDrawable(), this.backgroundTintMode);
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void updateMaskBounds(int height, int width) {
          Drawable drawable = this.maskDrawable;
          if (drawable != null) {
              drawable.setBounds(this.insetLeft, this.insetTop, width - this.insetRight, height - this.insetBottom);
          }
      }
  }
  