diff --git a/OsmAnd/src/net/osmand/OsmAndFormatter.java b/OsmAnd/src/net/osmand/OsmAndFormatter.java index 4e091b9af5..13c3ef6283 100644 --- a/OsmAnd/src/net/osmand/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/OsmAndFormatter.java @@ -16,7 +16,8 @@ public class OsmAndFormatter { private final static float FOOTS_IN_METER = YARDS_IN_METER * 3f; public static String getFormattedDistance(int meters, Context ctx) { - MetricsConstants mc = OsmandSettings.getDefaultMetricConstants(ctx); + OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx); + MetricsConstants mc = settings.METRIC_SYSTEM.get(); int mainUnitStr; float mainUnitInMeters; if (mc == MetricsConstants.KILOMETERS_AND_METERS) { @@ -48,7 +49,8 @@ public class OsmAndFormatter { } public static String getFormattedSpeed(float metersperseconds, Context ctx) { - MetricsConstants mc = OsmandSettings.getDefaultMetricConstants(ctx); + OsmandSettings settings = OsmandSettings.getOsmandSettings(ctx); + MetricsConstants mc = settings.METRIC_SYSTEM.get(); float kmh = metersperseconds * 3.6f; if(mc == MetricsConstants.KILOMETERS_AND_METERS){ return ((int) kmh) + ctx.getString(R.string.km_h); diff --git a/OsmAnd/src/net/osmand/plus/NavigationService.java b/OsmAnd/src/net/osmand/plus/NavigationService.java index b3ac443be7..8b3c96ed29 100644 --- a/OsmAnd/src/net/osmand/plus/NavigationService.java +++ b/OsmAnd/src/net/osmand/plus/NavigationService.java @@ -14,7 +14,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; @@ -44,7 +43,7 @@ public class NavigationService extends Service implements LocationListener { private SavingTrackHelper savingTrackHelper; private RoutingHelper routingHelper; - private SharedPreferences settings; + private OsmandSettings settings; private Handler handler; @@ -86,10 +85,10 @@ public class NavigationService extends Service implements LocationListener { // initializing variables setForeground(true); handler = new Handler(); - settings = OsmandSettings.getPrefs(this); - serviceOffInterval = OsmandSettings.getServiceOffInterval(settings); - serviceOffProvider = OsmandSettings.getServiceOffProvider(settings); - serviceError = OsmandSettings.getServiceOffWaitInterval(settings); + settings = OsmandSettings.getOsmandSettings(this); + serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get(); + serviceOffProvider = settings.SERVICE_OFF_PROVIDER.get(); + serviceError = settings.SERVICE_OFF_WAIT_INTERVAL.get(); savingTrackHelper = new SavingTrackHelper(this); routingHelper = ((OsmandApplication)getApplication()).getRoutingHelper(); @@ -159,7 +158,7 @@ public class NavigationService extends Service implements LocationListener { @Override public void onLocationChanged(Location location) { - if(location != null && !OsmandSettings.getMapActivityEnabled(settings)){ + if(location != null && !settings.MAP_ACTIVITY_ENABLED.get()){ if(!isContinuous()){ // unregister listener and wait next time LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 216185c69e..9a8663b082 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -17,6 +17,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; @@ -30,9 +32,805 @@ import android.os.Environment; import android.util.Log; public class OsmandSettings { + // GLOBAL instance - make instance global for application + // if some problems appear it can be unique for Application (ApplicationContext) + private static OsmandSettings INSTANCE; + + public static OsmandSettings getOsmandSettings(Context ctx) { + if (INSTANCE == null) { + synchronized (ctx.getApplicationContext()) { + if (INSTANCE == null) { + INSTANCE = new OsmandSettings(ctx.getApplicationContext()); + } + } + } + return INSTANCE; + } + + public interface OsmandPreference { + T get(); + + boolean set(T obj); + + String getId(); + } + + // These settings are stored in SharedPreferences + private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$ + + /// Settings variables + private Context ctx; + private SharedPreferences globalPreferences; + private SharedPreferences profilePreferences; + private ApplicationMode currentMode; + + // cache variables + private long lastTimeInternetConnectionChecked = 0; + private boolean internetConnectionAvailable = true; + + private OsmandSettings(Context ctx){ + this.ctx = ctx; + globalPreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + updateProfilePreferences(); + } + + private void updateProfilePreferences(){ + currentMode = getApplicationMode(globalPreferences); + profilePreferences = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME + "." + currentMode.name().toLowerCase(), Context.MODE_WORLD_READABLE); + } + + public SharedPreferences getPrefs(Context ctx){ + return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + } +public boolean setAppMode(ApplicationMode preset, OsmandApplication app) { + + ApplicationMode old = OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(app)); + if(preset == old){ + return false; + } + Editor edit = OsmandSettings.getWriteableEditor(app); + edit.putString(OsmandSettings.APPLICATION_MODE, preset.toString()); + if (preset == ApplicationMode.CAR) { + OsmandSettings.setUseInternetToDownloadTiles(true, edit); + // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, _); + edit.putBoolean(OsmandSettings.SHOW_TRANSPORT_OVER_MAP, false); + edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING); + edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); + edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, true); + edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, false); + edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, true); + // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); + edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true); + edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 5); + edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT); + // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); + } else if (preset == ApplicationMode.BICYCLE) { + // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); + // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_CALCULATE_ROUTE, _); + // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); + edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING); + edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true); + edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); + // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); + // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); + edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true); + edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 30); + edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT); + // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); + + } else if (preset == ApplicationMode.PEDESTRIAN) { + // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); + // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); + edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_COMPASS); + edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true); + edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); + edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, false); + // if(useInternetToDownloadTiles.isChecked()){ + // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, true); + // } + // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); + edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, false); + // edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _); + edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT); + // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); + + } else if (preset == ApplicationMode.DEFAULT) { + // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); + // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); + edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_NONE); + edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); + edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); + edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, true); + // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); + // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); + edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, false); + // edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _); + edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT); + // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); + + } + + BaseOsmandRender current = RendererRegistry.getRegistry().getCurrentSelectedRenderer(); + BaseOsmandRender defaultRender = RendererRegistry.getRegistry().defaultRender(); + BaseOsmandRender newRenderer; + if (preset == ApplicationMode.CAR) { + newRenderer = RendererRegistry.getRegistry().carRender(); + } else if (preset == ApplicationMode.BICYCLE) { + newRenderer = RendererRegistry.getRegistry().bicycleRender(); + } else if (preset == ApplicationMode.PEDESTRIAN) { + newRenderer = RendererRegistry.getRegistry().pedestrianRender(); + } else { + newRenderer = defaultRender; + } + if (newRenderer != current) { + RendererRegistry.getRegistry().setCurrentSelectedRender(newRenderer); + app.getResourceManager().getRenderer().clearCache(); + } + return edit.commit(); + } + + protected void switchApplicationMode(){ + // TODO + // change some global settings + // for car + if(currentMode == ApplicationMode.CAR){ + SHOW_TRANSPORT_OVER_MAP.set(false); + SHOW_OSM_BUGS.set(false); + } + } + // TODO + // 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() { + String s = globalPreferences.getString(APPLICATION_MODE, ApplicationMode.DEFAULT.name()); + try { + return ApplicationMode.valueOf(s); + } catch (IllegalArgumentException e) { + return ApplicationMode.DEFAULT; + } + } + + // TODO + public boolean setApplicationMode(Context ctx, ApplicationMode p) { + return globalPreferences.edit().putString(APPLICATION_MODE, p.name()).commit(); + } + + + //TODO make all layers profile preferenced???? + // Check internet connection available every 15 seconds + public boolean isInternetConnectionAvailable(){ + long delta = System.currentTimeMillis() - lastTimeInternetConnectionChecked; + if(delta < 0 || delta > 15000){ + ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo active = mgr.getActiveNetworkInfo(); + if(active == null){ + internetConnectionAvailable = false; + } else { + NetworkInfo.State state = active.getState(); + internetConnectionAvailable = state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING; + } + } + return internetConnectionAvailable; + } + + /////////////// PREFERENCES classes //////////////// + + private abstract class CommonPreference implements OsmandPreference { + private final String id; + private final boolean global; + private T cachedValue; + private boolean cache; + + public CommonPreference(String id, boolean global){ + this.id = id; + this.global = global; + } + + public CommonPreference(String id, boolean global, boolean cache){ + this.id = id; + this.global = global; + this.cache = cache; + } + + protected SharedPreferences getPreferences(){ + return global ? globalPreferences : profilePreferences; + } + + protected abstract T getValue(); + + protected abstract boolean setValue(T val); + + @Override + public T get() { + if(cache && cachedValue != null){ + return cachedValue; + } + cachedValue = getValue(); + return cachedValue; + } + + @Override + public String getId() { + return id; + } + + @Override + public boolean set(T obj) { + if(setValue(obj)){ + cachedValue = obj; + return true; + } + return false; + } + + } + + private class BooleanPreference extends CommonPreference { + + private final boolean defValue; + + private BooleanPreference(String id, boolean defaultValue, boolean global) { + super(id, global); + this.defValue = 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()); + } + + @Override + protected boolean setValue(Boolean val) { + return getPreferences().edit().putBoolean(getId(), val).commit(); + } + + } + private class IntPreference extends CommonPreference { + + private final int defValue; + + private IntPreference(String id, int defaultValue, boolean global) { + super(id, global); + this.defValue = defaultValue; + } + + private IntPreference(String id, int defaultValue, boolean global, boolean cache) { + super(id, global, cache); + this.defValue = defaultValue; + } + + protected int getDefValue() { + return defValue; + } + + @Override + protected Integer getValue() { + return getPreferences().getInt(getId(), getDefValue()); + } + + @Override + protected boolean setValue(Integer val) { + return getPreferences().edit().putInt(getId(), val).commit(); + } + + } + + private class StringPreference extends CommonPreference { + + private final String defValue; + + private StringPreference(String id, String defaultValue, boolean global) { + super(id, global); + this.defValue = defaultValue; + } + + @Override + protected String getValue() { + return getPreferences().getString(getId(), defValue); + } + + @Override + protected boolean setValue(String val) { + return getPreferences().edit().putString(getId(), val).commit(); + } + + } + + private class EnumIntPreference> extends CommonPreference { + + 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; + this.values = values; + } + + private EnumIntPreference(String id, E defaultValue, boolean global, E[] values) { + super(id, global); + this.defValue = defaultValue; + this.values = values; + } + + + @Override + protected E getValue() { + int i = getPreferences().getInt(getId(), -1); + if(i < 0 || i >= values.length){ + return defValue; + } + return values[i]; + } + + @Override + protected boolean setValue(E val) { + return getPreferences().edit().putInt(getId(), val.ordinal()).commit(); + } + + } + /////////////// PREFERENCES classes //////////////// + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_INTERNET_TO_DOWNLOAD_TILES = + new BooleanPreference("use_internet_to_download_tiles", true, true, true); + + + // this value string is synchronized with settings_pref.xml preference name + // cache of metrics constants as they are used very often + public final OsmandPreference METRIC_SYSTEM = new EnumIntPreference( + "default_metric_system", MetricsConstants.KILOMETERS_AND_METERS, true, true, MetricsConstants.values()); + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_TRACKBALL_FOR_MOVEMENTS = + new BooleanPreference("use_trackball_for_movements", true, true); + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_HIGH_RES_MAPS = + new BooleanPreference("use_high_res_maps", false, false, true); + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_POI_OVER_MAP = + new BooleanPreference("show_poi_over_map", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_TRANSPORT_OVER_MAP = + new BooleanPreference("show_transport_over_map", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference PREFERRED_LOCALE = + new StringPreference("preferred_locale", "", true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USER_NAME = + new StringPreference("user_name", "NoName", true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USER_OSM_BUG_NAME = + new StringPreference("user_osm_bug_name", "NoName/Osmand", true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USER_PASSWORD = + new StringPreference("user_password", "", true); + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference DAYNIGHT_MODE = + new EnumIntPreference("daynight_mode", DayNightMode.AUTO, false, DayNightMode.values()); + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference ROUTER_SERVICE = + new EnumIntPreference("router_service", RouteService.OSMAND, false, RouteService.values()); + + + // this value string is synchronized with settings_pref.xml preference name + public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ + public static final String RELOAD_INDEXES = "reload_indexes"; //$NON-NLS-1$ + public static final String DOWNLOAD_INDEXES = "download_indexes"; //$NON-NLS-1$ + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SAVE_TRACK_TO_GPX = new + BooleanPreference("save_track_to_gpx", false, false){ + protected boolean getDefaultValue() { + boolean defaultValue = false; + if (currentMode == ApplicationMode.CAR || currentMode == ApplicationMode.BICYCLE) { + defaultValue = true; + } + return defaultValue; + }; + }; + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference FAST_ROUTE_MODE = new + BooleanPreference("fast_route_mode", true, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SAVE_TRACK_INTERVAL = new + IntPreference("save_track_interval", 5, false){ + + protected int getDefValue() { + int defValue = 5; + if(currentMode == ApplicationMode.BICYCLE){ + defValue = 15; + } + return defValue; + } + }; + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_OSMAND_ROUTING_SERVICE_ALWAYS = + new BooleanPreference("use_osmand_routing_service", true, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_OSM_BUGS = new BooleanPreference("show_osm_bugs", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference DEBUG_RENDERING_INFO = new BooleanPreference("debug_rendering", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_YANDEX_TRAFFIC = new BooleanPreference("show_yandex_traffic", false, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_FAVORITES = new BooleanPreference("show_favorites", false, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference MAP_SCREEN_ORIENTATION = + new IntPreference("map_screen_orientation", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, true); + + // TODO switch modes + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SHOW_VIEW_ANGLE = + new BooleanPreference("show_view_angle", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference AUTO_ZOOM_MAP = + new BooleanPreference("auto_zoom_map", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public static final int ROTATE_MAP_TO_BEARING_DEF = 0; + public static final int ROTATE_MAP_NONE = 0; + public static final int ROTATE_MAP_BEARING = 1; + public static final int ROTATE_MAP_COMPASS = 2; + public final OsmandPreference ROTATE_MAP = + new IntPreference("rotate_map", ROTATE_MAP_TO_BEARING_DEF, false); + + // this value string is synchronized with settings_pref.xml preference name + public static final int CENTER_CONSTANT = 0; + public static final int BOTTOM_CONSTANT = 1; + public final OsmandPreference POSITION_ON_MAP = new IntPreference("position_on_map", CENTER_CONSTANT, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference MAX_LEVEL_TO_DOWNLOAD_TILE = new IntPreference("max_level_download_tile", 18, false, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference MAP_VIEW_3D = new BooleanPreference("map_view_3d", false, false); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_ENGLISH_NAMES = new BooleanPreference("use_english_names", false, true); + + public boolean usingEnglishNames(){ + return USE_ENGLISH_NAMES.get(); + } + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference USE_STEP_BY_STEP_RENDERING = new BooleanPreference("use_step_by_step_rendering", + true, false); + + // this value string is synchronized with settings_pref.xml preference name + public static final String MAP_VECTOR_DATA = "map_vector_data"; //$NON-NLS-1$ + public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$ + + public boolean isUsingMapVectorData(){ + return globalPreferences.getBoolean(MAP_VECTOR_DATA, false); + } + + public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$ + + public File getExternalStorageDirectory() { + return new File(globalPreferences.getString(EXTERNAL_STORAGE_DIR, Environment.getExternalStorageDirectory().getAbsolutePath())); + } + + public File extendOsmandPath(String path) { + return new File(getExternalStorageDirectory(), path); + } + + public ITileSource getMapTileSource() { + String tileName = globalPreferences.getString(MAP_TILE_SOURCES, null); + if (tileName != null) { + + List list = TileSourceManager.getKnownSourceTemplates(); + for (TileSourceTemplate l : list) { + if (l.getName().equals(tileName)) { + return l; + } + } + File tPath = extendOsmandPath(ResourceManager.TILES_PATH); + File dir = new File(tPath, tileName); + if(dir.exists()){ + if(tileName.endsWith(SQLiteTileSource.EXT)){ + return new SQLiteTileSource(dir); + } else if (dir.isDirectory()) { + String url = null; + File readUrl = new File(dir, "url"); //$NON-NLS-1$ + try { + if (readUrl.exists()) { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(readUrl), "UTF-8")); //$NON-NLS-1$ + url = reader.readLine(); + url = url.replaceAll(Pattern.quote("{$z}"), "{0}"); //$NON-NLS-1$ //$NON-NLS-2$ + url = url.replaceAll(Pattern.quote("{$x}"), "{1}"); //$NON-NLS-1$//$NON-NLS-2$ + url = url.replaceAll(Pattern.quote("{$y}"), "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ + reader.close(); + } + } catch (IOException e) { + Log.d(LogUtil.TAG, "Error reading url " + dir.getName(), e); //$NON-NLS-1$ + } + return new TileSourceManager.TileSourceTemplate(dir, dir.getName(), url); + } + } + + } + return TileSourceManager.getMapnikSource(); + } + + public static String getMapTileSourceName(SharedPreferences prefs) { + String tileName = prefs.getString(MAP_TILE_SOURCES, null); + if (tileName != null) { + return tileName; + } + return TileSourceManager.getMapnikSource().getName(); + } + + // This value is a key for saving last known location shown on the map + public static final String LAST_KNOWN_MAP_LAT = "last_known_map_lat"; //$NON-NLS-1$ + public static final String LAST_KNOWN_MAP_LON = "last_known_map_lon"; //$NON-NLS-1$ + public static final String IS_MAP_SYNC_TO_GPS_LOCATION = "is_map_sync_to_gps_location"; //$NON-NLS-1$ + public static final String LAST_KNOWN_MAP_ZOOM = "last_known_map_zoom"; //$NON-NLS-1$ + + public static final String MAP_LAT_TO_SHOW = "map_lat_to_show"; //$NON-NLS-1$ + public static final String MAP_LON_TO_SHOW = "map_lon_to_show"; //$NON-NLS-1$ + public static final String MAP_ZOOM_TO_SHOW = "map_zoom_to_show"; //$NON-NLS-1$ + + public LatLon getLastKnownMapLocation() { + float lat = globalPreferences.getFloat(LAST_KNOWN_MAP_LAT, 0); + float lon = globalPreferences.getFloat(LAST_KNOWN_MAP_LON, 0); + return new LatLon(lat, lon); + } + + public boolean isLastKnownMapLocation(){ + return globalPreferences.contains(LAST_KNOWN_MAP_LAT); + } + + public void setMapLocationToShow(double latitude, double longitude) { + setMapLocationToShow(latitude, longitude, getLastKnownMapZoom(), null); + } + + public void setMapLocationToShow(double latitude, double longitude, int zoom) { + setMapLocationToShow(latitude, longitude, null); + } + + public LatLon getAndClearMapLocationToShow(){ + if(!globalPreferences.contains(MAP_LAT_TO_SHOW)){ + return null; + } + float lat = globalPreferences.getFloat(MAP_LAT_TO_SHOW, 0); + float lon = globalPreferences.getFloat(MAP_LON_TO_SHOW, 0); + globalPreferences.edit().remove(MAP_LAT_TO_SHOW).commit(); + return new LatLon(lat, lon); + } + + public int getMapZoomToShow() { + return globalPreferences.getInt(MAP_ZOOM_TO_SHOW, 5); + } + + public void setMapLocationToShow(double latitude, double longitude, int zoom, String historyDescription) { + Editor edit = globalPreferences.edit(); + edit.putFloat(MAP_LAT_TO_SHOW, (float) latitude); + edit.putFloat(MAP_LON_TO_SHOW, (float) longitude); + edit.putInt(MAP_ZOOM_TO_SHOW, zoom); + edit.putBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, false); + edit.commit(); + if(historyDescription != null){ + SearchHistoryHelper.getInstance().addNewItemToHistory(latitude, longitude, historyDescription, ctx); + } + } + + public void setMapLocationToShow(double latitude, double longitude, String historyDescription) { + setMapLocationToShow(latitude, longitude, getLastKnownMapZoom(), historyDescription); + } + + // Do not use that method if you want to show point on map. Use setMapLocationToShow + public void setLastKnownMapLocation(double latitude, double longitude) { + Editor edit = globalPreferences.edit(); + edit.putFloat(LAST_KNOWN_MAP_LAT, (float) latitude); + edit.putFloat(LAST_KNOWN_MAP_LON, (float) longitude); + edit.commit(); + } + + public boolean setSyncMapToGpsLocation(boolean value) { + return globalPreferences.edit().putBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, value).commit(); + } + + public boolean isMapSyncToGpsLocation() { + return globalPreferences.getBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, true); + } + + public int getLastKnownMapZoom() { + return globalPreferences.getInt(LAST_KNOWN_MAP_ZOOM, 5); + } + + public void setLastKnownMapZoom(int zoom) { + globalPreferences.edit().putInt(LAST_KNOWN_MAP_ZOOM, zoom).commit(); + } + + public final static String POINT_NAVIGATE_LAT = "point_navigate_lat"; //$NON-NLS-1$ + public final static String POINT_NAVIGATE_LON = "point_navigate_lon"; //$NON-NLS-1$ + + public LatLon getPointToNavigate() { + float lat = globalPreferences.getFloat(POINT_NAVIGATE_LAT, 0); + float lon = globalPreferences.getFloat(POINT_NAVIGATE_LON, 0); + if (lat == 0 && lon == 0) { + return null; + } + return new LatLon(lat, lon); + } + + public boolean clearPointToNavigate() { + return globalPreferences.edit().remove(POINT_NAVIGATE_LAT).remove(POINT_NAVIGATE_LON).commit(); + } + + public boolean setPointToNavigate(double latitude, double longitude) { + return globalPreferences.edit().putFloat(POINT_NAVIGATE_LAT, (float) latitude).putFloat(POINT_NAVIGATE_LON, (float) longitude).commit(); + } + + public static final String LAST_SEARCHED_REGION = "last_searched_region"; //$NON-NLS-1$ + public static final String LAST_SEARCHED_CITY = "last_searched_city"; //$NON-NLS-1$ + public static final String lAST_SEARCHED_POSTCODE= "last_searched_postcode"; //$NON-NLS-1$ + public static final String LAST_SEARCHED_STREET = "last_searched_street"; //$NON-NLS-1$ + public static final String LAST_SEARCHED_BUILDING = "last_searched_building"; //$NON-NLS-1$ + public static final String LAST_SEARCHED_INTERSECTED_STREET = "last_searched_intersected_street"; //$NON-NLS-1$ + + public String getLastSearchedRegion() { + return globalPreferences.getString(LAST_SEARCHED_REGION, ""); //$NON-NLS-1$ + } + + public boolean setLastSearchedRegion(String region) { + Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_REGION, region).putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, + "").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ //$NON-NLS-2$ + if (globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) { + edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ + } + return edit.commit(); + } + + public String getLastSearchedPostcode(){ + return globalPreferences.getString(lAST_SEARCHED_POSTCODE, null); + } + + public boolean setLastSearchedPostcode(String postcode){ + Editor edit = globalPreferences.edit().putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$ + LAST_SEARCHED_BUILDING, "").putString(lAST_SEARCHED_POSTCODE, postcode); //$NON-NLS-1$ + if(globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)){ + edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ + } + return edit.commit(); + } + + public Long getLastSearchedCity() { + return globalPreferences.getLong(LAST_SEARCHED_CITY, -1); + } + + public boolean setLastSearchedCity(Long cityId) { + Editor edit = globalPreferences.edit().putLong(LAST_SEARCHED_CITY, cityId).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$ + LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ + edit.remove(lAST_SEARCHED_POSTCODE); + if(globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)){ + edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ + } + return edit.commit(); + } + + public String getLastSearchedStreet() { + return globalPreferences.getString(LAST_SEARCHED_STREET, ""); //$NON-NLS-1$ + } + + public boolean setLastSearchedStreet(String street) { + Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_STREET, street).putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ + if (globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) { + edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ + } + return edit.commit(); + } + + public String getLastSearchedBuilding() { + return globalPreferences.getString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ + } + + public boolean setLastSearchedBuilding(String building) { + return globalPreferences.edit().putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); + } + + public String getLastSearchedIntersectedStreet() { + if (!globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) { + return null; + } + return globalPreferences.getString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ + } + + public boolean setLastSearchedIntersectedStreet(String street) { + return globalPreferences.edit().putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit(); + } + + public boolean removeLastSearchedIntersectedStreet() { + return globalPreferences.edit().remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); + } + + public static final String SELECTED_POI_FILTER_FOR_MAP = "selected_poi_filter_for_map"; //$NON-NLS-1$ + + public boolean setPoiFilterForMap(String filterId) { + return globalPreferences.edit().putString(SELECTED_POI_FILTER_FOR_MAP, filterId).commit(); + } + + public PoiFilter getPoiFilterForMap(OsmandApplication application) { + String filterId = globalPreferences.getString(SELECTED_POI_FILTER_FOR_MAP, null); + PoiFilter filter = application.getPoiFilters().getFilterById(filterId); + if (filter != null) { + return filter; + } + return new PoiFilter(null, application); + } + + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference 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 RENDERER = new StringPreference("renderer", null, false); + + public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false, true); + + // for background service + public final OsmandPreference MAP_ACTIVITY_ENABLED = new BooleanPreference("map_activity_enabled", false, true); + + // this value string is synchronized with settings_pref.xml preference name + public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$ + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SERVICE_OFF_PROVIDER = new StringPreference("service_off_provider", LocationManager.GPS_PROVIDER, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval", + 5 * 60 * 1000, true); + + // this value string is synchronized with settings_pref.xml preference name + public final OsmandPreference SERVICE_OFF_WAIT_INTERVAL = new IntPreference("service_off_wait_interval", + 90 * 1000, true); + + public final OsmandPreference CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null, true); + + + public final OsmandPreference FOLLOW_TO_THE_ROUTE = new BooleanPreference("follow_to_route", false, true); + + public final OsmandPreference SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = + new BooleanPreference("show_arrival_time", true, true); + public enum DayNightMode { AUTO(R.string.daynight_mode_auto), DAY(R.string.daynight_mode_day), @@ -92,747 +890,5 @@ public class OsmandSettings { } } - - // These settings are stored in SharedPreferences - private static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$ - - public static final int CENTER_CONSTANT = 0; - public static final int BOTTOM_CONSTANT = 1; - - public static final Editor getWriteableEditor(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE); - return prefs.edit(); - } - - public static final SharedPreferences getPrefs(Context ctx){ - return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); - } - - public static final SharedPreferences getPrefsToEdit(Context ctx){ - return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_INTERNET_TO_DOWNLOAD_TILES = "use_internet_to_download_tiles"; //$NON-NLS-1$ - public static final boolean USE_INTERNET_TO_DOWNLOAD_TILES_DEF = true; - private static Boolean CACHE_USE_INTERNET_TO_DOWNLOAD_TILES = null; - private static long lastTimeInternetConnectionChecked = 0; - private static boolean internetConnectionAvailable = true; - - public static boolean isUsingInternetToDownloadTiles(SharedPreferences prefs) { - if(CACHE_USE_INTERNET_TO_DOWNLOAD_TILES == null){ - CACHE_USE_INTERNET_TO_DOWNLOAD_TILES = prefs.getBoolean(USE_INTERNET_TO_DOWNLOAD_TILES, USE_INTERNET_TO_DOWNLOAD_TILES_DEF); - } - return CACHE_USE_INTERNET_TO_DOWNLOAD_TILES; - } - - public static void setUseInternetToDownloadTiles(boolean use, Editor edit) { - edit.putBoolean(USE_INTERNET_TO_DOWNLOAD_TILES, use).commit(); - CACHE_USE_INTERNET_TO_DOWNLOAD_TILES = use; - } - - public static boolean isInternetConnectionAvailable(Context ctx){ - long delta = System.currentTimeMillis() - lastTimeInternetConnectionChecked; - if(delta < 0 || delta > 15000){ - ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo active = mgr.getActiveNetworkInfo(); - if(active == null){ - internetConnectionAvailable = false; - } else { - NetworkInfo.State state = active.getState(); - internetConnectionAvailable = state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING; - } - } - return internetConnectionAvailable; - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String DEFAULT_METRIC_SYSTEM = "default_metric_system"; //$NON-NLS-1$ - public static final int DEFAULT_METRIC_SYSTEM_DEF = 0; - // cache of metrics constants as they are used very often - private static MetricsConstants metricConstants = null; - - public static MetricsConstants getDefaultMetricConstants(Context ctx) { - if (metricConstants == null) { - int value = getPrefs(ctx).getInt(DEFAULT_METRIC_SYSTEM, DEFAULT_METRIC_SYSTEM_DEF); - if (value >= MetricsConstants.values().length) { - metricConstants = MetricsConstants.KILOMETERS_AND_METERS; - } else { - metricConstants = MetricsConstants.values()[value]; - } - } - return metricConstants; - } - - public static void setDefaultMetricConstants( MetricsConstants constants, Context ctx){ - getWriteableEditor(ctx).putInt(DEFAULT_METRIC_SYSTEM, constants.ordinal()).commit(); - metricConstants = constants; - } - - - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_TRACKBALL_FOR_MOVEMENTS = "use_trackball_for_movements"; //$NON-NLS-1$ - public static final boolean USE_TRACKBALL_FOR_MOVEMENTS_DEF = true; - - public static boolean isUsingTrackBall(SharedPreferences prefs) { - return prefs.getBoolean(USE_TRACKBALL_FOR_MOVEMENTS, USE_TRACKBALL_FOR_MOVEMENTS_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_HIGH_RES_MAPS = "use_high_res_maps"; //$NON-NLS-1$ - public static final boolean USE_HIGH_RES_MAPS_DEF = false; - - public static boolean isUsingHighResMaps(SharedPreferences prefs) { - return prefs.getBoolean(USE_HIGH_RES_MAPS, USE_HIGH_RES_MAPS_DEF); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_POI_OVER_MAP = "show_poi_over_map"; //$NON-NLS-1$ - public static final Boolean SHOW_POI_OVER_MAP_DEF = false; - - public static boolean isShowingPoiOverMap(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_POI_OVER_MAP, SHOW_POI_OVER_MAP_DEF); - } - - public static boolean setShowPoiOverMap(Context ctx, boolean val) { - return getWriteableEditor(ctx).putBoolean(SHOW_POI_OVER_MAP, val).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_TRANSPORT_OVER_MAP = "show_transport_over_map"; //$NON-NLS-1$ - public static final boolean SHOW_TRANSPORT_OVER_MAP_DEF = false; - - public static boolean isShowingTransportOverMap(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_TRANSPORT_OVER_MAP, SHOW_TRANSPORT_OVER_MAP_DEF); - } - - public static boolean setShowTransortOverMap(Context ctx, boolean val) { - return getWriteableEditor(ctx).putBoolean(SHOW_TRANSPORT_OVER_MAP, val).commit(); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String PREFERRED_LOCALE = "preferred_locale"; //$NON-NLS-1$ - public static final String PREFERRED_LOCALE_DEF = ""; //$NON-NLS-1$ - - public static String getPreferredLocale(SharedPreferences prefs) { - return prefs.getString(PREFERRED_LOCALE, PREFERRED_LOCALE_DEF); //$NON-NLS-1$ - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USER_NAME = "user_name"; //$NON-NLS-1$ - public static final String USER_NAME_DEF = "NoName"; //$NON-NLS-1$ - - public static String getUserName(SharedPreferences prefs) { - return prefs.getString(USER_NAME, USER_NAME_DEF); - } - - public static boolean setUserName(Context ctx, String name) { - return getWriteableEditor(ctx).putString(USER_NAME, name).commit(); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String USER_OSM_BUG_NAME = "user_osm_bug_name"; //$NON-NLS-1$ - - public static String getUserNameForOsmBug(SharedPreferences prefs) { - return prefs.getString(USER_OSM_BUG_NAME, "NoName/Osmand"); //$NON-NLS-1$ - } - - public static boolean setUserNameForOsmBug(Context ctx, String name) { - return getWriteableEditor(ctx).putString(USER_OSM_BUG_NAME, name).commit(); - } - - public static final String USER_PASSWORD = "user_password"; //$NON-NLS-1$ - public static String getUserPassword(SharedPreferences prefs){ - return prefs.getString(USER_PASSWORD, ""); //$NON-NLS-1$ - } - - public static boolean setUserPassword(Context ctx, String name){ - return getWriteableEditor(ctx).putString(USER_PASSWORD, name).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String APPLICATION_MODE = "application_mode"; //$NON-NLS-1$ - - public static ApplicationMode getApplicationMode(SharedPreferences prefs) { - String s = prefs.getString(APPLICATION_MODE, ApplicationMode.DEFAULT.name()); - try { - return ApplicationMode.valueOf(s); - } catch (IllegalArgumentException e) { - return ApplicationMode.DEFAULT; - } - } - - public static boolean setApplicationMode(Context ctx, ApplicationMode p) { - return getWriteableEditor(ctx).putString(APPLICATION_MODE, p.name()).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String DAYNIGHT_MODE = "daynight_mode"; //$NON-NLS-1$ - public static DayNightMode getDayNightMode(SharedPreferences prefs) { - String s = prefs.getString(DAYNIGHT_MODE, DayNightMode.AUTO.name()); - try { - return DayNightMode.valueOf(s); - } catch (IllegalArgumentException e) { - return DayNightMode.AUTO; - } - } - - public static boolean setDayNightMode(Context ctx, DayNightMode p) { - return getWriteableEditor(ctx).putString(APPLICATION_MODE, p.name()).commit(); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String ROUTER_SERVICE = "router_service"; //$NON-NLS-1$ - - public static RouteService getRouterService(SharedPreferences prefs) { - int ord = prefs.getInt(ROUTER_SERVICE, RouteService.OSMAND.ordinal()); - // that fix specially for 0.5.2 release - if(ord < RouteService.values().length){ - return RouteService.values()[ord]; - } else { - return RouteService.OSMAND; - } - } - - public static boolean setRouterService(Context ctx, RouteService p) { - return getWriteableEditor(ctx).putInt(ROUTER_SERVICE, p.ordinal()).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ - public static final String RELOAD_INDEXES = "reload_indexes"; //$NON-NLS-1$ - public static final String DOWNLOAD_INDEXES = "download_indexes"; //$NON-NLS-1$ - - // this value string is synchronized with settings_pref.xml preference name - public static final String SAVE_TRACK_TO_GPX = "save_track_to_gpx"; //$NON-NLS-1$ - public static final boolean SAVE_TRACK_TO_GPX_DEF = false; - - public static boolean isSavingTrackToGpx(Context ctx) { - SharedPreferences prefs = getPrefs(ctx); - return prefs.getBoolean(SAVE_TRACK_TO_GPX, SAVE_TRACK_TO_GPX_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String FAST_ROUTE_MODE = "fast_route_mode"; //$NON-NLS-1$ - public static final boolean FAST_ROUTE_MODE_DEF = true; - - public static boolean isFastRouteMode(Context ctx) { - SharedPreferences prefs = getPrefs(ctx); - return prefs.getBoolean(FAST_ROUTE_MODE, FAST_ROUTE_MODE_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SAVE_TRACK_INTERVAL = "save_track_interval"; //$NON-NLS-1$ - - public static int getSavingTrackInterval(SharedPreferences prefs) { - return prefs.getInt(SAVE_TRACK_INTERVAL, 5); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_OSMAND_ROUTING_SERVICE_ALWAYS = "use_osmand_routing_service"; //$NON-NLS-1$ - public static final boolean USE_OSMAND_ROUTING_SERVICE_ALWAYS_DEF = false; - - public static boolean isOsmandRoutingServiceUsed(Context ctx) { - SharedPreferences prefs = getPrefs(ctx); - return prefs.getBoolean(USE_OSMAND_ROUTING_SERVICE_ALWAYS, USE_OSMAND_ROUTING_SERVICE_ALWAYS_DEF); - } - - - - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_OSM_BUGS = "show_osm_bugs"; //$NON-NLS-1$ - public static final boolean SHOW_OSM_BUGS_DEF = false; - - public static boolean isShowingOsmBugs(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_OSM_BUGS, SHOW_OSM_BUGS_DEF); - } - - public static boolean setShowingOsmBugs(Context ctx, boolean val) { - return getWriteableEditor(ctx).putBoolean(SHOW_OSM_BUGS, val).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String DEBUG_RENDERING_INFO = "debug_rendering"; //$NON-NLS-1$ - public static final boolean DEBUG_RENDERING_INFO_DEF = false; - - public static boolean isDebugRendering(Context ctx) { - SharedPreferences prefs = getPrefs(ctx); - return prefs.getBoolean(DEBUG_RENDERING_INFO, DEBUG_RENDERING_INFO_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_YANDEX_TRAFFIC = "show_yandex_traffic"; //$NON-NLS-1$ - public static final boolean SHOW_YANDEX_TRAFFIC_DEF = false; - - public static boolean isShowingYandexTraffic(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_YANDEX_TRAFFIC, SHOW_YANDEX_TRAFFIC_DEF); - } - - public static boolean setShowingYandexTraffic(Context ctx, boolean val) { - return getWriteableEditor(ctx).putBoolean(SHOW_YANDEX_TRAFFIC, val).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_FAVORITES = "show_favorites"; //$NON-NLS-1$ - public static final boolean SHOW_FAVORITES_DEF = false; - - public static boolean isShowingFavorites(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_FAVORITES, SHOW_FAVORITES_DEF); - } - - public static boolean setShowingFavorites(Context ctx, boolean val) { - return getWriteableEditor(ctx).putBoolean(SHOW_FAVORITES, val).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String MAP_SCREEN_ORIENTATION = "map_screen_orientation"; //$NON-NLS-1$ - - public static int getMapOrientation(SharedPreferences prefs){ - return prefs.getInt(MAP_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SHOW_VIEW_ANGLE = "show_view_angle"; //$NON-NLS-1$ - public static final boolean SHOW_VIEW_ANGLE_DEF = false; - - public static boolean isShowingViewAngle(SharedPreferences prefs) { - return prefs.getBoolean(SHOW_VIEW_ANGLE, SHOW_VIEW_ANGLE_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String AUTO_ZOOM_MAP = "auto_zoom_map"; //$NON-NLS-1$ - public static final boolean AUTO_ZOOM_MAP_DEF = false; - - public static boolean isAutoZoomEnabled(SharedPreferences prefs) { - return prefs.getBoolean(AUTO_ZOOM_MAP, AUTO_ZOOM_MAP_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String ROTATE_MAP = "rotate_map"; //$NON-NLS-1$ - public static final int ROTATE_MAP_TO_BEARING_DEF = 0; - public static final int ROTATE_MAP_NONE = 0; - public static final int ROTATE_MAP_BEARING = 1; - public static final int ROTATE_MAP_COMPASS = 2; - - // return 0 - no rotate, 1 - to bearing, 2 - to compass - public static int getRotateMap(SharedPreferences prefs) { - return prefs.getInt(ROTATE_MAP, ROTATE_MAP_TO_BEARING_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String POSITION_ON_MAP = "position_on_map"; //$NON-NLS-1$ - - public static int getPositionOnMap(SharedPreferences prefs) { - return prefs.getInt(POSITION_ON_MAP, CENTER_CONSTANT); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String MAX_LEVEL_TO_DOWNLOAD_TILE = "max_level_download_tile"; //$NON-NLS-1$ - - public static int getMaximumLevelToDownloadTile(SharedPreferences prefs) { - return prefs.getInt(MAX_LEVEL_TO_DOWNLOAD_TILE, 18); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String MAP_VIEW_3D = "map_view_3d"; //$NON-NLS-1$ - public static final boolean MAP_VIEW_3D_DEF = false; - - public static boolean isMapView3D(SharedPreferences prefs) { - return prefs.getBoolean(MAP_VIEW_3D, MAP_VIEW_3D_DEF); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_ENGLISH_NAMES = "use_english_names"; //$NON-NLS-1$ - public static final boolean USE_ENGLISH_NAMES_DEF = false; - - public static boolean usingEnglishNames(SharedPreferences prefs) { - return prefs.getBoolean(USE_ENGLISH_NAMES, USE_ENGLISH_NAMES_DEF); - } - - public static boolean setUseEnglishNames(Context ctx, boolean useEnglishNames) { - return getWriteableEditor(ctx).putBoolean(USE_ENGLISH_NAMES, useEnglishNames).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String USE_STEP_BY_STEP_RENDERING = "use_step_by_step_rendering"; //$NON-NLS-1$ - public static final boolean USE_STEP_BY_STEP_RENDERING_DEF = true; - - public static boolean isUsingStepByStepRendering(SharedPreferences prefs) { - return prefs.getBoolean(USE_STEP_BY_STEP_RENDERING, USE_STEP_BY_STEP_RENDERING_DEF); - } - - public static boolean setUsingStepByStepRendering(Context ctx, boolean rendering) { - return getWriteableEditor(ctx).putBoolean(USE_STEP_BY_STEP_RENDERING, rendering).commit(); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String MAP_VECTOR_DATA = "map_vector_data"; //$NON-NLS-1$ - public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$ - - public static boolean isUsingMapVectorData(SharedPreferences prefs){ - return prefs.getBoolean(MAP_VECTOR_DATA, false); - } - - public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$ -// public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$ - - public static File getExternalStorageDirectory(SharedPreferences prefs) { - return new File(prefs.getString(EXTERNAL_STORAGE_DIR, Environment.getExternalStorageDirectory().getAbsolutePath())); - } - - public static File getExternalStorageDirectory(Context ctx) { - return getExternalStorageDirectory(getPrefs(ctx)); - } - - public static File extendOsmandPath(SharedPreferences prefs, String path) { - return new File(getExternalStorageDirectory(prefs), path); - } - - public static File extendOsmandPath(Context ctx, String path) { - return new File(getExternalStorageDirectory(ctx), path); - } - - public static ITileSource getMapTileSource(SharedPreferences prefs) { - String tileName = prefs.getString(MAP_TILE_SOURCES, null); - if (tileName != null) { - - List list = TileSourceManager.getKnownSourceTemplates(); - for (TileSourceTemplate l : list) { - if (l.getName().equals(tileName)) { - return l; - } - } - File tPath = OsmandSettings.extendOsmandPath(prefs, ResourceManager.TILES_PATH); - File dir = new File(tPath, tileName); - if(dir.exists()){ - if(tileName.endsWith(SQLiteTileSource.EXT)){ - return new SQLiteTileSource(dir); - } else if (dir.isDirectory()) { - String url = null; - File readUrl = new File(dir, "url"); //$NON-NLS-1$ - try { - if (readUrl.exists()) { - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(readUrl), "UTF-8")); //$NON-NLS-1$ - url = reader.readLine(); - url = url.replaceAll(Pattern.quote("{$z}"), "{0}"); //$NON-NLS-1$ //$NON-NLS-2$ - url = url.replaceAll(Pattern.quote("{$x}"), "{1}"); //$NON-NLS-1$//$NON-NLS-2$ - url = url.replaceAll(Pattern.quote("{$y}"), "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ - reader.close(); - } - } catch (IOException e) { - Log.d(LogUtil.TAG, "Error reading url " + dir.getName(), e); //$NON-NLS-1$ - } - return new TileSourceManager.TileSourceTemplate(dir, dir.getName(), url); - } - } - - } - return TileSourceManager.getMapnikSource(); - } - - public static String getMapTileSourceName(SharedPreferences prefs) { - String tileName = prefs.getString(MAP_TILE_SOURCES, null); - if (tileName != null) { - return tileName; - } - return TileSourceManager.getMapnikSource().getName(); - } - - // This value is a key for saving last known location shown on the map - public static final String LAST_KNOWN_MAP_LAT = "last_known_map_lat"; //$NON-NLS-1$ - public static final String LAST_KNOWN_MAP_LON = "last_known_map_lon"; //$NON-NLS-1$ - public static final String IS_MAP_SYNC_TO_GPS_LOCATION = "is_map_sync_to_gps_location"; //$NON-NLS-1$ - public static final String LAST_KNOWN_MAP_ZOOM = "last_known_map_zoom"; //$NON-NLS-1$ - - public static final String MAP_LAT_TO_SHOW = "map_lat_to_show"; //$NON-NLS-1$ - public static final String MAP_LON_TO_SHOW = "map_lon_to_show"; //$NON-NLS-1$ - public static final String MAP_ZOOM_TO_SHOW = "map_zoom_to_show"; //$NON-NLS-1$ - - public static LatLon getLastKnownMapLocation(SharedPreferences prefs) { - float lat = prefs.getFloat(LAST_KNOWN_MAP_LAT, 0); - float lon = prefs.getFloat(LAST_KNOWN_MAP_LON, 0); - return new LatLon(lat, lon); - } - - public static void setMapLocationToShow(Context ctx, double latitude, double longitude) { - setMapLocationToShow(ctx, latitude, longitude, getLastKnownMapZoom(getPrefs(ctx)), null); - } - - public static void setMapLocationToShow(Context ctx, double latitude, double longitude, int zoom) { - setMapLocationToShow(ctx, latitude, longitude, null); - } - - public static LatLon getAndClearMapLocationToShow(SharedPreferences prefs){ - if(!prefs.contains(MAP_LAT_TO_SHOW)){ - return null; - } - float lat = prefs.getFloat(MAP_LAT_TO_SHOW, 0); - float lon = prefs.getFloat(MAP_LON_TO_SHOW, 0); - prefs.edit().remove(MAP_LAT_TO_SHOW).commit(); - return new LatLon(lat, lon); - } - - public static int getMapZoomToShow(SharedPreferences prefs) { - return prefs.getInt(MAP_ZOOM_TO_SHOW, 5); - } - - public static void setMapLocationToShow(Context ctx, double latitude, double longitude, int zoom, String historyDescription) { - Editor edit = getWriteableEditor(ctx); - edit.putFloat(MAP_LAT_TO_SHOW, (float) latitude); - edit.putFloat(MAP_LON_TO_SHOW, (float) longitude); - edit.putInt(MAP_ZOOM_TO_SHOW, zoom); - edit.putBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, false); - edit.commit(); - if(historyDescription != null){ - SearchHistoryHelper.getInstance().addNewItemToHistory(latitude, longitude, historyDescription, ctx); - } - } - - public static void setMapLocationToShow(Context ctx, double latitude, double longitude, String historyDescription) { - setMapLocationToShow(ctx, latitude, longitude, getLastKnownMapZoom(getPrefs(ctx)), historyDescription); - } - - // Do not use that method if you want to show point on map. Use setMapLocationToShow - public static void setLastKnownMapLocation(Context ctx, double latitude, double longitude) { - Editor edit = getWriteableEditor(ctx); - edit.putFloat(LAST_KNOWN_MAP_LAT, (float) latitude); - edit.putFloat(LAST_KNOWN_MAP_LON, (float) longitude); - edit.commit(); - } - - public static boolean setSyncMapToGpsLocation(Context ctx, boolean value) { - return getWriteableEditor(ctx).putBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, value).commit(); - } - - public static boolean isMapSyncToGpsLocation(SharedPreferences prefs) { - return prefs.getBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, true); - } - - public static int getLastKnownMapZoom(SharedPreferences prefs) { - return prefs.getInt(LAST_KNOWN_MAP_ZOOM, 5); - } - - public static void setLastKnownMapZoom(Context ctx, int zoom) { - Editor edit = getWriteableEditor(ctx); - edit.putInt(LAST_KNOWN_MAP_ZOOM, zoom); - edit.commit(); - } - - public final static String POINT_NAVIGATE_LAT = "point_navigate_lat"; //$NON-NLS-1$ - public final static String POINT_NAVIGATE_LON = "point_navigate_lon"; //$NON-NLS-1$ - - public static LatLon getPointToNavigate(SharedPreferences prefs) { - float lat = prefs.getFloat(POINT_NAVIGATE_LAT, 0); - float lon = prefs.getFloat(POINT_NAVIGATE_LON, 0); - if (lat == 0 && lon == 0) { - return null; - } - return new LatLon(lat, lon); - } - - public static boolean clearPointToNavigate(Context ctx) { - return getWriteableEditor(ctx).remove(POINT_NAVIGATE_LAT).remove(POINT_NAVIGATE_LON).commit(); - } - - public static boolean setPointToNavigate(Context ctx, double latitude, double longitude) { - return getWriteableEditor(ctx).putFloat(POINT_NAVIGATE_LAT, (float) latitude).putFloat(POINT_NAVIGATE_LON, (float) longitude).commit(); - } - - public static final String LAST_SEARCHED_REGION = "last_searched_region"; //$NON-NLS-1$ - public static final String LAST_SEARCHED_CITY = "last_searched_city"; //$NON-NLS-1$ - public static final String lAST_SEARCHED_POSTCODE= "last_searched_postcode"; //$NON-NLS-1$ - public static final String LAST_SEARCHED_STREET = "last_searched_street"; //$NON-NLS-1$ - public static final String LAST_SEARCHED_BUILDING = "last_searched_building"; //$NON-NLS-1$ - public static final String LAST_SEARCHED_INTERSECTED_STREET = "last_searched_intersected_street"; //$NON-NLS-1$ - - public static String getLastSearchedRegion(SharedPreferences prefs) { - return prefs.getString(LAST_SEARCHED_REGION, ""); //$NON-NLS-1$ - } - - public static boolean setLastSearchedRegion(Context ctx, String region) { - SharedPreferences prefs = getPrefs(ctx); - Editor edit = getWriteableEditor(ctx).putString(LAST_SEARCHED_REGION, region).putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, - "").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ //$NON-NLS-2$ - if (prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)) { - edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ - } - return edit.commit(); - } - - public static String getLastSearchedPostcode(SharedPreferences prefs){ - return prefs.getString(lAST_SEARCHED_POSTCODE, null); - } - - public static boolean setLastSearchedPostcode(Context ctx, String postcode){ - SharedPreferences prefs = getPrefs(ctx); - Editor edit = getWriteableEditor(ctx).putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$ - LAST_SEARCHED_BUILDING, "").putString(lAST_SEARCHED_POSTCODE, postcode); //$NON-NLS-1$ - if(prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)){ - edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ - } - return edit.commit(); - } - - public static Long getLastSearchedCity(SharedPreferences prefs) { - return prefs.getLong(LAST_SEARCHED_CITY, -1); - } - - public static boolean setLastSearchedCity(Context ctx, Long cityId) { - SharedPreferences prefs = getPrefs(ctx); - Editor edit = getWriteableEditor(ctx).putLong(LAST_SEARCHED_CITY, cityId).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$ - LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ - edit.remove(lAST_SEARCHED_POSTCODE); - if(prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)){ - edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ - } - return edit.commit(); - } - - public static String getLastSearchedStreet(SharedPreferences prefs) { - return prefs.getString(LAST_SEARCHED_STREET, ""); //$NON-NLS-1$ - } - - public static boolean setLastSearchedStreet(Context ctx, String street) { - SharedPreferences prefs = getPrefs(ctx); - Editor edit = getWriteableEditor(ctx).putString(LAST_SEARCHED_STREET, street).putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ - if (prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)) { - edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ - } - return edit.commit(); - } - - public static String getLastSearchedBuilding(SharedPreferences prefs) { - return prefs.getString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ - } - - public static boolean setLastSearchedBuilding(Context ctx, String building) { - return getWriteableEditor(ctx).putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); - } - - public static String getLastSearchedIntersectedStreet(SharedPreferences prefs) { - if (!prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)) { - return null; - } - return prefs.getString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$ - } - - public static boolean setLastSearchedIntersectedStreet(Context ctx, String street) { - return getWriteableEditor(ctx).putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit(); - } - - public static boolean removeLastSearchedIntersectedStreet(Context ctx) { - return getWriteableEditor(ctx).remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); - } - - public static final String SELECTED_POI_FILTER_FOR_MAP = "selected_poi_filter_for_map"; //$NON-NLS-1$ - - public static boolean setPoiFilterForMap(Context ctx, String filterId) { - return getWriteableEditor(ctx).putString(SELECTED_POI_FILTER_FOR_MAP, filterId).commit(); - } - - public static PoiFilter getPoiFilterForMap(Context ctx, OsmandApplication application) { - SharedPreferences prefs = getPrefs(ctx); - String filterId = prefs.getString(SELECTED_POI_FILTER_FOR_MAP, null); - PoiFilter filter = application.getPoiFilters().getFilterById(filterId); - if (filter != null) { - return filter; - } - return new PoiFilter(null, application); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String VOICE_PROVIDER = "voice_provider"; //$NON-NLS-1$ - - public static String getVoiceProvider(SharedPreferences prefs){ - return prefs.getString(VOICE_PROVIDER, null); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String RENDERER = "renderer"; //$NON-NLS-1$ - - public static String getVectorRenderer(SharedPreferences prefs){ - return prefs.getString(RENDERER, null); - } - - public static final String VOICE_MUTE = "voice_mute"; //$NON-NLS-1$ - public static final boolean VOICE_MUTE_DEF = false; - - public static boolean isVoiceMute(SharedPreferences prefs){ - return prefs.getBoolean(VOICE_MUTE, VOICE_MUTE_DEF); - } - - public static boolean setVoiceMute(Context ctx, boolean mute){ - return getWriteableEditor(ctx).putBoolean(VOICE_MUTE, mute).commit(); - } - - // for background service - public static final String MAP_ACTIVITY_ENABLED = "map_activity_enabled"; //$NON-NLS-1$ - public static final boolean MAP_ACTIVITY_ENABLED_DEF = false; - public static boolean getMapActivityEnabled(SharedPreferences prefs) { - return prefs.getBoolean(MAP_ACTIVITY_ENABLED, MAP_ACTIVITY_ENABLED_DEF); - } - - public static boolean setMapActivityEnabled(Context ctx, boolean en) { - return getWriteableEditor(ctx).putBoolean(MAP_ACTIVITY_ENABLED, en).commit(); - } - - // this value string is synchronized with settings_pref.xml preference name - public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$ - - - - // this value string is synchronized with settings_pref.xml preference name - public static final String SERVICE_OFF_PROVIDER = "service_off_provider"; //$NON-NLS-1$ - public static String getServiceOffProvider(SharedPreferences prefs) { - return prefs.getString(SERVICE_OFF_PROVIDER, LocationManager.GPS_PROVIDER); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String SERVICE_OFF_INTERVAL = "service_off_interval"; //$NON-NLS-1$ - public static final int SERVICE_OFF_INTERVAL_DEF = 5 * 60 * 1000; - public static int getServiceOffInterval(SharedPreferences prefs) { - return prefs.getInt(SERVICE_OFF_INTERVAL, SERVICE_OFF_INTERVAL_DEF); - } - - - // this value string is synchronized with settings_pref.xml preference name - public static final String SERVICE_OFF_WAIT_INTERVAL = "service_off_wait_interval"; //$NON-NLS-1$ - public static final int SERVICE_OFF_WAIT_INTERVAL_DEF = 90 * 1000; - public static int getServiceOffWaitInterval(SharedPreferences prefs) { - return prefs.getInt(SERVICE_OFF_WAIT_INTERVAL, SERVICE_OFF_WAIT_INTERVAL_DEF); - } - - - public static final String FOLLOW_TO_THE_ROUTE = "follow_to_route"; //$NON-NLS-1$ - - public static boolean isFollowingByRoute(SharedPreferences prefs){ - return prefs.getBoolean(FOLLOW_TO_THE_ROUTE, false); - } - - public static boolean setFollowingByRoute(Context ctx, boolean val){ - return getWriteableEditor(ctx).putBoolean(FOLLOW_TO_THE_ROUTE, val).commit(); - } - - public static final String SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = "show_arrival_time"; //$NON-NLS-1$ - - public static boolean isShowingArrivalTime(SharedPreferences prefs){ - return prefs.getBoolean(SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME, true); - } - - public static boolean setShowingArrivalTime(Context ctx, boolean val){ - return getWriteableEditor(ctx).putBoolean(SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME, val).commit(); - } - - } diff --git a/OsmAnd/src/net/osmand/plus/ResourceManager.java b/OsmAnd/src/net/osmand/plus/ResourceManager.java index ec2b59dc98..85519b8ae1 100644 --- a/OsmAnd/src/net/osmand/plus/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/ResourceManager.java @@ -101,7 +101,7 @@ public class ResourceManager { } public void resetStoreDirectory() { - dirWithTiles = OsmandSettings.extendOsmandPath(context, TILES_PATH); + dirWithTiles = OsmandSettings.getOsmandSettings(context).extendOsmandPath(TILES_PATH); dirWithTiles.mkdirs(); } @@ -352,7 +352,7 @@ public class ResourceManager { } private void initRenderers(IProgress progress) { - File file = OsmandSettings.extendOsmandPath(context, APP_DIR + IndexConstants.RENDERERS_DIR); + File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(APP_DIR + IndexConstants.RENDERERS_DIR); file.mkdirs(); Map externalRenderers = new LinkedHashMap(); if (file.exists() && file.canRead()) { @@ -364,7 +364,7 @@ public class ResourceManager { } } RendererRegistry.getRegistry().setExternalRenderers(externalRenderers); - String r = OsmandSettings.getVectorRenderer(OsmandSettings.getPrefs(context)); + String r = OsmandSettings.getOsmandSettings(context).RENDERER.get(); if(r != null){ BaseOsmandRender obj = RendererRegistry.getRegistry().getRenderer(r); if(obj != null){ @@ -374,7 +374,7 @@ public class ResourceManager { } public List indexingMaps(final IProgress progress) { - File file = OsmandSettings.extendOsmandPath(context, MAPS_PATH); + File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(MAPS_PATH); file.mkdirs(); List warnings = new ArrayList(); renderer.clearAllResources(); @@ -431,7 +431,7 @@ public class ResourceManager { // POI INDEX // public List indexingPoi(final IProgress progress) { - File file = OsmandSettings.extendOsmandPath(context, POI_PATH); + File file = OsmandSettings.getOsmandSettings(context).extendOsmandPath(POI_PATH); file.mkdirs(); List warnings = new ArrayList(); closeAmenities(); diff --git a/OsmAnd/src/net/osmand/plus/activities/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/activities/ApplicationMode.java index cf6326c5f1..a3f7c81b9c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/activities/ApplicationMode.java @@ -27,92 +27,4 @@ public enum ApplicationMode { return ctx.getResources().getString(m.key); } - public static boolean setAppMode(ApplicationMode preset, OsmandApplication app) { - - ApplicationMode old = OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(app)); - if(preset == old){ - return false; - } - Editor edit = OsmandSettings.getWriteableEditor(app); - edit.putString(OsmandSettings.APPLICATION_MODE, preset.toString()); - if (preset == ApplicationMode.CAR) { - OsmandSettings.setUseInternetToDownloadTiles(true, edit); - // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, _); - edit.putBoolean(OsmandSettings.SHOW_TRANSPORT_OVER_MAP, false); - edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING); - edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); - edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, true); - edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, false); - edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, true); - // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); - edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true); - edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 5); - edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT); - // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); - - } else if (preset == ApplicationMode.BICYCLE) { - // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); - // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_CALCULATE_ROUTE, _); - // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); - edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_BEARING); - edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true); - edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); - // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); - // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); - edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, true); - edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, 30); - edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.BOTTOM_CONSTANT); - // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); - - } else if (preset == ApplicationMode.PEDESTRIAN) { - // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); - // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); - edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_COMPASS); - edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, true); - edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); - edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, false); - // if(useInternetToDownloadTiles.isChecked()){ - // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, true); - // } - // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); - edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, false); - // edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _); - edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT); - // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); - - } else if (preset == ApplicationMode.DEFAULT) { - // edit.putBoolean(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES, _); - // edit.putBoolean(OsmandSettings.SHOW_POI_OVER_MAP, true); - edit.putInt(OsmandSettings.ROTATE_MAP, OsmandSettings.ROTATE_MAP_NONE); - edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, false); - edit.putBoolean(OsmandSettings.AUTO_ZOOM_MAP, false); - edit.putBoolean(OsmandSettings.USE_STEP_BY_STEP_RENDERING, true); - // edit.putBoolean(OsmandSettings.SHOW_OSM_BUGS, _); - // edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, _); - edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, false); - // edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, _); - edit.putInt(OsmandSettings.POSITION_ON_MAP, OsmandSettings.CENTER_CONSTANT); - // edit.putString(OsmandSettings.MAP_TILE_SOURCES, _); - - } - - BaseOsmandRender current = RendererRegistry.getRegistry().getCurrentSelectedRenderer(); - BaseOsmandRender defaultRender = RendererRegistry.getRegistry().defaultRender(); - BaseOsmandRender newRenderer; - if (preset == ApplicationMode.CAR) { - newRenderer = RendererRegistry.getRegistry().carRender(); - } else if (preset == ApplicationMode.BICYCLE) { - newRenderer = RendererRegistry.getRegistry().bicycleRender(); - } else if (preset == ApplicationMode.PEDESTRIAN) { - newRenderer = RendererRegistry.getRegistry().pedestrianRender(); - } else { - newRenderer = defaultRender; - } - if (newRenderer != current) { - RendererRegistry.getRegistry().setCurrentSelectedRender(newRenderer); - app.getResourceManager().getRenderer().clearCache(); - } - return edit.commit(); - } - } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java index aa33350c14..33d6ca648c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java @@ -65,7 +65,7 @@ public class ContributionVersionActivity extends ListActivity { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.download_builds); - String installDate = OsmandSettings.getPrefs(this).getString(CONTRIBUTION_INSTALL_APP_DATE, null); + String installDate = OsmandSettings.getOsmandSettings(this).CONTRIBUTION_INSTALL_APP_DATE.get(); if(installDate != null){ try { currentInstalledDate = dateFormat.parse(installDate); @@ -138,8 +138,7 @@ public class ContributionVersionActivity extends ListActivity { MessageFormat.format(getString(R.string.build_installed), currentSelectedBuild.tag, dateFormat .format(currentSelectedBuild.date)), Toast.LENGTH_LONG).show(); } - OsmandSettings.getWriteableEditor(this).putString(CONTRIBUTION_INSTALL_APP_DATE, dateFormat.format(d)) - .commit(); + OsmandSettings.getOsmandSettings(this).CONTRIBUTION_INSTALL_APP_DATE.set(dateFormat.format(d)); } protected void executeThreadOperation(int operationId) throws Exception { diff --git a/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java b/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java index ac9a475e09..5e8b5df337 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java @@ -7,7 +7,6 @@ import java.util.TimeZone; import net.osmand.LogUtil; import net.osmand.SunriseSunset; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.DayNightMode; import org.apache.commons.logging.Log; @@ -44,8 +43,7 @@ public class DayNightHelper implements SensorEventListener { public DayNightHelper(OsmandApplication osmandApplication) { this.osmandApplication = osmandApplication; - setDayNightMode(OsmandSettings.getDayNightMode(OsmandSettings - .getPrefs(osmandApplication))); + setDayNightMode(osmandApplication.getSettings().DAYNIGHT_MODE.get()); } DayNightMode dayNightMode = DayNightMode.AUTO; diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 2ecd2851a4..61341cb2a3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -308,7 +308,7 @@ public class DownloadIndexActivity extends ListActivity { private List listAlreadyDownloadedWithAlternatives() { List files = new ArrayList(); - File externalStorageDirectory = OsmandSettings.getExternalStorageDirectory(getApplicationContext()); + File externalStorageDirectory = OsmandSettings.getOsmandSettings(getApplicationContext()).getExternalStorageDirectory(); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION)); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.APP_DIR),BINARY_MAP_INDEX_EXT,BINARY_MAP_INDEX_EXT_ZIP,BINARY_MAP_VERSION)); files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.VOICE_PATH),"",VOICE_INDEX_EXT_ZIP, VOICE_VERSION)); @@ -343,7 +343,7 @@ public class DownloadIndexActivity extends ListActivity { String toCheckPostfix = null; boolean unzipDir = false; - File externalStorageDirectory = OsmandSettings.getExternalStorageDirectory(getApplicationContext()); + File externalStorageDirectory = OsmandSettings.getOsmandSettings(getApplicationContext()).getExternalStorageDirectory(); if(fileName.endsWith(IndexConstants.POI_INDEX_EXT)){ parent = new File(externalStorageDirectory, ResourceManager.POI_PATH); toSavePostfix = POI_INDEX_EXT; diff --git a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java index 299cff81ac..19218fbcc0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java @@ -63,7 +63,7 @@ public class EditPOIFilterActivity extends ListActivity { public void onClick(View v) { Bundle extras = getIntent().getExtras(); boolean searchNearBy = true; - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(EditPOIFilterActivity.this)); + LatLon lastKnownMapLocation = OsmandSettings.getOsmandSettings(EditPOIFilterActivity.this).getLastKnownMapLocation(); double latitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLatitude() : 0; double longitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLongitude() : 0; final Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class); diff --git a/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java index 474fb5a9ac..6a4a447a40 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java @@ -140,7 +140,7 @@ public class EditingPOIActivity { Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(MessageFormat.format(this.view.getResources().getString(R.string.poi_remove_confirm_template), - OsmAndFormatter.getPoiStringWithoutType(a, OsmandSettings.usingEnglishNames(OsmandSettings.getPrefs(ctx))))); + OsmAndFormatter.getPoiStringWithoutType(a, OsmandSettings.getOsmandSettings(ctx).usingEnglishNames()))); final EditText comment = new EditText(ctx); comment.setText(R.string.poi_remove_title); builder.setView(comment); @@ -380,8 +380,8 @@ public class EditingPOIActivity { DefaultHttpClient httpclient = new DefaultHttpClient(params); if (doAuthenticate) { - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx)) + ":" //$NON-NLS-1$ - + OsmandSettings.getUserPassword(OsmandSettings.getPrefs(ctx))); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(OsmandSettings.getOsmandSettings(ctx).USER_NAME.get() + ":" //$NON-NLS-1$ + + OsmandSettings.getOsmandSettings(ctx).USER_PASSWORD.get()); httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials); } HttpRequestBase method = null; @@ -460,7 +460,7 @@ public class EditingPOIActivity { connection.setRequestMethod(requestMethod); StringBuilder responseBody = new StringBuilder(); if (doAuthenticate) { - String token = OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx)) + ":" + OsmandSettings.getUserPassword(OsmandSettings.getPrefs(ctx)); //$NON-NLS-1$ + String token = OsmandSettings.getOsmandSettings(ctx).USER_NAME.get() + ":" + OsmandSettings.getOsmandSettings(ctx).USER_PASSWORD.get(); //$NON-NLS-1$ connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } connection.setDoInput(true); @@ -645,7 +645,7 @@ public class EditingPOIActivity { ser.startTag(null, action); ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$ ser.attribute(null, "generator", Version.APP_NAME); //$NON-NLS-1$ - writeNode(n, info, ser, changeSetId, OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx))); + writeNode(n, info, ser, changeSetId, OsmandSettings.getOsmandSettings(ctx).USER_NAME.get()); ser.endTag(null, action); ser.endTag(null, "osmChange"); //$NON-NLS-1$ ser.endDocument(); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java index 6ec7864b30..20f8464756 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java @@ -99,7 +99,7 @@ public class FavouritesActivity extends ListActivity { list.addAll(helper.getFavoritePointsFromGPXFile()); } favouritesAdapter = new FavouritesAdapter(list); - final LatLon mapLocation = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); + final LatLon mapLocation = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); if(mapLocation != null){ favouritesAdapter.sort(new Comparator(){ @@ -122,8 +122,8 @@ public class FavouritesActivity extends ListActivity { public void onListItemClick(ListView parent, View v, int position, long id) { FavouritePoint point = favouritesAdapter.getItem(position); - OsmandSettings.setShowingFavorites(this, true); - OsmandSettings.setMapLocationToShow(this, point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ + OsmandSettings.getOsmandSettings(this).SHOW_FAVORITES.set( true); + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ Intent newIntent = new Intent(FavouritesActivity.this, MapActivity.class); startActivity(newIntent); } @@ -134,7 +134,7 @@ public class FavouritesActivity extends ListActivity { final FavouritePoint point = (FavouritePoint) favouritesAdapter.getItem(menuInfo.position); if (aItem.getItemId() == NAVIGATE_TO) { //OsmandSettings.setMapLocationToShow(this, point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ - OsmandSettings.setPointToNavigate(this, point.getLatitude(), point.getLongitude()); + OsmandSettings.getOsmandSettings(this).setPointToNavigate(point.getLatitude(), point.getLongitude()); Intent newIntent = new Intent(FavouritesActivity.this, MapActivity.class); startActivity(newIntent); } else if (aItem.getItemId() == EDIT_ITEM) { @@ -194,7 +194,7 @@ public class FavouritesActivity extends ListActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == EXPORT_ID){ - File appDir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR); + File appDir = OsmandSettings.getOsmandSettings(this).extendOsmandPath(ResourceManager.APP_DIR); if(favouritesAdapter.isEmpty()){ Toast.makeText(this, R.string.no_fav_to_save, Toast.LENGTH_LONG).show(); } else if(!appDir.exists()){ @@ -219,7 +219,7 @@ public class FavouritesActivity extends ListActivity { } } } else if(item.getItemId() == IMPORT_ID){ - File appDir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR); + File appDir = OsmandSettings.getOsmandSettings(this).extendOsmandPath(ResourceManager.APP_DIR); File f = new File(appDir, FILE_TO_SAVE); if(!f.exists()){ Toast.makeText(this, MessageFormat.format(getString(R.string.fav_file_to_load_not_found), f.getAbsolutePath()), Toast.LENGTH_LONG).show(); @@ -279,7 +279,7 @@ public class FavouritesActivity extends ListActivity { } else { icon.setImageResource(R.drawable.opened_poi); } - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(FavouritesActivity.this)); + LatLon lastKnownMapLocation = OsmandSettings.getOsmandSettings(FavouritesActivity.this).getLastKnownMapLocation(); int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist, FavouritesActivity.this)); diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index ca58eb29e3..8fea1ccf99 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -51,7 +51,7 @@ public class MainMenuActivity extends Activity { public void checkPreviousRunsForExceptions(boolean firstTime) { long size = getPreferences(MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0); - final File file = OsmandSettings.extendOsmandPath(getApplicationContext(), OsmandApplication.EXCEPTION_PATH); + final File file = OsmandSettings.getOsmandSettings(this).extendOsmandPath(OsmandApplication.EXCEPTION_PATH); if (file.exists() && file.length() > 0) { if (size != file.length() && !firstTime) { String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); @@ -125,7 +125,7 @@ public class MainMenuActivity extends Activity { String textVersion = Version.APP_VERSION + " " + Version.APP_DESCRIPTION; final TextView textVersionView = (TextView) findViewById(R.id.TextVersion); textVersionView.setText(textVersion); - SharedPreferences prefs = OsmandSettings.getPrefs(this); + SharedPreferences prefs = getApplicationContext().getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE); // only one commit should be with contribution version flag // prefs.edit().putBoolean(CONTRIBUTION_VERSION_FLAG, true).commit(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 65f4d0cfa1..960ec327cd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -157,10 +157,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso private boolean currentShowingAngle; private Dialog progressDlg = null; - private SharedPreferences settings; + private OsmandSettings settings; private boolean isMapLinkedToLocation(){ - return OsmandSettings.isMapSyncToGpsLocation(settings); + return settings.isMapSyncToGpsLocation(); } private Notification getNotification(){ @@ -178,7 +178,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - settings = OsmandSettings.getPrefs(this); + settings = OsmandSettings.getOsmandSettings(this); // for voice navigation setVolumeControlStream(AudioManager.STREAM_MUSIC); requestWindowFeature(Window.FEATURE_NO_TITLE); @@ -192,7 +192,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onDismiss(DialogInterface dialog) { OsmandApplication app = ((OsmandApplication)getApplication()); - if(OsmandSettings.isUsingMapVectorData(settings) && app.getResourceManager().getRenderer().isEmpty()){ + if(settings.isUsingMapVectorData() && app.getResourceManager().getRenderer().isEmpty()){ Toast.makeText(MapActivity.this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show(); } } @@ -272,7 +272,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso savingTrackHelper = new SavingTrackHelper(this); - LatLon pointToNavigate = OsmandSettings.getPointToNavigate(settings); + LatLon pointToNavigate = settings.getPointToNavigate(); // This situtation could be when navigation suddenly crashed and after restarting // it tries to continue the last route @@ -281,9 +281,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso routingHelper.setFinalAndCurrentLocation(pointToNavigate, null); } - if(OsmandSettings.isFollowingByRoute(settings)){ + if(settings.FOLLOW_TO_THE_ROUTE.get()){ if(pointToNavigate == null){ - OsmandSettings.setFollowingByRoute(this, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); } else if(!routingHelper.isRouteCalculated()){ Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.continue_follow_previous_route); @@ -297,7 +297,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { - OsmandSettings.setFollowingByRoute(MapActivity.this, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); routingHelper.setFinalLocation(null); mapView.refreshMap(); } @@ -308,8 +308,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso navigationLayer.setPointToNavigate(pointToNavigate); - SharedPreferences prefs = OsmandSettings.getPrefs(this); - if(prefs == null || !prefs.contains(OsmandSettings.LAST_KNOWN_MAP_LAT)){ + if(!settings.isLastKnownMapLocation()){ LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Location location = null; try { @@ -344,7 +343,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso mapView.getAnimatedDraggingThread().startZooming(mapView.getZoom(), mapView.getZoom() + 1); showAndHideMapPosition(); // user can preview map manually switch off auto zoom while user don't press back to location - if(OsmandSettings.isAutoZoomEnabled(settings)){ + if(settings.AUTO_ZOOM_MAP.get()){ locationChanged(mapView.getLatitude(), mapView.getLongitude(), null); } } @@ -357,7 +356,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso mapView.getAnimatedDraggingThread().startZooming(mapView.getZoom(), mapView.getZoom() - 1); showAndHideMapPosition(); // user can preview map manually switch off auto zoom while user don't press back to location - if(OsmandSettings.isAutoZoomEnabled(settings)){ + if(settings.AUTO_ZOOM_MAP.get()){ locationChanged(mapView.getLatitude(), mapView.getLongitude(), null); } } @@ -410,7 +409,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } @Override public boolean onTrackballEvent(MotionEvent event) { - if(event.getAction() == MotionEvent.ACTION_MOVE && OsmandSettings.isUsingTrackBall(settings)){ + if(event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()){ float x = event.getX(); float y = event.getY(); LatLon l = mapView.getLatLonFromScreenPoint(mapView.getCenterPointX() + x * 15, mapView.getCenterPointY() + y * 15); @@ -481,7 +480,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso protected void backToLocationImpl() { backToLocation.setVisibility(View.INVISIBLE); if(!isMapLinkedToLocation()){ - OsmandSettings.setSyncMapToGpsLocation(MapActivity.this, true); + settings.setSyncMapToGpsLocation(true); if(locationLayer.getLastKnownLocation() != null){ Location lastKnownLocation = locationLayer.getLastKnownLocation(); AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread(); @@ -529,7 +528,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){ Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$ } - if(location != null && OsmandSettings.isSavingTrackToGpx(this)){ + if(location != null && settings.SAVE_TRACK_TO_GPX.get()){ savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), location.getTime(), settings); } @@ -542,7 +541,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } if (location != null) { if (isMapLinkedToLocation()) { - if(OsmandSettings.isAutoZoomEnabled(settings) && location.hasSpeed()){ + if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){ int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom()); if(mapView.getZoom() != z && !mapView.mapIsAnimating()){ long now = System.currentTimeMillis(); @@ -587,14 +586,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso public void navigateToPoint(LatLon point){ if(point != null){ - OsmandSettings.setPointToNavigate(this, point.getLatitude(), point.getLongitude()); + settings.setPointToNavigate(point.getLatitude(), point.getLongitude()); } else { - OsmandSettings.clearPointToNavigate(this); + settings.clearPointToNavigate(); } routingHelper.setFinalAndCurrentLocation(point, null, routingHelper.getCurrentGPXRoute()); if(point == null){ routingHelper.setFollowingMode(false); - OsmandSettings.setFollowingByRoute(MapActivity.this, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); } navigationLayer.setPointToNavigate(point); } @@ -727,75 +726,75 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso ((OsmandApplication)getApplication()).getDaynightHelper().onMapPause(); - OsmandSettings.setLastKnownMapLocation(this, (float) mapView.getLatitude(), (float) mapView.getLongitude()); + settings.setLastKnownMapLocation((float) mapView.getLatitude(), (float) mapView.getLongitude()); AnimateDraggingMapThread animatedThread = mapView.getAnimatedDraggingThread(); if(animatedThread.isAnimating() && animatedThread.getTargetZoom() != 0){ - OsmandSettings.setMapLocationToShow(this, animatedThread.getTargetLatitude(), animatedThread.getTargetLongitude(), + settings.setMapLocationToShow(animatedThread.getTargetLatitude(), animatedThread.getTargetLongitude(), animatedThread.getTargetZoom()); } - OsmandSettings.setLastKnownMapZoom(this, mapView.getZoom()); + settings.setLastKnownMapZoom(mapView.getZoom()); if (wakeLock != null) { wakeLock.release(); wakeLock = null; } - OsmandSettings.setMapActivityEnabled(this, false); + settings.MAP_ACTIVITY_ENABLED.set(false); ((OsmandApplication)getApplication()).getResourceManager().interruptRendering(); ((OsmandApplication)getApplication()).getResourceManager().setBusyIndicator(null); } private void updateApplicationModeSettings(){ - currentMapRotation = OsmandSettings.getRotateMap(settings); - currentShowingAngle = OsmandSettings.isShowingViewAngle(settings); + currentMapRotation = settings.ROTATE_MAP.get(); + currentShowingAngle = settings.SHOW_VIEW_ANGLE.get(); if(currentMapRotation == OsmandSettings.ROTATE_MAP_NONE){ mapView.setRotate(0); } if(!currentShowingAngle){ locationLayer.setHeading(null); } - locationLayer.setAppMode(OsmandSettings.getApplicationMode(settings)); - routingHelper.setAppMode(OsmandSettings.getApplicationMode(settings)); - mapView.setMapPosition(OsmandSettings.getPositionOnMap(settings)); + locationLayer.setAppMode(settings.getApplicationMode()); + routingHelper.setAppMode(settings.getApplicationMode()); + mapView.setMapPosition(settings.POSITION_ON_MAP.get()); registerUnregisterSensor(getLastKnownLocation()); updateLayers(); } private void updateLayers(){ - if(mapView.getLayers().contains(transportStopsLayer) != OsmandSettings.isShowingTransportOverMap(settings)){ - if(OsmandSettings.isShowingTransportOverMap(settings)){ + if(mapView.getLayers().contains(transportStopsLayer) != settings.SHOW_TRANSPORT_OVER_MAP.get()){ + if(settings.SHOW_TRANSPORT_OVER_MAP.get()){ mapView.addLayer(transportStopsLayer, 5); } else { mapView.removeLayer(transportStopsLayer); } } - if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(settings)){ - if(OsmandSettings.isShowingOsmBugs(settings)){ + if(mapView.getLayers().contains(osmBugsLayer) != settings.SHOW_OSM_BUGS.get()){ + if(settings.SHOW_OSM_BUGS.get()){ mapView.addLayer(osmBugsLayer, 2); } else { mapView.removeLayer(osmBugsLayer); } } - if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(settings)){ - if(OsmandSettings.isShowingPoiOverMap(settings)){ + if(mapView.getLayers().contains(poiMapLayer) != settings.SHOW_POI_OVER_MAP.get()){ + if(settings.SHOW_POI_OVER_MAP.get()){ mapView.addLayer(poiMapLayer, 3); } else { mapView.removeLayer(poiMapLayer); } } - if(mapView.getLayers().contains(favoritesLayer) != OsmandSettings.isShowingFavorites(settings)){ - if(OsmandSettings.isShowingFavorites(settings)){ + if(mapView.getLayers().contains(favoritesLayer) != settings.SHOW_FAVORITES.get()){ + if(settings.SHOW_FAVORITES.get()){ mapView.addLayer(favoritesLayer, 4); } else { mapView.removeLayer(favoritesLayer); } } - trafficLayer.setVisible(OsmandSettings.isShowingYandexTraffic(settings)); + trafficLayer.setVisible(settings.SHOW_YANDEX_TRAFFIC.get()); } private void updateMapSource(){ - boolean vectorData = OsmandSettings.isUsingMapVectorData(settings); + boolean vectorData = settings.isUsingMapVectorData(); OsmandApplication app = ((OsmandApplication)getApplication()); ResourceManager rm = app.getResourceManager(); if(vectorData && !app.isApplicationInitializing()){ @@ -804,7 +803,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso vectorData = false; } } - ITileSource newSource = OsmandSettings.getMapTileSource(settings); + ITileSource newSource = settings.getMapTileSource(); if(mapView.getMap() instanceof SQLiteTileSource){ ((SQLiteTileSource)mapView.getMap()).closeDB(); } @@ -820,14 +819,14 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override protected void onResume() { super.onResume(); - if(OsmandSettings.getMapOrientation(settings) != getRequestedOrientation()){ - setRequestedOrientation(OsmandSettings.getMapOrientation(settings)); + if(settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()){ + setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get()); // can't return from this method we are not sure if activity will be recreated or not } currentScreenOrientation = getWindow().getWindowManager().getDefaultDisplay().getOrientation(); - boolean showTiles = !OsmandSettings.isUsingMapVectorData(settings); - ITileSource source = showTiles ? OsmandSettings.getMapTileSource(settings) : null; + boolean showTiles = !settings.isUsingMapVectorData(); + ITileSource source = showTiles ? settings.getMapTileSource() : null; if (showTiles != !rendererLayer.isVisible() || !Algoritms.objectEquals(mapView.getMap(), source)) { updateMapSource(); } @@ -835,7 +834,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso updateApplicationModeSettings(); - poiMapLayer.setFilter(OsmandSettings.getPoiFilterForMap(this, (OsmandApplication) getApplication())); + poiMapLayer.setFilter(settings.getPoiFilterForMap((OsmandApplication) getApplication())); backToLocation.setVisibility(View.INVISIBLE); routingHelper.setUiActivity(this); @@ -862,10 +861,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso providerSupportsBearing = prov == null ? false : prov.supportsBearing() && !isRunningOnEmulator(); providerSupportsSpeed = prov == null ? false : prov.supportsSpeed() && !isRunningOnEmulator(); - if(settings != null && settings.contains(OsmandSettings.LAST_KNOWN_MAP_LAT)){ - LatLon l = OsmandSettings.getLastKnownMapLocation(settings); + if(settings != null && settings.isLastKnownMapLocation()){ + LatLon l = settings.getLastKnownMapLocation(); mapView.setLatLon(l.getLatitude(), l.getLongitude()); - mapView.setZoom(OsmandSettings.getLastKnownMapZoom(settings)); + mapView.setZoom(settings.getLastKnownMapZoom()); } @@ -875,15 +874,15 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso wakeLock.acquire(); } - OsmandSettings.setMapActivityEnabled(this, true); + settings.MAP_ACTIVITY_ENABLED.set(true); checkExternalStorage(); showAndHideMapPosition(); LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude()); - LatLon latLon = OsmandSettings.getAndClearMapLocationToShow(settings); + LatLon latLon = settings.getAndClearMapLocationToShow(); if (latLon != null && !latLon.equals(cur)) { mapView.getAnimatedDraggingThread().startMoving(cur.getLatitude(), cur.getLongitude(), latLon.getLatitude(), - latLon.getLongitude(), mapView.getZoom(), OsmandSettings.getMapZoomToShow(settings), mapView.getSourceTileSize(), + latLon.getLongitude(), mapView.getZoom(), settings.getMapZoomToShow(), mapView.getSourceTileSize(), mapView.getRotate(), true); } @@ -946,7 +945,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso // when user start dragging if(locationLayer.getLastKnownLocation() != null){ if(isMapLinkedToLocation()){ - OsmandSettings.setSyncMapToGpsLocation(MapActivity.this, false); + settings.setSyncMapToGpsLocation(false); } if (backToLocation.getVisibility() != View.VISIBLE) { runOnUiThread(new Runnable() { @@ -998,7 +997,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso MenuItem navigateToPointMenu = menu.findItem(R.id.map_navigate_to_point); if (navigateToPointMenu != null) { navigateToPointMenu.setTitle(routingHelper.isRouteCalculated() ? R.string.stop_routing : R.string.stop_navigation); - if (OsmandSettings.getPointToNavigate(settings) != null) { + if (settings.getPointToNavigate() != null) { navigateToPointMenu.setVisible(true); } else { navigateToPointMenu.setVisible(false); @@ -1070,7 +1069,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if(navigationLayer.getPointToNavigate() != null){ if(routingHelper.isRouteCalculated()){ routingHelper.setFinalAndCurrentLocation(null, null); - OsmandSettings.setFollowingByRoute(MapActivity.this, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); routingHelper.setFollowingMode(false); } else { navigateToPoint(null); @@ -1095,7 +1094,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso return ApplicationMode.values()[i]; } } - return OsmandSettings.getApplicationMode(settings); + return settings.getApplicationMode(); } @@ -1111,7 +1110,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton); buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton); buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton); - ApplicationMode appMode = OsmandSettings.getApplicationMode(settings); + ApplicationMode appMode = settings.getApplicationMode(); for(int i=0; i< buttons.length; i++){ if(buttons[i] != null){ final int ind = i; @@ -1157,7 +1156,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso map.setLatitude(lat); map.setLongitude(lon); routingHelper.setAppMode(mode); - OsmandSettings.setFollowingByRoute(MapActivity.this, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); routingHelper.setFollowingMode(false); routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), map); } @@ -1168,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 = ApplicationMode.setAppMode(mode, (OsmandApplication) getApplication()); + boolean changed = settings.setAppMode(mode, (OsmandApplication) getApplication()); if (changed) { updateApplicationModeSettings(); mapView.refreshMap(); @@ -1181,7 +1180,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso location.setLongitude(lon); } routingHelper.setAppMode(mode); - OsmandSettings.setFollowingByRoute(MapActivity.this, true); + settings.FOLLOW_TO_THE_ROUTE.set(true); routingHelper.setFollowingMode(true); routingHelper.setFinalAndCurrentLocation(navigationLayer.getPointToNavigate(), location); @@ -1230,14 +1229,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso try { double lt = Double.parseDouble(lat); double ln = Double.parseDouble(lon); - Editor edit = OsmandSettings.getWriteableEditor(this); - edit.putFloat(OsmandSettings.LAST_KNOWN_MAP_LAT, (float) lt); - edit.putFloat(OsmandSettings.LAST_KNOWN_MAP_LON, (float) ln); + settings.setLastKnownMapLocation((float) lt, (float) ln); String zoom = data.getQueryParameter("z"); if(zoom != null){ - edit.putInt(OsmandSettings.LAST_KNOWN_MAP_ZOOM, Integer.parseInt(zoom)); + settings.setLastKnownMapZoom(Integer.parseInt(zoom)); } - edit.commit(); } catch (NumberFormatException e) { } } @@ -1267,10 +1263,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso final boolean[] selected = new boolean[layersList.size()]; Arrays.fill(selected, true); - selected[1] = OsmandSettings.isShowingPoiOverMap(settings); - selected[2] = OsmandSettings.isShowingTransportOverMap(settings); - selected[3] = OsmandSettings.isShowingOsmBugs(settings); - selected[4] = OsmandSettings.isShowingFavorites(settings); + selected[1] = settings.SHOW_POI_OVER_MAP.get(); + selected[2] = settings.SHOW_TRANSPORT_OVER_MAP.get(); + selected[3] = settings.SHOW_OSM_BUGS.get(); + selected[4] = settings.SHOW_FAVORITES.get(); selected[5] = gpxLayer.isVisible(); selected[trafficInd] = trafficLayer.isVisible(); if(routeInfoInd != -1){ @@ -1292,13 +1288,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if(isChecked){ selectPOIFilterLayer(); } - OsmandSettings.setShowPoiOverMap(MapActivity.this, isChecked); + settings.SHOW_POI_OVER_MAP.set(isChecked); } else if(item == 2){ - OsmandSettings.setShowTransortOverMap(MapActivity.this, isChecked); + settings.SHOW_TRANSPORT_OVER_MAP.set(isChecked); } else if(item == 3){ - OsmandSettings.setShowingOsmBugs(MapActivity.this, isChecked); + settings.SHOW_OSM_BUGS.set(isChecked); } else if(item == 4){ - OsmandSettings.setShowingFavorites(MapActivity.this, isChecked); + settings.SHOW_FAVORITES.set(isChecked); } else if(item == 5){ if(gpxLayer.isVisible()){ gpxLayer.clearCurrentGPX(); @@ -1312,7 +1308,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } else if(item == transportRouteInfoInd){ transportInfoLayer.setVisible(isChecked); } else if(item == trafficInd){ - OsmandSettings.setShowingYandexTraffic(MapActivity.this, isChecked); + settings.SHOW_YANDEX_TRAFFIC.set(isChecked); } updateLayers(); mapView.refreshMap(); @@ -1323,7 +1319,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso private void useGPXFileLayer(final boolean useRouting, final LatLon endForRouting) { final List list = new ArrayList(); - final File dir = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.APP_DIR + SavingTrackHelper.TRACKS_PATH); + final File dir = settings.extendOsmandPath(ResourceManager.APP_DIR + SavingTrackHelper.TRACKS_PATH); if (dir != null && dir.canRead()) { File[] files = dir.listFiles(); if (files != null) { @@ -1383,7 +1379,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } }); } else { - OsmandSettings.setShowingFavorites(MapActivity.this, true); + settings.SHOW_FAVORITES.set(true); List pts = new ArrayList(); for(WptPt p : res.wayPoints){ FavouritePoint pt = new FavouritePoint(); @@ -1436,12 +1432,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso LatLon endPoint = endForRouting; if(/*endForRouting == null && */!l.isEmpty()){ LatLon point = new LatLon(l.get(l.size() - 1).getLatitude(), l.get(l.size() - 1).getLongitude()); - OsmandSettings.setPointToNavigate(MapActivity.this, point.getLatitude(), point.getLongitude()); + settings.setPointToNavigate(point.getLatitude(), point.getLongitude()); endPoint = point; navigationLayer.setPointToNavigate(point); } if(endForRouting != null){ - OsmandSettings.setFollowingByRoute(MapActivity.this, true); + settings.FOLLOW_TO_THE_ROUTE.set(true); routingHelper.setFollowingMode(true); routingHelper.setFinalAndCurrentLocation(endPoint, startForRouting, l); ((OsmandApplication)getApplication()).showDialogInitializingCommandPlayer(MapActivity.this); @@ -1486,7 +1482,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso newIntent.putExtra(EditPOIFilterActivity.SEARCH_LON, mapView.getLongitude()); startActivity(newIntent); } else { - OsmandSettings.setPoiFilterForMap(MapActivity.this, filterId); + settings.setPoiFilterForMap(filterId); poiMapLayer.setFilter(poiFilters.getFilterById(filterId)); mapView.refreshMap(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java index 90bd2fed71..7f150c818f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java @@ -49,7 +49,7 @@ public class NavigatePointActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - LatLon loc = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); + LatLon loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); setContentView(R.layout.navigate_point); setTitle(R.string.map_specify_point); initUI(loc.getLatitude(), loc.getLongitude()); @@ -129,7 +129,7 @@ public class NavigatePointActivity extends Activity { double lon = convert(((TextView) findViewById(R.id.LongitudeEdit)).getText().toString()); if(navigate){ - OsmandSettings.setPointToNavigate(this, lat, lon); + OsmandSettings.getOsmandSettings(this).setPointToNavigate(lat, lon); } else { // in case when it is dialog if(activity != null) { @@ -137,7 +137,7 @@ public class NavigatePointActivity extends Activity { activity.getMapView().getAnimatedDraggingThread().startMoving(v.getLatitude(), v.getLongitude(), lat, lon, v.getZoom(), v.getZoom(), v.getSourceTileSize(), v.getRotate(), true); } else { - OsmandSettings.setMapLocationToShow(this, lat, lon, MessageFormat.format(getString(R.string.search_history_navigate_to), lat, lon)); + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(lat, lon, MessageFormat.format(getString(R.string.search_history_navigate_to), lat, lon)); } } close(); diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java index 669d9e510d..2a1bd86a65 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java @@ -26,7 +26,6 @@ import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Handler; import android.text.format.DateFormat; @@ -41,6 +40,7 @@ public class OsmandApplication extends Application { RoutingHelper routingHelper = null; FavouritesDbHelper favorites = null; CommandPlayer player = null; + OsmandSettings osmandSettings; // start variables @@ -52,11 +52,12 @@ public class OsmandApplication extends Application { private NavigationService navigationService; private boolean applicationInitializing = false; private Locale prefferedLocale = null; - + public void onCreate(){ super.onCreate(); - routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(OsmandApplication.this)), OsmandApplication.this, player); + osmandSettings = OsmandSettings.getOsmandSettings(this); + routingHelper = new RoutingHelper(osmandSettings, OsmandApplication.this, player); manager = new ResourceManager(this); daynightHelper = new DayNightHelper(this); uiHandler = new Handler(); @@ -64,6 +65,10 @@ public class OsmandApplication extends Application { startApplication(); } + public OsmandSettings getSettings() { + return osmandSettings; + } + public PoiFiltersHelper getPoiFilters() { if(poiFilters == null){ poiFilters = new PoiFiltersHelper(this); @@ -103,9 +108,8 @@ public class OsmandApplication extends Application { } public void checkPrefferedLocale() { - SharedPreferences settings = OsmandSettings.getPrefs(this); Configuration config = getBaseContext().getResources().getConfiguration(); - String lang = OsmandSettings.getPreferredLocale(settings); + String lang = osmandSettings.PREFERRED_LOCALE.get(); if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) { prefferedLocale = new Locale(lang); Locale.setDefault(prefferedLocale); @@ -144,7 +148,7 @@ public class OsmandApplication extends Application { public void showDialogInitializingCommandPlayer(final Context uiContext){ - String voiceProvider = OsmandSettings.getVoiceProvider(OsmandSettings.getPrefs(this)); + String voiceProvider = osmandSettings.VOICE_PROVIDER.get(); if(voiceProvider == null){ Builder builder = new AlertDialog.Builder(uiContext); builder.setCancelable(true); @@ -191,7 +195,7 @@ public class OsmandApplication extends Application { player = new CommandPlayer(OsmandApplication.this); routingHelper.getVoiceRouter().setPlayer(player); } - return player.init(OsmandSettings.getVoiceProvider(OsmandSettings.getPrefs(this))); + return player.init(osmandSettings.VOICE_PROVIDER.get()); } public NavigationService getNavigationService() { @@ -288,7 +292,7 @@ public class OsmandApplication extends Application { @Override public void uncaughtException(final Thread thread, final Throwable ex) { - File file = OsmandSettings.extendOsmandPath(getApplicationContext(), EXCEPTION_PATH); + File file = osmandSettings.extendOsmandPath(EXCEPTION_PATH); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(out); diff --git a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java index 4f0af7a830..79f230b328 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java @@ -60,13 +60,16 @@ public class RoutingHelper { private int evalWaitInterval = 3000; private ApplicationMode mode; + private OsmandSettings settings; private RouteProvider provider = new RouteProvider(); private VoiceRouter voiceRouter; + - public RoutingHelper(ApplicationMode mode, Context context, CommandPlayer player){ - this.mode = mode; + + public RoutingHelper(OsmandSettings settings, Context context, CommandPlayer player){ + this.settings = settings; this.context = context; voiceRouter = new VoiceRouter(this, player); } @@ -138,7 +141,7 @@ public class RoutingHelper { if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){ if(lastFixedLocation != null && lastFixedLocation.distanceTo(lastPoint) < 60){ showMessage(context.getString(R.string.arrived_at_destination)); - OsmandSettings.setFollowingByRoute(context, false); + settings.FOLLOW_TO_THE_ROUTE.set(false); voiceRouter.arrivedDestinationPoint(); updateCurrentRoute(routeNodes.size() - 1); // clear final location to prevent all time showing message @@ -425,8 +428,8 @@ public class RoutingHelper { } // temporary check while osmand offline router is not stable - RouteService serviceToUse= OsmandSettings.getRouterService(OsmandSettings.getPrefs(context)); - if (serviceToUse == RouteService.OSMAND && !OsmandSettings.isOsmandRoutingServiceUsed(context)) { + RouteService serviceToUse= settings.ROUTER_SERVICE.get(); + if (serviceToUse == RouteService.OSMAND && !settings.USE_OSMAND_ROUTING_SERVICE_ALWAYS.get()) { double distance = MapUtils.getDistance(end, start.getLatitude(), start.getLongitude()); if (distance > DISTANCE_TO_USE_OSMAND_ROUTER) { showMessage(context.getString(R.string.osmand_routing_experimental)); @@ -438,7 +441,7 @@ public class RoutingHelper { if(currentRunningJob == null){ // do not evaluate very often if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) { - final boolean fastRouteMode = OsmandSettings.isFastRouteMode(context); + final boolean fastRouteMode = settings.FAST_ROUTE_MODE.get(); synchronized (this) { currentRunningJob = new Thread(new Runnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index e57cffc522..3acb0b17d7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -19,7 +19,6 @@ import net.osmand.plus.ResourceManager; import org.apache.commons.logging.Log; import android.content.Context; -import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -115,7 +114,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { public List saveDataToGpx(){ SQLiteDatabase db = getReadableDatabase(); List warnings = new ArrayList(); - File dir = OsmandSettings.getExternalStorageDirectory(ctx); + File dir = OsmandSettings.getOsmandSettings(ctx).getExternalStorageDirectory(); if(db != null && dir.canWrite()){ dir = new File(dir, ResourceManager.APP_DIR + TRACKS_PATH); dir.mkdirs(); @@ -228,8 +227,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { query.close(); } - public void insertData(double lat, double lon, double alt, double speed, long time, SharedPreferences settings){ - if (time - lastTimeUpdated > OsmandSettings.getSavingTrackInterval(settings)*1000) { + public void insertData(double lat, double lon, double alt, double speed, long time, OsmandSettings settings){ + if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get()*1000) { SQLiteDatabase db = getWritableDatabase(); if (db != null) { db.execSQL(updateScript, new Object[] { lat, lon, alt, speed, time }); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 37c5ce0637..cdf3565c29 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -9,6 +9,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; @@ -21,6 +22,7 @@ import net.osmand.plus.ResourceManager; import net.osmand.plus.SQLiteTileSource; 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; @@ -53,32 +55,6 @@ import android.widget.Toast; public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener { private final static String VECTOR_MAP = "#VECTOR_MAP"; //$NON-NLS-1$ - private class BooleanPreference { - private final boolean defValue; - private final String id; - private CheckBoxPreference pref; - - public BooleanPreference(String id, boolean defValue){ - this.id = id; - this.defValue = defValue; - } - - public String getId() { - return id; - } - - public boolean getDefValue() { - return defValue; - } - - public void setPref(CheckBoxPreference pref) { - this.pref = pref; - } - public CheckBoxPreference getPref() { - return pref; - } - } - private EditTextPreference userPassword; private EditTextPreference userName; private EditTextPreference applicationDir; @@ -88,57 +64,81 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private Preference downloadIndexes; private ListPreference applicationMode; - private ListPreference daynightMode; private ListPreference saveTrackInterval; - private ListPreference rotateMap; private ListPreference tileSourcePreference; - private ListPreference positionOnMap; - private ListPreference routerPreference; - private ListPreference maxLevelToDownload; - private ListPreference mapScreenOrientation; - private ListPreference voicePreference; - private ListPreference metricPreference; - private ListPreference preferredLocale; private ListPreference rendererPreference; private ListPreference routeServiceInterval; private ListPreference routeServiceWaitInterval; - private ListPreference routeServiceProvider; private CheckBoxPreference routeServiceEnabled; - private CheckBoxPreference useInternetToDownload; private ProgressDialog progressDlg; - private BooleanPreference[] booleanPreferences = new BooleanPreference[]{ - new BooleanPreference(OsmandSettings.SHOW_VIEW_ANGLE, OsmandSettings.SHOW_VIEW_ANGLE_DEF), - new BooleanPreference(OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS, OsmandSettings.USE_TRACKBALL_FOR_MOVEMENTS_DEF), - new BooleanPreference(OsmandSettings.USE_HIGH_RES_MAPS, OsmandSettings.USE_HIGH_RES_MAPS_DEF), - new BooleanPreference(OsmandSettings.USE_ENGLISH_NAMES, OsmandSettings.USE_ENGLISH_NAMES_DEF), - new BooleanPreference(OsmandSettings.AUTO_ZOOM_MAP, OsmandSettings.AUTO_ZOOM_MAP_DEF), - new BooleanPreference(OsmandSettings.SAVE_TRACK_TO_GPX, OsmandSettings.SAVE_TRACK_TO_GPX_DEF), - new BooleanPreference(OsmandSettings.DEBUG_RENDERING_INFO, OsmandSettings.DEBUG_RENDERING_INFO_DEF), - new BooleanPreference(OsmandSettings.USE_STEP_BY_STEP_RENDERING, OsmandSettings.USE_STEP_BY_STEP_RENDERING_DEF), - new BooleanPreference(OsmandSettings.FAST_ROUTE_MODE, OsmandSettings.FAST_ROUTE_MODE_DEF), - new BooleanPreference(OsmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS, OsmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS_DEF), - }; private BroadcastReceiver broadcastReceiver; + private OsmandSettings osmandSettings; + + private Map screenPreferences = new LinkedHashMap(); + private Map> booleanPreferences = new LinkedHashMap>(); + private Map> listPreferences = new LinkedHashMap>(); + private Map> listPrefValues = new LinkedHashMap>(); + private void registerBooleanPreference(OsmandPreference b, PreferenceScreen screen){ + CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId()); + p.setOnPreferenceChangeListener(this); + screenPreferences.put(b.getId(), p); + booleanPreferences.put(b.getId(), b); + } + + private void registerListPreference(OsmandPreference b, PreferenceScreen screen, String[] names, T[] values){ + ListPreference p = (ListPreference) screen.findPreference(b.getId()); + p.setOnPreferenceChangeListener(this); + LinkedHashMap vals = new LinkedHashMap(); + screenPreferences.put(b.getId(), p); + listPreferences.put(b.getId(), b); + listPrefValues.put(b.getId(), vals); + assert names.length == values.length; + for(int i=0; i getVoiceFiles(){ + // read available voice data + File extStorage = osmandSettings.extendOsmandPath(ResourceManager.VOICE_PATH); + Set setFiles = new LinkedHashSet(); + if (extStorage.exists()) { + for (File f : extStorage.listFiles()) { + if (f.isDirectory()) { + setFiles.add(f.getName()); + } + } + } + return setFiles; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings_pref); + String[] entries; + String[] entrieValues; PreferenceScreen screen = getPreferenceScreen(); + osmandSettings = OsmandSettings.getOsmandSettings(this); - for(BooleanPreference b : booleanPreferences){ - CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId()); - p.setOnPreferenceChangeListener(this); - b.setPref(p); - } - - useInternetToDownload =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES); - useInternetToDownload.setOnPreferenceChangeListener(this); + registerBooleanPreference(osmandSettings.SHOW_VIEW_ANGLE,screen); + registerBooleanPreference(osmandSettings.USE_TRACKBALL_FOR_MOVEMENTS,screen); + registerBooleanPreference(osmandSettings.USE_HIGH_RES_MAPS,screen); + registerBooleanPreference(osmandSettings.USE_ENGLISH_NAMES,screen); + registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP,screen); + registerBooleanPreference(osmandSettings.SAVE_TRACK_TO_GPX,screen); + registerBooleanPreference(osmandSettings.DEBUG_RENDERING_INFO,screen); + registerBooleanPreference(osmandSettings.USE_STEP_BY_STEP_RENDERING,screen); + registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE,screen); + 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); @@ -146,49 +146,102 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference 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); - userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME); + userName = (EditTextPreference) screen.findPreference(osmandSettings.USER_NAME.getId()); userName.setOnPreferenceChangeListener(this); - userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD); + userPassword = (EditTextPreference) screen.findPreference(osmandSettings.USER_PASSWORD.getId()); userPassword.setOnPreferenceChangeListener(this); applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR); applicationDir.setOnPreferenceChangeListener(this); + // List preferences + registerListPreference(osmandSettings.ROTATE_MAP, screen, + new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}, + new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); + + registerListPreference(osmandSettings.MAP_SCREEN_ORIENTATION, screen, + new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}, + new Integer[] {ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED}); + + registerListPreference(osmandSettings.POSITION_ON_MAP, screen, + new String[] {getString(R.string.position_on_map_center), getString(R.string.position_on_map_bottom)}, + new Integer[] {OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT}); + + entries = new String[DayNightMode.values().length]; + for(int i=0; i voiceFiles = getVoiceFiles(); + entries = new String[voiceFiles.size() + 1]; + entrieValues = new String[voiceFiles.size() + 1]; + int k = 0; + entries[k++] = getString(R.string.voice_not_use); + for (String s : voiceFiles) { + entries[k] = s; + entrieValues[k] = s; + k++; + } + registerListPreference(osmandSettings.VOICE_PROVIDER, screen, entries, entries); + + int startZoom = 12; + int endZoom = 19; + entries = new String[endZoom - startZoom + 1]; + Integer[] intValues = new Integer[endZoom - startZoom + 1]; + for (int i = startZoom; i <= endZoom; i++) { + entries[i - startZoom] = i + ""; //$NON-NLS-1$ + intValues[i - startZoom] = i ; + } + registerListPreference(osmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, screen, entries, intValues); + + entries = new String[RouteService.values().length]; + for(int i=0; i b : booleanPreferences.values()){ + CheckBoxPreference pref = (CheckBoxPreference) screenPreferences.get(b.getId()); + pref.setChecked(b.get()); } + + + for(OsmandPreference p : listPreferences.values()){ + ListPreference listPref = (ListPreference) screenPreferences.get(p.getId()); + Map prefValues = listPrefValues.get(p.getId()); + String[] entryValues = new String[prefValues.size()]; + String[] entries = new String[prefValues.size()]; + int i = 0; + for(Entry e : prefValues.entrySet()){ + entries[i] = e.getKey(); + entryValues[i] = e.getValue() + ""; // case of null + i++; + } + listPref.setEntries(entries); + listPref.setEntryValues(entryValues); + listPref.setValue(p.get() + ""); + } + + userName.setText(OsmandSettings.getUserName(prefs)); userPassword.setText(OsmandSettings.getUserPassword(prefs)); applicationDir.setText(OsmandSettings.getExternalStorageDirectory(prefs).getAbsolutePath()); - useInternetToDownload.setChecked(OsmandSettings.isUsingInternetToDownloadTiles(prefs)); Resources resources = this.getResources(); - String[] e = new String[] {resources.getString(R.string.position_on_map_center), - resources.getString(R.string.position_on_map_bottom)}; - positionOnMap.setEntryValues(e); - positionOnMap.setEntries(e); - positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(prefs)); fillTime(saveTrackInterval, new int[]{1, 2, 3, 5, 15, 20, 30}, new int[]{1, 2, 3, 5}, OsmandSettings.getSavingTrackInterval(prefs)); //$NON-NLS-1$ @@ -261,27 +327,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference fillTime(routeServiceWaitInterval, new int[]{15, 30, 45, 60, 90}, new int[]{2, 3, 5, 10}, OsmandSettings.getServiceOffWaitInterval(prefs)/1000); - fill(rotateMap, // - new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}, // - new String[]{OsmandSettings.ROTATE_MAP_NONE+"", OsmandSettings.ROTATE_MAP_BEARING+"", OsmandSettings.ROTATE_MAP_COMPASS+""}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - OsmandSettings.getRotateMap(prefs)+""); //$NON-NLS-1$ - fill(routeServiceProvider,// - new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)}, // - new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER}, // - OsmandSettings.getServiceOffProvider(prefs)); routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null); - fill(mapScreenOrientation, // - new String[] { - resources.getString(R.string.map_orientation_portrait), - resources.getString(R.string.map_orientation_landscape), - resources.getString(R.string.map_orientation_default), }, // - new String[] { - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + "", //$NON-NLS-1$ - ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + "", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + "" }, //$NON-NLS-1$ //$NON-NLS-2$ - OsmandSettings.getMapOrientation(prefs) + ""); //$NON-NLS-1$ + ApplicationMode[] presets = ApplicationMode.values(); String[] names = new String[presets.length]; @@ -292,65 +342,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } fill(applicationMode, names, values, OsmandSettings.getApplicationMode(prefs).name()); - DayNightMode[] dnpresets = DayNightMode.possibleValues(this); - names = new String[dnpresets.length]; - values = new String[dnpresets.length]; - for(int i=0; i< dnpresets.length; i++){ - names[i] = dnpresets[i].toHumanString(this); - values[i] = dnpresets[i].name(); - } - fill(daynightMode, names, values, OsmandSettings.getDayNightMode(prefs).name()); - String[] entries = new String[RouteService.values().length]; - String entry = OsmandSettings.getRouterService(prefs).getName(); - for (int i = 0; i < RouteService.values().length; i++) { - entries[i] = RouteService.values()[i].getName(); - } - fill(routerPreference, entries, entries, entry); - names = new String[MetricsConstants.values().length]; - values = new String[MetricsConstants.values().length]; - entry = OsmandSettings.getDefaultMetricConstants(this).name(); - for (int i = 0; i < MetricsConstants.values().length; i++) { - values[i] = MetricsConstants.values()[i].name(); - names[i] = MetricsConstants.values()[i].toHumanString(this); - } - fill(metricPreference, names, values, entry); - - String[] locales = //getResources().getAssets().getLocales(); - new String [] { "en", "cs", "de", "es", "fr", "hu", "it", "pt", "ru", "sk"}; - values = new String[locales.length + 1]; - names = new String[locales.length + 1] ; - values[0] = OsmandSettings.PREFERRED_LOCALE_DEF; - names[0] = getString(R.string.system_locale); - System.arraycopy(locales, 0, names, 1, locales.length); - System.arraycopy(locales, 0, values, 1, locales.length); - fill(preferredLocale, names, values, OsmandSettings.getPreferredLocale(prefs)); - - // read available voice data - File extStorage = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.VOICE_PATH); - Set setFiles = new LinkedHashSet(); - if (extStorage.exists()) { - for (File f : extStorage.listFiles()) { - if (f.isDirectory()) { - setFiles.add(f.getName()); - } - } - } - String provider = OsmandSettings.getVoiceProvider(prefs); - entries = new String[setFiles.size() + 1]; - int k = 0; - entries[k++] = getString(R.string.voice_not_use); - for(String s : setFiles){ - entries[k++] = s; - } - voicePreference.setEntries(entries); - voicePreference.setEntryValues(entries); - if(setFiles.contains(provider)){ - voicePreference.setValue(provider); - } else { - voicePreference.setValueIndex(0); - } String vectorRenderer = OsmandSettings.getVectorRenderer(prefs); Collection rendererNames = RendererRegistry.getRegistry().getRendererNames(); @@ -363,13 +356,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference rendererPreference.setValueIndex(0); } - int startZoom = 12; - int endZoom = 19; - entries = new String[endZoom - startZoom + 1]; - for (int i = startZoom; i <= endZoom; i++) { - entries[i - startZoom] = i + ""; //$NON-NLS-1$ - } - fill(maxLevelToDownload, entries, entries, OsmandSettings.getMaximumLevelToDownloadTile(prefs)+""); //$NON-NLS-1$ + Map entriesMap = getTileSourceEntries(this); entries = new String[entriesMap.size() + 1]; @@ -449,51 +436,49 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference OsmandSettings.getWriteableEditor(this).putInt(id, value).commit(); } + @SuppressWarnings("unchecked") @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // handle boolean prefences - BooleanPreference p = null; - for(BooleanPreference b : booleanPreferences){ - if(b.getPref() == preference){ - p = b; - break; + OsmandPreference boolPref = booleanPreferences.get(preference.getKey()); + OsmandPreference listPref = (OsmandPreference) listPreferences.get(preference.getKey()); + if(boolPref != null){ + boolPref.set((Boolean)newValue); + } else if (listPref != null) { + CharSequence entry = ((ListPreference) preference).getEntry(); + Map map = listPrefValues.get(preference.getKey()); + Object obj = map.get(entry); + listPref.set(obj); + + 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(p != null){ - editBoolean(p.getId(), (Boolean)newValue); } else if(preference == applicationMode){ boolean changed = ApplicationMode.setAppMode(ApplicationMode.valueOf(newValue.toString()), getMyApplication()); if(changed){ updateAllSettings(); } - } else if(preference == daynightMode){ - editString(OsmandSettings.DAYNIGHT_MODE, (String) newValue); - getMyApplication().getDaynightHelper().setDayNightMode(DayNightMode.valueOf(newValue.toString())); - } else if(preference == mapScreenOrientation){ - editInt(OsmandSettings.MAP_SCREEN_ORIENTATION, Integer.parseInt(newValue.toString())); } else if(preference == saveTrackInterval){ editInt(OsmandSettings.SAVE_TRACK_INTERVAL, Integer.parseInt(newValue.toString())); + } else if (preference == routeServiceInterval) { + editInt(OsmandSettings.SERVICE_OFF_INTERVAL, Integer.parseInt((String) newValue) * 1000); + } else if (preference == routeServiceWaitInterval) { + editInt(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL, Integer.parseInt((String) newValue) * 1000); } else if(preference == userPassword){ editString(OsmandSettings.USER_PASSWORD, (String) newValue); - } else if(preference == useInternetToDownload){ - OsmandSettings.setUseInternetToDownloadTiles((Boolean) newValue, OsmandSettings.getWriteableEditor(this)); } else if(preference == userName){ editString(OsmandSettings.USER_NAME, (String) newValue); } else if(preference == applicationDir){ warnAboutChangingStorage((String) newValue); return false; - } else if(preference == positionOnMap){ - editInt(OsmandSettings.POSITION_ON_MAP, positionOnMap.findIndexOfValue((String) newValue)); - } else if (preference == maxLevelToDownload) { - editInt(OsmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, Integer.parseInt((String) newValue)); - } else if (preference == routeServiceInterval) { - editInt(OsmandSettings.SERVICE_OFF_INTERVAL, Integer.parseInt((String) newValue) * 1000); - } else if (preference == routeServiceWaitInterval) { - editInt(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL, Integer.parseInt((String) newValue) * 1000); - } else if (preference == rotateMap) { - editInt(OsmandSettings.ROTATE_MAP, Integer.parseInt((String) newValue)); - } else if (preference == routeServiceProvider) { - editString(OsmandSettings.SERVICE_OFF_PROVIDER, (String) newValue); } else if (preference == routeServiceEnabled) { Intent serviceIntent = new Intent(this, NavigationService.class); if ((Boolean) newValue) { @@ -506,17 +491,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null); } } - } else if (preference == routerPreference) { - RouteService s = null; - for(RouteService r : RouteService.values()){ - if(r.getName().equals(newValue)){ - s = r; - break; - } - } - if(s != null){ - editInt(OsmandSettings.ROUTER_SERVICE, s.ordinal()); - } } else if (preference == rendererPreference) { BaseOsmandRender loaded = RendererRegistry.getRegistry().getRenderer((String) newValue); if(loaded == null){ @@ -527,24 +501,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show(); getMyApplication().getResourceManager().getRenderer().clearCache(); } - } else if (preference == voicePreference) { - int i = voicePreference.findIndexOfValue((String) newValue); - if (i == 0) { - editString(OsmandSettings.VOICE_PROVIDER, null); - } else { - editString(OsmandSettings.VOICE_PROVIDER, (String) newValue); - } - getMyApplication().initCommandPlayer(); - } else if (preference == metricPreference) { - MetricsConstants mc = MetricsConstants.valueOf((String) newValue); - OsmandSettings.setDefaultMetricConstants(mc, this); - } else if (preference == preferredLocale) { - editString(OsmandSettings.PREFERRED_LOCALE, (String) newValue); - // restart activity - getMyApplication().checkPrefferedLocale(); - Intent intent = getIntent(); - finish(); - startActivity(intent); } else if (preference == tileSourcePreference) { if(VECTOR_MAP.equals((String) newValue)){ editBoolean(OsmandSettings.MAP_VECTOR_DATA, true); diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 6e867b83ef..86cd475eea 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -81,7 +81,7 @@ public class ShowRouteInfoActivity extends ListActivity { RouteDirectionInfo item = ((RouteInfoAdapter)getListAdapter()).getItem(position - 1); Location loc = helper.getLocationFromRouteDirection(item); if(loc != null){ - OsmandSettings.setMapLocationToShow(this, loc.getLatitude(),loc.getLongitude()); + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(loc.getLatitude(),loc.getLongitude()); startActivity(new Intent(this, MapActivity.class)); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 9e9484a33f..834cffd183 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -49,8 +49,7 @@ public class GeoIntentActivity extends ListActivity { super.onCreate(savedInstanceState); setContentView(R.layout.search_address_offline); getMyApplication().checkApplicationIsBeingInitialized(this); - location = OsmandSettings.getLastKnownMapLocation(OsmandSettings - .getPrefs(this)); + location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); final Intent intent = getIntent(); if (intent != null) { progressDlg = ProgressDialog.show(this, @@ -145,7 +144,7 @@ public class GeoIntentActivity extends ListActivity { super.onListItemClick(l, v, position, id); MapObject item = ((MapObjectAdapter) getListAdapter()) .getItem(position); - OsmandSettings.setMapLocationToShow(this, item.getLocation() + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(item.getLocation() .getLatitude(), item.getLocation().getLongitude(), getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$ startActivity(new Intent(this, MapActivity.class)); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java index 11a41b9c61..21879fedea 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java @@ -45,6 +45,7 @@ public class SearchAddressActivity extends Activity { private Button searchOnline; private ProgressDialog progressDlg; + private OsmandSettings osmandSettings; @Override @@ -60,6 +61,7 @@ public class SearchAddressActivity extends Activity { countryButton = (Button) findViewById(R.id.CountryButton); buildingButton = (Button) findViewById(R.id.BuildingButton); searchOnline = (Button) findViewById(R.id.SearchOnline); + osmandSettings = OsmandSettings.getOsmandSettings(SearchAddressActivity.this); attachListeners(); } @@ -96,10 +98,10 @@ public class SearchAddressActivity extends Activity { @Override public void onClick(View v) { if(radioBuilding){ - OsmandSettings.removeLastSearchedIntersectedStreet(SearchAddressActivity.this); + osmandSettings.removeLastSearchedIntersectedStreet(); startActivity(new Intent(SearchAddressActivity.this, SearchBuildingByNameActivity.class)); } else { - OsmandSettings.setLastSearchedIntersectedStreet(SearchAddressActivity.this, ""); //$NON-NLS-1$ + osmandSettings.setLastSearchedIntersectedStreet(""); //$NON-NLS-1$ startActivity(new Intent(SearchAddressActivity.this, SearchStreet2ByNameActivity.class)); } } @@ -175,7 +177,7 @@ public class SearchAddressActivity extends Activity { LatLon l = null; String historyName = null; int zoom = 12; - boolean en = OsmandSettings.usingEnglishNames(OsmandSettings.getPrefs(this)); + boolean en = osmandSettings.USE_ENGLISH_NAMES.get(); if (street2 != null && street != null) { l = region.findStreetIntersection(street, street2); if(l != null) { @@ -201,9 +203,9 @@ public class SearchAddressActivity extends Activity { } if (l != null) { if(navigateTo){ - OsmandSettings.setPointToNavigate(SearchAddressActivity.this, l.getLatitude(), l.getLongitude()); + osmandSettings.setPointToNavigate(l.getLatitude(), l.getLongitude()); } else { - OsmandSettings.setMapLocationToShow(SearchAddressActivity.this, l.getLatitude(), l.getLongitude(), zoom, historyName); + osmandSettings.setMapLocationToShow(l.getLatitude(), l.getLongitude(), zoom, historyName); } startActivity(new Intent(SearchAddressActivity.this, MapActivity.class)); @@ -280,28 +282,27 @@ public class SearchAddressActivity extends Activity { } public void loadData(){ - SharedPreferences prefs = OsmandSettings.getPrefs(this); if (region != null) { - if(region.useEnglishNames() != OsmandSettings.usingEnglishNames(prefs)){ - region.setUseEnglishNames(OsmandSettings.usingEnglishNames(prefs)); + if(region.useEnglishNames() != osmandSettings.USE_ENGLISH_NAMES.get()){ + region.setUseEnglishNames(osmandSettings.USE_ENGLISH_NAMES.get()); } - String postcodeStr = OsmandSettings.getLastSearchedPostcode(prefs); + String postcodeStr = osmandSettings.getLastSearchedPostcode(); if(postcodeStr != null){ postcode = region.getPostcode(postcodeStr); } else { - city = region.getCityById(OsmandSettings.getLastSearchedCity(prefs)); + city = region.getCityById(osmandSettings.getLastSearchedCity()); } if (postcode != null || city != null) { MapObject o = postcode == null ? city : postcode; - street = region.getStreetByName(o, OsmandSettings.getLastSearchedStreet(prefs)); + street = region.getStreetByName(o, osmandSettings.getLastSearchedStreet()); if (street != null) { - String str = OsmandSettings.getLastSearchedIntersectedStreet(prefs); + String str = osmandSettings.getLastSearchedIntersectedStreet(); radioBuilding = str == null; if(str != null){ street2 = region.getStreetByName(o, str); } else { - building = region.getBuildingByName(street, OsmandSettings.getLastSearchedBuilding(prefs)); + building = region.getBuildingByName(street, osmandSettings.getLastSearchedBuilding()); } } } @@ -334,16 +335,15 @@ public class SearchAddressActivity extends Activity { @Override protected void onResume() { super.onResume(); - SharedPreferences prefs = OsmandSettings.getPrefs(this); region = null; - String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(prefs); + String lastSearchedRegion = osmandSettings.getLastSearchedRegion(); region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(lastSearchedRegion); String progressMsg = null; // try to determine whether progress dialog & new thread needed if (region != null) { - Long cityId = OsmandSettings.getLastSearchedCity(prefs); - String postcode = OsmandSettings.getLastSearchedPostcode(prefs); + Long cityId = osmandSettings.getLastSearchedCity(); + String postcode = osmandSettings.getLastSearchedPostcode(); if (!region.areCitiesPreloaded()) { progressMsg = getString(R.string.loading_cities); } else if (postcode != null && !region.arePostcodesPreloaded()) { @@ -352,7 +352,7 @@ public class SearchAddressActivity extends Activity { progressMsg = getString(R.string.loading_streets_buildings); } else if (postcode != null && region.getPostcode(postcode) != null && region.getPostcode(postcode).isEmptyWithStreets()) { progressMsg = getString(R.string.loading_streets_buildings); - } else if (OsmandSettings.usingEnglishNames(prefs) != region.useEnglishNames()) { + } else if (osmandSettings.USE_ENGLISH_NAMES.get() != region.useEnglishNames()) { progressMsg = getString(R.string.converting_names); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java index dc6ef3b8f0..9a4ecc3e69 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java @@ -65,7 +65,7 @@ public class SearchAddressOnlineActivity extends ListActivity { searchPlaces(((EditText) findViewById(R.id.SearchText)).getText().toString()); } }); - location = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); + location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); } protected void searchPlaces(final String search) { @@ -158,7 +158,7 @@ public class SearchAddressOnlineActivity extends ListActivity { protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Place item = ((PlacesAdapter) getListAdapter()).getItem(position); - OsmandSettings.setMapLocationToShow(this, item.lat, item.lon, getString(R.string.address)+ " : " + item.displayName); //$NON-NLS-1$ + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(item.lat, item.lon, getString(R.string.address)+ " : " + item.displayName); //$NON-NLS-1$ startActivity(new Intent(this, MapActivity.class)); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java index e1d0953111..5d5ea2ab67 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java @@ -20,18 +20,19 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity { private RegionAddressRepository region; private LatLon location; + private OsmandSettings settings; @Override protected void onCreate(Bundle savedInstanceState) { - region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(OsmandSettings.getPrefs(this))); - location = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); + settings = ((OsmandApplication)getApplication()).getSettings(); + region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); + location = settings.getLastKnownMapLocation(); super.onCreate(savedInstanceState); ((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city); } @@ -51,12 +53,12 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity av, View v, int pos, long id) { final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(pos); - String format = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, OsmandSettings.usingEnglishNames(settings)); + String format = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, settings.USE_ENGLISH_NAMES.get()); if (amenity.getOpeningHours() != null) { format += " "+getString(R.string.opening_hours) + " : " + amenity.getOpeningHours(); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -228,18 +228,18 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen @Override public void onClick(DialogInterface dialog, int which) { if(which == 0){ - int z = OsmandSettings.getLastKnownMapZoom(settings); - String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, OsmandSettings.usingEnglishNames(settings)); - OsmandSettings.setMapLocationToShow(SearchPOIActivity.this, + int z = settings.getLastKnownMapZoom(); + String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, settings.usingEnglishNames()); + settings.setMapLocationToShow( amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), Math.max(16, z), getString(R.string.poi)+" : " + poiSimpleFormat); //$NON-NLS-1$ } else if(which == 1){ LatLon l = amenity.getLocation(); - OsmandSettings.setPointToNavigate(SearchPOIActivity.this, l.getLatitude(), l.getLongitude()); + settings.setPointToNavigate(l.getLatitude(), l.getLongitude()); } if(filter != null){ - OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId()); - OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true); + settings.setPoiFilterForMap(filter.getFilterId()); + settings.SHOW_POI_OVER_MAP.set(true); } Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class); @@ -480,13 +480,13 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen public void onListItemClick(ListView parent, View v, int position, long id) { if(filter != null){ - OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId()); - OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true); + settings.setPoiFilterForMap(filter.getFilterId()); + settings.SHOW_POI_OVER_MAP.set(true); } - int z = OsmandSettings.getLastKnownMapZoom(settings); + int z = settings.getLastKnownMapZoom(); Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); - String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, this, OsmandSettings.usingEnglishNames(settings)); - OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), + String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, this, settings.usingEnglishNames()); + settings.setMapLocationToShow( amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), Math.max(16, z), getString(R.string.poi)+" : " + poiSimpleFormat); //$NON-NLS-1$ Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class); startActivity(newIntent); @@ -598,7 +598,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen LatLon l = amenity.getLocation(); Location.distanceBetween(l.getLatitude(), l.getLongitude(), location.getLatitude(), location.getLongitude(), mes); } - String str = OsmAndFormatter.getPoiStringWithoutType(amenity, OsmandSettings.usingEnglishNames(settings)); + String str = OsmAndFormatter.getPoiStringWithoutType(amenity, settings.usingEnglishNames()); label.setText(str); int opened = -1; if (amenity.getOpeningHours() != null) { @@ -664,7 +664,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen .toLowerCase(); List filter = new ArrayList(); for (Amenity item : originalAmenityList) { - String lower = OsmAndFormatter.getPoiStringWithoutType(item, OsmandSettings.usingEnglishNames(settings)).toLowerCase(); + String lower = OsmAndFormatter.getPoiStringWithoutType(item, settings.usingEnglishNames()).toLowerCase(); if(lower.indexOf(lowerCase) != -1){ filter.add(item); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java index e93595f8d2..131f479f2f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java @@ -55,7 +55,7 @@ public class SearchPoiFilterActivity extends ListActivity { latitude = extras.getDouble(SEARCH_LAT); longitude = extras.getDouble(SEARCH_LON); } else { - LatLon loc = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); + LatLon loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); latitude = loc.getLatitude(); longitude = loc.getLongitude(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java index 804c52ceb7..6dcfc78df4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java @@ -35,7 +35,7 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity initialList = new ArrayList(); private ProgressDialog progressDlg; + private OsmandSettings settings; @Override protected void onCreate(Bundle savedInstanceState) { - SharedPreferences prefs = OsmandSettings.getPrefs(this); - region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(prefs)); + settings = OsmandSettings.getOsmandSettings(this); + region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); if(region != null){ - postcode = region.getPostcode(OsmandSettings.getLastSearchedPostcode(prefs)); - city = region.getCityById(OsmandSettings.getLastSearchedCity(prefs)); + postcode = region.getPostcode(settings.getLastSearchedPostcode()); + city = region.getCityById(settings.getLastSearchedCity()); if(postcode != null){ - street1 = region.getStreetByName(postcode, (OsmandSettings.getLastSearchedStreet(prefs))); + street1 = region.getStreetByName(postcode, (settings.getLastSearchedStreet())); if(street1 != null){ city = street1.getCity(); } } else if(city != null){ - street1 = region.getStreetByName(city, (OsmandSettings.getLastSearchedStreet(prefs))); + street1 = region.getStreetByName(city, (settings.getLastSearchedStreet())); } if(city != null){ startLoadDataInThread(getString(R.string.loading_streets)); @@ -109,7 +109,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity stops = route.getDirection() ? route.getRoute().getForwardStops() : route.getRoute().getBackwardStops(); - boolean en = OsmandSettings.usingEnglishNames(settings); + boolean en = settings.usingEnglishNames(); String info = getInformation(route, stops, routeInd, false); StringBuilder txt = new StringBuilder(300); @@ -459,7 +459,7 @@ public class SearchTransportActivity extends ListActivity { } else { labelW.append(getString(R.string.transport_search_none)); } - labelW.append("]\n").append(route.getName(OsmandSettings.usingEnglishNames(settings))); //$NON-NLS-1$ + labelW.append("]\n").append(route.getName(settings.usingEnglishNames())); //$NON-NLS-1$ label.setText(labelW.toString()); // TODO icons if (locationToGo != null && stop.getDistToLocation() < 400) { @@ -531,7 +531,7 @@ public class SearchTransportActivity extends ListActivity { icon.setVisibility(View.VISIBLE); StringBuilder labelW = new StringBuilder(150); labelW.append(route.getType()).append(" ").append(route.getRef()); //$NON-NLS-1$ - boolean en = OsmandSettings.usingEnglishNames(settings); + boolean en = settings.usingEnglishNames(); labelW.append(" : ").append(info.getStart().getName(en)).append(" - ").append(info.getStop().getName(en)); //$NON-NLS-1$ //$NON-NLS-2$ // additional information if route is calculated if (currentRouteLocation == -1) { diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 63fae69998..934009bec6 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -73,12 +73,12 @@ public class MapRenderRepositories { private boolean interrupted = false; private RenderingContext currentRenderingContext; private SearchRequest searchRequest; - private SharedPreferences prefs; + private OsmandSettings prefs; public MapRenderRepositories(Context context){ this.context = context; this.renderer = new OsmandRenderer(context); handler = new Handler(Looper.getMainLooper()); - prefs = OsmandSettings.getPrefs(context); + prefs = OsmandSettings.getOsmandSettings(context); } public Context getContext() { @@ -355,7 +355,7 @@ public class MapRenderRepositories { Bitmap bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, Config.RGB_565); - boolean stepByStep = OsmandSettings.isUsingStepByStepRendering(prefs); + boolean stepByStep = prefs.USE_STEP_BY_STEP_RENDERING.get(); // 1. generate image step by step if (stepByStep) { this.bmp = bmp; @@ -365,7 +365,7 @@ public class MapRenderRepositories { renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, - OsmandSettings.usingEnglishNames(prefs), renderingType, stepByStep ? notifyList : null); + prefs.USE_ENGLISH_NAMES.get(), renderingType, stepByStep ? notifyList : null); if (checkWhetherInterrupted()) { currentRenderingContext = null; return; @@ -378,7 +378,7 @@ public class MapRenderRepositories { this.bmp = bmp; this.bmpLocation = tileRect; } - if(OsmandSettings.isDebugRendering(context)){ + if(prefs.DEBUG_RENDERING_INFO.get()){ final String msg = "Search done in "+ searchTime+" ms\nRendering done in "+ renderingTime+ " ms"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ handler.post(new Runnable(){ @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 6f863ecdd0..46c8bfd663 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -4,7 +4,6 @@ import net.osmand.Algoritms; import net.osmand.OsmAndFormatter; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo; @@ -172,7 +171,7 @@ public class MapInfoLayer implements OsmandMapLayer { pathTransform.postTranslate(boundsForMiniRoute.left, boundsForMiniRoute.top); - showArrivalTime = OsmandSettings.isShowingArrivalTime(view.getSettings()); + showArrivalTime = view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.get(); } private void scaleRect(RectF r){ @@ -567,14 +566,14 @@ public class MapInfoLayer implements OsmandMapLayer { } if (boundsForLeftTime.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) { showArrivalTime = !showArrivalTime; - OsmandSettings.setShowingArrivalTime(view.getContext(), showArrivalTime); + view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime); view.refreshMap(); return true; } } if(cachedDistString != null && boundsForDist.contains(point.x, point.y)){ AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); - LatLon pointToNavigate = OsmandSettings.getPointToNavigate(view.getSettings()); + LatLon pointToNavigate = view.getSettings().getPointToNavigate(); if(pointToNavigate != null){ int fZoom = view.getZoom() < 15 ? 15 : view.getZoom(); thread.startMoving(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java index 3cfcb0fa41..e72baf30fa 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmBugsLayer.java @@ -328,7 +328,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe String text = ((EditText)openBug.findViewById(R.id.BugMessage)).getText().toString(); String author = ((EditText)openBug.findViewById(R.id.AuthorName)).getText().toString(); // do not set name as author it is ridiculous in that case - OsmandSettings.setUserNameForOsmBug(ctx, author); + view.getSettings().USER_OSM_BUG_NAME.set(author); boolean bug = createNewBug(latitude, longitude, text, author); if (bug) { Toast.makeText(ctx, ctx.getResources().getString(R.string.osb_add_dialog_success), Toast.LENGTH_LONG).show(); @@ -347,7 +347,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe public void openBug(final Context ctx, LayoutInflater layoutInflater, final OsmandMapTileView mapView, final double latitude, final double longitude){ - openBugAlertDialog(ctx, layoutInflater, mapView, latitude, longitude, "", OsmandSettings.getUserNameForOsmBug(OsmandSettings.getPrefs(ctx))); + openBugAlertDialog(ctx, layoutInflater, mapView, latitude, longitude, "", mapView.getSettings().USER_OSM_BUG_NAME.get()); } public void commentBug(final Context ctx, LayoutInflater layoutInflater, final OpenStreetBug bug){ @@ -355,14 +355,14 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe builder.setTitle(R.string.osb_comment_dialog_title); final View view = layoutInflater.inflate(R.layout.open_bug, null); builder.setView(view); - ((EditText)view.findViewById(R.id.AuthorName)).setText(OsmandSettings.getUserNameForOsmBug(OsmandSettings.getPrefs(ctx))); + ((EditText)view.findViewById(R.id.AuthorName)).setText(OsmandSettings.getOsmandSettings(ctx).USER_OSM_BUG_NAME.get()); builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setPositiveButton(R.string.osb_comment_dialog_add_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String text = ((EditText)view.findViewById(R.id.BugMessage)).getText().toString(); String author = ((EditText)view.findViewById(R.id.AuthorName)).getText().toString(); - OsmandSettings.setUserNameForOsmBug(ctx, author); + OsmandSettings.getOsmandSettings(ctx).USER_OSM_BUG_NAME.set(author); boolean added = addingComment(bug.getId(), text, author); if (added) { Toast.makeText(ctx, ctx.getResources().getString(R.string.osb_comment_dialog_success), Toast.LENGTH_LONG).show(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index c6885a5126..a395903012 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -234,7 +234,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall // that trigger allows to scale tiles for certain devices // for example for device with density > 1 draw tiles the same size as with density = 1 // It makes text bigger but blurry, the settings could be introduced for that - if (dm != null && dm.density > 1f && !OsmandSettings.isUsingHighResMaps(getSettings()) ) { + if (dm != null && dm.density > 1f && !getSettings().USE_HIGH_RES_MAPS.get() ) { res *= dm.density; } return res; @@ -457,11 +457,11 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall protected Rect boundsRect = new Rect(); protected RectF bitmapToDraw = new RectF(); protected Rect bitmapToZoom = new Rect(); - protected SharedPreferences settings = null; + protected OsmandSettings settings = null; - public SharedPreferences getSettings(){ + public OsmandSettings getSettings(){ if(settings == null){ - settings = OsmandSettings.getPrefs(getContext()); + settings = OsmandSettings.getOsmandSettings(getContext()); } return settings; } @@ -471,7 +471,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall return; } - boolean useInternet = OsmandSettings.isUsingInternetToDownloadTiles(getSettings()); + boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get(); if (useInternet) { MapTileDownloader.getInstance().refuseAllPreviousRequests(); } @@ -510,9 +510,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right); if (map != null) { ResourceManager mgr = getApplication().getResourceManager(); - useInternet = useInternet && OsmandSettings.isInternetConnectionAvailable(getContext()) + useInternet = useInternet && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet(); - int maxLevel = Math.min(OsmandSettings.getMaximumLevelToDownloadTile(getSettings()), map.getMaximumZoomSupported()); + + int maxLevel = Math.min(getSettings().MAX_LEVEL_TO_DOWNLOAD_TILE.get(), map.getMaximumZoomSupported()); for (int i = 0; i < width; i++) { diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 09c5b6d12b..b674f5b42a 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -7,7 +7,6 @@ import net.osmand.LogUtil; import net.osmand.OsmAndFormatter; import net.osmand.data.Amenity; import net.osmand.osm.LatLon; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.PoiFilter; import net.osmand.plus.R; import net.osmand.plus.ResourceManager; @@ -83,7 +82,8 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen public boolean onTouchEvent(PointF point) { Amenity n = getAmenityFromPoint(point); if(n != null){ - String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getContext(), OsmandSettings.usingEnglishNames(view.getSettings())); + String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getContext(), + view.getSettings().USE_ENGLISH_NAMES.get()); if(n.getOpeningHours() != null){ format += "\n" + view.getContext().getString(R.string.opening_hours) +" : "+ n.getOpeningHours(); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -213,7 +213,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen @Override public String getObjectDescription(Object o) { if(o instanceof Amenity){ - return OsmAndFormatter.getPoiSimpleFormat((Amenity) o, view.getContext(), OsmandSettings.usingEnglishNames(view.getSettings())); + return OsmAndFormatter.getPoiSimpleFormat((Amenity) o, view.getContext(), view.getSettings().USE_ENGLISH_NAMES.get()); } return null; } diff --git a/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java index fec78b0775..bbf97a1f3d 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java @@ -144,7 +144,7 @@ public class TransportInfoLayer implements OsmandMapLayer { int x = view.getRotatedMapXForPoint(location.getLatitude(), location.getLongitude()); int y = view.getRotatedMapYForPoint(location.getLatitude(), location.getLongitude()); if (Math.abs(x - ex) < getRadius() * 3 /2 && Math.abs(y - ey) < getRadius() * 3 /2) { - Toast.makeText(view.getContext(), st.getName(OsmandSettings.usingEnglishNames(view.getSettings())) + " : " + //$NON-NLS-1$ + Toast.makeText(view.getContext(), st.getName(view.getSettings().USE_ENGLISH_NAMES.get()) + " : " + //$NON-NLS-1$ route.getType() + " " + route.getRef() //$NON-NLS-1$ , Toast.LENGTH_LONG).show(); return true; diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 63136a2fd2..4266c5e50c 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -81,7 +81,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo private String getStopDescription(TransportStop n, boolean useName) { StringBuilder text = new StringBuilder(250); text.append(view.getContext().getString(R.string.transport_Stop)) - .append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getSettings()))); //$NON-NLS-1$ + .append(" : ").append(n.getName(view.getSettings().USE_ENGLISH_NAMES.get())); //$NON-NLS-1$ text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ List reps = view.getApplication().getResourceManager().searchTransportRepositories( n.getLocation().getLatitude(), n.getLocation().getLongitude()); @@ -91,7 +91,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo List l; if (!useName) { l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$ - } else if (OsmandSettings.usingEnglishNames(view.getSettings())) { + } else if (view.getSettings().USE_ENGLISH_NAMES.get()) { l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {3}"); //$NON-NLS-1$ } else { l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {2}"); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java index dcacb18999..373aab180e 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java @@ -83,7 +83,7 @@ public class CommandPlayer { prologSystem.clearTheory(); voiceDir = null; if(voiceProvider != null){ - File parent = OsmandSettings.extendOsmandPath(ctx, ResourceManager.VOICE_PATH); + File parent = OsmandSettings.getOsmandSettings(ctx).extendOsmandPath(ResourceManager.VOICE_PATH); voiceDir = new File(parent, voiceProvider); if(!voiceDir.exists()){ voiceDir = null;