summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt17
-rw-r--r--core/jni/android/graphics/ColorFilter.cpp6
-rw-r--r--graphics/java/android/graphics/ColorFilter.java14
-rw-r--r--graphics/java/android/graphics/ColorMatrix.java43
-rw-r--r--graphics/java/android/graphics/ColorMatrixColorFilter.java90
-rw-r--r--graphics/java/android/graphics/LightingColorFilter.java81
-rw-r--r--graphics/java/android/graphics/PorterDuffColorFilter.java81
-rw-r--r--tests/HwAccelerationTest/AndroidManifest.xml9
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java180
9 files changed, 472 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt
index 4fb2fb9..2d3cc86 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -9100,6 +9100,9 @@ package android.graphics {
public class ColorMatrixColorFilter extends android.graphics.ColorFilter {
ctor public ColorMatrixColorFilter(android.graphics.ColorMatrix);
ctor public ColorMatrixColorFilter(float[]);
+ method public android.graphics.ColorMatrix getColorMatrix();
+ method public void setColorMatrix(android.graphics.ColorMatrix);
+ method public void setColorMatrix(float[]);
}
public class ComposePathEffect extends android.graphics.PathEffect {
@@ -9175,6 +9178,10 @@ package android.graphics {
public class LightingColorFilter extends android.graphics.ColorFilter {
ctor public LightingColorFilter(int, int);
+ method public int getColorAdd();
+ method public int getColorMultiply();
+ method public void setColorAdd(int);
+ method public void setColorMultiply(int);
}
public class LinearGradient extends android.graphics.Shader {
@@ -9649,6 +9656,10 @@ package android.graphics {
public class PorterDuffColorFilter extends android.graphics.ColorFilter {
ctor public PorterDuffColorFilter(int, android.graphics.PorterDuff.Mode);
+ method public int getColor();
+ method public android.graphics.PorterDuff.Mode getMode();
+ method public void setColor(int);
+ method public void setMode(android.graphics.PorterDuff.Mode);
}
public class PorterDuffXfermode extends android.graphics.Xfermode {
@@ -42436,11 +42447,11 @@ package java.util.concurrent {
}
public class ConcurrentHashMap extends java.util.AbstractMap implements java.util.concurrent.ConcurrentMap java.io.Serializable {
- ctor public ConcurrentHashMap(int, float, int);
- ctor public ConcurrentHashMap(int, float);
- ctor public ConcurrentHashMap(int);
ctor public ConcurrentHashMap();
+ ctor public ConcurrentHashMap(int);
ctor public ConcurrentHashMap(java.util.Map<? extends K, ? extends V>);
+ ctor public ConcurrentHashMap(int, float);
+ ctor public ConcurrentHashMap(int, float, int);
method public boolean contains(java.lang.Object);
method public java.util.Enumeration<V> elements();
method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp
index dd1177b..26169e7 100644
--- a/core/jni/android/graphics/ColorFilter.cpp
+++ b/core/jni/android/graphics/ColorFilter.cpp
@@ -33,10 +33,10 @@ using namespace uirenderer;
class SkColorFilterGlue {
public:
static void finalizer(JNIEnv* env, jobject clazz, SkColorFilter* obj, SkiaColorFilter* f) {
- SkSafeUnref(obj);
+ if (obj) SkSafeUnref(obj);
// f == NULL when not !USE_OPENGL_RENDERER, so no need to delete outside the ifdef
#ifdef USE_OPENGL_RENDERER
- if (android::uirenderer::Caches::hasInstance()) {
+ if (f && android::uirenderer::Caches::hasInstance()) {
android::uirenderer::Caches::getInstance().resourceCache.destructor(f);
} else {
delete f;
@@ -112,7 +112,7 @@ public:
};
static JNINativeMethod colorfilter_methods[] = {
- {"finalizer", "(II)V", (void*) SkColorFilterGlue::finalizer}
+ {"destroyFilter", "(II)V", (void*) SkColorFilterGlue::finalizer}
};
static JNINativeMethod porterduff_methods[] = {
diff --git a/graphics/java/android/graphics/ColorFilter.java b/graphics/java/android/graphics/ColorFilter.java
index e5cf830..8e0af77 100644
--- a/graphics/java/android/graphics/ColorFilter.java
+++ b/graphics/java/android/graphics/ColorFilter.java
@@ -21,22 +21,30 @@
package android.graphics;
-
+/**
+ * A color filter can be used with a {@link Paint} to modify the color of
+ * each pixel drawn with that paint. This is an abstract class that should
+ * never be used directly.
+ */
public class ColorFilter {
+ // Holds the pointer to the native SkColorFilter instance
int native_instance;
/**
+ * Holds the pointer to the native SkiaColorFilter instance, from libhwui.
+ *
* @hide
*/
public int nativeColorFilter;
+ @Override
protected void finalize() throws Throwable {
try {
super.finalize();
} finally {
- finalizer(native_instance, nativeColorFilter);
+ destroyFilter(native_instance, nativeColorFilter);
}
}
- private static native void finalizer(int native_instance, int nativeColorFilter);
+ static native void destroyFilter(int native_instance, int nativeColorFilter);
}
diff --git a/graphics/java/android/graphics/ColorMatrix.java b/graphics/java/android/graphics/ColorMatrix.java
index c22cda1..0ef037d 100644
--- a/graphics/java/android/graphics/ColorMatrix.java
+++ b/graphics/java/android/graphics/ColorMatrix.java
@@ -18,23 +18,29 @@ package android.graphics;
import android.util.FloatMath;
+import java.util.Arrays;
+
/**
- * 5x4 matrix for transforming the color+alpha components of a Bitmap.
- * The matrix is stored in a single array, and its treated as follows:
+ * 5x4 matrix for transforming the color+alpha components of a Bitmap.
+ * The matrix is stored in a single array, and its treated as follows:
+ * <pre>
* [ a, b, c, d, e,
* f, g, h, i, j,
* k, l, m, n, o,
* p, q, r, s, t ]
+ * </pre>
*
- * When applied to a color [r, g, b, a], the resulting color is computed as
- * (after clamping)
+ * When applied to a color <code>[r, g, b, a]</code>, the resulting color
+ * is computed as (after clamping):
+ * <pre>
* R' = a*R + b*G + c*B + d*A + e;
* G' = f*R + g*G + h*B + i*A + j;
* B' = k*R + l*G + m*B + n*A + o;
* A' = p*R + q*G + r*B + s*A + t;
+ * </pre>
*/
+@SuppressWarnings({ "MismatchedReadAndWriteOfArray", "PointlessArithmeticExpression" })
public class ColorMatrix {
-
private final float[] mArray = new float[20];
/**
@@ -66,17 +72,16 @@ public class ColorMatrix {
/**
* Set this colormatrix to identity:
+ * <pre>
* [ 1 0 0 0 0 - red vector
* 0 1 0 0 0 - green vector
* 0 0 1 0 0 - blue vector
* 0 0 0 1 0 ] - alpha vector
+ * </pre>
*/
public void reset() {
final float[] a = mArray;
-
- for (int i = 19; i > 0; --i) {
- a[i] = 0;
- }
+ Arrays.fill(a, 0);
a[0] = a[6] = a[12] = a[18] = 1;
}
@@ -112,9 +117,9 @@ public class ColorMatrix {
/**
* Set the rotation on a color axis by the specified values.
- * axis=0 correspond to a rotation around the RED color
- * axis=1 correspond to a rotation around the GREEN color
- * axis=2 correspond to a rotation around the BLUE color
+ * <code>axis=0</code> correspond to a rotation around the RED color
+ * <code>axis=1</code> correspond to a rotation around the GREEN color
+ * <code>axis=2</code> correspond to a rotation around the BLUE color
*/
public void setRotate(int axis, float degrees) {
reset();
@@ -144,7 +149,7 @@ public class ColorMatrix {
throw new RuntimeException();
}
}
-
+
/**
* Set this colormatrix to the concatenation of the two specified
* colormatrices, such that the resulting colormatrix has the same effect
@@ -152,12 +157,10 @@ public class ColorMatrix {
* matB to be the same colormatrix as this.
*/
public void setConcat(ColorMatrix matA, ColorMatrix matB) {
- float[] tmp = null;
-
+ float[] tmp;
if (matA == this || matB == this) {
tmp = new float[20];
- }
- else {
+ } else {
tmp = mArray;
}
@@ -178,7 +181,7 @@ public class ColorMatrix {
System.arraycopy(tmp, 0, mArray, 0, 20);
}
}
-
+
/**
* Concat this colormatrix with the specified prematrix. This is logically
* the same as calling setConcat(this, prematrix);
@@ -186,7 +189,7 @@ public class ColorMatrix {
public void preConcat(ColorMatrix prematrix) {
setConcat(this, prematrix);
}
-
+
/**
* Concat this colormatrix with the specified postmatrix. This is logically
* the same as calling setConcat(postmatrix, this);
@@ -194,7 +197,7 @@ public class ColorMatrix {
public void postConcat(ColorMatrix postmatrix) {
setConcat(postmatrix, this);
}
-
+
///////////////////////////////////////////////////////////////////////////
/**
diff --git a/graphics/java/android/graphics/ColorMatrixColorFilter.java b/graphics/java/android/graphics/ColorMatrixColorFilter.java
index 4f32342..8de32ec 100644
--- a/graphics/java/android/graphics/ColorMatrixColorFilter.java
+++ b/graphics/java/android/graphics/ColorMatrixColorFilter.java
@@ -16,24 +16,31 @@
package android.graphics;
+/**
+ * A color filter that transforms colors through a 4x5 color matrix. This filter
+ * can be used to change the saturation of pixels, convert from YUV to RGB, etc.
+ *
+ * @see ColorMatrix
+ */
public class ColorMatrixColorFilter extends ColorFilter {
+ private final ColorMatrix mMatrix = new ColorMatrix();
+
/**
- * Create a colorfilter that transforms colors through a 4x5 color matrix.
+ * Create a color filter that transforms colors through a 4x5 color matrix.
*
* @param matrix 4x5 matrix used to transform colors. It is copied into
* the filter, so changes made to the matrix after the filter
* is constructed will not be reflected in the filter.
*/
public ColorMatrixColorFilter(ColorMatrix matrix) {
- final float[] colorMatrix = matrix.getArray();
- native_instance = nativeColorMatrixFilter(colorMatrix);
- nativeColorFilter = nColorMatrixFilter(native_instance, colorMatrix);
+ mMatrix.set(matrix);
+ update();
}
/**
- * Create a colorfilter that transforms colors through a 4x5 color matrix.
+ * Create a color filter that transforms colors through a 4x5 color matrix.
*
- * @param array array of floats used to transform colors, treated as a 4x5
+ * @param array Array of floats used to transform colors, treated as a 4x5
* matrix. The first 20 entries of the array are copied into
* the filter. See ColorMatrix.
*/
@@ -41,8 +48,75 @@ public class ColorMatrixColorFilter extends ColorFilter {
if (array.length < 20) {
throw new ArrayIndexOutOfBoundsException();
}
- native_instance = nativeColorMatrixFilter(array);
- nativeColorFilter = nColorMatrixFilter(native_instance, array);
+ mMatrix.set(array);
+ update();
+ }
+
+ /**
+ * Returns the {@link ColorMatrix} used by this filter. The returned
+ * value is never null. Modifying the returned matrix does not have
+ * any effect until you call {@link #setColorMatrix(ColorMatrix)}.
+ *
+ * @see #setColorMatrix(ColorMatrix)
+ */
+ public ColorMatrix getColorMatrix() {
+ return mMatrix;
+ }
+
+ /**
+ * Specifies the color matrix used by this filter. If the specified
+ * color matrix is null, this filter's color matrix will be reset to
+ * the identity matrix.
+ *
+ * @param matrix A {@link ColorMatrix} or null
+ *
+ * @see #getColorMatrix()
+ * @see android.graphics.ColorMatrix#reset()
+ * @see #setColorMatrix(float[])
+ */
+ public void setColorMatrix(ColorMatrix matrix) {
+ if (matrix == null) {
+ mMatrix.reset();
+ } else if (matrix != mMatrix) {
+ mMatrix.set(matrix);
+ }
+ update();
+ }
+
+ /**
+ * Specifies the color matrix used by this filter. If the specified
+ * color matrix is null, this filter's color matrix will be reset to
+ * the identity matrix.
+ *
+ * @param array Array of floats used to transform colors, treated as a 4x5
+ * matrix. The first 20 entries of the array are copied into
+ * the filter. See {@link ColorMatrix}.
+ *
+ * @see #getColorMatrix()
+ * @see android.graphics.ColorMatrix#reset()
+ * @see #setColorMatrix(ColorMatrix)
+ *
+ * @throws ArrayIndexOutOfBoundsException if the specified array's
+ * length is < 20
+ */
+ public void setColorMatrix(float[] array) {
+ if (array == null) {
+ mMatrix.reset();
+ } else {
+ if (array.length < 20) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ mMatrix.set(array);
+ }
+ update();
+ }
+
+ private void update() {
+ final float[] colorMatrix = mMatrix.getArray();
+ destroyFilter(native_instance, nativeColorFilter);
+ native_instance = nativeColorMatrixFilter(colorMatrix);
+ nativeColorFilter = nColorMatrixFilter(native_instance, colorMatrix);
}
private static native int nativeColorMatrixFilter(float[] array);
diff --git a/graphics/java/android/graphics/LightingColorFilter.java b/graphics/java/android/graphics/LightingColorFilter.java
index c621de6..75f1827 100644
--- a/graphics/java/android/graphics/LightingColorFilter.java
+++ b/graphics/java/android/graphics/LightingColorFilter.java
@@ -21,16 +21,87 @@
package android.graphics;
+/**
+ * A color filter that can be used to simulate simple lighting effects.
+ * A <code>LightingColorFilter</code> is defined by two parameters, one
+ * used to multiply the source color (called <code>colorMultiply</code>)
+ * and one used to add to the source color (called <code>colorAdd</code>).
+ * The alpha channel is left untouched by this color filter.
+ *
+ * Given a source color RGB, the resulting R'G'B' color is computed thusly:
+ * <pre>
+ * R' = R * colorMultiply.R + colorAdd.R
+ * G' = G * colorMultiply.G + colorAdd.G
+ * B' = B * colorMultiply.B + colorAdd.B
+ * </pre>
+ * The result is pinned to the <code>[0..255]</code> range for each channel.
+ */
public class LightingColorFilter extends ColorFilter {
+ private int mMul;
+ private int mAdd;
/**
- * Create a colorfilter that multiplies the RGB channels by one color, and then adds a second color,
- * pinning the result for each component to [0..255]. The alpha components of the mul and add arguments
- * are ignored.
+ * Create a colorfilter that multiplies the RGB channels by one color,
+ * and then adds a second color. The alpha components of the mul and add
+ * arguments are ignored.
+ *
+ * @see #setColorMultiply(int)
+ * @see #setColorAdd(int)
*/
public LightingColorFilter(int mul, int add) {
- native_instance = native_CreateLightingFilter(mul, add);
- nativeColorFilter = nCreateLightingFilter(native_instance, mul, add);
+ mMul = mul;
+ mAdd = add;
+ update();
+ }
+
+ /**
+ * Returns the RGB color used to multiply the source color when the
+ * color filter is applied.
+ *
+ * @see #setColorMultiply(int)
+ */
+ public int getColorMultiply() {
+ return mMul;
+ }
+
+ /**
+ * Specifies the RGB color used to multiply the source color when the
+ * color filter is applied.
+ * The alpha channel of this color is ignored.
+ *
+ * @see #getColorMultiply()
+ */
+ public void setColorMultiply(int mul) {
+ mMul = mul;
+ update();
+ }
+
+ /**
+ * Returns the RGB color that will be added to the source color
+ * when the color filter is applied.
+ *
+ * @see #setColorAdd(int)
+ */
+ public int getColorAdd() {
+ return mAdd;
+ }
+
+ /**
+ * Specifies the RGB that will be added to the source color when
+ * the color filter is applied.
+ * The alpha channel of this color is ignored.
+ *
+ * @see #getColorAdd()
+ */
+ public void setColorAdd(int add) {
+ mAdd = add;
+ update();
+ }
+
+ private void update() {
+ destroyFilter(native_instance, nativeColorFilter);
+ native_instance = native_CreateLightingFilter(mMul, mAdd);
+ nativeColorFilter = nCreateLightingFilter(native_instance, mMul, mAdd);
}
private static native int native_CreateLightingFilter(int mul, int add);
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);
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 1bb0db0..6f774f8 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -706,6 +706,15 @@
</activity>
<activity
+ android:name="ColorFiltersMutateActivity"
+ android:label="ColorFilters/Mutate Filters">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
+
+ <activity
android:name="LinesActivity"
android:label="Draw/Lines">
<intent-filter>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
new file mode 100644
index 0000000..808b5d3
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.hwui;
+
+import android.animation.ArgbEvaluator;
+import android.animation.ObjectAnimator;
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.LightingColorFilter;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.os.Bundle;
+import android.view.View;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class ColorFiltersMutateActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ final BitmapsView view = new BitmapsView(this);
+ setContentView(view);
+ }
+
+ static class BitmapsView extends View {
+ private final Bitmap mBitmap1;
+ private final Bitmap mBitmap2;
+ private final Paint mColorMatrixPaint;
+ private final Paint mLightingPaint;
+ private final Paint mBlendPaint;
+
+ private float mSaturation = 0.0f;
+ private int mLightAdd = 0;
+ private int mLightMul = 0;
+ private int mPorterDuffColor = 0;
+
+ BitmapsView(Context c) {
+ super(c);
+
+ mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
+ mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
+
+ mColorMatrixPaint = new Paint();
+ final ColorMatrix colorMatrix = new ColorMatrix();
+ colorMatrix.setSaturation(0);
+ mColorMatrixPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
+
+ mLightingPaint = new Paint();
+ mLightingPaint.setColorFilter(new LightingColorFilter(0, 0));
+
+ mBlendPaint = new Paint();
+ mBlendPaint.setColorFilter(new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_OVER));
+
+ ObjectAnimator sat = ObjectAnimator.ofFloat(this, "saturation", 1.0f);
+ sat.setDuration(1000);
+ sat.setRepeatCount(ObjectAnimator.INFINITE);
+ sat.setRepeatMode(ObjectAnimator.REVERSE);
+ sat.start();
+
+ ObjectAnimator light = ObjectAnimator.ofInt(this, "lightAdd", 0x00101030);
+ light.setEvaluator(new ArgbEvaluator());
+ light.setDuration(1000);
+ light.setRepeatCount(ObjectAnimator.INFINITE);
+ light.setRepeatMode(ObjectAnimator.REVERSE);
+ light.start();
+
+ ObjectAnimator mult = ObjectAnimator.ofInt(this, "lightMul", 0x0060ffff);
+ mult.setEvaluator(new ArgbEvaluator());
+ mult.setDuration(1000);
+ mult.setRepeatCount(ObjectAnimator.INFINITE);
+ mult.setRepeatMode(ObjectAnimator.REVERSE);
+ mult.start();
+
+ ObjectAnimator color = ObjectAnimator.ofInt(this, "porterDuffColor", 0x7f990040);
+ color.setEvaluator(new ArgbEvaluator());
+ color.setDuration(1000);
+ color.setRepeatCount(ObjectAnimator.INFINITE);
+ color.setRepeatMode(ObjectAnimator.REVERSE);
+ color.start();
+ }
+
+ public int getPorterDuffColor() {
+ return mPorterDuffColor;
+ }
+
+ public void setPorterDuffColor(int porterDuffColor) {
+ mPorterDuffColor = porterDuffColor;
+ final PorterDuffColorFilter filter =
+ (PorterDuffColorFilter) mBlendPaint.getColorFilter();
+ filter.setColor(mPorterDuffColor);
+ invalidate();
+ }
+
+ public int getLightAdd() {
+ return mLightAdd;
+ }
+
+ public void setLightAdd(int lightAdd) {
+ mLightAdd = lightAdd;
+ final LightingColorFilter filter =
+ (LightingColorFilter) mLightingPaint.getColorFilter();
+ filter.setColorAdd(lightAdd);
+ invalidate();
+ }
+
+ public int getLightMul() {
+ return mLightAdd;
+ }
+
+ public void setLightMul(int lightMul) {
+ mLightMul = lightMul;
+ final LightingColorFilter filter =
+ (LightingColorFilter) mLightingPaint.getColorFilter();
+ filter.setColorMultiply(lightMul);
+ invalidate();
+ }
+
+ public void setSaturation(float saturation) {
+ mSaturation = saturation;
+ final ColorMatrixColorFilter filter =
+ (ColorMatrixColorFilter) mColorMatrixPaint.getColorFilter();
+ final ColorMatrix m = filter.getColorMatrix();
+ m.setSaturation(saturation);
+ filter.setColorMatrix(m);
+ invalidate();
+ }
+
+ public float getSaturation() {
+ return mSaturation;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ canvas.drawARGB(255, 255, 255, 255);
+
+ canvas.save();
+ canvas.translate(120.0f, 50.0f);
+ canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mColorMatrixPaint);
+
+ canvas.translate(0.0f, 50.0f + mBitmap1.getHeight());
+ canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mLightingPaint);
+
+ canvas.translate(0.0f, 50.0f + mBitmap1.getHeight());
+ canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBlendPaint);
+ canvas.restore();
+
+ canvas.save();
+ canvas.translate(120.0f + mBitmap1.getWidth() + 120.0f, 50.0f);
+ canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, mColorMatrixPaint);
+
+ canvas.translate(0.0f, 50.0f + mBitmap2.getHeight());
+ canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, mLightingPaint);
+
+ canvas.translate(0.0f, 50.0f + mBitmap2.getHeight());
+ canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, mBlendPaint);
+ canvas.restore();
+ }
+ }
+}