diff options
author | Romain Guy <romainguy@google.com> | 2013-08-19 17:42:51 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2013-08-19 18:18:00 -0700 |
commit | 13656743cc21bac43676568314366497346713ee (patch) | |
tree | 38e4547d5669b5d43c6482bb7372b6dab9b334d4 /graphics/java/android/graphics/PorterDuffColorFilter.java | |
parent | 0c5e72127b7c002c9e9e7facf65b9c2e41c99556 (diff) | |
download | frameworks_base-13656743cc21bac43676568314366497346713ee.zip frameworks_base-13656743cc21bac43676568314366497346713ee.tar.gz frameworks_base-13656743cc21bac43676568314366497346713ee.tar.bz2 |
Make color filters mutable
Change-Id: I3d035d24a75e09db13d136a22bd7dbd326d0ce36
Diffstat (limited to 'graphics/java/android/graphics/PorterDuffColorFilter.java')
-rw-r--r-- | graphics/java/android/graphics/PorterDuffColorFilter.java | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/graphics/java/android/graphics/PorterDuffColorFilter.java b/graphics/java/android/graphics/PorterDuffColorFilter.java index ecc7c24..9870ad2 100644 --- a/graphics/java/android/graphics/PorterDuffColorFilter.java +++ b/graphics/java/android/graphics/PorterDuffColorFilter.java @@ -16,17 +16,84 @@ package android.graphics; +/** + * A color filter that can be used to tint the source pixels using a single + * color and a specific {@link PorterDuff Porter-Duff composite mode}. + */ public class PorterDuffColorFilter extends ColorFilter { + private int mColor; + private PorterDuff.Mode mMode; + + /** + * Create a color filter that uses the specified color and Porter-Duff mode. + * + * @param color The ARGB source color used with the specified Porter-Duff mode + * @param mode The porter-duff mode that is applied + * + * @see Color + * @see #setColor(int) + * @see #setMode(android.graphics.PorterDuff.Mode) + */ + public PorterDuffColorFilter(int color, PorterDuff.Mode mode) { + mColor = color; + mMode = mode; + update(); + } + + /** + * Returns the ARGB color used to tint the source pixels when this filter + * is applied. + * + * @see Color + * @see #setColor(int) + */ + public int getColor() { + return mColor; + } + /** - * Create a colorfilter that uses the specified color and porter-duff mode. + * Specifies the color to tint the source pixels with when this color + * filter is applied. * - * @param srcColor The source color used with the specified - * porter-duff mode - * @param mode The porter-duff mode that is applied + * @param color An ARGB {@link Color color} + * + * @see Color + * @see #getColor() + * @see #getMode() */ - public PorterDuffColorFilter(int srcColor, PorterDuff.Mode mode) { - native_instance = native_CreatePorterDuffFilter(srcColor, mode.nativeInt); - nativeColorFilter = nCreatePorterDuffFilter(native_instance, srcColor, mode.nativeInt); + public void setColor(int color) { + mColor = color; + update(); + } + + /** + * Returns the Porter-Duff mode used to composite this color filter's + * color with the source pixel when this filter is applied. + * + * @see PorterDuff + * @see #setMode(android.graphics.PorterDuff.Mode) + */ + public PorterDuff.Mode getMode() { + return mMode; + } + + /** + * Specifies the Porter-Duff mode to use when compositing this color + * filter's color with the source pixel at draw time. + * + * @see PorterDuff + * @see #getMode() + * @see #getColor() + */ + public void setMode(PorterDuff.Mode mode) { + mMode = mode; + update(); + } + + private void update() { + destroyFilter(native_instance, nativeColorFilter); + native_instance = native_CreatePorterDuffFilter(mColor, mMode.nativeInt); + nativeColorFilter = nCreatePorterDuffFilter(native_instance, mColor, mMode.nativeInt); } private static native int native_CreatePorterDuffFilter(int srcColor, int porterDuffMode); |