org.osmdroid.api.IMapView Java Examples

The following examples show how to use org.osmdroid.api.IMapView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BingMapTileSource.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves url patterns to update urls with current map view mode and available sub domain.<br>
 * When several subdomains are available, change current sub domain in a cycle manner
 */
protected void updateBaseUrl() {
    Log.d(IMapView.LOGTAG, "updateBaseUrl");
    final String subDomain = mImageryData.getSubDomain();
    final int idx = mImageryData.m_imageUrl.lastIndexOf("/");
    if (idx > 0) {
        mBaseUrl = mImageryData.m_imageUrl.substring(0, idx);
    } else {
        mBaseUrl = mImageryData.m_imageUrl;
    }

    mUrl = mImageryData.m_imageUrl;
    if (subDomain != null) {
        mBaseUrl = String.format(mBaseUrl, subDomain);
        mUrl = String.format(mUrl, subDomain, "%s", mLocale);
    }
    Log.d(IMapView.LOGTAG, "updated url = " + mUrl);
    Log.d(IMapView.LOGTAG, "end updateBaseUrl");
}
 
Example #2
Source File: GpsMyLocationProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationChanged(final Location location) {
	if (mIgnorer==null) {
		Log.w(IMapView.LOGTAG, "GpsMyLocation provider, mIgnore is null, unexpected. Location update will be ignored");
		return;
	}
	if (location==null || location.getProvider()==null)
		return;
	// ignore temporary non-gps fix
	if (mIgnorer.shouldIgnore(location.getProvider(), System.currentTimeMillis()))
		return;

	mLocation = location;
	if (mMyLocationConsumer != null && mLocation !=null)
		mMyLocationConsumer.onLocationChanged(mLocation, this);
}
 
Example #3
Source File: MyLocationNewOverlay.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onSnapToItem(final int x, final int y, final Point snapPoint,
		final IMapView mapView) {
	if (this.mLocation != null) {
		Projection pj = mMapView.getProjection();
		pj.toPixels(mGeoPoint, mSnapPixel);
		snapPoint.x = mSnapPixel.x;
		snapPoint.y = mSnapPixel.y;
		final double xDiff = x - mSnapPixel.x;
		final double yDiff = y - mSnapPixel.y;
		boolean snap = xDiff * xDiff + yDiff * yDiff < 64;
		if (Configuration.getInstance().isDebugMode()) {
                   Log.d(IMapView.LOGTAG, "snap=" + snap);
		}
		return snap;
	} else {
		return false;
	}
}
 
Example #4
Source File: BookmarkDatastore.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public BookmarkDatastore() {

        Configuration.getInstance().getOsmdroidTileCache().mkdirs();
        db_file = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + DATABASE_FILENAME);


        try {
            mDatabase = SQLiteDatabase.openOrCreateDatabase(db_file, null);
            mDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (" +
                COLUMN_LAT+ " INTEGER , " +
                COLUMN_LON + " INTEGER, " +
                COLUMN_TITLE + " TEXT, " +
                COLUMN_ID + " TEXT, " +
                COLUMN_DESC+" TEXT, PRIMARY KEY (" + COLUMN_ID + ") );");
        } catch (Throwable ex) {
            Log.e(IMapView.LOGTAG, "Unable to start the bookmark database. Check external storage availability.", ex);
        }
    }
 
Example #5
Source File: GpsMyLocationProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Enable location updates and show your current location on the map. By default this will
 * request location updates as frequently as possible, but you can change the frequency and/or
 * distance by calling {@link #setLocationUpdateMinTime} and/or {@link
 * #setLocationUpdateMinDistance} before calling this method.
 */
@SuppressLint("MissingPermission")
@Override
public boolean startLocationProvider(IMyLocationConsumer myLocationConsumer) {
	mMyLocationConsumer = myLocationConsumer;
	boolean result = false;
	for (final String provider : mLocationManager.getProviders(true)) {
		if (locationSources.contains(provider)) {

			try {
				mLocationManager.requestLocationUpdates(provider, mLocationUpdateMinTime,
					mLocationUpdateMinDistance, this);
				result = true;
			} catch (Throwable ex) {
				Log.e(IMapView.LOGTAG, "Unable to attach listener for location provider " + provider + " check permissions?", ex);
			}
		}
	}
	return result;
}
 
Example #6
Source File: BookmarkDatastore.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public List<Marker> getBookmarksAsMarkers(MapView view) {
    List<Marker> markers = new ArrayList<>();
    try {
        //TODO order by title
        final Cursor cur = mDatabase.rawQuery("SELECT * FROM " + TABLE, null);
        while(cur.moveToNext()) {
            Marker m = new Marker(view);
            m.setId(cur.getString(cur.getColumnIndex(COLUMN_ID)));
            m.setTitle(cur.getString(cur.getColumnIndex(COLUMN_TITLE)));
            m.setSubDescription(cur.getString(cur.getColumnIndex(COLUMN_DESC)));
            m.setPosition(new GeoPoint(cur.getDouble(cur.getColumnIndex(COLUMN_LAT)),cur.getDouble(cur.getColumnIndex(COLUMN_LON))));
            m.setSnippet(m.getPosition().toDoubleString());

            markers.add(m);
        }
        cur.close();
    } catch (final Exception e) {
        Log.w(IMapView.LOGTAG,"Error getting tile sources: ", e);
    }
    return markers;
}
 
Example #7
Source File: MarkerInfoWindow.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override public void onOpen(Object item) {
	super.onOpen(item);
	
	mMarkerRef = (Marker)item;
	if (mView==null) {
		Log.w(IMapView.LOGTAG, "Error trapped, MarkerInfoWindow.open, mView is null!");
		return;
	}
	//handle image
	ImageView imageView = (ImageView)mView.findViewById(mImageId /*R.id.image*/);
	Drawable image = mMarkerRef.getImage();
	if (image != null){
		imageView.setImageDrawable(image); //or setBackgroundDrawable(image)?
		imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		imageView.setVisibility(View.VISIBLE);
	} else
		imageView.setVisibility(View.GONE);
}
 
Example #8
Source File: TileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public TileWriter() {

		if (!hasInited) {
			hasInited = true;
			// do this in the background because it takes a long time
			initThread = new Thread() {
				@Override
				public void run() {
					mUsedCacheSpace = 0; // because it's static

					calculateDirectorySize(Configuration.getInstance().getOsmdroidTileCache());

					if (mUsedCacheSpace > Configuration.getInstance().getTileFileSystemCacheMaxBytes()) {
						cutCurrentCache();
					}
					if (Configuration.getInstance().isDebugMode()) {
						Log.d(IMapView.LOGTAG, "Finished init thread");
					}
				}
			};
			initThread.setName("TileWriter#init");
			initThread.setPriority(Thread.MIN_PRIORITY);
			initThread.start();
		}
	}
 
Example #9
Source File: TileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public Drawable loadTile(final ITileSource pTileSource, final long pMapTileIndex) throws Exception{
	// 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 = getFile(pTileSource, pMapTileIndex);
	if (!file.exists()) {
		return null;
	}

	final Drawable drawable = pTileSource.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 (Configuration.getInstance().isDebugMode()) {
			Log.d(IMapView.LOGTAG,"Tile expired: " + MapTileIndex.toString(pMapTileIndex));
		}
		ExpirableBitmapDrawable.setState(drawable, ExpirableBitmapDrawable.EXPIRED);
	}

	return drawable;
}
 
Example #10
Source File: SqliteArchiveTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public SqliteArchiveTileWriter(String outputFile) throws Exception {
    // do this in the background because it takes a long time
    db_file = new File(outputFile);
    try {
        mDatabase = SQLiteDatabase.openOrCreateDatabase(db_file.getAbsolutePath(), null);
    } catch (Exception ex) {
        throw new Exception("Trouble creating database file at " + outputFile, ex);
    }
    try {

        mDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + DatabaseFileArchive.TABLE + " (" + DatabaseFileArchive.COLUMN_KEY + " INTEGER , " + DatabaseFileArchive.COLUMN_PROVIDER + " TEXT, tile BLOB, PRIMARY KEY (key, provider));");
    } catch (Throwable t) {
        t.printStackTrace();
        Log.d(IMapView.LOGTAG, "error setting db schema, it probably exists already", t);
        // throw new IOException("Trouble creating database file"+ t.getMessage());
    }
}
 
Example #11
Source File: GeoPackageProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public GeoPackageProvider(final IRegisterReceiver pRegisterReceiver,
                          final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource,
                          final Context pContext, final IFilesystemCache cacheWriter, File[] databases) {


    super(pTileSource, pRegisterReceiver);
    Log.i(IMapView.LOGTAG, "Geopackage support is BETA. Please report any issues");

    if (cacheWriter != null) {
        tileWriter = cacheWriter;
    } else {
        if (Build.VERSION.SDK_INT < 10) {
            tileWriter = new TileWriter();
        } else {
            tileWriter = new SqlTileWriter();
        }
    }

    mTileProviderList.add(MapTileProviderBasic.getMapTileFileStorageProviderBase(pRegisterReceiver, pTileSource, tileWriter));
    geopackage = new GeoPackageMapTileModuleProvider(databases, pContext, tileWriter);
    mTileProviderList.add(geopackage);


}
 
Example #12
Source File: MapTileModuleProviderBase.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public void loadMapTileAsync(final MapTileRequestState pState) {
	// Make sure we're not detached
	if (mExecutor.isShutdown())
		return;

	synchronized (mQueueLockObject) {
		if (Configuration.getInstance().isDebugTileProviders()) {
			Log.d(IMapView.LOGTAG,"MapTileModuleProviderBase.loadMaptileAsync() on provider: "
					+ getName() + " for tile: " + MapTileIndex.toString(pState.getMapTile()));
			if (mPending.containsKey(pState.getMapTile()))
				Log.d(IMapView.LOGTAG,"MapTileModuleProviderBase.loadMaptileAsync() tile already exists in request queue for modular provider. Moving to front of queue.");
			else
				Log.d(IMapView.LOGTAG,"MapTileModuleProviderBase.loadMaptileAsync() adding tile to request queue for modular provider.");
		}

		// this will put the tile in the queue, or move it to the front of
		// the queue if it's already present
		mPending.put(pState.getMapTile(), pState);
	}
	try {
		mExecutor.execute(getTileLoader());
	} catch (final RejectedExecutionException e) {
		Log.w(IMapView.LOGTAG,"RejectedExecutionException", e);
	}
}
 
Example #13
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a specific tile from the cache
 *
 * @since 5.6
 */
@Override
public boolean remove(final ITileSource pTileSourceInfo, final long pMapTileIndex) {
    final SQLiteDatabase db = getDb();
    if (db == null || !db.isOpen()) {
        Log.d(IMapView.LOGTAG, "Unable to delete cached tile from " + pTileSourceInfo.name() + " " + MapTileIndex.toString(pMapTileIndex) + ", database not available.");
        Counters.fileCacheSaveErrors++;
        return false;
    }
    try {
        final long index = getIndex(pMapTileIndex);
        db.delete(DatabaseFileArchive.TABLE, primaryKey, getPrimaryKeyParameters(index, pTileSourceInfo));
        return true;
    } catch (Exception ex) {
        //note, although we check for db null state at the beginning of this method, it's possible for the
        //db to be closed during the execution of this method
        Log.e(IMapView.LOGTAG, "Unable to delete cached tile from " + pTileSourceInfo.name() + " " + MapTileIndex.toString(pMapTileIndex) + " db is " + (db == null ? "null" : "not null"), ex);
        Counters.fileCacheSaveErrors++;
        catchException(ex);
    }
    return false;
}
 
Example #14
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
* Returns the expiry time of the tile that expires first.
*/
public long getFirstExpiry() {
    final SQLiteDatabase db = getDb();
    if (db == null || !db.isOpen()) {
        return 0;
    }
    try {
        Cursor cursor = db.rawQuery("select min(" + COLUMN_EXPIRES + ") from " + TABLE, null);
        cursor.moveToFirst();
        long time = cursor.getLong(0);
        cursor.close();
        return time;
    } catch (Exception ex) {
        Log.e(IMapView.LOGTAG, "Unable to query for oldest tile", ex);
        catchException(ex);
    }
    return 0;
}
 
Example #15
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public Long getExpirationTimestamp(final ITileSource pTileSource, final long pMapTileIndex) {
    Cursor cursor = null;
    try {
        cursor = getTileCursor(getPrimaryKeyParameters(getIndex(pMapTileIndex), pTileSource), expireQueryColumn);
        if(cursor.moveToNext()) {
            return cursor.getLong(0);
        }
    } catch (Exception ex) {
        Log.e(IMapView.LOGTAG, "error getting expiration date from the tile cache", ex);
        catchException(ex);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return null;
}
 
Example #16
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.0.2
 */
protected SQLiteDatabase getDb() {
    if (mDb != null) {
        return mDb;
    }
    synchronized (mLock) {
        Configuration.getInstance().getOsmdroidTileCache().mkdirs();
        db_file = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + DATABASE_FILENAME);
        if (mDb == null) {
            try {
                mDb = SQLiteDatabase.openOrCreateDatabase(db_file, null);
                mDb.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (" + DatabaseFileArchive.COLUMN_KEY + " INTEGER , " + DatabaseFileArchive.COLUMN_PROVIDER + " TEXT, " + DatabaseFileArchive.COLUMN_TILE + " BLOB, " + COLUMN_EXPIRES + " INTEGER, PRIMARY KEY (" + DatabaseFileArchive.COLUMN_KEY + ", " + DatabaseFileArchive.COLUMN_PROVIDER + "));");
            } catch (Exception ex) {
                Log.e(IMapView.LOGTAG, "Unable to start the sqlite tile writer. Check external storage availability.", ex);
                catchException(ex);
                return null;
            }
        }
    }
    return mDb;
}
 
Example #17
Source File: MapTileFileArchiveProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private synchronized InputStream getInputStream(final long pMapTileIndex,
		final ITileSource tileSource) {
	for (final IArchiveFile archiveFile : mArchiveFiles) {
		if (archiveFile!=null) {
			final InputStream in = archiveFile.getInputStream(tileSource, pMapTileIndex);
			if (in != null) {
				if (Configuration.getInstance().isDebugMode()) {
					Log.d(IMapView.LOGTAG, "Found tile " + MapTileIndex.toString(pMapTileIndex) + " in " + archiveFile);
				}
				return in;
			}
		}
	}

	return null;
}
 
Example #18
Source File: TileDownloader.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.0.3
 * @return the max-age corresponding to the http header (in seconds), or null
 * @deprecated Use {@link TileSourcePolicy#getHttpCacheControlDuration(String)} instead
 */
@Deprecated
public Long getHttpCacheControlDuration(final String pHttpCacheControlHeader) {
    if (pHttpCacheControlHeader != null && pHttpCacheControlHeader.length() > 0) {
        try {
            final String[] parts = pHttpCacheControlHeader.split(", ");
            final String maxAge = "max-age=";
            for (final String part : parts) {
                final int pos = part.indexOf(maxAge);
                if (pos == 0) {
                    final String durationString = part.substring(maxAge.length());
                    return Long.valueOf(durationString);
                }
            }
        } catch (final Exception ex) {
            if (Configuration.getInstance().isDebugMapTileDownloader())
                Log.d(IMapView.LOGTAG,
                        "Unable to parse cache control tag for tile, server returned " + pHttpCacheControlHeader, ex);
        }
    }
    return null;
}
 
Example #19
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * this could be a long running operation, don't run on the UI thread unless necessary.
 * This function prunes the database for old or expired tiles.
 *
 * @since 5.6
 */
public void runCleanupOperation() {
    final SQLiteDatabase db = getDb();
    if (db == null || !db.isOpen()) {
        if (Configuration.getInstance().isDebugMode()) {
            Log.d(IMapView.LOGTAG, "Finished init thread, aborted due to null database reference");
        }
        return;
    }

    // index creation is run now (regardless of the table size)
    // therefore potentially on a small table, for better index creation performances
    createIndex(db);

    final long dbLength = db_file.length();
    if (dbLength <= Configuration.getInstance().getTileFileSystemCacheMaxBytes()) {
        return;
    }

    runCleanupOperation(
            dbLength - Configuration.getInstance().getTileFileSystemCacheTrimBytes(),
            Configuration.getInstance().getTileGCBulkSize(),
            Configuration.getInstance().getTileGCBulkPauseInMillis(),
            true);
}
 
Example #20
Source File: MapTileProviderBase.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void handleTile(final long pMapTileIndex, final int pX, final int pY) {
	if (!isWorth) {
		return;
	}

	// Get tile from cache.
	// If it's found then no need to created scaled version.
	// If not found (null) them we've initiated a new request for it,
	// and now we'll create a scaled version until the request completes.
	final Drawable requestedTile = getMapTile(pMapTileIndex);
	if (requestedTile == null) {
		try {
			computeTile(pMapTileIndex, pX, pY);
		} catch(final OutOfMemoryError e) {
			Log.e(IMapView.LOGTAG,"OutOfMemoryError rescaling cache");
		}
	}
}
 
Example #21
Source File: SafeTileWriter.java    From android_frameworks_mapsv1 with Apache License 2.0 6 votes vote down vote up
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;
	}
}
 
Example #22
Source File: CacheManager.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public CacheManagerAction getDownloadingAction() {
    return new CacheManagerAction() {
        @Override
        public boolean preCheck() {
            if (mTileSource instanceof OnlineTileSourceBase) {
                if (!((OnlineTileSourceBase) mTileSource).getTileSourcePolicy().acceptsBulkDownload()) {
                    throw new TileSourcePolicyException("This online tile source doesn't support bulk download");
                }
                return true;
            } else {
                Log.e(IMapView.LOGTAG, "TileSource is not an online tile source");
                return false;
            }
        }

        @Override
        public int getProgressModulo() {
            return 10;
        }

        @Override
        public boolean tileAction(final long pMapTileIndex) {
            return !loadTile((OnlineTileSourceBase) mTileSource, pMapTileIndex);
        }
    };
}
 
Example #23
Source File: ManifestUtil.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve a key from the manifest meta data, or empty string if not found.
 */
public static String retrieveKey(final Context aContext, final String aKey) {

    // get the key from the manifest
    final PackageManager pm = aContext.getPackageManager();
    try {
        final ApplicationInfo info = pm.getApplicationInfo(aContext.getPackageName(),
	PackageManager.GET_META_DATA);
        if (info.metaData == null) {
            Log.i(IMapView.LOGTAG,"Key %s not found in manifest"+aKey);
        } else {
            final String value = info.metaData.getString(aKey);
            if (value == null) {
                Log.i(IMapView.LOGTAG,"Key %s not found in manifest"+aKey);
            } else {
                return value.trim();
            }
        }
    } catch (final PackageManager.NameNotFoundException e) {
        Log.i(IMapView.LOGTAG,"Key %s not found in manifest" +aKey);
    }
    return "";
}
 
Example #24
Source File: TileSourcePolicy.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * @since 6.1.7
 * Used to be in {@link TileDownloader}
 * @return the max-age corresponding to the http header (in seconds), or null
 */
public Long getHttpCacheControlDuration(final String pHttpCacheControlHeader) {
    if (pHttpCacheControlHeader != null && pHttpCacheControlHeader.length() > 0) {
        try {
            final String[] parts = pHttpCacheControlHeader.split(", ");
            final String maxAge = "max-age=";
            for (final String part : parts) {
                final int pos = part.indexOf(maxAge);
                if (pos == 0) {
                    final String durationString = part.substring(maxAge.length());
                    return Long.valueOf(durationString);
                }
            }
        } catch (final Exception ex) {
            if (Configuration.getInstance().isDebugMapTileDownloader())
                Log.d(IMapView.LOGTAG,
                        "Unable to parse cache control tag for tile, server returned " + pHttpCacheControlHeader, ex);
        }
    }
    return null;
}
 
Example #25
Source File: DefaultOverlayManager.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSnapToItem(final int x, final int y, final Point snapPoint, final IMapView pMapView) {
    for (final Overlay overlay : this.overlaysReversed()) {
        if (overlay instanceof Snappable) {
            if (((Snappable) overlay).onSnapToItem(x, y, snapPoint, pMapView)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #26
Source File: MapTileFileArchiveProvider.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable loadTile(final long pMapTileIndex) {

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

	InputStream inputStream = null;
	try {
		if (Configuration.getInstance().isDebugMode()) {
			Log.d(IMapView.LOGTAG,"Archives - Tile doesn't exist: " + MapTileIndex.toString(pMapTileIndex));
		}

		inputStream = getInputStream(pMapTileIndex, tileSource);
		if (inputStream != null) {
			if (Configuration.getInstance().isDebugMode()) {
				Log.d(IMapView.LOGTAG,"Use tile from archive: " + MapTileIndex.toString(pMapTileIndex));
			}
			final Drawable drawable = tileSource.getDrawable(inputStream);
			returnValue = drawable;
		}
	} catch (final Throwable e) {
		Log.e(IMapView.LOGTAG,"Error loading tile", e);
	} finally {
		if (inputStream != null) {
			StreamUtils.closeStream(inputStream);
		}
	}

	return returnValue;
}
 
Example #27
Source File: TileDownloader.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.0.3
 * @return the Epoch timestamp corresponding to the http header (in milliseconds), or null
 * @deprecated Use {@link TileSourcePolicy#getHttpExpiresTime(String)} instead
 */
@Deprecated
public Long getHttpExpiresTime(final String pHttpExpiresHeader) {
    if (pHttpExpiresHeader != null && pHttpExpiresHeader.length() > 0) {
        try {
            final Date dateExpires = Configuration.getInstance().getHttpHeaderDateTimeFormat().parse(pHttpExpiresHeader);
            return dateExpires.getTime();
        } catch (final Exception ex) {
            if (Configuration.getInstance().isDebugMapTileDownloader())
                Log.d(IMapView.LOGTAG, "Unable to parse expiration tag for tile, server returned " + pHttpExpiresHeader, ex);
        }
    }
    return null;
}
 
Example #28
Source File: MapTileProviderBase.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Called by implementation class methods indicating that they have completed the request as
 * best it can. The tile is added to the cache, and a MAPTILE_SUCCESS_ID message is sent.
 *
 * @param pState
 *            the map tile request state object
 * @param pDrawable
 *            the Drawable of the map tile
 */
@Override
public void mapTileRequestCompleted(final MapTileRequestState pState, final Drawable pDrawable) {
	// put the tile in the cache
	putTileIntoCache(pState.getMapTile(), pDrawable, ExpirableBitmapDrawable.UP_TO_DATE);

	// tell our caller we've finished and it should update its view
	sendMessage(MAPTILE_SUCCESS_ID);

	if (Configuration.getInstance().isDebugTileProviders()) {
              Log.d(IMapView.LOGTAG,"MapTileProviderBase.mapTileRequestCompleted(): " + MapTileIndex.toString(pState.getMapTile()));
	}
}
 
Example #29
Source File: SqlTileWriter.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * purges and deletes everything from the cache database
 *
 * @return
 * @since 5.6
 */
public boolean purgeCache() {
    final SQLiteDatabase db = getDb();
    if (db != null && db.isOpen()) {
        try {
            db.delete(TABLE, null, null);
            return true;
        } catch (Exception e) {
            Log.w(IMapView.LOGTAG, "Error purging the db", e);
            catchException(e);
        }
    }
    return false;
}
 
Example #30
Source File: MapTileProviderBase.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Called by implementation class methods indicating that they have failed to retrieve the
 * requested map tile. a MAPTILE_FAIL_ID message is sent.
 *
 * @param pState
 *            the map tile request state object
 */
@Override
public void mapTileRequestFailed(final MapTileRequestState pState) {

	if (mTileNotFoundImage!=null) {
		putTileIntoCache(pState.getMapTile(), mTileNotFoundImage, ExpirableBitmapDrawable.NOT_FOUND);
		sendMessage(MAPTILE_SUCCESS_ID);
	} else {
		sendMessage(MAPTILE_FAIL_ID);
	}
	if (Configuration.getInstance().isDebugTileProviders()) {
		Log.d(IMapView.LOGTAG,"MapTileProviderBase.mapTileRequestFailed(): " + MapTileIndex.toString(pState.getMapTile()));
	}
}