Add default implementation of services
This commit is contained in:
parent
cb2c25d3d8
commit
9049e2bcc1
9 changed files with 209 additions and 208 deletions
|
@ -21,6 +21,8 @@ import net.osmand.plus.activities.ApplicationMode;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
import net.osmand.plus.activities.RouteProvider.RouteService;
|
import net.osmand.plus.activities.RouteProvider.RouteService;
|
||||||
import net.osmand.plus.activities.search.SearchHistoryHelper;
|
import net.osmand.plus.activities.search.SearchHistoryHelper;
|
||||||
|
import net.osmand.plus.render.BaseOsmandRender;
|
||||||
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
|
@ -42,7 +44,7 @@ public class OsmandSettings {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
synchronized (ctx.getApplicationContext()) {
|
synchronized (ctx.getApplicationContext()) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
INSTANCE = new OsmandSettings(ctx.getApplicationContext());
|
INSTANCE = new OsmandSettings((OsmandApplication) ctx.getApplicationContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +63,9 @@ public class OsmandSettings {
|
||||||
private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$
|
private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$
|
||||||
|
|
||||||
/// Settings variables
|
/// Settings variables
|
||||||
private Context ctx;
|
private OsmandApplication ctx;
|
||||||
private SharedPreferences globalPreferences;
|
private SharedPreferences globalPreferences;
|
||||||
|
private SharedPreferences defaultProfilePreferences;
|
||||||
private SharedPreferences profilePreferences;
|
private SharedPreferences profilePreferences;
|
||||||
private ApplicationMode currentMode;
|
private ApplicationMode currentMode;
|
||||||
|
|
||||||
|
@ -71,27 +74,49 @@ public class OsmandSettings {
|
||||||
private boolean internetConnectionAvailable = true;
|
private boolean internetConnectionAvailable = true;
|
||||||
|
|
||||||
//TODO make all layers profile preferenced????
|
//TODO make all layers profile preferenced????
|
||||||
private OsmandSettings(Context ctx){
|
private OsmandSettings(OsmandApplication ctx){
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
globalPreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
globalPreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
// start from default settings
|
// start from default settings
|
||||||
currentMode = ApplicationMode.DEFAULT;
|
currentMode = ApplicationMode.DEFAULT;
|
||||||
updateProfilePreferences();
|
defaultProfilePreferences = getProfilePreferences(ApplicationMode.DEFAULT);
|
||||||
|
profilePreferences = defaultProfilePreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProfilePreferences(){
|
private SharedPreferences getProfilePreferences(ApplicationMode mode){
|
||||||
profilePreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME + "." + currentMode.name().toLowerCase(), Context.MODE_WORLD_READABLE);
|
return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME + "." + mode.name().toLowerCase(), Context.MODE_WORLD_READABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public static final String APPLICATION_MODE = "application_mode"; //$NON-NLS-1$
|
public final OsmandPreference<ApplicationMode> APPLICATION_MODE = new OsmandPreference<ApplicationMode>(){
|
||||||
|
public String getId() {
|
||||||
|
return "application_mode";
|
||||||
|
};
|
||||||
|
|
||||||
public ApplicationMode getApplicationMode() {
|
@Override
|
||||||
|
public ApplicationMode get() {
|
||||||
return currentMode;
|
return currentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean set(ApplicationMode val) {
|
||||||
|
ApplicationMode oldMode = currentMode;
|
||||||
|
boolean changed = globalPreferences.edit().putString(getId(), val.name()).commit();
|
||||||
|
if(changed){
|
||||||
|
currentMode = val;
|
||||||
|
profilePreferences = getProfilePreferences(currentMode);
|
||||||
|
switchApplicationMode(oldMode);
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public ApplicationMode getApplicationMode(){
|
||||||
|
return APPLICATION_MODE.get();
|
||||||
|
}
|
||||||
|
|
||||||
protected ApplicationMode readApplicationMode() {
|
protected ApplicationMode readApplicationMode() {
|
||||||
String s = globalPreferences.getString(APPLICATION_MODE, ApplicationMode.DEFAULT.name());
|
String s = globalPreferences.getString(APPLICATION_MODE.getId(), ApplicationMode.DEFAULT.name());
|
||||||
try {
|
try {
|
||||||
return ApplicationMode.valueOf(s);
|
return ApplicationMode.valueOf(s);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -99,17 +124,6 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setApplicationMode(ApplicationMode p, OsmandApplication app) {
|
|
||||||
ApplicationMode oldMode = currentMode;
|
|
||||||
boolean changed = globalPreferences.edit().putString(APPLICATION_MODE, p.name()).commit();
|
|
||||||
if(changed){
|
|
||||||
currentMode = p;
|
|
||||||
updateProfilePreferences();
|
|
||||||
switchApplicationMode(oldMode);
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void switchApplicationMode(ApplicationMode oldMode){
|
protected void switchApplicationMode(ApplicationMode oldMode){
|
||||||
// TODO
|
// TODO
|
||||||
// change some global settings
|
// change some global settings
|
||||||
|
@ -230,33 +244,53 @@ public class OsmandSettings {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final boolean global;
|
private final boolean global;
|
||||||
private T cachedValue;
|
private T cachedValue;
|
||||||
|
private SharedPreferences cachedPreference;
|
||||||
private boolean cache;
|
private boolean cache;
|
||||||
|
private Map<ApplicationMode, T> defaultValues;
|
||||||
|
private T defaultValue;
|
||||||
|
|
||||||
public CommonPreference(String id, boolean global){
|
public CommonPreference(String id, boolean global, T defaultValue){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.global = global;
|
this.global = global;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommonPreference(String id, boolean global, boolean cache){
|
public CommonPreference(String id, boolean global, boolean cache, T defaultValue){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.global = global;
|
this.global = global;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SharedPreferences getPreferences(){
|
protected SharedPreferences getPreferences(){
|
||||||
return global ? globalPreferences : profilePreferences;
|
return global ? globalPreferences : profilePreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract T getValue();
|
protected T getDefaultValue(){
|
||||||
|
if(global){
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if(defaultValues != null && defaultValues.containsKey(currentMode)){
|
||||||
|
return defaultValues.get(currentMode);
|
||||||
|
}
|
||||||
|
if(defaultProfilePreferences.contains(getId())) {
|
||||||
|
return getValue(defaultProfilePreferences, defaultValue);
|
||||||
|
} else {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract boolean setValue(T val);
|
protected abstract T getValue(SharedPreferences prefs, T defaultValue);
|
||||||
|
|
||||||
|
protected abstract boolean setValue(SharedPreferences prefs, T val);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get() {
|
public T get() {
|
||||||
if(cache && cachedValue != null){
|
if(cache && cachedValue != null && cachedPreference == getPreferences()){
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
cachedValue = getValue();
|
cachedPreference = getPreferences();
|
||||||
|
cachedValue = getValue(cachedPreference, getDefaultValue());
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +301,10 @@ public class OsmandSettings {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean set(T obj) {
|
public boolean set(T obj) {
|
||||||
if(setValue(obj)){
|
SharedPreferences prefs = getPreferences();
|
||||||
|
if(setValue(prefs,obj)){
|
||||||
cachedValue = obj;
|
cachedValue = obj;
|
||||||
|
cachedPreference = prefs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -278,114 +314,94 @@ public class OsmandSettings {
|
||||||
|
|
||||||
private class BooleanPreference extends CommonPreference<Boolean> {
|
private class BooleanPreference extends CommonPreference<Boolean> {
|
||||||
|
|
||||||
private final boolean defValue;
|
|
||||||
|
|
||||||
private BooleanPreference(String id, boolean defaultValue, boolean global) {
|
private BooleanPreference(String id, boolean defaultValue, boolean global) {
|
||||||
super(id, global);
|
super(id, global, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BooleanPreference(String id, boolean defaultValue, boolean global, boolean cache) {
|
private BooleanPreference(String id, boolean defaultValue, boolean global, boolean cache) {
|
||||||
super(id, global, cache);
|
super(id, global, cache);
|
||||||
this.defValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean getDefaultValue(){
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected Boolean getValue() {
|
|
||||||
return getPreferences().getBoolean(getId(), getDefaultValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Boolean val) {
|
protected Boolean getValue(SharedPreferences prefs, Boolean defaultValue) {
|
||||||
return getPreferences().edit().putBoolean(getId(), val).commit();
|
return prefs.getBoolean(getId(), defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setValue(SharedPreferences prefs, Boolean val) {
|
||||||
|
return prefs.edit().putBoolean(getId(), val).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private class IntPreference extends CommonPreference<Integer> {
|
private class IntPreference extends CommonPreference<Integer> {
|
||||||
|
|
||||||
private final int defValue;
|
|
||||||
|
|
||||||
private IntPreference(String id, int defaultValue, boolean global) {
|
private IntPreference(String id, int defaultValue, boolean global) {
|
||||||
super(id, global);
|
super(id, global, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntPreference(String id, int defaultValue, boolean global, boolean cache) {
|
private IntPreference(String id, int defaultValue, boolean global, boolean cache) {
|
||||||
super(id, global, cache);
|
super(id, global, cache, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getDefValue() {
|
|
||||||
return defValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer getValue() {
|
protected Integer getValue(SharedPreferences prefs, Integer defaultValue) {
|
||||||
return getPreferences().getInt(getId(), getDefValue());
|
return prefs.getInt(getId(), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Integer val) {
|
protected boolean setValue(SharedPreferences prefs, Integer val) {
|
||||||
return getPreferences().edit().putInt(getId(), val).commit();
|
return prefs.edit().putInt(getId(), val).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StringPreference extends CommonPreference<String> {
|
private class StringPreference extends CommonPreference<String> {
|
||||||
|
|
||||||
private final String defValue;
|
|
||||||
|
|
||||||
private StringPreference(String id, String defaultValue, boolean global) {
|
private StringPreference(String id, String defaultValue, boolean global) {
|
||||||
super(id, global);
|
super(id, global, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getValue() {
|
protected String getValue(SharedPreferences prefs, String defaultValue) {
|
||||||
return getPreferences().getString(getId(), defValue);
|
return prefs.getString(getId(), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(String val) {
|
protected boolean setValue(SharedPreferences prefs, String val) {
|
||||||
return getPreferences().edit().putString(getId(), val).commit();
|
return prefs.edit().putString(getId(), val).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> {
|
private class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> {
|
||||||
|
|
||||||
private final E defValue;
|
|
||||||
private final E[] values;
|
private final E[] values;
|
||||||
|
|
||||||
private EnumIntPreference(String id, E defaultValue, boolean global, boolean cache,
|
private EnumIntPreference(String id, E defaultValue, boolean global, boolean cache,
|
||||||
E[] values) {
|
E[] values) {
|
||||||
super(id, global, cache);
|
super(id, global, cache, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnumIntPreference(String id, E defaultValue, boolean global, E[] values) {
|
private EnumIntPreference(String id, E defaultValue, boolean global, E[] values) {
|
||||||
super(id, global);
|
super(id, global, defaultValue);
|
||||||
this.defValue = defaultValue;
|
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected E getValue() {
|
protected E getValue(SharedPreferences prefs, E defaultValue) {
|
||||||
int i = getPreferences().getInt(getId(), -1);
|
int i = prefs.getInt(getId(), -1);
|
||||||
if(i < 0 || i >= values.length){
|
if(i < 0 || i >= values.length){
|
||||||
return defValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return values[i];
|
return values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(E val) {
|
protected boolean setValue(SharedPreferences prefs,E val) {
|
||||||
return getPreferences().edit().putInt(getId(), val.ordinal()).commit();
|
return prefs.edit().putInt(getId(), val.ordinal()).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -393,7 +409,7 @@ public class OsmandSettings {
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES =
|
public final OsmandPreference<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES =
|
||||||
new BooleanPreference("use_internet_to_download_tiles", true, true, true);
|
new BooleanPreference("use_internet_to_download_tiles", true, false, true);
|
||||||
|
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
@ -439,7 +455,12 @@ public class OsmandSettings {
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<DayNightMode> DAYNIGHT_MODE =
|
public final OsmandPreference<DayNightMode> DAYNIGHT_MODE =
|
||||||
new EnumIntPreference<DayNightMode>("daynight_mode", DayNightMode.AUTO, false, DayNightMode.values());
|
new EnumIntPreference<DayNightMode>("daynight_mode", DayNightMode.AUTO, false, DayNightMode.values()) {
|
||||||
|
protected boolean setValue(SharedPreferences prefs, DayNightMode val) {
|
||||||
|
ctx.getDaynightHelper().setDayNightMode(val);
|
||||||
|
return super.setValue(prefs, val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
@ -455,7 +476,7 @@ public class OsmandSettings {
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<Boolean> SAVE_TRACK_TO_GPX = new
|
public final OsmandPreference<Boolean> SAVE_TRACK_TO_GPX = new
|
||||||
BooleanPreference("save_track_to_gpx", false, false){
|
BooleanPreference("save_track_to_gpx", false, false){
|
||||||
protected boolean getDefaultValue() {
|
protected Boolean getDefaultValue() {
|
||||||
boolean defaultValue = false;
|
boolean defaultValue = false;
|
||||||
if (currentMode == ApplicationMode.CAR || currentMode == ApplicationMode.BICYCLE) {
|
if (currentMode == ApplicationMode.CAR || currentMode == ApplicationMode.BICYCLE) {
|
||||||
defaultValue = true;
|
defaultValue = true;
|
||||||
|
@ -853,8 +874,21 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<String> VOICE_PROVIDER = new StringPreference("voice_provider", null, false);
|
public final OsmandPreference<String> VOICE_PROVIDER = new StringPreference("voice_provider", null, false);
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
// TODO init default value !!!
|
public final OsmandPreference<String> RENDERER = new StringPreference("renderer", RendererRegistry.DEFAULT_RENDER, false) {
|
||||||
public final OsmandPreference<String> RENDERER = new StringPreference("renderer", null, false);
|
protected boolean setValue(SharedPreferences prefs, String val) {
|
||||||
|
if(val == null){
|
||||||
|
val = RendererRegistry.DEFAULT_RENDER;
|
||||||
|
}
|
||||||
|
BaseOsmandRender loaded = ctx.getRendererRegistry().getRenderer(val);
|
||||||
|
if (loaded != null) {
|
||||||
|
ctx.getRendererRegistry().setCurrentSelectedRender(loaded);
|
||||||
|
super.setValue(prefs, val);
|
||||||
|
ctx.getResourceManager().getRenderer().clearCache();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
public final OsmandPreference<Boolean> VOICE_MUTE = new BooleanPreference("voice_mute", false, true);
|
public final OsmandPreference<Boolean> VOICE_MUTE = new BooleanPreference("voice_mute", false, true);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetStoreDirectory() {
|
public void resetStoreDirectory() {
|
||||||
dirWithTiles = OsmandSettings.getOsmandSettings(context).extendOsmandPath(TILES_PATH);
|
dirWithTiles = context.getSettings().extendOsmandPath(TILES_PATH);
|
||||||
dirWithTiles.mkdirs();
|
dirWithTiles.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initRenderers(IProgress progress) {
|
private void initRenderers(IProgress progress) {
|
||||||
File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(APP_DIR + IndexConstants.RENDERERS_DIR);
|
File file = context.getSettings().extendOsmandPath(APP_DIR + IndexConstants.RENDERERS_DIR);
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
|
Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
|
||||||
if (file.exists() && file.canRead()) {
|
if (file.exists() && file.canRead()) {
|
||||||
|
@ -363,18 +363,18 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RendererRegistry.getRegistry().setExternalRenderers(externalRenderers);
|
context.getRendererRegistry().setExternalRenderers(externalRenderers);
|
||||||
String r = OsmandSettings.getOsmandSettings(context).RENDERER.get();
|
String r = context.getSettings().RENDERER.get();
|
||||||
if(r != null){
|
if(r != null){
|
||||||
BaseOsmandRender obj = RendererRegistry.getRegistry().getRenderer(r);
|
BaseOsmandRender obj = context.getRendererRegistry().getRenderer(r);
|
||||||
if(obj != null){
|
if(obj != null){
|
||||||
RendererRegistry.getRegistry().setCurrentSelectedRender(obj);
|
context.getRendererRegistry().setCurrentSelectedRender(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> indexingMaps(final IProgress progress) {
|
public List<String> indexingMaps(final IProgress progress) {
|
||||||
File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(MAPS_PATH);
|
File file = context.getSettings().extendOsmandPath(MAPS_PATH);
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
List<String> warnings = new ArrayList<String>();
|
List<String> warnings = new ArrayList<String>();
|
||||||
renderer.clearAllResources();
|
renderer.clearAllResources();
|
||||||
|
@ -431,7 +431,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
// POI INDEX //
|
// POI INDEX //
|
||||||
public List<String> indexingPoi(final IProgress progress) {
|
public List<String> indexingPoi(final IProgress progress) {
|
||||||
File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(POI_PATH);
|
File file = context.getSettings().extendOsmandPath(POI_PATH);
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
List<String> warnings = new ArrayList<String>();
|
List<String> warnings = new ArrayList<String>();
|
||||||
closeAmenities();
|
closeAmenities();
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.render.BaseOsmandRender;
|
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences.Editor;
|
|
||||||
|
|
||||||
public enum ApplicationMode {
|
public enum ApplicationMode {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
settings = OsmandSettings.getOsmandSettings(this);
|
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||||
// for voice navigation
|
// for voice navigation
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
@ -1167,7 +1167,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
ApplicationMode mode = getAppMode(buttons);
|
ApplicationMode mode = getAppMode(buttons);
|
||||||
// change global settings
|
// change global settings
|
||||||
boolean changed = settings.setApplicationMode(mode, (OsmandApplication) getApplication());
|
boolean changed = settings.APPLICATION_MODE.set(mode);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
updateApplicationModeSettings();
|
updateApplicationModeSettings();
|
||||||
mapView.refreshMap();
|
mapView.refreshMap();
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.plus.PoiFiltersHelper;
|
||||||
import net.osmand.plus.ProgressDialogImplementation;
|
import net.osmand.plus.ProgressDialogImplementation;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.ResourceManager;
|
import net.osmand.plus.ResourceManager;
|
||||||
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.voice.CommandPlayer;
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
@ -41,6 +42,9 @@ public class OsmandApplication extends Application {
|
||||||
FavouritesDbHelper favorites = null;
|
FavouritesDbHelper favorites = null;
|
||||||
CommandPlayer player = null;
|
CommandPlayer player = null;
|
||||||
OsmandSettings osmandSettings;
|
OsmandSettings osmandSettings;
|
||||||
|
DayNightHelper daynightHelper;
|
||||||
|
NavigationService navigationService;
|
||||||
|
RendererRegistry rendererRegistry;
|
||||||
|
|
||||||
|
|
||||||
// start variables
|
// start variables
|
||||||
|
@ -48,8 +52,7 @@ public class OsmandApplication extends Application {
|
||||||
private List<String> startingWarnings;
|
private List<String> startingWarnings;
|
||||||
private ProgressDialog progressDlg;
|
private ProgressDialog progressDlg;
|
||||||
private Handler uiHandler;
|
private Handler uiHandler;
|
||||||
private DayNightHelper daynightHelper;
|
|
||||||
private NavigationService navigationService;
|
|
||||||
private boolean applicationInitializing = false;
|
private boolean applicationInitializing = false;
|
||||||
private Locale prefferedLocale = null;
|
private Locale prefferedLocale = null;
|
||||||
|
|
||||||
|
@ -61,10 +64,15 @@ public class OsmandApplication extends Application {
|
||||||
manager = new ResourceManager(this);
|
manager = new ResourceManager(this);
|
||||||
daynightHelper = new DayNightHelper(this);
|
daynightHelper = new DayNightHelper(this);
|
||||||
uiHandler = new Handler();
|
uiHandler = new Handler();
|
||||||
|
rendererRegistry = new RendererRegistry();
|
||||||
checkPrefferedLocale();
|
checkPrefferedLocale();
|
||||||
startApplication();
|
startApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RendererRegistry getRendererRegistry() {
|
||||||
|
return rendererRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
public OsmandSettings getSettings() {
|
public OsmandSettings getSettings() {
|
||||||
return osmandSettings;
|
return osmandSettings;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ import net.osmand.plus.OsmandSettings.DayNightMode;
|
||||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.activities.RouteProvider.RouteService;
|
import net.osmand.plus.activities.RouteProvider.RouteService;
|
||||||
import net.osmand.plus.render.BaseOsmandRender;
|
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
@ -51,10 +49,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
private Preference reloadIndexes;
|
private Preference reloadIndexes;
|
||||||
private Preference downloadIndexes;
|
private Preference downloadIndexes;
|
||||||
|
|
||||||
private ListPreference applicationMode;
|
|
||||||
private EditTextPreference applicationDir;
|
private EditTextPreference applicationDir;
|
||||||
private ListPreference tileSourcePreference;
|
private ListPreference tileSourcePreference;
|
||||||
private ListPreference rendererPreference;
|
|
||||||
|
|
||||||
private CheckBoxPreference routeServiceEnabled;
|
private CheckBoxPreference routeServiceEnabled;
|
||||||
private BroadcastReceiver broadcastReceiver;
|
private BroadcastReceiver broadcastReceiver;
|
||||||
|
@ -104,11 +100,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
Integer[] ints = new Integer[secondsLength + minutesLength];
|
Integer[] ints = new Integer[secondsLength + minutesLength];
|
||||||
String[] intDescriptions = new String[ints.length];
|
String[] intDescriptions = new String[ints.length];
|
||||||
for (int i = 0; i < secondsLength; i++) {
|
for (int i = 0; i < secondsLength; i++) {
|
||||||
ints[i] = seconds[i]*coeff;
|
ints[i] = seconds[i] * coeff;
|
||||||
intDescriptions[i] = ints[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
|
intDescriptions[i] = seconds[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
for (int i = 0; i < minutesLength; i++) {
|
for (int i = 0; i < minutesLength; i++) {
|
||||||
ints[secondsLength + i] = (minutes[i] * 60)*coeff;
|
ints[secondsLength + i] = (minutes[i] * 60) * coeff;
|
||||||
intDescriptions[secondsLength + i] = minutes[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
|
intDescriptions[secondsLength + i] = minutes[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
registerListPreference(b, screen, intDescriptions, ints);
|
registerListPreference(b, screen, intDescriptions, ints);
|
||||||
|
@ -149,21 +145,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
registerBooleanPreference(osmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS,screen);
|
registerBooleanPreference(osmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS,screen);
|
||||||
registerBooleanPreference(osmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES,screen);
|
registerBooleanPreference(osmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES,screen);
|
||||||
|
|
||||||
|
|
||||||
reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES);
|
|
||||||
reloadIndexes.setOnPreferenceClickListener(this);
|
|
||||||
downloadIndexes =(Preference) screen.findPreference(OsmandSettings.DOWNLOAD_INDEXES);
|
|
||||||
downloadIndexes.setOnPreferenceClickListener(this);
|
|
||||||
saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK);
|
|
||||||
saveCurrentTrack.setOnPreferenceClickListener(this);
|
|
||||||
routeServiceEnabled =(CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
|
|
||||||
routeServiceEnabled.setOnPreferenceChangeListener(this);
|
|
||||||
|
|
||||||
registerEditTextPreference(osmandSettings.USER_NAME, screen);
|
registerEditTextPreference(osmandSettings.USER_NAME, screen);
|
||||||
registerEditTextPreference(osmandSettings.USER_PASSWORD, screen);
|
registerEditTextPreference(osmandSettings.USER_PASSWORD, screen);
|
||||||
|
|
||||||
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
|
|
||||||
applicationDir.setOnPreferenceChangeListener(this);
|
|
||||||
|
|
||||||
// List preferences
|
// List preferences
|
||||||
registerListPreference(osmandSettings.ROTATE_MAP, screen,
|
registerListPreference(osmandSettings.ROTATE_MAP, screen,
|
||||||
|
@ -191,13 +176,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
registerListPreference(osmandSettings.METRIC_SYSTEM, screen, entries, MetricsConstants.values());
|
registerListPreference(osmandSettings.METRIC_SYSTEM, screen, entries, MetricsConstants.values());
|
||||||
|
|
||||||
//getResources().getAssets().getLocales();
|
//getResources().getAssets().getLocales();
|
||||||
entries = new String[] { "", "en", "cs", "de", "es", "fr", "hu", "it", "pt", "ru", "sk" };
|
entrieValues = new String[] { "", "en", "cs", "de", "es", "fr", "hu", "it", "pt", "ru", "sk" };
|
||||||
entrieValues = new String[entries.length];
|
entries = new String[entrieValues.length];
|
||||||
entrieValues[0] = getString(R.string.system_locale);
|
entries[0] = getString(R.string.system_locale);
|
||||||
for (int i=1; i< entries.length; i++) {
|
for (int i = 1; i < entries.length; i++) {
|
||||||
entrieValues[i] = entries[i];
|
entries[i] = entrieValues[i];
|
||||||
}
|
}
|
||||||
registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entries);
|
registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);
|
||||||
|
|
||||||
Set<String> voiceFiles = getVoiceFiles();
|
Set<String> voiceFiles = getVoiceFiles();
|
||||||
entries = new String[voiceFiles.size() + 1];
|
entries = new String[voiceFiles.size() + 1];
|
||||||
|
@ -209,7 +194,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
entrieValues[k] = s;
|
entrieValues[k] = s;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
registerListPreference(osmandSettings.VOICE_PROVIDER, screen, entries, entries);
|
registerListPreference(osmandSettings.VOICE_PROVIDER, screen, entries, entrieValues);
|
||||||
|
|
||||||
int startZoom = 12;
|
int startZoom = 12;
|
||||||
int endZoom = 19;
|
int endZoom = 19;
|
||||||
|
@ -230,7 +215,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
|
|
||||||
entries = new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)};
|
entries = new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)};
|
||||||
entrieValues = new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER};
|
entrieValues = new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER};
|
||||||
registerListPreference(osmandSettings.SERVICE_OFF_PROVIDER, screen, entries, entries);
|
registerListPreference(osmandSettings.SERVICE_OFF_PROVIDER, screen, entries, entrieValues);
|
||||||
|
|
||||||
registerTimeListPreference(osmandSettings.SAVE_TRACK_INTERVAL, screen, new int[]{1, 2, 3, 5, 15, 20, 30}, new int[]{1, 2, 3, 5}, 1);
|
registerTimeListPreference(osmandSettings.SAVE_TRACK_INTERVAL, screen, new int[]{1, 2, 3, 5, 15, 20, 30}, new int[]{1, 2, 3, 5}, 1);
|
||||||
registerTimeListPreference(osmandSettings.SERVICE_OFF_INTERVAL, screen,
|
registerTimeListPreference(osmandSettings.SERVICE_OFF_INTERVAL, screen,
|
||||||
|
@ -238,14 +223,31 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
registerTimeListPreference(osmandSettings.SERVICE_OFF_WAIT_INTERVAL, screen,
|
registerTimeListPreference(osmandSettings.SERVICE_OFF_WAIT_INTERVAL, screen,
|
||||||
new int[]{15, 30, 45, 60, 90}, new int[]{2, 3, 5, 10}, 1000);
|
new int[]{15, 30, 45, 60, 90}, new int[]{2, 3, 5, 10}, 1000);
|
||||||
|
|
||||||
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
|
|
||||||
applicationMode.setOnPreferenceChangeListener(this);
|
entries = new String[ApplicationMode.values().length];
|
||||||
|
for(int i=0; i<entries.length; i++){
|
||||||
|
entries[i] = ApplicationMode.toHumanString(ApplicationMode.values()[i], this);
|
||||||
|
}
|
||||||
|
registerListPreference(osmandSettings.APPLICATION_MODE, screen, entries, ApplicationMode.values());
|
||||||
|
|
||||||
|
Collection<String> rendererNames = getMyApplication().getRendererRegistry().getRendererNames();
|
||||||
|
entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
|
||||||
|
registerListPreference(osmandSettings.RENDERER, screen, entries, entries);
|
||||||
|
|
||||||
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
||||||
tileSourcePreference.setOnPreferenceChangeListener(this);
|
tileSourcePreference.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
rendererPreference =(ListPreference) screen.findPreference(osmandSettings.RENDERER.getId());
|
|
||||||
rendererPreference.setOnPreferenceChangeListener(this);
|
|
||||||
|
|
||||||
|
reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES);
|
||||||
|
reloadIndexes.setOnPreferenceClickListener(this);
|
||||||
|
downloadIndexes =(Preference) screen.findPreference(OsmandSettings.DOWNLOAD_INDEXES);
|
||||||
|
downloadIndexes.setOnPreferenceClickListener(this);
|
||||||
|
saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK);
|
||||||
|
saveCurrentTrack.setOnPreferenceClickListener(this);
|
||||||
|
routeServiceEnabled =(CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
|
||||||
|
routeServiceEnabled.setOnPreferenceChangeListener(this);
|
||||||
|
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
|
||||||
|
applicationDir.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
|
||||||
broadcastReceiver = new BroadcastReceiver(){
|
broadcastReceiver = new BroadcastReceiver(){
|
||||||
|
@ -258,7 +260,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION));
|
registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateApplicationDirSummary() {
|
private void updateApplicationDirTextAndSummary() {
|
||||||
String storageDir = osmandSettings.getExternalStorageDirectory().getAbsolutePath();
|
String storageDir = osmandSettings.getExternalStorageDirectory().getAbsolutePath();
|
||||||
applicationDir.setText(storageDir);
|
applicationDir.setText(storageDir);
|
||||||
applicationDir.setSummary(storageDir);
|
applicationDir.setSummary(storageDir);
|
||||||
|
@ -283,7 +285,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
pref.setChecked(b.get());
|
pref.setChecked(b.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(OsmandPreference<?> p : listPreferences.values()){
|
for(OsmandPreference<?> p : listPreferences.values()){
|
||||||
ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
|
ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
|
||||||
Map<String, ?> prefValues = listPrefValues.get(p.getId());
|
Map<String, ?> prefValues = listPrefValues.get(p.getId());
|
||||||
|
@ -305,38 +306,12 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
pref.setText(s.get());
|
pref.setText(s.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationDir.setText(osmandSettings.getExternalStorageDirectory().getAbsolutePath());
|
// Specific properties
|
||||||
|
|
||||||
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
|
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
|
||||||
|
|
||||||
ApplicationMode[] presets = ApplicationMode.values();
|
|
||||||
String[] names = new String[presets.length];
|
|
||||||
String[] values = new String[presets.length];
|
|
||||||
for(int i=0; i<presets.length; i++){
|
|
||||||
names[i] = ApplicationMode.toHumanString(presets[i], this);
|
|
||||||
values[i] = presets[i].name();
|
|
||||||
}
|
|
||||||
fill(applicationMode, names, values, osmandSettings.getApplicationMode().name());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String vectorRenderer = osmandSettings.RENDERER.get();
|
|
||||||
Collection<String> rendererNames = RendererRegistry.getRegistry().getRendererNames();
|
|
||||||
String[] entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
|
|
||||||
rendererPreference.setEntries(entries);
|
|
||||||
rendererPreference.setEntryValues(entries);
|
|
||||||
if(rendererNames.contains(vectorRenderer)){
|
|
||||||
rendererPreference.setValue(vectorRenderer);
|
|
||||||
} else {
|
|
||||||
rendererPreference.setValueIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, String> entriesMap = osmandSettings.getTileSourceEntries();
|
Map<String, String> entriesMap = osmandSettings.getTileSourceEntries();
|
||||||
entries = new String[entriesMap.size() + 1];
|
String[] entries = new String[entriesMap.size() + 1];
|
||||||
values = new String[entriesMap.size() + 1];
|
String[] values = new String[entriesMap.size() + 1];
|
||||||
values[0] = VECTOR_MAP;
|
values[0] = VECTOR_MAP;
|
||||||
entries[0] = getString(R.string.vector_data);
|
entries[0] = getString(R.string.vector_data);
|
||||||
int ki = 1;
|
int ki = 1;
|
||||||
|
@ -348,6 +323,12 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
String value = osmandSettings.isUsingMapVectorData()? VECTOR_MAP : osmandSettings.getMapTileSourceName();
|
String value = osmandSettings.isUsingMapVectorData()? VECTOR_MAP : osmandSettings.getMapTileSourceName();
|
||||||
fill(tileSourcePreference, entries, values, value);
|
fill(tileSourcePreference, entries, values, value);
|
||||||
|
|
||||||
|
updateTileSourceSummary();
|
||||||
|
|
||||||
|
updateApplicationDirTextAndSummary();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTileSourceSummary() {
|
||||||
String mapName = " " + (osmandSettings.isUsingMapVectorData() ? getString(R.string.vector_data) : //$NON-NLS-1$
|
String mapName = " " + (osmandSettings.isUsingMapVectorData() ? getString(R.string.vector_data) : //$NON-NLS-1$
|
||||||
osmandSettings.getMapTileSourceName());
|
osmandSettings.getMapTileSourceName());
|
||||||
String summary = tileSourcePreference.getSummary().toString();
|
String summary = tileSourcePreference.getSummary().toString();
|
||||||
|
@ -355,8 +336,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
|
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
|
||||||
}
|
}
|
||||||
tileSourcePreference.setSummary(summary + mapName);
|
tileSourcePreference.setSummary(summary + mapName);
|
||||||
|
|
||||||
updateApplicationDirSummary();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fill(ListPreference component, String[] list, String[] values, String selected) {
|
private void fill(ListPreference component, String[] list, String[] values, String selected) {
|
||||||
|
@ -378,27 +357,32 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
} else if (editPref != null) {
|
} else if (editPref != null) {
|
||||||
editPref.set((String) newValue);
|
editPref.set((String) newValue);
|
||||||
} else if (listPref != null) {
|
} else if (listPref != null) {
|
||||||
CharSequence entry = ((ListPreference) preference).getEntry();
|
int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
|
||||||
|
CharSequence entry = ((ListPreference) preference).getEntries()[ind];
|
||||||
Map<String, ?> map = listPrefValues.get(preference.getKey());
|
Map<String, ?> map = listPrefValues.get(preference.getKey());
|
||||||
Object obj = map.get(entry);
|
Object obj = map.get(entry);
|
||||||
listPref.set(obj);
|
boolean changed = listPref.set(obj);
|
||||||
|
|
||||||
// Specific actions after list preference changed
|
// Specific actions after list preference changed
|
||||||
if(listPref.getId().equals(osmandSettings.DAYNIGHT_MODE.getId())){
|
if (changed) {
|
||||||
getMyApplication().getDaynightHelper().setDayNightMode(osmandSettings.DAYNIGHT_MODE.get());
|
if (listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())) {
|
||||||
} else if(listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())){
|
|
||||||
getMyApplication().initCommandPlayer();
|
getMyApplication().initCommandPlayer();
|
||||||
} else if(listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())){
|
} else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
|
||||||
// restart activity
|
updateAllSettings();
|
||||||
|
} else if (listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())) {
|
||||||
|
// restart application to update locale
|
||||||
getMyApplication().checkPrefferedLocale();
|
getMyApplication().checkPrefferedLocale();
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
finish();
|
finish();
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
} else if(preference == applicationMode){
|
}
|
||||||
boolean changed = osmandSettings.setApplicationMode(ApplicationMode.valueOf(newValue.toString()), getMyApplication());
|
if (listPref.getId().equals(osmandSettings.RENDERER.getId())) {
|
||||||
if(changed){
|
if(changed){
|
||||||
updateAllSettings();
|
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(preference == applicationDir){
|
} else if(preference == applicationDir){
|
||||||
warnAboutChangingStorage((String) newValue);
|
warnAboutChangingStorage((String) newValue);
|
||||||
|
@ -415,16 +399,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
|
routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (preference == rendererPreference) {
|
|
||||||
BaseOsmandRender loaded = RendererRegistry.getRegistry().getRenderer((String) newValue);
|
|
||||||
if(loaded == null){
|
|
||||||
Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
RendererRegistry.getRegistry().setCurrentSelectedRender(loaded);
|
|
||||||
osmandSettings.RENDERER.set((String) newValue);
|
|
||||||
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
|
|
||||||
getMyApplication().getResourceManager().getRenderer().clearCache();
|
|
||||||
}
|
|
||||||
} else if (preference == tileSourcePreference) {
|
} else if (preference == tileSourcePreference) {
|
||||||
if(VECTOR_MAP.equals((String) newValue)){
|
if(VECTOR_MAP.equals((String) newValue)){
|
||||||
osmandSettings.setUsingMapVectorData(true);
|
osmandSettings.setUsingMapVectorData(true);
|
||||||
|
@ -432,14 +406,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
osmandSettings.setUsingMapVectorData(true);
|
osmandSettings.setUsingMapVectorData(true);
|
||||||
osmandSettings.setMapTileSource((String) newValue);
|
osmandSettings.setMapTileSource((String) newValue);
|
||||||
}
|
}
|
||||||
String summary = tileSourcePreference.getSummary().toString();
|
updateTileSourceSummary();
|
||||||
if (summary.lastIndexOf(':') != -1) {
|
|
||||||
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
|
|
||||||
}
|
|
||||||
summary += " " + (osmandSettings.isUsingMapVectorData() ? getString(R.string.vector_data) : //$NON-NLS-1$
|
|
||||||
osmandSettings.getMapTileSourceName());
|
|
||||||
tileSourcePreference.setSummary(summary);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -462,7 +429,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
osmandSettings.setExternalStorageDirectory(newDir);
|
osmandSettings.setExternalStorageDirectory(newDir);
|
||||||
getMyApplication().getResourceManager().resetStoreDirectory();
|
getMyApplication().getResourceManager().resetStoreDirectory();
|
||||||
reloadIndexes();
|
reloadIndexes();
|
||||||
updateApplicationDirSummary();
|
updateApplicationDirTextAndSummary();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.default_buttons_cancel, null);
|
builder.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class GeoIntentActivity extends ListActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.search_address_offline);
|
setContentView(R.layout.search_address_offline);
|
||||||
getMyApplication().checkApplicationIsBeingInitialized(this);
|
getMyApplication().checkApplicationIsBeingInitialized(this);
|
||||||
location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
location = getMyApplication().getSettings().getLastKnownMapLocation();
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
progressDlg = ProgressDialog.show(this,
|
progressDlg = ProgressDialog.show(this,
|
||||||
|
@ -144,7 +144,7 @@ public class GeoIntentActivity extends ListActivity {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
MapObject item = ((MapObjectAdapter) getListAdapter())
|
MapObject item = ((MapObjectAdapter) getListAdapter())
|
||||||
.getItem(position);
|
.getItem(position);
|
||||||
OsmandSettings.getOsmandSettings(this).setMapLocationToShow(item.getLocation()
|
getMyApplication().getSettings().setMapLocationToShow(item.getLocation()
|
||||||
.getLatitude(), item.getLocation().getLongitude(),
|
.getLatitude(), item.getLocation().getLongitude(),
|
||||||
getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$
|
getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$
|
||||||
startActivity(new Intent(this, MapActivity.class));
|
startActivity(new Intent(this, MapActivity.class));
|
||||||
|
|
|
@ -39,7 +39,6 @@ import net.osmand.render.OsmandRenderingRulesParser;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Bitmap.Config;
|
import android.graphics.Bitmap.Config;
|
||||||
|
@ -307,10 +306,11 @@ public class MapRenderRepositories {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// find selected rendering type
|
// find selected rendering type
|
||||||
Boolean renderDay = ((OsmandApplication)context.getApplicationContext()).getDaynightHelper().getDayNightRenderer();
|
OsmandApplication app = ((OsmandApplication)context.getApplicationContext());
|
||||||
BaseOsmandRender renderingType = RendererRegistry.getRegistry().getCurrentSelectedRenderer();
|
Boolean renderDay = app.getDaynightHelper().getDayNightRenderer();
|
||||||
|
BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||||
if(renderDay != null && renderingType != null && renderDay.booleanValue() != renderingType.isDayRender()){
|
if(renderDay != null && renderingType != null && renderDay.booleanValue() != renderingType.isDayRender()){
|
||||||
renderingType = RendererRegistry.getRegistry().getOppositeRendererForDayNight(renderingType);
|
renderingType = app.getRendererRegistry().getOppositeRendererForDayNight(renderingType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent editing
|
// prevent editing
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class RendererRegistry {
|
public class RendererRegistry {
|
||||||
|
|
||||||
private final static RendererRegistry registry = new RendererRegistry();
|
|
||||||
private final static Log log = LogUtil.getLog(RendererRegistry.class);
|
private final static Log log = LogUtil.getLog(RendererRegistry.class);
|
||||||
|
|
||||||
public final static String DEFAULT_RENDER = "default"; //$NON-NLS-1$
|
public final static String DEFAULT_RENDER = "default"; //$NON-NLS-1$
|
||||||
|
@ -33,9 +32,6 @@ public class RendererRegistry {
|
||||||
public final static String CAR_NIGHT_RENDER = CAR_RENDER + NIGHT_SUFFIX;
|
public final static String CAR_NIGHT_RENDER = CAR_RENDER + NIGHT_SUFFIX;
|
||||||
|
|
||||||
|
|
||||||
public static RendererRegistry getRegistry() {
|
|
||||||
return registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RendererRegistry(){
|
public RendererRegistry(){
|
||||||
internalRenderers.put(DEFAULT_RENDER, "default.render.xml"); //$NON-NLS-1$
|
internalRenderers.put(DEFAULT_RENDER, "default.render.xml"); //$NON-NLS-1$
|
||||||
|
|
Loading…
Reference in a new issue