diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBackgroundHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBackgroundHelper.java index b47c21f..c397b73 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBackgroundHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBackgroundHelper.java @@ -35,7 +35,7 @@ * @author xyczero617@gmail.com * @time 15/9/26 */ -public class AppCompatBackgroundHelper extends AppCompatBaseHelper { +public class AppCompatBackgroundHelper extends AppCompatBaseHelper { private TintInfo mBackgroundTintInfo; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBaseHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBaseHelper.java index 761dfee..a3188e0 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBaseHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatBaseHelper.java @@ -25,13 +25,13 @@ * @author xyczero617@gmail.com * @time 15/10/1 */ -public abstract class AppCompatBaseHelper { - protected View mView; +public abstract class AppCompatBaseHelper { + protected T mView; protected TintManager mTintManager; private boolean mSkipNextApply; - public AppCompatBaseHelper(View view, TintManager tintManager) { + public AppCompatBaseHelper(T view, TintManager tintManager) { mView = view; mTintManager = tintManager; } diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundButtonHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundButtonHelper.java index 48b3362..ef96b98 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundButtonHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundButtonHelper.java @@ -35,7 +35,7 @@ * @author xyczero617@gmail.com * @time 15/11/23 */ -public class AppCompatCompoundButtonHelper extends AppCompatBaseHelper { +public class AppCompatCompoundButtonHelper extends AppCompatBaseHelper { private TintInfo mCompoundButtonTintInfo; private int mCompoundButtonResId; @@ -106,7 +106,7 @@ public void setButtonDrawableTintList(int resId, PorterDuff.Mode mode) { private void setButtonDrawable(Drawable drawable) { if (skipNextApply()) return; - ((CompoundButton) mView).setButtonDrawable(drawable); + mView.setButtonDrawable(drawable); } public boolean setSupportButtonDrawableTint(int resId) { @@ -131,7 +131,7 @@ private void setSupportButtonDrawableTintMode(PorterDuff.Mode mode) { } public boolean applySupportButtonDrawableTint() { - Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView); + Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView); if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) { buttonDrawable = DrawableCompat.wrap(buttonDrawable); buttonDrawable = buttonDrawable.mutate(); @@ -165,7 +165,7 @@ public int getCompoundPaddingLeft(int superValue) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { // Before JB-MR1 the button drawable wasn't taken into account for padding. We'll // workaround that here - Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView); + Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView); if (buttonDrawable != null) { superValue += buttonDrawable.getIntrinsicWidth(); } diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundDrawableHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundDrawableHelper.java index 7e3018a..87ad38e 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundDrawableHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatCompoundDrawableHelper.java @@ -27,7 +27,6 @@ import com.bilibili.magicasakura.R; import com.bilibili.magicasakura.utils.DrawableUtils; -import com.bilibili.magicasakura.utils.ThemeUtils; import com.bilibili.magicasakura.utils.TintInfo; import com.bilibili.magicasakura.utils.TintManager; @@ -35,7 +34,7 @@ * @author xyczero617@gmail.com * @time 15/9/26 */ -public class AppCompatCompoundDrawableHelper extends AppCompatBaseHelper { +public class AppCompatCompoundDrawableHelper extends AppCompatBaseHelper { private TintInfo[] mCompoundDrawableTintInfos = new TintInfo[4]; @@ -123,7 +122,7 @@ public void setCompoundDrawablesTintList(int... resIds) { private void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) { if (skipNextApply()) return; - ((TextView) mView).setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); + mView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom); } private Drawable getCompoundDrawableByPosition(int i) { @@ -164,7 +163,7 @@ private void setSupportCompoundDrawableTintModeByPosition(int position, PorterDu } private Drawable applySupportCompoundDrawableTint(int position) { - Drawable originDrawable = ((TextView) mView).getCompoundDrawables()[position]; + Drawable originDrawable = mView.getCompoundDrawables()[position]; Drawable compoundDrawable = originDrawable; TintInfo tintInfo = mCompoundDrawableTintInfos[position]; if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) { diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatForegroundHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatForegroundHelper.java index d1130b1..34d468b 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatForegroundHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatForegroundHelper.java @@ -35,7 +35,7 @@ * @author xyczero617@gmail.com * @time 16/4/7 */ -public class AppCompatForegroundHelper extends AppCompatBaseHelper { +public class AppCompatForegroundHelper extends AppCompatBaseHelper { private TintInfo mForegroundTintInfo; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatImageHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatImageHelper.java index 8ebf4f6..5002e48 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatImageHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatImageHelper.java @@ -22,7 +22,6 @@ import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.util.AttributeSet; -import android.view.View; import android.widget.ImageView; import com.bilibili.magicasakura.R; @@ -34,13 +33,13 @@ * @author xyczero617@gmail.com * @time 15/11/15 */ -public class AppCompatImageHelper extends AppCompatBaseHelper { +public class AppCompatImageHelper extends AppCompatBaseHelper { private TintInfo mImageTintInfo; private int mImageResId; private int mImageTintResId; - public AppCompatImageHelper(View view, TintManager tintManager) { + public AppCompatImageHelper(ImageView view, TintManager tintManager) { super(view, tintManager); } @@ -49,7 +48,7 @@ public AppCompatImageHelper(View view, TintManager tintManager) { void loadFromAttribute(AttributeSet attrs, int defStyleAttr) { TypedArray array = mView.getContext().obtainStyledAttributes(attrs, R.styleable.TintImageHelper, defStyleAttr, 0); // first resolve srcCompat due to not extending by AppCompatImageView - if (((ImageView) mView).getDrawable() == null) { + if (mView.getDrawable() == null) { Drawable image = mTintManager.getDrawable(mImageResId = array.getResourceId(R.styleable.TintImageHelper_srcCompat, 0)); if (image != null) { setImageDrawable(image); @@ -109,7 +108,7 @@ public void setImageTintList(int resId, PorterDuff.Mode mode) { private void setImageDrawable(Drawable drawable) { if (skipNextApply()) return; - ((ImageView) mView).setImageDrawable(drawable); + mView.setImageDrawable(drawable); } private boolean setSupportImageTint(int resId) { @@ -134,7 +133,7 @@ private void setSupportImageTintMode(PorterDuff.Mode mode) { } private boolean applySupportImageTint() { - Drawable image = ((ImageView) mView).getDrawable(); + Drawable image = mView.getDrawable(); if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) { Drawable tintDrawable = image.mutate(); tintDrawable = DrawableCompat.wrap(tintDrawable); diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatProgressBarHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatProgressBarHelper.java index 00c1d73..e6e86a4 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatProgressBarHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatProgressBarHelper.java @@ -34,7 +34,7 @@ * @author xyczero617@gmail.com * @time 16/2/4 */ -public class AppCompatProgressBarHelper extends AppCompatBaseHelper { +public class AppCompatProgressBarHelper extends AppCompatBaseHelper { private int mProgressTintResId; private int mIndeterminateTintResId; @@ -42,7 +42,7 @@ public class AppCompatProgressBarHelper extends AppCompatBaseHelper { private TintInfo mProgressTintInfo; private TintInfo mIndeterminateTintInfo; - public AppCompatProgressBarHelper(View view, TintManager tintManager) { + public AppCompatProgressBarHelper(TintProgressBar view, TintManager tintManager) { super(view, tintManager); } @@ -99,11 +99,11 @@ private void applySupportProgressTint() { } private void applySupportIndeterminateTint() { - Drawable mIndeterminateDrawable = ((ProgressBar) mView).getIndeterminateDrawable(); + Drawable mIndeterminateDrawable = mView.getIndeterminateDrawable(); if (mIndeterminateDrawable != null && mIndeterminateTintInfo != null) { final TintInfo tintInfo = mIndeterminateTintInfo; if (tintInfo.mHasTintList || tintInfo.mHasTintMode) { - ((ProgressBar) mView).setIndeterminateDrawable(mIndeterminateDrawable = mIndeterminateDrawable.mutate()); + mView.setIndeterminateDrawable(mIndeterminateDrawable = mIndeterminateDrawable.mutate()); TintManager.tintViewDrawable(mView, mIndeterminateDrawable, mIndeterminateTintInfo); // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. @@ -118,9 +118,9 @@ private void applySupportIndeterminateTint() { private Drawable getTintTarget(int layerId, boolean shouldFallback) { Drawable layer = null; - final Drawable d = ((ProgressBar) mView).getProgressDrawable(); + final Drawable d = mView.getProgressDrawable(); if (d != null) { - ((ProgressBar) mView).setProgressDrawable(d.mutate()); + mView.setProgressDrawable(d.mutate()); if (d instanceof LayerDrawable) { layer = ((LayerDrawable) d).findDrawableByLayerId(layerId); diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatTextHelper.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatTextHelper.java index cd43e43..70f55ec 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatTextHelper.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/AppCompatTextHelper.java @@ -31,7 +31,7 @@ * @author xyczero617@gmail.com * @time 15/9/26 */ -public class AppCompatTextHelper extends AppCompatBaseHelper { +public class AppCompatTextHelper extends AppCompatBaseHelper { //If writing like this: //int[] ATTRS = { R.attr.tintText, android.R.attr.textColor, android.R.attr.textColorLink, ...}; @@ -43,7 +43,7 @@ public class AppCompatTextHelper extends AppCompatBaseHelper { private TintInfo mTextColorTintInfo; private TintInfo mTextLinkColorTintInfo; - public AppCompatTextHelper(View view, TintManager tintManager) { + public AppCompatTextHelper(TextView view, TintManager tintManager) { super(view, tintManager); } @@ -111,7 +111,7 @@ public void setTextColorById(@ColorRes int colorId) { private void setTextColor(ColorStateList tint) { if (skipNextApply()) return; - ((TextView) mView).setTextColor(tint); + mView.setTextColor(tint); } private void setTextColor(@ColorRes int resId) { @@ -164,7 +164,7 @@ private void applySupportTextColorTint() { private void applySupportTextLinkColorTint() { if (mTextLinkColorTintInfo != null && mTextLinkColorTintInfo.mHasTintList) { - ((TextView) mView).setLinkTextColor(mTextLinkColorTintInfo.mTintList); + mView.setLinkTextColor(mTextLinkColorTintInfo.mTintList); } } diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintAutoCompleteTextView.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintAutoCompleteTextView.java index 63c7755..f2e9feb 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintAutoCompleteTextView.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintAutoCompleteTextView.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -28,6 +29,7 @@ * @author xyczero617@gmail.com * @time 16/2/14 */ +@SuppressLint("AppCompatCustomView") public class TintAutoCompleteTextView extends AutoCompleteTextView implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatCompoundDrawableHelper.CompoundDrawableExtensible { private AppCompatBackgroundHelper mBackgroundHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintButton.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintButton.java index 57e3894..a5f7e75 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintButton.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintButton.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; @@ -32,6 +33,8 @@ * @author xyczero617@gmail.com * @time 15/10/25 */ + +@SuppressLint("AppCompatCustomView") public class TintButton extends Button implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatTextHelper.TextExtensible { private AppCompatTextHelper mTextHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckBox.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckBox.java index 48d76d5..406c0e6 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckBox.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckBox.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; @@ -37,6 +38,7 @@ * @author xyczero617@gmail.com * @time 16/1/27 */ +@SuppressLint("AppCompatCustomView") public class TintCheckBox extends CheckBox implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatCompoundButtonHelper.CompoundButtonExtensible, AppCompatTextHelper.TextExtensible { private AppCompatBackgroundHelper mBackgroundHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckedTextView.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckedTextView.java index b3c3ab2..25d4ad0 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckedTextView.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintCheckedTextView.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.graphics.PorterDuff; @@ -36,6 +37,7 @@ * special view for replacing view in preference , not recommend to use it in common * layout: select_dialog_singlechoice_xxx */ +@SuppressLint("AppCompatCustomView") public class TintCheckedTextView extends CheckedTextView implements Tintable { private static final int[] ATTRS = { android.R.attr.drawableLeft, diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintEditText.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintEditText.java index 51c05fe..5c4baca 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintEditText.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintEditText.java @@ -17,6 +17,7 @@ package com.bilibili.magicasakura.widgets; import android.annotation.TargetApi; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; @@ -35,6 +36,7 @@ * @author xyczero617@gmail.com * @time 16/2/1 */ +@SuppressLint("AppCompatCustomView") public class TintEditText extends EditText implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatCompoundDrawableHelper.CompoundDrawableExtensible, AppCompatTextHelper.TextExtensible { private AppCompatBackgroundHelper mBackgroundHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintImageView.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintImageView.java index 33986d7..f581de1 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintImageView.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintImageView.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -28,6 +29,7 @@ * @author xyczero617@gmail.com * @time 15/11/8 */ +@SuppressLint("AppCompatCustomView") public class TintImageView extends ImageView implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatImageHelper.ImageExtensible { private AppCompatBackgroundHelper mBackgroundHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintRadioButton.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintRadioButton.java index 889b7ae..c80816f 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintRadioButton.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintRadioButton.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; @@ -37,6 +38,7 @@ * @author xyczero617@gmail.com * @time 16/1/19 */ +@SuppressLint("AppCompatCustomView") public class TintRadioButton extends RadioButton implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible , AppCompatCompoundButtonHelper.CompoundButtonExtensible, AppCompatTextHelper.TextExtensible { private AppCompatTextHelper mTextHelper; diff --git a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintTextView.java b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintTextView.java index b32b73f..9a7c824 100644 --- a/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintTextView.java +++ b/magicasakura/src/main/java/com/bilibili/magicasakura/widgets/TintTextView.java @@ -16,6 +16,7 @@ package com.bilibili.magicasakura.widgets; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; @@ -35,6 +36,7 @@ * @author xyczero617@gmail.com * @time 15/9/14 */ +@SuppressLint("AppCompatCustomView") public class TintTextView extends TextView implements Tintable, AppCompatBackgroundHelper.BackgroundExtensible, AppCompatCompoundDrawableHelper.CompoundDrawableExtensible, AppCompatTextHelper.TextExtensible { private AppCompatTextHelper mTextHelper;