diff --git a/api/current.txt b/api/current.txt index 4ed68397257ca..e736d78aa24ba 100644 --- a/api/current.txt +++ b/api/current.txt @@ -380,6 +380,8 @@ package android { field public static final int centerY = 16843171; // 0x10101a3 field public static final int checkBoxPreferenceStyle = 16842895; // 0x101008f field public static final int checkMark = 16843016; // 0x1010108 + field public static final int checkMarkTint = 16843949; // 0x10104ad + field public static final int checkMarkTintMode = 16843950; // 0x10104ae field public static final int checkable = 16843237; // 0x10101e5 field public static final int checkableBehavior = 16843232; // 0x10101e0 field public static final int checkboxStyle = 16842860; // 0x101006c @@ -37638,9 +37640,13 @@ package android.widget { ctor public CheckedTextView(android.content.Context, android.util.AttributeSet, int); ctor public CheckedTextView(android.content.Context, android.util.AttributeSet, int, int); method public android.graphics.drawable.Drawable getCheckMarkDrawable(); + method public android.content.res.ColorStateList getCheckMarkTint(); + method public android.graphics.PorterDuff.Mode getCheckMarkTintMode(); method public boolean isChecked(); method public void setCheckMarkDrawable(int); method public void setCheckMarkDrawable(android.graphics.drawable.Drawable); + method public void setCheckMarkTint(android.content.res.ColorStateList); + method public void setCheckMarkTintMode(android.graphics.PorterDuff.Mode); method public void setChecked(boolean); method public void toggle(); } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index e138345c37190..90eb5161cddf0 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -15546,7 +15546,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * This function is called whenever the drawable hotspot changes. + * This function is called whenever the view hotspot changes and needs to + * be propagated to drawables managed by the view. *
* Be sure to call through to the superclass when overriding this function. * @@ -15887,30 +15888,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return mBackground; } - /** - * Applies a tint to the background drawable. - *
- * Subsequent calls to {@link #setBackground(Drawable)} will automatically - * mutate the drawable and apply the specified tint and tint mode using - * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#View_backgroundTint - * @attr ref android.R.styleable#View_backgroundTintMode - * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) - */ - private void setBackgroundTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mBackgroundTint = tint; - mBackgroundTintMode = tintMode; - mHasBackgroundTint = true; - - applyBackgroundTint(); - } - /** * Applies a tint to the background drawable. Does not modify the current tint * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. @@ -15922,16 +15899,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#View_backgroundTint - * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #getBackgroundTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setBackgroundTint(@Nullable ColorStateList tint) { - setBackgroundTint(tint, mBackgroundTintMode); + mBackgroundTint = tint; + mHasBackgroundTint = true; + + applyBackgroundTint(); } /** * @return the tint applied to the background drawable * @attr ref android.R.styleable#View_backgroundTint - * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #setBackgroundTint(ColorStateList) */ @Nullable public ColorStateList getBackgroundTint() { @@ -15946,16 +15927,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#View_backgroundTintMode - * @see #setBackgroundTint(ColorStateList) + * @see #getBackgroundTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) { - setBackgroundTint(mBackgroundTint, tintMode); + mBackgroundTintMode = tintMode; + + applyBackgroundTint(); } /** * @return the blending mode used to apply the tint to the background drawable * @attr ref android.R.styleable#View_backgroundTintMode - * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #setBackgroundTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getBackgroundTintMode() { diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index 7e2d809b9aaa2..be7e0bc429095 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -92,10 +92,11 @@ public abstract class AbsSeekBar extends ProgressBar { final Drawable thumb = a.getDrawable(com.android.internal.R.styleable.SeekBar_thumb); setThumb(thumb); + mThumbTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.SeekBar_thumbTintMode, -1), mThumbTintMode); + if (a.hasValue(R.styleable.SeekBar_thumbTint)) { mThumbTint = a.getColorStateList(R.styleable.SeekBar_thumbTint); - mThumbTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.SeekBar_thumbTintMode, -1), mThumbTintMode); mHasThumbTint = true; applyThumbTint(); @@ -182,30 +183,6 @@ public abstract class AbsSeekBar extends ProgressBar { return mThumb; } - /** - * Applies a tint to the thumb drawable. - *
- * Subsequent calls to {@link #setThumb(Drawable)} will automatically - * mutate the drawable and apply the specified tint and tint mode using - * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#SeekBar_thumbTint - * @attr ref android.R.styleable#SeekBar_thumbTintMode - * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) - */ - private void setThumbTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mThumbTint = tint; - mThumbTintMode = tintMode; - mHasThumbTint = true; - - applyThumbTint(); - } - /** * Applies a tint to the thumb drawable. Does not modify the current tint * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. @@ -217,16 +194,20 @@ public abstract class AbsSeekBar extends ProgressBar { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#SeekBar_thumbTint - * @see #setThumbTint(ColorStateList, PorterDuff.Mode) + * @see #getThumbTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setThumbTint(@Nullable ColorStateList tint) { - setThumbTint(tint, mThumbTintMode); + mThumbTint = tint; + mHasThumbTint = true; + + applyThumbTint(); } /** * @return the tint applied to the thumb drawable * @attr ref android.R.styleable#SeekBar_thumbTint - * @see #setThumbTint(ColorStateList, PorterDuff.Mode) + * @see #setThumbTint(ColorStateList) */ @Nullable public ColorStateList getThumbTint() { @@ -240,17 +221,21 @@ public abstract class AbsSeekBar extends ProgressBar { * * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint + * * @attr ref android.R.styleable#SeekBar_thumbTintMode - * @see #setThumbTint(ColorStateList) + * @see #getThumbTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) { - setThumbTint(mThumbTint, tintMode); + mThumbTintMode = tintMode; + + applyThumbTint(); } /** * @return the blending mode used to apply the tint to the thumb drawable * @attr ref android.R.styleable#SeekBar_thumbTintMode - * @see #setThumbTint(ColorStateList, PorterDuff.Mode) + * @see #setThumbTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getThumbTintMode() { diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java index 4aa2300c652ce..791151cd6419e 100644 --- a/core/java/android/widget/CheckedTextView.java +++ b/core/java/android/widget/CheckedTextView.java @@ -18,9 +18,12 @@ package android.widget; import com.android.internal.R; +import android.annotation.Nullable; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Canvas; +import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; @@ -41,8 +44,13 @@ import android.view.accessibility.AccessibilityNodeInfo; */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; + private int mCheckMarkResource; private Drawable mCheckMarkDrawable; + private ColorStateList mCheckMarkTint = null; + private PorterDuff.Mode mCheckMarkTintMode = PorterDuff.Mode.SRC_ATOP; + private boolean mHasCheckMarkTint = false; + private int mBasePadding; private int mCheckMarkWidth; private boolean mNeedRequestlayout; @@ -74,6 +82,16 @@ public class CheckedTextView extends TextView implements Checkable { setCheckMarkDrawable(d); } + mCheckMarkTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.CompoundButton_buttonTintMode, -1), mCheckMarkTintMode); + + if (a.hasValue(R.styleable.CompoundButton_buttonTint)) { + mCheckMarkTint = a.getColorStateList(R.styleable.CompoundButton_buttonTint); + mHasCheckMarkTint = true; + + applyCheckMarkTint(); + } + boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); @@ -153,6 +171,7 @@ public class CheckedTextView extends TextView implements Checkable { mCheckMarkWidth = d.getIntrinsicWidth(); d.setState(getDrawableState()); + applyCheckMarkTint(); } else { mCheckMarkWidth = 0; } @@ -163,6 +182,72 @@ public class CheckedTextView extends TextView implements Checkable { resolvePadding(); } + /** + * Applies a tint to the check mark drawable. Does not modify the + * current tint mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. + *
+ * Subsequent calls to {@link #setCheckMarkDrawable(Drawable)} will + * automatically mutate the drawable and apply the specified tint and + * tint mode using + * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}. + * + * @param tint the tint to apply, may be {@code null} to clear tint + * + * @attr ref android.R.styleable#CheckedTextView_checkMarkTint + * @see #getCheckMarkTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) + */ + public void setCheckMarkTint(@Nullable ColorStateList tint) { + mCheckMarkTint = tint; + mHasCheckMarkTint = true; + + applyCheckMarkTint(); + } + + /** + * @return the tint applied to the check mark drawable + * @attr ref android.R.styleable#CheckedTextView_checkMarkTint + * @see #setCheckMarkTint(ColorStateList) + */ + @Nullable + public ColorStateList getCheckMarkTint() { + return mCheckMarkTint; + } + + /** + * Specifies the blending mode used to apply the tint specified by + * {@link #setCheckMarkTint(ColorStateList)} to the check mark + * drawable. The default mode is {@link PorterDuff.Mode#SRC_ATOP}. + * + * @param tintMode the blending mode used to apply the tint, may be + * {@code null} to clear tint + * @attr ref android.R.styleable#CheckedTextView_checkMarkTintMode + * @see #setCheckMarkTint(ColorStateList) + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) + */ + public void setCheckMarkTintMode(@Nullable PorterDuff.Mode tintMode) { + mCheckMarkTintMode = tintMode; + + applyCheckMarkTint(); + } + + /** + * @return the blending mode used to apply the tint to the check mark drawable + * @attr ref android.R.styleable#CheckedTextView_checkMarkTintMode + * @see #setCheckMarkTintMode(PorterDuff.Mode) + */ + @Nullable + public PorterDuff.Mode getCheckMarkTintMode() { + return mCheckMarkTintMode; + } + + private void applyCheckMarkTint() { + if (mCheckMarkDrawable != null && mHasCheckMarkTint) { + mCheckMarkDrawable = mCheckMarkDrawable.mutate(); + mCheckMarkDrawable.setTint(mCheckMarkTint, mCheckMarkTintMode); + } + } + @RemotableViewMethod @Override public void setVisibility(int visibility) { diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java index 9ba0fe1a55ba4..a45777eba8cba 100644 --- a/core/java/android/widget/CompoundButton.java +++ b/core/java/android/widget/CompoundButton.java @@ -87,10 +87,11 @@ public abstract class CompoundButton extends Button implements Checkable { setButtonDrawable(d); } + mButtonTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.CompoundButton_buttonTintMode, -1), mButtonTintMode); + if (a.hasValue(R.styleable.CompoundButton_buttonTint)) { mButtonTint = a.getColorStateList(R.styleable.CompoundButton_buttonTint); - mButtonTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.CompoundButton_buttonTintMode, -1), mButtonTintMode); mHasButtonTint = true; applyButtonTint(); @@ -237,31 +238,6 @@ public abstract class CompoundButton extends Button implements Checkable { } } - /** - * Applies a tint to the button drawable. - *
- * Subsequent calls to {@link #setButtonDrawable(Drawable)} will - * automatically mutate the drawable and apply the specified tint and tint - * mode using - * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#CompoundButton_buttonTint - * @attr ref android.R.styleable#CompoundButton_buttonTintMode - * @see Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode) - */ - private void setButtonTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mButtonTint = tint; - mButtonTintMode = tintMode; - mHasButtonTint = true; - - applyButtonTint(); - } - /** * Applies a tint to the button drawable. Does not modify the current tint * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. @@ -269,21 +245,25 @@ public abstract class CompoundButton extends Button implements Checkable { * Subsequent calls to {@link #setButtonDrawable(Drawable)} will * automatically mutate the drawable and apply the specified tint and tint * mode using - * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}. + * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}. * * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#CompoundButton_buttonTint - * @see #setButtonTint(ColorStateList, android.graphics.PorterDuff.Mode) + * @see #setButtonTint(ColorStateList) + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setButtonTint(@Nullable ColorStateList tint) { - setButtonTint(tint, mButtonTintMode); + mButtonTint = tint; + mHasButtonTint = true; + + applyButtonTint(); } /** * @return the tint applied to the button drawable * @attr ref android.R.styleable#CompoundButton_buttonTint - * @see #setButtonTint(ColorStateList, PorterDuff.Mode) + * @see #setButtonTint(ColorStateList) */ @Nullable public ColorStateList getButtonTint() { @@ -298,16 +278,19 @@ public abstract class CompoundButton extends Button implements Checkable { * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#CompoundButton_buttonTintMode - * @see #setButtonTint(ColorStateList) + * @see #getButtonTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setButtonTintMode(@Nullable PorterDuff.Mode tintMode) { - setButtonTint(mButtonTint, tintMode); + mButtonTintMode = tintMode; + + applyButtonTint(); } /** * @return the blending mode used to apply the tint to the button drawable * @attr ref android.R.styleable#CompoundButton_buttonTintMode - * @see #setButtonTint(ColorStateList, PorterDuff.Mode) + * @see #setButtonTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getButtonTintMode() { diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java index 34f333ee35280..81dfcbb3766c3 100644 --- a/core/java/android/widget/FrameLayout.java +++ b/core/java/android/widget/FrameLayout.java @@ -127,10 +127,11 @@ public class FrameLayout extends ViewGroup { setMeasureAllChildren(true); } + mForegroundTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.FrameLayout_foregroundTintMode, -1), mForegroundTintMode); + if (a.hasValue(R.styleable.FrameLayout_foregroundTint)) { mForegroundTint = a.getColorStateList(R.styleable.FrameLayout_foregroundTint); - mForegroundTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.FrameLayout_foregroundTintMode, -1), mForegroundTintMode); mHasForegroundTint = true; applyForegroundTint(); @@ -316,11 +317,6 @@ public class FrameLayout extends ViewGroup { */ private void setForegroundTint(@Nullable ColorStateList tint, @Nullable PorterDuff.Mode tintMode) { - mForegroundTint = tint; - mForegroundTintMode = tintMode; - mHasForegroundTint = true; - - applyForegroundTint(); } /** @@ -334,16 +330,20 @@ public class FrameLayout extends ViewGroup { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#FrameLayout_foregroundTint - * @see #setForegroundTint(ColorStateList, PorterDuff.Mode) + * @see #getForegroundTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setForegroundTint(@Nullable ColorStateList tint) { - setForegroundTint(tint, mForegroundTintMode); + mForegroundTint = tint; + mHasForegroundTint = true; + + applyForegroundTint(); } /** * @return the tint applied to the foreground drawable * @attr ref android.R.styleable#FrameLayout_foregroundTint - * @see #setForegroundTint(ColorStateList, PorterDuff.Mode) + * @see #setForegroundTint(ColorStateList) */ @Nullable public ColorStateList getForegroundTint() { @@ -358,17 +358,20 @@ public class FrameLayout extends ViewGroup { * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#FrameLayout_foregroundTintMode - * @see #setForegroundTint(ColorStateList) + * @see #getForegroundTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setForegroundTintMode(@Nullable PorterDuff.Mode tintMode) { - setForegroundTint(mForegroundTint, tintMode); + mForegroundTintMode = tintMode; + + applyForegroundTint(); } /** * @return the blending mode used to apply the tint to the foreground * drawable * @attr ref android.R.styleable#FrameLayout_foregroundTintMode - * @see #setForegroundTint(ColorStateList, PorterDuff.Mode) + * @see #setForegroundTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getForegroundTintMode() { diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index e97177d310ae2..0881f3eac19ee 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -168,10 +168,11 @@ public class ImageView extends View { setScaleType(sScaleTypeArray[index]); } + mDrawableTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.ImageView_tintMode, -1), mDrawableTintMode); + if (a.hasValue(R.styleable.ImageView_tint)) { mDrawableTint = a.getColorStateList(R.styleable.ImageView_tint); - mDrawableTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.ImageView_tintMode, -1), mDrawableTintMode); mHasDrawableTint = true; applyDrawableTint(); @@ -447,30 +448,6 @@ public class ImageView extends View { } } - /** - * Applies a tint to the image drawable. - *
- * Subsequent calls to {@link #setImageDrawable(Drawable)} will automatically - * mutate the drawable and apply the specified tint and tint mode using - * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#ImageView_tint - * @attr ref android.R.styleable#ImageView_tintMode - * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) - */ - private void setTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mDrawableTint = tint; - mDrawableTintMode = tintMode; - mHasDrawableTint = true; - - applyDrawableTint(); - } - /** * Applies a tint to the image drawable. Does not modify the current tint * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. @@ -482,16 +459,20 @@ public class ImageView extends View { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#ImageView_tint + * @see #getTint() * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setTint(@Nullable ColorStateList tint) { - setTint(tint, mDrawableTintMode); + mDrawableTint = tint; + mHasDrawableTint = true; + + applyDrawableTint(); } /** * @return the tint applied to the image drawable * @attr ref android.R.styleable#ImageView_tint - * @see #setTint(ColorStateList, PorterDuff.Mode) + * @see #setTint(ColorStateList) */ @Nullable public ColorStateList getTint() { @@ -506,16 +487,19 @@ public class ImageView extends View { * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#ImageView_tintMode - * @see #setTint(ColorStateList) + * @see #getTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setTintMode(@Nullable PorterDuff.Mode tintMode) { - setTint(mDrawableTint, tintMode); + mDrawableTintMode = tintMode; + + applyDrawableTint(); } /** * @return the blending mode used to apply the tint to the image drawable * @attr ref android.R.styleable#ImageView_tintMode - * @see #setTint(ColorStateList, PorterDuff.Mode) + * @see #setTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getTintMode() { diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 394b255618ce1..20c1aa4f1481d 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -326,48 +326,48 @@ public class ProgressBar extends View { mMirrorForRtl = a.getBoolean(R.styleable.ProgressBar_mirrorForRtl, mMirrorForRtl); + mProgressTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.ProgressBar_progressBackgroundTintMode, -1), mProgressTintMode); + if (a.hasValue(R.styleable.ProgressBar_progressTint)) { mProgressTint = a.getColorStateList( R.styleable.ProgressBar_progressTint); - mProgressTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.ProgressBar_progressBackgroundTintMode, -1), - mProgressTintMode); mHasProgressTint = true; applyProgressLayerTint(R.id.progress, mProgressTint, mProgressTintMode, true); } + mProgressBackgroundTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.ProgressBar_progressTintMode, -1), mProgressBackgroundTintMode); + if (a.hasValue(R.styleable.ProgressBar_progressBackgroundTint)) { mProgressBackgroundTint = a.getColorStateList( R.styleable.ProgressBar_progressBackgroundTint); - mProgressBackgroundTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.ProgressBar_progressTintMode, -1), - mProgressBackgroundTintMode); mHasProgressBackgroundTint = true; applyProgressLayerTint(R.id.background, mProgressBackgroundTint, mProgressBackgroundTintMode, false); } + mSecondaryProgressTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.ProgressBar_secondaryProgressTintMode, -1), mSecondaryProgressTintMode); + if (a.hasValue(R.styleable.ProgressBar_secondaryProgressTint)) { mSecondaryProgressTint = a.getColorStateList( R.styleable.ProgressBar_secondaryProgressTint); - mSecondaryProgressTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.ProgressBar_secondaryProgressTintMode, -1), - mSecondaryProgressTintMode); mHasSecondaryProgressTint = true; applyProgressLayerTint(R.id.secondaryProgress, mSecondaryProgressTint, mSecondaryProgressTintMode, false); } + mIndeterminateTintMode = Drawable.parseTintMode(a.getInt( + R.styleable.ProgressBar_indeterminateTintMode, -1), mIndeterminateTintMode); + if (a.hasValue(R.styleable.ProgressBar_indeterminateTint)) { mIndeterminateTint = a.getColorStateList( R.styleable.ProgressBar_indeterminateTint); - mIndeterminateTintMode = Drawable.parseTintMode(a.getInt( - R.styleable.ProgressBar_indeterminateTintMode, -1), - mIndeterminateTintMode); mHasIndeterminateTint = true; applyIndeterminateTint(); @@ -573,31 +573,6 @@ public class ProgressBar extends View { } } - /** - * Applies a tint to the indeterminate drawable. - *
- * Subsequent calls to {@link #setVisibilminateDrawable(Drawable)} will - * automatically mutate the drawable and apply the specified tint and - * tint mode using - * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#ProgressBar_indeterminateTint - * @attr ref android.R.styleable#ProgressBar_indeterminateTintMode - * @see Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode) - */ - private void setIndeterminateTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mIndeterminateTint = tint; - mIndeterminateTintMode = tintMode; - mHasIndeterminateTint = true; - - applyIndeterminateTint(); - } - /** * Applies a tint to the indeterminate drawable. Does not modify the * current tint mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default. @@ -610,16 +585,20 @@ public class ProgressBar extends View { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#ProgressBar_indeterminateTint - * @see #setIndeterminateTint(ColorStateList, PorterDuff.Mode) + * @see #getIndeterminateTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setIndeterminateTint(@Nullable ColorStateList tint) { - setIndeterminateTint(tint, mIndeterminateTintMode); + mIndeterminateTint = tint; + mHasIndeterminateTint = true; + + applyIndeterminateTint(); } /** * @return the tint applied to the indeterminate drawable * @attr ref android.R.styleable#ProgressBar_indeterminateTint - * @see #setIndeterminateTint(ColorStateList, PorterDuff.Mode) + * @see #setIndeterminateTint(ColorStateList) */ @Nullable public ColorStateList getIndeterminateTint() { @@ -635,15 +614,18 @@ public class ProgressBar extends View { * {@code null} to clear tint * @attr ref android.R.styleable#ProgressBar_indeterminateTintMode * @see #setIndeterminateTint(ColorStateList) + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setIndeterminateTintMode(@Nullable PorterDuff.Mode tintMode) { - setIndeterminateTint(mIndeterminateTint, tintMode); + mIndeterminateTintMode = tintMode; + + applyIndeterminateTint(); } /** * @return the blending mode used to apply the tint to the indeterminate drawable * @attr ref android.R.styleable#ProgressBar_indeterminateTintMode - * @see #setIndeterminateTint(ColorStateList, PorterDuff.Mode) + * @see #setIndeterminateTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getIndeterminateTintMode() { @@ -747,36 +729,6 @@ public class ProgressBar extends View { } } - /** - * Applies a tint to the progress indicator, if one exists, or to the - * entire progress drawable otherwise. - *
- * The progress indicator should be specified as a layer with - * id {@link android.R.id#progress} in a {@link LayerDrawable} - * used as the progress drawable. - *
- * Subsequent calls to {@link #setProgressDrawable(Drawable)} will - * automatically mutate the drawable and apply the specified tint and - * tint mode using - * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#ProgressBar_progressTint - * @attr ref android.R.styleable#ProgressBar_progressTintMode - * @see Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode) - */ - private void setProgressTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mProgressTint = tint; - mProgressTintMode = tintMode; - mHasProgressTint = true; - - applyProgressLayerTint(R.id.progress, tint, tintMode, true); - } - /** * Applies a tint to the progress indicator, if one exists, or to the * entire progress drawable otherwise. Does not modify the current tint @@ -794,16 +746,20 @@ public class ProgressBar extends View { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#ProgressBar_progressTint - * @see #setProgressTint(ColorStateList) + * @see #getProgressTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setProgressTint(@Nullable ColorStateList tint) { - setProgressTint(tint, mProgressTintMode); + mProgressTint = tint; + mHasProgressTint = true; + + applyProgressLayerTint(R.id.progress, tint, mProgressTintMode, true); } /** * @return the tint applied to the progress drawable * @attr ref android.R.styleable#ProgressBar_progressTint - * @see #setProgressTint(ColorStateList, PorterDuff.Mode) + * @see #setProgressTint(ColorStateList) */ @Nullable public ColorStateList getProgressTint() { @@ -818,51 +774,25 @@ public class ProgressBar extends View { * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#ProgressBar_progressTintMode - * @see #setProgressTint(ColorStateList) + * @see #getProgressTintMode() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setProgressTintMode(@Nullable PorterDuff.Mode tintMode) { - setProgressTint(mProgressTint, tintMode); + mProgressTintMode = tintMode; + + applyProgressLayerTint(R.id.progress, mProgressTint, tintMode, true); } /** * @return the blending mode used to apply the tint to the progress drawable * @attr ref android.R.styleable#ProgressBar_progressTintMode - * @see #setProgressTint(ColorStateList, PorterDuff.Mode) + * @see #setProgressTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getProgressTintMode() { return mProgressTintMode; } - /** - * Applies a tint to the progress background, if one exists. - *
- * The progress background must be specified as a layer with - * id {@link android.R.id#background} in a {@link LayerDrawable} - * used as the progress drawable. - *
- * Subsequent calls to {@link #setProgressDrawable(Drawable)} where the - * drawable contains a progress background will automatically mutate the - * drawable and apply the specified tint and tint mode using - * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}. - * - * @param tint the tint to apply, may be {@code null} to clear tint - * @param tintMode the blending mode used to apply the tint, may be - * {@code null} to clear tint - * - * @attr ref android.R.styleable#ProgressBar_progressBackgroundTint - * @attr ref android.R.styleable#ProgressBar_progressBackgroundTintMode - * @see Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode) - */ - private void setProgressBackgroundTint(@Nullable ColorStateList tint, - @Nullable PorterDuff.Mode tintMode) { - mProgressBackgroundTint = tint; - mProgressBackgroundTintMode = tintMode; - mHasProgressBackgroundTint = true; - - applyProgressLayerTint(R.id.background, tint, tintMode, false); - } - /** * Applies a tint to the progress background, if one exists. Does not * modify the current tint mode, which is @@ -880,16 +810,20 @@ public class ProgressBar extends View { * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#ProgressBar_progressBackgroundTint - * @see #setProgressBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #getProgressBackgroundTint() + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setProgressBackgroundTint(@Nullable ColorStateList tint) { - setProgressBackgroundTint(tint, mProgressBackgroundTintMode); + mProgressBackgroundTint = tint; + mHasProgressBackgroundTint = true; + + applyProgressLayerTint(R.id.background, tint, mProgressBackgroundTintMode, false); } /** * @return the tint applied to the progress background * @attr ref android.R.styleable#ProgressBar_progressBackgroundTint - * @see #setProgressBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #setProgressBackgroundTint(ColorStateList) */ @Nullable public ColorStateList getProgressBackgroundTint() { @@ -905,51 +839,25 @@ public class ProgressBar extends View { * {@code null} to clear tint * @attr ref android.R.styleable#ProgressBar_progressBackgroundTintMode * @see #setProgressBackgroundTint(ColorStateList) + * @see Drawable#setTint(ColorStateList, PorterDuff.Mode) */ public void setProgressBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) { - setProgressBackgroundTint(mProgressBackgroundTint, tintMode); + mProgressBackgroundTintMode = tintMode; + + applyProgressLayerTint(R.id.background, mProgressBackgroundTint, tintMode, false); } /** * @return the blending mode used to apply the tint to the progress * background * @attr ref android.R.styleable#ProgressBar_progressBackgroundTintMode - * @see #setProgressBackgroundTint(ColorStateList, PorterDuff.Mode) + * @see #setProgressBackgroundTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getProgressBackgroundTintMode() { return mProgressBackgroundTintMode; } - /** - * Applies a tint to the secondary progress indicator, if one exists. - *
- * The secondary progress indicator must be specified as a layer with - * id {@link android.R.id#secondaryProgress} in a {@link LayerDrawable} - * used as the progress drawable. - *
- * Subsequent calls to {@link #setProgressDrawable(Drawable)} where the
- * drawable contains a secondary progress indicator will automatically
- * mutate the drawable and apply the specified tint and tint mode using
- * {@link Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)}.
- *
- * @param tint the tint to apply, may be {@code null} to clear tint
- * @param tintMode the blending mode used to apply the tint, may be
- * {@code null} to clear tint
- *
- * @attr ref android.R.styleable#ProgressBar_secondaryProgressTint
- * @attr ref android.R.styleable#ProgressBar_secondaryProgressTintMode
- * @see Drawable#setTint(ColorStateList, android.graphics.PorterDuff.Mode)
- */
- private void setSecondaryProgressTint(@Nullable ColorStateList tint,
- @Nullable PorterDuff.Mode tintMode) {
- mSecondaryProgressTint = tint;
- mSecondaryProgressTintMode = tintMode;
- mHasSecondaryProgressTint = true;
-
- applyProgressLayerTint(R.id.secondaryProgress, tint, tintMode, false);
- }
-
/**
* Applies a tint to the secondary progress indicator, if one exists.
* Does not modify the current tint mode, which is
@@ -967,16 +875,20 @@ public class ProgressBar extends View {
* @param tint the tint to apply, may be {@code null} to clear tint
*
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTint
- * @see #setSecondaryProgressTint(ColorStateList, PorterDuff.Mode)
+ * @see #getSecondaryProgressTint()
+ * @see Drawable#setTint(ColorStateList, PorterDuff.Mode)
*/
public void setSecondaryProgressTint(@Nullable ColorStateList tint) {
- setSecondaryProgressTint(tint, mSecondaryProgressTintMode);
+ mSecondaryProgressTint = tint;
+ mHasSecondaryProgressTint = true;
+
+ applyProgressLayerTint(R.id.secondaryProgress, tint, mSecondaryProgressTintMode, false);
}
/**
* @return the tint applied to the secondary progress drawable
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTint
- * @see #setSecondaryProgressTint(ColorStateList, PorterDuff.Mode)
+ * @see #setSecondaryProgressTint(ColorStateList)
*/
@Nullable
public ColorStateList getSecondaryProgressTint() {
@@ -993,16 +905,19 @@ public class ProgressBar extends View {
* {@code null} to clear tint
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTintMode
* @see #setSecondaryProgressTint(ColorStateList)
+ * @see Drawable#setTint(ColorStateList, PorterDuff.Mode)
*/
public void setSecondaryProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
- setSecondaryProgressTint(mSecondaryProgressTint, tintMode);
+ mSecondaryProgressTintMode = tintMode;
+
+ applyProgressLayerTint(R.id.secondaryProgress, mSecondaryProgressTint, tintMode, false);
}
/**
* @return the blending mode used to apply the tint to the secondary
* progress drawable
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTintMode
- * @see #setSecondaryProgressTint(ColorStateList, PorterDuff.Mode)
+ * @see #setSecondaryProgressTintMode(PorterDuff.Mode)
*/
@Nullable
public PorterDuff.Mode getSecondaryProgressTintMode() {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 2c5cfe1fc0559..f69ab0fac2bb1 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3114,6 +3114,28 @@