TileCache: fix samples, improves #112, closes #116

This commit is contained in:
Emux 2016-08-09 12:20:47 +03:00
parent 85adc04a05
commit 1db23decca
3 changed files with 34 additions and 10 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Stephan Leuschner
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -107,7 +108,9 @@ public class TileCache implements ITileCache {
if (dbg)
log.debug("open cache {}, {}", cacheDirectory, dbName);
dbHelper = new SQLiteHelper(context, new File(cacheDirectory, dbName).getAbsolutePath());
if (cacheDirectory != null)
dbName = new File(cacheDirectory, dbName).getAbsolutePath();
dbHelper = new SQLiteHelper(context, dbName);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
dbHelper.setWriteAheadLoggingEnabled(true);

View File

@ -1,6 +1,24 @@
/*
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.app;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.oscim.android.cache.TileCache;
import org.oscim.layers.GenericLayer;
@ -26,8 +44,6 @@ public class MapLayers {
final static Logger log = LoggerFactory.getLogger(MapLayers.class);
private static final String CACHE_DIRECTORY = "/Android/data/org.oscim.app/cache/";
abstract static class Config {
final String name;
@ -71,7 +87,8 @@ public class MapLayers {
setBackgroundMap(-1);
}
void setBaseMap(SharedPreferences preferences) {
void setBaseMap(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String dbname = preferences.getString("mapDatabase", "OPENSCIENCEMAP4");
if (dbname.equals(mMapDatabase) && mBaseLayer != null)
@ -89,7 +106,7 @@ public class MapLayers {
}
if (tileSource instanceof UrlTileSource) {
mCache = new TileCache(App.activity, CACHE_DIRECTORY, dbname);
mCache = new TileCache(App.activity, context.getExternalCacheDir().getAbsolutePath(), dbname);
mCache.setCacheSize(512 * (1 << 10));
tileSource.setCache(mCache);
} else {
@ -106,8 +123,10 @@ public class MapLayers {
mMapDatabase = dbname;
}
void setPreferences(SharedPreferences preferences) {
setBaseMap(preferences);
void setPreferences(Context context) {
setBaseMap(context);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
ThemeFile theme = VtmThemes.DEFAULT;
if (preferences.contains("theme")) {

View File

@ -1,5 +1,6 @@
/* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2012 Hannes Janetzek
* Copyright 2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -12,7 +13,6 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.app;
import android.app.AlertDialog;
@ -81,8 +81,9 @@ public class TileMap extends MapActivity implements MapEventsReceiver {
App.activity = this;
mMapLayers = new MapLayers();
mMapLayers.setBaseMap(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mMapLayers.setBaseMap(prefs);
if (!prefs.contains("distanceTouch"))
prefs.edit().putBoolean("distanceTouch", true).apply();
@ -347,8 +348,9 @@ public class TileMap extends MapActivity implements MapEventsReceiver {
mCompass.resume();
mLocation.resume();
mMapLayers.setPreferences(this);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
mMapLayers.setPreferences(preferences);
if (preferences.getBoolean("fullscreen", false)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);