diff options
Diffstat (limited to 'graphics/java')
9 files changed, 36 insertions, 40 deletions
diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java index 335bce0..3bccf08 100644 --- a/graphics/java/android/graphics/NinePatch.java +++ b/graphics/java/android/graphics/NinePatch.java @@ -43,7 +43,7 @@ public class NinePatch { @SuppressWarnings({"UnusedDeclaration"}) // called from JNI InsetStruct(int opticalLeft, int opticalTop, int opticalRight, int opticalBottom, int outlineLeft, int outlineTop, int outlineRight, int outlineBottom, - float outlineRadius, boolean outlineFilled, float decodeScale) { + float outlineRadius, int outlineAlpha, float decodeScale) { opticalRect = new Rect(opticalLeft, opticalTop, opticalRight, opticalBottom); outlineRect = new Rect(outlineLeft, outlineTop, outlineRight, outlineBottom); @@ -55,13 +55,13 @@ public class NinePatch { outlineRect.scaleRoundIn(decodeScale); } this.outlineRadius = outlineRadius * decodeScale; - this.outlineFilled = outlineFilled; + this.outlineAlpha = outlineAlpha / 255.0f; } public final Rect opticalRect; public final Rect outlineRect; public final float outlineRadius; - public final boolean outlineFilled; + public final float outlineAlpha; } private final Bitmap mBitmap; diff --git a/graphics/java/android/graphics/Outline.java b/graphics/java/android/graphics/Outline.java index 3a4c2a7..1cf5f37 100644 --- a/graphics/java/android/graphics/Outline.java +++ b/graphics/java/android/graphics/Outline.java @@ -37,9 +37,8 @@ public final class Outline { public Rect mRect; /** @hide */ public float mRadius; - /** @hide */ - public boolean mIsFilled; + public float mAlpha; /** * Constructs an empty Outline. Call one of the setter methods to make @@ -63,7 +62,6 @@ public final class Outline { mPath = null; mRect = null; mRadius = 0; - mIsFilled = true; } /** @@ -92,24 +90,24 @@ public final class Outline { } /** - * Sets whether the outline represents a fully opaque area. + * Sets the alpha represented by the Outline. * - * A filled outline is assumed, by the drawing system, to fully cover content beneath it, - * meaning content beneath may be optimized away. + * Content producing a fully opaque (alpha = 1.0f) outline is assumed, by the drawing system, + * to fully cover content beneath it, meaning content beneath may be optimized away. * * @hide */ - public void setFilled(boolean isFilled) { - mIsFilled = isFilled; + public void setAlpha(float alpha) { + mAlpha = alpha; } /** - * Returns whether the outline represents a fully opaque area. + * Sets the alpha represented by the Outline. * * @hide */ - public boolean isFilled() { - return !isEmpty() && mIsFilled; + public float getAlpha() { + return mAlpha; } /** @@ -132,7 +130,7 @@ public final class Outline { mRect.set(src.mRect); } mRadius = src.mRadius; - mIsFilled = src.mIsFilled; + mAlpha = src.mAlpha; } /** @@ -164,7 +162,6 @@ public final class Outline { mRect.set(left, top, right, bottom); mRadius = radius; mPath = null; - mIsFilled = true; } /** @@ -193,7 +190,6 @@ public final class Outline { mPath.reset(); mPath.addOval(left, top, right, bottom, Path.Direction.CW); mRect = null; - mIsFilled = true; } /** @@ -220,6 +216,5 @@ public final class Outline { mPath.set(convexPath); mRect = null; mRadius = -1.0f; - mIsFilled = true; } } diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index acb34c2..df9f3c3 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -861,16 +861,14 @@ public abstract class Drawable { * This method is called by the default {@link android.view.ViewOutlineProvider} to define * the outline of the View. * <p> - * The default behavior defines the outline to be the bounding rectangle. Subclasses that wish - * to convey a different shape must override this method. - * - * @return true if this drawable actually has an outline, else false. The outline must be - * populated by the drawable if true is returned. + * The default behavior defines the outline to be the bounding rectangle of 0 alpha. + * Subclasses that wish to convey a different shape or alpha value must override this method. * * @see android.view.View#setOutlineProvider(android.view.ViewOutlineProvider) */ public void getOutline(@NonNull Outline outline) { outline.setRect(getBounds()); + outline.setAlpha(getAlpha() / 255.0f); } /** diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 4815586..a383aab 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -1413,6 +1413,7 @@ public class GradientDrawable extends Drawable { public void getOutline(Outline outline) { final GradientState st = mGradientState; final Rect bounds = getBounds(); + outline.setAlpha(mAlpha / 255.0f); switch (st.mShape) { case RECTANGLE: diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 073100a..d094ce4 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -595,12 +595,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { } /** - * Populates <code>outline</code> with the first available layer outline. - * Returns <code>true</code> if an outline is available, <code>false</code> - * otherwise. + * Populates <code>outline</code> with the first available (non-empty) layer outline. * * @param outline Outline in which to place the first available layer outline - * @return <code>true</code> if an outline is available */ @Override public void getOutline(@NonNull Outline outline) { diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index 6afce41..3397e94 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -296,7 +296,7 @@ public class NinePatchDrawable extends Drawable { bounds.right - outlineInsets.right, bounds.bottom - outlineInsets.bottom, insets.outlineRadius); - outline.setFilled(insets.outlineFilled); + outline.setAlpha(insets.outlineAlpha * (getAlpha() / 255.0f)); return; } } diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index eb7291c..cf675ed 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -585,11 +585,9 @@ public class RippleDrawable extends LayerDrawable { /** * Populates <code>outline</code> with the first available layer outline, - * excluding the mask layer. Returns <code>true</code> if an outline is - * available, <code>false</code> otherwise. + * excluding the mask layer. * * @param outline Outline in which to place the first available layer outline - * @return <code>true</code> if an outline is available */ @Override public void getOutline(@NonNull Outline outline) { diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 2bed3b0..394f584 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -470,6 +470,7 @@ public class ShapeDrawable extends Drawable { public void getOutline(Outline outline) { if (mShapeState.mShape != null) { mShapeState.mShape.getOutline(outline); + outline.setAlpha(getAlpha() / 255.0f); } } diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index f41b11a..be02c9b 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -364,13 +364,19 @@ public class VectorDrawable extends Drawable { /** @hide */ public static VectorDrawable create(Resources resources, int rid) { try { - final XmlPullParser xpp = resources.getXml(rid); - final AttributeSet attrs = Xml.asAttributeSet(xpp); - final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); - factory.setNamespaceAware(true); + final XmlPullParser parser = resources.getXml(rid); + final AttributeSet attrs = Xml.asAttributeSet(parser); + int type; + while ((type=parser.next()) != XmlPullParser.START_TAG && + type != XmlPullParser.END_DOCUMENT) { + // Empty loop + } + if (type != XmlPullParser.START_TAG) { + throw new XmlPullParserException("No start tag found"); + } final VectorDrawable drawable = new VectorDrawable(); - drawable.inflate(resources, xpp, attrs); + drawable.inflate(resources, parser, attrs); return drawable; } catch (XmlPullParserException e) { @@ -436,10 +442,10 @@ public class VectorDrawable extends Drawable { if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + - "<viewport> tag requires viewportWidth > 0"); + "<vector> tag requires viewportWidth > 0"); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + - "<viewport> tag requires viewportHeight > 0"); + "<vector> tag requires viewportHeight > 0"); } pathRenderer.mBaseWidth = a.getDimension( @@ -449,10 +455,10 @@ public class VectorDrawable extends Drawable { if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + - "<size> tag requires width > 0"); + "<vector> tag requires width > 0"); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + - "<size> tag requires height > 0"); + "<vector> tag requires height > 0"); } } |