Java源码示例:org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants

示例1
private boolean createFolderAndCheckIfExists(final File pFile) {
	if (pFile.mkdirs()) {
		return true;
	}
	if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
		Log.d(IMapView.LOGTAG,"Failed to create " + pFile + " - wait and check again");
	}

	// if create failed, wait a bit in case another thread created it
	try {
		Thread.sleep(500);
	} catch (final InterruptedException ignore) {
	}
	// and then check again
	if (pFile.exists()) {
		if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
			Log.d(IMapView.LOGTAG,"Seems like another thread created " + pFile);
		}
		return true;
	} else {
		if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
			Log.d(IMapView.LOGTAG,"File still doesn't exist: " + pFile);
		}
		return false;
	}
}
 
示例2
/**
 * @since 6.0.3
 * @return the expiration time (as Epoch timestamp in milliseconds)
 * @deprecated Use {@link TileSourcePolicy#computeExpirationTime(HttpURLConnection, long)} instead
 */
@Deprecated
public long computeExpirationTime(final String pHttpExpiresHeader, final String pHttpCacheControlHeader, final long pNow) {
    final Long override=Configuration.getInstance().getExpirationOverrideDuration();
    if (override != null) {
        return pNow + override;
    }

    final long extension = Configuration.getInstance().getExpirationExtendedDuration();
    final Long cacheControlDuration = getHttpCacheControlDuration(pHttpCacheControlHeader);
    if (cacheControlDuration != null) {
        return pNow + cacheControlDuration * 1000 + extension;
    }

    final Long httpExpiresTime = getHttpExpiresTime(pHttpExpiresHeader);
    if (httpExpiresTime != null) {
        return httpExpiresTime + extension;
    }

    return pNow + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + extension;
}
 
示例3
/**
 * @since 6.1.7
 * Used to be in {@link TileDownloader}
 * @return the expiration time (as Epoch timestamp in milliseconds)
 */
public long computeExpirationTime(final String pHttpExpiresHeader, final String pHttpCacheControlHeader, final long pNow) {
    final Long override=Configuration.getInstance().getExpirationOverrideDuration();
    if (override != null) {
        return pNow + override;
    }

    final long extension = Configuration.getInstance().getExpirationExtendedDuration();
    final Long cacheControlDuration = getHttpCacheControlDuration(pHttpCacheControlHeader);
    if (cacheControlDuration != null) {
        return pNow + cacheControlDuration * 1000 + extension;
    }

    final Long httpExpiresTime = getHttpExpiresTime(pHttpExpiresHeader);
    if (httpExpiresTime != null) {
        return httpExpiresTime + extension;
    }

    return pNow + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + extension;
}
 
示例4
@Override
public boolean saveFile(final ITileSource pTileSource, final MapTile pTile,
						final InputStream pStream) {

	final File file = new File(safeTilePathBase, pTileSource.getTileRelativeFilenameString(pTile)
			+ OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);

	final File parent = file.getParentFile();
	if (!parent.exists() && !createFolderAndCheckIfExists(parent)) {
		return false;
	}

	BufferedOutputStream outputStream = null;
	try {
		outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()),
				StreamUtils.IO_BUFFER_SIZE);
		final long length = StreamUtils.copy(pStream, outputStream);

		mUsedCacheSpace += length;
		if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_MAX_CACHE_SIZE_BYTES) {
			cutCurrentCache(); // TODO perhaps we should do this in the background
		}
	} catch (final IOException e) {
		return false;
	} finally {
		if (outputStream != null) {
			StreamUtils.closeStream(outputStream);
		}
	}
	return true;
}
 
示例5
/**
 * If the cache size is greater than the max then trim it down to the trim level. This method is
 * synchronized so that only one thread can run it at a time.
 */
private void cutCurrentCache() {

	final File lock=safeTilePathBase;
	synchronized (lock) {

		if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {

			Log.d(IMapView.LOGTAG,"Trimming tile cache from " + mUsedCacheSpace + " to "
					+ OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES);

			final List<File> z = getDirectoryFileList(safeTilePathBase);

			// order list by files day created from old to new
			final File[] files = z.toArray(new File[0]);
			Arrays.sort(files, new Comparator<File>() {
				@Override
				public int compare(final File f1, final File f2) {
					return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
				}
			});

			for (final File file : files) {
				if (mUsedCacheSpace <= OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {
					break;
				}

				final long length = file.length();
				if (file.delete()) {
					mUsedCacheSpace -= length;
				}
			}

			Log.d(IMapView.LOGTAG,"Finished trimming tile cache");
		}
	}
}
 
示例6
@Override
public int getMaximumZoomLevel() {
	int result = OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
	synchronized (mTileProviderList) {
		for (final MapTileModuleProviderBase tileProvider : mTileProviderList) {
			if (tileProvider.getMaximumZoomLevel() > result) {
				result = tileProvider.getMaximumZoomLevel();
			}
		}
	}
	return result;
}
 
示例7
private void computeZoomLevels() {
    boolean first = true;
    minZoomLevel = OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
    for (final MapTileModuleProviderBase provider : mProviders) {
        final int otherMin = provider.getMinimumZoomLevel();;
        if (first) {
            first = false;
            minZoomLevel = otherMin;
        } else {
            minZoomLevel = Math.min(minZoomLevel, otherMin);
        }
    }
}
 
示例8
/**
 * Approximate a tile from a lower zoom level
 *
 * @since 6.0.0
 * @param pMapTileIndex Destination tile, for the same place on the planet as the source, but on a higher zoom
 * @return
 */
public Bitmap approximateTileFromLowerZoom(final long pMapTileIndex) {
    for (int zoomDiff = 1; MapTileIndex.getZoom(pMapTileIndex) - zoomDiff >= OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL ; zoomDiff ++) {
        final Bitmap bitmap = approximateTileFromLowerZoom(pMapTileIndex, zoomDiff);
        if (bitmap != null) {
            return bitmap;
        }
    }
    return null;
}
 
示例9
/**
 * @since 6.1.7
 * @return the expiration time (as Epoch timestamp in milliseconds)
 */
public long computeExpirationTime(final HttpURLConnection pHttpURLConnection, final long pNow) {
    final String expires = pHttpURLConnection.getHeaderField(OpenStreetMapTileProviderConstants.HTTP_EXPIRES_HEADER);
    final String cacheControl = pHttpURLConnection.getHeaderField(OpenStreetMapTileProviderConstants.HTTP_CACHECONTROL_HEADER);
    final long result = computeExpirationTime(expires, cacheControl, pNow);
    if (Configuration.getInstance().isDebugMapTileDownloader()) {
        Log.d(IMapView.LOGTAG, "computeExpirationTime('" + expires + "','" + cacheControl + "'," + pNow + "=" + result);
    }
    return result;
}
 
示例10
public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
								 final ITileSource aTileSource) {
	this(context, pRegisterReceiver, aTileSource, OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE);
}
 
示例11
public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
									 final ITileSource pTileSource, final long pMaximumCachedFileAge) {
	this(context, pRegisterReceiver, pTileSource, pMaximumCachedFileAge,
			OpenStreetMapTileProviderConstants.NUMBER_OF_TILE_FILESYSTEM_THREADS,
			OpenStreetMapTileProviderConstants.TILE_FILESYSTEM_MAXIMUM_QUEUE_SIZE);
}
 
示例12
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
示例13
@Override
public Drawable loadTile(final MapTileRequestState pState) throws CantContinueException {

	ITileSource tileSource = mTileSource.get();
	if (tileSource == null) {
		return null;
	}

	final MapTile tile = 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: " + tile);
		}
		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(safeTilePathBase,
			tileSource.getTileRelativeFilenameString(tile) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
	if (file.exists()) {

		try {
			final Drawable drawable = tileSource.getDrawable(file.getPath());

			// 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 && drawable != null) {
				if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
					Log.d(IMapView.LOGTAG,"Tile expired: " + tile);
				}
				ExpirableBitmapDrawable.setDrawableExpired(drawable);
			}

			return drawable;
		} catch (final LowMemoryException e) {
			// low memory so empty the queue
			Log.w(IMapView.LOGTAG,"LowMemoryException downloading MapTile: " + tile + " : " + e);
			throw new CantContinueException(e);
		}
	}

	// If we get here then there is no file in the file cache
	return null;
}
 
示例14
/**
 *
 * @since 5.6.5
 */
public File getFile(final ITileSource pTileSource, final long pMapTileIndex) {
	return new File(Configuration.getInstance().getOsmdroidTileCache(), pTileSource.getTileRelativeFilenameString(pMapTileIndex)
			+ OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
}
 
示例15
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
示例16
public MapTileFilesystemProvider(final IRegisterReceiver pRegisterReceiver,
		final ITileSource aTileSource) {
	this(pRegisterReceiver, aTileSource, Configuration.getInstance().getExpirationExtendedDuration() + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE);
}
 
示例17
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
示例18
@Override
public int getMinimumZoomLevel() {
	OnlineTileSourceBase tileSource = mTileSource.get();
	return (tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL);
}
 
示例19
@Override
public int getMinimumZoomLevel() {
    ITileSource tileSource = mTileSource.get();
    return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
示例20
@Override
public int getMinimumZoomLevel() {
	ITileSource tileSource = mTileSource.get();
	return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
}
 
示例21
public static File getFileName(ITileSource tileSource, final long pMapTileIndex) {
    final File file = new File(Configuration.getInstance().getOsmdroidTileCache(),
            tileSource.getTileRelativeFilenameString(pMapTileIndex) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
    return file;
}