From 452f6ece7fe2fd1a85fca53f54e90bf041083b21 Mon Sep 17 00:00:00 2001 From: ztenghui Date: Wed, 28 May 2014 09:48:36 -0700 Subject: [PATCH] Add translation and scale to the group tag and related tests. bug:15288554 Change-Id: Iebe176d0a9c2c566d1910674a068e65e15569829 --- api/current.txt | 2 + core/res/res/values/attrs.xml | 8 +++ core/res/res/values/public.xml | 2 + .../graphics/drawable/VectorDrawable.java | 56 ++++++++++++++++--- .../res/drawable/vector_drawable01.xml | 3 +- .../res/drawable/vector_drawable16.xml | 19 ++++++- .../res/drawable/vector_drawable21.xml | 51 +++++++++++++++++ .../dynamic/VectorDrawablePerformance.java | 3 +- 8 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 tests/VectorDrawableTest/res/drawable/vector_drawable21.xml diff --git a/api/current.txt b/api/current.txt index b9dd90698428c..47b71b6d9233b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -1243,6 +1243,8 @@ package android { field public static final int transition = 16843743; // 0x10103df field public static final int transitionGroup = 16843803; // 0x101041b field public static final int transitionOrdering = 16843744; // 0x10103e0 + field public static final int translateX = 16843869; // 0x101045d + field public static final int translateY = 16843870; // 0x101045e field public static final int translationX = 16843554; // 0x1010322 field public static final int translationY = 16843555; // 0x1010323 field public static final int translationZ = 16843796; // 0x1010414 diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 0b72c2cb6c75a..e34730240974b 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -4790,6 +4790,14 @@ + + + + + + + + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 42ed318df5442..9c33d8052cc16 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2180,6 +2180,8 @@ + + diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index b85e85ce3c01f..afd529ced30cb 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -58,7 +58,23 @@ import java.util.HashMap; * The size is defined using the attributes android:viewportHeight * android:viewportWidth *
<group>
- *
Defines a group of paths or subgroups, plus transformation information.
+ *
Defines a group of paths or subgroups, plus transformation information. + * The transformations are defined in the same coordinates as the viewport. + * And the transformations are applied in the order of scale, rotate then translate.
+ *
android:rotation + *
The degrees of rotation of the group.
+ *
android:pivotX + *
The X coordinate of the pivot for the scale and rotation of the group
+ *
android:pivotY + *
The Y coordinate of the pivot for the scale and rotation of the group
+ *
android:scaleX + *
The amount of scale on the X Coordinate
+ *
android:scaleY + *
The amount of scale on the Y coordinate
+ *
android:translateX + *
The amount of translation on the X coordinate
+ *
android:translateY + *
The amount of translation on the Y coordinate
*
<path>
*
Defines paths to be drawn. *
@@ -76,12 +92,6 @@ import java.util.HashMap; *
The width a path stroke
*
android:strokeOpacity *
The opacity of a path stroke
- *
android:rotation - *
The amount to rotation the path stroke.
- *
android:pivotX - *
The X coordinate of the center of rotation of a path
- *
android:pivotY - *
The Y coordinate of the center of rotation of a path
*
android:fillOpacity *
The opacity to fill the path with
*
android:trimPathStart @@ -457,7 +467,13 @@ public class VectorDrawable extends Drawable { mMatrix.reset(); - mMatrix.postRotate(vGroup.mRotate, vGroup.mPivotX, vGroup.mPivotY); + // The order we apply is the same as the + // RenderNode.cpp::applyViewPropertyTransforms(). + mMatrix.postTranslate(-vGroup.mPivotX, -vGroup.mPivotY); + mMatrix.postScale(vGroup.mScaleX, vGroup.mScaleY); + mMatrix.postRotate(vGroup.mRotate, 0, 0); + mMatrix.postTranslate(vGroup.mTranslateX + vGroup.mPivotX, vGroup.mTranslateY + vGroup.mPivotY); + mMatrix.postScale(scale, scale, mViewportWidth / 2f, mViewportHeight / 2f); mMatrix.postTranslate(w / 2f - mViewportWidth / 2f, h / 2f - mViewportHeight / 2f); @@ -577,6 +593,10 @@ public class VectorDrawable extends Drawable { private float mRotate = 0; private float mPivotX = 0; private float mPivotY = 0; + private float mScaleX = 1; + private float mScaleY = 1; + private float mTranslateX = 0; + private float mTranslateY = 0; private int[] mThemeAttrs; @@ -597,6 +617,10 @@ public class VectorDrawable extends Drawable { mRotate = a.getFloat(R.styleable.VectorDrawableGroup_rotation, mRotate); mPivotX = a.getFloat(R.styleable.VectorDrawableGroup_pivotX, mPivotX); mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY); + mScaleX = a.getFloat(R.styleable.VectorDrawableGroup_scaleX, mScaleX); + mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY); + mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX); + mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY); a.recycle(); } @@ -620,6 +644,22 @@ public class VectorDrawable extends Drawable { mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY); } + if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_scaleX] == 0) { + mScaleX = a.getFloat(R.styleable.VectorDrawableGroup_scaleX, mScaleX); + } + + if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_scaleY] == 0) { + mScaleY = a.getFloat(R.styleable.VectorDrawableGroup_scaleY, mScaleY); + } + + if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_translateX] == 0) { + mTranslateX = a.getFloat(R.styleable.VectorDrawableGroup_translateX, mTranslateX); + } + + if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_translateY] == 0) { + mTranslateY = a.getFloat(R.styleable.VectorDrawableGroup_translateY, mTranslateY); + } + a.recycle(); } diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml index d0f2a2db366a8..66a9452d53800 100644 --- a/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml +++ b/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml @@ -13,8 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + + + diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable21.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable21.xml new file mode 100644 index 0000000000000..e0013e7d28dd4 --- /dev/null +++ b/tests/VectorDrawableTest/res/drawable/vector_drawable21.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java index dcc7769881d62..e0624e55db2b0 100644 --- a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java @@ -47,7 +47,8 @@ public class VectorDrawablePerformance extends Activity { R.drawable.vector_drawable17, R.drawable.vector_drawable18, R.drawable.vector_drawable19, - R.drawable.vector_drawable20 + R.drawable.vector_drawable20, + R.drawable.vector_drawable21 }; @Override