package skin.support.widget; import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.v7.appcompat.R; import android.support.v7.widget.AppCompatEditText; import android.util.AttributeSet; import static skin.support.widget.SkinCompatHelper.INVALID_ID; /** * Created by ximsfei on 2017/1/10. */ public class SkinCompatEditText extends AppCompatEditText implements SkinCompatSupportable { private SkinCompatTextHelper mTextHelper; private SkinCompatBackgroundHelper mBackgroundTintHelper; public SkinCompatEditText(Context context) { this(context, null); } public SkinCompatEditText(Context context, AttributeSet attrs) { this(context, attrs, R.attr.editTextStyle); } public SkinCompatEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mBackgroundTintHelper = new SkinCompatBackgroundHelper(this); mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr); mTextHelper = SkinCompatTextHelper.create(this); mTextHelper.loadFromAttributes(attrs, defStyleAttr); } @Override public void setBackgroundResource(@DrawableRes int resId) { super.setBackgroundResource(resId); if (mBackgroundTintHelper != null) { mBackgroundTintHelper.onSetBackgroundResource(resId); } } @Override public void setTextAppearance(int resId) { setTextAppearance(getContext(), resId); } @Override public void setTextAppearance(Context context, int resId) { super.setTextAppearance(context, resId); if (mTextHelper != null) { mTextHelper.onSetTextAppearance(context, resId); } } public int getTextColorResId() { return mTextHelper != null ? mTextHelper.getTextColorResId() : INVALID_ID; } @Override public void setCompoundDrawablesRelativeWithIntrinsicBounds( @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) { super.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); if (mTextHelper != null) { mTextHelper.onSetCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } } @Override public void setCompoundDrawablesWithIntrinsicBounds( @DrawableRes int left, @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom) { super.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); if (mTextHelper != null) { mTextHelper.onSetCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); } } @Override public void applySkin() { if (mBackgroundTintHelper != null) { mBackgroundTintHelper.applySkin(); } if (mTextHelper != null) { mTextHelper.applySkin(); } } }