Merge "Added BlendMode equivalent APIs to replace deprecated PorterDuff variants" into qt-dev

This commit is contained in:
Nader Jawad
2019-04-18 21:18:32 +00:00
committed by Android (Google) Code Review
33 changed files with 594 additions and 245 deletions

View File

@@ -488,7 +488,7 @@ public class MenuInflater {
}
if (mItemIconBlendMode != null) {
item.setIconTintMode(mItemIconBlendMode);
item.setIconTintBlendMode(mItemIconBlendMode);
}
if (itemIconTintList != null) {

View File

@@ -270,11 +270,8 @@ public interface MenuItem {
* @attr ref android.R.styleable#MenuItem_iconTintMode
* @see #setIconTintList(ColorStateList)
* @see Drawable#setTintMode(PorterDuff.Mode)
* @see Drawable#setTintMode(BlendMode)
*
* @deprecated use {@link #setIconTintMode(BlendMode)} instead
* @see Drawable#setTintBlendMode(BlendMode)
*/
@Deprecated
default @NonNull MenuItem setIconTintMode(@Nullable PorterDuff.Mode tintMode) {
return this;
}
@@ -289,7 +286,7 @@ public interface MenuItem {
* @attr ref android.R.styleable#MenuItem_iconTintMode
* @see #setIconTintList(ColorStateList)
*/
default @NonNull MenuItem setIconTintMode(@Nullable BlendMode blendMode) {
default @NonNull MenuItem setIconTintBlendMode(@Nullable BlendMode blendMode) {
PorterDuff.Mode mode = BlendMode.blendModeToPorterDuffMode(blendMode);
if (mode != null) {
return setIconTintMode(mode);
@@ -304,11 +301,9 @@ public interface MenuItem {
* @return the blending mode used to apply the tint to this item's icon
* @attr ref android.R.styleable#MenuItem_iconTintMode
* @see #setIconTintMode(PorterDuff.Mode)
* @see #setIconTintMode(BlendMode)
* @see #setIconTintBlendMode(BlendMode)
*
* @deprecated Use {@link #getIconTintBlendMode()} instead
*/
@Deprecated
@Nullable
public default PorterDuff.Mode getIconTintMode() { return null; }
@@ -317,7 +312,7 @@ public interface MenuItem {
*
* @return the blending mode used to apply the tint to this item's icon
* @attr ref android.R.styleable#MenuItem_iconTintMode
* @see #setIconTintMode(BlendMode)
* @see #setIconTintBlendMode(BlendMode)
*
*/
@Nullable

View File

@@ -5608,7 +5608,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
break;
case R.styleable.View_foregroundTintMode:
if (targetSdkVersion >= Build.VERSION_CODES.M || this instanceof FrameLayout) {
setForegroundTintMode(Drawable.parseBlendMode(a.getInt(attr, -1), null));
setForegroundTintBlendMode(
Drawable.parseBlendMode(a.getInt(attr, -1),
null));
}
break;
case R.styleable.View_foregroundTint:
@@ -22873,17 +22875,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_backgroundTintMode
* @see #getBackgroundTintMode()
* @see Drawable#setTintMode(PorterDuff.Mode)
*
* @deprecated use @setBackgroundTintMode(BlendMode) instead
*/
@Deprecated
public void setBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
BlendMode mode = null;
if (tintMode != null) {
mode = BlendMode.fromValue(tintMode.nativeInt);
}
setBackgroundTintMode(mode);
setBackgroundTintBlendMode(mode);
}
/**
@@ -22895,9 +22894,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* {@code null} to clear tint
* @attr ref android.R.styleable#View_backgroundTintMode
* @see #getBackgroundTintMode()
* @see Drawable#setTintMode(BlendMode)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setBackgroundTintMode(@Nullable BlendMode blendMode) {
public void setBackgroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mBackgroundTint == null) {
mBackgroundTint = new TintInfo();
}
@@ -22915,13 +22914,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return the blending mode used to apply the tint to the background
* drawable
* @attr ref android.R.styleable#View_backgroundTintMode
* @see #setBackgroundTintMode(BlendMode)
* @see #setBackgroundTintBlendMode(BlendMode)
*
* @deprecated use #getBackgroundBlendMode() instead
*/
@Nullable
@InspectableProperty
@Deprecated
public PorterDuff.Mode getBackgroundTintMode() {
PorterDuff.Mode porterDuffMode;
if (mBackgroundTint != null && mBackgroundTint.mBlendMode != null) {
@@ -22939,9 +22936,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return the blending mode used to apply the tint to the background
* drawable, null if no blend has previously been configured
* @attr ref android.R.styleable#View_backgroundTintMode
* @see #setBackgroundTintMode(BlendMode)
* @see #setBackgroundTintBlendMode(BlendMode)
*/
public @Nullable BlendMode getBackgroundBlendMode() {
public @Nullable BlendMode getBackgroundTintBlendMode() {
return mBackgroundTint != null ? mBackgroundTint.mBlendMode : null;
}
@@ -22956,7 +22953,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
if (tintInfo.mHasTintMode) {
mBackground.setTintMode(tintInfo.mBlendMode);
mBackground.setTintBlendMode(tintInfo.mBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -23141,15 +23138,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #getForegroundTintMode()
* @see Drawable#setTintMode(PorterDuff.Mode)
*
* @deprecated use #setForegroundTintMode(BlendMode)
*/
@Deprecated
public void setForegroundTintMode(@Nullable PorterDuff.Mode tintMode) {
BlendMode mode = null;
if (tintMode != null) {
mode = BlendMode.fromValue(tintMode.nativeInt);
}
setForegroundTintMode(mode);
setForegroundTintBlendMode(mode);
}
/**
@@ -23161,9 +23156,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* {@code null} to clear tint
* @attr ref android.R.styleable#View_foregroundTintMode
* @see #getForegroundTintMode()
* @see Drawable#setTintMode(BlendMode)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setForegroundTintMode(@Nullable BlendMode blendMode) {
public void setForegroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mForegroundInfo == null) {
mForegroundInfo = new ForegroundInfo();
}
@@ -23184,12 +23179,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* drawable
* @attr ref android.R.styleable#View_foregroundTintMode
* @see #setForegroundTintMode(PorterDuff.Mode)
*
* @deprecated use #getForegroundBlendMode() instead
*/
@InspectableProperty
@Nullable
@Deprecated
public PorterDuff.Mode getForegroundTintMode() {
BlendMode blendMode = mForegroundInfo != null && mForegroundInfo.mTintInfo != null
? mForegroundInfo.mTintInfo.mBlendMode : null;
@@ -23207,10 +23199,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return the blending mode used to apply the tint to the foreground
* drawable
* @attr ref android.R.styleable#View_foregroundTintMode
* @see #setForegroundTintMode(BlendMode)
* @see #setForegroundTintBlendMode(BlendMode)
*
*/
public @Nullable BlendMode getForegroundBlendMode() {
public @Nullable BlendMode getForegroundTintBlendMode() {
return mForegroundInfo != null && mForegroundInfo.mTintInfo != null
? mForegroundInfo.mTintInfo.mBlendMode : null;
}
@@ -23227,7 +23219,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
if (tintInfo.mHasTintMode) {
mForegroundInfo.mDrawable.setTintMode(tintInfo.mBlendMode);
mForegroundInfo.mDrawable.setTintBlendMode(tintInfo.mBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -22,6 +22,7 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.PorterDuff;
@@ -48,15 +49,15 @@ public abstract class AbsSeekBar extends ProgressBar {
@UnsupportedAppUsage
private Drawable mThumb;
private ColorStateList mThumbTintList = null;
private PorterDuff.Mode mThumbTintMode = null;
private BlendMode mThumbBlendMode = null;
private boolean mHasThumbTint = false;
private boolean mHasThumbTintMode = false;
private boolean mHasThumbBlendMode = false;
private Drawable mTickMark;
private ColorStateList mTickMarkTintList = null;
private PorterDuff.Mode mTickMarkTintMode = null;
private BlendMode mTickMarkBlendMode = null;
private boolean mHasTickMarkTint = false;
private boolean mHasTickMarkTintMode = false;
private boolean mHasTickMarkBlendMode = false;
private int mThumbOffset;
@UnsupportedAppUsage
@@ -114,9 +115,9 @@ public abstract class AbsSeekBar extends ProgressBar {
setThumb(thumb);
if (a.hasValue(R.styleable.SeekBar_thumbTintMode)) {
mThumbTintMode = Drawable.parseTintMode(a.getInt(
R.styleable.SeekBar_thumbTintMode, -1), mThumbTintMode);
mHasThumbTintMode = true;
mThumbBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.SeekBar_thumbTintMode, -1), mThumbBlendMode);
mHasThumbBlendMode = true;
}
if (a.hasValue(R.styleable.SeekBar_thumbTint)) {
@@ -128,9 +129,9 @@ public abstract class AbsSeekBar extends ProgressBar {
setTickMark(tickMark);
if (a.hasValue(R.styleable.SeekBar_tickMarkTintMode)) {
mTickMarkTintMode = Drawable.parseTintMode(a.getInt(
R.styleable.SeekBar_tickMarkTintMode, -1), mTickMarkTintMode);
mHasTickMarkTintMode = true;
mTickMarkBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.SeekBar_tickMarkTintMode, -1), mTickMarkBlendMode);
mHasTickMarkBlendMode = true;
}
if (a.hasValue(R.styleable.SeekBar_tickMarkTint)) {
@@ -274,9 +275,25 @@ public abstract class AbsSeekBar extends ProgressBar {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) {
mThumbTintMode = tintMode;
mHasThumbTintMode = true;
setThumbTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) :
null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setThumbTintList(ColorStateList)}} to the thumb drawable. The
* default mode is {@link BlendMode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
*
* @attr ref android.R.styleable#SeekBar_thumbTintMode
* @see #getThumbTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setThumbTintBlendMode(@Nullable BlendMode blendMode) {
mThumbBlendMode = blendMode;
mHasThumbBlendMode = true;
applyThumbTint();
}
@@ -291,19 +308,33 @@ public abstract class AbsSeekBar extends ProgressBar {
@InspectableProperty
@Nullable
public PorterDuff.Mode getThumbTintMode() {
return mThumbTintMode;
return mThumbBlendMode != null
? BlendMode.blendModeToPorterDuffMode(mThumbBlendMode) : null;
}
/**
* 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 #setThumbTintBlendMode(BlendMode)
*/
@Nullable
public BlendMode getThumbTintBlendMode() {
return mThumbBlendMode;
}
private void applyThumbTint() {
if (mThumb != null && (mHasThumbTint || mHasThumbTintMode)) {
if (mThumb != null && (mHasThumbTint || mHasThumbBlendMode)) {
mThumb = mThumb.mutate();
if (mHasThumbTint) {
mThumb.setTintList(mThumbTintList);
}
if (mHasThumbTintMode) {
mThumb.setTintMode(mThumbTintMode);
if (mHasThumbBlendMode) {
mThumb.setTintBlendMode(mThumbBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -430,8 +461,24 @@ public abstract class AbsSeekBar extends ProgressBar {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setTickMarkTintMode(@Nullable PorterDuff.Mode tintMode) {
mTickMarkTintMode = tintMode;
mHasTickMarkTintMode = true;
setTickMarkTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setTickMarkTintList(ColorStateList)}} to the tick mark drawable. The
* default mode is {@link BlendMode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
*
* @attr ref android.R.styleable#SeekBar_tickMarkTintMode
* @see #getTickMarkTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setTickMarkTintBlendMode(@Nullable BlendMode blendMode) {
mTickMarkBlendMode = blendMode;
mHasTickMarkBlendMode = true;
applyTickMarkTint();
}
@@ -447,19 +494,34 @@ public abstract class AbsSeekBar extends ProgressBar {
@InspectableProperty
@Nullable
public PorterDuff.Mode getTickMarkTintMode() {
return mTickMarkTintMode;
return mTickMarkBlendMode != null
? BlendMode.blendModeToPorterDuffMode(mTickMarkBlendMode) : null;
}
/**
* Returns the blending mode used to apply the tint to the tick mark drawable,
* if specified.
*
* @return the blending mode used to apply the tint to the tick mark drawable
* @attr ref android.R.styleable#SeekBar_tickMarkTintMode
* @see #setTickMarkTintMode(PorterDuff.Mode)
*/
@InspectableProperty(attributeId = android.R.styleable.SeekBar_tickMarkTintMode)
@Nullable
public BlendMode getTickMarkTintBlendMode() {
return mTickMarkBlendMode;
}
private void applyTickMarkTint() {
if (mTickMark != null && (mHasTickMarkTint || mHasTickMarkTintMode)) {
if (mTickMark != null && (mHasTickMarkTint || mHasTickMarkBlendMode)) {
mTickMark = mTickMark.mutate();
if (mHasTickMarkTint) {
mTickMark.setTintList(mTickMarkTintList);
}
if (mHasTickMarkTintMode) {
mTickMark.setTintMode(mTickMarkTintMode);
if (mHasTickMarkBlendMode) {
mTickMark.setTintBlendMode(mTickMarkBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -23,6 +23,7 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@@ -58,7 +59,7 @@ public class CheckedTextView extends TextView implements Checkable {
@UnsupportedAppUsage
private Drawable mCheckMarkDrawable;
private ColorStateList mCheckMarkTintList = null;
private PorterDuff.Mode mCheckMarkTintMode = null;
private BlendMode mCheckMarkBlendMode = null;
private boolean mHasCheckMarkTint = false;
private boolean mHasCheckMarkTintMode = false;
@@ -99,8 +100,9 @@ public class CheckedTextView extends TextView implements Checkable {
}
if (a.hasValue(R.styleable.CheckedTextView_checkMarkTintMode)) {
mCheckMarkTintMode = Drawable.parseTintMode(a.getInt(
R.styleable.CheckedTextView_checkMarkTintMode, -1), mCheckMarkTintMode);
mCheckMarkBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.CheckedTextView_checkMarkTintMode, -1),
mCheckMarkBlendMode);
mHasCheckMarkTintMode = true;
}
@@ -259,7 +261,23 @@ public class CheckedTextView extends TextView implements Checkable {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setCheckMarkTintMode(@Nullable PorterDuff.Mode tintMode) {
mCheckMarkTintMode = tintMode;
setCheckMarkTintBlendMode(tintMode != null
? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* 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_IN}.
*
* @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 #setCheckMarkTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setCheckMarkTintBlendMode(@Nullable BlendMode tintMode) {
mCheckMarkBlendMode = tintMode;
mHasCheckMarkTintMode = true;
applyCheckMarkTint();
@@ -277,7 +295,23 @@ public class CheckedTextView extends TextView implements Checkable {
@InspectableProperty
@Nullable
public PorterDuff.Mode getCheckMarkTintMode() {
return mCheckMarkTintMode;
return mCheckMarkBlendMode != null
? BlendMode.blendModeToPorterDuffMode(mCheckMarkBlendMode) : null;
}
/**
* 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)
*/
@InspectableProperty(attributeId = android.R.styleable.CheckedTextView_checkMarkTintMode)
@Nullable
public BlendMode getCheckMarkTintBlendMode() {
return mCheckMarkBlendMode;
}
private void applyCheckMarkTint() {
@@ -289,7 +323,7 @@ public class CheckedTextView extends TextView implements Checkable {
}
if (mHasCheckMarkTintMode) {
mCheckMarkDrawable.setTintMode(mCheckMarkTintMode);
mCheckMarkDrawable.setTintBlendMode(mCheckMarkBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -23,6 +23,7 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@@ -67,9 +68,9 @@ public abstract class CompoundButton extends Button implements Checkable {
@UnsupportedAppUsage
private Drawable mButtonDrawable;
private ColorStateList mButtonTintList = null;
private PorterDuff.Mode mButtonTintMode = null;
private BlendMode mButtonBlendMode = null;
private boolean mHasButtonTint = false;
private boolean mHasButtonTintMode = false;
private boolean mHasButtonBlendMode = false;
@UnsupportedAppUsage
private OnCheckedChangeListener mOnCheckedChangeListener;
@@ -109,9 +110,9 @@ public abstract class CompoundButton extends Button implements Checkable {
}
if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
mButtonTintMode = Drawable.parseTintMode(a.getInt(
R.styleable.CompoundButton_buttonTintMode, -1), mButtonTintMode);
mHasButtonTintMode = true;
mButtonBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.CompoundButton_buttonTintMode, -1), mButtonBlendMode);
mHasButtonBlendMode = true;
}
if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
@@ -337,8 +338,23 @@ public abstract class CompoundButton extends Button implements Checkable {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setButtonTintMode(@Nullable PorterDuff.Mode tintMode) {
mButtonTintMode = tintMode;
mHasButtonTintMode = true;
setButtonTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* 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_IN}.
*
* @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 #getButtonTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setButtonTintBlendMode(@Nullable BlendMode tintMode) {
mButtonBlendMode = tintMode;
mHasButtonBlendMode = true;
applyButtonTint();
}
@@ -348,22 +364,35 @@ public abstract class CompoundButton extends Button implements Checkable {
* @attr ref android.R.styleable#CompoundButton_buttonTintMode
* @see #setButtonTintMode(PorterDuff.Mode)
*/
@InspectableProperty
@InspectableProperty(name = "buttonTintMode")
@Nullable
public PorterDuff.Mode getButtonTintMode() {
return mButtonTintMode;
return mButtonBlendMode != null ? BlendMode.blendModeToPorterDuffMode(mButtonBlendMode) :
null;
}
/**
* @return the blending mode used to apply the tint to the button drawable
* @attr ref android.R.styleable#CompoundButton_buttonTintMode
* @see #setButtonTintBlendMode(BlendMode)
*/
@InspectableProperty(name = "buttonBlendMode",
attributeId = R.styleable.CompoundButton_buttonTintMode)
@Nullable
public BlendMode getButtonTintBlendMode() {
return mButtonBlendMode;
}
private void applyButtonTint() {
if (mButtonDrawable != null && (mHasButtonTint || mHasButtonTintMode)) {
if (mButtonDrawable != null && (mHasButtonTint || mHasButtonBlendMode)) {
mButtonDrawable = mButtonDrawable.mutate();
if (mHasButtonTint) {
mButtonDrawable.setTintList(mButtonTintList);
}
if (mHasButtonTintMode) {
mButtonDrawable.setTintMode(mButtonTintMode);
if (mHasButtonBlendMode) {
mButtonDrawable.setTintBlendMode(mButtonBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -27,6 +27,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.ImageDecoder;
@@ -127,9 +128,9 @@ public class ImageView extends View {
@UnsupportedAppUsage
private BitmapDrawable mRecycleableBitmapDrawable = null;
private ColorStateList mDrawableTintList = null;
private PorterDuff.Mode mDrawableTintMode = null;
private BlendMode mDrawableBlendMode = null;
private boolean mHasDrawableTint = false;
private boolean mHasDrawableTintMode = false;
private boolean mHasDrawableBlendMode = false;
private int[] mState = null;
private boolean mMergeState = false;
@@ -226,14 +227,14 @@ public class ImageView extends View {
// Prior to L, this attribute would always set a color filter with
// blending mode SRC_ATOP. Preserve that default behavior.
mDrawableTintMode = PorterDuff.Mode.SRC_ATOP;
mHasDrawableTintMode = true;
mDrawableBlendMode = BlendMode.SRC_ATOP;
mHasDrawableBlendMode = true;
}
if (a.hasValue(R.styleable.ImageView_tintMode)) {
mDrawableTintMode = Drawable.parseTintMode(a.getInt(
R.styleable.ImageView_tintMode, -1), mDrawableTintMode);
mHasDrawableTintMode = true;
mDrawableBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.ImageView_tintMode, -1), mDrawableBlendMode);
mHasDrawableBlendMode = true;
}
applyImageTint();
@@ -674,8 +675,23 @@ public class ImageView extends View {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setImageTintMode(@Nullable PorterDuff.Mode tintMode) {
mDrawableTintMode = tintMode;
mHasDrawableTintMode = true;
setImageTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setImageTintList(ColorStateList)}} to the image drawable. The default
* mode is {@link BlendMode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#ImageView_tintMode
* @see #getImageTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setImageTintBlendMode(@Nullable BlendMode blendMode) {
mDrawableBlendMode = blendMode;
mHasDrawableBlendMode = true;
applyImageTint();
}
@@ -689,19 +705,32 @@ public class ImageView extends View {
@Nullable
@InspectableProperty(name = "tintMode")
public PorterDuff.Mode getImageTintMode() {
return mDrawableTintMode;
return mDrawableBlendMode != null
? BlendMode.blendModeToPorterDuffMode(mDrawableBlendMode) : null;
}
/**
* Gets the blending mode used to apply the tint to the image Drawable
* @return the blending mode used to apply the tint to the image Drawable
* @attr ref android.R.styleable#ImageView_tintMode
* @see #setImageTintBlendMode(BlendMode)
*/
@Nullable
@InspectableProperty(name = "blendMode", attributeId = android.R.styleable.ImageView_tintMode)
public BlendMode getImageTintBlendMode() {
return mDrawableBlendMode;
}
private void applyImageTint() {
if (mDrawable != null && (mHasDrawableTint || mHasDrawableTintMode)) {
if (mDrawable != null && (mHasDrawableTint || mHasDrawableBlendMode)) {
mDrawable = mDrawable.mutate();
if (mHasDrawableTint) {
mDrawable.setTintList(mDrawableTintList);
}
if (mHasDrawableTintMode) {
mDrawable.setTintMode(mDrawableTintMode);
if (mHasDrawableBlendMode) {
mDrawable.setTintBlendMode(mDrawableBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -25,6 +25,7 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -334,7 +335,7 @@ public class ProgressBar extends View {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressTintMode = Drawable.parseTintMode(a.getInt(
mProgressTintInfo.mProgressBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.ProgressBar_progressTintMode, -1), null);
mProgressTintInfo.mHasProgressTintMode = true;
}
@@ -352,7 +353,7 @@ public class ProgressBar extends View {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressBackgroundTintMode = Drawable.parseTintMode(a.getInt(
mProgressTintInfo.mProgressBackgroundBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.ProgressBar_progressBackgroundTintMode, -1), null);
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
}
@@ -370,7 +371,7 @@ public class ProgressBar extends View {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mSecondaryProgressTintMode = Drawable.parseTintMode(
mProgressTintInfo.mSecondaryProgressBlendMode = Drawable.parseBlendMode(
a.getInt(R.styleable.ProgressBar_secondaryProgressTintMode, -1), null);
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
}
@@ -388,7 +389,7 @@ public class ProgressBar extends View {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mIndeterminateTintMode = Drawable.parseTintMode(a.getInt(
mProgressTintInfo.mIndeterminateBlendMode = Drawable.parseBlendMode(a.getInt(
R.styleable.ProgressBar_indeterminateTintMode, -1), null);
mProgressTintInfo.mHasIndeterminateTintMode = true;
}
@@ -796,12 +797,29 @@ public class ProgressBar extends View {
* @attr ref android.R.styleable#ProgressBar_indeterminateTintMode
* @see #setIndeterminateTintList(ColorStateList)
* @see Drawable#setTintMode(PorterDuff.Mode)
*
*/
public void setIndeterminateTintMode(@Nullable PorterDuff.Mode tintMode) {
setIndeterminateTintBlendMode(tintMode != null
? BlendMode.fromValue(tintMode.nativeInt) : 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_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#ProgressBar_indeterminateTintMode
* @see #setIndeterminateTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setIndeterminateTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mIndeterminateTintMode = tintMode;
mProgressTintInfo.mIndeterminateBlendMode = blendMode;
mProgressTintInfo.mHasIndeterminateTintMode = true;
applyIndeterminateTint();
@@ -819,7 +837,23 @@ public class ProgressBar extends View {
@InspectableProperty
@Nullable
public PorterDuff.Mode getIndeterminateTintMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateTintMode : null;
BlendMode mode = getIndeterminateTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* 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 #setIndeterminateTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = R.styleable.ProgressBar_indeterminateTintMode)
@Nullable
public BlendMode getIndeterminateTintBlendMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateBlendMode : null;
}
private void applyIndeterminateTint() {
@@ -833,7 +867,7 @@ public class ProgressBar extends View {
}
if (tintInfo.mHasIndeterminateTintMode) {
mIndeterminateDrawable.setTintMode(tintInfo.mIndeterminateTintMode);
mIndeterminateDrawable.setTintBlendMode(tintInfo.mIndeterminateBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -956,7 +990,7 @@ public class ProgressBar extends View {
target.setTintList(mProgressTintInfo.mProgressTintList);
}
if (mProgressTintInfo.mHasProgressTintMode) {
target.setTintMode(mProgressTintInfo.mProgressTintMode);
target.setTintBlendMode(mProgressTintInfo.mProgressBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -981,7 +1015,7 @@ public class ProgressBar extends View {
target.setTintList(mProgressTintInfo.mProgressBackgroundTintList);
}
if (mProgressTintInfo.mHasProgressBackgroundTintMode) {
target.setTintMode(mProgressTintInfo.mProgressBackgroundTintMode);
target.setTintBlendMode(mProgressTintInfo.mProgressBackgroundBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -1006,7 +1040,7 @@ public class ProgressBar extends View {
target.setTintList(mProgressTintInfo.mSecondaryProgressTintList);
}
if (mProgressTintInfo.mHasSecondaryProgressTintMode) {
target.setTintMode(mProgressTintInfo.mSecondaryProgressTintMode);
target.setTintBlendMode(mProgressTintInfo.mSecondaryProgressBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -1076,10 +1110,25 @@ public class ProgressBar extends View {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
setProgressTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : 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_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#ProgressBar_progressTintMode
* @see #getProgressTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setProgressTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressTintMode = tintMode;
mProgressTintInfo.mProgressBlendMode = blendMode;
mProgressTintInfo.mHasProgressTintMode = true;
if (mProgressDrawable != null) {
@@ -1099,7 +1148,23 @@ public class ProgressBar extends View {
@InspectableProperty
@Nullable
public PorterDuff.Mode getProgressTintMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mProgressTintMode : null;
BlendMode mode = getProgressTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* 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 #setProgressTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = android.R.styleable.ProgressBar_progressTintMode)
@Nullable
public BlendMode getProgressTintBlendMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBlendMode : null;
}
/**
@@ -1160,10 +1225,26 @@ public class ProgressBar extends View {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setProgressBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
setProgressBackgroundTintBlendMode(tintMode != null
? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setProgressBackgroundTintList(ColorStateList)}} to the progress
* background. The default mode is {@link BlendMode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#ProgressBar_progressBackgroundTintMode
* @see #setProgressBackgroundTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setProgressBackgroundTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressBackgroundTintMode = tintMode;
mProgressTintInfo.mProgressBackgroundBlendMode = blendMode;
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
if (mProgressDrawable != null) {
@@ -1180,7 +1261,20 @@ public class ProgressBar extends View {
@InspectableProperty
@Nullable
public PorterDuff.Mode getProgressBackgroundTintMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundTintMode : null;
BlendMode mode = getProgressBackgroundTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* @return the blending mode used to apply the tint to the progress
* background
* @attr ref android.R.styleable#ProgressBar_progressBackgroundTintMode
* @see #setProgressBackgroundTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = R.styleable.ProgressBar_progressBackgroundTintMode)
@Nullable
public BlendMode getProgressBackgroundTintBlendMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundBlendMode : null;
}
/**
@@ -1242,10 +1336,27 @@ public class ProgressBar extends View {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setSecondaryProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
setSecondaryProgressTintBlendMode(tintMode != null
? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setSecondaryProgressTintList(ColorStateList)}} to the secondary
* progress indicator. The default mode is
* {@link PorterDuff.Mode#SRC_ATOP}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#ProgressBar_secondaryProgressTintMode
* @see #setSecondaryProgressTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setSecondaryProgressTintBlendMode(@Nullable BlendMode blendMode) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mSecondaryProgressTintMode = tintMode;
mProgressTintInfo.mSecondaryProgressBlendMode = blendMode;
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
if (mProgressDrawable != null) {
@@ -1265,7 +1376,23 @@ public class ProgressBar extends View {
@InspectableProperty
@Nullable
public PorterDuff.Mode getSecondaryProgressTintMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressTintMode : null;
BlendMode mode = getSecondaryProgressTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* 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
* @see #setSecondaryProgressTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = android.R.styleable.ProgressBar_secondaryProgressTintMode)
@Nullable
public BlendMode getSecondaryProgressTintBlendMode() {
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressBlendMode : null;
}
/**
@@ -2208,22 +2335,22 @@ public class ProgressBar extends View {
private static class ProgressTintInfo {
ColorStateList mIndeterminateTintList;
PorterDuff.Mode mIndeterminateTintMode;
BlendMode mIndeterminateBlendMode;
boolean mHasIndeterminateTint;
boolean mHasIndeterminateTintMode;
ColorStateList mProgressTintList;
PorterDuff.Mode mProgressTintMode;
BlendMode mProgressBlendMode;
boolean mHasProgressTint;
boolean mHasProgressTintMode;
ColorStateList mProgressBackgroundTintList;
PorterDuff.Mode mProgressBackgroundTintMode;
BlendMode mProgressBackgroundBlendMode;
boolean mHasProgressBackgroundTint;
boolean mHasProgressBackgroundTintMode;
ColorStateList mSecondaryProgressTintList;
PorterDuff.Mode mSecondaryProgressTintMode;
BlendMode mSecondaryProgressBlendMode;
boolean mHasSecondaryProgressTint;
boolean mHasSecondaryProgressTintMode;
}

View File

@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Paint;
@@ -98,14 +99,14 @@ public class Switch extends CompoundButton {
@UnsupportedAppUsage
private Drawable mThumbDrawable;
private ColorStateList mThumbTintList = null;
private PorterDuff.Mode mThumbTintMode = null;
private BlendMode mThumbBlendMode = null;
private boolean mHasThumbTint = false;
private boolean mHasThumbTintMode = false;
@UnsupportedAppUsage
private Drawable mTrackDrawable;
private ColorStateList mTrackTintList = null;
private PorterDuff.Mode mTrackTintMode = null;
private BlendMode mTrackBlendMode = null;
private boolean mHasTrackTint = false;
private boolean mHasTrackTintMode = false;
@@ -268,10 +269,11 @@ public class Switch extends CompoundButton {
mThumbTintList = thumbTintList;
mHasThumbTint = true;
}
PorterDuff.Mode thumbTintMode = Drawable.parseTintMode(
a.getInt(com.android.internal.R.styleable.Switch_thumbTintMode, -1), null);
if (mThumbTintMode != thumbTintMode) {
mThumbTintMode = thumbTintMode;
BlendMode thumbTintMode = Drawable.parseBlendMode(
a.getInt(com.android.internal.R.styleable.Switch_thumbTintMode, -1),
null);
if (mThumbBlendMode != thumbTintMode) {
mThumbBlendMode = thumbTintMode;
mHasThumbTintMode = true;
}
if (mHasThumbTint || mHasThumbTintMode) {
@@ -284,10 +286,11 @@ public class Switch extends CompoundButton {
mTrackTintList = trackTintList;
mHasTrackTint = true;
}
PorterDuff.Mode trackTintMode = Drawable.parseTintMode(
a.getInt(com.android.internal.R.styleable.Switch_trackTintMode, -1), null);
if (mTrackTintMode != trackTintMode) {
mTrackTintMode = trackTintMode;
BlendMode trackTintMode = Drawable.parseBlendMode(
a.getInt(com.android.internal.R.styleable.Switch_trackTintMode, -1),
null);
if (mTrackBlendMode != trackTintMode) {
mTrackBlendMode = trackTintMode;
mHasTrackTintMode = true;
}
if (mHasTrackTint || mHasTrackTintMode) {
@@ -587,7 +590,22 @@ public class Switch extends CompoundButton {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setTrackTintMode(@Nullable PorterDuff.Mode tintMode) {
mTrackTintMode = tintMode;
setTrackTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setTrackTintList(ColorStateList)}} to the track drawable.
* The default mode is {@link BlendMode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#Switch_trackTintMode
* @see #getTrackTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setTrackTintBlendMode(@Nullable BlendMode blendMode) {
mTrackBlendMode = blendMode;
mHasTrackTintMode = true;
applyTrackTint();
@@ -602,7 +620,20 @@ public class Switch extends CompoundButton {
@InspectableProperty
@Nullable
public PorterDuff.Mode getTrackTintMode() {
return mTrackTintMode;
BlendMode mode = getTrackTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* @return the blending mode used to apply the tint to the track
* drawable
* @attr ref android.R.styleable#Switch_trackTintMode
* @see #setTrackTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = com.android.internal.R.styleable.Switch_trackTintMode)
@Nullable
public BlendMode getTrackTintBlendMode() {
return mTrackBlendMode;
}
private void applyTrackTint() {
@@ -614,7 +645,7 @@ public class Switch extends CompoundButton {
}
if (mHasTrackTintMode) {
mTrackDrawable.setTintMode(mTrackTintMode);
mTrackDrawable.setTintBlendMode(mTrackBlendMode);
}
// The drawable (or one of its children) may not have been
@@ -713,7 +744,22 @@ public class Switch extends CompoundButton {
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) {
mThumbTintMode = tintMode;
setThumbTintBlendMode(tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* 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_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#Switch_thumbTintMode
* @see #getThumbTintMode()
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setThumbTintBlendMode(@Nullable BlendMode blendMode) {
mThumbBlendMode = blendMode;
mHasThumbTintMode = true;
applyThumbTint();
@@ -728,7 +774,20 @@ public class Switch extends CompoundButton {
@InspectableProperty
@Nullable
public PorterDuff.Mode getThumbTintMode() {
return mThumbTintMode;
BlendMode mode = getThumbTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* @return the blending mode used to apply the tint to the thumb
* drawable
* @attr ref android.R.styleable#Switch_thumbTintMode
* @see #setThumbTintBlendMode(BlendMode)
*/
@InspectableProperty(attributeId = com.android.internal.R.styleable.Switch_thumbTintMode)
@Nullable
public BlendMode getThumbTintBlendMode() {
return mThumbBlendMode;
}
private void applyThumbTint() {
@@ -740,7 +799,7 @@ public class Switch extends CompoundButton {
}
if (mHasThumbTintMode) {
mThumbDrawable.setTintMode(mThumbTintMode);
mThumbDrawable.setTintBlendMode(mThumbBlendMode);
}
// The drawable (or one of its children) may not have been

View File

@@ -55,6 +55,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.BaseCanvas;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Paint;
@@ -489,7 +490,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final Drawable[] mShowing = new Drawable[4];
ColorStateList mTintList;
PorterDuff.Mode mTintMode;
BlendMode mBlendMode;
boolean mHasTint;
boolean mHasTintMode;
@@ -1036,7 +1037,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
Drawable drawableLeft = null, drawableTop = null, drawableRight = null,
drawableBottom = null, drawableStart = null, drawableEnd = null;
ColorStateList drawableTint = null;
PorterDuff.Mode drawableTintMode = null;
BlendMode drawableTintMode = null;
int drawablePadding = 0;
int ellipsize = ELLIPSIZE_NOT_SET;
boolean singleLine = false;
@@ -1139,7 +1140,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
break;
case com.android.internal.R.styleable.TextView_drawableTintMode:
drawableTintMode = Drawable.parseTintMode(a.getInt(attr, -1), drawableTintMode);
drawableTintMode = Drawable.parseBlendMode(a.getInt(attr, -1),
drawableTintMode);
break;
case com.android.internal.R.styleable.TextView_drawablePadding:
@@ -1543,7 +1545,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mDrawables.mHasTint = true;
}
if (drawableTintMode != null) {
mDrawables.mTintMode = drawableTintMode;
mDrawables.mBlendMode = drawableTintMode;
mDrawables.mHasTintMode = true;
}
}
@@ -3299,10 +3301,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @see Drawable#setTintMode(PorterDuff.Mode)
*/
public void setCompoundDrawableTintMode(@Nullable PorterDuff.Mode tintMode) {
setCompoundDrawableTintBlendMode(tintMode != null
? BlendMode.fromValue(tintMode.nativeInt) : null);
}
/**
* Specifies the blending mode used to apply the tint specified by
* {@link #setCompoundDrawableTintList(ColorStateList)} to the compound
* drawables. The default mode is {@link PorterDuff.Mode#SRC_IN}.
*
* @param blendMode the blending mode used to apply the tint, may be
* {@code null} to clear tint
* @attr ref android.R.styleable#TextView_drawableTintMode
* @see #setCompoundDrawableTintList(ColorStateList)
* @see Drawable#setTintBlendMode(BlendMode)
*/
public void setCompoundDrawableTintBlendMode(@Nullable BlendMode blendMode) {
if (mDrawables == null) {
mDrawables = new Drawables(getContext());
}
mDrawables.mTintMode = tintMode;
mDrawables.mBlendMode = blendMode;
mDrawables.mHasTintMode = true;
applyCompoundDrawableTint();
@@ -3316,10 +3334,27 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* drawables
* @attr ref android.R.styleable#TextView_drawableTintMode
* @see #setCompoundDrawableTintMode(PorterDuff.Mode)
*
*/
@InspectableProperty(name = "drawableTintMode")
public PorterDuff.Mode getCompoundDrawableTintMode() {
return mDrawables != null ? mDrawables.mTintMode : null;
BlendMode mode = getCompoundDrawableTintBlendMode();
return mode != null ? BlendMode.blendModeToPorterDuffMode(mode) : null;
}
/**
* Returns the blending mode used to apply the tint to the compound
* drawables, if specified.
*
* @return the blending mode used to apply the tint to the compound
* drawables
* @attr ref android.R.styleable#TextView_drawableTintMode
* @see #setCompoundDrawableTintBlendMode(BlendMode)
*/
@InspectableProperty(name = "drawableBlendMode",
attributeId = com.android.internal.R.styleable.TextView_drawableTintMode)
public @Nullable BlendMode getCompoundDrawableTintBlendMode() {
return mDrawables != null ? mDrawables.mBlendMode : null;
}
private void applyCompoundDrawableTint() {
@@ -3329,7 +3364,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (mDrawables.mHasTint || mDrawables.mHasTintMode) {
final ColorStateList tintList = mDrawables.mTintList;
final PorterDuff.Mode tintMode = mDrawables.mTintMode;
final BlendMode blendMode = mDrawables.mBlendMode;
final boolean hasTint = mDrawables.mHasTint;
final boolean hasTintMode = mDrawables.mHasTintMode;
final int[] state = getDrawableState();
@@ -3353,7 +3388,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
if (hasTintMode) {
dr.setTintMode(tintMode);
dr.setTintBlendMode(blendMode);
}
// The drawable (or one of its children) may not have been