summaryrefslogtreecommitdiff
path: root/core/java/android/widget/CheckedTextView.java
diff options
context:
space:
mode:
authorNader Jawad <njawad@google.com>2019-04-14 21:58:04 -0700
committerNader Jawad <njawad@google.com>2019-04-15 17:01:56 -0700
commit8e31c3ef143f391b2360fd8f16ea68af9151d122 (patch)
treed252378c33820cffc870ffbdd0116648d91ae376 /core/java/android/widget/CheckedTextView.java
parentb9a4f633390ec9ed51296c74887ee08b0056eff8 (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
Diffstat (limited to 'core/java/android/widget/CheckedTextView.java')
-rw-r--r--core/java/android/widget/CheckedTextView.java46
1 files changed, 40 insertions, 6 deletions
diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java
index a211b4686f4c..8b70f41f050c 100644
--- a/core/java/android/widget/CheckedTextView.java
+++ b/core/java/android/widget/CheckedTextView.java
@@ -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