diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index ff4ab98ae1d16..2da861543cf8d 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -46,7 +46,7 @@ import java.util.HashMap;
* This lets you create a drawable based on an XML vector graphic It can be
* defined in an XML file with the <vector> element.
*
- * The vector drawable has 6 elements:
+ * The vector drawable has the following elements:
*
*
* <vector>
@@ -59,15 +59,15 @@ import java.util.HashMap;
* - Used to defined the size of the virtual canvas the paths are drawn on.
* The size is defined using the attributes
android:viewportHeight
* android:viewportWidth
- * <group>
- * - Defines the static 2D image.
* <path>
- * - Defines paths to be drawn. The path elements must be within a group
+ *
- Defines paths to be drawn. Multiple paths can be defined in one xml file.
+ * The paths are drawn in the order of their definition order.
*
* android:name
* - Defines the name of the path.
* android:pathData
- * - Defines path string.
+ * - Defines path string. This is using exactly same format as "d" attribute
+ * in the SVG's path data
* android:fill
* - Defines the color to fill the path (none if not present).
* android:stroke
@@ -108,7 +108,6 @@ public class VectorDrawable extends Drawable {
private static final String SHAPE_SIZE = "size";
private static final String SHAPE_VIEWPORT = "viewport";
- private static final String SHAPE_GROUP = "group";
private static final String SHAPE_PATH = "path";
private static final String SHAPE_VECTOR = "vector";
@@ -266,10 +265,9 @@ public class VectorDrawable extends Drawable {
boolean noSizeTag = true;
boolean noViewportTag = true;
- boolean noGroupTag = true;
boolean noPathTag = true;
- VGroup currentGroup = null;
+ VGroup currentGroup = new VGroup();
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
@@ -286,10 +284,6 @@ public class VectorDrawable extends Drawable {
} else if (SHAPE_VIEWPORT.equals(tagName)) {
pathRenderer.parseViewport(res, attrs);
noViewportTag = false;
- } else if (SHAPE_GROUP.equals(tagName)) {
- currentGroup = new VGroup();
- pathRenderer.mGroupList.add(currentGroup);
- noGroupTag = false;
} else if (SHAPE_VECTOR.equals(tagName)) {
final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawable);
@@ -310,7 +304,7 @@ public class VectorDrawable extends Drawable {
eventType = parser.next();
}
- if (noSizeTag || noViewportTag || noGroupTag || noPathTag) {
+ if (noSizeTag || noViewportTag || noPathTag) {
final StringBuffer tag = new StringBuffer();
if (noSizeTag) {
@@ -324,13 +318,6 @@ public class VectorDrawable extends Drawable {
tag.append(SHAPE_SIZE);
}
- if (noGroupTag) {
- if (tag.length() > 0) {
- tag.append(" & ");
- }
- tag.append(SHAPE_GROUP);
- }
-
if (noPathTag) {
if (tag.length() > 0) {
tag.append(" or ");
@@ -341,6 +328,7 @@ public class VectorDrawable extends Drawable {
throw new XmlPullParserException("no " + tag + " defined");
}
+ pathRenderer.mCurrentGroup = currentGroup;
// post parse cleanup
pathRenderer.parseFinish();
return pathRenderer;
@@ -394,7 +382,7 @@ public class VectorDrawable extends Drawable {
private Paint mFillPaint;
private PathMeasure mPathMeasure;
- final ArrayList mGroupList = new ArrayList();
+ private VGroup mCurrentGroup = new VGroup();
float mBaseWidth = 1;
float mBaseHeight = 1;
@@ -405,7 +393,7 @@ public class VectorDrawable extends Drawable {
}
public VPathRenderer(VPathRenderer copy) {
- mGroupList.addAll(copy.mGroupList);
+ mCurrentGroup = copy.mCurrentGroup;
if (copy.mCurrentPaths != null) {
mCurrentPaths = new VPath[copy.mCurrentPaths.length];
for (int i = 0; i < mCurrentPaths.length; i++) {
@@ -420,32 +408,24 @@ public class VectorDrawable extends Drawable {
}
public boolean canApplyTheme() {
- final ArrayList groups = mGroupList;
- for (int i = groups.size() - 1; i >= 0; i--) {
- final ArrayList paths = groups.get(i).mVGList;
- for (int j = paths.size() - 1; j >= 0; j--) {
- final VPath path = paths.get(j);
- if (path.canApplyTheme()) {
- return true;
- }
+ final ArrayList paths = mCurrentGroup.mVGList;
+ for (int j = paths.size() - 1; j >= 0; j--) {
+ final VPath path = paths.get(j);
+ if (path.canApplyTheme()) {
+ return true;
}
}
-
return false;
}
public void applyTheme(Theme t) {
- final ArrayList groups = mGroupList;
- for (int i = groups.size() - 1; i >= 0; i--) {
- final ArrayList paths = groups.get(i).mVGList;
- for (int j = paths.size() - 1; j >= 0; j--) {
- final VPath path = paths.get(j);
- if (path.canApplyTheme()) {
- path.applyTheme(t);
- }
+ final ArrayList paths = mCurrentGroup.mVGList;
+ for (int j = paths.size() - 1; j >= 0; j--) {
+ final VPath path = paths.get(j);
+ if (path.canApplyTheme()) {
+ path.applyTheme(t);
}
}
-
}
public void draw(Canvas canvas, int w, int h) {
@@ -537,11 +517,11 @@ public class VectorDrawable extends Drawable {
}
/**
- * Build the "current" path based on the first group
+ * Build the "current" path based on the current group
* TODO: improve memory use & performance or move to C++
*/
public void parseFinish() {
- final Collection paths = mGroupList.get(0).getPaths();
+ final Collection paths = mCurrentGroup.getPaths();
mCurrentPaths = paths.toArray(new VPath[paths.size()]);
for (int i = 0; i < mCurrentPaths.length; i++) {
mCurrentPaths[i] = new VPath(mCurrentPaths[i]);
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml
index d0f2a2db366a8..118f25800dabd 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable01.xml
@@ -24,13 +24,12 @@
android:viewportHeight="480"
android:viewportWidth="480" />
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable02.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable02.xml
index 728624a149ac8..034f7a0b95c56 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable02.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable02.xml
@@ -1,4 +1,5 @@
-
-
+
+ android:height="64dp"
+ android:width="64dp" />
+ android:viewportHeight="12.25"
+ android:viewportWidth="7.30625" />
-
-
-
-
+
-
+
-
+
-
-
+ q -0.78125024,0.8125 -2.2187502,2.265625Z" />
+
+
\ No newline at end of file
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
index c6595facbe667..e6c25574a9812 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
@@ -23,18 +23,17 @@
android:viewportHeight="12.25"
android:viewportWidth="7.30625" />
-
-
-
-
+
\ No newline at end of file
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable06.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable06.xml
index 850de28965000..3f8cc09ec722d 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable06.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable06.xml
@@ -1,4 +1,5 @@
-
-
+
+
+ android:height="64dp"
+ android:width="64dp" />
-
+
-
-
-
-
+ M 20,55 l 7.07,-7.07 35.3,35.3 -7.07,7.07 z" />
+
+
\ No newline at end of file
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable08.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable08.xml
index 59f745942dc7f..44ef9796bc0ff 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable08.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable08.xml
@@ -1,4 +1,5 @@
-