Search in sources :

Example 1 with SVG

use of com.larvalabs.svgandroid.SVG in project iosched by google.

the class ConferenceDataHandler method processMapOverlayFiles.

/**
     * Synchronise the map overlay files either from the local assets (if available) or from a remote url.
     *
     * @param collection Set of tiles containing a local filename and remote url.
     * @throws IOException
     */
private void processMapOverlayFiles(Collection<Tile> collection, boolean downloadAllowed) throws IOException, SVGParseException {
    // clear the tile cache on disk if any tiles have been updated
    boolean shouldClearCache = false;
    // keep track of used files, unused files are removed
    ArrayList<String> usedTiles = new ArrayList<>();
    for (Tile tile : collection) {
        final String filename = tile.filename;
        final String url = tile.url;
        usedTiles.add(filename);
        if (!MapUtils.hasTile(mContext, filename)) {
            shouldClearCache = true;
            // copy or download the tile if it is not stored yet
            if (MapUtils.hasTileAsset(mContext, filename)) {
                // file already exists as an asset, copy it
                MapUtils.copyTileAsset(mContext, filename);
            } else if (downloadAllowed && !TextUtils.isEmpty(url)) {
                try {
                    // download the file only if downloads are allowed and url is not empty
                    File tileFile = MapUtils.getTileFile(mContext, filename);
                    BasicHttpClient httpClient = new BasicHttpClient();
                    httpClient.setRequestLogger(mQuietLogger);
                    IOUtils.authorizeHttpClient(mContext, httpClient);
                    HttpResponse httpResponse = httpClient.get(url, null);
                    IOUtils.writeToFile(httpResponse.getBody(), tileFile);
                    // ensure the file is valid SVG
                    InputStream is = new FileInputStream(tileFile);
                    SVG svg = new SVGBuilder().readFromInputStream(is).build();
                    is.close();
                } catch (IOException ex) {
                    LOGE(TAG, "FAILED downloading map overlay tile " + url + ": " + ex.getMessage(), ex);
                } catch (SVGParseException ex) {
                    LOGE(TAG, "FAILED parsing map overlay tile " + url + ": " + ex.getMessage(), ex);
                }
            } else {
                LOGD(TAG, "Skipping download of map overlay tile" + " (since downloadsAllowed=false)");
            }
        }
    }
    if (shouldClearCache) {
        MapUtils.clearDiskCache(mContext);
    }
    MapUtils.removeUnusedTiles(mContext, usedTiles);
}
Also used : SVG(com.larvalabs.svgandroid.SVG) ArrayList(java.util.ArrayList) Tile(com.google.samples.apps.iosched.io.map.model.Tile) BasicHttpClient(com.turbomanage.httpclient.BasicHttpClient) HttpResponse(com.turbomanage.httpclient.HttpResponse) SVGBuilder(com.larvalabs.svgandroid.SVGBuilder) SVGParseException(com.larvalabs.svgandroid.SVGParseException)

Example 2 with SVG

use of com.larvalabs.svgandroid.SVG in project fitscales by paulburton.

the class BoardView method init.

private void init() {
    SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.wii_balance_board);
    svgLimits = svg.getLimits();
    svgPicture = svg.getPicture();
    btnPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    btnPaint.setColor(0xffb0b0b0);
    ledOnPaint = new Paint();
    ledOnPaint.setColor(0xffa0c0ff);
    ledOffPaint = new Paint();
    ledOffPaint.setColor(0xff404040);
    balancePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    balancePaint.setStyle(Style.FILL);
    balancePaint.setColor(0xff60ff60);
}
Also used : SVG(com.larvalabs.svgandroid.SVG) Paint(android.graphics.Paint)

Example 3 with SVG

use of com.larvalabs.svgandroid.SVG in project storymaker by StoryMaker.

the class OverlayCameraActivity method setOverlayImage.

private void setOverlayImage(int idx) {
    try {
        String groupPath = "images/overlays/svg/" + overlayGroup;
        if (overlays == null)
            overlays = getAssets().list(groupPath);
        bitmap = Bitmap.createBitmap(mOverlayView.getWidth(), mOverlayView.getHeight(), Bitmap.Config.ARGB_8888);
        canvas = new Canvas(bitmap);
        String imgPath = groupPath + '/' + overlays[idx];
        //    SVG svg = SVGParser.getSVGFromAsset(getAssets(), "images/overlays/svg/" + overlays[idx],0xFFFFFF,0xCC0000);
        SVG svg = SVGParser.getSVGFromAsset(getAssets(), imgPath);
        Rect rBounds = new Rect(0, 0, mOverlayView.getWidth(), mOverlayView.getHeight());
        Picture p = svg.getPicture();
        canvas.drawPicture(p, rBounds);
        mOverlayView.setImageBitmap(bitmap);
    } catch (IOException ex) {
        Timber.e(ex, "error rendering overlay", ex);
        return;
    }
}
Also used : Rect(android.graphics.Rect) SVG(com.larvalabs.svgandroid.SVG) Picture(android.graphics.Picture) Canvas(android.graphics.Canvas) IOException(java.io.IOException)

Aggregations

SVG (com.larvalabs.svgandroid.SVG)3 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Picture (android.graphics.Picture)1 Rect (android.graphics.Rect)1 Tile (com.google.samples.apps.iosched.io.map.model.Tile)1 SVGBuilder (com.larvalabs.svgandroid.SVGBuilder)1 SVGParseException (com.larvalabs.svgandroid.SVGParseException)1 BasicHttpClient (com.turbomanage.httpclient.BasicHttpClient)1 HttpResponse (com.turbomanage.httpclient.HttpResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1