package com.google.android.material.button;

import android.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.text.Layout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.StateSet;
import android.util.TypedValue;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.Dimension;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.RestrictTo;
import androidx.appcompat.widget.AppCompatButton;
import com.bumptech.glide.f;
import com.google.android.material.internal.w0;
import com.google.android.material.shape.StateListSizeChange$SizeChangeType;
import com.google.android.material.shape.g0;
import com.google.android.material.shape.k;
import com.google.android.material.shape.n0;
import com.google.android.material.shape.p0;
import com.google.android.material.shape.q;
import com.google.android.material.shape.q0;
import com.google.android.material.shape.s;
import e1.m;
import e1.n;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.LinkedHashSet;
import x8.l;
import xyz.stream.api.a0;

/* JADX INFO: loaded from: classes2.dex */
public class MaterialButton extends AppCompatButton implements Checkable, g0 {

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static final int[] f22339d0 = {R.attr.state_checkable};

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public static final int[] f22340e0 = {R.attr.state_checked};

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public static final int f22341f0 = l.Widget_MaterialComponents_Button;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public static final int f22342g0 = x8.c.materialSizeOverlay;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public static final c5.d f22343h0 = new c5.d("widthIncrease", 0);
    public float Q;
    public int R;
    public int S;
    public boolean T;
    public int U;
    public boolean V;
    public int W;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public int f22344a0;

    @Nullable
    private String accessibilityClassName;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public float f22345b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public float f22346c0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final d f22347d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final LinkedHashSet f22348e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f22349f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f22350g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f22351h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f22352i;

    @Nullable
    private Drawable icon;

    @Nullable
    private ColorStateList iconTint;

    @Nullable
    private PorterDuff.Mode iconTintMode;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f22353j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f22354k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f22355l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f22356m;

    @Nullable
    private a onPressedChangeListenerInternal;

    @Nullable
    private LinearLayout.LayoutParams originalLayoutParams;

    @Nullable
    q0 sizeChange;

    @Nullable
    private m widthIncreaseSpringAnimation;

    @Retention(RetentionPolicy.SOURCE)
    public @interface IconGravity {
    }

    public MaterialButton(@NonNull Context context) {
        this(context, null);
    }

    public static /* synthetic */ void a(MaterialButton materialButton) {
        materialButton.U = materialButton.getOpticalCenterShift();
        materialButton.l();
        materialButton.invalidate();
    }

    private Layout.Alignment getActualTextAlignment() {
        int textAlignment = getTextAlignment();
        return textAlignment != 1 ? (textAlignment == 6 || textAlignment == 3) ? Layout.Alignment.ALIGN_OPPOSITE : textAlignment != 4 ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER : getGravityTextAlignment();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public float getDisplayedWidthIncrease() {
        return this.f22345b0;
    }

    private Layout.Alignment getGravityTextAlignment() {
        int gravity = getGravity() & 8388615;
        return gravity != 1 ? (gravity == 5 || gravity == 8388613) ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    }

    private int getOpticalCenterShift() {
        k materialShapeDrawable;
        if (this.T && this.V && (materialShapeDrawable = this.f22347d.getMaterialShapeDrawable()) != null) {
            return (int) (materialShapeDrawable.m() * 0.11f);
        }
        return 0;
    }

    private int getTextHeight() {
        if (getLineCount() > 1) {
            return getLayout().getHeight();
        }
        TextPaint paint = getPaint();
        String string = getText().toString();
        if (getTransformationMethod() != null) {
            string = getTransformationMethod().getTransformation(string, this).toString();
        }
        Rect rect = new Rect();
        paint.getTextBounds(string, 0, string.length(), rect);
        return Math.min(rect.height(), getLayout().getHeight());
    }

    private int getTextLayoutWidth() {
        int lineCount = getLineCount();
        float fMax = 0.0f;
        for (int i10 = 0; i10 < lineCount; i10++) {
            fMax = Math.max(fMax, getLayout().getLineWidth(i10));
        }
        return (int) Math.ceil(fMax);
    }

    private void setCheckedInternal(boolean z10) {
        if (!e() || this.f22353j == z10) {
            return;
        }
        this.f22353j = z10;
        refreshDrawableState();
        if (getParent() instanceof MaterialButtonToggleGroup) {
            MaterialButtonToggleGroup materialButtonToggleGroup = (MaterialButtonToggleGroup) getParent();
            boolean z11 = this.f22353j;
            if (!materialButtonToggleGroup.f22366j) {
                materialButtonToggleGroup.h(getId(), z11);
            }
        }
        if (this.f22354k) {
            return;
        }
        this.f22354k = true;
        for (e eVar : this.f22348e) {
            boolean z12 = this.f22353j;
            eVar.getClass();
            int i10 = MaterialSplitButton.f22370i;
            setStateDescription(eVar.f22389a.getResources().getString(z12 ? x8.k.mtrl_button_expanded_content_description : x8.k.mtrl_button_collapsed_content_description));
        }
        this.f22354k = false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void setDisplayedWidthIncrease(float f10) {
        if (this.f22345b0 != f10) {
            this.f22345b0 = f10;
            l();
            invalidate();
            if (getParent() instanceof MaterialButtonGroup) {
                ((MaterialButtonGroup) getParent()).d(this, (int) this.f22345b0);
            }
        }
    }

    public final n d() {
        Context context = getContext();
        int i10 = x8.c.motionSpringFastSpatial;
        int i11 = l.Motion_Material3_Spring_Standard_Fast_Spatial;
        TypedValue typedValueResolve = q9.c.resolve(context, i10);
        TypedArray typedArrayObtainStyledAttributes = typedValueResolve == null ? context.obtainStyledAttributes(null, x8.m.MaterialSpring, 0, i11) : context.obtainStyledAttributes(typedValueResolve.resourceId, x8.m.MaterialSpring);
        n nVar = new n();
        try {
            float f10 = typedArrayObtainStyledAttributes.getFloat(x8.m.MaterialSpring_stiffness, Float.MIN_VALUE);
            if (f10 == Float.MIN_VALUE) {
                throw new IllegalArgumentException("A MaterialSpring style must have stiffness value.");
            }
            float f11 = typedArrayObtainStyledAttributes.getFloat(x8.m.MaterialSpring_damping, Float.MIN_VALUE);
            if (f11 == Float.MIN_VALUE) {
                throw new IllegalArgumentException("A MaterialSpring style must have a damping value.");
            }
            nVar.b(f10);
            nVar.a(f11);
            return nVar;
        } finally {
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public final boolean e() {
        d dVar = this.f22347d;
        return dVar != null && dVar.f22385l;
    }

    public final boolean f() {
        d dVar = this.f22347d;
        return (dVar == null || dVar.f22383j) ? false : true;
    }

    /* JADX WARN: Removed duplicated region for block: B:39:0x007f  */
    /* JADX WARN: Removed duplicated region for block: B:46:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void g(boolean z10) {
        int i10;
        if (this.sizeChange == null) {
            return;
        }
        if (this.widthIncreaseSpringAnimation == null) {
            m mVar = new m(this, f22343h0);
            this.widthIncreaseSpringAnimation = mVar;
            mVar.f25431s = d();
        }
        if (!this.V) {
            return;
        }
        int i11 = this.f22344a0;
        q0 q0Var = this.sizeChange;
        int[] drawableState = getDrawableState();
        int[][] iArr = q0Var.f23148c;
        int i12 = 0;
        int i13 = 0;
        while (true) {
            i10 = -1;
            if (i13 >= q0Var.f23146a) {
                i13 = -1;
                break;
            } else if (StateSet.stateSetMatches(iArr[i13], drawableState)) {
                break;
            } else {
                i13++;
            }
        }
        if (i13 < 0) {
            int[] iArr2 = StateSet.WILD_CARD;
            int[][] iArr3 = q0Var.f23148c;
            int i14 = 0;
            while (true) {
                if (i14 >= q0Var.f23146a) {
                    break;
                }
                if (StateSet.stateSetMatches(iArr3[i14], iArr2)) {
                    i10 = i14;
                    break;
                }
                i14++;
            }
            i13 = i10;
        }
        p0 p0Var = (i13 < 0 ? q0Var.f23147b : q0Var.f23149d[i13]).widthChange;
        int width = getWidth();
        StateListSizeChange$SizeChangeType stateListSizeChange$SizeChangeType = StateListSizeChange$SizeChangeType.f23039a;
        float f10 = p0Var.f23133b;
        StateListSizeChange$SizeChangeType stateListSizeChange$SizeChangeType2 = p0Var.f23132a;
        if (stateListSizeChange$SizeChangeType2 != stateListSizeChange$SizeChangeType) {
            if (stateListSizeChange$SizeChangeType2 == StateListSizeChange$SizeChangeType.f23040b) {
            }
            this.widthIncreaseSpringAnimation.c(Math.min(i11, i12));
            if (z10) {
                return;
            }
            this.widthIncreaseSpringAnimation.d();
            return;
        }
        f10 *= width;
        i12 = (int) f10;
        this.widthIncreaseSpringAnimation.c(Math.min(i11, i12));
        if (z10) {
        }
    }

    @NonNull
    @SuppressLint({"KotlinPropertyAccess"})
    public String getA11yClassName() {
        if (TextUtils.isEmpty(this.accessibilityClassName)) {
            return (e() ? CompoundButton.class : Button.class).getName();
        }
        return this.accessibilityClassName;
    }

    @Px
    public int getAllowedWidthDecrease() {
        return this.W;
    }

    @Override // android.view.View
    @Nullable
    public ColorStateList getBackgroundTintList() {
        return getSupportBackgroundTintList();
    }

    @Override // android.view.View
    @Nullable
    public PorterDuff.Mode getBackgroundTintMode() {
        return getSupportBackgroundTintMode();
    }

    @Px
    public int getCornerRadius() {
        if (f()) {
            return this.f22347d.f22380g;
        }
        return 0;
    }

    @Nullable
    @RestrictTo({RestrictTo.Scope.f556b})
    public n getCornerSpringForce() {
        return this.f22347d.getCornerSpringForce();
    }

    public Drawable getIcon() {
        return this.icon;
    }

    public int getIconGravity() {
        return this.f22355l;
    }

    @Px
    public int getIconPadding() {
        return this.f22352i;
    }

    @Px
    public int getIconSize() {
        return this.f22349f;
    }

    public ColorStateList getIconTint() {
        return this.iconTint;
    }

    public PorterDuff.Mode getIconTintMode() {
        return this.iconTintMode;
    }

    @Dimension
    public int getInsetBottom() {
        return this.f22347d.f22379f;
    }

    @Dimension
    public int getInsetTop() {
        return this.f22347d.f22378e;
    }

    @Nullable
    public ColorStateList getRippleColor() {
        if (f()) {
            return this.f22347d.getRippleColor();
        }
        return null;
    }

    @NonNull
    public s getShapeAppearanceModel() {
        if (f()) {
            return this.f22347d.f22375b;
        }
        throw new IllegalStateException("Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background.");
    }

    @Nullable
    @RestrictTo({RestrictTo.Scope.f556b})
    public n0 getStateListShapeAppearanceModel() {
        if (f()) {
            return this.f22347d.getStateListShapeAppearanceModel();
        }
        throw new IllegalStateException("Attempted to get StateListShapeAppearanceModel from a MaterialButton which has an overwritten background.");
    }

    public ColorStateList getStrokeColor() {
        if (f()) {
            return this.f22347d.getStrokeColor();
        }
        return null;
    }

    @Px
    public int getStrokeWidth() {
        if (f()) {
            return this.f22347d.f22381h;
        }
        return 0;
    }

    @Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.x0
    @Nullable
    @RestrictTo({RestrictTo.Scope.f556b})
    public ColorStateList getSupportBackgroundTintList() {
        return f() ? this.f22347d.a() : super.getSupportBackgroundTintList();
    }

    @Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.x0
    @Nullable
    @RestrictTo({RestrictTo.Scope.f556b})
    public PorterDuff.Mode getSupportBackgroundTintMode() {
        return f() ? this.f22347d.b() : super.getSupportBackgroundTintMode();
    }

    public final void h() {
        LinearLayout.LayoutParams layoutParams = this.originalLayoutParams;
        if (layoutParams != null) {
            setLayoutParams(layoutParams);
            this.originalLayoutParams = null;
            this.Q = -1.0f;
        }
    }

    public final void i() {
        int i10 = this.f22355l;
        boolean z10 = true;
        if (i10 != 1 && i10 != 2) {
            z10 = false;
        }
        if (z10) {
            setCompoundDrawablesRelative(this.icon, null, null, null);
            return;
        }
        if (i10 == 3 || i10 == 4) {
            setCompoundDrawablesRelative(null, null, this.icon, null);
        } else if (i10 == 16 || i10 == 32) {
            setCompoundDrawablesRelative(null, this.icon, null, null);
        }
    }

    @Override // android.widget.Checkable
    public final boolean isChecked() {
        return this.f22353j;
    }

    public final void j(boolean z10) {
        Drawable drawable = this.icon;
        if (drawable != null) {
            Drawable drawableMutate = drawable.mutate();
            this.icon = drawableMutate;
            drawableMutate.setTintList(this.iconTint);
            PorterDuff.Mode mode = this.iconTintMode;
            if (mode != null) {
                this.icon.setTintMode(mode);
            }
            int intrinsicWidth = this.f22349f;
            if (intrinsicWidth == 0) {
                intrinsicWidth = this.icon.getIntrinsicWidth();
            }
            int intrinsicHeight = this.f22349f;
            if (intrinsicHeight == 0) {
                intrinsicHeight = this.icon.getIntrinsicHeight();
            }
            Drawable drawable2 = this.icon;
            int i10 = this.f22350g;
            int i11 = this.f22351h;
            drawable2.setBounds(i10, i11, intrinsicWidth + i10, intrinsicHeight + i11);
            this.icon.setVisible(true, z10);
        }
        if (z10) {
            i();
            return;
        }
        Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
        Drawable drawable3 = compoundDrawablesRelative[0];
        Drawable drawable4 = compoundDrawablesRelative[1];
        Drawable drawable5 = compoundDrawablesRelative[2];
        int i12 = this.f22355l;
        if (((i12 == 1 || i12 == 2) && drawable3 != this.icon) || (((i12 == 3 || i12 == 4) && drawable5 != this.icon) || ((i12 == 16 || i12 == 32) && drawable4 != this.icon))) {
            i();
        }
    }

    public final void k(int i10, int i11) {
        if (this.icon == null || getLayout() == null) {
            return;
        }
        int i12 = this.f22355l;
        if (!(i12 == 1 || i12 == 2) && i12 != 3 && i12 != 4) {
            if (i12 == 16 || i12 == 32) {
                this.f22350g = 0;
                if (i12 == 16) {
                    this.f22351h = 0;
                    j(false);
                    return;
                }
                int intrinsicHeight = this.f22349f;
                if (intrinsicHeight == 0) {
                    intrinsicHeight = this.icon.getIntrinsicHeight();
                }
                int iMax = Math.max(0, (((((i11 - getTextHeight()) - getPaddingTop()) - intrinsicHeight) - this.f22352i) - getPaddingBottom()) / 2);
                if (this.f22351h != iMax) {
                    this.f22351h = iMax;
                    j(false);
                    return;
                }
                return;
            }
            return;
        }
        this.f22351h = 0;
        Layout.Alignment actualTextAlignment = getActualTextAlignment();
        int i13 = this.f22355l;
        if (i13 == 1 || i13 == 3 || ((i13 == 2 && actualTextAlignment == Layout.Alignment.ALIGN_NORMAL) || (i13 == 4 && actualTextAlignment == Layout.Alignment.ALIGN_OPPOSITE))) {
            this.f22350g = 0;
            j(false);
            return;
        }
        int intrinsicWidth = this.f22349f;
        if (intrinsicWidth == 0) {
            intrinsicWidth = this.icon.getIntrinsicWidth();
        }
        int textLayoutWidth = ((((i10 - getTextLayoutWidth()) - getPaddingEnd()) - intrinsicWidth) - this.f22352i) - getPaddingStart();
        if (actualTextAlignment == Layout.Alignment.ALIGN_CENTER) {
            textLayoutWidth /= 2;
        }
        if ((getLayoutDirection() == 1) != (this.f22355l == 4)) {
            textLayoutWidth = -textLayoutWidth;
        }
        if (this.f22350g != textLayoutWidth) {
            this.f22350g = textLayoutWidth;
            j(false);
        }
    }

    public final void l() {
        int i10 = (int) (this.f22345b0 - this.f22346c0);
        int i11 = (i10 / 2) + this.U;
        getLayoutParams().width = (int) (this.Q + i10);
        setPaddingRelative(this.R + i11, getPaddingTop(), (this.S + i10) - i11, getPaddingBottom());
    }

    @Override // android.widget.TextView, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (f()) {
            f.v(this, this.f22347d.getMaterialShapeDrawable());
        }
    }

    @Override // android.widget.TextView, android.view.View
    public final int[] onCreateDrawableState(int i10) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i10 + 2);
        if (e()) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, f22339d0);
        }
        if (isChecked()) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, f22340e0);
        }
        return iArrOnCreateDrawableState;
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.view.View
    public final void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        super.onInitializeAccessibilityEvent(accessibilityEvent);
        accessibilityEvent.setClassName(getA11yClassName());
        accessibilityEvent.setChecked(isChecked());
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.view.View
    public final void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
        accessibilityNodeInfo.setClassName(getA11yClassName());
        accessibilityNodeInfo.setCheckable(e());
        accessibilityNodeInfo.setChecked(isChecked());
        accessibilityNodeInfo.setClickable(isClickable());
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.widget.TextView, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        int i14;
        super.onLayout(z10, i10, i11, i12, i13);
        k(getMeasuredWidth(), getMeasuredHeight());
        int i15 = getResources().getConfiguration().orientation;
        if (this.f22356m != i15) {
            this.f22356m = i15;
            this.Q = -1.0f;
        }
        if (this.Q == -1.0f) {
            this.Q = getMeasuredWidth();
            if (this.originalLayoutParams == null && (getParent() instanceof MaterialButtonGroup) && ((MaterialButtonGroup) getParent()).getButtonSizeChange() != null) {
                this.originalLayoutParams = (LinearLayout.LayoutParams) getLayoutParams();
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(this.originalLayoutParams);
                layoutParams.width = (int) this.Q;
                setLayoutParams(layoutParams);
            }
        }
        boolean z11 = false;
        if (this.W == -1) {
            if (this.icon == null) {
                i14 = 0;
            } else {
                int iconPadding = getIconPadding();
                int intrinsicWidth = this.f22349f;
                if (intrinsicWidth == 0) {
                    intrinsicWidth = this.icon.getIntrinsicWidth();
                }
                i14 = iconPadding + intrinsicWidth;
            }
            this.W = (getMeasuredWidth() - getTextLayoutWidth()) - i14;
        }
        if (this.R == -1) {
            this.R = getPaddingStart();
        }
        if (this.S == -1) {
            this.S = getPaddingEnd();
        }
        if ((getParent() instanceof MaterialButtonGroup) && ((MaterialButtonGroup) getParent()).getOrientation() == 0) {
            z11 = true;
        }
        this.V = z11;
    }

    @Override // android.widget.TextView, android.view.View
    public void onRestoreInstanceState(@Nullable Parcelable parcelable) {
        if (!(parcelable instanceof b)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        b bVar = (b) parcelable;
        super.onRestoreInstanceState(bVar.getSuperState());
        setChecked(bVar.f22371c);
    }

    @Override // android.widget.TextView, android.view.View
    public final Parcelable onSaveInstanceState() {
        b bVar = new b(super.onSaveInstanceState());
        bVar.f22371c = this.f22353j;
        return bVar;
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.widget.TextView
    public final void onTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
        super.onTextChanged(charSequence, i10, i11, i12);
        k(getMeasuredWidth(), getMeasuredHeight());
    }

    @Override // android.view.View
    public final boolean performClick() {
        if (isEnabled() && this.f22347d.f22386m) {
            toggle();
        }
        return super.performClick();
    }

    @Override // android.view.View
    public final void refreshDrawableState() {
        super.refreshDrawableState();
        if (this.icon != null) {
            if (this.icon.setState(getDrawableState())) {
                invalidate();
            }
        }
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    public void setA11yClassName(@Nullable String str) {
        this.accessibilityClassName = str;
    }

    @Override // android.view.View
    public void setBackground(@NonNull Drawable drawable) {
        setBackgroundDrawable(drawable);
    }

    @Override // android.view.View
    public void setBackgroundColor(@ColorInt int i10) {
        if (!f()) {
            super.setBackgroundColor(i10);
            return;
        }
        d dVar = this.f22347d;
        if (dVar.getMaterialShapeDrawable() != null) {
            dVar.getMaterialShapeDrawable().setTint(i10);
        }
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.view.View
    public void setBackgroundDrawable(@NonNull Drawable drawable) {
        if (!f()) {
            super.setBackgroundDrawable(drawable);
        } else if (drawable == getBackground()) {
            getBackground().setState(drawable.getState());
        } else {
            this.f22347d.d();
            super.setBackgroundDrawable(drawable);
        }
    }

    @Override // androidx.appcompat.widget.AppCompatButton, android.view.View
    public void setBackgroundResource(@DrawableRes int i10) {
        setBackgroundDrawable(i10 != 0 ? f.a.getDrawable(getContext(), i10) : null);
    }

    @Override // android.view.View
    public void setBackgroundTintList(@Nullable ColorStateList colorStateList) {
        setSupportBackgroundTintList(colorStateList);
    }

    @Override // android.view.View
    public void setBackgroundTintMode(@Nullable PorterDuff.Mode mode) {
        setSupportBackgroundTintMode(mode);
    }

    public void setCheckable(boolean z10) {
        if (f()) {
            this.f22347d.f22385l = z10;
        }
    }

    @Override // android.widget.Checkable
    public void setChecked(boolean z10) {
        setCheckedInternal(z10);
    }

    public void setCornerRadius(@Px int i10) {
        if (f()) {
            d dVar = this.f22347d;
            if (dVar.f22384k && dVar.f22380g == i10) {
                return;
            }
            dVar.f22380g = i10;
            dVar.f22384k = true;
            q qVarH = dVar.f22375b.h();
            qVarH.c(i10);
            dVar.f(qVarH.a());
        }
    }

    public void setCornerRadiusResource(@DimenRes int i10) {
        if (f()) {
            setCornerRadius(getResources().getDimensionPixelSize(i10));
        }
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    public void setCornerSpringForce(@NonNull n nVar) {
        this.f22347d.e(nVar);
    }

    public void setDisplayedWidthDecrease(int i10) {
        this.f22346c0 = Math.min(i10, this.W);
        l();
        invalidate();
    }

    @Override // android.view.View
    public void setElevation(float f10) {
        super.setElevation(f10);
        if (f()) {
            this.f22347d.getMaterialShapeDrawable().w(f10);
        }
    }

    public void setIcon(@Nullable Drawable drawable) {
        if (this.icon != drawable) {
            this.icon = drawable;
            j(true);
            k(getMeasuredWidth(), getMeasuredHeight());
        }
    }

    public void setIconGravity(int i10) {
        if (this.f22355l != i10) {
            this.f22355l = i10;
            k(getMeasuredWidth(), getMeasuredHeight());
        }
    }

    public void setIconPadding(@Px int i10) {
        if (this.f22352i != i10) {
            this.f22352i = i10;
            setCompoundDrawablePadding(i10);
        }
    }

    public void setIconResource(@DrawableRes int i10) {
        setIcon(i10 != 0 ? f.a.getDrawable(getContext(), i10) : null);
    }

    public void setIconSize(@Px int i10) {
        if (i10 < 0) {
            throw new IllegalArgumentException("iconSize cannot be less than 0");
        }
        if (this.f22349f != i10) {
            this.f22349f = i10;
            j(true);
        }
    }

    public void setIconTint(@Nullable ColorStateList colorStateList) {
        if (this.iconTint != colorStateList) {
            this.iconTint = colorStateList;
            j(false);
        }
    }

    public void setIconTintMode(PorterDuff.Mode mode) {
        if (this.iconTintMode != mode) {
            this.iconTintMode = mode;
            j(false);
        }
    }

    public void setIconTintResource(@ColorRes int i10) {
        setIconTint(g0.d.getColorStateList(getContext(), i10));
    }

    public void setInsetBottom(@Dimension int i10) {
        d dVar = this.f22347d;
        dVar.h(dVar.f22378e, i10);
    }

    public void setInsetTop(@Dimension int i10) {
        d dVar = this.f22347d;
        dVar.h(i10, dVar.f22379f);
    }

    public void setInternalBackground(Drawable drawable) {
        super.setBackgroundDrawable(drawable);
    }

    public void setOnPressedChangeListenerInternal(@Nullable a aVar) {
        this.onPressedChangeListenerInternal = aVar;
    }

    public void setOpticalCenterEnabled(boolean z10) {
        if (this.T != z10) {
            this.T = z10;
            d dVar = this.f22347d;
            if (z10) {
                dVar.setCornerSizeChangeListener(new androidx.core.app.e(this, 22));
            } else {
                dVar.setCornerSizeChangeListener(null);
            }
            post(new y.a(this, 10));
        }
    }

    @Override // android.view.View
    public void setPressed(boolean z10) {
        a aVar = this.onPressedChangeListenerInternal;
        if (aVar != null) {
            ((MaterialButtonGroup) ((a0) aVar).f35758b).invalidate();
        }
        super.setPressed(z10);
        g(false);
    }

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        if (f()) {
            this.f22347d.setRippleColor(colorStateList);
        }
    }

    public void setRippleColorResource(@ColorRes int i10) {
        if (f()) {
            setRippleColor(g0.d.getColorStateList(getContext(), i10));
        }
    }

    @Override // com.google.android.material.shape.g0
    public void setShapeAppearanceModel(@NonNull s sVar) {
        if (!f()) {
            throw new IllegalStateException("Attempted to set ShapeAppearanceModel on a MaterialButton which has an overwritten background.");
        }
        this.f22347d.f(sVar);
    }

    public void setShouldDrawSurfaceColorStroke(boolean z10) {
        if (f()) {
            d dVar = this.f22347d;
            dVar.f22382i = z10;
            dVar.k();
        }
    }

    public void setSizeChange(@NonNull q0 q0Var) {
        if (this.sizeChange != q0Var) {
            this.sizeChange = q0Var;
            g(true);
        }
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    public void setStateListShapeAppearanceModel(@NonNull n0 n0Var) {
        if (!f()) {
            throw new IllegalStateException("Attempted to set StateListShapeAppearanceModel on a MaterialButton which has an overwritten background.");
        }
        d dVar = this.f22347d;
        if (dVar.getCornerSpringForce() == null && n0Var.b()) {
            dVar.e(d());
        }
        dVar.g(n0Var);
    }

    public void setStrokeColor(@Nullable ColorStateList colorStateList) {
        if (f()) {
            this.f22347d.setStrokeColor(colorStateList);
        }
    }

    public void setStrokeColorResource(@ColorRes int i10) {
        if (f()) {
            setStrokeColor(g0.d.getColorStateList(getContext(), i10));
        }
    }

    public void setStrokeWidth(@Px int i10) {
        if (f()) {
            d dVar = this.f22347d;
            if (dVar.f22381h != i10) {
                dVar.f22381h = i10;
                dVar.k();
            }
        }
    }

    public void setStrokeWidthResource(@DimenRes int i10) {
        if (f()) {
            setStrokeWidth(getResources().getDimensionPixelSize(i10));
        }
    }

    @Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.x0
    @RestrictTo({RestrictTo.Scope.f556b})
    public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) {
        if (f()) {
            this.f22347d.setSupportBackgroundTintList(colorStateList);
        } else {
            super.setSupportBackgroundTintList(colorStateList);
        }
    }

    @Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.x0
    @RestrictTo({RestrictTo.Scope.f556b})
    public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode mode) {
        if (f()) {
            this.f22347d.setSupportBackgroundTintMode(mode);
        } else {
            super.setSupportBackgroundTintMode(mode);
        }
    }

    @Override // android.view.View
    public void setTextAlignment(int i10) {
        super.setTextAlignment(i10);
        k(getMeasuredWidth(), getMeasuredHeight());
    }

    public void setToggleCheckedStateOnClick(boolean z10) {
        this.f22347d.f22386m = z10;
    }

    @Override // android.widget.TextView
    public void setWidth(@Px int i10) {
        this.Q = -1.0f;
        super.setWidth(i10);
    }

    public void setWidthChangeMax(@Px int i10) {
        if (this.f22344a0 != i10) {
            this.f22344a0 = i10;
            g(true);
        }
    }

    @Override // android.widget.Checkable
    public final void toggle() {
        setChecked(!this.f22353j);
    }

    public MaterialButton(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, x8.c.materialButtonStyle);
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public MaterialButton(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        s sVarA;
        int i11 = f22341f0;
        super(x9.a.wrap(context, attributeSet, i10, i11, new int[]{f22342g0}), attributeSet, i10);
        this.f22348e = new LinkedHashSet();
        this.f22353j = false;
        this.f22354k = false;
        this.f22356m = -1;
        this.Q = -1.0f;
        this.R = -1;
        this.S = -1;
        this.W = -1;
        Context context2 = getContext();
        TypedArray typedArrayC = com.google.android.material.internal.q0.c(context2, attributeSet, x8.m.MaterialButton, i10, i11, new int[0]);
        this.f22352i = typedArrayC.getDimensionPixelSize(x8.m.MaterialButton_iconPadding, 0);
        this.iconTintMode = w0.f(typedArrayC.getInt(x8.m.MaterialButton_iconTintMode, -1), PorterDuff.Mode.SRC_IN);
        this.iconTint = q9.d.getColorStateList(getContext(), typedArrayC, x8.m.MaterialButton_iconTint);
        this.icon = q9.d.getDrawable(getContext(), typedArrayC, x8.m.MaterialButton_icon);
        this.f22355l = typedArrayC.getInteger(x8.m.MaterialButton_iconGravity, 1);
        this.f22349f = typedArrayC.getDimensionPixelSize(x8.m.MaterialButton_iconSize, 0);
        n0 n0VarCreate = n0.create(context2, typedArrayC, x8.m.MaterialButton_shapeAppearance);
        if (n0VarCreate != null) {
            sVarA = n0VarCreate.a();
        } else {
            sVarA = s.c(context2, attributeSet, i10, i11).a();
        }
        boolean z10 = typedArrayC.getBoolean(x8.m.MaterialButton_opticalCenterEnabled, false);
        d dVar = new d(this, sVarA);
        this.f22347d = dVar;
        dVar.c(typedArrayC);
        setCheckedInternal(typedArrayC.getBoolean(x8.m.MaterialButton_android_checked, false));
        if (n0VarCreate != null) {
            dVar.e(d());
            dVar.g(n0VarCreate);
        }
        setOpticalCenterEnabled(z10);
        typedArrayC.recycle();
        setCompoundDrawablePadding(this.f22352i);
        j(this.icon != null);
    }
}
