diff options
-rw-r--r-- | graphics/java/android/graphics/drawable/VectorDrawable.java | 10 | ||||
-rw-r--r-- | tests/VectorDrawableTest/src/com/android/test/dynamic/ScaleDrawableTests.java | 37 |
2 files changed, 15 insertions, 32 deletions
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 0f237a7..13ef89b 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -735,10 +735,12 @@ public class VectorDrawable extends Drawable { private void drawPath(VGroup vGroup, VPath vPath, float stackedAlpha, Canvas canvas, int w, int h) { - final float scale = Math.min(h / mViewportHeight, w / mViewportWidth); + final float scaleX = w / mViewportWidth; + final float scaleY = h / mViewportHeight; + final float minScale = Math.min(scaleX, scaleY); mFinalPathMatrix.set(vGroup.mStackedMatrix); - mFinalPathMatrix.postScale(scale, scale, mViewportWidth / 2f, mViewportHeight / 2f); + mFinalPathMatrix.postScale(scaleX, scaleY, mViewportWidth / 2f, mViewportHeight / 2f); mFinalPathMatrix.postTranslate( w / 2f - mViewportWidth / 2f, h / 2f - mViewportHeight / 2f); @@ -802,10 +804,10 @@ public class VectorDrawable extends Drawable { strokePaint.setStrokeCap(vPath.mStrokeLineCap); } - strokePaint.setStrokeMiter(vPath.mStrokeMiterlimit * scale); + strokePaint.setStrokeMiter(vPath.mStrokeMiterlimit * minScale); strokePaint.setColor(applyAlpha(vPath.mStrokeColor, stackedAlpha)); - strokePaint.setStrokeWidth(vPath.mStrokeWidth * scale); + strokePaint.setStrokeWidth(vPath.mStrokeWidth * minScale); canvas.drawPath(mRenderPath, strokePaint); } } diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/ScaleDrawableTests.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/ScaleDrawableTests.java index 07ca2eb..3787843 100644 --- a/tests/VectorDrawableTest/src/com/android/test/dynamic/ScaleDrawableTests.java +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/ScaleDrawableTests.java @@ -36,30 +36,9 @@ public class ScaleDrawableTests extends Activity { "CENTER_INSIDE (7)" }; - protected int[] icon = { - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - R.drawable.bitmap_drawable01, - }; - - protected int[] vector_icons = { - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - R.drawable.vector_drawable16, - }; - + protected int icon = R.drawable.bitmap_drawable01; + protected int vector_icon = R.drawable.vector_drawable16; @Override protected void onCreate(Bundle savedInstanceState) { @@ -74,21 +53,23 @@ public class ScaleDrawableTests extends Activity { params.width = 400; params.height = 300; - for (int i = 0; i < icon.length; i++) { + for (int i = 0; i < scaleTypes.length; i++) { TextView t = new TextView(this); t.setText(scaleTypes[i]); container.addView(t); + ImageView.ScaleType scaleType = ImageView.ScaleType.values()[i]; + ImageView png_view = new ImageView(this); png_view.setLayoutParams(params); - png_view.setScaleType(ImageView.ScaleType.values()[i]); - png_view.setImageResource(icon[i]); + png_view.setScaleType(scaleType); + png_view.setImageResource(icon); container.addView(png_view); ImageView view = new ImageView(this); view.setLayoutParams(params); - view.setScaleType(ImageView.ScaleType.values()[i]); - view.setImageResource(vector_icons[i]); + view.setScaleType(scaleType); + view.setImageResource(vector_icon); container.addView(view); } |