package androidx.appcompat.widget; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.ActionMode; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.Button; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.appcompat.R; import androidx.core.view.TintableBackgroundView; import androidx.core.widget.AutoSizeableTextView; import androidx.core.widget.TextViewCompat; import androidx.core.widget.TintableCompoundDrawablesView; public class AppCompatButton extends Button implements TintableBackgroundView, AutoSizeableTextView, TintableCompoundDrawablesView { private final AppCompatBackgroundHelper mBackgroundTintHelper; private final AppCompatTextHelper mTextHelper; public AppCompatButton(@NonNull Context context) { this(context, null); } public AppCompatButton(@NonNull Context context, @Nullable AttributeSet attributeSet) { this(context, attributeSet, R.attr.buttonStyle); } public AppCompatButton(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) { super(TintContextWrapper.wrap(context), attributeSet, i); ThemeUtils.checkAppCompatTheme(this, getContext()); AppCompatBackgroundHelper appCompatBackgroundHelper = new AppCompatBackgroundHelper(this); this.mBackgroundTintHelper = appCompatBackgroundHelper; appCompatBackgroundHelper.loadFromAttributes(attributeSet, i); AppCompatTextHelper appCompatTextHelper = new AppCompatTextHelper(this); this.mTextHelper = appCompatTextHelper; appCompatTextHelper.loadFromAttributes(attributeSet, i); appCompatTextHelper.applyCompoundDrawablesTints(); } @Override // android.widget.TextView, android.view.View public void drawableStateChanged() { super.drawableStateChanged(); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.applySupportBackgroundTint(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.applyCompoundDrawablesTints(); } } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int getAutoSizeMaxTextSize() { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { return super.getAutoSizeMaxTextSize(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { return appCompatTextHelper.getAutoSizeMaxTextSize(); } return -1; } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int getAutoSizeMinTextSize() { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { return super.getAutoSizeMinTextSize(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { return appCompatTextHelper.getAutoSizeMinTextSize(); } return -1; } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int getAutoSizeStepGranularity() { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { return super.getAutoSizeStepGranularity(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { return appCompatTextHelper.getAutoSizeStepGranularity(); } return -1; } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int[] getAutoSizeTextAvailableSizes() { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { return super.getAutoSizeTextAvailableSizes(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; return appCompatTextHelper != null ? appCompatTextHelper.getAutoSizeTextAvailableSizes() : new int[0]; } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @SuppressLint({"WrongConstant"}) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int getAutoSizeTextType() { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { return super.getAutoSizeTextType() == 1 ? 1 : 0; } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { return appCompatTextHelper.getAutoSizeTextType(); } return 0; } @Override // androidx.core.view.TintableBackgroundView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public ColorStateList getSupportBackgroundTintList() { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { return appCompatBackgroundHelper.getSupportBackgroundTintList(); } return null; } @Override // androidx.core.view.TintableBackgroundView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public PorterDuff.Mode getSupportBackgroundTintMode() { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { return appCompatBackgroundHelper.getSupportBackgroundTintMode(); } return null; } @Override // androidx.core.widget.TintableCompoundDrawablesView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public ColorStateList getSupportCompoundDrawablesTintList() { return this.mTextHelper.getCompoundDrawableTintList(); } @Override // androidx.core.widget.TintableCompoundDrawablesView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public PorterDuff.Mode getSupportCompoundDrawablesTintMode() { return this.mTextHelper.getCompoundDrawableTintMode(); } @Override // android.view.View public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) { super.onInitializeAccessibilityEvent(accessibilityEvent); accessibilityEvent.setClassName(Button.class.getName()); } @Override // android.view.View public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) { super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo); accessibilityNodeInfo.setClassName(Button.class.getName()); } @Override // android.widget.TextView, android.view.View public void onLayout(boolean z2, int i, int i2, int i3, int i4) { super.onLayout(z2, i, i2, i3, i4); AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.onLayout(z2, i, i2, i3, i4); } } @Override // android.widget.TextView public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { super.onTextChanged(charSequence, i, i2, i3); AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null && !AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE && appCompatTextHelper.isAutoSizeEnabled()) { this.mTextHelper.autoSizeText(); } } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setAutoSizeTextTypeUniformWithConfiguration(int i, int i2, int i3, int i4) throws IllegalArgumentException { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { super.setAutoSizeTextTypeUniformWithConfiguration(i, i2, i3, i4); return; } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.setAutoSizeTextTypeUniformWithConfiguration(i, i2, i3, i4); } } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull int[] iArr, int i) throws IllegalArgumentException { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { super.setAutoSizeTextTypeUniformWithPresetSizes(iArr, i); return; } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.setAutoSizeTextTypeUniformWithPresetSizes(iArr, i); } } @Override // android.widget.TextView, androidx.core.widget.AutoSizeableTextView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setAutoSizeTextTypeWithDefaults(int i) { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { super.setAutoSizeTextTypeWithDefaults(i); return; } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.setAutoSizeTextTypeWithDefaults(i); } } @Override // android.view.View public void setBackgroundDrawable(Drawable drawable) { super.setBackgroundDrawable(drawable); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.onSetBackgroundDrawable(drawable); } } @Override // android.view.View public void setBackgroundResource(@DrawableRes int i) { super.setBackgroundResource(i); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.onSetBackgroundResource(i); } } @Override // android.widget.TextView public void setCustomSelectionActionModeCallback(ActionMode.Callback callback) { super.setCustomSelectionActionModeCallback(TextViewCompat.wrapCustomSelectionActionModeCallback(this, callback)); } public void setSupportAllCaps(boolean z2) { AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.setAllCaps(z2); } } @Override // androidx.core.view.TintableBackgroundView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.setSupportBackgroundTintList(colorStateList); } } @Override // androidx.core.view.TintableBackgroundView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode mode) { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.setSupportBackgroundTintMode(mode); } } @Override // androidx.core.widget.TintableCompoundDrawablesView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportCompoundDrawablesTintList(@Nullable ColorStateList colorStateList) { this.mTextHelper.setCompoundDrawableTintList(colorStateList); this.mTextHelper.applyCompoundDrawablesTints(); } @Override // androidx.core.widget.TintableCompoundDrawablesView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportCompoundDrawablesTintMode(@Nullable PorterDuff.Mode mode) { this.mTextHelper.setCompoundDrawableTintMode(mode); this.mTextHelper.applyCompoundDrawablesTints(); } @Override // android.widget.TextView public void setTextAppearance(Context context, int i) { super.setTextAppearance(context, i); AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.onSetTextAppearance(context, i); } } @Override // android.widget.TextView public void setTextSize(int i, float f) { if (AutoSizeableTextView.PLATFORM_SUPPORTS_AUTOSIZE) { super.setTextSize(i, f); return; } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.setTextSize(i, f); } } }