package androidx.appcompat.widget; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.CheckBox; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.appcompat.R; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.view.TintableBackgroundView; import androidx.core.widget.TintableCompoundButton; public class AppCompatCheckBox extends CheckBox implements TintableCompoundButton, TintableBackgroundView { private final AppCompatBackgroundHelper mBackgroundTintHelper; private final AppCompatCompoundButtonHelper mCompoundButtonHelper; private final AppCompatTextHelper mTextHelper; public AppCompatCheckBox(@NonNull Context context) { this(context, null); } public AppCompatCheckBox(@NonNull Context context, @Nullable AttributeSet attributeSet) { this(context, attributeSet, R.attr.checkboxStyle); } public AppCompatCheckBox(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) { super(TintContextWrapper.wrap(context), attributeSet, i); ThemeUtils.checkAppCompatTheme(this, getContext()); AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = new AppCompatCompoundButtonHelper(this); this.mCompoundButtonHelper = appCompatCompoundButtonHelper; appCompatCompoundButtonHelper.loadFromAttributes(attributeSet, i); AppCompatBackgroundHelper appCompatBackgroundHelper = new AppCompatBackgroundHelper(this); this.mBackgroundTintHelper = appCompatBackgroundHelper; appCompatBackgroundHelper.loadFromAttributes(attributeSet, i); AppCompatTextHelper appCompatTextHelper = new AppCompatTextHelper(this); this.mTextHelper = appCompatTextHelper; appCompatTextHelper.loadFromAttributes(attributeSet, i); } @Override // android.widget.TextView, android.widget.CompoundButton, 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, android.widget.CompoundButton public int getCompoundPaddingLeft() { int compoundPaddingLeft = super.getCompoundPaddingLeft(); AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; return appCompatCompoundButtonHelper != null ? appCompatCompoundButtonHelper.getCompoundPaddingLeft(compoundPaddingLeft) : compoundPaddingLeft; } @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.TintableCompoundButton @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public ColorStateList getSupportButtonTintList() { AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; if (appCompatCompoundButtonHelper != null) { return appCompatCompoundButtonHelper.getSupportButtonTintList(); } return null; } @Override // androidx.core.widget.TintableCompoundButton @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public PorterDuff.Mode getSupportButtonTintMode() { AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; if (appCompatCompoundButtonHelper != null) { return appCompatCompoundButtonHelper.getSupportButtonTintMode(); } return null; } @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.CompoundButton public void setButtonDrawable(@DrawableRes int i) { setButtonDrawable(AppCompatResources.getDrawable(getContext(), i)); } @Override // android.widget.CompoundButton public void setButtonDrawable(Drawable drawable) { super.setButtonDrawable(drawable); AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; if (appCompatCompoundButtonHelper != null) { appCompatCompoundButtonHelper.onSetButtonDrawable(); } } @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.TintableCompoundButton @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportButtonTintList(@Nullable ColorStateList colorStateList) { AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; if (appCompatCompoundButtonHelper != null) { appCompatCompoundButtonHelper.setSupportButtonTintList(colorStateList); } } @Override // androidx.core.widget.TintableCompoundButton @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportButtonTintMode(@Nullable PorterDuff.Mode mode) { AppCompatCompoundButtonHelper appCompatCompoundButtonHelper = this.mCompoundButtonHelper; if (appCompatCompoundButtonHelper != null) { appCompatCompoundButtonHelper.setSupportButtonTintMode(mode); } } }