package com.google.android.material.button;

import A3.a;
import M.J;
import android.R;
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.graphics.drawable.RippleDrawable;
import android.os.Parcelable;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
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 com.google.android.gms.internal.measurement.AbstractC0707u1;
import h3.AbstractC1031a;
import java.lang.reflect.Field;
import java.util.LinkedHashSet;
import l6.C1139a;
import n.AbstractC1222m;
import n3.C1274b;
import n3.C1275c;
import n3.InterfaceC1273a;
import n3.e;
import s3.k;
import s7.d;
import v3.AbstractC1674a;
import x3.C1713a;
import x3.j;
import x3.u;

/* JADX INFO: loaded from: classes.dex */
public class MaterialButton extends AbstractC1222m implements Checkable, u {

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

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

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

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public int f10162C;
    public boolean D;

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final C1275c f10165t;

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

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public InterfaceC1273a f10167v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public PorterDuff.Mode f10168w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public ColorStateList f10169x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public Drawable f10170y;

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

    public MaterialButton(Context context, AttributeSet attributeSet) {
        super(a.a(context, attributeSet, com.martsnew.tv.R.attr.materialButtonStyle, com.martsnew.tv.R.style.Widget_MaterialComponents_Button), attributeSet);
        this.f10166u = new LinkedHashSet();
        this.D = false;
        this.f10163E = false;
        Context context2 = getContext();
        TypedArray typedArrayE = k.e(context2, attributeSet, AbstractC1031a.f13405l, com.martsnew.tv.R.attr.materialButtonStyle, com.martsnew.tv.R.style.Widget_MaterialComponents_Button, new int[0]);
        this.f10162C = typedArrayE.getDimensionPixelSize(12, 0);
        int i = typedArrayE.getInt(15, -1);
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        this.f10168w = k.f(i, mode);
        this.f10169x = d.q(getContext(), typedArrayE, 14);
        this.f10170y = d.u(getContext(), typedArrayE, 10);
        this.f10164F = typedArrayE.getInteger(11, 1);
        this.f10171z = typedArrayE.getDimensionPixelSize(13, 0);
        C1275c c1275c = new C1275c(this, x3.k.b(context2, attributeSet, com.martsnew.tv.R.attr.materialButtonStyle, com.martsnew.tv.R.style.Widget_MaterialComponents_Button).a());
        this.f10165t = c1275c;
        c1275c.f15140c = typedArrayE.getDimensionPixelOffset(1, 0);
        c1275c.f15141d = typedArrayE.getDimensionPixelOffset(2, 0);
        c1275c.f15142e = typedArrayE.getDimensionPixelOffset(3, 0);
        c1275c.f15143f = typedArrayE.getDimensionPixelOffset(4, 0);
        if (typedArrayE.hasValue(8)) {
            int dimensionPixelSize = typedArrayE.getDimensionPixelSize(8, -1);
            c1275c.f15144g = dimensionPixelSize;
            float f3 = dimensionPixelSize;
            j jVarE = c1275c.f15139b.e();
            jVarE.f18629e = new C1713a(f3);
            jVarE.f18630f = new C1713a(f3);
            jVarE.f18631g = new C1713a(f3);
            jVarE.f18632h = new C1713a(f3);
            c1275c.c(jVarE.a());
            c1275c.f15152p = true;
        }
        c1275c.f15145h = typedArrayE.getDimensionPixelSize(20, 0);
        c1275c.i = k.f(typedArrayE.getInt(7, -1), mode);
        c1275c.f15146j = d.q(getContext(), typedArrayE, 6);
        c1275c.f15147k = d.q(getContext(), typedArrayE, 19);
        c1275c.f15148l = d.q(getContext(), typedArrayE, 16);
        c1275c.f15153q = typedArrayE.getBoolean(5, false);
        c1275c.f15155s = typedArrayE.getDimensionPixelSize(9, 0);
        Field field = J.f4065a;
        int paddingStart = getPaddingStart();
        int paddingTop = getPaddingTop();
        int paddingEnd = getPaddingEnd();
        int paddingBottom = getPaddingBottom();
        if (typedArrayE.hasValue(0)) {
            c1275c.f15151o = true;
            setSupportBackgroundTintList(c1275c.f15146j);
            setSupportBackgroundTintMode(c1275c.i);
        } else {
            c1275c.e();
        }
        setPaddingRelative(paddingStart + c1275c.f15140c, paddingTop + c1275c.f15142e, paddingEnd + c1275c.f15141d, paddingBottom + c1275c.f15143f);
        typedArrayE.recycle();
        setCompoundDrawablePadding(this.f10162C);
        c(this.f10170y != null);
    }

    private String getA11yClassName() {
        C1275c c1275c = this.f10165t;
        return ((c1275c == null || !c1275c.f15153q) ? Button.class : CompoundButton.class).getName();
    }

    private int getTextHeight() {
        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 getTextWidth() {
        TextPaint paint = getPaint();
        String string = getText().toString();
        if (getTransformationMethod() != null) {
            string = getTransformationMethod().getTransformation(string, this).toString();
        }
        return Math.min((int) paint.measureText(string), getLayout().getEllipsizedWidth());
    }

    public final boolean a() {
        C1275c c1275c = this.f10165t;
        return (c1275c == null || c1275c.f15151o) ? false : true;
    }

    public final void b() {
        int i = this.f10164F;
        boolean z8 = true;
        if (i != 1 && i != 2) {
            z8 = false;
        }
        if (z8) {
            setCompoundDrawablesRelative(this.f10170y, null, null, null);
            return;
        }
        if (i == 3 || i == 4) {
            setCompoundDrawablesRelative(null, null, this.f10170y, null);
        } else if (i == 16 || i == 32) {
            setCompoundDrawablesRelative(null, this.f10170y, null, null);
        }
    }

    public final void c(boolean z8) {
        Drawable drawable = this.f10170y;
        if (drawable != null) {
            Drawable drawableMutate = drawable.mutate();
            this.f10170y = drawableMutate;
            drawableMutate.setTintList(this.f10169x);
            PorterDuff.Mode mode = this.f10168w;
            if (mode != null) {
                this.f10170y.setTintMode(mode);
            }
            int intrinsicWidth = this.f10171z;
            if (intrinsicWidth == 0) {
                intrinsicWidth = this.f10170y.getIntrinsicWidth();
            }
            int intrinsicHeight = this.f10171z;
            if (intrinsicHeight == 0) {
                intrinsicHeight = this.f10170y.getIntrinsicHeight();
            }
            Drawable drawable2 = this.f10170y;
            int i = this.f10160A;
            int i5 = this.f10161B;
            drawable2.setBounds(i, i5, intrinsicWidth + i, intrinsicHeight + i5);
        }
        if (z8) {
            b();
            return;
        }
        Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
        Drawable drawable3 = compoundDrawablesRelative[0];
        Drawable drawable4 = compoundDrawablesRelative[1];
        Drawable drawable5 = compoundDrawablesRelative[2];
        int i8 = this.f10164F;
        if (((i8 == 1 || i8 == 2) && drawable3 != this.f10170y) || (((i8 == 3 || i8 == 4) && drawable5 != this.f10170y) || ((i8 == 16 || i8 == 32) && drawable4 != this.f10170y))) {
            b();
        }
    }

    public final void d(int i, int i5) {
        if (this.f10170y == null || getLayout() == null) {
            return;
        }
        int i8 = this.f10164F;
        if (!(i8 == 1 || i8 == 2) && i8 != 3 && i8 != 4) {
            if (i8 == 16 || i8 == 32) {
                this.f10160A = 0;
                if (i8 == 16) {
                    this.f10161B = 0;
                    c(false);
                    return;
                }
                int intrinsicHeight = this.f10171z;
                if (intrinsicHeight == 0) {
                    intrinsicHeight = this.f10170y.getIntrinsicHeight();
                }
                int textHeight = (((((i5 - getTextHeight()) - getPaddingTop()) - intrinsicHeight) - this.f10162C) - getPaddingBottom()) / 2;
                if (this.f10161B != textHeight) {
                    this.f10161B = textHeight;
                    c(false);
                    return;
                }
                return;
            }
            return;
        }
        this.f10161B = 0;
        if (i8 == 1 || i8 == 3) {
            this.f10160A = 0;
            c(false);
            return;
        }
        int intrinsicWidth = this.f10171z;
        if (intrinsicWidth == 0) {
            intrinsicWidth = this.f10170y.getIntrinsicWidth();
        }
        int textWidth = i - getTextWidth();
        Field field = J.f4065a;
        int paddingEnd = ((((textWidth - getPaddingEnd()) - intrinsicWidth) - this.f10162C) - getPaddingStart()) / 2;
        if ((getLayoutDirection() == 1) != (this.f10164F == 4)) {
            paddingEnd = -paddingEnd;
        }
        if (this.f10160A != paddingEnd) {
            this.f10160A = paddingEnd;
            c(false);
        }
    }

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

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

    public int getCornerRadius() {
        if (a()) {
            return this.f10165t.f15144g;
        }
        return 0;
    }

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

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

    public int getIconPadding() {
        return this.f10162C;
    }

    public int getIconSize() {
        return this.f10171z;
    }

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

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

    public int getInsetBottom() {
        return this.f10165t.f15143f;
    }

    public int getInsetTop() {
        return this.f10165t.f15142e;
    }

    public ColorStateList getRippleColor() {
        if (a()) {
            return this.f10165t.f15148l;
        }
        return null;
    }

    public x3.k getShapeAppearanceModel() {
        if (a()) {
            return this.f10165t.f15139b;
        }
        throw new IllegalStateException("Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background.");
    }

    public ColorStateList getStrokeColor() {
        if (a()) {
            return this.f10165t.f15147k;
        }
        return null;
    }

    public int getStrokeWidth() {
        if (a()) {
            return this.f10165t.f15145h;
        }
        return 0;
    }

    @Override // n.AbstractC1222m
    public ColorStateList getSupportBackgroundTintList() {
        return a() ? this.f10165t.f15146j : super.getSupportBackgroundTintList();
    }

    @Override // n.AbstractC1222m
    public PorterDuff.Mode getSupportBackgroundTintMode() {
        return a() ? this.f10165t.i : super.getSupportBackgroundTintMode();
    }

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

    @Override // android.widget.TextView, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (a()) {
            AbstractC0707u1.m(this, this.f10165t.b(false));
        }
    }

    @Override // android.widget.TextView, android.view.View
    public final int[] onCreateDrawableState(int i) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i + 2);
        C1275c c1275c = this.f10165t;
        if (c1275c != null && c1275c.f15153q) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, f10159G);
        }
        if (this.D) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, H);
        }
        return iArrOnCreateDrawableState;
    }

    @Override // n.AbstractC1222m, android.view.View
    public final void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        super.onInitializeAccessibilityEvent(accessibilityEvent);
        accessibilityEvent.setClassName(getA11yClassName());
        accessibilityEvent.setChecked(this.D);
    }

    @Override // n.AbstractC1222m, android.view.View
    public final void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
        accessibilityNodeInfo.setClassName(getA11yClassName());
        C1275c c1275c = this.f10165t;
        accessibilityNodeInfo.setCheckable(c1275c != null && c1275c.f15153q);
        accessibilityNodeInfo.setChecked(this.D);
        accessibilityNodeInfo.setClickable(isClickable());
    }

    @Override // android.widget.TextView, android.view.View
    public final void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof C1274b)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        C1274b c1274b = (C1274b) parcelable;
        super.onRestoreInstanceState(c1274b.f6203q);
        setChecked(c1274b.f15137s);
    }

    @Override // android.widget.TextView, android.view.View
    public final Parcelable onSaveInstanceState() {
        C1274b c1274b = new C1274b(super.onSaveInstanceState());
        c1274b.f15137s = this.D;
        return c1274b;
    }

    @Override // android.view.View
    public final void onSizeChanged(int i, int i5, int i8, int i9) {
        super.onSizeChanged(i, i5, i8, i9);
        d(i, i5);
    }

    @Override // n.AbstractC1222m, android.widget.TextView
    public final void onTextChanged(CharSequence charSequence, int i, int i5, int i8) {
        super.onTextChanged(charSequence, i, i5, i8);
        d(getMeasuredWidth(), getMeasuredHeight());
    }

    @Override // android.view.View
    public final boolean performClick() {
        toggle();
        return super.performClick();
    }

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

    @Override // android.view.View
    public void setBackgroundColor(int i) {
        if (!a()) {
            super.setBackgroundColor(i);
            return;
        }
        C1275c c1275c = this.f10165t;
        if (c1275c.b(false) != null) {
            c1275c.b(false).setTint(i);
        }
    }

    @Override // n.AbstractC1222m, android.view.View
    public void setBackgroundDrawable(Drawable drawable) {
        if (!a()) {
            super.setBackgroundDrawable(drawable);
            return;
        }
        if (drawable == getBackground()) {
            getBackground().setState(drawable.getState());
            return;
        }
        Log.w("MaterialButton", "MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled");
        C1275c c1275c = this.f10165t;
        c1275c.f15151o = true;
        ColorStateList colorStateList = c1275c.f15146j;
        MaterialButton materialButton = c1275c.f15138a;
        materialButton.setSupportBackgroundTintList(colorStateList);
        materialButton.setSupportBackgroundTintMode(c1275c.i);
        super.setBackgroundDrawable(drawable);
    }

    @Override // n.AbstractC1222m, android.view.View
    public void setBackgroundResource(int i) {
        setBackgroundDrawable(i != 0 ? android.support.v4.media.session.a.l(getContext(), i) : null);
    }

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

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

    public void setCheckable(boolean z8) {
        if (a()) {
            this.f10165t.f15153q = z8;
        }
    }

    @Override // android.widget.Checkable
    public void setChecked(boolean z8) {
        C1275c c1275c = this.f10165t;
        if (c1275c == null || !c1275c.f15153q || !isEnabled() || this.D == z8) {
            return;
        }
        this.D = z8;
        refreshDrawableState();
        if (this.f10163E) {
            return;
        }
        this.f10163E = true;
        for (e eVar : this.f10166u) {
            boolean z9 = this.D;
            MaterialButtonToggleGroup materialButtonToggleGroup = eVar.f15157a;
            if (!materialButtonToggleGroup.f10179w) {
                if (materialButtonToggleGroup.f10180x) {
                    materialButtonToggleGroup.f10182z = z9 ? getId() : -1;
                }
                if (materialButtonToggleGroup.d(getId(), z9)) {
                    getId();
                    materialButtonToggleGroup.b();
                }
                materialButtonToggleGroup.invalidate();
            }
        }
        this.f10163E = false;
    }

    public void setCornerRadius(int i) {
        if (a()) {
            C1275c c1275c = this.f10165t;
            if (c1275c.f15152p && c1275c.f15144g == i) {
                return;
            }
            c1275c.f15144g = i;
            c1275c.f15152p = true;
            float f3 = i;
            j jVarE = c1275c.f15139b.e();
            jVarE.f18629e = new C1713a(f3);
            jVarE.f18630f = new C1713a(f3);
            jVarE.f18631g = new C1713a(f3);
            jVarE.f18632h = new C1713a(f3);
            c1275c.c(jVarE.a());
        }
    }

    public void setCornerRadiusResource(int i) {
        if (a()) {
            setCornerRadius(getResources().getDimensionPixelSize(i));
        }
    }

    @Override // android.view.View
    public void setElevation(float f3) {
        super.setElevation(f3);
        if (a()) {
            this.f10165t.b(false).h(f3);
        }
    }

    public void setIcon(Drawable drawable) {
        if (this.f10170y != drawable) {
            this.f10170y = drawable;
            c(true);
            d(getMeasuredWidth(), getMeasuredHeight());
        }
    }

    public void setIconGravity(int i) {
        if (this.f10164F != i) {
            this.f10164F = i;
            d(getMeasuredWidth(), getMeasuredHeight());
        }
    }

    public void setIconPadding(int i) {
        if (this.f10162C != i) {
            this.f10162C = i;
            setCompoundDrawablePadding(i);
        }
    }

    public void setIconResource(int i) {
        setIcon(i != 0 ? android.support.v4.media.session.a.l(getContext(), i) : null);
    }

    public void setIconSize(int i) {
        if (i < 0) {
            throw new IllegalArgumentException("iconSize cannot be less than 0");
        }
        if (this.f10171z != i) {
            this.f10171z = i;
            c(true);
        }
    }

    public void setIconTint(ColorStateList colorStateList) {
        if (this.f10169x != colorStateList) {
            this.f10169x = colorStateList;
            c(false);
        }
    }

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

    public void setIconTintResource(int i) {
        setIconTint(d.p(getContext(), i));
    }

    public void setInsetBottom(int i) {
        C1275c c1275c = this.f10165t;
        c1275c.d(c1275c.f15142e, i);
    }

    public void setInsetTop(int i) {
        C1275c c1275c = this.f10165t;
        c1275c.d(i, c1275c.f15143f);
    }

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

    public void setOnPressedChangeListenerInternal(InterfaceC1273a interfaceC1273a) {
        this.f10167v = interfaceC1273a;
    }

    @Override // android.view.View
    public void setPressed(boolean z8) {
        InterfaceC1273a interfaceC1273a = this.f10167v;
        if (interfaceC1273a != null) {
            ((MaterialButtonToggleGroup) ((C1139a) interfaceC1273a).f14409q).invalidate();
        }
        super.setPressed(z8);
    }

    public void setRippleColor(ColorStateList colorStateList) {
        if (a()) {
            C1275c c1275c = this.f10165t;
            if (c1275c.f15148l != colorStateList) {
                c1275c.f15148l = colorStateList;
                MaterialButton materialButton = c1275c.f15138a;
                if (materialButton.getBackground() instanceof RippleDrawable) {
                    ((RippleDrawable) materialButton.getBackground()).setColor(AbstractC1674a.a(colorStateList));
                }
            }
        }
    }

    public void setRippleColorResource(int i) {
        if (a()) {
            setRippleColor(d.p(getContext(), i));
        }
    }

    @Override // x3.u
    public void setShapeAppearanceModel(x3.k kVar) {
        if (!a()) {
            throw new IllegalStateException("Attempted to set ShapeAppearanceModel on a MaterialButton which has an overwritten background.");
        }
        this.f10165t.c(kVar);
    }

    public void setShouldDrawSurfaceColorStroke(boolean z8) {
        if (a()) {
            C1275c c1275c = this.f10165t;
            c1275c.f15150n = z8;
            c1275c.f();
        }
    }

    public void setStrokeColor(ColorStateList colorStateList) {
        if (a()) {
            C1275c c1275c = this.f10165t;
            if (c1275c.f15147k != colorStateList) {
                c1275c.f15147k = colorStateList;
                c1275c.f();
            }
        }
    }

    public void setStrokeColorResource(int i) {
        if (a()) {
            setStrokeColor(d.p(getContext(), i));
        }
    }

    public void setStrokeWidth(int i) {
        if (a()) {
            C1275c c1275c = this.f10165t;
            if (c1275c.f15145h != i) {
                c1275c.f15145h = i;
                c1275c.f();
            }
        }
    }

    public void setStrokeWidthResource(int i) {
        if (a()) {
            setStrokeWidth(getResources().getDimensionPixelSize(i));
        }
    }

    @Override // n.AbstractC1222m
    public void setSupportBackgroundTintList(ColorStateList colorStateList) {
        if (!a()) {
            super.setSupportBackgroundTintList(colorStateList);
            return;
        }
        C1275c c1275c = this.f10165t;
        if (c1275c.f15146j != colorStateList) {
            c1275c.f15146j = colorStateList;
            if (c1275c.b(false) != null) {
                c1275c.b(false).setTintList(c1275c.f15146j);
            }
        }
    }

    @Override // n.AbstractC1222m
    public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
        if (!a()) {
            super.setSupportBackgroundTintMode(mode);
            return;
        }
        C1275c c1275c = this.f10165t;
        if (c1275c.i != mode) {
            c1275c.i = mode;
            if (c1275c.b(false) == null || c1275c.i == null) {
                return;
            }
            c1275c.b(false).setTintMode(c1275c.i);
        }
    }

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