diff options
| author | Rahul Ravikumar <rahulrav@google.com> | 2019-02-06 13:25:04 -0800 |
|---|---|---|
| committer | Rahul Ravikumar <rahulrav@google.com> | 2019-02-06 14:15:13 -0800 |
| commit | 7ab5459af98bae3af7138598b4bf54c3e8844f87 (patch) | |
| tree | 1d2d311cd4f1b7f93433112b54a2e68a1b07d022 /core/java/android/widget/EdgeEffect.java | |
| parent | adafb1b44e385db4c90520e17936cfa5ddda05e0 (diff) | |
Add a EdgeEffect#setBlendMode API.
* Fixes hidden api usage b/123769450
* Move from setXferMode() to setBlendMode in Paint.
Fixes: b/123769450
Test: Added CTS Tests.
Change-Id: I1f950e4c14d30dd223cce05835b230c086755089
Diffstat (limited to 'core/java/android/widget/EdgeEffect.java')
| -rw-r--r-- | core/java/android/widget/EdgeEffect.java | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index 7e42862558e4..fa0af78694ab 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -17,14 +17,15 @@ package android.widget; import android.annotation.ColorInt; +import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Paint; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffXfermode; import android.graphics.Rect; +import android.os.Build; import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; @@ -48,6 +49,12 @@ import android.view.animation.Interpolator; * {@link #draw(Canvas)} method.</p> */ public class EdgeEffect { + + /** + * The default blend mode used by {@link EdgeEffect}. + */ + public static final BlendMode DEFAULT_BLEND_MODE = BlendMode.SRC_ATOP; + @SuppressWarnings("UnusedDeclaration") private static final String TAG = "EdgeEffect"; @@ -108,7 +115,7 @@ public class EdgeEffect { private float mPullDistance; private final Rect mBounds = new Rect(); - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769450) private final Paint mPaint = new Paint(); private float mRadius; private float mBaseGlowScale; @@ -128,7 +135,7 @@ public class EdgeEffect { a.recycle(); mPaint.setColor((themeColor & 0xffffff) | 0x33000000); mPaint.setStyle(Paint.Style.FILL); - mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); + mPaint.setBlendMode(DEFAULT_BLEND_MODE); mInterpolator = new DecelerateInterpolator(); } @@ -302,6 +309,22 @@ public class EdgeEffect { } /** + * Set or clear the blend mode. A blend mode defines how source pixels + * (generated by a drawing command) are composited with the destination pixels + * (content of the render target). + * <p /> + * Pass null to clear any previous blend mode. + * <p /> + * + * @see BlendMode + * + * @param blendmode May be null. The blend mode to be installed in the paint + */ + public void setBlendMode(@Nullable BlendMode blendmode) { + mPaint.setBlendMode(blendmode); + } + + /** * Return the color of this edge effect in argb. * @return The color of this edge effect in argb */ @@ -310,6 +333,20 @@ public class EdgeEffect { return mPaint.getColor(); } + + /** + * Returns the blend mode. A blend mode defines how source pixels + * (generated by a drawing command) are composited with the destination pixels + * (content of the render target). + * <p /> + * + * @return BlendMode + */ + @Nullable + public BlendMode getBlendMode() { + return mPaint.getBlendMode(); + } + /** * Draw into the provided canvas. Assumes that the canvas has been rotated * accordingly and the size has been set. The effect will be drawn the full |
