@Override public Drawable loadTile(final MapTileRequestState pState) { if (mTileSource == null) { return null; } final MapTile pTile = pState.getMapTile(); // if there's no sdcard then don't do anything if (!getSdCardAvailable()) { if (DEBUGMODE) { logger.debug("No sdcard - do nothing for tile: " + pTile); } return null; } // Check the tile source to see if its file is available and if so, then render the // drawable and return the tile final File file = new File( TILE_PATH_BASE, mTileSource.getTileRelativeFilenameString(pTile) + TILE_PATH_EXTENSION); if (file.exists()) { // Check to see if file has expired final long now = System.currentTimeMillis(); final long lastModified = file.lastModified(); final boolean fileExpired = lastModified < now - mMaximumCachedFileAge; if (!fileExpired) { // If the file has not expired, then render it and return it! final Drawable drawable = mTileSource.getDrawable(file.getPath()); return drawable; } else { // If the file has expired then we render it, but we return it as a candidate // and then fail on the request. This allows the tile to be loaded, but also // allows other tile providers to do a better job. final Drawable drawable = mTileSource.getDrawable(file.getPath()); tileCandidateLoaded(pState, drawable); return null; } } // If we get here then there is no file in the file cache return null; }
@Override public Drawable loadTile(final MapTileRequestState pState) { ITileSource tileSource = mTileSource.get(); if (tileSource == null) { return null; } final MapTile pTile = pState.getMapTile(); // if there's no sdcard then don't do anything if (!getSdCardAvailable()) { if (OpenStreetMapTileProviderConstants.DEBUGMODE) { Log.d(IMapView.LOGTAG, "No sdcard - do nothing for tile: " + pTile); } return null; } InputStream inputStream = null; try { if (OpenStreetMapTileProviderConstants.DEBUGMODE) { Log.d(IMapView.LOGTAG, "Tile doesn't exist: " + pTile); } inputStream = getInputStream(pTile, tileSource); if (inputStream != null) { if (OpenStreetMapTileProviderConstants.DEBUGMODE) { Log.d(IMapView.LOGTAG, "Use tile from archive: " + pTile); } final Drawable drawable = tileSource.getDrawable(inputStream); return drawable; } } catch (final Throwable e) { Log.e(IMapView.LOGTAG, "Error loading tile", e); } finally { if (inputStream != null) { StreamUtils.closeStream(inputStream); } } return null; }