/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(BoundingBox, byte, Canvas, Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if one or more of the following two conditions apply: * <ul> * <li>The {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#isExpired()} method returns {@code True}.</li> * <li>The layer has a time-to-live (TTL) set ({@link #getCacheTimeToLive()} returns a nonzero value) and the sum of * the {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()} and TTL is less than current * time (as returned by {@link java.lang.System#currentTimeMillis()}).</li> * </ul> * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update * the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which * cannot be reached), the stale tile will continue to be used until another * {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. This parameter is not used for a {@code TileDownloadLayer} and can be null. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { if (bitmap.isExpired()) return true; return cacheTimeToLive != 0 && ((bitmap.getTimestamp() + cacheTimeToLive) < System.currentTimeMillis()); }
/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(BoundingBox, byte, Canvas, Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if one or more of the following two conditions apply: * <ul> * <li>The {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#isExpired()} method returns {@code True}.</li> * <li>The layer has a time-to-live (TTL) set ({@link #getCacheTimeToLive()} returns a nonzero value) and the sum of * the {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()} and TTL is less than current * time (as returned by {@link java.lang.System#currentTimeMillis()}).</li> * </ul> * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update * the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which * cannot be reached), the stale tile will continue to be used until another * {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. This parameter is not used for a {@code TileDownloadLayer} and can be null. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { if (bitmap.isExpired()) return true; return cacheTimeToLive != 0 && ((bitmap.getTimestamp() + cacheTimeToLive) < System.currentTimeMillis()); }