Loading graphics/java/android/graphics/drawable/VectorDrawable.java +60 −47 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.content.res.Resources; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; Loading Loading @@ -134,8 +135,6 @@ public class VectorDrawable extends Drawable { private final VectorDrawableState mVectorState; private int mAlpha = 0xFF; public VectorDrawable() { mVectorState = new VectorDrawableState(null); } Loading Loading @@ -164,9 +163,8 @@ public class VectorDrawable extends Drawable { @Override public void setAlpha(int alpha) { // TODO correct handling of transparent if (mAlpha != alpha) { mAlpha = alpha; if (mVectorState.mVPathRenderer.getRootAlpha() != alpha) { mVectorState.mVPathRenderer.setRootAlpha(alpha); invalidateSelf(); } } Loading Loading @@ -273,6 +271,13 @@ public class VectorDrawable extends Drawable { return null; } private static int applyAlpha(int color, float alpha) { int alphaBytes = Color.alpha(color); color &= 0x00FFFFFF; color |= ((int) (alphaBytes * alpha)) << 24; return color; } private VPathRenderer inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { final VPathRenderer pathRenderer = new VPathRenderer(); Loading Loading @@ -434,6 +439,7 @@ public class VectorDrawable extends Drawable { private float mBaseHeight = 0; private float mViewportWidth = 0; private float mViewportHeight = 0; private int mRootAlpha = 0xFF; private final Matrix mFinalPathMatrix = new Matrix(); Loading @@ -441,6 +447,14 @@ public class VectorDrawable extends Drawable { mRootGroup = new VGroup(); } public void setRootAlpha(int alpha) { mRootAlpha = alpha; } public int getRootAlpha() { return mRootAlpha; } public VPathRenderer(VPathRenderer copy) { mRootGroup = copy.mRootGroup; mBaseWidth = copy.mBaseWidth; Loading Loading @@ -519,7 +533,7 @@ public class VectorDrawable extends Drawable { } private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix, Canvas canvas, int w, int h) { float currentAlpha, Canvas canvas, int w, int h) { // Calculate current group's matrix by preConcat the parent's and // and the current one on the top of the stack. // Basically the Mfinal = Mviewport * M0 * M1 * M2; Loading @@ -528,20 +542,21 @@ public class VectorDrawable extends Drawable { currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix); drawPath(currentGroup, canvas, w, h); float stackedAlpha = currentAlpha * currentGroup.mGroupAlpha; drawPath(currentGroup, stackedAlpha, canvas, w, h); // Draw the group tree in post order. for (int i = 0 ; i < currentGroup.mChildGroupList.size(); i++) { drawGroupTree(currentGroup.mChildGroupList.get(i), currentGroup.mStackedMatrix, canvas, w, h); currentGroup.mStackedMatrix, stackedAlpha, canvas, w, h); } } public void draw(Canvas canvas, int w, int h) { // Travese the tree in pre-order to draw. drawGroupTree(mRootGroup, IDENTITY_MATRIX, canvas, w, h); drawGroupTree(mRootGroup, IDENTITY_MATRIX, ((float) mRootAlpha) / 0xFF, canvas, w, h); } private void drawPath(VGroup vGroup, Canvas canvas, int w, int h) { private void drawPath(VGroup vGroup, float stackedAlpha, Canvas canvas, int w, int h) { final float scale = Math.min(h / mViewportHeight, w / mViewportWidth); mFinalPathMatrix.set(vGroup.mStackedMatrix); Loading Loading @@ -582,8 +597,7 @@ public class VectorDrawable extends Drawable { if (vPath.mClip) { canvas.clipPath(mRenderPath, Region.Op.REPLACE); } } else { if (vPath.mFillColor != 0) { if (mFillPaint == null) { mFillPaint = new Paint(); Loading @@ -591,8 +605,7 @@ public class VectorDrawable extends Drawable { mFillPaint.setStyle(Paint.Style.FILL); mFillPaint.setAntiAlias(true); } mFillPaint.setColor(vPath.mFillColor); mFillPaint.setColor(applyAlpha(vPath.mFillColor, stackedAlpha)); canvas.drawPath(mRenderPath, mFillPaint); } Loading @@ -614,12 +627,14 @@ public class VectorDrawable extends Drawable { } strokePaint.setStrokeMiter(vPath.mStrokeMiterlimit * scale); strokePaint.setColor(vPath.mStrokeColor); strokePaint.setColor(applyAlpha(vPath.mStrokeColor, stackedAlpha)); strokePaint.setStrokeWidth(vPath.mStrokeWidth * scale); canvas.drawPath(mRenderPath, strokePaint); } } } } private void parseViewport(Resources r, AttributeSet attrs) throws XmlPullParserException { Loading Loading @@ -669,7 +684,7 @@ public class VectorDrawable extends Drawable { private float mScaleY = 1; private float mTranslateX = 0; private float mTranslateY = 0; private float mAlpha = 1; private float mGroupAlpha = 1; // mLocalMatrix is parsed from the XML. private final Matrix mLocalMatrix = new Matrix(); Loading Loading @@ -714,7 +729,7 @@ public class VectorDrawable extends Drawable { mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY); mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX); mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY); mAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mAlpha); mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha); updateLocalMatrix(); if (a.hasValue(R.styleable.VectorDrawableGroup_name)) { mName = a.getString(R.styleable.VectorDrawableGroup_name); Loading Loading @@ -763,7 +778,7 @@ public class VectorDrawable extends Drawable { } if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_alpha] == 0) { mAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mAlpha); mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha); } updateLocalMatrix(); Loading Loading @@ -799,7 +814,7 @@ public class VectorDrawable extends Drawable { float mStrokeWidth = 0; float mStrokeOpacity = Float.NaN; int mFillColor = 0; int mFillColor = Color.BLACK; int mFillRule; float mFillOpacity = Float.NaN; Loading Loading @@ -984,13 +999,11 @@ public class VectorDrawable extends Drawable { private void updateColorAlphas() { if (!Float.isNaN(mFillOpacity)) { mFillColor &= 0x00FFFFFF; mFillColor |= ((int) (0xFF * mFillOpacity)) << 24; mFillColor = applyAlpha(mFillColor, mFillOpacity); } if (!Float.isNaN(mStrokeOpacity)) { mStrokeColor &= 0x00FFFFFF; mStrokeColor |= ((int) (0xFF * mStrokeOpacity)) << 24; mStrokeColor = applyAlpha(mStrokeColor, mStrokeOpacity); } } Loading tests/VectorDrawableTest/res/drawable/vector_drawable06.xml +4 −0 Original line number Diff line number Diff line Loading @@ -25,10 +25,12 @@ <group> <path android:pathData="M 569.374 461.472L 569.374 160.658L 160.658 160.658L 160.658 461.472L 569.374 461.472z" android:name="path2451" android:fill="#00000000" android:stroke="#FF000000" android:strokeWidth="30.65500000000000"/> <path android:pathData="M 365.015 311.066" android:name="path2453" android:fill="#00000000" android:stroke="#FF000000" android:strokeWidth="30.655000000000001"/> <path android:pathData="M 164.46 164.49L 340.78 343.158C 353.849 356.328 377.63 356.172 390.423 343.278L 566.622 165.928" Loading @@ -38,10 +40,12 @@ android:strokeWidth="30.655000000000001"/> <path android:pathData="M 170.515 451.566L 305.61 313.46" android:name="path2457" android:fill="#00000000" android:stroke="#000000" android:strokeWidth="30.655000000000001"/> <path android:pathData="M 557.968 449.974L 426.515 315.375" android:name="path2459" android:fill="#00000000" android:stroke="#000000" android:strokeWidth="30.655000000000001"/> </group> Loading tests/VectorDrawableTest/res/drawable/vector_drawable12.xml +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ <path android:name="pie1" android:pathData="M300,70 a230,230 0 1,0 1,0 z" android:fill="#00000000" android:stroke="#FF00FF00" android:strokeWidth="70" android:trimPathEnd=".75" Loading tests/VectorDrawableTest/res/drawable/vector_drawable14.xml +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ a25,25 -30 0,1 100,-50 l 50,-25 a25,37 -30 0,1 100,-50 l 50,-25 a25,50 -30 0,1 100,-50 l 50,-25" android:fill="#00000000" android:stroke="#FF00FF00" android:strokeWidth="10" /> </group> Loading tests/VectorDrawableTest/res/drawable/vector_drawable17.xml +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ <path android:name="house" android:pathData="M200,300 Q400,50 600,300 T1000,300" android:fill="#00000000" android:stroke="#FFFF0000" android:strokeWidth="10"/> </group> Loading Loading
graphics/java/android/graphics/drawable/VectorDrawable.java +60 −47 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.content.res.Resources; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; Loading Loading @@ -134,8 +135,6 @@ public class VectorDrawable extends Drawable { private final VectorDrawableState mVectorState; private int mAlpha = 0xFF; public VectorDrawable() { mVectorState = new VectorDrawableState(null); } Loading Loading @@ -164,9 +163,8 @@ public class VectorDrawable extends Drawable { @Override public void setAlpha(int alpha) { // TODO correct handling of transparent if (mAlpha != alpha) { mAlpha = alpha; if (mVectorState.mVPathRenderer.getRootAlpha() != alpha) { mVectorState.mVPathRenderer.setRootAlpha(alpha); invalidateSelf(); } } Loading Loading @@ -273,6 +271,13 @@ public class VectorDrawable extends Drawable { return null; } private static int applyAlpha(int color, float alpha) { int alphaBytes = Color.alpha(color); color &= 0x00FFFFFF; color |= ((int) (alphaBytes * alpha)) << 24; return color; } private VPathRenderer inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { final VPathRenderer pathRenderer = new VPathRenderer(); Loading Loading @@ -434,6 +439,7 @@ public class VectorDrawable extends Drawable { private float mBaseHeight = 0; private float mViewportWidth = 0; private float mViewportHeight = 0; private int mRootAlpha = 0xFF; private final Matrix mFinalPathMatrix = new Matrix(); Loading @@ -441,6 +447,14 @@ public class VectorDrawable extends Drawable { mRootGroup = new VGroup(); } public void setRootAlpha(int alpha) { mRootAlpha = alpha; } public int getRootAlpha() { return mRootAlpha; } public VPathRenderer(VPathRenderer copy) { mRootGroup = copy.mRootGroup; mBaseWidth = copy.mBaseWidth; Loading Loading @@ -519,7 +533,7 @@ public class VectorDrawable extends Drawable { } private void drawGroupTree(VGroup currentGroup, Matrix currentMatrix, Canvas canvas, int w, int h) { float currentAlpha, Canvas canvas, int w, int h) { // Calculate current group's matrix by preConcat the parent's and // and the current one on the top of the stack. // Basically the Mfinal = Mviewport * M0 * M1 * M2; Loading @@ -528,20 +542,21 @@ public class VectorDrawable extends Drawable { currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix); drawPath(currentGroup, canvas, w, h); float stackedAlpha = currentAlpha * currentGroup.mGroupAlpha; drawPath(currentGroup, stackedAlpha, canvas, w, h); // Draw the group tree in post order. for (int i = 0 ; i < currentGroup.mChildGroupList.size(); i++) { drawGroupTree(currentGroup.mChildGroupList.get(i), currentGroup.mStackedMatrix, canvas, w, h); currentGroup.mStackedMatrix, stackedAlpha, canvas, w, h); } } public void draw(Canvas canvas, int w, int h) { // Travese the tree in pre-order to draw. drawGroupTree(mRootGroup, IDENTITY_MATRIX, canvas, w, h); drawGroupTree(mRootGroup, IDENTITY_MATRIX, ((float) mRootAlpha) / 0xFF, canvas, w, h); } private void drawPath(VGroup vGroup, Canvas canvas, int w, int h) { private void drawPath(VGroup vGroup, float stackedAlpha, Canvas canvas, int w, int h) { final float scale = Math.min(h / mViewportHeight, w / mViewportWidth); mFinalPathMatrix.set(vGroup.mStackedMatrix); Loading Loading @@ -582,8 +597,7 @@ public class VectorDrawable extends Drawable { if (vPath.mClip) { canvas.clipPath(mRenderPath, Region.Op.REPLACE); } } else { if (vPath.mFillColor != 0) { if (mFillPaint == null) { mFillPaint = new Paint(); Loading @@ -591,8 +605,7 @@ public class VectorDrawable extends Drawable { mFillPaint.setStyle(Paint.Style.FILL); mFillPaint.setAntiAlias(true); } mFillPaint.setColor(vPath.mFillColor); mFillPaint.setColor(applyAlpha(vPath.mFillColor, stackedAlpha)); canvas.drawPath(mRenderPath, mFillPaint); } Loading @@ -614,12 +627,14 @@ public class VectorDrawable extends Drawable { } strokePaint.setStrokeMiter(vPath.mStrokeMiterlimit * scale); strokePaint.setColor(vPath.mStrokeColor); strokePaint.setColor(applyAlpha(vPath.mStrokeColor, stackedAlpha)); strokePaint.setStrokeWidth(vPath.mStrokeWidth * scale); canvas.drawPath(mRenderPath, strokePaint); } } } } private void parseViewport(Resources r, AttributeSet attrs) throws XmlPullParserException { Loading Loading @@ -669,7 +684,7 @@ public class VectorDrawable extends Drawable { private float mScaleY = 1; private float mTranslateX = 0; private float mTranslateY = 0; private float mAlpha = 1; private float mGroupAlpha = 1; // mLocalMatrix is parsed from the XML. private final Matrix mLocalMatrix = new Matrix(); Loading Loading @@ -714,7 +729,7 @@ public class VectorDrawable extends Drawable { mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY); mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX); mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY); mAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mAlpha); mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha); updateLocalMatrix(); if (a.hasValue(R.styleable.VectorDrawableGroup_name)) { mName = a.getString(R.styleable.VectorDrawableGroup_name); Loading Loading @@ -763,7 +778,7 @@ public class VectorDrawable extends Drawable { } if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_alpha] == 0) { mAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mAlpha); mGroupAlpha = a.getFloat(R.styleable.VectorDrawableGroup_alpha, mGroupAlpha); } updateLocalMatrix(); Loading Loading @@ -799,7 +814,7 @@ public class VectorDrawable extends Drawable { float mStrokeWidth = 0; float mStrokeOpacity = Float.NaN; int mFillColor = 0; int mFillColor = Color.BLACK; int mFillRule; float mFillOpacity = Float.NaN; Loading Loading @@ -984,13 +999,11 @@ public class VectorDrawable extends Drawable { private void updateColorAlphas() { if (!Float.isNaN(mFillOpacity)) { mFillColor &= 0x00FFFFFF; mFillColor |= ((int) (0xFF * mFillOpacity)) << 24; mFillColor = applyAlpha(mFillColor, mFillOpacity); } if (!Float.isNaN(mStrokeOpacity)) { mStrokeColor &= 0x00FFFFFF; mStrokeColor |= ((int) (0xFF * mStrokeOpacity)) << 24; mStrokeColor = applyAlpha(mStrokeColor, mStrokeOpacity); } } Loading
tests/VectorDrawableTest/res/drawable/vector_drawable06.xml +4 −0 Original line number Diff line number Diff line Loading @@ -25,10 +25,12 @@ <group> <path android:pathData="M 569.374 461.472L 569.374 160.658L 160.658 160.658L 160.658 461.472L 569.374 461.472z" android:name="path2451" android:fill="#00000000" android:stroke="#FF000000" android:strokeWidth="30.65500000000000"/> <path android:pathData="M 365.015 311.066" android:name="path2453" android:fill="#00000000" android:stroke="#FF000000" android:strokeWidth="30.655000000000001"/> <path android:pathData="M 164.46 164.49L 340.78 343.158C 353.849 356.328 377.63 356.172 390.423 343.278L 566.622 165.928" Loading @@ -38,10 +40,12 @@ android:strokeWidth="30.655000000000001"/> <path android:pathData="M 170.515 451.566L 305.61 313.46" android:name="path2457" android:fill="#00000000" android:stroke="#000000" android:strokeWidth="30.655000000000001"/> <path android:pathData="M 557.968 449.974L 426.515 315.375" android:name="path2459" android:fill="#00000000" android:stroke="#000000" android:strokeWidth="30.655000000000001"/> </group> Loading
tests/VectorDrawableTest/res/drawable/vector_drawable12.xml +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ <path android:name="pie1" android:pathData="M300,70 a230,230 0 1,0 1,0 z" android:fill="#00000000" android:stroke="#FF00FF00" android:strokeWidth="70" android:trimPathEnd=".75" Loading
tests/VectorDrawableTest/res/drawable/vector_drawable14.xml +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ a25,25 -30 0,1 100,-50 l 50,-25 a25,37 -30 0,1 100,-50 l 50,-25 a25,50 -30 0,1 100,-50 l 50,-25" android:fill="#00000000" android:stroke="#FF00FF00" android:strokeWidth="10" /> </group> Loading
tests/VectorDrawableTest/res/drawable/vector_drawable17.xml +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ <path android:name="house" android:pathData="M200,300 Q400,50 600,300 T1000,300" android:fill="#00000000" android:stroke="#FFFF0000" android:strokeWidth="10"/> </group> Loading