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);
}
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);
}
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;
}
}
Aggregations