Skip to content

Instantly share code, notes, and snippets.

@ishmal
Created June 13, 2013 19:26
Show Gist options
  • Save ishmal/5776586 to your computer and use it in GitHub Desktop.
Save ishmal/5776586 to your computer and use it in GitHub Desktop.
Tweak to SVGParser to avoid LinearGradient exception
diff --git a/svgandroid/src/com/larvalabs/svgandroid/SVGParser.java b/svgandroid/src/com/larvalabs/svgandroid/SVGParser.java
index acd9fed..1b9b328 100644
--- a/svgandroid/src/com/larvalabs/svgandroid/SVGParser.java
+++ b/svgandroid/src/com/larvalabs/svgandroid/SVGParser.java
@@ -1191,15 +1191,16 @@ public class SVGParser {
for (int i = 0; i < positions.length; i++) {
positions[i] = gradient.positions.get(i);
}
- if (colors.length == 0) {
+ if (colors.length < 2) {
Log.d("BAD", "BAD");
+ } else {
+ LinearGradient g = new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, Shader.TileMode.CLAMP);
+ if (gradient.matrix != null) {
+ g.setLocalMatrix(gradient.matrix);
+ }
+ gradientMap.put(gradient.id, g);
+ gradientRefMap.put(gradient.id, gradient);
}
- LinearGradient g = new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, Shader.TileMode.CLAMP);
- if (gradient.matrix != null) {
- g.setLocalMatrix(gradient.matrix);
- }
- gradientMap.put(gradient.id, g);
- gradientRefMap.put(gradient.id, gradient);
}
} else if (localName.equals("radialGradient")) {
if (gradient.id != null) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment