package com.google.android.material.button; import android.R; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; 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 androidx.appcompat.app.m; import androidx.appcompat.widget.f; import androidx.core.view.n0; import androidx.core.widget.t; import c3.i; import e.b; import java.util.Iterator; import java.util.LinkedHashSet; import p3.h; import p3.k; import p3.n; import r.c; /* loaded from: classes2.dex */ public class MaterialButton extends f implements Checkable, n { /* renamed from: n, reason: collision with root package name */ private static final int[] f4366n = {R.attr.state_checkable}; /* renamed from: o, reason: collision with root package name */ private static final int[] f4367o = {R.attr.state_checked}; /* renamed from: p, reason: collision with root package name */ private static final int f4368p = i.f3555e; /* renamed from: c, reason: collision with root package name */ private final com.google.android.material.button.a f4369c; /* renamed from: d, reason: collision with root package name */ private final LinkedHashSet f4370d; /* renamed from: e, reason: collision with root package name */ private PorterDuff.Mode f4371e; /* renamed from: f, reason: collision with root package name */ private ColorStateList f4372f; /* renamed from: g, reason: collision with root package name */ private Drawable f4373g; /* renamed from: h, reason: collision with root package name */ private int f4374h; /* renamed from: i, reason: collision with root package name */ private int f4375i; /* renamed from: j, reason: collision with root package name */ private int f4376j; /* renamed from: k, reason: collision with root package name */ private boolean f4377k; /* renamed from: l, reason: collision with root package name */ private boolean f4378l; /* renamed from: m, reason: collision with root package name */ private int f4379m; interface a { } public MaterialButton(Context context, AttributeSet attributeSet) { this(context, attributeSet, c3.a.f3459o); } private boolean b() { return n0.B(this) == 1; } private boolean c() { com.google.android.material.button.a aVar = this.f4369c; return (aVar == null || aVar.m()) ? false : true; } private void d(boolean z10) { if (z10) { t.i(this, this.f4373g, null, null, null); } else { t.i(this, null, null, this.f4373g, null); } } private void e(boolean z10) { Drawable drawable = this.f4373g; boolean z11 = false; if (drawable != null) { Drawable mutate = c.r(drawable).mutate(); this.f4373g = mutate; c.o(mutate, this.f4372f); PorterDuff.Mode mode = this.f4371e; if (mode != null) { c.p(this.f4373g, mode); } int i10 = this.f4374h; if (i10 == 0) { i10 = this.f4373g.getIntrinsicWidth(); } int i11 = this.f4374h; if (i11 == 0) { i11 = this.f4373g.getIntrinsicHeight(); } Drawable drawable2 = this.f4373g; int i12 = this.f4375i; drawable2.setBounds(i12, 0, i10 + i12, i11); } int i13 = this.f4379m; boolean z12 = i13 == 1 || i13 == 2; if (z10) { d(z12); return; } Drawable[] a10 = t.a(this); Drawable drawable3 = a10[0]; Drawable drawable4 = a10[2]; if ((z12 && drawable3 != this.f4373g) || (!z12 && drawable4 != this.f4373g)) { z11 = true; } if (z11) { d(z12); } } private void f() { if (this.f4373g == null || getLayout() == null) { return; } int i10 = this.f4379m; if (i10 == 1 || i10 == 3) { this.f4375i = 0; e(false); return; } TextPaint paint = getPaint(); String charSequence = getText().toString(); if (getTransformationMethod() != null) { charSequence = getTransformationMethod().getTransformation(charSequence, this).toString(); } int min = Math.min((int) paint.measureText(charSequence), getLayout().getEllipsizedWidth()); int i11 = this.f4374h; if (i11 == 0) { i11 = this.f4373g.getIntrinsicWidth(); } int measuredWidth = (((((getMeasuredWidth() - min) - n0.F(this)) - i11) - this.f4376j) - n0.G(this)) / 2; if (b() != (this.f4379m == 4)) { measuredWidth = -measuredWidth; } if (this.f4375i != measuredWidth) { this.f4375i = measuredWidth; e(false); } } private String getA11yClassName() { return (a() ? CompoundButton.class : Button.class).getName(); } public boolean a() { com.google.android.material.button.a aVar = this.f4369c; return aVar != null && aVar.n(); } @Override // android.view.View public ColorStateList getBackgroundTintList() { return getSupportBackgroundTintList(); } @Override // android.view.View public PorterDuff.Mode getBackgroundTintMode() { return getSupportBackgroundTintMode(); } public int getCornerRadius() { if (c()) { return this.f4369c.b(); } return 0; } public Drawable getIcon() { return this.f4373g; } public int getIconGravity() { return this.f4379m; } public int getIconPadding() { return this.f4376j; } public int getIconSize() { return this.f4374h; } public ColorStateList getIconTint() { return this.f4372f; } public PorterDuff.Mode getIconTintMode() { return this.f4371e; } public ColorStateList getRippleColor() { if (c()) { return this.f4369c.f(); } return null; } public k getShapeAppearanceModel() { if (c()) { return this.f4369c.g(); } throw new IllegalStateException("Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background."); } public ColorStateList getStrokeColor() { if (c()) { return this.f4369c.h(); } return null; } public int getStrokeWidth() { if (c()) { return this.f4369c.i(); } return 0; } @Override // androidx.appcompat.widget.f public ColorStateList getSupportBackgroundTintList() { return c() ? this.f4369c.j() : super.getSupportBackgroundTintList(); } @Override // androidx.appcompat.widget.f public PorterDuff.Mode getSupportBackgroundTintMode() { return c() ? this.f4369c.k() : super.getSupportBackgroundTintMode(); } @Override // android.widget.Checkable public boolean isChecked() { return this.f4377k; } @Override // android.widget.TextView, android.view.View protected void onAttachedToWindow() { super.onAttachedToWindow(); h.f(this, this.f4369c.d()); } @Override // android.widget.TextView, android.view.View protected int[] onCreateDrawableState(int i10) { int[] onCreateDrawableState = super.onCreateDrawableState(i10 + 2); if (a()) { View.mergeDrawableStates(onCreateDrawableState, f4366n); } if (isChecked()) { View.mergeDrawableStates(onCreateDrawableState, f4367o); } return onCreateDrawableState; } @Override // androidx.appcompat.widget.f, android.view.View public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) { super.onInitializeAccessibilityEvent(accessibilityEvent); accessibilityEvent.setClassName(getA11yClassName()); accessibilityEvent.setChecked(isChecked()); } @Override // androidx.appcompat.widget.f, android.view.View public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) { super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo); accessibilityNodeInfo.setClassName(getA11yClassName()); accessibilityNodeInfo.setCheckable(a()); accessibilityNodeInfo.setChecked(isChecked()); accessibilityNodeInfo.setClickable(isClickable()); } @Override // androidx.appcompat.widget.f, android.widget.TextView, android.view.View protected void onLayout(boolean z10, int i10, int i11, int i12, int i13) { com.google.android.material.button.a aVar; super.onLayout(z10, i10, i11, i12, i13); if (Build.VERSION.SDK_INT != 21 || (aVar = this.f4369c) == null) { return; } aVar.B(i13 - i11, i12 - i10); } @Override // android.widget.TextView, android.view.View protected void onMeasure(int i10, int i11) { super.onMeasure(i10, i11); f(); } @Override // androidx.appcompat.widget.f, android.widget.TextView protected void onTextChanged(CharSequence charSequence, int i10, int i11, int i12) { super.onTextChanged(charSequence, i10, i11, i12); f(); } @Override // android.view.View public 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 i10) { if (c()) { this.f4369c.p(i10); } else { super.setBackgroundColor(i10); } } @Override // androidx.appcompat.widget.f, android.view.View public void setBackgroundDrawable(Drawable drawable) { if (!c()) { super.setBackgroundDrawable(drawable); } else { if (drawable == getBackground()) { getBackground().setState(drawable.getState()); return; } Log.w("MaterialButton", "Do not set the background; MaterialButton manages its own background drawable."); this.f4369c.q(); super.setBackgroundDrawable(drawable); } } @Override // androidx.appcompat.widget.f, android.view.View public void setBackgroundResource(int i10) { setBackgroundDrawable(i10 != 0 ? b.d(getContext(), i10) : 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 z10) { if (c()) { this.f4369c.r(z10); } } @Override // android.widget.Checkable public void setChecked(boolean z10) { if (a() && isEnabled() && this.f4377k != z10) { this.f4377k = z10; refreshDrawableState(); if (this.f4378l) { return; } this.f4378l = true; Iterator it = this.f4370d.iterator(); if (it.hasNext()) { m.a(it.next()); throw null; } this.f4378l = false; } } public void setCornerRadius(int i10) { if (c()) { this.f4369c.s(i10); } } public void setCornerRadiusResource(int i10) { if (c()) { setCornerRadius(getResources().getDimensionPixelSize(i10)); } } @Override // android.view.View public void setElevation(float f10) { super.setElevation(f10); if (c()) { this.f4369c.d().Q(f10); } } public void setIcon(Drawable drawable) { if (this.f4373g != drawable) { this.f4373g = drawable; e(true); } } public void setIconGravity(int i10) { if (this.f4379m != i10) { this.f4379m = i10; f(); } } public void setIconPadding(int i10) { if (this.f4376j != i10) { this.f4376j = i10; setCompoundDrawablePadding(i10); } } public void setIconResource(int i10) { setIcon(i10 != 0 ? b.d(getContext(), i10) : null); } public void setIconSize(int i10) { if (i10 < 0) { throw new IllegalArgumentException("iconSize cannot be less than 0"); } if (this.f4374h != i10) { this.f4374h = i10; e(true); } } public void setIconTint(ColorStateList colorStateList) { if (this.f4372f != colorStateList) { this.f4372f = colorStateList; e(false); } } public void setIconTintMode(PorterDuff.Mode mode) { if (this.f4371e != mode) { this.f4371e = mode; e(false); } } public void setIconTintResource(int i10) { setIconTint(b.c(getContext(), i10)); } void setInternalBackground(Drawable drawable) { super.setBackgroundDrawable(drawable); } void setOnPressedChangeListenerInternal(a aVar) { } @Override // android.view.View public void setPressed(boolean z10) { super.setPressed(z10); } public void setRippleColor(ColorStateList colorStateList) { if (c()) { this.f4369c.t(colorStateList); } } public void setRippleColorResource(int i10) { if (c()) { setRippleColor(b.c(getContext(), i10)); } } @Override // p3.n public void setShapeAppearanceModel(k kVar) { if (!c()) { throw new IllegalStateException("Attempted to set ShapeAppearanceModel on a MaterialButton which has an overwritten background."); } this.f4369c.u(kVar); } void setShouldDrawSurfaceColorStroke(boolean z10) { if (c()) { this.f4369c.v(z10); } } public void setStrokeColor(ColorStateList colorStateList) { if (c()) { this.f4369c.w(colorStateList); } } public void setStrokeColorResource(int i10) { if (c()) { setStrokeColor(b.c(getContext(), i10)); } } public void setStrokeWidth(int i10) { if (c()) { this.f4369c.x(i10); } } public void setStrokeWidthResource(int i10) { if (c()) { setStrokeWidth(getResources().getDimensionPixelSize(i10)); } } @Override // androidx.appcompat.widget.f public void setSupportBackgroundTintList(ColorStateList colorStateList) { if (c()) { this.f4369c.y(colorStateList); } else { super.setSupportBackgroundTintList(colorStateList); } } @Override // androidx.appcompat.widget.f public void setSupportBackgroundTintMode(PorterDuff.Mode mode) { if (c()) { this.f4369c.z(mode); } else { super.setSupportBackgroundTintMode(mode); } } @Override // android.widget.Checkable public void toggle() { setChecked(!this.f4377k); } /* JADX WARN: Illegal instructions before constructor call */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public MaterialButton(android.content.Context r9, android.util.AttributeSet r10, int r11) { /* r8 = this; int r6 = com.google.android.material.button.MaterialButton.f4368p android.content.Context r9 = com.google.android.material.internal.f.f(r9, r10, r11, r6) r8.(r9, r10, r11) java.util.LinkedHashSet r9 = new java.util.LinkedHashSet r9.() r8.f4370d = r9 r9 = 0 r8.f4377k = r9 r8.f4378l = r9 android.content.Context r7 = r8.getContext() int[] r2 = c3.j.f3607h1 int[] r5 = new int[r9] r0 = r7 r1 = r10 r3 = r11 r4 = r6 android.content.res.TypedArray r0 = com.google.android.material.internal.f.k(r0, r1, r2, r3, r4, r5) int r1 = c3.j.f3677t1 int r1 = r0.getDimensionPixelSize(r1, r9) r8.f4376j = r1 int r1 = c3.j.f3692w1 r2 = -1 int r1 = r0.getInt(r1, r2) android.graphics.PorterDuff$Mode r2 = android.graphics.PorterDuff.Mode.SRC_IN android.graphics.PorterDuff$Mode r1 = com.google.android.material.internal.g.c(r1, r2) r8.f4371e = r1 android.content.Context r1 = r8.getContext() int r2 = c3.j.f3687v1 android.content.res.ColorStateList r1 = m3.c.a(r1, r0, r2) r8.f4372f = r1 android.content.Context r1 = r8.getContext() int r2 = c3.j.f3667r1 android.graphics.drawable.Drawable r1 = m3.c.d(r1, r0, r2) r8.f4373g = r1 int r1 = c3.j.f3672s1 r2 = 1 int r1 = r0.getInteger(r1, r2) r8.f4379m = r1 int r1 = c3.j.f3682u1 int r1 = r0.getDimensionPixelSize(r1, r9) r8.f4374h = r1 p3.k$b r10 = p3.k.e(r7, r10, r11, r6) p3.k r10 = r10.m() com.google.android.material.button.a r11 = new com.google.android.material.button.a r11.(r8, r10) r8.f4369c = r11 r11.o(r0) r0.recycle() int r10 = r8.f4376j r8.setCompoundDrawablePadding(r10) android.graphics.drawable.Drawable r10 = r8.f4373g if (r10 == 0) goto L84 r9 = 1 L84: r8.e(r9) return */ throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.button.MaterialButton.(android.content.Context, android.util.AttributeSet, int):void"); } }