ADD week 5
This commit is contained in:
@ -0,0 +1,860 @@
|
||||
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.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.Layout;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.inspector.PropertyMapper;
|
||||
import android.view.inspector.PropertyReader;
|
||||
import android.widget.Button;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.CompoundButton;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.widget.TextViewCompat;
|
||||
import androidx.customview.view.AbsSavedState;
|
||||
import androidx.tracing.Trace$$ExternalSyntheticApiModelOutline0;
|
||||
import com.google.android.material.shape.MaterialShapeUtils;
|
||||
import com.google.android.material.shape.ShapeAppearanceModel;
|
||||
import com.google.android.material.shape.Shapeable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class MaterialButton extends AppCompatButton implements Checkable, Shapeable {
|
||||
private static final int[] CHECKABLE_STATE_SET = {R.attr.state_checkable};
|
||||
private static final int[] CHECKED_STATE_SET = {R.attr.state_checked};
|
||||
private static final int DEF_STYLE_RES = com.google.android.material.R.style.Widget_MaterialComponents_Button;
|
||||
public static final int ICON_GRAVITY_END = 3;
|
||||
public static final int ICON_GRAVITY_START = 1;
|
||||
public static final int ICON_GRAVITY_TEXT_END = 4;
|
||||
public static final int ICON_GRAVITY_TEXT_START = 2;
|
||||
public static final int ICON_GRAVITY_TEXT_TOP = 32;
|
||||
public static final int ICON_GRAVITY_TOP = 16;
|
||||
private static final String LOG_TAG = "MaterialButton";
|
||||
private String accessibilityClassName;
|
||||
private boolean broadcasting;
|
||||
private boolean checked;
|
||||
private Drawable icon;
|
||||
private int iconGravity;
|
||||
private int iconLeft;
|
||||
private int iconPadding;
|
||||
private int iconSize;
|
||||
private ColorStateList iconTint;
|
||||
private PorterDuff.Mode iconTintMode;
|
||||
private int iconTop;
|
||||
private final MaterialButtonHelper materialButtonHelper;
|
||||
private final LinkedHashSet<OnCheckedChangeListener> onCheckedChangeListeners;
|
||||
private OnPressedChangeListener onPressedChangeListenerInternal;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface IconGravity {
|
||||
}
|
||||
|
||||
public interface OnCheckedChangeListener {
|
||||
void onCheckedChanged(MaterialButton materialButton, boolean z);
|
||||
}
|
||||
|
||||
interface OnPressedChangeListener {
|
||||
void onPressedChanged(MaterialButton materialButton, boolean z);
|
||||
}
|
||||
|
||||
private boolean isIconEnd() {
|
||||
int i = this.iconGravity;
|
||||
return i == 3 || i == 4;
|
||||
}
|
||||
|
||||
private boolean isIconStart() {
|
||||
int i = this.iconGravity;
|
||||
return i == 1 || i == 2;
|
||||
}
|
||||
|
||||
private boolean isIconTop() {
|
||||
int i = this.iconGravity;
|
||||
return i == 16 || i == 32;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public int getIconGravity() {
|
||||
return this.iconGravity;
|
||||
}
|
||||
|
||||
public int getIconPadding() {
|
||||
return this.iconPadding;
|
||||
}
|
||||
|
||||
public int getIconSize() {
|
||||
return this.iconSize;
|
||||
}
|
||||
|
||||
public ColorStateList getIconTint() {
|
||||
return this.iconTint;
|
||||
}
|
||||
|
||||
public PorterDuff.Mode getIconTintMode() {
|
||||
return this.iconTintMode;
|
||||
}
|
||||
|
||||
@Override // android.widget.Checkable
|
||||
public boolean isChecked() {
|
||||
return this.checked;
|
||||
}
|
||||
|
||||
void setA11yClassName(String str) {
|
||||
this.accessibilityClassName = str;
|
||||
}
|
||||
|
||||
void setOnPressedChangeListenerInternal(OnPressedChangeListener onPressedChangeListener) {
|
||||
this.onPressedChangeListenerInternal = onPressedChangeListener;
|
||||
}
|
||||
|
||||
public final class InspectionCompanion implements android.view.inspector.InspectionCompanion<MaterialButton> {
|
||||
private int mIconPaddingId;
|
||||
private boolean mPropertiesMapped = false;
|
||||
|
||||
@Override // android.view.inspector.InspectionCompanion
|
||||
public void mapProperties(PropertyMapper propertyMapper) {
|
||||
int mapInt;
|
||||
mapInt = propertyMapper.mapInt("iconPadding", com.google.android.material.R.attr.iconPadding);
|
||||
this.mIconPaddingId = mapInt;
|
||||
this.mPropertiesMapped = true;
|
||||
}
|
||||
|
||||
@Override // android.view.inspector.InspectionCompanion
|
||||
public void readProperties(MaterialButton materialButton, PropertyReader propertyReader) {
|
||||
if (!this.mPropertiesMapped) {
|
||||
throw Trace$$ExternalSyntheticApiModelOutline0.m176m();
|
||||
}
|
||||
propertyReader.readInt(this.mIconPaddingId, materialButton.getIconPadding());
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialButton(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MaterialButton(Context context, AttributeSet attributeSet) {
|
||||
this(context, attributeSet, com.google.android.material.R.attr.materialButtonStyle);
|
||||
}
|
||||
|
||||
/* JADX WARN: Illegal instructions before constructor call */
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct add '--show-bad-code' argument
|
||||
*/
|
||||
public MaterialButton(android.content.Context r9, android.util.AttributeSet r10, int r11) {
|
||||
/*
|
||||
r8 = this;
|
||||
int r6 = com.google.android.material.button.MaterialButton.DEF_STYLE_RES
|
||||
android.content.Context r9 = com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap(r9, r10, r11, r6)
|
||||
r8.<init>(r9, r10, r11)
|
||||
java.util.LinkedHashSet r9 = new java.util.LinkedHashSet
|
||||
r9.<init>()
|
||||
r8.onCheckedChangeListeners = r9
|
||||
r9 = 0
|
||||
r8.checked = r9
|
||||
r8.broadcasting = r9
|
||||
android.content.Context r7 = r8.getContext()
|
||||
int[] r2 = com.google.android.material.R.styleable.MaterialButton
|
||||
int[] r5 = new int[r9]
|
||||
r0 = r7
|
||||
r1 = r10
|
||||
r3 = r11
|
||||
r4 = r6
|
||||
android.content.res.TypedArray r0 = com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(r0, r1, r2, r3, r4, r5)
|
||||
int r1 = com.google.android.material.R.styleable.MaterialButton_iconPadding
|
||||
int r1 = r0.getDimensionPixelSize(r1, r9)
|
||||
r8.iconPadding = r1
|
||||
int r1 = com.google.android.material.R.styleable.MaterialButton_iconTintMode
|
||||
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.ViewUtils.parseTintMode(r1, r2)
|
||||
r8.iconTintMode = r1
|
||||
android.content.Context r1 = r8.getContext()
|
||||
int r2 = com.google.android.material.R.styleable.MaterialButton_iconTint
|
||||
android.content.res.ColorStateList r1 = com.google.android.material.resources.MaterialResources.getColorStateList(r1, r0, r2)
|
||||
r8.iconTint = r1
|
||||
android.content.Context r1 = r8.getContext()
|
||||
int r2 = com.google.android.material.R.styleable.MaterialButton_icon
|
||||
android.graphics.drawable.Drawable r1 = com.google.android.material.resources.MaterialResources.getDrawable(r1, r0, r2)
|
||||
r8.icon = r1
|
||||
int r1 = com.google.android.material.R.styleable.MaterialButton_iconGravity
|
||||
r2 = 1
|
||||
int r1 = r0.getInteger(r1, r2)
|
||||
r8.iconGravity = r1
|
||||
int r1 = com.google.android.material.R.styleable.MaterialButton_iconSize
|
||||
int r1 = r0.getDimensionPixelSize(r1, r9)
|
||||
r8.iconSize = r1
|
||||
com.google.android.material.shape.ShapeAppearanceModel$Builder r10 = com.google.android.material.shape.ShapeAppearanceModel.builder(r7, r10, r11, r6)
|
||||
com.google.android.material.shape.ShapeAppearanceModel r10 = r10.build()
|
||||
com.google.android.material.button.MaterialButtonHelper r11 = new com.google.android.material.button.MaterialButtonHelper
|
||||
r11.<init>(r8, r10)
|
||||
r8.materialButtonHelper = r11
|
||||
r11.loadFromAttributes(r0)
|
||||
r0.recycle()
|
||||
int r10 = r8.iconPadding
|
||||
r8.setCompoundDrawablePadding(r10)
|
||||
android.graphics.drawable.Drawable r10 = r8.icon
|
||||
if (r10 == 0) goto L84
|
||||
r9 = 1
|
||||
L84:
|
||||
r8.updateIcon(r9)
|
||||
return
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.button.MaterialButton.<init>(android.content.Context, android.util.AttributeSet, int):void");
|
||||
}
|
||||
|
||||
String getA11yClassName() {
|
||||
if (TextUtils.isEmpty(this.accessibilityClassName)) {
|
||||
return (isCheckable() ? CompoundButton.class : Button.class).getName();
|
||||
}
|
||||
return this.accessibilityClassName;
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
||||
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
|
||||
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
||||
accessibilityNodeInfo.setClassName(getA11yClassName());
|
||||
accessibilityNodeInfo.setCheckable(isCheckable());
|
||||
accessibilityNodeInfo.setChecked(isChecked());
|
||||
accessibilityNodeInfo.setClickable(isClickable());
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
||||
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
||||
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
||||
accessibilityEvent.setClassName(getA11yClassName());
|
||||
accessibilityEvent.setChecked(isChecked());
|
||||
}
|
||||
|
||||
@Override // android.widget.TextView, android.view.View
|
||||
public Parcelable onSaveInstanceState() {
|
||||
SavedState savedState = new SavedState(super.onSaveInstanceState());
|
||||
savedState.checked = this.checked;
|
||||
return savedState;
|
||||
}
|
||||
|
||||
@Override // android.widget.TextView, android.view.View
|
||||
public void onRestoreInstanceState(Parcelable parcelable) {
|
||||
if (!(parcelable instanceof SavedState)) {
|
||||
super.onRestoreInstanceState(parcelable);
|
||||
return;
|
||||
}
|
||||
SavedState savedState = (SavedState) parcelable;
|
||||
super.onRestoreInstanceState(savedState.getSuperState());
|
||||
setChecked(savedState.checked);
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
||||
public void setSupportBackgroundTintList(ColorStateList colorStateList) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setSupportBackgroundTintList(colorStateList);
|
||||
} else {
|
||||
super.setSupportBackgroundTintList(colorStateList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
||||
public ColorStateList getSupportBackgroundTintList() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getSupportBackgroundTintList();
|
||||
}
|
||||
return super.getSupportBackgroundTintList();
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
||||
public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setSupportBackgroundTintMode(mode);
|
||||
} else {
|
||||
super.setSupportBackgroundTintMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, androidx.core.view.TintableBackgroundView
|
||||
public PorterDuff.Mode getSupportBackgroundTintMode() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getSupportBackgroundTintMode();
|
||||
}
|
||||
return super.getSupportBackgroundTintMode();
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setBackgroundTintList(ColorStateList colorStateList) {
|
||||
setSupportBackgroundTintList(colorStateList);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public ColorStateList getBackgroundTintList() {
|
||||
return getSupportBackgroundTintList();
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setBackgroundTintMode(PorterDuff.Mode mode) {
|
||||
setSupportBackgroundTintMode(mode);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public PorterDuff.Mode getBackgroundTintMode() {
|
||||
return getSupportBackgroundTintMode();
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setBackgroundColor(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setBackgroundColor(i);
|
||||
} else {
|
||||
super.setBackgroundColor(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setBackground(Drawable drawable) {
|
||||
setBackgroundDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
||||
public void setBackgroundResource(int i) {
|
||||
setBackgroundDrawable(i != 0 ? AppCompatResources.getDrawable(getContext(), i) : null);
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, android.view.View
|
||||
public void setBackgroundDrawable(Drawable drawable) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
if (drawable != getBackground()) {
|
||||
Log.w(LOG_TAG, "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");
|
||||
this.materialButtonHelper.setBackgroundOverwritten();
|
||||
super.setBackgroundDrawable(drawable);
|
||||
return;
|
||||
}
|
||||
getBackground().setState(drawable.getState());
|
||||
return;
|
||||
}
|
||||
super.setBackgroundDrawable(drawable);
|
||||
}
|
||||
|
||||
@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.materialButtonHelper) != null) {
|
||||
materialButtonHelper.updateMaskBounds(i4 - i2, i3 - i);
|
||||
}
|
||||
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
|
||||
@Override // androidx.appcompat.widget.AppCompatButton, android.widget.TextView
|
||||
protected void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
super.onTextChanged(charSequence, i, i2, i3);
|
||||
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
|
||||
@Override // android.widget.TextView, android.view.View
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (isUsingOriginalBackground()) {
|
||||
MaterialShapeUtils.setParentAbsoluteElevation(this, this.materialButtonHelper.getMaterialShapeDrawable());
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setElevation(float f) {
|
||||
super.setElevation(f);
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.getMaterialShapeDrawable().setElevation(f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void refreshDrawableState() {
|
||||
super.refreshDrawableState();
|
||||
if (this.icon != null) {
|
||||
if (this.icon.setState(getDrawableState())) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setTextAlignment(int i) {
|
||||
super.setTextAlignment(i);
|
||||
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
|
||||
private Layout.Alignment getGravityTextAlignment() {
|
||||
int gravity = getGravity() & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK;
|
||||
if (gravity == 1) {
|
||||
return Layout.Alignment.ALIGN_CENTER;
|
||||
}
|
||||
if (gravity == 5 || gravity == 8388613) {
|
||||
return Layout.Alignment.ALIGN_OPPOSITE;
|
||||
}
|
||||
return Layout.Alignment.ALIGN_NORMAL;
|
||||
}
|
||||
|
||||
private Layout.Alignment getActualTextAlignment() {
|
||||
int textAlignment = getTextAlignment();
|
||||
if (textAlignment == 1) {
|
||||
return getGravityTextAlignment();
|
||||
}
|
||||
if (textAlignment == 6 || textAlignment == 3) {
|
||||
return Layout.Alignment.ALIGN_OPPOSITE;
|
||||
}
|
||||
if (textAlignment == 4) {
|
||||
return Layout.Alignment.ALIGN_CENTER;
|
||||
}
|
||||
return Layout.Alignment.ALIGN_NORMAL;
|
||||
}
|
||||
|
||||
private void updateIconPosition(int i, int i2) {
|
||||
if (this.icon == null || getLayout() == null) {
|
||||
return;
|
||||
}
|
||||
if (isIconStart() || isIconEnd()) {
|
||||
this.iconTop = 0;
|
||||
Layout.Alignment actualTextAlignment = getActualTextAlignment();
|
||||
int i3 = this.iconGravity;
|
||||
if (i3 == 1 || i3 == 3 || ((i3 == 2 && actualTextAlignment == Layout.Alignment.ALIGN_NORMAL) || (this.iconGravity == 4 && actualTextAlignment == Layout.Alignment.ALIGN_OPPOSITE))) {
|
||||
this.iconLeft = 0;
|
||||
updateIcon(false);
|
||||
return;
|
||||
}
|
||||
int i4 = this.iconSize;
|
||||
if (i4 == 0) {
|
||||
i4 = this.icon.getIntrinsicWidth();
|
||||
}
|
||||
int textLayoutWidth = ((((i - getTextLayoutWidth()) - ViewCompat.getPaddingEnd(this)) - i4) - this.iconPadding) - ViewCompat.getPaddingStart(this);
|
||||
if (actualTextAlignment == Layout.Alignment.ALIGN_CENTER) {
|
||||
textLayoutWidth /= 2;
|
||||
}
|
||||
if (isLayoutRTL() != (this.iconGravity == 4)) {
|
||||
textLayoutWidth = -textLayoutWidth;
|
||||
}
|
||||
if (this.iconLeft != textLayoutWidth) {
|
||||
this.iconLeft = textLayoutWidth;
|
||||
updateIcon(false);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isIconTop()) {
|
||||
this.iconLeft = 0;
|
||||
if (this.iconGravity == 16) {
|
||||
this.iconTop = 0;
|
||||
updateIcon(false);
|
||||
return;
|
||||
}
|
||||
int i5 = this.iconSize;
|
||||
if (i5 == 0) {
|
||||
i5 = this.icon.getIntrinsicHeight();
|
||||
}
|
||||
int max = Math.max(0, (((((i2 - getTextHeight()) - getPaddingTop()) - i5) - this.iconPadding) - getPaddingBottom()) / 2);
|
||||
if (this.iconTop != max) {
|
||||
this.iconTop = max;
|
||||
updateIcon(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getTextLayoutWidth() {
|
||||
int lineCount = getLineCount();
|
||||
float f = 0.0f;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
f = Math.max(f, getLayout().getLineWidth(i));
|
||||
}
|
||||
return (int) Math.ceil(f);
|
||||
}
|
||||
|
||||
private int getTextHeight() {
|
||||
if (getLineCount() > 1) {
|
||||
return getLayout().getHeight();
|
||||
}
|
||||
TextPaint paint = getPaint();
|
||||
String charSequence = getText().toString();
|
||||
if (getTransformationMethod() != null) {
|
||||
charSequence = getTransformationMethod().getTransformation(charSequence, this).toString();
|
||||
}
|
||||
Rect rect = new Rect();
|
||||
paint.getTextBounds(charSequence, 0, charSequence.length(), rect);
|
||||
return Math.min(rect.height(), getLayout().getHeight());
|
||||
}
|
||||
|
||||
private boolean isLayoutRTL() {
|
||||
return ViewCompat.getLayoutDirection(this) == 1;
|
||||
}
|
||||
|
||||
void setInternalBackground(Drawable drawable) {
|
||||
super.setBackgroundDrawable(drawable);
|
||||
}
|
||||
|
||||
public void setIconPadding(int i) {
|
||||
if (this.iconPadding != i) {
|
||||
this.iconPadding = i;
|
||||
setCompoundDrawablePadding(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIconSize(int i) {
|
||||
if (i < 0) {
|
||||
throw new IllegalArgumentException("iconSize cannot be less than 0");
|
||||
}
|
||||
if (this.iconSize != i) {
|
||||
this.iconSize = i;
|
||||
updateIcon(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIcon(Drawable drawable) {
|
||||
if (this.icon != drawable) {
|
||||
this.icon = drawable;
|
||||
updateIcon(true);
|
||||
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public void setIconResource(int i) {
|
||||
setIcon(i != 0 ? AppCompatResources.getDrawable(getContext(), i) : null);
|
||||
}
|
||||
|
||||
public void setIconTint(ColorStateList colorStateList) {
|
||||
if (this.iconTint != colorStateList) {
|
||||
this.iconTint = colorStateList;
|
||||
updateIcon(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIconTintResource(int i) {
|
||||
setIconTint(AppCompatResources.getColorStateList(getContext(), i));
|
||||
}
|
||||
|
||||
public void setIconTintMode(PorterDuff.Mode mode) {
|
||||
if (this.iconTintMode != mode) {
|
||||
this.iconTintMode = mode;
|
||||
updateIcon(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateIcon(boolean z) {
|
||||
Drawable drawable = this.icon;
|
||||
if (drawable != null) {
|
||||
Drawable mutate = DrawableCompat.wrap(drawable).mutate();
|
||||
this.icon = mutate;
|
||||
DrawableCompat.setTintList(mutate, this.iconTint);
|
||||
PorterDuff.Mode mode = this.iconTintMode;
|
||||
if (mode != null) {
|
||||
DrawableCompat.setTintMode(this.icon, mode);
|
||||
}
|
||||
int i = this.iconSize;
|
||||
if (i == 0) {
|
||||
i = this.icon.getIntrinsicWidth();
|
||||
}
|
||||
int i2 = this.iconSize;
|
||||
if (i2 == 0) {
|
||||
i2 = this.icon.getIntrinsicHeight();
|
||||
}
|
||||
Drawable drawable2 = this.icon;
|
||||
int i3 = this.iconLeft;
|
||||
int i4 = this.iconTop;
|
||||
drawable2.setBounds(i3, i4, i + i3, i2 + i4);
|
||||
this.icon.setVisible(true, z);
|
||||
}
|
||||
if (z) {
|
||||
resetIconDrawable();
|
||||
return;
|
||||
}
|
||||
Drawable[] compoundDrawablesRelative = TextViewCompat.getCompoundDrawablesRelative(this);
|
||||
Drawable drawable3 = compoundDrawablesRelative[0];
|
||||
Drawable drawable4 = compoundDrawablesRelative[1];
|
||||
Drawable drawable5 = compoundDrawablesRelative[2];
|
||||
if ((!isIconStart() || drawable3 == this.icon) && ((!isIconEnd() || drawable5 == this.icon) && (!isIconTop() || drawable4 == this.icon))) {
|
||||
return;
|
||||
}
|
||||
resetIconDrawable();
|
||||
}
|
||||
|
||||
private void resetIconDrawable() {
|
||||
if (isIconStart()) {
|
||||
TextViewCompat.setCompoundDrawablesRelative(this, this.icon, null, null, null);
|
||||
} else if (isIconEnd()) {
|
||||
TextViewCompat.setCompoundDrawablesRelative(this, null, null, this.icon, null);
|
||||
} else if (isIconTop()) {
|
||||
TextViewCompat.setCompoundDrawablesRelative(this, null, this.icon, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRippleColor(ColorStateList colorStateList) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setRippleColor(colorStateList);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRippleColorResource(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
setRippleColor(AppCompatResources.getColorStateList(getContext(), i));
|
||||
}
|
||||
}
|
||||
|
||||
public ColorStateList getRippleColor() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getRippleColor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setStrokeColor(ColorStateList colorStateList) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setStrokeColor(colorStateList);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStrokeColorResource(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
setStrokeColor(AppCompatResources.getColorStateList(getContext(), i));
|
||||
}
|
||||
}
|
||||
|
||||
public ColorStateList getStrokeColor() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getStrokeColor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setStrokeWidth(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setStrokeWidth(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStrokeWidthResource(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
setStrokeWidth(getResources().getDimensionPixelSize(i));
|
||||
}
|
||||
}
|
||||
|
||||
public int getStrokeWidth() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getStrokeWidth();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setCornerRadius(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setCornerRadius(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCornerRadiusResource(int i) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
setCornerRadius(getResources().getDimensionPixelSize(i));
|
||||
}
|
||||
}
|
||||
|
||||
public int getCornerRadius() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getCornerRadius();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setIconGravity(int i) {
|
||||
if (this.iconGravity != i) {
|
||||
this.iconGravity = i;
|
||||
updateIconPosition(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public void setInsetBottom(int i) {
|
||||
this.materialButtonHelper.setInsetBottom(i);
|
||||
}
|
||||
|
||||
public int getInsetBottom() {
|
||||
return this.materialButtonHelper.getInsetBottom();
|
||||
}
|
||||
|
||||
public void setInsetTop(int i) {
|
||||
this.materialButtonHelper.setInsetTop(i);
|
||||
}
|
||||
|
||||
public int getInsetTop() {
|
||||
return this.materialButtonHelper.getInsetTop();
|
||||
}
|
||||
|
||||
@Override // android.widget.TextView, android.view.View
|
||||
protected int[] onCreateDrawableState(int i) {
|
||||
int[] onCreateDrawableState = super.onCreateDrawableState(i + 2);
|
||||
if (isCheckable()) {
|
||||
mergeDrawableStates(onCreateDrawableState, CHECKABLE_STATE_SET);
|
||||
}
|
||||
if (isChecked()) {
|
||||
mergeDrawableStates(onCreateDrawableState, CHECKED_STATE_SET);
|
||||
}
|
||||
return onCreateDrawableState;
|
||||
}
|
||||
|
||||
public void addOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
|
||||
this.onCheckedChangeListeners.add(onCheckedChangeListener);
|
||||
}
|
||||
|
||||
public void removeOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
|
||||
this.onCheckedChangeListeners.remove(onCheckedChangeListener);
|
||||
}
|
||||
|
||||
public void clearOnCheckedChangeListeners() {
|
||||
this.onCheckedChangeListeners.clear();
|
||||
}
|
||||
|
||||
@Override // android.widget.Checkable
|
||||
public void setChecked(boolean z) {
|
||||
if (isCheckable() && isEnabled() && this.checked != z) {
|
||||
this.checked = z;
|
||||
refreshDrawableState();
|
||||
if (getParent() instanceof MaterialButtonToggleGroup) {
|
||||
((MaterialButtonToggleGroup) getParent()).onButtonCheckedStateChanged(this, this.checked);
|
||||
}
|
||||
if (this.broadcasting) {
|
||||
return;
|
||||
}
|
||||
this.broadcasting = true;
|
||||
Iterator<OnCheckedChangeListener> it = this.onCheckedChangeListeners.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().onCheckedChanged(this, this.checked);
|
||||
}
|
||||
this.broadcasting = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.widget.Checkable
|
||||
public void toggle() {
|
||||
setChecked(!this.checked);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public boolean performClick() {
|
||||
if (this.materialButtonHelper.isToggleCheckedStateOnClick()) {
|
||||
toggle();
|
||||
}
|
||||
return super.performClick();
|
||||
}
|
||||
|
||||
public boolean isToggleCheckedStateOnClick() {
|
||||
return this.materialButtonHelper.isToggleCheckedStateOnClick();
|
||||
}
|
||||
|
||||
public void setToggleCheckedStateOnClick(boolean z) {
|
||||
this.materialButtonHelper.setToggleCheckedStateOnClick(z);
|
||||
}
|
||||
|
||||
public boolean isCheckable() {
|
||||
MaterialButtonHelper materialButtonHelper = this.materialButtonHelper;
|
||||
return materialButtonHelper != null && materialButtonHelper.isCheckable();
|
||||
}
|
||||
|
||||
public void setCheckable(boolean z) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setCheckable(z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.shape.Shapeable
|
||||
public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setShapeAppearanceModel(shapeAppearanceModel);
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException("Attempted to set ShapeAppearanceModel on a MaterialButton which has an overwritten background.");
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.shape.Shapeable
|
||||
public ShapeAppearanceModel getShapeAppearanceModel() {
|
||||
if (isUsingOriginalBackground()) {
|
||||
return this.materialButtonHelper.getShapeAppearanceModel();
|
||||
}
|
||||
throw new IllegalStateException("Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background.");
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setPressed(boolean z) {
|
||||
OnPressedChangeListener onPressedChangeListener = this.onPressedChangeListenerInternal;
|
||||
if (onPressedChangeListener != null) {
|
||||
onPressedChangeListener.onPressedChanged(this, z);
|
||||
}
|
||||
super.setPressed(z);
|
||||
}
|
||||
|
||||
private boolean isUsingOriginalBackground() {
|
||||
MaterialButtonHelper materialButtonHelper = this.materialButtonHelper;
|
||||
return (materialButtonHelper == null || materialButtonHelper.isBackgroundOverwritten()) ? false : true;
|
||||
}
|
||||
|
||||
void setShouldDrawSurfaceColorStroke(boolean z) {
|
||||
if (isUsingOriginalBackground()) {
|
||||
this.materialButtonHelper.setShouldDrawSurfaceColorStroke(z);
|
||||
}
|
||||
}
|
||||
|
||||
static class SavedState extends AbsSavedState {
|
||||
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.ClassLoaderCreator<SavedState>() { // from class: com.google.android.material.button.MaterialButton.SavedState.1
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // android.os.Parcelable.ClassLoaderCreator
|
||||
public SavedState createFromParcel(Parcel parcel, ClassLoader classLoader) {
|
||||
return new SavedState(parcel, classLoader);
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public SavedState createFromParcel(Parcel parcel) {
|
||||
return new SavedState(parcel, null);
|
||||
}
|
||||
|
||||
@Override // android.os.Parcelable.Creator
|
||||
public SavedState[] newArray(int i) {
|
||||
return new SavedState[i];
|
||||
}
|
||||
};
|
||||
boolean checked;
|
||||
|
||||
public SavedState(Parcelable parcelable) {
|
||||
super(parcelable);
|
||||
}
|
||||
|
||||
public SavedState(Parcel parcel, ClassLoader classLoader) {
|
||||
super(parcel, classLoader);
|
||||
if (classLoader == null) {
|
||||
getClass().getClassLoader();
|
||||
}
|
||||
readFromParcel(parcel);
|
||||
}
|
||||
|
||||
@Override // androidx.customview.view.AbsSavedState, android.os.Parcelable
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
super.writeToParcel(parcel, i);
|
||||
parcel.writeInt(this.checked ? 1 : 0);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel parcel) {
|
||||
this.checked = parcel.readInt() == 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,355 @@
|
||||
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;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class MaterialButtonHelper {
|
||||
private static final boolean IS_LOLLIPOP;
|
||||
private static final boolean IS_MIN_LOLLIPOP = true;
|
||||
private ColorStateList backgroundTint;
|
||||
private PorterDuff.Mode backgroundTintMode;
|
||||
private boolean checkable;
|
||||
private int cornerRadius;
|
||||
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 ColorStateList strokeColor;
|
||||
private int strokeWidth;
|
||||
private boolean shouldDrawSurfaceColorStroke = false;
|
||||
private boolean backgroundOverwritten = false;
|
||||
private boolean cornerRadiusSet = false;
|
||||
private boolean toggleCheckedStateOnClick = true;
|
||||
|
||||
static {
|
||||
IS_LOLLIPOP = Build.VERSION.SDK_INT <= 22;
|
||||
}
|
||||
|
||||
int getCornerRadius() {
|
||||
return this.cornerRadius;
|
||||
}
|
||||
|
||||
public int getInsetBottom() {
|
||||
return this.insetBottom;
|
||||
}
|
||||
|
||||
public int getInsetTop() {
|
||||
return this.insetTop;
|
||||
}
|
||||
|
||||
ColorStateList getRippleColor() {
|
||||
return this.rippleColor;
|
||||
}
|
||||
|
||||
ShapeAppearanceModel getShapeAppearanceModel() {
|
||||
return this.shapeAppearanceModel;
|
||||
}
|
||||
|
||||
ColorStateList getStrokeColor() {
|
||||
return this.strokeColor;
|
||||
}
|
||||
|
||||
int getStrokeWidth() {
|
||||
return this.strokeWidth;
|
||||
}
|
||||
|
||||
ColorStateList getSupportBackgroundTintList() {
|
||||
return this.backgroundTint;
|
||||
}
|
||||
|
||||
PorterDuff.Mode getSupportBackgroundTintMode() {
|
||||
return this.backgroundTintMode;
|
||||
}
|
||||
|
||||
boolean isBackgroundOverwritten() {
|
||||
return this.backgroundOverwritten;
|
||||
}
|
||||
|
||||
boolean isCheckable() {
|
||||
return this.checkable;
|
||||
}
|
||||
|
||||
boolean isToggleCheckedStateOnClick() {
|
||||
return this.toggleCheckedStateOnClick;
|
||||
}
|
||||
|
||||
void setCheckable(boolean z) {
|
||||
this.checkable = z;
|
||||
}
|
||||
|
||||
void setToggleCheckedStateOnClick(boolean z) {
|
||||
this.toggleCheckedStateOnClick = z;
|
||||
}
|
||||
|
||||
MaterialButtonHelper(MaterialButton materialButton, ShapeAppearanceModel shapeAppearanceModel) {
|
||||
this.materialButton = materialButton;
|
||||
this.shapeAppearanceModel = shapeAppearanceModel;
|
||||
}
|
||||
|
||||
void loadFromAttributes(TypedArray typedArray) {
|
||||
this.insetLeft = typedArray.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetLeft, 0);
|
||||
this.insetRight = typedArray.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetRight, 0);
|
||||
this.insetTop = typedArray.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetTop, 0);
|
||||
this.insetBottom = typedArray.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetBottom, 0);
|
||||
if (typedArray.hasValue(R.styleable.MaterialButton_cornerRadius)) {
|
||||
int dimensionPixelSize = typedArray.getDimensionPixelSize(R.styleable.MaterialButton_cornerRadius, -1);
|
||||
this.cornerRadius = dimensionPixelSize;
|
||||
setShapeAppearanceModel(this.shapeAppearanceModel.withCornerSize(dimensionPixelSize));
|
||||
this.cornerRadiusSet = true;
|
||||
}
|
||||
this.strokeWidth = typedArray.getDimensionPixelSize(R.styleable.MaterialButton_strokeWidth, 0);
|
||||
this.backgroundTintMode = ViewUtils.parseTintMode(typedArray.getInt(R.styleable.MaterialButton_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN);
|
||||
this.backgroundTint = MaterialResources.getColorStateList(this.materialButton.getContext(), typedArray, R.styleable.MaterialButton_backgroundTint);
|
||||
this.strokeColor = MaterialResources.getColorStateList(this.materialButton.getContext(), typedArray, R.styleable.MaterialButton_strokeColor);
|
||||
this.rippleColor = MaterialResources.getColorStateList(this.materialButton.getContext(), typedArray, R.styleable.MaterialButton_rippleColor);
|
||||
this.checkable = typedArray.getBoolean(R.styleable.MaterialButton_android_checkable, false);
|
||||
this.elevation = typedArray.getDimensionPixelSize(R.styleable.MaterialButton_elevation, 0);
|
||||
this.toggleCheckedStateOnClick = typedArray.getBoolean(R.styleable.MaterialButton_toggleCheckedStateOnClick, true);
|
||||
int paddingStart = ViewCompat.getPaddingStart(this.materialButton);
|
||||
int paddingTop = this.materialButton.getPaddingTop();
|
||||
int paddingEnd = ViewCompat.getPaddingEnd(this.materialButton);
|
||||
int paddingBottom = this.materialButton.getPaddingBottom();
|
||||
if (typedArray.hasValue(R.styleable.MaterialButton_android_background)) {
|
||||
setBackgroundOverwritten();
|
||||
} else {
|
||||
updateBackground();
|
||||
}
|
||||
ViewCompat.setPaddingRelative(this.materialButton, paddingStart + this.insetLeft, paddingTop + this.insetTop, paddingEnd + this.insetRight, paddingBottom + this.insetBottom);
|
||||
}
|
||||
|
||||
private void updateBackground() {
|
||||
this.materialButton.setInternalBackground(createBackground());
|
||||
MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
|
||||
if (materialShapeDrawable != null) {
|
||||
materialShapeDrawable.setElevation(this.elevation);
|
||||
materialShapeDrawable.setState(this.materialButton.getDrawableState());
|
||||
}
|
||||
}
|
||||
|
||||
void setBackgroundOverwritten() {
|
||||
this.backgroundOverwritten = true;
|
||||
this.materialButton.setSupportBackgroundTintList(this.backgroundTint);
|
||||
this.materialButton.setSupportBackgroundTintMode(this.backgroundTintMode);
|
||||
}
|
||||
|
||||
private InsetDrawable wrapDrawableWithInset(Drawable drawable) {
|
||||
return new InsetDrawable(drawable, this.insetLeft, this.insetTop, this.insetRight, this.insetBottom);
|
||||
}
|
||||
|
||||
void setSupportBackgroundTintList(ColorStateList colorStateList) {
|
||||
if (this.backgroundTint != colorStateList) {
|
||||
this.backgroundTint = colorStateList;
|
||||
if (getMaterialShapeDrawable() != null) {
|
||||
DrawableCompat.setTintList(getMaterialShapeDrawable(), this.backgroundTint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
|
||||
if (this.backgroundTintMode != mode) {
|
||||
this.backgroundTintMode = mode;
|
||||
if (getMaterialShapeDrawable() == null || this.backgroundTintMode == null) {
|
||||
return;
|
||||
}
|
||||
DrawableCompat.setTintMode(getMaterialShapeDrawable(), this.backgroundTintMode);
|
||||
}
|
||||
}
|
||||
|
||||
void setShouldDrawSurfaceColorStroke(boolean z) {
|
||||
this.shouldDrawSurfaceColorStroke = z;
|
||||
updateStroke();
|
||||
}
|
||||
|
||||
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(this.strokeWidth, this.strokeColor);
|
||||
MaterialShapeDrawable materialShapeDrawable2 = new MaterialShapeDrawable(this.shapeAppearanceModel);
|
||||
materialShapeDrawable2.setTint(0);
|
||||
materialShapeDrawable2.setStroke(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 rippleDrawable = new RippleDrawable(RippleUtils.sanitizeRippleDrawableColor(this.rippleColor), wrapDrawableWithInset(new LayerDrawable(new Drawable[]{materialShapeDrawable2, materialShapeDrawable})), this.maskDrawable);
|
||||
this.rippleDrawable = rippleDrawable;
|
||||
return rippleDrawable;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void updateMaskBounds(int i, int i2) {
|
||||
Drawable drawable = this.maskDrawable;
|
||||
if (drawable != null) {
|
||||
drawable.setBounds(this.insetLeft, this.insetTop, i2 - this.insetRight, i - this.insetBottom);
|
||||
}
|
||||
}
|
||||
|
||||
void setBackgroundColor(int i) {
|
||||
if (getMaterialShapeDrawable() != null) {
|
||||
getMaterialShapeDrawable().setTint(i);
|
||||
}
|
||||
}
|
||||
|
||||
void setRippleColor(ColorStateList colorStateList) {
|
||||
if (this.rippleColor != colorStateList) {
|
||||
this.rippleColor = colorStateList;
|
||||
boolean z = IS_MIN_LOLLIPOP;
|
||||
if (z && (this.materialButton.getBackground() instanceof RippleDrawable)) {
|
||||
((RippleDrawable) this.materialButton.getBackground()).setColor(RippleUtils.sanitizeRippleDrawableColor(colorStateList));
|
||||
} else {
|
||||
if (z || !(this.materialButton.getBackground() instanceof RippleDrawableCompat)) {
|
||||
return;
|
||||
}
|
||||
((RippleDrawableCompat) this.materialButton.getBackground()).setTintList(RippleUtils.sanitizeRippleDrawableColor(colorStateList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setStrokeColor(ColorStateList colorStateList) {
|
||||
if (this.strokeColor != colorStateList) {
|
||||
this.strokeColor = colorStateList;
|
||||
updateStroke();
|
||||
}
|
||||
}
|
||||
|
||||
void setStrokeWidth(int i) {
|
||||
if (this.strokeWidth != i) {
|
||||
this.strokeWidth = i;
|
||||
updateStroke();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStroke() {
|
||||
MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
|
||||
MaterialShapeDrawable surfaceColorStrokeDrawable = getSurfaceColorStrokeDrawable();
|
||||
if (materialShapeDrawable != null) {
|
||||
materialShapeDrawable.setStroke(this.strokeWidth, this.strokeColor);
|
||||
if (surfaceColorStrokeDrawable != null) {
|
||||
surfaceColorStrokeDrawable.setStroke(this.strokeWidth, this.shouldDrawSurfaceColorStroke ? MaterialColors.getColor(this.materialButton, R.attr.colorSurface) : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setCornerRadius(int i) {
|
||||
if (this.cornerRadiusSet && this.cornerRadius == i) {
|
||||
return;
|
||||
}
|
||||
this.cornerRadius = i;
|
||||
this.cornerRadiusSet = true;
|
||||
setShapeAppearanceModel(this.shapeAppearanceModel.withCornerSize(i));
|
||||
}
|
||||
|
||||
private MaterialShapeDrawable getMaterialShapeDrawable(boolean z) {
|
||||
LayerDrawable layerDrawable = this.rippleDrawable;
|
||||
if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (IS_MIN_LOLLIPOP) {
|
||||
return (MaterialShapeDrawable) ((LayerDrawable) ((InsetDrawable) this.rippleDrawable.getDrawable(0)).getDrawable()).getDrawable(!z ? 1 : 0);
|
||||
}
|
||||
return (MaterialShapeDrawable) this.rippleDrawable.getDrawable(!z ? 1 : 0);
|
||||
}
|
||||
|
||||
MaterialShapeDrawable getMaterialShapeDrawable() {
|
||||
return getMaterialShapeDrawable(false);
|
||||
}
|
||||
|
||||
private MaterialShapeDrawable getSurfaceColorStrokeDrawable() {
|
||||
return getMaterialShapeDrawable(true);
|
||||
}
|
||||
|
||||
private void updateButtonShape(ShapeAppearanceModel shapeAppearanceModel) {
|
||||
if (IS_LOLLIPOP && !this.backgroundOverwritten) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (getMaterialShapeDrawable() != null) {
|
||||
getMaterialShapeDrawable().setShapeAppearanceModel(shapeAppearanceModel);
|
||||
}
|
||||
if (getSurfaceColorStrokeDrawable() != null) {
|
||||
getSurfaceColorStrokeDrawable().setShapeAppearanceModel(shapeAppearanceModel);
|
||||
}
|
||||
if (getMaskDrawable() != null) {
|
||||
getMaskDrawable().setShapeAppearanceModel(shapeAppearanceModel);
|
||||
}
|
||||
}
|
||||
|
||||
public Shapeable getMaskDrawable() {
|
||||
LayerDrawable layerDrawable = this.rippleDrawable;
|
||||
if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 1) {
|
||||
return null;
|
||||
}
|
||||
if (this.rippleDrawable.getNumberOfLayers() > 2) {
|
||||
return (Shapeable) this.rippleDrawable.getDrawable(2);
|
||||
}
|
||||
return (Shapeable) this.rippleDrawable.getDrawable(1);
|
||||
}
|
||||
|
||||
void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel) {
|
||||
this.shapeAppearanceModel = shapeAppearanceModel;
|
||||
updateButtonShape(shapeAppearanceModel);
|
||||
}
|
||||
|
||||
public void setInsetBottom(int i) {
|
||||
setVerticalInsets(this.insetTop, i);
|
||||
}
|
||||
|
||||
public void setInsetTop(int i) {
|
||||
setVerticalInsets(i, this.insetBottom);
|
||||
}
|
||||
|
||||
private void setVerticalInsets(int i, int i2) {
|
||||
int paddingStart = ViewCompat.getPaddingStart(this.materialButton);
|
||||
int paddingTop = this.materialButton.getPaddingTop();
|
||||
int paddingEnd = ViewCompat.getPaddingEnd(this.materialButton);
|
||||
int paddingBottom = this.materialButton.getPaddingBottom();
|
||||
int i3 = this.insetTop;
|
||||
int i4 = this.insetBottom;
|
||||
this.insetBottom = i2;
|
||||
this.insetTop = i;
|
||||
if (!this.backgroundOverwritten) {
|
||||
updateBackground();
|
||||
}
|
||||
ViewCompat.setPaddingRelative(this.materialButton, paddingStart, (paddingTop + i) - i3, paddingEnd, (paddingBottom + i2) - i4);
|
||||
}
|
||||
}
|
@ -0,0 +1,547 @@
|
||||
package com.google.android.material.button;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.ToggleButton;
|
||||
import androidx.core.view.AccessibilityDelegateCompat;
|
||||
import androidx.core.view.MarginLayoutParamsCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import com.google.android.material.R;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.internal.ViewUtils;
|
||||
import com.google.android.material.shape.AbsoluteCornerSize;
|
||||
import com.google.android.material.shape.CornerSize;
|
||||
import com.google.android.material.shape.ShapeAppearanceModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class MaterialButtonToggleGroup extends LinearLayout {
|
||||
private static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_MaterialButtonToggleGroup;
|
||||
private static final String LOG_TAG = "MButtonToggleGroup";
|
||||
private Set<Integer> checkedIds;
|
||||
private Integer[] childOrder;
|
||||
private final Comparator<MaterialButton> childOrderComparator;
|
||||
private final int defaultCheckId;
|
||||
private final LinkedHashSet<OnButtonCheckedListener> onButtonCheckedListeners;
|
||||
private final List<CornerData> originalCornerData;
|
||||
private final PressedStateTracker pressedStateTracker;
|
||||
private boolean selectionRequired;
|
||||
private boolean singleSelection;
|
||||
private boolean skipCheckedStateTracker;
|
||||
|
||||
public interface OnButtonCheckedListener {
|
||||
void onButtonChecked(MaterialButtonToggleGroup materialButtonToggleGroup, int i, boolean z);
|
||||
}
|
||||
|
||||
public boolean isSelectionRequired() {
|
||||
return this.selectionRequired;
|
||||
}
|
||||
|
||||
public boolean isSingleSelection() {
|
||||
return this.singleSelection;
|
||||
}
|
||||
|
||||
public void setSelectionRequired(boolean z) {
|
||||
this.selectionRequired = z;
|
||||
}
|
||||
|
||||
public MaterialButtonToggleGroup(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MaterialButtonToggleGroup(Context context, AttributeSet attributeSet) {
|
||||
this(context, attributeSet, R.attr.materialButtonToggleGroupStyle);
|
||||
}
|
||||
|
||||
/* JADX WARN: Illegal instructions before constructor call */
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct add '--show-bad-code' argument
|
||||
*/
|
||||
public MaterialButtonToggleGroup(android.content.Context r7, android.util.AttributeSet r8, int r9) {
|
||||
/*
|
||||
r6 = this;
|
||||
int r4 = com.google.android.material.button.MaterialButtonToggleGroup.DEF_STYLE_RES
|
||||
android.content.Context r7 = com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap(r7, r8, r9, r4)
|
||||
r6.<init>(r7, r8, r9)
|
||||
java.util.ArrayList r7 = new java.util.ArrayList
|
||||
r7.<init>()
|
||||
r6.originalCornerData = r7
|
||||
com.google.android.material.button.MaterialButtonToggleGroup$PressedStateTracker r7 = new com.google.android.material.button.MaterialButtonToggleGroup$PressedStateTracker
|
||||
r0 = 0
|
||||
r7.<init>()
|
||||
r6.pressedStateTracker = r7
|
||||
java.util.LinkedHashSet r7 = new java.util.LinkedHashSet
|
||||
r7.<init>()
|
||||
r6.onButtonCheckedListeners = r7
|
||||
com.google.android.material.button.MaterialButtonToggleGroup$1 r7 = new com.google.android.material.button.MaterialButtonToggleGroup$1
|
||||
r7.<init>()
|
||||
r6.childOrderComparator = r7
|
||||
r7 = 0
|
||||
r6.skipCheckedStateTracker = r7
|
||||
java.util.HashSet r0 = new java.util.HashSet
|
||||
r0.<init>()
|
||||
r6.checkedIds = r0
|
||||
android.content.Context r0 = r6.getContext()
|
||||
int[] r2 = com.google.android.material.R.styleable.MaterialButtonToggleGroup
|
||||
int[] r5 = new int[r7]
|
||||
r1 = r8
|
||||
r3 = r9
|
||||
android.content.res.TypedArray r8 = com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(r0, r1, r2, r3, r4, r5)
|
||||
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_singleSelection
|
||||
boolean r9 = r8.getBoolean(r9, r7)
|
||||
r6.setSingleSelection(r9)
|
||||
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_checkedButton
|
||||
r0 = -1
|
||||
int r9 = r8.getResourceId(r9, r0)
|
||||
r6.defaultCheckId = r9
|
||||
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_selectionRequired
|
||||
boolean r7 = r8.getBoolean(r9, r7)
|
||||
r6.selectionRequired = r7
|
||||
r7 = 1
|
||||
r6.setChildrenDrawingOrderEnabled(r7)
|
||||
int r9 = com.google.android.material.R.styleable.MaterialButtonToggleGroup_android_enabled
|
||||
boolean r9 = r8.getBoolean(r9, r7)
|
||||
r6.setEnabled(r9)
|
||||
r8.recycle()
|
||||
androidx.core.view.ViewCompat.setImportantForAccessibility(r6, r7)
|
||||
return
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.button.MaterialButtonToggleGroup.<init>(android.content.Context, android.util.AttributeSet, int):void");
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
int i = this.defaultCheckId;
|
||||
if (i != -1) {
|
||||
updateCheckedIds(Collections.singleton(Integer.valueOf(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.view.ViewGroup, android.view.View
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
updateChildOrder();
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
|
||||
@Override // android.view.ViewGroup
|
||||
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
|
||||
if (!(view instanceof MaterialButton)) {
|
||||
Log.e(LOG_TAG, "Child views must be of type MaterialButton.");
|
||||
return;
|
||||
}
|
||||
super.addView(view, i, layoutParams);
|
||||
MaterialButton materialButton = (MaterialButton) view;
|
||||
setGeneratedIdIfNeeded(materialButton);
|
||||
setupButtonChild(materialButton);
|
||||
checkInternal(materialButton.getId(), materialButton.isChecked());
|
||||
ShapeAppearanceModel shapeAppearanceModel = materialButton.getShapeAppearanceModel();
|
||||
this.originalCornerData.add(new CornerData(shapeAppearanceModel.getTopLeftCornerSize(), shapeAppearanceModel.getBottomLeftCornerSize(), shapeAppearanceModel.getTopRightCornerSize(), shapeAppearanceModel.getBottomRightCornerSize()));
|
||||
materialButton.setEnabled(isEnabled());
|
||||
ViewCompat.setAccessibilityDelegate(materialButton, new AccessibilityDelegateCompat() { // from class: com.google.android.material.button.MaterialButtonToggleGroup.2
|
||||
@Override // androidx.core.view.AccessibilityDelegateCompat
|
||||
public void onInitializeAccessibilityNodeInfo(View view2, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
|
||||
super.onInitializeAccessibilityNodeInfo(view2, accessibilityNodeInfoCompat);
|
||||
accessibilityNodeInfoCompat.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(0, 1, MaterialButtonToggleGroup.this.getIndexWithinVisibleButtons(view2), 1, false, ((MaterialButton) view2).isChecked()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // android.view.ViewGroup
|
||||
public void onViewRemoved(View view) {
|
||||
super.onViewRemoved(view);
|
||||
if (view instanceof MaterialButton) {
|
||||
((MaterialButton) view).setOnPressedChangeListenerInternal(null);
|
||||
}
|
||||
int indexOfChild = indexOfChild(view);
|
||||
if (indexOfChild >= 0) {
|
||||
this.originalCornerData.remove(indexOfChild);
|
||||
}
|
||||
updateChildShapes();
|
||||
adjustChildMarginsAndUpdateLayout();
|
||||
}
|
||||
|
||||
@Override // android.widget.LinearLayout, android.view.View
|
||||
protected void onMeasure(int i, int i2) {
|
||||
updateChildShapes();
|
||||
adjustChildMarginsAndUpdateLayout();
|
||||
super.onMeasure(i, i2);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
|
||||
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
||||
AccessibilityNodeInfoCompat.wrap(accessibilityNodeInfo).setCollectionInfo(AccessibilityNodeInfoCompat.CollectionInfoCompat.obtain(1, getVisibleButtonCount(), false, isSingleSelection() ? 1 : 2));
|
||||
}
|
||||
|
||||
public void check(int i) {
|
||||
checkInternal(i, true);
|
||||
}
|
||||
|
||||
public void uncheck(int i) {
|
||||
checkInternal(i, false);
|
||||
}
|
||||
|
||||
public void clearChecked() {
|
||||
updateCheckedIds(new HashSet());
|
||||
}
|
||||
|
||||
public int getCheckedButtonId() {
|
||||
if (!this.singleSelection || this.checkedIds.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
return this.checkedIds.iterator().next().intValue();
|
||||
}
|
||||
|
||||
public List<Integer> getCheckedButtonIds() {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
int id = getChildButton(i).getId();
|
||||
if (this.checkedIds.contains(Integer.valueOf(id))) {
|
||||
arrayList.add(Integer.valueOf(id));
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public void addOnButtonCheckedListener(OnButtonCheckedListener onButtonCheckedListener) {
|
||||
this.onButtonCheckedListeners.add(onButtonCheckedListener);
|
||||
}
|
||||
|
||||
public void removeOnButtonCheckedListener(OnButtonCheckedListener onButtonCheckedListener) {
|
||||
this.onButtonCheckedListeners.remove(onButtonCheckedListener);
|
||||
}
|
||||
|
||||
public void clearOnButtonCheckedListeners() {
|
||||
this.onButtonCheckedListeners.clear();
|
||||
}
|
||||
|
||||
public void setSingleSelection(boolean z) {
|
||||
if (this.singleSelection != z) {
|
||||
this.singleSelection = z;
|
||||
clearChecked();
|
||||
}
|
||||
updateChildrenA11yClassName();
|
||||
}
|
||||
|
||||
private void updateChildrenA11yClassName() {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildButton(i).setA11yClassName((this.singleSelection ? RadioButton.class : ToggleButton.class).getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setSingleSelection(int i) {
|
||||
setSingleSelection(getResources().getBoolean(i));
|
||||
}
|
||||
|
||||
private void setCheckedStateForView(int i, boolean z) {
|
||||
View findViewById = findViewById(i);
|
||||
if (findViewById instanceof MaterialButton) {
|
||||
this.skipCheckedStateTracker = true;
|
||||
((MaterialButton) findViewById).setChecked(z);
|
||||
this.skipCheckedStateTracker = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustChildMarginsAndUpdateLayout() {
|
||||
int firstVisibleChildIndex = getFirstVisibleChildIndex();
|
||||
if (firstVisibleChildIndex == -1) {
|
||||
return;
|
||||
}
|
||||
for (int i = firstVisibleChildIndex + 1; i < getChildCount(); i++) {
|
||||
MaterialButton childButton = getChildButton(i);
|
||||
int min = Math.min(childButton.getStrokeWidth(), getChildButton(i - 1).getStrokeWidth());
|
||||
LinearLayout.LayoutParams buildLayoutParams = buildLayoutParams(childButton);
|
||||
if (getOrientation() == 0) {
|
||||
MarginLayoutParamsCompat.setMarginEnd(buildLayoutParams, 0);
|
||||
MarginLayoutParamsCompat.setMarginStart(buildLayoutParams, -min);
|
||||
buildLayoutParams.topMargin = 0;
|
||||
} else {
|
||||
buildLayoutParams.bottomMargin = 0;
|
||||
buildLayoutParams.topMargin = -min;
|
||||
MarginLayoutParamsCompat.setMarginStart(buildLayoutParams, 0);
|
||||
}
|
||||
childButton.setLayoutParams(buildLayoutParams);
|
||||
}
|
||||
resetChildMargins(firstVisibleChildIndex);
|
||||
}
|
||||
|
||||
private MaterialButton getChildButton(int i) {
|
||||
return (MaterialButton) getChildAt(i);
|
||||
}
|
||||
|
||||
private void resetChildMargins(int i) {
|
||||
if (getChildCount() == 0 || i == -1) {
|
||||
return;
|
||||
}
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getChildButton(i).getLayoutParams();
|
||||
if (getOrientation() == 1) {
|
||||
layoutParams.topMargin = 0;
|
||||
layoutParams.bottomMargin = 0;
|
||||
} else {
|
||||
MarginLayoutParamsCompat.setMarginEnd(layoutParams, 0);
|
||||
MarginLayoutParamsCompat.setMarginStart(layoutParams, 0);
|
||||
layoutParams.leftMargin = 0;
|
||||
layoutParams.rightMargin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void updateChildShapes() {
|
||||
int childCount = getChildCount();
|
||||
int firstVisibleChildIndex = getFirstVisibleChildIndex();
|
||||
int lastVisibleChildIndex = getLastVisibleChildIndex();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
MaterialButton childButton = getChildButton(i);
|
||||
if (childButton.getVisibility() != 8) {
|
||||
ShapeAppearanceModel.Builder builder = childButton.getShapeAppearanceModel().toBuilder();
|
||||
updateBuilderWithCornerData(builder, getNewCornerData(i, firstVisibleChildIndex, lastVisibleChildIndex));
|
||||
childButton.setShapeAppearanceModel(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getFirstVisibleChildIndex() {
|
||||
int childCount = getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
if (isChildVisible(i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getLastVisibleChildIndex() {
|
||||
for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) {
|
||||
if (isChildVisible(childCount)) {
|
||||
return childCount;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private boolean isChildVisible(int i) {
|
||||
return getChildAt(i).getVisibility() != 8;
|
||||
}
|
||||
|
||||
private int getVisibleButtonCount() {
|
||||
int i = 0;
|
||||
for (int i2 = 0; i2 < getChildCount(); i2++) {
|
||||
if ((getChildAt(i2) instanceof MaterialButton) && isChildVisible(i2)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int getIndexWithinVisibleButtons(View view) {
|
||||
if (!(view instanceof MaterialButton)) {
|
||||
return -1;
|
||||
}
|
||||
int i = 0;
|
||||
for (int i2 = 0; i2 < getChildCount(); i2++) {
|
||||
if (getChildAt(i2) == view) {
|
||||
return i;
|
||||
}
|
||||
if ((getChildAt(i2) instanceof MaterialButton) && isChildVisible(i2)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private CornerData getNewCornerData(int i, int i2, int i3) {
|
||||
CornerData cornerData = this.originalCornerData.get(i);
|
||||
if (i2 == i3) {
|
||||
return cornerData;
|
||||
}
|
||||
boolean z = getOrientation() == 0;
|
||||
if (i == i2) {
|
||||
return z ? CornerData.start(cornerData, this) : CornerData.top(cornerData);
|
||||
}
|
||||
if (i == i3) {
|
||||
return z ? CornerData.end(cornerData, this) : CornerData.bottom(cornerData);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void updateBuilderWithCornerData(ShapeAppearanceModel.Builder builder, CornerData cornerData) {
|
||||
if (cornerData == null) {
|
||||
builder.setAllCornerSizes(0.0f);
|
||||
} else {
|
||||
builder.setTopLeftCornerSize(cornerData.topLeft).setBottomLeftCornerSize(cornerData.bottomLeft).setTopRightCornerSize(cornerData.topRight).setBottomRightCornerSize(cornerData.bottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInternal(int i, boolean z) {
|
||||
if (i == -1) {
|
||||
Log.e(LOG_TAG, "Button ID is not valid: " + i);
|
||||
return;
|
||||
}
|
||||
HashSet hashSet = new HashSet(this.checkedIds);
|
||||
if (z && !hashSet.contains(Integer.valueOf(i))) {
|
||||
if (this.singleSelection && !hashSet.isEmpty()) {
|
||||
hashSet.clear();
|
||||
}
|
||||
hashSet.add(Integer.valueOf(i));
|
||||
} else {
|
||||
if (z || !hashSet.contains(Integer.valueOf(i))) {
|
||||
return;
|
||||
}
|
||||
if (!this.selectionRequired || hashSet.size() > 1) {
|
||||
hashSet.remove(Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
updateCheckedIds(hashSet);
|
||||
}
|
||||
|
||||
private void updateCheckedIds(Set<Integer> set) {
|
||||
Set<Integer> set2 = this.checkedIds;
|
||||
this.checkedIds = new HashSet(set);
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
int id = getChildButton(i).getId();
|
||||
setCheckedStateForView(id, set.contains(Integer.valueOf(id)));
|
||||
if (set2.contains(Integer.valueOf(id)) != set.contains(Integer.valueOf(id))) {
|
||||
dispatchOnButtonChecked(id, set.contains(Integer.valueOf(id)));
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void dispatchOnButtonChecked(int i, boolean z) {
|
||||
Iterator<OnButtonCheckedListener> it = this.onButtonCheckedListeners.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().onButtonChecked(this, i, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void setGeneratedIdIfNeeded(MaterialButton materialButton) {
|
||||
if (materialButton.getId() == -1) {
|
||||
materialButton.setId(ViewCompat.generateViewId());
|
||||
}
|
||||
}
|
||||
|
||||
private void setupButtonChild(MaterialButton materialButton) {
|
||||
materialButton.setMaxLines(1);
|
||||
materialButton.setEllipsize(TextUtils.TruncateAt.END);
|
||||
materialButton.setCheckable(true);
|
||||
materialButton.setOnPressedChangeListenerInternal(this.pressedStateTracker);
|
||||
materialButton.setShouldDrawSurfaceColorStroke(true);
|
||||
}
|
||||
|
||||
private LinearLayout.LayoutParams buildLayoutParams(View view) {
|
||||
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
|
||||
if (layoutParams instanceof LinearLayout.LayoutParams) {
|
||||
return (LinearLayout.LayoutParams) layoutParams;
|
||||
}
|
||||
return new LinearLayout.LayoutParams(layoutParams.width, layoutParams.height);
|
||||
}
|
||||
|
||||
@Override // android.view.ViewGroup
|
||||
protected int getChildDrawingOrder(int i, int i2) {
|
||||
Integer[] numArr = this.childOrder;
|
||||
if (numArr == null || i2 >= numArr.length) {
|
||||
Log.w(LOG_TAG, "Child order wasn't updated");
|
||||
return i2;
|
||||
}
|
||||
return numArr[i2].intValue();
|
||||
}
|
||||
|
||||
private void updateChildOrder() {
|
||||
TreeMap treeMap = new TreeMap(this.childOrderComparator);
|
||||
int childCount = getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
treeMap.put(getChildButton(i), Integer.valueOf(i));
|
||||
}
|
||||
this.childOrder = (Integer[]) treeMap.values().toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
void onButtonCheckedStateChanged(MaterialButton materialButton, boolean z) {
|
||||
if (this.skipCheckedStateTracker) {
|
||||
return;
|
||||
}
|
||||
checkInternal(materialButton.getId(), z);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
public void setEnabled(boolean z) {
|
||||
super.setEnabled(z);
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildButton(i).setEnabled(z);
|
||||
}
|
||||
}
|
||||
|
||||
private class PressedStateTracker implements MaterialButton.OnPressedChangeListener {
|
||||
private PressedStateTracker() {
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.button.MaterialButton.OnPressedChangeListener
|
||||
public void onPressedChanged(MaterialButton materialButton, boolean z) {
|
||||
MaterialButtonToggleGroup.this.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private static class CornerData {
|
||||
private static final CornerSize noCorner = new AbsoluteCornerSize(0.0f);
|
||||
CornerSize bottomLeft;
|
||||
CornerSize bottomRight;
|
||||
CornerSize topLeft;
|
||||
CornerSize topRight;
|
||||
|
||||
CornerData(CornerSize cornerSize, CornerSize cornerSize2, CornerSize cornerSize3, CornerSize cornerSize4) {
|
||||
this.topLeft = cornerSize;
|
||||
this.topRight = cornerSize3;
|
||||
this.bottomRight = cornerSize4;
|
||||
this.bottomLeft = cornerSize2;
|
||||
}
|
||||
|
||||
public static CornerData start(CornerData cornerData, View view) {
|
||||
return ViewUtils.isLayoutRtl(view) ? right(cornerData) : left(cornerData);
|
||||
}
|
||||
|
||||
public static CornerData end(CornerData cornerData, View view) {
|
||||
return ViewUtils.isLayoutRtl(view) ? left(cornerData) : right(cornerData);
|
||||
}
|
||||
|
||||
public static CornerData left(CornerData cornerData) {
|
||||
CornerSize cornerSize = cornerData.topLeft;
|
||||
CornerSize cornerSize2 = cornerData.bottomLeft;
|
||||
CornerSize cornerSize3 = noCorner;
|
||||
return new CornerData(cornerSize, cornerSize2, cornerSize3, cornerSize3);
|
||||
}
|
||||
|
||||
public static CornerData right(CornerData cornerData) {
|
||||
CornerSize cornerSize = noCorner;
|
||||
return new CornerData(cornerSize, cornerSize, cornerData.topRight, cornerData.bottomRight);
|
||||
}
|
||||
|
||||
public static CornerData top(CornerData cornerData) {
|
||||
CornerSize cornerSize = cornerData.topLeft;
|
||||
CornerSize cornerSize2 = noCorner;
|
||||
return new CornerData(cornerSize, cornerSize2, cornerData.topRight, cornerSize2);
|
||||
}
|
||||
|
||||
public static CornerData bottom(CornerData cornerData) {
|
||||
CornerSize cornerSize = noCorner;
|
||||
return new CornerData(cornerSize, cornerData.bottomLeft, cornerSize, cornerData.bottomRight);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user