remember theme preference
This commit is contained in:
parent
1a27f56313
commit
b210c5ee73
@ -14,6 +14,9 @@
|
||||
*/
|
||||
package org.mapsforge.android;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.mapsforge.android.rendertheme.InternalRenderTheme;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.core.MapPosition;
|
||||
|
||||
@ -37,6 +40,7 @@ public abstract class MapActivity extends Activity {
|
||||
private static final String KEY_MAP_FILE = "mapFile";
|
||||
private static final String KEY_ZOOM_LEVEL = "zoomLevel";
|
||||
private static final String PREFERENCES_FILE = "MapActivity";
|
||||
private static final String KEY_THEME = "Theme";
|
||||
|
||||
private static boolean containsMapViewPosition(SharedPreferences sharedPreferences) {
|
||||
return sharedPreferences.contains(KEY_LATITUDE)
|
||||
@ -44,23 +48,15 @@ public abstract class MapActivity extends Activity {
|
||||
&& sharedPreferences.contains(KEY_ZOOM_LEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counter to store the last ID given to a MapView.
|
||||
*/
|
||||
private int lastMapViewId;
|
||||
|
||||
/**
|
||||
* Internal list which contains references to all running MapView objects.
|
||||
*/
|
||||
private MapView mMapView;
|
||||
|
||||
private void destroyMapViews() {
|
||||
mMapView.destroy();
|
||||
}
|
||||
|
||||
private void restoreMapView(MapView mapView) {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE,
|
||||
MODE_PRIVATE);
|
||||
|
||||
if (containsMapViewPosition(sharedPreferences)) {
|
||||
|
||||
if (sharedPreferences.contains(KEY_MAP_FILE)) {
|
||||
@ -77,12 +73,25 @@ public abstract class MapActivity extends Activity {
|
||||
MapPosition mapPosition = new MapPosition(geoPoint, (byte) zoomLevel, 1);
|
||||
mapView.setCenterAndZoom(mapPosition);
|
||||
}
|
||||
|
||||
String theme = sharedPreferences.getString(KEY_THEME,
|
||||
InternalRenderTheme.OSMARENDER.name());
|
||||
|
||||
if (theme.startsWith("/")) {
|
||||
try {
|
||||
mapView.setRenderTheme(theme);
|
||||
} catch (FileNotFoundException e) {
|
||||
mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
||||
}
|
||||
} else {
|
||||
mapView.setRenderTheme(InternalRenderTheme.valueOf(theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
destroyMapViews();
|
||||
mMapView.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,6 +116,8 @@ public abstract class MapActivity extends Activity {
|
||||
editor.putString(KEY_MAP_FILE, mMapView.getMapFile());
|
||||
}
|
||||
|
||||
editor.putString(KEY_THEME, mMapView.getRenderTheme());
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@ -116,13 +127,6 @@ public abstract class MapActivity extends Activity {
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a unique MapView ID on each call.
|
||||
*/
|
||||
final int getMapViewId() {
|
||||
return ++lastMapViewId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called once by each MapView during its setup process.
|
||||
*
|
||||
|
||||
@ -94,8 +94,6 @@ public class MapView extends GLSurfaceView {
|
||||
private DebugSettings debugSettings;
|
||||
private String mMapFile;
|
||||
|
||||
private File cacheDir;
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* the enclosing MapActivity instance.
|
||||
@ -138,8 +136,6 @@ public class MapView extends GLSurfaceView {
|
||||
|
||||
MapActivity mapActivity = (MapActivity) context;
|
||||
|
||||
cacheDir = context.getFilesDir();
|
||||
|
||||
debugSettings = new DebugSettings(false, false, false, false);
|
||||
|
||||
mMapController = new MapController(this);
|
||||
@ -181,10 +177,12 @@ public class MapView extends GLSurfaceView {
|
||||
setMapFile("default");
|
||||
initMapStartPosition();
|
||||
|
||||
if (!setRenderTheme(DEFAULT_RENDER_THEME)) {
|
||||
Log.d(TAG, "X could not parse theme");
|
||||
// FIXME show init error dialog
|
||||
}
|
||||
mapActivity.registerMapView(this);
|
||||
|
||||
// if (!setRenderTheme(DEFAULT_RENDER_THEME)) {
|
||||
// Log.d(TAG, "X could not parse theme");
|
||||
// // FIXME show init error dialog
|
||||
// }
|
||||
|
||||
setEGLConfigChooser(new GlConfigChooser());
|
||||
setEGLContextClientVersion(2);
|
||||
@ -193,8 +191,6 @@ public class MapView extends GLSurfaceView {
|
||||
|
||||
if (!debugFrameTime)
|
||||
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
||||
|
||||
mapActivity.registerMapView(this);
|
||||
}
|
||||
|
||||
public final static boolean debugFrameTime = false;
|
||||
@ -348,7 +344,7 @@ public class MapView extends GLSurfaceView {
|
||||
if (mapFile != null)
|
||||
fileOpenResult = mapDatabase.openFile(new File(mapFile));
|
||||
else
|
||||
fileOpenResult = mapDatabase.openFile(cacheDir);
|
||||
fileOpenResult = mapDatabase.openFile(null);
|
||||
|
||||
if (fileOpenResult != null && fileOpenResult.isSuccess()) {
|
||||
mMapFile = mapFile;
|
||||
@ -436,6 +432,12 @@ public class MapView extends GLSurfaceView {
|
||||
mapWorkersProceed();
|
||||
}
|
||||
|
||||
private String mRenderTheme;
|
||||
|
||||
public String getRenderTheme() {
|
||||
return mRenderTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the internal theme which is used for rendering the map.
|
||||
*
|
||||
@ -451,6 +453,9 @@ public class MapView extends GLSurfaceView {
|
||||
}
|
||||
|
||||
boolean ret = setRenderTheme((Theme) internalRenderTheme);
|
||||
if (ret) {
|
||||
mRenderTheme = internalRenderTheme.name();
|
||||
}
|
||||
|
||||
clearAndRedrawMapView();
|
||||
return ret;
|
||||
@ -471,7 +476,10 @@ public class MapView extends GLSurfaceView {
|
||||
throw new IllegalArgumentException("render theme path must not be null");
|
||||
}
|
||||
|
||||
setRenderTheme(new ExternalRenderTheme(renderThemePath));
|
||||
boolean ret = setRenderTheme(new ExternalRenderTheme(renderThemePath));
|
||||
if (ret) {
|
||||
mRenderTheme = renderThemePath;
|
||||
}
|
||||
|
||||
clearAndRedrawMapView();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user