Back to project page android-shape-imageview.
The source code is released under:
Apache License
If you think the Android project android-shape-imageview listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.siyamed.shapeimageview.path.parser; // ww w .ja v a 2 s . c om import org.xmlpull.v1.XmlPullParser; @SuppressWarnings("FinalStaticMethod") class ParseUtil { static final String escape (String s) { return s .replaceAll("\"", """) .replaceAll("'", "&apos") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll("&", "&"); } static final String getStringAttr(String name, XmlPullParser attributes) { int n = attributes.getAttributeCount(); for (int i = 0; i < n; i++) { if (attributes.getAttributeName(i).equals(name)) { return attributes.getAttributeValue(i); } } return null; } /* * Some SVG unit conversions. This is approximate */ static final Float convertUnits(String name, XmlPullParser atts, float dpi, float width, float height) { String value = getStringAttr(name, atts); if (value == null) { return null; } else if (value.endsWith("px")) { return Float.parseFloat(value.substring(0, value.length() - 2)); } else if (value.endsWith("pt")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 72; } else if (value.endsWith("pc")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 6; } else if (value.endsWith("cm")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 2.54f; } else if (value.endsWith("mm")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 254; } else if (value.endsWith("in")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi; } else if (value.endsWith("%")) { Float result = Float.valueOf(value.substring(0, value.length() - 1)); float mult; if (name.contains("x") || name.equals("width") ) { mult = width / 100f; } else if (name.contains("y") || name.equals("height")) { mult = height / 100f; } else { mult = (height + width) / 2f; } return result * mult; } else { return Float.valueOf(value); } } }