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