diff --git a/OsmAnd/src/net/osmand/NavigationService.java b/OsmAnd/src/net/osmand/NavigationService.java index dc299b99ee..c98712d66d 100644 --- a/OsmAnd/src/net/osmand/NavigationService.java +++ b/OsmAnd/src/net/osmand/NavigationService.java @@ -12,6 +12,7 @@ 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; @@ -36,6 +37,7 @@ public class NavigationService extends Service implements LocationListener { private int serviceError; private RoutingHelper routingHelper; private Notification notification; + private SharedPreferences settings; @Override @@ -70,10 +72,10 @@ public class NavigationService extends Service implements LocationListener { super.onCreate(); setForeground(true); handler = new Handler(); - - serviceOffInterval = OsmandSettings.getServiceOffInterval(this); - serviceOffProvider = OsmandSettings.getServiceOffProvider(this); - serviceError = OsmandSettings.getServiceOffWaitInterval(this); + settings = OsmandSettings.getSharedPreferences(this); + serviceOffInterval = OsmandSettings.getServiceOffInterval(settings); + serviceOffProvider = OsmandSettings.getServiceOffProvider(settings); + serviceError = OsmandSettings.getServiceOffWaitInterval(settings); savingTrackHelper = new SavingTrackHelper(this); delayedAction(true, 500); routingHelper = ((OsmandApplication)getApplication()).getRoutingHelper(); @@ -114,9 +116,9 @@ public class NavigationService extends Service implements LocationListener { @Override public void onLocationChanged(Location location) { - if(location != null && !OsmandSettings.getMapActivityEnabled(this)){ + if(location != null && !OsmandSettings.getMapActivityEnabled(settings)){ savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), - location.getSpeed(), location.getTime()); + location.getSpeed(), location.getTime(), settings); if(routingHelper.isFollowingMode()){ routingHelper.setCurrentLocation(location); } diff --git a/OsmAnd/src/net/osmand/OsmandSettings.java b/OsmAnd/src/net/osmand/OsmandSettings.java index 6f0a794247..4acc4a96a0 100644 --- a/OsmAnd/src/net/osmand/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/OsmandSettings.java @@ -59,6 +59,14 @@ public class OsmandSettings { SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); return prefs.edit(); } + + public static final SharedPreferences getSharedPreferences(Context ctx){ + return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + } + + public static final SharedPreferences getPrefs(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$ @@ -67,9 +75,8 @@ public class OsmandSettings { private static long lastTimeInternetConnectionChecked = 0; private static boolean internetConnectionAvailable = true; - public static boolean isUsingInternetToDownloadTiles(Context ctx) { + public static boolean isUsingInternetToDownloadTiles(SharedPreferences prefs) { if(CACHE_USE_INTERNET_TO_DOWNLOAD_TILES == null){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); 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; @@ -101,8 +108,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isUsingTrackBall(SharedPreferences prefs) { return prefs.getBoolean(USE_TRACKBALL_FOR_MOVEMENTS, USE_TRACKBALL_FOR_MOVEMENTS_DEF); } @@ -111,8 +117,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingPoiOverMap(SharedPreferences prefs) { return prefs.getBoolean(SHOW_POI_OVER_MAP, SHOW_POI_OVER_MAP_DEF); } @@ -125,8 +130,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingTransportOverMap(SharedPreferences prefs) { return prefs.getBoolean(SHOW_TRANSPORT_OVER_MAP, SHOW_TRANSPORT_OVER_MAP_DEF); } @@ -138,8 +142,7 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final String USER_NAME = "user_name"; //$NON-NLS-1$ - public static String getUserName(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getUserName(SharedPreferences prefs) { return prefs.getString(USER_NAME, "NoName"); //$NON-NLS-1$ } @@ -152,8 +155,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getUserNameForOsmBug(SharedPreferences prefs) { return prefs.getString(USER_OSM_BUG_NAME, "NoName/Osmand"); //$NON-NLS-1$ } @@ -163,8 +165,7 @@ public class OsmandSettings { } public static final String USER_PASSWORD = "user_password"; //$NON-NLS-1$ - public static String getUserPassword(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getUserPassword(SharedPreferences prefs){ return prefs.getString(USER_PASSWORD, ""); //$NON-NLS-1$ } @@ -176,8 +177,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static ApplicationMode getApplicationMode(SharedPreferences prefs) { String s = prefs.getString(APPLICATION_MODE, ApplicationMode.DEFAULT.name()); try { return ApplicationMode.valueOf(s); @@ -194,8 +194,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static RouteService getRouterService(SharedPreferences prefs) { int ord = prefs.getInt(ROUTER_SERVICE, RouteService.CLOUDMADE.ordinal()); if(ord < RouteService.values().length){ return RouteService.values()[ord]; @@ -226,8 +225,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getSavingTrackInterval(SharedPreferences prefs) { return prefs.getInt(SAVE_TRACK_INTERVAL, 5); } @@ -235,8 +233,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingOsmBugs(SharedPreferences prefs) { return prefs.getBoolean(SHOW_OSM_BUGS, SHOW_OSM_BUGS_DEF); } @@ -249,8 +246,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingYandexTraffic(SharedPreferences prefs) { return prefs.getBoolean(SHOW_YANDEX_TRAFFIC, SHOW_YANDEX_TRAFFIC_DEF); } @@ -263,8 +259,7 @@ public class OsmandSettings { public static final String SHOW_FAVORITES = "show_favorites"; //$NON-NLS-1$ public static final boolean SHOW_FAVORITES_DEF = false; - public static boolean isShowingFavorites(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingFavorites(SharedPreferences prefs) { return prefs.getBoolean(SHOW_FAVORITES, SHOW_FAVORITES_DEF); } @@ -276,8 +271,7 @@ public class OsmandSettings { // 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(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getMapOrientation(SharedPreferences prefs){ return prefs.getInt(MAP_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } @@ -285,8 +279,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingViewAngle(SharedPreferences prefs) { return prefs.getBoolean(SHOW_VIEW_ANGLE, SHOW_VIEW_ANGLE_DEF); } @@ -294,8 +287,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isAutoZoomEnabled(SharedPreferences prefs) { return prefs.getBoolean(AUTO_ZOOM_MAP, AUTO_ZOOM_MAP_DEF); } @@ -307,24 +299,21 @@ public class OsmandSettings { public static final int ROTATE_MAP_COMPASS = 2; // return 0 - no rotate, 1 - to bearing, 2 - to compass - public static int getRotateMap(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getMaximumLevelToDownloadTile(SharedPreferences prefs) { return prefs.getInt(MAX_LEVEL_TO_DOWNLOAD_TILE, 18); } @@ -332,8 +321,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isMapView3D(SharedPreferences prefs) { return prefs.getBoolean(MAP_VIEW_3D, MAP_VIEW_3D_DEF); } @@ -341,8 +329,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean usingEnglishNames(SharedPreferences prefs) { return prefs.getBoolean(USE_ENGLISH_NAMES, USE_ENGLISH_NAMES_DEF); } @@ -355,13 +342,11 @@ public class OsmandSettings { 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(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isUsingMapVectorData(SharedPreferences prefs){ return prefs.getBoolean(MAP_VECTOR_DATA, false); } - public static ITileSource getMapTileSource(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static ITileSource getMapTileSource(SharedPreferences prefs) { String tileName = prefs.getString(MAP_TILE_SOURCES, null); if (tileName != null) { @@ -399,8 +384,7 @@ public class OsmandSettings { return TileSourceManager.getMapnikSource(); } - public static String getMapTileSourceName(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getMapTileSourceName(SharedPreferences prefs) { String tileName = prefs.getString(MAP_TILE_SOURCES, null); if (tileName != null) { return tileName; @@ -418,23 +402,21 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + 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(ctx), null); + setMapLocationToShow(ctx, latitude, longitude, getLastKnownMapZoom(getSharedPreferences(ctx)), null); } public static void setMapLocationToShow(Context ctx, double latitude, double longitude, int zoom) { setMapLocationToShow(ctx, latitude, longitude, null); } - public static LatLon getAndClearMapLocationToShow(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static LatLon getAndClearMapLocationToShow(SharedPreferences prefs){ if(!prefs.contains(MAP_LAT_TO_SHOW)){ return null; } @@ -444,8 +426,7 @@ public class OsmandSettings { return new LatLon(lat, lon); } - public static int getMapZoomToShow(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getMapZoomToShow(SharedPreferences prefs) { return prefs.getInt(MAP_ZOOM_TO_SHOW, 5); } @@ -463,7 +444,7 @@ public class OsmandSettings { } public static void setMapLocationToShow(Context ctx, double latitude, double longitude, String historyDescription) { - setMapLocationToShow(ctx, latitude, longitude, getLastKnownMapZoom(ctx), historyDescription); + setMapLocationToShow(ctx, latitude, longitude, getLastKnownMapZoom(getSharedPreferences(ctx)), historyDescription); } // Do not use that method if you want to show point on map. Use setMapLocationToShow @@ -480,13 +461,11 @@ public class OsmandSettings { return prefs.edit().putBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, value).commit(); } - public static boolean isMapSyncToGpsLocation(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isMapSyncToGpsLocation(SharedPreferences prefs) { return prefs.getBoolean(IS_MAP_SYNC_TO_GPS_LOCATION, true); } - public static int getLastKnownMapZoom(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getLastKnownMapZoom(SharedPreferences prefs) { return prefs.getInt(LAST_KNOWN_MAP_ZOOM, 5); } @@ -500,8 +479,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + 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) { @@ -510,8 +488,7 @@ public class OsmandSettings { return new LatLon(lat, lon); } - public static boolean clearPointToNavigate(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean clearPointToNavigate(SharedPreferences prefs) { return prefs.edit().remove(POINT_NAVIGATE_LAT).remove(POINT_NAVIGATE_LON).commit(); } @@ -527,8 +504,7 @@ public class OsmandSettings { 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getLastSearchedRegion(SharedPreferences prefs) { return prefs.getString(LAST_SEARCHED_REGION, ""); //$NON-NLS-1$ } @@ -542,8 +518,7 @@ public class OsmandSettings { return edit.commit(); } - public static String getLastSearchedPostcode(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getLastSearchedPostcode(SharedPreferences prefs){ return prefs.getString(lAST_SEARCHED_POSTCODE, null); } @@ -557,8 +532,7 @@ public class OsmandSettings { return edit.commit(); } - public static Long getLastSearchedCity(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static Long getLastSearchedCity(SharedPreferences prefs) { return prefs.getLong(LAST_SEARCHED_CITY, -1); } @@ -573,8 +547,7 @@ public class OsmandSettings { return edit.commit(); } - public static String getLastSearchedStreet(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getLastSearchedStreet(SharedPreferences prefs) { return prefs.getString(LAST_SEARCHED_STREET, ""); //$NON-NLS-1$ } @@ -587,8 +560,7 @@ public class OsmandSettings { return edit.commit(); } - public static String getLastSearchedBuilding(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getLastSearchedBuilding(SharedPreferences prefs) { return prefs.getString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ } @@ -597,8 +569,7 @@ public class OsmandSettings { return prefs.edit().putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); } - public static String getLastSearchedIntersectedStreet(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getLastSearchedIntersectedStreet(SharedPreferences prefs) { if (!prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)) { return null; } @@ -611,7 +582,7 @@ public class OsmandSettings { } public static boolean removeLastSearchedIntersectedStreet(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + SharedPreferences prefs = getPrefs(ctx); return prefs.edit().remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); } @@ -636,16 +607,14 @@ public class OsmandSettings { // 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(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getVoiceProvider(SharedPreferences prefs){ return prefs.getString(VOICE_PROVIDER, null); } public static final String VOICE_MUTE = "voice_mute"; //$NON-NLS-1$ public static final boolean VOICE_MUTE_DEF = false; - public static boolean isVoiceMute(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isVoiceMute(SharedPreferences prefs){ return prefs.getBoolean(VOICE_MUTE, VOICE_MUTE_DEF); } @@ -657,8 +626,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean getMapActivityEnabled(SharedPreferences prefs) { return prefs.getBoolean(MAP_ACTIVITY_ENABLED, MAP_ACTIVITY_ENABLED_DEF); } @@ -670,8 +638,7 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$ public static final boolean SERVICE_OFF_ENABLED_DEF = false; - public static boolean getServiceOffEnabled(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean getServiceOffEnabled(SharedPreferences prefs) { return prefs.getBoolean(SERVICE_OFF_ENABLED, SERVICE_OFF_ENABLED_DEF); } @@ -683,8 +650,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static String getServiceOffProvider(SharedPreferences prefs) { return prefs.getString(SERVICE_OFF_PROVIDER, LocationManager.GPS_PROVIDER); } @@ -692,8 +658,7 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static int getServiceOffInterval(SharedPreferences prefs) { return prefs.getInt(SERVICE_OFF_INTERVAL, SERVICE_OFF_INTERVAL_DEF); } @@ -701,16 +666,14 @@ public class OsmandSettings { // 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(Context ctx) { - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + 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(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isFollowingByRoute(SharedPreferences prefs){ return prefs.getBoolean(FOLLOW_TO_THE_ROUTE, false); } @@ -721,8 +684,7 @@ public class OsmandSettings { public static final String SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = "show_arrival_time"; //$NON-NLS-1$ - public static boolean isShowingArrivalTime(Context ctx){ - SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + public static boolean isShowingArrivalTime(SharedPreferences prefs){ return prefs.getBoolean(SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME, true); } diff --git a/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java index 507d607f42..fb6bfb8faf 100644 --- a/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/activities/EditPOIFilterActivity.java @@ -62,7 +62,7 @@ public class EditPOIFilterActivity extends ListActivity { public void onClick(View v) { Bundle extras = getIntent().getExtras(); boolean searchNearBy = true; - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(EditPOIFilterActivity.this); + LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(EditPOIFilterActivity.this)); 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/activities/EditingPOIActivity.java b/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java index 182870ed23..c277cdb4a1 100644 --- a/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/activities/EditingPOIActivity.java @@ -134,7 +134,7 @@ public class EditingPOIActivity { } Builder builder = new AlertDialog.Builder(ctx); - builder.setTitle(MessageFormat.format(this.view.getResources().getString(R.string.poi_remove_confirm_template), a.getStringWithoutType(OsmandSettings.usingEnglishNames(ctx)))); + builder.setTitle(MessageFormat.format(this.view.getResources().getString(R.string.poi_remove_confirm_template), a.getStringWithoutType(OsmandSettings.usingEnglishNames(OsmandSettings.getPrefs(ctx))))); final EditText comment = new EditText(ctx); comment.setText(R.string.poi_remove_title); builder.setView(comment); @@ -365,8 +365,8 @@ public class EditingPOIActivity { DefaultHttpClient httpclient = new DefaultHttpClient(params); if (doAuthenticate) { - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(OsmandSettings.getUserName(ctx) + ":" //$NON-NLS-1$ - + OsmandSettings.getUserPassword(ctx)); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx)) + ":" //$NON-NLS-1$ + + OsmandSettings.getUserPassword(OsmandSettings.getPrefs(ctx))); httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials); } HttpRequestBase method = null; @@ -445,7 +445,7 @@ public class EditingPOIActivity { connection.setRequestMethod(requestMethod); StringBuilder responseBody = new StringBuilder(); if (doAuthenticate) { - String token = OsmandSettings.getUserName(ctx) + ":" + OsmandSettings.getUserPassword(ctx); //$NON-NLS-1$ + String token = OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx)) + ":" + OsmandSettings.getUserPassword(OsmandSettings.getPrefs(ctx)); //$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); @@ -626,7 +626,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(ctx)); + writeNode(n, info, ser, changeSetId, OsmandSettings.getUserName(OsmandSettings.getPrefs(ctx))); ser.endTag(null, action); ser.endTag(null, "osmChange"); //$NON-NLS-1$ ser.endDocument(); diff --git a/OsmAnd/src/net/osmand/activities/FavouritesActivity.java b/OsmAnd/src/net/osmand/activities/FavouritesActivity.java index 6ccb244ab2..0ce166a473 100644 --- a/OsmAnd/src/net/osmand/activities/FavouritesActivity.java +++ b/OsmAnd/src/net/osmand/activities/FavouritesActivity.java @@ -368,7 +368,7 @@ public class FavouritesActivity extends ListActivity { ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon); FavouritePoint model = (FavouritePoint) getItem(position); icon.setImageResource(R.drawable.opened_poi); - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(FavouritesActivity.this); + LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(FavouritesActivity.this)); int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); distanceLabel.setText(MapUtils.getFormattedDistance(dist)); diff --git a/OsmAnd/src/net/osmand/activities/MapActivity.java b/OsmAnd/src/net/osmand/activities/MapActivity.java index 7051c779c5..1242e9e602 100644 --- a/OsmAnd/src/net/osmand/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/activities/MapActivity.java @@ -159,11 +159,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso private boolean currentShowingAngle; private Dialog progressDlg = null; + private SharedPreferences settings; private boolean isMapLinkedToLocation(){ - return OsmandSettings.isMapSyncToGpsLocation(this); + return OsmandSettings.isMapSyncToGpsLocation(settings); } private Notification getNotification(){ @@ -181,7 +182,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + settings = OsmandSettings.getPrefs(this); // for voice navigation setVolumeControlStream(AudioManager.STREAM_MUSIC); requestWindowFeature(Window.FEATURE_NO_TITLE); @@ -263,7 +264,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso savingTrackHelper = new SavingTrackHelper(this); - LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this); + LatLon pointToNavigate = OsmandSettings.getPointToNavigate(settings); // TODO how this situation could be ? if(!Algoritms.objectEquals(routingHelper.getFinalLocation(), pointToNavigate)){ @@ -273,7 +274,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso routingHelper.setFinalAndCurrentLocation(pointToNavigate, null); } - if(OsmandSettings.isFollowingByRoute(this)){ + if(OsmandSettings.isFollowingByRoute(settings)){ if(pointToNavigate == null){ OsmandSettings.setFollowingByRoute(this, false); } else if(!routingHelper.isRouteCalculated()){ @@ -325,7 +326,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(MapActivity.this)){ + if(OsmandSettings.isAutoZoomEnabled(settings)){ locationChanged(mapView.getLatitude(), mapView.getLongitude(), null); } } @@ -339,7 +340,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(MapActivity.this)){ + if(OsmandSettings.isAutoZoomEnabled(settings)){ locationChanged(mapView.getLatitude(), mapView.getLongitude(), null); } } @@ -388,7 +389,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } @Override public boolean onTrackballEvent(MotionEvent event) { - if(event.getAction() == MotionEvent.ACTION_MOVE && OsmandSettings.isUsingTrackBall(this)){ + if(event.getAction() == MotionEvent.ACTION_MOVE && OsmandSettings.isUsingTrackBall(settings)){ float x = event.getX(); float y = event.getY(); LatLon l = mapView.getLatLonFromScreenPoint(mapView.getCenterPointX() + x * 15, mapView.getCenterPointY() + y * 15); @@ -483,7 +484,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } if(location != null && OsmandSettings.isSavingTrackToGpx(this)){ savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), - location.getAltitude(), location.getSpeed(), location.getTime()); + location.getAltitude(), location.getSpeed(), location.getTime(), settings); } registerUnregisterSensor(location); updateSpeedBearing(location); @@ -494,7 +495,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } if (location != null) { if (isMapLinkedToLocation()) { - if(OsmandSettings.isAutoZoomEnabled(this) && location.hasSpeed()){ + if(OsmandSettings.isAutoZoomEnabled(settings) && location.hasSpeed()){ int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom()); if(mapView.getZoom() != z && !mapView.mapIsAnimating()){ mapView.setZoom(z); @@ -536,7 +537,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if(point != null){ OsmandSettings.setPointToNavigate(this, point.getLatitude(), point.getLongitude()); } else { - OsmandSettings.clearPointToNavigate(this); + OsmandSettings.clearPointToNavigate(settings); } routingHelper.setFinalAndCurrentLocation(point, null, routingHelper.getCurrentGPXRoute()); if(point == null){ @@ -679,57 +680,57 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } private void updateApplicationModeSettings(){ - currentMapRotation = OsmandSettings.getRotateMap(this); - currentShowingAngle = OsmandSettings.isShowingViewAngle(this); + currentMapRotation = OsmandSettings.getRotateMap(settings); + currentShowingAngle = OsmandSettings.isShowingViewAngle(settings); if(currentMapRotation == OsmandSettings.ROTATE_MAP_NONE){ mapView.setRotate(0); } if(!currentShowingAngle){ locationLayer.setHeading(null); } - locationLayer.setAppMode(OsmandSettings.getApplicationMode(this)); - routingHelper.setAppMode(OsmandSettings.getApplicationMode(this)); - mapView.setMapPosition(OsmandSettings.getPositionOnMap(this)); + locationLayer.setAppMode(OsmandSettings.getApplicationMode(settings)); + routingHelper.setAppMode(OsmandSettings.getApplicationMode(settings)); + mapView.setMapPosition(OsmandSettings.getPositionOnMap(settings)); registerUnregisterSensor(getLastKnownLocation()); updateLayers(); } private void updateLayers(){ - if(mapView.getLayers().contains(transportStopsLayer) != OsmandSettings.isShowingTransportOverMap(this)){ - if(OsmandSettings.isShowingTransportOverMap(this)){ + if(mapView.getLayers().contains(transportStopsLayer) != OsmandSettings.isShowingTransportOverMap(settings)){ + if(OsmandSettings.isShowingTransportOverMap(settings)){ mapView.addLayer(transportStopsLayer, 5); } else { mapView.removeLayer(transportStopsLayer); } } - if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(this)){ - if(OsmandSettings.isShowingOsmBugs(this)){ + if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(settings)){ + if(OsmandSettings.isShowingOsmBugs(settings)){ mapView.addLayer(osmBugsLayer, 2); } else { mapView.removeLayer(osmBugsLayer); } } - if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){ - if(OsmandSettings.isShowingPoiOverMap(this)){ + if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(settings)){ + if(OsmandSettings.isShowingPoiOverMap(settings)){ mapView.addLayer(poiMapLayer, 3); } else { mapView.removeLayer(poiMapLayer); } } - if(mapView.getLayers().contains(favoritesLayer) != OsmandSettings.isShowingFavorites(this)){ - if(OsmandSettings.isShowingFavorites(this)){ + if(mapView.getLayers().contains(favoritesLayer) != OsmandSettings.isShowingFavorites(settings)){ + if(OsmandSettings.isShowingFavorites(settings)){ mapView.addLayer(favoritesLayer, 4); } else { mapView.removeLayer(favoritesLayer); } } - trafficLayer.setVisible(OsmandSettings.isShowingYandexTraffic(this)); + trafficLayer.setVisible(OsmandSettings.isShowingYandexTraffic(settings)); } private void updateMapSource(){ - boolean vectorData = OsmandSettings.isUsingMapVectorData(this); + boolean vectorData = OsmandSettings.isUsingMapVectorData(settings); ResourceManager rm = ((OsmandApplication)getApplication()).getResourceManager(); if(vectorData){ if(rm.getRenderer().isEmpty()){ @@ -737,7 +738,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso vectorData = false; } } - ITileSource newSource = OsmandSettings.getMapTileSource(this); + ITileSource newSource = OsmandSettings.getMapTileSource(settings); if(mapView.getMap() instanceof SQLiteTileSource){ ((SQLiteTileSource)mapView.getMap()).closeDB(); } @@ -750,19 +751,19 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override protected void onResume() { super.onResume(); - if(OsmandSettings.getMapOrientation(this) != getRequestedOrientation()){ - setRequestedOrientation(OsmandSettings.getMapOrientation(this)); + if(OsmandSettings.getMapOrientation(settings) != getRequestedOrientation()){ + setRequestedOrientation(OsmandSettings.getMapOrientation(settings)); // do nothing now (let recreate activity) // only save map position - LatLon l = OsmandSettings.getLastKnownMapLocation(this); + LatLon l = OsmandSettings.getLastKnownMapLocation(settings); mapView.setLatLon(l.getLatitude(), l.getLongitude()); - mapView.setZoom(OsmandSettings.getLastKnownMapZoom(this)); + mapView.setZoom(OsmandSettings.getLastKnownMapZoom(settings)); return; } currentScreenOrientation = getWindow().getWindowManager().getDefaultDisplay().getOrientation(); - boolean showTiles = !OsmandSettings.isUsingMapVectorData(this); - ITileSource source = showTiles ? OsmandSettings.getMapTileSource(this) : null; + boolean showTiles = !OsmandSettings.isUsingMapVectorData(settings); + ITileSource source = showTiles ? OsmandSettings.getMapTileSource(settings) : null; if (showTiles != !rendererLayer.isVisible() || !Algoritms.objectEquals(mapView.getMap(), source)) { updateMapSource(); } @@ -798,15 +799,15 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); if(prefs != null && prefs.contains(OsmandSettings.LAST_KNOWN_MAP_LAT)){ - LatLon l = OsmandSettings.getLastKnownMapLocation(this); + LatLon l = OsmandSettings.getLastKnownMapLocation(settings); mapView.setLatLon(l.getLatitude(), l.getLongitude()); - mapView.setZoom(OsmandSettings.getLastKnownMapZoom(this)); - LatLon latLon = OsmandSettings.getAndClearMapLocationToShow(this); + mapView.setZoom(OsmandSettings.getLastKnownMapZoom(settings)); + LatLon latLon = OsmandSettings.getAndClearMapLocationToShow(settings); LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude()); if(latLon != null && !latLon.equals(cur)){ mapView.getAnimatedDraggingThread().startMoving(cur.getLatitude(), cur.getLongitude(), latLon.getLatitude(), latLon.getLongitude(), - mapView.getZoom(), OsmandSettings.getMapZoomToShow(this), + mapView.getZoom(), OsmandSettings.getMapZoomToShow(settings), mapView.getSourceTileSize(), mapView.getRotate(), true); } } @@ -928,7 +929,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(this) != null) { + if (OsmandSettings.getPointToNavigate(settings) != null) { navigateToPointMenu.setVisible(true); } else { navigateToPointMenu.setVisible(false); @@ -1007,7 +1008,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso return ApplicationMode.values()[i]; } } - return OsmandSettings.getApplicationMode(this); + return OsmandSettings.getApplicationMode(settings); } @@ -1023,7 +1024,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(this); + ApplicationMode appMode = OsmandSettings.getApplicationMode(settings); for(int i=0; i< buttons.length; i++){ if(buttons[i] != null){ final int ind = i; @@ -1080,7 +1081,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso public void onClick(DialogInterface dialog, int which) { ApplicationMode mode = getAppMode(buttons); // change global settings - if (OsmandSettings.getApplicationMode(MapActivity.this) != mode) { + if (OsmandSettings.getApplicationMode(settings) != mode) { Editor edit = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_WRITEABLE).edit(); edit.putString(OsmandSettings.APPLICATION_MODE, mode.name()); SettingsActivity.setAppMode(mode, edit); @@ -1245,10 +1246,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso final boolean[] selected = new boolean[layersList.size()]; Arrays.fill(selected, true); - selected[1] = OsmandSettings.isShowingPoiOverMap(this); - selected[2] = OsmandSettings.isShowingTransportOverMap(this); - selected[3] = OsmandSettings.isShowingOsmBugs(this); - selected[4] = OsmandSettings.isShowingFavorites(this); + selected[1] = OsmandSettings.isShowingPoiOverMap(settings); + selected[2] = OsmandSettings.isShowingTransportOverMap(settings); + selected[3] = OsmandSettings.isShowingOsmBugs(settings); + selected[4] = OsmandSettings.isShowingFavorites(settings); selected[5] = gpxLayer.isVisible(); selected[trafficInd] = trafficLayer.isVisible(); if(routeInfoInd != -1){ diff --git a/OsmAnd/src/net/osmand/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/activities/NavigatePointActivity.java index 012685c6f9..d3c940edce 100644 --- a/OsmAnd/src/net/osmand/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/activities/NavigatePointActivity.java @@ -48,7 +48,7 @@ public class NavigatePointActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - LatLon loc = OsmandSettings.getLastKnownMapLocation(this); + LatLon loc = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); setContentView(R.layout.navigate_point); setTitle(R.string.map_specify_point); initUI(loc.getLatitude(), loc.getLongitude()); diff --git a/OsmAnd/src/net/osmand/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/activities/OsmandApplication.java index 7914edf748..67410c448c 100644 --- a/OsmAnd/src/net/osmand/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/activities/OsmandApplication.java @@ -44,7 +44,7 @@ public class OsmandApplication extends Application { public void onCreate(){ super.onCreate(); - routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandApplication.this), OsmandApplication.this, player); + routingHelper = new RoutingHelper(OsmandSettings.getApplicationMode(OsmandSettings.getPrefs(OsmandApplication.this)), OsmandApplication.this, player); manager = new ResourceManager(this); uiHandler = new Handler(); startApplication(); @@ -104,7 +104,7 @@ public class OsmandApplication extends Application { List warnings = null; try { warnings = manager.reloadIndexes(startDialog); - String voice = OsmandSettings.getVoiceProvider(OsmandApplication.this); + String voice = OsmandSettings.getVoiceProvider(OsmandSettings.getPrefs(OsmandApplication.this)); player = null; if(voice != null){ startDialog.startTask(getString(R.string.voice_data_initializing), -1); diff --git a/OsmAnd/src/net/osmand/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/activities/RoutingHelper.java index e79ad2db40..80e6b4e2bb 100644 --- a/OsmAnd/src/net/osmand/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/activities/RoutingHelper.java @@ -434,7 +434,7 @@ public class RoutingHelper { } public void calculateRoute(final Location start, final LatLon end, final List currentGPXRoute){ - final RouteService service = OsmandSettings.getRouterService(context); + final RouteService service = OsmandSettings.getRouterService(OsmandSettings.getPrefs(context)); if(currentRunningJob == null){ // do not evaluate very often if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) { diff --git a/OsmAnd/src/net/osmand/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/activities/SavingTrackHelper.java index 93ac18e76b..13f65243ef 100644 --- a/OsmAnd/src/net/osmand/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/activities/SavingTrackHelper.java @@ -14,6 +14,7 @@ import net.osmand.GPXUtilities.TrkPt; 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; @@ -149,8 +150,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { return warnings; } - public void insertData(double lat, double lon, double alt, double speed, long time){ - if (time - lastTimeUpdated > OsmandSettings.getSavingTrackInterval(ctx)) { + public void insertData(double lat, double lon, double alt, double speed, long time, SharedPreferences settings){ + if (time - lastTimeUpdated > OsmandSettings.getSavingTrackInterval(settings)) { SQLiteDatabase db = getWritableDatabase(); if (db != null) { db.execSQL(updateScript, new Object[] { lat, lon, alt, speed, time }); diff --git a/OsmAnd/src/net/osmand/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/activities/SettingsActivity.java index ff12c2062f..bb181a1aa8 100644 --- a/OsmAnd/src/net/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/activities/SettingsActivity.java @@ -191,16 +191,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference for(BooleanPreference b : booleanPreferences){ b.getPref().setChecked(prefs.getBoolean(b.getId(), b.getDefValue())); } - userName.setText(OsmandSettings.getUserName(this)); - userPassword.setText(OsmandSettings.getUserPassword(this)); - useInternetToDownload.setChecked(OsmandSettings.isUsingInternetToDownloadTiles(this)); + userName.setText(OsmandSettings.getUserName(prefs)); + userPassword.setText(OsmandSettings.getUserPassword(prefs)); + 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(this)); + positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(prefs)); saveTrackInterval.setEntries(new String[]{ @@ -212,7 +212,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference resources.getString(R.string.interval_1_minute), resources.getString(R.string.interval_5_minutes)}); saveTrackInterval.setEntryValues(new String[]{"1", "2", "5", "15", "30", "60", "300"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(this)+""); //$NON-NLS-1$ + saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(prefs)+""); //$NON-NLS-1$ String[] ints = new String[]{"1", "2", "5", "8", "10", "15", "20", "25", "30", "40", "45", "60", "90" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ String[] intDescriptions = new String[ints.length]; @@ -221,7 +221,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } routeServiceInterval.setEntries(intDescriptions); routeServiceInterval.setEntryValues(ints); - routeServiceInterval.setValue(OsmandSettings.getServiceOffInterval(this)/60000+""); //$NON-NLS-1$ + routeServiceInterval.setValue(OsmandSettings.getServiceOffInterval(prefs)/60000+""); //$NON-NLS-1$ ints = new String[]{"15", "30", "45", "60", "90", "120", "180", "300", "600"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ intDescriptions = new String[ints.length]; @@ -230,17 +230,17 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } routeServiceWaitInterval.setEntries(intDescriptions); routeServiceWaitInterval.setEntryValues(ints); - routeServiceWaitInterval.setValue(OsmandSettings.getServiceOffWaitInterval(this)/1000+""); //$NON-NLS-1$ + routeServiceWaitInterval.setValue(OsmandSettings.getServiceOffWaitInterval(prefs)/1000+""); //$NON-NLS-1$ rotateMap.setEntries(new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}); rotateMap.setEntryValues(new String[]{OsmandSettings.ROTATE_MAP_NONE+"", OsmandSettings.ROTATE_MAP_BEARING+"", OsmandSettings.ROTATE_MAP_COMPASS+""}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - rotateMap.setValue(OsmandSettings.getRotateMap(this)+""); //$NON-NLS-1$ + rotateMap.setValue(OsmandSettings.getRotateMap(prefs)+""); //$NON-NLS-1$ routeServiceProvider.setEntries(new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)}); routeServiceProvider.setEntryValues(new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER}); - routeServiceProvider.setValue(OsmandSettings.getServiceOffProvider(this)); + routeServiceProvider.setValue(OsmandSettings.getServiceOffProvider(prefs)); - routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(this)); + routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(prefs)); mapScreenOrientation.setEntries(new String[]{ resources.getString(R.string.map_orientation_portrait), @@ -249,7 +249,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference }); mapScreenOrientation.setEntryValues(new String[]{ActivityInfo.SCREEN_ORIENTATION_PORTRAIT+"", //$NON-NLS-1$ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE+"", ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED+""}); //$NON-NLS-1$ //$NON-NLS-2$ - mapScreenOrientation.setValue(OsmandSettings.getMapOrientation(this)+""); //$NON-NLS-1$ + mapScreenOrientation.setValue(OsmandSettings.getMapOrientation(prefs)+""); //$NON-NLS-1$ ApplicationMode[] presets = ApplicationMode.values(); String[] values = new String[presets.length]; @@ -260,11 +260,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } applicationMode.setEntries(values); applicationMode.setEntryValues(valueEntries); - applicationMode.setValue(OsmandSettings.getApplicationMode(this).name()); + applicationMode.setValue(OsmandSettings.getApplicationMode(prefs).name()); String[] entries = new String[RouteService.values().length]; - String entry = OsmandSettings.getRouterService(this).getName(); + String entry = OsmandSettings.getRouterService(prefs).getName(); for(int i=0; i entriesMap = getTileSourceEntries(this); @@ -322,9 +322,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference tileSourcePreference.setEntries(entries); tileSourcePreference.setEntryValues(valueEntries); - String value = OsmandSettings.isUsingMapVectorData(this)? VECTOR_MAP : OsmandSettings.getMapTileSourceName(this); - String mapName = " " + (OsmandSettings.isUsingMapVectorData(this) ? getString(R.string.vector_data) : //$NON-NLS-1$ - OsmandSettings.getMapTileSourceName(this)); + String value = OsmandSettings.isUsingMapVectorData(prefs)? VECTOR_MAP : OsmandSettings.getMapTileSourceName(prefs); + String mapName = " " + (OsmandSettings.isUsingMapVectorData(prefs) ? getString(R.string.vector_data) : //$NON-NLS-1$ + OsmandSettings.getMapTileSourceName(prefs)); tileSourcePreference.setValue(value); String summary = tileSourcePreference.getSummary().toString(); if (summary.lastIndexOf(':') != -1) { @@ -432,11 +432,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference if ((Boolean) newValue) { ComponentName name = startService(serviceIntent); if (name == null) { - routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(this)); + routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(prefs)); } } else { if(!stopService(serviceIntent)){ - routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(this)); + routeServiceEnabled.setChecked(OsmandSettings.getServiceOffEnabled(prefs)); } } } else if (preference == routerPreference) { @@ -472,8 +472,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference if (summary.lastIndexOf(':') != -1) { summary = summary.substring(0, summary.lastIndexOf(':') + 1); } - summary += " " + (OsmandSettings.isUsingMapVectorData(this) ? getString(R.string.vector_data) : //$NON-NLS-1$ - OsmandSettings.getMapTileSourceName(this)); + summary += " " + (OsmandSettings.isUsingMapVectorData(prefs) ? getString(R.string.vector_data) : //$NON-NLS-1$ + OsmandSettings.getMapTileSourceName(prefs)); tileSourcePreference.setSummary(summary); } diff --git a/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java index 0cd3861afa..f13082c601 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchAddressActivity.java @@ -19,6 +19,7 @@ import net.osmand.osm.Way; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.view.Window; @@ -176,7 +177,7 @@ public class SearchAddressActivity extends Activity { LatLon l = null; String historyName = null; int zoom = 12; - boolean en = OsmandSettings.usingEnglishNames(this); + boolean en = OsmandSettings.usingEnglishNames(OsmandSettings.getPrefs(this)); if (street2 != null && street != null) { region.preloadWayNodes(street2); region.preloadWayNodes(street); @@ -296,27 +297,28 @@ public class SearchAddressActivity extends Activity { } public void loadData(){ + SharedPreferences prefs = OsmandSettings.getPrefs(this); if (region != null) { - if(region.useEnglishNames() != OsmandSettings.usingEnglishNames(this)){ - region.setUseEnglishNames(OsmandSettings.usingEnglishNames(this)); + if(region.useEnglishNames() != OsmandSettings.usingEnglishNames(prefs)){ + region.setUseEnglishNames(OsmandSettings.usingEnglishNames(prefs)); } - String postcodeStr = OsmandSettings.getLastSearchedPostcode(this); + String postcodeStr = OsmandSettings.getLastSearchedPostcode(prefs); if(postcodeStr != null){ postcode = region.getPostcode(postcodeStr); } else { - city = region.getCityById(OsmandSettings.getLastSearchedCity(SearchAddressActivity.this)); + city = region.getCityById(OsmandSettings.getLastSearchedCity(prefs)); } if (postcode != null || city != null) { MapObject o = postcode == null ? city : postcode; - street = region.getStreetByName(o, OsmandSettings.getLastSearchedStreet(SearchAddressActivity.this)); + street = region.getStreetByName(o, OsmandSettings.getLastSearchedStreet(prefs)); if (street != null) { - String str = OsmandSettings.getLastSearchedIntersectedStreet(SearchAddressActivity.this); + String str = OsmandSettings.getLastSearchedIntersectedStreet(prefs); radioBuilding = str == null; if(str != null){ street2 = region.getStreetByName(o, str); } else { - building = region.getBuildingByName(street, OsmandSettings.getLastSearchedBuilding(SearchAddressActivity.this)); + building = region.getBuildingByName(street, OsmandSettings.getLastSearchedBuilding(prefs)); } } } @@ -349,16 +351,16 @@ public class SearchAddressActivity extends Activity { @Override protected void onResume() { super.onResume(); - + SharedPreferences prefs = OsmandSettings.getPrefs(this); region = null; - String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(SearchAddressActivity.this); + String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(prefs); 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(this); - String postcode = OsmandSettings.getLastSearchedPostcode(this); + Long cityId = OsmandSettings.getLastSearchedCity(prefs); + String postcode = OsmandSettings.getLastSearchedPostcode(prefs); if (!region.areCitiesPreloaded()) { progressMsg = getString(R.string.loading_cities); } else if (postcode != null && !region.arePostcodesPreloaded()) { @@ -367,7 +369,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(this) != region.useEnglishNames()) { + } else if (OsmandSettings.usingEnglishNames(prefs) != region.useEnglishNames()) { progressMsg = getString(R.string.converting_names); } } diff --git a/OsmAnd/src/net/osmand/activities/search/SearchAddressOnlineActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchAddressOnlineActivity.java index ff068424a6..1dc3ac41ae 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchAddressOnlineActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchAddressOnlineActivity.java @@ -64,7 +64,7 @@ public class SearchAddressOnlineActivity extends ListActivity { searchPlaces(((EditText) findViewById(R.id.SearchText)).getText().toString()); } }); - location = OsmandSettings.getLastKnownMapLocation(this); + location = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); } protected void searchPlaces(final String search) { diff --git a/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java index ec70c1c57a..e2316cbec0 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchBuildingByNameActivity.java @@ -11,6 +11,7 @@ import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.PostCode; import net.osmand.data.Street; +import android.content.SharedPreferences; import android.os.Bundle; import android.widget.TextView; @@ -22,14 +23,15 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity av, View v, int pos, long id) { Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(pos); - String format = amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(v.getContext())); + String format = amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(settings)); if (amenity.getOpeningHours() != null) { format += "\n"+getString(R.string.opening_hours) + " : " + amenity.getOpeningHours(); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -448,10 +452,10 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId()); OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true); } - int z = OsmandSettings.getLastKnownMapZoom(this); + int z = OsmandSettings.getLastKnownMapZoom(settings); Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); OsmandSettings.setMapLocationToShow(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), - Math.max(16, z), getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(this))); //$NON-NLS-1$ + Math.max(16, z), getString(R.string.poi)+" : " + amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(settings))); //$NON-NLS-1$ Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class); startActivity(newIntent); } @@ -559,7 +563,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen Location.distanceBetween(l.getLatitude(), l.getLongitude(), location.getLatitude(), location.getLongitude(), mes); } - String str = amenity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this)); + String str = amenity.getStringWithoutType(OsmandSettings.usingEnglishNames(settings)); label.setText(str); int opened = -1; if (amenity.getOpeningHours() != null) { diff --git a/OsmAnd/src/net/osmand/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchPoiFilterActivity.java index e0bbae2a48..9bb5e3c79e 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchPoiFilterActivity.java +++ b/OsmAnd/src/net/osmand/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(this); + LatLon loc = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this)); latitude = loc.getLatitude(); longitude = loc.getLongitude(); } diff --git a/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java index a879514f76..162ddc8b50 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchStreet2ByNameActivity.java @@ -11,6 +11,7 @@ import net.osmand.data.City; import net.osmand.data.PostCode; import net.osmand.data.Street; import android.app.ProgressDialog; +import android.content.SharedPreferences; import android.os.Bundle; import android.widget.TextView; @@ -24,17 +25,18 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity stops = route.getDirection() ? route.getRoute().getForwardStops() : route.getRoute().getBackwardStops(); - boolean en = OsmandSettings.usingEnglishNames(this); + boolean en = OsmandSettings.usingEnglishNames(settings); String info = getInformation(route, stops, routeInd, false); StringBuilder txt = new StringBuilder(300); @@ -455,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(SearchTransportActivity.this))); //$NON-NLS-1$ + labelW.append("]\n").append(route.getName(OsmandSettings.usingEnglishNames(settings))); //$NON-NLS-1$ label.setText(labelW.toString()); // TODO icons if (locationToGo != null && stop.getDistToLocation() < 400) { @@ -527,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(SearchTransportActivity.this); + boolean en = OsmandSettings.usingEnglishNames(settings); 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/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/render/MapRenderRepositories.java index 80071df132..9c866d316f 100644 --- a/OsmAnd/src/net/osmand/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/render/MapRenderRepositories.java @@ -411,7 +411,7 @@ public class MapRenderRepositories { return; } - Bitmap bmp = renderer.generateNewBitmap(currentRenderingContext, cObjects, OsmandSettings.usingEnglishNames(context)); + Bitmap bmp = renderer.generateNewBitmap(currentRenderingContext, cObjects, OsmandSettings.usingEnglishNames(OsmandSettings.getPrefs(context))); if(checkWhetherInterrupted()){ currentRenderingContext = null; return; diff --git a/OsmAnd/src/net/osmand/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/views/MapInfoLayer.java index 50604ba047..f1f553d1c5 100644 --- a/OsmAnd/src/net/osmand/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/views/MapInfoLayer.java @@ -172,7 +172,7 @@ public class MapInfoLayer implements OsmandMapLayer { pathTransform.postTranslate(boundsForMiniRoute.left, boundsForMiniRoute.top); - showArrivalTime = OsmandSettings.isShowingArrivalTime(view.getContext()); + showArrivalTime = OsmandSettings.isShowingArrivalTime(view.getSettings()); } private void scaleRect(RectF r){ @@ -574,7 +574,7 @@ public class MapInfoLayer implements OsmandMapLayer { } if(cachedDistString != null && boundsForDist.contains(point.x, point.y)){ AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); - LatLon pointToNavigate = OsmandSettings.getPointToNavigate(view.getContext()); + LatLon pointToNavigate = OsmandSettings.getPointToNavigate(view.getSettings()); 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/views/OsmBugsLayer.java b/OsmAnd/src/net/osmand/views/OsmBugsLayer.java index e38176a76d..e6dd6d3695 100644 --- a/OsmAnd/src/net/osmand/views/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/views/OsmBugsLayer.java @@ -319,7 +319,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe builder.setTitle(R.string.osb_add_dialog_title); final View view = layoutInflater.inflate(R.layout.open_bug, null); builder.setView(view); - ((EditText)view.findViewById(R.id.AuthorName)).setText(OsmandSettings.getUserNameForOsmBug(ctx)); + ((EditText)view.findViewById(R.id.AuthorName)).setText(OsmandSettings.getUserNameForOsmBug(OsmandSettings.getPrefs(ctx))); builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() { @Override @@ -349,7 +349,7 @@ 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(ctx)); + ((EditText)view.findViewById(R.id.AuthorName)).setText(OsmandSettings.getUserNameForOsmBug(OsmandSettings.getPrefs(ctx))); builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setPositiveButton(R.string.osb_comment_dialog_add_button, new DialogInterface.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java index 982053c05f..e2104e27a6 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java @@ -22,6 +22,7 @@ import net.osmand.views.MultiTouchSupport.MultiTouchZoomListener; import org.apache.commons.logging.Log; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -452,13 +453,21 @@ 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; + + public SharedPreferences getSettings(){ + if(settings == null){ + settings = OsmandSettings.getPrefs(getContext()); + } + return settings; + } private void refreshMapInternal() { if (handler.hasMessages(1)) { return; } - boolean useInternet = OsmandSettings.isUsingInternetToDownloadTiles(getContext()); + boolean useInternet = OsmandSettings.isUsingInternetToDownloadTiles(getSettings()); if (useInternet) { MapTileDownloader.getInstance().refuseAllPreviousRequests(); } @@ -492,7 +501,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall ResourceManager mgr = getApplication().getResourceManager(); useInternet = useInternet && OsmandSettings.isInternetConnectionAvailable(getContext()) && map.couldBeDownloadedFromInternet(); - int maxLevel = Math.min(OsmandSettings.getMaximumLevelToDownloadTile(getContext()), map.getMaximumZoomSupported()); + int maxLevel = Math.min(OsmandSettings.getMaximumLevelToDownloadTile(getSettings()), map.getMaximumZoomSupported()); for (int i = 0; i < width; i++) { diff --git a/OsmAnd/src/net/osmand/views/POIMapLayer.java b/OsmAnd/src/net/osmand/views/POIMapLayer.java index eeedb96131..21fce8a809 100644 --- a/OsmAnd/src/net/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/views/POIMapLayer.java @@ -76,7 +76,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen public boolean onTouchEvent(PointF point) { Amenity n = getAmenityFromPoint(point); if(n != null){ - String format = n.getSimpleFormat(OsmandSettings.usingEnglishNames(view.getContext())); + String format = n.getSimpleFormat(OsmandSettings.usingEnglishNames(view.getSettings())); if(n.getOpeningHours() != null){ format += "\n" + view.getContext().getString(R.string.opening_hours) +" : "+ n.getOpeningHours(); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -164,7 +164,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen @Override public String getObjectDescription(Object o) { if(o instanceof Amenity){ - return ((Amenity)o).getSimpleFormat(OsmandSettings.usingEnglishNames(view.getContext())); + return ((Amenity)o).getSimpleFormat(OsmandSettings.usingEnglishNames(view.getSettings())); } return null; } diff --git a/OsmAnd/src/net/osmand/views/TransportInfoLayer.java b/OsmAnd/src/net/osmand/views/TransportInfoLayer.java index 10edb6640b..11f595d333 100644 --- a/OsmAnd/src/net/osmand/views/TransportInfoLayer.java +++ b/OsmAnd/src/net/osmand/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.getContext())) + " : " + //$NON-NLS-1$ + Toast.makeText(view.getContext(), st.getName(OsmandSettings.usingEnglishNames(view.getSettings())) + " : " + //$NON-NLS-1$ route.getType() + " " + route.getRef() //$NON-NLS-1$ , Toast.LENGTH_LONG).show(); return true; diff --git a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java index 369b376062..be4188b275 100644 --- a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java @@ -80,14 +80,14 @@ 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.getContext()))); //$NON-NLS-1$ + text.append(view.getContext().getString(R.string.transport_Stop)).append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getSettings()))); //$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()); if(!reps.isEmpty()){ List l; if(!useName){ l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$ - } else if(OsmandSettings.usingEnglishNames(view.getContext())){ + } else if(OsmandSettings.usingEnglishNames(view.getSettings())){ 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/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/voice/CommandPlayer.java index 53b837f033..d2f7b15f77 100644 --- a/OsmAnd/src/net/osmand/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/voice/CommandPlayer.java @@ -77,7 +77,7 @@ public class CommandPlayer { } public String init(){ - String voiceProvider = OsmandSettings.getVoiceProvider(ctx); + String voiceProvider = OsmandSettings.getVoiceProvider(OsmandSettings.getPrefs(ctx)); prologSystem.clearTheory(); voiceDir = null; if(voiceProvider != null){