use of com.google.android.gms.maps.model.Tile in project iosched by google.
the class CachedTileProvider method getTile.
/**
* Load a tile.
* If cached, the data for the tile is read from the underlying cache, otherwise the tile is
* generated by the {@link com.google.android.gms.maps.model.TileProvider} and added to the
* cache.
*/
@Override
public Tile getTile(int x, int y, int zoom) {
final String key = CachedTileProvider.generateKey(x, y, zoom, mKeyTag);
Tile tile = getCachedTile(key);
if (tile == null) {
// tile not cached, load from provider and then cache
tile = mTileProvider.getTile(x, y, zoom);
if (cacheTile(key, tile)) {
LOGD(TAG, "Added tile to cache " + key);
}
}
return tile;
}
use of com.google.android.gms.maps.model.Tile in project iosched by google.
the class CachedTileProvider method getCachedTile.
/**
* Load a tile from cache.
* Returns null if there is no corresponding cache entry or it could not be loaded.
*/
private Tile getCachedTile(String key) {
if (mCache.isClosed()) {
return null;
}
try {
DiskLruCache.Snapshot snapshot = mCache.get(key);
if (snapshot == null) {
// tile is not in cache
return null;
}
final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA));
final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT));
final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH));
if (data != null) {
LOGD(TAG, "Cache hit for tile " + key);
return new Tile(width, height, data);
}
} catch (IOException e) {
// ignore error
}
return null;
}
Aggregations