Search in sources :

Example 6 with Tile

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;
}
Also used : Tile(com.google.android.gms.maps.model.Tile)

Example 7 with 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;
}
Also used : DiskLruCache(com.jakewharton.disklrucache.DiskLruCache) Tile(com.google.android.gms.maps.model.Tile) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Aggregations

Tile (com.google.android.gms.maps.model.Tile)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Cursor (android.database.Cursor)2 IOException (java.io.IOException)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 MenuItem (android.view.MenuItem)1 ViewGroup (android.view.ViewGroup)1 RelativeLayout (android.widget.RelativeLayout)1 GoogleMap (com.google.android.gms.maps.GoogleMap)1 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)1 CameraPosition (com.google.android.gms.maps.model.CameraPosition)1 LatLng (com.google.android.gms.maps.model.LatLng)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 TileProvider (com.google.android.gms.maps.model.TileProvider)1 DiskLruCache (com.jakewharton.disklrucache.DiskLruCache)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1