private static SVG parse( InputStream in, Integer searchColor, Integer replaceColor, boolean whiteMode) throws SVGParseException { // Util.debug("Parsing SVG..."); try { // long start = System.currentTimeMillis(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); final Picture picture = new Picture(); SVGHandler handler = new SVGHandler(picture); handler.setColorSwap(searchColor, replaceColor); handler.setWhiteMode(whiteMode); xr.setContentHandler(handler); xr.parse(new InputSource(in)); // Util.debug("Parsing complete in " + (System.currentTimeMillis() - start) + " // millis."); SVG result = new SVG(picture, handler.bounds); // Skip bounds if it was an empty pic if (!Float.isInfinite(handler.limits.top)) { result.setLimits(handler.limits); } return result; } catch (Exception e) { throw new SVGParseException(e); } }
protected Picture doInBackground(Integer... resourceId) { try { SVG svg = SVG.getFromResource(getContext(), resourceId[0]); return svg.renderToPicture(); } catch (SVGParseException e) { Log.e( "SVGImageView", String.format("Error loading resource 0x%x: %s", resourceId, e.getMessage())); } return null; }
protected Picture doInBackground(String... filename) { try { SVG svg = SVG.getFromAsset(getContext().getAssets(), filename[0]); return svg.renderToPicture(); } catch (SVGParseException e) { Log.e("SVGImageView", "Error loading file " + filename + ": " + e.getMessage()); } catch (FileNotFoundException e) { Log.e("SVGImageView", "File not found: " + filename); } catch (IOException e) { Log.e("SVGImageView", "Unable to load asset file: " + filename, e); } return null; }
protected Picture doInBackground(InputStream... is) { try { SVG svg = SVG.getFromInputStream(is[0]); return svg.renderToPicture(); } catch (SVGParseException e) { Log.e("SVGImageView", "Parse error loading URI: " + e.getMessage()); } finally { try { is[0].close(); } catch (IOException e) { /* do nothing */ } } return null; }
/** Directly set the SVG. */ public void setSVG(SVG mysvg) { if (mysvg == null) throw new IllegalArgumentException("Null value passed to setSVG()"); setSoftwareLayerType(); setImageDrawable(new PictureDrawable(mysvg.renderToPicture())); }
public SVGPolyLine() { setElement(SVG.createPolyline()); }