Merge "Clean up view drawable tinting methods, fix default modes" into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
670288c252
@@ -3187,9 +3187,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
|
||||
@ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_")
|
||||
private Drawable mBackground;
|
||||
private ColorStateList mBackgroundTintList = null;
|
||||
private PorterDuff.Mode mBackgroundTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private boolean mHasBackgroundTint = false;
|
||||
private TintInfo mBackgroundTint;
|
||||
|
||||
/**
|
||||
* RenderNode used for backgrounds.
|
||||
@@ -3205,6 +3203,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
|
||||
private String mTransitionName;
|
||||
|
||||
private static class TintInfo {
|
||||
ColorStateList mTintList;
|
||||
PorterDuff.Mode mTintMode;
|
||||
boolean mHasTintMode;
|
||||
boolean mHasTintList;
|
||||
}
|
||||
|
||||
static class ListenerInfo {
|
||||
/**
|
||||
* Listener used to dispatch focus change events.
|
||||
@@ -4044,13 +4049,21 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
break;
|
||||
case R.styleable.View_backgroundTint:
|
||||
// This will get applied later during setBackground().
|
||||
mBackgroundTintList = a.getColorStateList(R.styleable.View_backgroundTint);
|
||||
mHasBackgroundTint = true;
|
||||
if (mBackgroundTint == null) {
|
||||
mBackgroundTint = new TintInfo();
|
||||
}
|
||||
mBackgroundTint.mTintList = a.getColorStateList(
|
||||
R.styleable.View_backgroundTint);
|
||||
mBackgroundTint.mHasTintList = true;
|
||||
break;
|
||||
case R.styleable.View_backgroundTintMode:
|
||||
// This will get applied later during setBackground().
|
||||
mBackgroundTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.View_backgroundTintMode, -1), mBackgroundTintMode);
|
||||
if (mBackgroundTint == null) {
|
||||
mBackgroundTint = new TintInfo();
|
||||
}
|
||||
mBackgroundTint.mTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.View_backgroundTintMode, -1), null);
|
||||
mBackgroundTint.mHasTintMode = true;
|
||||
break;
|
||||
case R.styleable.View_outlineProvider:
|
||||
setOutlineProviderFromAttribute(a.getInt(R.styleable.View_outlineProvider,
|
||||
@@ -16210,7 +16223,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
|
||||
/**
|
||||
* Applies a tint to the background drawable. Does not modify the current tint
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setBackground(Drawable)} will automatically
|
||||
* mutate the drawable and apply the specified tint and tint mode using
|
||||
@@ -16223,26 +16236,31 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setBackgroundTintList(@Nullable ColorStateList tint) {
|
||||
mBackgroundTintList = tint;
|
||||
mHasBackgroundTint = true;
|
||||
if (mBackgroundTint == null) {
|
||||
mBackgroundTint = new TintInfo();
|
||||
}
|
||||
mBackgroundTint.mTintList = tint;
|
||||
mBackgroundTint.mHasTintList = true;
|
||||
|
||||
applyBackgroundTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the tint applied to the background drawable, if specified.
|
||||
*
|
||||
* @return the tint applied to the background drawable
|
||||
* @attr ref android.R.styleable#View_backgroundTint
|
||||
* @see #setBackgroundTintList(ColorStateList)
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getBackgroundTintList() {
|
||||
return mBackgroundTintList;
|
||||
return mBackgroundTint != null ? mBackgroundTint.mTintList : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setBackgroundTintList(ColorStateList)}} to the background drawable.
|
||||
* The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* {@link #setBackgroundTintList(ColorStateList)}} to the background
|
||||
* drawable. The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -16251,26 +16269,43 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @see Drawable#setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mBackgroundTintMode = tintMode;
|
||||
if (mBackgroundTint == null) {
|
||||
mBackgroundTint = new TintInfo();
|
||||
}
|
||||
mBackgroundTint.mTintMode = tintMode;
|
||||
mBackgroundTint.mHasTintMode = true;
|
||||
|
||||
applyBackgroundTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blending mode used to apply the tint to the background drawable
|
||||
* Return the blending mode used to apply the tint to the background
|
||||
* drawable, if specified.
|
||||
*
|
||||
* @return the blending mode used to apply the tint to the background
|
||||
* drawable
|
||||
* @attr ref android.R.styleable#View_backgroundTintMode
|
||||
* @see #setBackgroundTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getBackgroundTintMode() {
|
||||
return mBackgroundTintMode;
|
||||
return mBackgroundTint != null ? mBackgroundTint.mTintMode : null;
|
||||
}
|
||||
|
||||
private void applyBackgroundTint() {
|
||||
if (mBackground != null && mHasBackgroundTint) {
|
||||
mBackground = mBackground.mutate();
|
||||
mBackground.setTintList(mBackgroundTintList);
|
||||
mBackground.setTintMode(mBackgroundTintMode);
|
||||
if (mBackground != null && mBackgroundTint != null) {
|
||||
final TintInfo tintInfo = mBackgroundTint;
|
||||
if (tintInfo.mHasTintList || tintInfo.mHasTintMode) {
|
||||
mBackground = mBackground.mutate();
|
||||
|
||||
if (tintInfo.mHasTintList) {
|
||||
mBackground.setTintList(tintInfo.mTintList);
|
||||
}
|
||||
|
||||
if (tintInfo.mHasTintMode) {
|
||||
mBackground.setTintMode(tintInfo.mTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,9 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
|
||||
private Drawable mThumb;
|
||||
private ColorStateList mThumbTintList = null;
|
||||
private PorterDuff.Mode mThumbTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private PorterDuff.Mode mThumbTintMode = null;
|
||||
private boolean mHasThumbTint = false;
|
||||
private boolean mHasThumbTintMode = false;
|
||||
|
||||
private int mThumbOffset;
|
||||
private boolean mSplitTrack;
|
||||
@@ -96,14 +97,15 @@ 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_thumbTintMode)) {
|
||||
mThumbTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.SeekBar_thumbTintMode, -1), mThumbTintMode);
|
||||
mHasThumbTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.SeekBar_thumbTint)) {
|
||||
mThumbTintList = a.getColorStateList(R.styleable.SeekBar_thumbTint);
|
||||
mHasThumbTint = true;
|
||||
|
||||
applyThumbTint();
|
||||
}
|
||||
|
||||
// Guess thumb offset if thumb != null, but allow layout to override.
|
||||
@@ -119,6 +121,8 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.Theme_disabledAlpha, 0.5f);
|
||||
a.recycle();
|
||||
|
||||
applyThumbTint();
|
||||
|
||||
mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
}
|
||||
|
||||
@@ -189,7 +193,7 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
|
||||
/**
|
||||
* Applies a tint to the thumb drawable. Does not modify the current tint
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setThumb(Drawable)} will automatically
|
||||
* mutate the drawable and apply the specified tint and tint mode using
|
||||
@@ -209,6 +213,8 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tint applied to the thumb drawable, if specified.
|
||||
*
|
||||
* @return the tint applied to the thumb drawable
|
||||
* @attr ref android.R.styleable#SeekBar_thumbTint
|
||||
* @see #setThumbTintList(ColorStateList)
|
||||
@@ -221,7 +227,7 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setThumbTintList(ColorStateList)}} to the thumb drawable. The
|
||||
* default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -232,11 +238,15 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
*/
|
||||
public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mThumbTintMode = tintMode;
|
||||
mHasThumbTintMode = true;
|
||||
|
||||
applyThumbTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blending mode used to apply the tint to the thumb drawable,
|
||||
* if specified.
|
||||
*
|
||||
* @return the blending mode used to apply the tint to the thumb drawable
|
||||
* @attr ref android.R.styleable#SeekBar_thumbTintMode
|
||||
* @see #setThumbTintMode(PorterDuff.Mode)
|
||||
@@ -247,10 +257,16 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
}
|
||||
|
||||
private void applyThumbTint() {
|
||||
if (mThumb != null && mHasThumbTint) {
|
||||
if (mThumb != null && (mHasThumbTint || mHasThumbTintMode)) {
|
||||
mThumb = mThumb.mutate();
|
||||
mThumb.setTintList(mThumbTintList);
|
||||
mThumb.setTintMode(mThumbTintMode);
|
||||
|
||||
if (mHasThumbTint) {
|
||||
mThumb.setTintList(mThumbTintList);
|
||||
}
|
||||
|
||||
if (mHasThumbTintMode) {
|
||||
mThumb.setTintMode(mThumbTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,9 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
private int mCheckMarkResource;
|
||||
private Drawable mCheckMarkDrawable;
|
||||
private ColorStateList mCheckMarkTintList = null;
|
||||
private PorterDuff.Mode mCheckMarkTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private PorterDuff.Mode mCheckMarkTintMode = null;
|
||||
private boolean mHasCheckMarkTint = false;
|
||||
private boolean mHasCheckMarkTintMode = false;
|
||||
|
||||
private int mBasePadding;
|
||||
private int mCheckMarkWidth;
|
||||
@@ -79,27 +80,30 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
final TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.CheckedTextView, defStyleAttr, defStyleRes);
|
||||
|
||||
Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMark);
|
||||
final Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMark);
|
||||
if (d != null) {
|
||||
setCheckMarkDrawable(d);
|
||||
}
|
||||
|
||||
mCheckMarkTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.CheckedTextView_checkMarkTintMode, -1), mCheckMarkTintMode);
|
||||
if (a.hasValue(R.styleable.CheckedTextView_checkMarkTintMode)) {
|
||||
mCheckMarkTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.CheckedTextView_checkMarkTintMode, -1), mCheckMarkTintMode);
|
||||
mHasCheckMarkTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.CheckedTextView_checkMarkTint)) {
|
||||
mCheckMarkTintList = a.getColorStateList(R.styleable.CheckedTextView_checkMarkTint);
|
||||
mHasCheckMarkTint = true;
|
||||
|
||||
applyCheckMarkTint();
|
||||
}
|
||||
|
||||
mCheckMarkGravity = a.getInt(R.styleable.CheckedTextView_checkMarkGravity, Gravity.END);
|
||||
|
||||
boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false);
|
||||
final boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false);
|
||||
setChecked(checked);
|
||||
|
||||
a.recycle();
|
||||
|
||||
applyCheckMarkTint();
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
@@ -188,7 +192,7 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
|
||||
/**
|
||||
* Applies a tint to the check mark drawable. Does not modify the
|
||||
* current tint mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* current tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setCheckMarkDrawable(Drawable)} will
|
||||
* automatically mutate the drawable and apply the specified tint and
|
||||
@@ -209,6 +213,8 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tint applied to the check mark drawable, if specified.
|
||||
*
|
||||
* @return the tint applied to the check mark drawable
|
||||
* @attr ref android.R.styleable#CheckedTextView_checkMarkTint
|
||||
* @see #setCheckMarkTintList(ColorStateList)
|
||||
@@ -221,7 +227,7 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setCheckMarkTintList(ColorStateList)} to the check mark
|
||||
* drawable. The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* drawable. The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -231,12 +237,17 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
*/
|
||||
public void setCheckMarkTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mCheckMarkTintMode = tintMode;
|
||||
mHasCheckMarkTintMode = true;
|
||||
|
||||
applyCheckMarkTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blending mode used to apply the tint to the check mark drawable
|
||||
* Returns the blending mode used to apply the tint to the check mark
|
||||
* drawable, if specified.
|
||||
*
|
||||
* @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)
|
||||
*/
|
||||
@@ -246,10 +257,16 @@ public class CheckedTextView extends TextView implements Checkable {
|
||||
}
|
||||
|
||||
private void applyCheckMarkTint() {
|
||||
if (mCheckMarkDrawable != null && mHasCheckMarkTint) {
|
||||
if (mCheckMarkDrawable != null && (mHasCheckMarkTint || mHasCheckMarkTintMode)) {
|
||||
mCheckMarkDrawable = mCheckMarkDrawable.mutate();
|
||||
mCheckMarkDrawable.setTintList(mCheckMarkTintList);
|
||||
mCheckMarkDrawable.setTintMode(mCheckMarkTintMode);
|
||||
|
||||
if (mHasCheckMarkTint) {
|
||||
mCheckMarkDrawable.setTintList(mCheckMarkTintList);
|
||||
}
|
||||
|
||||
if (mHasCheckMarkTintMode) {
|
||||
mCheckMarkDrawable.setTintMode(mCheckMarkTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,9 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
|
||||
private Drawable mButtonDrawable;
|
||||
private ColorStateList mButtonTintList = null;
|
||||
private PorterDuff.Mode mButtonTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private PorterDuff.Mode mButtonTintMode = null;
|
||||
private boolean mHasButtonTint = false;
|
||||
private boolean mHasButtonTintMode = false;
|
||||
|
||||
private OnCheckedChangeListener mOnCheckedChangeListener;
|
||||
private OnCheckedChangeListener mOnCheckedChangeWidgetListener;
|
||||
@@ -87,14 +88,15 @@ 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_buttonTintMode)) {
|
||||
mButtonTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.CompoundButton_buttonTintMode, -1), mButtonTintMode);
|
||||
mHasButtonTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
|
||||
mButtonTintList = a.getColorStateList(R.styleable.CompoundButton_buttonTint);
|
||||
mHasButtonTint = true;
|
||||
|
||||
applyButtonTint();
|
||||
}
|
||||
|
||||
final boolean checked = a.getBoolean(
|
||||
@@ -102,6 +104,8 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
setChecked(checked);
|
||||
|
||||
a.recycle();
|
||||
|
||||
applyButtonTint();
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
@@ -240,7 +244,7 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
|
||||
/**
|
||||
* Applies a tint to the button drawable. Does not modify the current tint
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setButtonDrawable(Drawable)} will
|
||||
* automatically mutate the drawable and apply the specified tint and tint
|
||||
@@ -273,7 +277,7 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setButtonTintList(ColorStateList)}} to the button drawable. The
|
||||
* default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -283,6 +287,7 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
*/
|
||||
public void setButtonTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mButtonTintMode = tintMode;
|
||||
mHasButtonTintMode = true;
|
||||
|
||||
applyButtonTint();
|
||||
}
|
||||
@@ -298,10 +303,16 @@ public abstract class CompoundButton extends Button implements Checkable {
|
||||
}
|
||||
|
||||
private void applyButtonTint() {
|
||||
if (mButtonDrawable != null && mHasButtonTint) {
|
||||
if (mButtonDrawable != null && (mHasButtonTint || mHasButtonTintMode)) {
|
||||
mButtonDrawable = mButtonDrawable.mutate();
|
||||
mButtonDrawable.setTintList(mButtonTintList);
|
||||
mButtonDrawable.setTintMode(mButtonTintMode);
|
||||
|
||||
if (mHasButtonTint) {
|
||||
mButtonDrawable.setTintList(mButtonTintList);
|
||||
}
|
||||
|
||||
if (mHasButtonTintMode) {
|
||||
mButtonDrawable.setTintMode(mButtonTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,9 @@ public class FrameLayout extends ViewGroup {
|
||||
@ViewDebug.ExportedProperty(category = "drawing")
|
||||
private Drawable mForeground;
|
||||
private ColorStateList mForegroundTintList = null;
|
||||
private PorterDuff.Mode mForegroundTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private PorterDuff.Mode mForegroundTintMode = null;
|
||||
private boolean mHasForegroundTint = false;
|
||||
private boolean mHasForegroundTintMode = false;
|
||||
|
||||
@ViewDebug.ExportedProperty(category = "padding")
|
||||
private int mForegroundPaddingLeft = 0;
|
||||
@@ -127,20 +128,22 @@ public class FrameLayout extends ViewGroup {
|
||||
setMeasureAllChildren(true);
|
||||
}
|
||||
|
||||
mForegroundTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.FrameLayout_foregroundTintMode, -1), mForegroundTintMode);
|
||||
if (a.hasValue(R.styleable.FrameLayout_foregroundTintMode)) {
|
||||
mForegroundTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.FrameLayout_foregroundTintMode, -1), mForegroundTintMode);
|
||||
mHasForegroundTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.FrameLayout_foregroundTint)) {
|
||||
mForegroundTintList = a.getColorStateList(R.styleable.FrameLayout_foregroundTint);
|
||||
mHasForegroundTint = true;
|
||||
|
||||
applyForegroundTint();
|
||||
}
|
||||
|
||||
mForegroundInPadding = a.getBoolean(
|
||||
com.android.internal.R.styleable.FrameLayout_foregroundInsidePadding, true);
|
||||
mForegroundInPadding = a.getBoolean(R.styleable.FrameLayout_foregroundInsidePadding, true);
|
||||
|
||||
a.recycle();
|
||||
|
||||
applyForegroundTint();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +305,7 @@ public class FrameLayout extends ViewGroup {
|
||||
|
||||
/**
|
||||
* Applies a tint to the foreground drawable. Does not modify the current
|
||||
* tint mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setForeground(Drawable)} will automatically
|
||||
* mutate the drawable and apply the specified tint and tint mode using
|
||||
@@ -334,7 +337,7 @@ public class FrameLayout extends ViewGroup {
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setForegroundTintList(ColorStateList)}} to the foreground drawable.
|
||||
* The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -344,6 +347,7 @@ public class FrameLayout extends ViewGroup {
|
||||
*/
|
||||
public void setForegroundTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mForegroundTintMode = tintMode;
|
||||
mHasForegroundTintMode = true;
|
||||
|
||||
applyForegroundTint();
|
||||
}
|
||||
@@ -360,10 +364,16 @@ public class FrameLayout extends ViewGroup {
|
||||
}
|
||||
|
||||
private void applyForegroundTint() {
|
||||
if (mForeground != null && mHasForegroundTint) {
|
||||
if (mForeground != null && (mHasForegroundTint || mHasForegroundTintMode)) {
|
||||
mForeground = mForeground.mutate();
|
||||
mForeground.setTintList(mForegroundTintList);
|
||||
mForeground.setTintMode(mForegroundTintMode);
|
||||
|
||||
if (mHasForegroundTint) {
|
||||
mForeground.setTintList(mForegroundTintList);
|
||||
}
|
||||
|
||||
if (mHasForegroundTintMode) {
|
||||
mForeground.setTintMode(mForegroundTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,9 +87,10 @@ public class ImageView extends View {
|
||||
private boolean mColorMod = false;
|
||||
|
||||
private Drawable mDrawable = null;
|
||||
private ColorStateList mDrawableTint = null;
|
||||
private PorterDuff.Mode mDrawableTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private ColorStateList mDrawableTintList = null;
|
||||
private PorterDuff.Mode mDrawableTintMode = null;
|
||||
private boolean mHasDrawableTint = false;
|
||||
private boolean mHasDrawableTintMode = false;
|
||||
|
||||
private int[] mState = null;
|
||||
private boolean mMergeState = false;
|
||||
@@ -168,16 +169,25 @@ 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);
|
||||
mDrawableTintList = a.getColorStateList(R.styleable.ImageView_tint);
|
||||
mHasDrawableTint = true;
|
||||
|
||||
applyImageTint();
|
||||
// Prior to L, the tint mode was always SRC_ATOP.
|
||||
if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.L) {
|
||||
mDrawableTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
mHasDrawableTintMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.ImageView_tintMode)) {
|
||||
mDrawableTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ImageView_tintMode, -1), mDrawableTintMode);
|
||||
mHasDrawableTintMode = true;
|
||||
}
|
||||
|
||||
applyImageTint();
|
||||
|
||||
final int alpha = a.getInt(com.android.internal.R.styleable.ImageView_drawableAlpha, 255);
|
||||
if (alpha != 255) {
|
||||
setAlpha(alpha);
|
||||
@@ -450,7 +460,7 @@ public class ImageView extends View {
|
||||
|
||||
/**
|
||||
* Applies a tint to the image drawable. Does not modify the current tint
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setImageDrawable(Drawable)} will automatically
|
||||
* mutate the drawable and apply the specified tint and tint mode using
|
||||
@@ -463,7 +473,7 @@ public class ImageView extends View {
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setImageTintList(@Nullable ColorStateList tint) {
|
||||
mDrawableTint = tint;
|
||||
mDrawableTintList = tint;
|
||||
mHasDrawableTint = true;
|
||||
|
||||
applyImageTint();
|
||||
@@ -476,13 +486,13 @@ public class ImageView extends View {
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getImageTintList() {
|
||||
return mDrawableTint;
|
||||
return mDrawableTintList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setImageTintList(ColorStateList)}} to the image drawable. The default
|
||||
* mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -492,6 +502,7 @@ public class ImageView extends View {
|
||||
*/
|
||||
public void setImageTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mDrawableTintMode = tintMode;
|
||||
mHasDrawableTintMode = true;
|
||||
|
||||
applyImageTint();
|
||||
}
|
||||
@@ -507,10 +518,16 @@ public class ImageView extends View {
|
||||
}
|
||||
|
||||
private void applyImageTint() {
|
||||
if (mDrawable != null && mHasDrawableTint) {
|
||||
if (mDrawable != null && (mHasDrawableTint || mHasDrawableTintMode)) {
|
||||
mDrawable = mDrawable.mutate();
|
||||
mDrawable.setTintList(mDrawableTint);
|
||||
mDrawable.setTintMode(mDrawableTintMode);
|
||||
|
||||
if (mHasDrawableTint) {
|
||||
mDrawable.setTintList(mDrawableTintList);
|
||||
}
|
||||
|
||||
if (mHasDrawableTintMode) {
|
||||
mDrawable.setTintMode(mDrawableTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -216,25 +216,10 @@ public class ProgressBar extends View {
|
||||
private boolean mHasAnimation;
|
||||
|
||||
private Drawable mIndeterminateDrawable;
|
||||
private ColorStateList mIndeterminateTintList = null;
|
||||
private PorterDuff.Mode mIndeterminateTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private boolean mHasIndeterminateTint = false;
|
||||
|
||||
private Drawable mProgressDrawable;
|
||||
|
||||
private ColorStateList mProgressTintList = null;
|
||||
private PorterDuff.Mode mProgressTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private boolean mHasProgressTint = false;
|
||||
|
||||
private ColorStateList mProgressBackgroundTintList = null;
|
||||
private PorterDuff.Mode mProgressBackgroundTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private boolean mHasProgressBackgroundTint = false;
|
||||
|
||||
private ColorStateList mSecondaryProgressTintList = null;
|
||||
private PorterDuff.Mode mSecondaryProgressTintMode = PorterDuff.Mode.SRC_ATOP;
|
||||
private boolean mHasSecondaryProgressTint = false;
|
||||
|
||||
private Drawable mCurrentDrawable;
|
||||
private ProgressTintInfo mProgressTintInfo;
|
||||
|
||||
Bitmap mSampleTile;
|
||||
private boolean mNoInvalidate;
|
||||
private Interpolator mInterpolator;
|
||||
@@ -328,55 +313,83 @@ 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_progressTintMode)) {
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_progressBackgroundTintMode, -1), null);
|
||||
mProgressTintInfo.mHasProgressTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.ProgressBar_progressTint)) {
|
||||
mProgressTintList = a.getColorStateList(
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressTintList = a.getColorStateList(
|
||||
R.styleable.ProgressBar_progressTint);
|
||||
mHasProgressTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.progress, mProgressTintList,
|
||||
mProgressTintMode, true);
|
||||
mProgressTintInfo.mHasProgressTint = true;
|
||||
}
|
||||
|
||||
mProgressBackgroundTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_progressTintMode, -1), mProgressBackgroundTintMode);
|
||||
if (a.hasValue(R.styleable.ProgressBar_progressBackgroundTintMode)) {
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressBackgroundTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_progressTintMode, -1), null);
|
||||
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.ProgressBar_progressBackgroundTint)) {
|
||||
mProgressBackgroundTintList = a.getColorStateList(
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressBackgroundTintList = a.getColorStateList(
|
||||
R.styleable.ProgressBar_progressBackgroundTint);
|
||||
mHasProgressBackgroundTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.background, mProgressBackgroundTintList,
|
||||
mProgressBackgroundTintMode, false);
|
||||
mProgressTintInfo.mHasProgressBackgroundTint = true;
|
||||
}
|
||||
|
||||
mSecondaryProgressTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_secondaryProgressTintMode, -1), mSecondaryProgressTintMode);
|
||||
if (a.hasValue(R.styleable.ProgressBar_secondaryProgressTintMode)) {
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mSecondaryProgressTintMode = Drawable.parseTintMode(
|
||||
a.getInt(R.styleable.ProgressBar_secondaryProgressTintMode, -1), null);
|
||||
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.ProgressBar_secondaryProgressTint)) {
|
||||
mSecondaryProgressTintList = a.getColorStateList(
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mSecondaryProgressTintList = a.getColorStateList(
|
||||
R.styleable.ProgressBar_secondaryProgressTint);
|
||||
mHasSecondaryProgressTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.secondaryProgress, mSecondaryProgressTintList,
|
||||
mSecondaryProgressTintMode, false);
|
||||
mProgressTintInfo.mHasSecondaryProgressTint = true;
|
||||
}
|
||||
|
||||
mIndeterminateTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_indeterminateTintMode, -1), mIndeterminateTintMode);
|
||||
if (a.hasValue(R.styleable.ProgressBar_indeterminateTint)) {
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mIndeterminateTintMode = Drawable.parseTintMode(a.getInt(
|
||||
R.styleable.ProgressBar_indeterminateTintMode, -1), null);
|
||||
mProgressTintInfo.mHasIndeterminateTintMode = true;
|
||||
}
|
||||
|
||||
if (a.hasValue(R.styleable.ProgressBar_indeterminateTint)) {
|
||||
mIndeterminateTintList = a.getColorStateList(
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mIndeterminateTintList = a.getColorStateList(
|
||||
R.styleable.ProgressBar_indeterminateTint);
|
||||
mHasIndeterminateTint = true;
|
||||
|
||||
applyIndeterminateTint();
|
||||
mProgressTintInfo.mHasIndeterminateTint = true;
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
|
||||
applyProgressTints();
|
||||
applyIndeterminateTint();
|
||||
|
||||
// If not explicitly specified this view is important for accessibility.
|
||||
if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
|
||||
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
|
||||
@@ -578,7 +591,7 @@ public class ProgressBar extends View {
|
||||
|
||||
/**
|
||||
* Applies a tint to the indeterminate drawable. Does not modify the
|
||||
* current tint mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* current tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* Subsequent calls to {@link #setIndeterminateDrawable(Drawable)} will
|
||||
* automatically mutate the drawable and apply the specified tint and
|
||||
@@ -592,8 +605,11 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setIndeterminateTintList(@Nullable ColorStateList tint) {
|
||||
mIndeterminateTintList = tint;
|
||||
mHasIndeterminateTint = true;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mIndeterminateTintList = tint;
|
||||
mProgressTintInfo.mHasIndeterminateTint = true;
|
||||
|
||||
applyIndeterminateTint();
|
||||
}
|
||||
@@ -605,13 +621,13 @@ public class ProgressBar extends View {
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getIndeterminateTintList() {
|
||||
return mIndeterminateTintList;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateTintList : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setIndeterminateTintList(ColorStateList)} to the indeterminate
|
||||
* drawable. The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* drawable. The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -620,26 +636,43 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setIndeterminateTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mIndeterminateTintMode = tintMode;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mIndeterminateTintMode = tintMode;
|
||||
mProgressTintInfo.mHasIndeterminateTintMode = true;
|
||||
|
||||
applyIndeterminateTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blending mode used to apply the tint to the indeterminate drawable
|
||||
* Returns the blending mode used to apply the tint to the indeterminate
|
||||
* drawable, if specified.
|
||||
*
|
||||
* @return the blending mode used to apply the tint to the indeterminate
|
||||
* drawable
|
||||
* @attr ref android.R.styleable#ProgressBar_indeterminateTintMode
|
||||
* @see #setIndeterminateTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getIndeterminateTintMode() {
|
||||
return mIndeterminateTintMode;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateTintMode : null;
|
||||
}
|
||||
|
||||
private void applyIndeterminateTint() {
|
||||
if (mIndeterminateDrawable != null && mHasIndeterminateTint) {
|
||||
mIndeterminateDrawable = mIndeterminateDrawable.mutate();
|
||||
mIndeterminateDrawable.setTintList(mIndeterminateTintList);
|
||||
mIndeterminateDrawable.setTintMode(mIndeterminateTintMode);
|
||||
if (mIndeterminateDrawable != null && mProgressTintInfo != null) {
|
||||
final ProgressTintInfo tintInfo = mProgressTintInfo;
|
||||
if (tintInfo.mHasIndeterminateTint || tintInfo.mHasIndeterminateTintMode) {
|
||||
mIndeterminateDrawable = mIndeterminateDrawable.mutate();
|
||||
|
||||
if (tintInfo.mHasIndeterminateTint) {
|
||||
mIndeterminateDrawable.setTintList(tintInfo.mIndeterminateTintList);
|
||||
}
|
||||
|
||||
if (tintInfo.mHasIndeterminateTintMode) {
|
||||
mIndeterminateDrawable.setTintMode(tintInfo.mIndeterminateTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,20 +738,7 @@ public class ProgressBar extends View {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
if (mHasProgressTint) {
|
||||
applyProgressLayerTint(R.id.progress, mProgressTintList,
|
||||
mProgressTintMode, true);
|
||||
}
|
||||
|
||||
if (mHasProgressBackgroundTint) {
|
||||
applyProgressLayerTint(R.id.background, mProgressBackgroundTintList,
|
||||
mProgressBackgroundTintMode, false);
|
||||
}
|
||||
|
||||
if (mHasSecondaryProgressTint) {
|
||||
applyProgressLayerTint(R.id.secondaryProgress, mSecondaryProgressTintList,
|
||||
mSecondaryProgressTintMode, false);
|
||||
}
|
||||
applyProgressTints();
|
||||
}
|
||||
|
||||
if (!mIndeterminate) {
|
||||
@@ -734,10 +754,78 @@ public class ProgressBar extends View {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the progress tints in order of increasing specificity.
|
||||
*/
|
||||
private void applyProgressTints() {
|
||||
if (mProgressDrawable != null && mProgressTintInfo != null) {
|
||||
applyPrimaryProgressTint();
|
||||
applyProgressBackgroundTint();
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be called if we've already verified that mProgressDrawable
|
||||
* and mProgressTintInfo are non-null.
|
||||
*/
|
||||
private void applyPrimaryProgressTint() {
|
||||
if (mProgressTintInfo.mHasProgressTint
|
||||
|| mProgressTintInfo.mHasProgressTintMode) {
|
||||
final Drawable target = getTintTarget(R.id.progress, true);
|
||||
if (target != null) {
|
||||
if (mProgressTintInfo.mHasProgressTint) {
|
||||
target.setTintList(mProgressTintInfo.mProgressTintList);
|
||||
}
|
||||
if (mProgressTintInfo.mHasProgressTintMode) {
|
||||
target.setTintMode(mProgressTintInfo.mProgressTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be called if we've already verified that mProgressDrawable
|
||||
* and mProgressTintInfo are non-null.
|
||||
*/
|
||||
private void applyProgressBackgroundTint() {
|
||||
if (mProgressTintInfo.mHasProgressBackgroundTint
|
||||
|| mProgressTintInfo.mHasProgressBackgroundTintMode) {
|
||||
final Drawable target = getTintTarget(R.id.background, false);
|
||||
if (target != null) {
|
||||
if (mProgressTintInfo.mHasProgressBackgroundTint) {
|
||||
target.setTintList(mProgressTintInfo.mProgressBackgroundTintList);
|
||||
}
|
||||
if (mProgressTintInfo.mHasProgressBackgroundTintMode) {
|
||||
target.setTintMode(mProgressTintInfo.mProgressBackgroundTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be called if we've already verified that mProgressDrawable
|
||||
* and mProgressTintInfo are non-null.
|
||||
*/
|
||||
private void applySecondaryProgressTint() {
|
||||
if (mProgressTintInfo.mHasSecondaryProgressTint
|
||||
|| mProgressTintInfo.mHasSecondaryProgressTintMode) {
|
||||
final Drawable target = getTintTarget(R.id.secondaryProgress, false);
|
||||
if (target != null) {
|
||||
if (mProgressTintInfo.mHasSecondaryProgressTint) {
|
||||
target.setTintList(mProgressTintInfo.mSecondaryProgressTintList);
|
||||
}
|
||||
if (mProgressTintInfo.mHasSecondaryProgressTintMode) {
|
||||
target.setTintMode(mProgressTintInfo.mSecondaryProgressTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a tint to the progress indicator, if one exists, or to the
|
||||
* entire progress drawable otherwise. Does not modify the current tint
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
|
||||
* mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
|
||||
* <p>
|
||||
* The progress indicator should be specified as a layer with
|
||||
* id {@link android.R.id#progress} in a {@link LayerDrawable}
|
||||
@@ -755,26 +843,33 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setProgressTintList(@Nullable ColorStateList tint) {
|
||||
mProgressTintList = tint;
|
||||
mHasProgressTint = true;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressTintList = tint;
|
||||
mProgressTintInfo.mHasProgressTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.progress, tint, mProgressTintMode, true);
|
||||
if (mProgressDrawable != null) {
|
||||
applyPrimaryProgressTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tint applied to the progress drawable, if specified.
|
||||
*
|
||||
* @return the tint applied to the progress drawable
|
||||
* @attr ref android.R.styleable#ProgressBar_progressTint
|
||||
* @see #setProgressTintList(ColorStateList)
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getProgressTintList() {
|
||||
return mProgressTintList;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mProgressTintList : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setProgressTintList(ColorStateList)}} to the progress
|
||||
* indicator. The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* indicator. The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -783,19 +878,29 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressTintMode = tintMode;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressTintMode = tintMode;
|
||||
mProgressTintInfo.mHasProgressTintMode = true;
|
||||
|
||||
applyProgressLayerTint(R.id.progress, mProgressTintList, tintMode, true);
|
||||
if (mProgressDrawable != null) {
|
||||
applyPrimaryProgressTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blending mode used to apply the tint to the progress drawable
|
||||
* Returns the blending mode used to apply the tint to the progress
|
||||
* drawable, if specified.
|
||||
*
|
||||
* @return the blending mode used to apply the tint to the progress
|
||||
* drawable
|
||||
* @attr ref android.R.styleable#ProgressBar_progressTintMode
|
||||
* @see #setProgressTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getProgressTintMode() {
|
||||
return mProgressTintMode;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mProgressTintMode : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -819,26 +924,33 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setProgressBackgroundTintList(@Nullable ColorStateList tint) {
|
||||
mProgressBackgroundTintList = tint;
|
||||
mHasProgressBackgroundTint = true;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressBackgroundTintList = tint;
|
||||
mProgressTintInfo.mHasProgressBackgroundTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.background, tint, mProgressBackgroundTintMode, false);
|
||||
if (mProgressDrawable != null) {
|
||||
applyProgressBackgroundTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tint applied to the progress background, if specified.
|
||||
*
|
||||
* @return the tint applied to the progress background
|
||||
* @attr ref android.R.styleable#ProgressBar_progressBackgroundTint
|
||||
* @see #setProgressBackgroundTintList(ColorStateList)
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getProgressBackgroundTintList() {
|
||||
return mProgressBackgroundTintList;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundTintList : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the blending mode used to apply the tint specified by
|
||||
* {@link #setProgressBackgroundTintList(ColorStateList)}} to the progress
|
||||
* background. The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
|
||||
* background. The default mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
*
|
||||
* @param tintMode the blending mode used to apply the tint, may be
|
||||
* {@code null} to clear tint
|
||||
@@ -847,9 +959,15 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setProgressBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressBackgroundTintMode = tintMode;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mProgressBackgroundTintMode = tintMode;
|
||||
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
|
||||
|
||||
applyProgressLayerTint(R.id.background, mProgressBackgroundTintList, tintMode, false);
|
||||
if (mProgressDrawable != null) {
|
||||
applyProgressBackgroundTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -860,7 +978,7 @@ public class ProgressBar extends View {
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getProgressBackgroundTintMode() {
|
||||
return mProgressBackgroundTintMode;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundTintMode : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -884,20 +1002,28 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintList(ColorStateList)
|
||||
*/
|
||||
public void setSecondaryProgressTintList(@Nullable ColorStateList tint) {
|
||||
mSecondaryProgressTintList = tint;
|
||||
mHasSecondaryProgressTint = true;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mSecondaryProgressTintList = tint;
|
||||
mProgressTintInfo.mHasSecondaryProgressTint = true;
|
||||
|
||||
applyProgressLayerTint(R.id.secondaryProgress, tint, mSecondaryProgressTintMode, false);
|
||||
if (mProgressDrawable != null) {
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tint applied to the secondary progress drawable, if
|
||||
* specified.
|
||||
*
|
||||
* @return the tint applied to the secondary progress drawable
|
||||
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTint
|
||||
* @see #setSecondaryProgressTintList(ColorStateList)
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getSecondaryProgressTintList() {
|
||||
return mSecondaryProgressTintList;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressTintList : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -913,12 +1039,21 @@ public class ProgressBar extends View {
|
||||
* @see Drawable#setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setSecondaryProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mSecondaryProgressTintMode = tintMode;
|
||||
if (mProgressTintInfo == null) {
|
||||
mProgressTintInfo = new ProgressTintInfo();
|
||||
}
|
||||
mProgressTintInfo.mSecondaryProgressTintMode = tintMode;
|
||||
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
|
||||
|
||||
applyProgressLayerTint(R.id.secondaryProgress, mSecondaryProgressTintList, tintMode, false);
|
||||
if (mProgressDrawable != null) {
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blending mode used to apply the tint to the secondary
|
||||
* progress drawable, if specified.
|
||||
*
|
||||
* @return the blending mode used to apply the tint to the secondary
|
||||
* progress drawable
|
||||
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTintMode
|
||||
@@ -926,16 +1061,25 @@ public class ProgressBar extends View {
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getSecondaryProgressTintMode() {
|
||||
return mSecondaryProgressTintMode;
|
||||
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressTintMode : null;
|
||||
}
|
||||
|
||||
private void applyProgressLayerTint(int layerId, @Nullable ColorStateList tint,
|
||||
@Nullable PorterDuff.Mode tintMode, boolean shouldFallback) {
|
||||
/**
|
||||
* Returns the drawable to which a tint or tint mode should be applied.
|
||||
*
|
||||
* @param layerId id of the layer to modify
|
||||
* @param shouldFallback whether the base drawable should be returned
|
||||
* if the id does not exist
|
||||
* @return the drawable to modify
|
||||
*/
|
||||
@Nullable
|
||||
private Drawable getTintTarget(int layerId, boolean shouldFallback) {
|
||||
Drawable layer = null;
|
||||
|
||||
final Drawable d = mProgressDrawable;
|
||||
if (d != null) {
|
||||
mProgressDrawable = d.mutate();
|
||||
|
||||
Drawable layer = null;
|
||||
if (d instanceof LayerDrawable) {
|
||||
layer = ((LayerDrawable) d).findDrawableByLayerId(layerId);
|
||||
}
|
||||
@@ -943,12 +1087,9 @@ public class ProgressBar extends View {
|
||||
if (shouldFallback && layer == null) {
|
||||
layer = d;
|
||||
}
|
||||
|
||||
if (layer != null) {
|
||||
layer.setTintList(tint);
|
||||
layer.setTintMode(tintMode);
|
||||
}
|
||||
}
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1748,4 +1889,26 @@ public class ProgressBar extends View {
|
||||
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ProgressTintInfo {
|
||||
ColorStateList mIndeterminateTintList;
|
||||
PorterDuff.Mode mIndeterminateTintMode;
|
||||
boolean mHasIndeterminateTint;
|
||||
boolean mHasIndeterminateTintMode;
|
||||
|
||||
ColorStateList mProgressTintList;
|
||||
PorterDuff.Mode mProgressTintMode;
|
||||
boolean mHasProgressTint;
|
||||
boolean mHasProgressTintMode;
|
||||
|
||||
ColorStateList mProgressBackgroundTintList;
|
||||
PorterDuff.Mode mProgressBackgroundTintMode;
|
||||
boolean mHasProgressBackgroundTint;
|
||||
boolean mHasProgressBackgroundTintMode;
|
||||
|
||||
ColorStateList mSecondaryProgressTintList;
|
||||
PorterDuff.Mode mSecondaryProgressTintMode;
|
||||
boolean mHasSecondaryProgressTint;
|
||||
boolean mHasSecondaryProgressTintMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3459,8 +3459,6 @@
|
||||
<!-- @hide The alpha value (0-255) set on the ImageView's drawable. Equivalent
|
||||
to calling ImageView.setAlpha(int), not the same as View.setAlpha(float). -->
|
||||
<attr name="drawableAlpha" format="integer" />
|
||||
<!-- Tint to apply to the image. -->
|
||||
<attr name="tint" />
|
||||
<!-- Blending mode used to apply the image tint. -->
|
||||
<attr name="tintMode" />
|
||||
</declare-styleable>
|
||||
|
||||
Reference in New Issue
Block a user