364 lines
11 KiB
Java
364 lines
11 KiB
Java
package com.google.android.material.button;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import androidx.appcompat.content.res.AppCompatResources;
|
|
import androidx.appcompat.widget.AppCompatButton;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.core.widget.TextViewCompat;
|
|
import com.google.android.material.R$attr;
|
|
import com.google.android.material.R$style;
|
|
import com.google.android.material.R$styleable;
|
|
import com.google.android.material.internal.ThemeEnforcement;
|
|
import com.google.android.material.internal.ViewUtils;
|
|
import com.google.android.material.resources.MaterialResources;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MaterialButton extends AppCompatButton {
|
|
private final MaterialButtonHelper c;
|
|
private int d;
|
|
private PorterDuff.Mode e;
|
|
private ColorStateList f;
|
|
private Drawable g;
|
|
private int h;
|
|
private int i;
|
|
private int j;
|
|
|
|
public MaterialButton(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, R$attr.materialButtonStyle);
|
|
}
|
|
|
|
private boolean a() {
|
|
return ViewCompat.k(this) == 1;
|
|
}
|
|
|
|
private boolean b() {
|
|
MaterialButtonHelper materialButtonHelper = this.c;
|
|
return (materialButtonHelper == null || materialButtonHelper.g()) ? false : true;
|
|
}
|
|
|
|
private void c() {
|
|
Drawable drawable = this.g;
|
|
if (drawable != null) {
|
|
this.g = drawable.mutate();
|
|
DrawableCompat.a(this.g, this.f);
|
|
PorterDuff.Mode mode = this.e;
|
|
if (mode != null) {
|
|
DrawableCompat.a(this.g, mode);
|
|
}
|
|
int i = this.h;
|
|
if (i == 0) {
|
|
i = this.g.getIntrinsicWidth();
|
|
}
|
|
int i2 = this.h;
|
|
if (i2 == 0) {
|
|
i2 = this.g.getIntrinsicHeight();
|
|
}
|
|
Drawable drawable2 = this.g;
|
|
int i3 = this.i;
|
|
drawable2.setBounds(i3, 0, i + i3, i2);
|
|
}
|
|
TextViewCompat.a(this, this.g, null, null, null);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public ColorStateList getBackgroundTintList() {
|
|
return getSupportBackgroundTintList();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public PorterDuff.Mode getBackgroundTintMode() {
|
|
return getSupportBackgroundTintMode();
|
|
}
|
|
|
|
public int getCornerRadius() {
|
|
if (b()) {
|
|
return this.c.a();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public Drawable getIcon() {
|
|
return this.g;
|
|
}
|
|
|
|
public int getIconGravity() {
|
|
return this.j;
|
|
}
|
|
|
|
public int getIconPadding() {
|
|
return this.d;
|
|
}
|
|
|
|
public int getIconSize() {
|
|
return this.h;
|
|
}
|
|
|
|
public ColorStateList getIconTint() {
|
|
return this.f;
|
|
}
|
|
|
|
public PorterDuff.Mode getIconTintMode() {
|
|
return this.e;
|
|
}
|
|
|
|
public ColorStateList getRippleColor() {
|
|
if (b()) {
|
|
return this.c.b();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public ColorStateList getStrokeColor() {
|
|
if (b()) {
|
|
return this.c.c();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int getStrokeWidth() {
|
|
if (b()) {
|
|
return this.c.d();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
|
public ColorStateList getSupportBackgroundTintList() {
|
|
return b() ? this.c.e() : super.getSupportBackgroundTintList();
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
|
public PorterDuff.Mode getSupportBackgroundTintMode() {
|
|
return b() ? this.c.f() : super.getSupportBackgroundTintMode();
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
super.onDraw(canvas);
|
|
if (Build.VERSION.SDK_INT >= 21 || !b()) {
|
|
return;
|
|
}
|
|
this.c.a(canvas);
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, android.widget.TextView, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
MaterialButtonHelper materialButtonHelper;
|
|
super.onLayout(z, i, i2, i3, i4);
|
|
if (Build.VERSION.SDK_INT != 21 || (materialButtonHelper = this.c) == null) {
|
|
return;
|
|
}
|
|
materialButtonHelper.a(i4 - i2, i3 - i);
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
if (this.g == null || this.j != 2) {
|
|
return;
|
|
}
|
|
int measureText = (int) getPaint().measureText(getText().toString());
|
|
int i3 = this.h;
|
|
if (i3 == 0) {
|
|
i3 = this.g.getIntrinsicWidth();
|
|
}
|
|
int measuredWidth = (((((getMeasuredWidth() - measureText) - ViewCompat.n(this)) - i3) - this.d) - ViewCompat.o(this)) / 2;
|
|
if (a()) {
|
|
measuredWidth = -measuredWidth;
|
|
}
|
|
if (this.i != measuredWidth) {
|
|
this.i = measuredWidth;
|
|
c();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setBackground(Drawable drawable) {
|
|
setBackgroundDrawable(drawable);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setBackgroundColor(int i) {
|
|
if (b()) {
|
|
this.c.a(i);
|
|
} else {
|
|
super.setBackgroundColor(i);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
|
public void setBackgroundDrawable(Drawable drawable) {
|
|
if (!b()) {
|
|
super.setBackgroundDrawable(drawable);
|
|
} else {
|
|
if (drawable == getBackground()) {
|
|
getBackground().setState(drawable.getState());
|
|
return;
|
|
}
|
|
Log.i("MaterialButton", "Setting a custom background is not supported.");
|
|
this.c.h();
|
|
super.setBackgroundDrawable(drawable);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
|
public void setBackgroundResource(int i) {
|
|
setBackgroundDrawable(i != 0 ? AppCompatResources.c(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 setCornerRadius(int i) {
|
|
if (b()) {
|
|
this.c.b(i);
|
|
}
|
|
}
|
|
|
|
public void setCornerRadiusResource(int i) {
|
|
if (b()) {
|
|
setCornerRadius(getResources().getDimensionPixelSize(i));
|
|
}
|
|
}
|
|
|
|
public void setIcon(Drawable drawable) {
|
|
if (this.g != drawable) {
|
|
this.g = drawable;
|
|
c();
|
|
}
|
|
}
|
|
|
|
public void setIconGravity(int i) {
|
|
this.j = i;
|
|
}
|
|
|
|
public void setIconPadding(int i) {
|
|
if (this.d != i) {
|
|
this.d = i;
|
|
setCompoundDrawablePadding(i);
|
|
}
|
|
}
|
|
|
|
public void setIconResource(int i) {
|
|
setIcon(i != 0 ? AppCompatResources.c(getContext(), i) : null);
|
|
}
|
|
|
|
public void setIconSize(int i) {
|
|
if (i < 0) {
|
|
throw new IllegalArgumentException("iconSize cannot be less than 0");
|
|
}
|
|
if (this.h != i) {
|
|
this.h = i;
|
|
c();
|
|
}
|
|
}
|
|
|
|
public void setIconTint(ColorStateList colorStateList) {
|
|
if (this.f != colorStateList) {
|
|
this.f = colorStateList;
|
|
c();
|
|
}
|
|
}
|
|
|
|
public void setIconTintMode(PorterDuff.Mode mode) {
|
|
if (this.e != mode) {
|
|
this.e = mode;
|
|
c();
|
|
}
|
|
}
|
|
|
|
public void setIconTintResource(int i) {
|
|
setIconTint(AppCompatResources.b(getContext(), i));
|
|
}
|
|
|
|
void setInternalBackground(Drawable drawable) {
|
|
super.setBackgroundDrawable(drawable);
|
|
}
|
|
|
|
public void setRippleColor(ColorStateList colorStateList) {
|
|
if (b()) {
|
|
this.c.a(colorStateList);
|
|
}
|
|
}
|
|
|
|
public void setRippleColorResource(int i) {
|
|
if (b()) {
|
|
setRippleColor(AppCompatResources.b(getContext(), i));
|
|
}
|
|
}
|
|
|
|
public void setStrokeColor(ColorStateList colorStateList) {
|
|
if (b()) {
|
|
this.c.b(colorStateList);
|
|
}
|
|
}
|
|
|
|
public void setStrokeColorResource(int i) {
|
|
if (b()) {
|
|
setStrokeColor(AppCompatResources.b(getContext(), i));
|
|
}
|
|
}
|
|
|
|
public void setStrokeWidth(int i) {
|
|
if (b()) {
|
|
this.c.c(i);
|
|
}
|
|
}
|
|
|
|
public void setStrokeWidthResource(int i) {
|
|
if (b()) {
|
|
setStrokeWidth(getResources().getDimensionPixelSize(i));
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
|
public void setSupportBackgroundTintList(ColorStateList colorStateList) {
|
|
if (b()) {
|
|
this.c.c(colorStateList);
|
|
} else if (this.c != null) {
|
|
super.setSupportBackgroundTintList(colorStateList);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
|
public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
|
|
if (b()) {
|
|
this.c.a(mode);
|
|
} else if (this.c != null) {
|
|
super.setSupportBackgroundTintMode(mode);
|
|
}
|
|
}
|
|
|
|
public MaterialButton(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
TypedArray c = ThemeEnforcement.c(context, attributeSet, R$styleable.MaterialButton, i, R$style.Widget_MaterialComponents_Button, new int[0]);
|
|
this.d = c.getDimensionPixelSize(R$styleable.MaterialButton_iconPadding, 0);
|
|
this.e = ViewUtils.a(c.getInt(R$styleable.MaterialButton_iconTintMode, -1), PorterDuff.Mode.SRC_IN);
|
|
this.f = MaterialResources.a(getContext(), c, R$styleable.MaterialButton_iconTint);
|
|
this.g = MaterialResources.b(getContext(), c, R$styleable.MaterialButton_icon);
|
|
this.j = c.getInteger(R$styleable.MaterialButton_iconGravity, 1);
|
|
this.h = c.getDimensionPixelSize(R$styleable.MaterialButton_iconSize, 0);
|
|
this.c = new MaterialButtonHelper(this);
|
|
this.c.a(c);
|
|
c.recycle();
|
|
setCompoundDrawablePadding(this.d);
|
|
c();
|
|
}
|
|
}
|