Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.larvalabs.svgandroid
Class SVGParser

    java.lang.Object
      com.larvalabs.svgandroid.SVGParser

    public class SVGParser

extends java.lang.Object

Entry point for parsing SVG files for Android. Use one of the various static methods for parsing SVGs by resource, asset or input stream. Optionally, a single color can be searched and replaced in the SVG while parsing. You can also parse an svg path directly.

Author:
  Larva Labs, LLC
See Also:
  `getSVGFromResource(android.content.res.Resources, int)`, `getSVGFromAsset(android.content.res.AssetManager, String)`, `getSVGFromString(String)`, `getSVGFromInputStream(java.io.InputStream)`, `parsePath(String)`

Constructor Summary
`SVGParser()`

Method Summary
`static SVG` | `getSVGFromAsset(android.content.res.AssetManager assetMngr, java.lang.String svgPath)` Parse SVG data from an Android application asset.
`static SVG` | `getSVGFromAsset(android.content.res.AssetManager assetMngr, java.lang.String svgPath, int searchColor, int replaceColor)` Parse SVG data from an Android application asset.
`static SVG` | `getSVGFromInputStream(java.io.InputStream svgData)` Parse SVG data from an input stream.
`static SVG` | `getSVGFromInputStream(java.io.InputStream svgData, int searchColor, int replaceColor)` Parse SVG data from an input stream, replacing a single color with another color.
`static SVG` | `getSVGFromResource(android.content.res.Resources resources, int resId)` Parse SVG data from an Android application resource.
`static SVG` | `getSVGFromResource(android.content.res.Resources resources, int resId, int searchColor, int replaceColor)` Parse SVG data from an Android application resource.
`static SVG` | `getSVGFromString(java.lang.String svgData)` Parse SVG data from a string.
`static SVG` | `getSVGFromString(java.lang.String svgData, int searchColor, int replaceColor)` Parse SVG data from a string.
`static android.graphics.Path` | `parsePath(java.lang.String pathString)` Parses a single SVG path and returns it as a `android.graphics.Path` object.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SVGParser

    public SVGParser()

Method Detail

### getSVGFromInputStream

    public static SVG getSVGFromInputStream(java.io.InputStream svgData)
                                     throws SVGParseException

  Parse SVG data from an input stream.

  Parameters:
    `svgData` - the input stream, with SVG XML data in UTF-8 character encoding.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromString

    public static SVG getSVGFromString(java.lang.String svgData)
                                throws SVGParseException

  Parse SVG data from a string.

  Parameters:
    `svgData` - the string containing SVG XML data.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromResource

    public static SVG getSVGFromResource(android.content.res.Resources resources,
                                         int resId)
                                  throws SVGParseException

  Parse SVG data from an Android application resource.

  Parameters:
    `resources` - the Android context resources.
    `resId` - the ID of the raw resource SVG.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromAsset

    public static SVG getSVGFromAsset(android.content.res.AssetManager assetMngr,
                                      java.lang.String svgPath)
                               throws SVGParseException,
                                      java.io.IOException

  Parse SVG data from an Android application asset.

  Parameters:
    `assetMngr` - the Android asset manager.
    `svgPath` - the path to the SVG file in the application's assets.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.
    `java.io.IOException` - if there was a problem reading the file.

### getSVGFromInputStream

    public static SVG getSVGFromInputStream(java.io.InputStream svgData,
                                            int searchColor,
                                            int replaceColor)
                                     throws SVGParseException

  Parse SVG data from an input stream, replacing a single color with another color.

  Parameters:
    `svgData` - the input stream, with SVG XML data in UTF-8 character encoding.
    `searchColor` - the color in the SVG to replace.
    `replaceColor` - the color with which to replace the search color.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromString

    public static SVG getSVGFromString(java.lang.String svgData,
                                       int searchColor,
                                       int replaceColor)
                                throws SVGParseException

  Parse SVG data from a string.

  Parameters:
    `svgData` - the string containing SVG XML data.
    `searchColor` - the color in the SVG to replace.
    `replaceColor` - the color with which to replace the search color.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromResource

    public static SVG getSVGFromResource(android.content.res.Resources resources,
                                         int resId,
                                         int searchColor,
                                         int replaceColor)
                                  throws SVGParseException

  Parse SVG data from an Android application resource.

  Parameters:
    `resources` - the Android context
    `resId` - the ID of the raw resource SVG.
    `searchColor` - the color in the SVG to replace.
    `replaceColor` - the color with which to replace the search color.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.

### getSVGFromAsset

    public static SVG getSVGFromAsset(android.content.res.AssetManager assetMngr,
                                      java.lang.String svgPath,
                                      int searchColor,
                                      int replaceColor)
                               throws SVGParseException,
                                      java.io.IOException

  Parse SVG data from an Android application asset.

  Parameters:
    `assetMngr` - the Android asset manager.
    `svgPath` - the path to the SVG file in the application's assets.
    `searchColor` - the color in the SVG to replace.
    `replaceColor` - the color with which to replace the search color.
  Returns:
    the parsed SVG.
  Throws:
    `SVGParseException` - if there is an error while parsing.
    `java.io.IOException` - if there was a problem reading the file.

### parsePath

    public static android.graphics.Path parsePath(java.lang.String pathString)

  Parses a single SVG path and returns it as a `android.graphics.Path` object. An example path is `M250,150L150,350L350,350Z`, which draws a triangle.

  Parameters:
    `pathString` - the SVG path, see the specification here.

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD