Source code
package android.support.v7.widget;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.view.TintableBackgroundView;
import android.support.v7.appcompat.R;
import android.support.v7.internal.widget.TintManager;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
public class AppCompatButton extends Button implements TintableBackgroundView {
private final AppCompatBackgroundHelper mBackgroundTintHelper;
private final AppCompatTextHelper mTextHelper;
private final TintManager mTintManager;
public AppCompatButton(Context context) {
this(context, null);
}
public AppCompatButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.buttonStyle);
}
public AppCompatButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.mTintManager = TintManager.get(getContext());
this.mBackgroundTintHelper = new AppCompatBackgroundHelper(this, this.mTintManager);
this.mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
this.mTextHelper = AppCompatTextHelper.create(this);
this.mTextHelper.loadFromAttributes(attrs, defStyleAttr);
this.mTextHelper.applyCompoundDrawablesTints();
}
public void setBackgroundResource(@DrawableRes int resId) {
super.setBackgroundResource(resId);
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.onSetBackgroundResource(resId);
}
}
public void setBackgroundDrawable(Drawable background) {
super.setBackgroundDrawable(background);
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.onSetBackgroundDrawable(background);
}
}
public void setSupportBackgroundTintList(@Nullable ColorStateList tint) {
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.setSupportBackgroundTintList(tint);
}
}
@Nullable
public ColorStateList getSupportBackgroundTintList() {
return this.mBackgroundTintHelper != null ? this.mBackgroundTintHelper.getSupportBackgroundTintList() : null;
}
public void setSupportBackgroundTintMode(@Nullable Mode tintMode) {
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.setSupportBackgroundTintMode(tintMode);
}
}
@Nullable
public Mode getSupportBackgroundTintMode() {
return this.mBackgroundTintHelper != null ? this.mBackgroundTintHelper.getSupportBackgroundTintMode() : null;
}
protected void drawableStateChanged() {
super.drawableStateChanged();
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.applySupportBackgroundTint();
}
if (this.mTextHelper != null) {
this.mTextHelper.applyCompoundDrawablesTints();
}
}
public void setTextAppearance(Context context, int resId) {
super.setTextAppearance(context, resId);
if (this.mTextHelper != null) {
this.mTextHelper.onSetTextAppearance(context, resId);
}
}
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(Button.class.getName());
}
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(Button.class.getName());
}
public void setSupportAllCaps(boolean allCaps) {
if (this.mTextHelper != null) {
this.mTextHelper.setAllCaps(allCaps);
}
}
}