summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java19
-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/ImageFormat.java6
-rw-r--r--graphics/java/android/graphics/LightingColorFilter.java81
-rw-r--r--graphics/java/android/graphics/PorterDuffColorFilter.java81
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java3
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java179
-rw-r--r--graphics/java/android/renderscript/Allocation.java26
-rw-r--r--graphics/java/android/renderscript/Type.java75
11 files changed, 526 insertions, 91 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index 429be49..b714fab 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -300,17 +300,22 @@ public class BitmapFactory {
public boolean inPreferQualityOverSpeed;
/**
- * The resulting width of the bitmap, set independent of the state of
- * inJustDecodeBounds. However, if there is an error trying to decode,
- * outWidth will be set to -1.
+ * The resulting width of the bitmap. If {@link #inJustDecodeBounds} is
+ * set to false, this will be width of the output bitmap after any
+ * scaling is applied. If true, it will be the width of the input image
+ * without any accounting for scaling.
+ *
+ * <p>outWidth will be set to -1 if there is an error trying to decode.</p>
*/
-
public int outWidth;
/**
- * The resulting height of the bitmap, set independent of the state of
- * inJustDecodeBounds. However, if there is an error trying to decode,
- * outHeight will be set to -1.
+ * The resulting height of the bitmap. If {@link #inJustDecodeBounds} is
+ * set to false, this will be height of the output bitmap after any
+ * scaling is applied. If true, it will be the height of the input image
+ * without any accounting for scaling.
+ *
+ * <p>outHeight will be set to -1 if there is an error trying to decode.</p>
*/
public int outHeight;
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/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java
index 1bcfc18..e08ed50 100644
--- a/graphics/java/android/graphics/ImageFormat.java
+++ b/graphics/java/android/graphics/ImageFormat.java
@@ -187,6 +187,10 @@ public class ImageFormat {
* == {@link android.media.Image.Plane#getPixelStride() vPlane.getPixelStride()};
* ).</p>
*
+ * <p>For example, the {@link android.media.Image} object can provide data
+ * in this format from a {@link android.hardware.camera2.CameraDevice}
+ * through a {@link android.media.ImageReader} object.</p>
+ *
* @see android.media.Image
* @see android.media.ImageReader
* @see android.hardware.camera2.CameraDevice
@@ -203,8 +207,6 @@ public class ImageFormat {
* needed information to interpret a raw sensor image must be queried from
* the {@link android.hardware.camera2.CameraDevice} which produced the
* image.</p>
- *
- * @hide
*/
public static final int RAW_SENSOR = 0x20;
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/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 93738b0..c84cdb0 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -39,6 +39,7 @@ import android.util.DisplayMetrics;
import android.util.StateSet;
import android.util.TypedValue;
import android.util.Xml;
+import android.view.View;
import java.io.IOException;
import java.io.InputStream;
@@ -399,7 +400,7 @@ public abstract class Drawable {
*
* @hide
*/
- public void setLayoutDirection(int layoutDirection) {
+ public void setLayoutDirection(@View.ResolvedLayoutDir int layoutDirection) {
if (getLayoutDirection() != layoutDirection) {
mLayoutDirection = layoutDirection;
}
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index b340777..e51dfbc 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -16,6 +16,7 @@
package android.graphics.drawable;
+import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -24,12 +25,12 @@ import android.graphics.ColorFilter;
import android.graphics.DashPathEffect;
import android.graphics.LinearGradient;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.PixelFormat;
+import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
-import android.graphics.Path;
-import android.graphics.RadialGradient;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import android.util.Log;
@@ -233,6 +234,23 @@ public class GradientDrawable extends Drawable {
}
/**
+ * <p>Set the stroke width and color state list for the drawable. If width
+ * is zero, then no stroke is drawn.</p>
+ * <p><strong>Note</strong>: changing this property will affect all instances
+ * of a drawable loaded from a resource. It is recommended to invoke
+ * {@link #mutate()} before changing this property.</p>
+ *
+ * @param width The width in pixels of the stroke
+ * @param colorStateList The color state list of the stroke
+ *
+ * @see #mutate()
+ * @see #setStroke(int, ColorStateList, float, float)
+ */
+ public void setStroke(int width, ColorStateList colorStateList) {
+ setStroke(width, colorStateList, 0, 0);
+ }
+
+ /**
* <p>Set the stroke width and color for the drawable. If width is zero,
* then no stroke is drawn. This method can also be used to dash the stroke.</p>
* <p><strong>Note</strong>: changing this property will affect all instances
@@ -249,7 +267,35 @@ public class GradientDrawable extends Drawable {
*/
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mGradientState.setStroke(width, color, dashWidth, dashGap);
+ setStrokeInternal(width, color, dashWidth, dashGap);
+ }
+ /**
+ * <p>Set the stroke width and color state list for the drawable. If width
+ * is zero, then no stroke is drawn. This method can also be used to dash
+ * the stroke.</p>
+ * <p><strong>Note</strong>: changing this property will affect all instances
+ * of a drawable loaded from a resource. It is recommended to invoke
+ * {@link #mutate()} before changing this property.</p>
+ *
+ * @param width The width in pixels of the stroke
+ * @param colorStateList The color state list of the stroke
+ * @param dashWidth The length in pixels of the dashes, set to 0 to disable dashes
+ * @param dashGap The gap in pixels between dashes
+ *
+ * @see #mutate()
+ * @see #setStroke(int, ColorStateList)
+ */
+ public void setStroke(
+ int width, ColorStateList colorStateList, float dashWidth, float dashGap) {
+ mGradientState.setStroke(width, colorStateList, dashWidth, dashGap);
+
+ final int[] stateSet = getState();
+ final int color = colorStateList.getColorForState(stateSet, 0);
+ setStrokeInternal(width, color, dashWidth, dashGap);
+ }
+
+ private void setStrokeInternal(int width, int color, float dashWidth, float dashGap) {
if (mStrokePaint == null) {
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setStyle(Paint.Style.STROKE);
@@ -479,7 +525,8 @@ public class GradientDrawable extends Drawable {
mFillPaint.setAlpha(currFillAlpha);
mFillPaint.setDither(mDither);
mFillPaint.setColorFilter(mColorFilter);
- if (mColorFilter != null && !mGradientState.mHasSolidColor) {
+ if (mColorFilter != null && !mGradientState.mHasSolidColor
+ && mGradientState.mColorStateList == null) {
mFillPaint.setColor(mAlpha << 24);
}
if (haveStroke) {
@@ -610,7 +657,7 @@ public class GradientDrawable extends Drawable {
}
/**
- * <p>Changes this drawbale to use a single color instead of a gradient.</p>
+ * <p>Changes this drawable to use a single color instead of a gradient.</p>
* <p><strong>Note</strong>: changing color will affect all instances
* of a drawable loaded from a resource. It is recommended to invoke
* {@link #mutate()} before changing the color.</p>
@@ -626,6 +673,65 @@ public class GradientDrawable extends Drawable {
invalidateSelf();
}
+ /**
+ * Changes this drawable to use a single color state list instead of a
+ * gradient.
+ * <p>
+ * <strong>Note</strong>: changing color will affect all instances of a
+ * drawable loaded from a resource. It is recommended to invoke
+ * {@link #mutate()} before changing the color.</p>
+ *
+ * @param colorStateList The color state list used to fill the shape
+ * @see #mutate()
+ */
+ public void setColor(ColorStateList colorStateList) {
+ final int color = colorStateList.getColorForState(getState(), 0);
+ mGradientState.setColorStateList(colorStateList);
+ mFillPaint.setColor(color);
+ invalidateSelf();
+ }
+
+ @Override
+ public boolean onStateChange(int[] stateSet) {
+ boolean invalidateSelf = false;
+
+ final GradientState s = mGradientState;
+ final ColorStateList stateList = s.mColorStateList;
+ if (stateList != null) {
+ final int newColor = stateList.getColorForState(stateSet, 0);
+ final int oldColor = mFillPaint.getColor();
+ if (oldColor != newColor) {
+ mFillPaint.setColor(newColor);
+ invalidateSelf |= true;
+ }
+ }
+
+ final ColorStateList strokeStateList = s.mStrokeColorStateList;
+ if (strokeStateList != null) {
+ final int newColor = stateList.getColorForState(stateSet, 0);
+ final int oldColor = mStrokePaint.getColor();
+ if (oldColor != newColor) {
+ mStrokePaint.setColor(newColor);
+ invalidateSelf |= true;
+ }
+ }
+
+ if (invalidateSelf) {
+ invalidateSelf();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean isStateful() {
+ final GradientState s = mGradientState;
+ return super.isStateful()
+ || (s.mColorStateList != null && s.mColorStateList.isStateful())
+ || (s.mStrokeColorStateList != null && s.mStrokeColorStateList.isStateful());
+ }
+
@Override
public int getChangingConfigurations() {
return super.getChangingConfigurations() | mGradientState.mChangingConfigurations;
@@ -791,7 +897,7 @@ public class GradientDrawable extends Drawable {
// If we don't have a solid color, the alpha channel must be
// maxed out so that alpha modulation works correctly.
- if (!st.mHasSolidColor) {
+ if (!st.mHasSolidColor && st.mColorStateList == null) {
mFillPaint.setColor(Color.BLACK);
}
}
@@ -967,25 +1073,25 @@ public class GradientDrawable extends Drawable {
} else if (name.equals("solid")) {
a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.GradientDrawableSolid);
- int argb = a.getColor(
- com.android.internal.R.styleable.GradientDrawableSolid_color, 0);
+ final ColorStateList colorStateList = a.getColorStateList(
+ com.android.internal.R.styleable.GradientDrawableSolid_color);
a.recycle();
- setColor(argb);
+ setColor(colorStateList);
} else if (name.equals("stroke")) {
a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.GradientDrawableStroke);
- int width = a.getDimensionPixelSize(
+ final int width = a.getDimensionPixelSize(
com.android.internal.R.styleable.GradientDrawableStroke_width, 0);
- int color = a.getColor(
- com.android.internal.R.styleable.GradientDrawableStroke_color, 0);
- float dashWidth = a.getDimension(
+ final ColorStateList colorStateList = a.getColorStateList(
+ com.android.internal.R.styleable.GradientDrawableStroke_color);
+ final float dashWidth = a.getDimension(
com.android.internal.R.styleable.GradientDrawableStroke_dashWidth, 0);
if (dashWidth != 0.0f) {
- float dashGap = a.getDimension(
+ final float dashGap = a.getDimension(
com.android.internal.R.styleable.GradientDrawableStroke_dashGap, 0);
- setStroke(width, color, dashWidth, dashGap);
+ setStroke(width, colorStateList, dashWidth, dashGap);
} else {
- setStroke(width, color);
+ setStroke(width, colorStateList);
}
a.recycle();
} else if (name.equals("corners")) {
@@ -1077,6 +1183,8 @@ public class GradientDrawable extends Drawable {
public int mShape = RECTANGLE;
public int mGradient = LINEAR_GRADIENT;
public Orientation mOrientation;
+ public ColorStateList mColorStateList;
+ public ColorStateList mStrokeColorStateList;
public int[] mColors;
public int[] mTempColors; // no need to copy
public float[] mTempPositions; // no need to copy
@@ -1113,6 +1221,7 @@ public class GradientDrawable extends Drawable {
mShape = state.mShape;
mGradient = state.mGradient;
mOrientation = state.mOrientation;
+ mColorStateList = state.mColorStateList;
if (state.mColors != null) {
mColors = state.mColors.clone();
}
@@ -1178,6 +1287,7 @@ public class GradientDrawable extends Drawable {
public void setColors(int[] colors) {
mHasSolidColor = false;
mColors = colors;
+ mColorStateList = null;
computeOpacity();
}
@@ -1185,6 +1295,14 @@ public class GradientDrawable extends Drawable {
mHasSolidColor = true;
mSolidColor = argb;
mColors = null;
+ mColorStateList = null;
+ computeOpacity();
+ }
+
+ public void setColorStateList(ColorStateList colorStateList) {
+ mHasSolidColor = false;
+ mColors = null;
+ mColorStateList = colorStateList;
computeOpacity();
}
@@ -1199,11 +1317,23 @@ public class GradientDrawable extends Drawable {
return;
}
- if (mStrokeWidth > 0 && !isOpaque(mStrokeColor)) {
+ if (mStrokeWidth > 0) {
+ if (mStrokeColorStateList != null) {
+ if (!mStrokeColorStateList.isOpaque()) {
+ mOpaque = false;
+ return;
+ }
+ } else if (!isOpaque(mStrokeColor)) {
+ mOpaque = false;
+ return;
+ }
+ }
+
+ if (mColorStateList != null && !mColorStateList.isOpaque()) {
mOpaque = false;
return;
}
-
+
if (mHasSolidColor) {
mOpaque = isOpaque(mSolidColor);
return;
@@ -1228,12 +1358,23 @@ public class GradientDrawable extends Drawable {
public void setStroke(int width, int color) {
mStrokeWidth = width;
mStrokeColor = color;
+ mStrokeColorStateList = null;
computeOpacity();
}
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mStrokeWidth = width;
mStrokeColor = color;
+ mStrokeColorStateList = null;
+ mStrokeDashWidth = dashWidth;
+ mStrokeDashGap = dashGap;
+ computeOpacity();
+ }
+
+ public void setStroke(
+ int width, ColorStateList colorStateList, float dashWidth, float dashGap) {
+ mStrokeWidth = width;
+ mStrokeColorStateList = colorStateList;
mStrokeDashWidth = dashWidth;
mStrokeDashGap = dashGap;
computeOpacity();
@@ -1274,6 +1415,10 @@ public class GradientDrawable extends Drawable {
private void initializeWithState(GradientState state) {
if (state.mHasSolidColor) {
mFillPaint.setColor(state.mSolidColor);
+ } else if (state.mColorStateList != null) {
+ final int[] currentState = getState();
+ final int stateColor = state.mColorStateList.getColorForState(currentState, 0);
+ mFillPaint.setColor(stateColor);
} else if (state.mColors == null) {
// If we don't have a solid color and we don't have a gradient,
// the app is stroking the shape, set the color to the default
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index dca934f..bb1e743 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -24,7 +24,6 @@ import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Surface;
-import android.graphics.SurfaceTexture;
import android.util.Log;
import android.util.TypedValue;
import android.graphics.Canvas;
@@ -127,17 +126,17 @@ public class Allocation extends BaseObj {
public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010;
/**
- * The Allocation will be used as a {@link android.graphics.SurfaceTexture}
- * consumer. This usage will cause the Allocation to be created as
- * read-only.
+ * The Allocation will be used as a {@link android.view.Surface}
+ * consumer. This usage will cause the Allocation to be created
+ * as read-only.
*
*/
public static final int USAGE_IO_INPUT = 0x0020;
/**
- * The Allocation will be used as a {@link android.graphics.SurfaceTexture}
+ * The Allocation will be used as a {@link android.view.Surface}
* producer. The dimensions and format of the {@link
- * android.graphics.SurfaceTexture} will be forced to those of the
+ * android.view.Surface} will be forced to those of the
* Allocation.
*
*/
@@ -412,14 +411,6 @@ public class Allocation extends BaseObj {
}
/**
- * Delete once code is updated.
- * @hide
- */
- public void ioSendOutput() {
- ioSend();
- }
-
- /**
* Receive the latest input into the Allocation. This operation
* is only valid if {@link #USAGE_IO_INPUT} is set on the Allocation.
*
@@ -1547,13 +1538,6 @@ public class Allocation extends BaseObj {
}
/**
- * @hide
- */
- public void setSurfaceTexture(SurfaceTexture st) {
- setSurface(new Surface(st));
- }
-
- /**
* Associate a {@link android.view.Surface} with this Allocation. This
* operation is only valid for Allocations with {@link #USAGE_IO_OUTPUT}.
*
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index e023739..db4b577 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -216,6 +216,81 @@ public class Type extends BaseObj {
}
/**
+ * Utility function for creating basic 1D types. The type is
+ * created without mipmaps enabled.
+ *
+ * @param rs The RenderScript context
+ * @param e The Element for the Type
+ * @param dimX The X dimension, must be > 0
+ *
+ * @return Type
+ */
+ static public Type createX(RenderScript rs, Element e, int dimX) {
+ if (dimX < 1) {
+ throw new RSInvalidStateException("Dimension must be >= 1.");
+ }
+
+ int id = rs.nTypeCreate(e.getID(rs), dimX, 0, 0, false, false, 0);
+ Type t = new Type(id, rs);
+ t.mElement = e;
+ t.mDimX = dimX;
+ t.calcElementCount();
+ return t;
+ }
+
+ /**
+ * Utility function for creating basic 2D types. The type is
+ * created without mipmaps or cubemaps.
+ *
+ * @param rs The RenderScript context
+ * @param e The Element for the Type
+ * @param dimX The X dimension, must be > 0
+ * @param dimY The Y dimension, must be > 0
+ *
+ * @return Type
+ */
+ static public Type createXY(RenderScript rs, Element e, int dimX, int dimY) {
+ if ((dimX < 1) || (dimY < 1)) {
+ throw new RSInvalidStateException("Dimension must be >= 1.");
+ }
+
+ int id = rs.nTypeCreate(e.getID(rs), dimX, dimY, 0, false, false, 0);
+ Type t = new Type(id, rs);
+ t.mElement = e;
+ t.mDimX = dimX;
+ t.mDimY = dimY;
+ t.calcElementCount();
+ return t;
+ }
+
+ /**
+ * Utility function for creating basic 3D types. The type is
+ * created without mipmaps.
+ *
+ * @param rs The RenderScript context
+ * @param e The Element for the Type
+ * @param dimX The X dimension, must be > 0
+ * @param dimY The Y dimension, must be > 0
+ * @param dimZ The Z dimension, must be > 0
+ *
+ * @return Type
+ */
+ static public Type createXYZ(RenderScript rs, Element e, int dimX, int dimY, int dimZ) {
+ if ((dimX < 1) || (dimY < 1) || (dimZ < 1)) {
+ throw new RSInvalidStateException("Dimension must be >= 1.");
+ }
+
+ int id = rs.nTypeCreate(e.getID(rs), dimX, dimY, dimZ, false, false, 0);
+ Type t = new Type(id, rs);
+ t.mElement = e;
+ t.mDimX = dimX;
+ t.mDimY = dimY;
+ t.mDimZ = dimZ;
+ t.calcElementCount();
+ return t;
+ }
+
+ /**
* Builder class for Type.
*
*/