diff options
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/LinearGradient.java | 8 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Rect.java | 22 | ||||
| -rw-r--r-- | graphics/java/android/graphics/RectF.java | 18 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/GradientDrawable.java | 209 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 1 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 2 |
6 files changed, 227 insertions, 33 deletions
diff --git a/graphics/java/android/graphics/LinearGradient.java b/graphics/java/android/graphics/LinearGradient.java index 82ed199..96a71e3 100644 --- a/graphics/java/android/graphics/LinearGradient.java +++ b/graphics/java/android/graphics/LinearGradient.java @@ -28,8 +28,8 @@ public class LinearGradient extends Shader { the the colors are distributed evenly along the gradient line. @param tile The Shader tiling mode */ - public LinearGradient(float x0, float y0, float x1, float y1, - int colors[], float positions[], TileMode tile) { + public LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[], + TileMode tile) { if (colors.length < 2) { throw new IllegalArgumentException("needs >= 2 number of colors"); } @@ -50,8 +50,8 @@ public class LinearGradient extends Shader { @param color1 The color at the end of the gradient line. @param tile The Shader tiling mode */ - public LinearGradient(float x0, float y0, float x1, float y1, - int color0, int color1, TileMode tile) { + public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, + TileMode tile) { native_instance = nativeCreate2(x0, y0, x1, y1, color0, color1, tile.nativeInt); native_shader = nativePostCreate2(native_instance, x0, y0, x1, y1, color0, color1, tile.nativeInt); diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java index 7830224..0ada1fb 100644 --- a/graphics/java/android/graphics/Rect.java +++ b/graphics/java/android/graphics/Rect.java @@ -76,13 +76,21 @@ public final class Rect implements Parcelable { } @Override - public boolean equals(Object obj) { - Rect r = (Rect) obj; - if (r != null) { - return left == r.left && top == r.top && right == r.right - && bottom == r.bottom; - } - return false; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Rect r = (Rect) o; + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } + + @Override + public int hashCode() { + int result = left; + result = 31 * result + top; + result = 31 * result + right; + result = 31 * result + bottom; + return result; } @Override diff --git a/graphics/java/android/graphics/RectF.java b/graphics/java/android/graphics/RectF.java index 00e9609..293dfcc 100644 --- a/graphics/java/android/graphics/RectF.java +++ b/graphics/java/android/graphics/RectF.java @@ -79,6 +79,24 @@ public class RectF implements Parcelable { bottom = r.bottom; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Rect r = (Rect) o; + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } + + @Override + public int hashCode() { + int result = (left != +0.0f ? Float.floatToIntBits(left) : 0); + result = 31 * result + (top != +0.0f ? Float.floatToIntBits(top) : 0); + result = 31 * result + (right != +0.0f ? Float.floatToIntBits(right) : 0); + result = 31 * result + (bottom != +0.0f ? Float.floatToIntBits(bottom) : 0); + return result; + } + public String toString() { return "RectF(" + left + ", " + top + ", " + right + ", " + bottom + ")"; diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 50964d5..5b50beb 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -173,9 +173,20 @@ public class GradientDrawable extends Drawable { } /** - * Specify radii for each of the 4 corners. For each corner, the array - * contains 2 values, [X_radius, Y_radius]. The corners are ordered - * top-left, top-right, bottom-right, bottom-left + * <p>Specify radii for each of the 4 corners. For each corner, the array + * contains 2 values, <code>[X_radius, Y_radius]</code>. The corners are ordered + * top-left, top-right, bottom-right, bottom-left. This property + * is honored only when the shape is of type {@link #RECTANGLE}.</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 radii 4 pairs of X and Y radius for each corner, specified in pixels. + * The length of this array must be >= 8 + * + * @see #mutate() + * @see #setCornerRadii(float[]) + * @see #setShape(int) */ public void setCornerRadii(float[] radii) { mGradientState.setCornerRadii(radii); @@ -184,23 +195,57 @@ public class GradientDrawable extends Drawable { } /** - * Specify radius for the corners of the gradient. If this is > 0, then the - * drawable is drawn in a round-rectangle, rather than a rectangle. + * <p>Specify radius for the corners of the gradient. If this is > 0, then the + * drawable is drawn in a round-rectangle, rather than a rectangle. This property + * is honored only when the shape is of type {@link #RECTANGLE}.</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 radius The radius in pixels of the corners of the rectangle shape + * + * @see #mutate() + * @see #setCornerRadii(float[]) + * @see #setShape(int) */ public void setCornerRadius(float radius) { mGradientState.setCornerRadius(radius); mPathIsDirty = true; invalidateSelf(); } - + /** - * Set the stroke width and color for the drawable. If width is zero, - * then no stroke is drawn. + * <p>Set the stroke width and color 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 color The color of the stroke + * + * @see #mutate() + * @see #setStroke(int, int, float, float) */ public void setStroke(int width, int color) { setStroke(width, color, 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 + * 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 color The color 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, int) + */ public void setStroke(int width, int color, float dashWidth, float dashGap) { mGradientState.setStroke(width, color, dashWidth, dashGap); @@ -218,13 +263,37 @@ public class GradientDrawable extends Drawable { mStrokePaint.setPathEffect(e); invalidateSelf(); } - + + + /** + * <p>Sets the size of the shape drawn by this drawable.</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 of the shape used by this drawable + * @param height The height of the shape used by this drawable + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setSize(int width, int height) { mGradientState.setSize(width, height); mPathIsDirty = true; invalidateSelf(); } - + + /** + * <p>Sets the type of shape used to draw the gradient.</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 shape The desired shape for this drawable: {@link #LINE}, + * {@link #OVAL}, {@link #RECTANGLE} or {@link #RING} + * + * @see #mutate() + */ public void setShape(int shape) { mRingPath = null; mPathIsDirty = true; @@ -232,24 +301,73 @@ public class GradientDrawable extends Drawable { invalidateSelf(); } + /** + * <p>Sets the type of gradient used by this drawable..</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 gradient The type of the gradient: {@link #LINEAR_GRADIENT}, + * {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT} + * + * @see #mutate() + */ public void setGradientType(int gradient) { mGradientState.setGradientType(gradient); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets the center location of the gradient. The radius is honored only when + * the gradient type is set to {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT}.</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 x The x coordinate of the gradient's center + * @param y The y coordinate of the gradient's center + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setGradientCenter(float x, float y) { mGradientState.setGradientCenter(x, y); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets the radius of the gradient. The radius is honored only when the + * gradient type is set to {@link #RADIAL_GRADIENT}.</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 gradientRadius The radius of the gradient in pixels + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setGradientRadius(float gradientRadius) { mGradientState.setGradientRadius(gradientRadius); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets whether or not this drawable will honor its <code>level</code> + * property.</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 useLevel True if this drawable should honor its level, false otherwise + * + * @see #mutate() + * @see #setLevel(int) + * @see #getLevel() + */ public void setUseLevel(boolean useLevel) { mGradientState.mUseLevel = useLevel; mRectIsDirty = true; @@ -261,6 +379,47 @@ public class GradientDrawable extends Drawable { return alpha * scale >> 8; } + /** + * Returns the orientation of the gradient defined in this drawable. + */ + public Orientation getOrientation() { + return mGradientState.mOrientation; + } + + /** + * <p>Changes the orientation of the gradient defined in this drawable.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param orientation The desired orientation (angle) of the gradient + * + * @see #mutate() + */ + public void setOrientation(Orientation orientation) { + mGradientState.mOrientation = orientation; + mRectIsDirty = true; + invalidateSelf(); + } + + /** + * <p>Sets the colors used to draw the gradient. Each color is specified as an + * ARGB integer and the array must contain at least 2 colors.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param colors 2 or more ARGB colors + * + * @see #mutate() + * @see #setColor(int) + */ + public void setColors(int[] colors) { + mGradientState.setColors(colors); + mRectIsDirty = true; + invalidateSelf(); + } + @Override public void draw(Canvas canvas) { if (!ensureValidRect()) { @@ -442,6 +601,17 @@ public class GradientDrawable extends Drawable { return ringPath; } + /** + * <p>Changes this drawbale to use a single color instead of a gradient.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param argb The color used to fill the shape + * + * @see #mutate() + * @see #setColors(int[]) + */ public void setColor(int argb) { mGradientState.setSolidColor(argb); mFillPaint.setColor(argb); @@ -450,10 +620,9 @@ public class GradientDrawable extends Drawable { @Override public int getChangingConfigurations() { - return super.getChangingConfigurations() - | mGradientState.mChangingConfigurations; + return super.getChangingConfigurations() | mGradientState.mChangingConfigurations; } - + @Override public void setAlpha(int alpha) { if (alpha != mAlpha) { @@ -480,7 +649,6 @@ public class GradientDrawable extends Drawable { @Override public int getOpacity() { - // XXX need to figure out the actual opacity... return PixelFormat.TRANSLUCENT; } @@ -911,11 +1079,6 @@ public class GradientDrawable extends Drawable { private float mGradientRadius = 0.5f; private boolean mUseLevel; private boolean mUseLevelForShape; - - - GradientState() { - mOrientation = Orientation.TOP_BOTTOM; - } GradientState(Orientation orientation, int[] colors) { mOrientation = orientation; @@ -987,6 +1150,11 @@ public class GradientDrawable extends Drawable { mCenterY = y; } + public void setColors(int[] colors) { + mHasSolidColor = false; + mColors = colors; + } + public void setSolidColor(int argb) { mHasSolidColor = true; mSolidColor = argb; @@ -1055,4 +1223,3 @@ public class GradientDrawable extends Drawable { } } } - diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index f285f5b..11c2427 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -487,6 +487,7 @@ public class Allocation extends BaseObj { final byte[] data = fp.getData(); int eSize = mType.mElement.mElements[component_number].getSizeBytes(); + eSize *= mType.mElement.mArraySizes[component_number]; if (data.length != eSize) { throw new RSIllegalArgumentException("Field packer sizelength " + data.length + diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index ad10832..03ad5ae 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -837,7 +837,7 @@ public class RenderScript { mRS.mErrorCallback.mErrorNum = subID; mRS.mErrorCallback.run(); } else { - //throw new RSRuntimeException("Received error num " + subID + ", details: " + e); + throw new RSRuntimeException("Received error num " + subID + ", details: " + e); } continue; } |
