diff options
Diffstat (limited to 'graphics/java/android/graphics/drawable/shapes')
4 files changed, 59 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/drawable/shapes/OvalShape.java b/graphics/java/android/graphics/drawable/shapes/OvalShape.java index c914999..198dcc1 100644 --- a/graphics/java/android/graphics/drawable/shapes/OvalShape.java +++ b/graphics/java/android/graphics/drawable/shapes/OvalShape.java @@ -17,7 +17,9 @@ package android.graphics.drawable.shapes; import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Paint; +import android.graphics.RectF; /** * Defines an oval shape. @@ -36,5 +38,13 @@ public class OvalShape extends RectShape { public void draw(Canvas canvas, Paint paint) { canvas.drawOval(rect(), paint); } + + @Override + public boolean getOutline(Outline outline) { + final RectF rect = rect(); + outline.setOval((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), + (int) Math.floor(rect.right), (int) Math.floor(rect.bottom)); + return true; + } } diff --git a/graphics/java/android/graphics/drawable/shapes/RectShape.java b/graphics/java/android/graphics/drawable/shapes/RectShape.java index a3d2654..2a0256c 100644 --- a/graphics/java/android/graphics/drawable/shapes/RectShape.java +++ b/graphics/java/android/graphics/drawable/shapes/RectShape.java @@ -17,6 +17,7 @@ package android.graphics.drawable.shapes; import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Paint; import android.graphics.RectF; @@ -40,10 +41,18 @@ public class RectShape extends Shape { } @Override + public boolean getOutline(Outline outline) { + final RectF rect = rect(); + outline.setRect((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), + (int) Math.floor(rect.right), (int) Math.floor(rect.bottom)); + return true; + } + + @Override protected void onResize(float width, float height) { mRect.set(0, 0, width, height); } - + /** * Returns the RectF that defines this rectangle's bounds. */ diff --git a/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java b/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java index b469d2a..a6bb1bb 100644 --- a/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java +++ b/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java @@ -17,6 +17,7 @@ package android.graphics.drawable.shapes; import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; @@ -77,11 +78,34 @@ public class RoundRectShape extends RectShape { public void draw(Canvas canvas, Paint paint) { canvas.drawPath(mPath, paint); } - + + @Override + public boolean getOutline(Outline outline) { + if (mInnerRect != null) return false; // have a hole, can't produce valid outline + + float radius = 0; + if (mOuterRadii != null) { + radius = mOuterRadii[0]; + for (int i = 1; i < 8; i++) { + if (mOuterRadii[i] != radius) { + // can't call simple constructors, use path + outline.setConvexPath(mPath); + return true; + } + } + } + + final RectF rect = rect(); + outline.setRoundRect((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), + (int) Math.floor(rect.right), (int) Math.floor(rect.bottom), + radius); + return true; + } + @Override protected void onResize(float w, float h) { super.onResize(w, h); - + RectF r = rect(); mPath.reset(); diff --git a/graphics/java/android/graphics/drawable/shapes/Shape.java b/graphics/java/android/graphics/drawable/shapes/Shape.java index 4e192f9..1a20e8b 100644 --- a/graphics/java/android/graphics/drawable/shapes/Shape.java +++ b/graphics/java/android/graphics/drawable/shapes/Shape.java @@ -17,6 +17,7 @@ package android.graphics.drawable.shapes; import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Paint; /** @@ -43,7 +44,6 @@ public abstract class Shape implements Cloneable { return mHeight; } - /** * Draw this shape into the provided Canvas, with the provided Paint. * Before calling this, you must call {@link #resize(float,float)}. @@ -52,7 +52,6 @@ public abstract class Shape implements Cloneable { * @param paint the Paint object that defines this shape's characteristics */ public abstract void draw(Canvas canvas, Paint paint); - /** * Resizes the dimensions of this shape. @@ -93,8 +92,20 @@ public abstract class Shape implements Cloneable { */ protected void onResize(float width, float height) {} + /** + * Compute the Outline of the shape. + * + * The default implementation does not supply an outline. + * + * @return True if a valid outline has been computed, false otherwise. + */ + public boolean getOutline(Outline outline) { + return false; + } + @Override public Shape clone() throws CloneNotSupportedException { return (Shape) super.clone(); } + } |