use of com.google.samples.apps.iosched.io.map.model.Tile in project iosched by google.
the class MapPropertyHandler method buildTiles.
private void buildTiles(ArrayList<ContentProviderOperation> list) {
Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(ScheduleContract.MapTiles.CONTENT_URI);
list.add(ContentProviderOperation.newDelete(uri).build());
for (String floor : mTileOverlays.keySet()) {
Tile tileOverlay = mTileOverlays.get(floor);
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
builder.withValue(ScheduleContract.MapTiles.TILE_FLOOR, floor);
builder.withValue(ScheduleContract.MapTiles.TILE_FILE, tileOverlay.filename);
builder.withValue(ScheduleContract.MapTiles.TILE_URL, tileOverlay.url);
list.add(builder.build());
}
}
use of com.google.samples.apps.iosched.io.map.model.Tile 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);
}
Aggregations