summaryrefslogtreecommitdiff
path: root/core/java/android/widget/ImageView.java
diff options
context:
space:
mode:
authorNader Jawad <njawad@google.com>2019-04-14 21:58:04 -0700
committerAurimas Liutikas <aurimas@google.com>2019-04-17 21:11:39 +0000
commit531db61ac1671745d81caaead9bf41e01baecc78 (patch)
treef4eaa1854e7ff6c5facf6ebb5856b372d94a1d30 /core/java/android/widget/ImageView.java
parenta8853fe2829fab3deb3a8cf7fcf8a0dcaed4b4c8 (diff)
Added BlendMode equivalent APIs to replace deprecated PorterDuff
variants Updated various framework Views to have equivalent BlendMode APIs to replace the deprecated PorterDuff equivalents. Updated InspectableProperty annotations to refer to the same xml attributes as the original tintmode APIs Bug: 126726419 Test: Added CTS tests to verify new BlendMode APIs Change-Id: Id9ab36d3d4d29f351250723e9d13d49bc6062c83 Merged-In: Id9ab36d3d4d29f351250723e9d13d49bc6062c83
Diffstat (limited to 'core/java/android/widget/ImageView.java')
-rw-r--r--core/java/android/widget/ImageView.java55
1 files changed, 42 insertions, 13 deletions
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 9ae62ef8ab7a..be5d2211c670 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -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