Merge branch 'customProfiles400'

This commit is contained in:
Victor Shcherb 2011-05-14 17:20:25 +02:00
commit 6df0671597
43 changed files with 1396 additions and 1571 deletions

View file

@ -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);

View file

@ -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.getSharedPreferences(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);

File diff suppressed because it is too large Load diff

View file

@ -101,7 +101,7 @@ public class ResourceManager {
}
public void resetStoreDirectory() {
dirWithTiles = OsmandSettings.extendOsmandPath(context, TILES_PATH);
dirWithTiles = context.getSettings().extendOsmandPath(TILES_PATH);
dirWithTiles.mkdirs();
}
@ -352,7 +352,7 @@ public class ResourceManager {
}
private void initRenderers(IProgress progress) {
File file = OsmandSettings.extendOsmandPath(context, APP_DIR + IndexConstants.RENDERERS_DIR);
File file = context.getSettings().extendOsmandPath(APP_DIR + IndexConstants.RENDERERS_DIR);
file.mkdirs();
Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
if (file.exists() && file.canRead()) {
@ -363,18 +363,18 @@ public class ResourceManager {
}
}
}
RendererRegistry.getRegistry().setExternalRenderers(externalRenderers);
String r = OsmandSettings.getVectorRenderer(OsmandSettings.getPrefs(context));
context.getRendererRegistry().setExternalRenderers(externalRenderers);
String r = context.getSettings().RENDERER.get();
if(r != null){
BaseOsmandRender obj = RendererRegistry.getRegistry().getRenderer(r);
BaseOsmandRender obj = context.getRendererRegistry().getRenderer(r);
if(obj != null){
RendererRegistry.getRegistry().setCurrentSelectedRender(obj);
context.getRendererRegistry().setCurrentSelectedRender(obj);
}
}
}
public List<String> indexingMaps(final IProgress progress) {
File file = OsmandSettings.extendOsmandPath(context, MAPS_PATH);
File file = context.getSettings().extendOsmandPath(MAPS_PATH);
file.mkdirs();
List<String> warnings = new ArrayList<String>();
renderer.clearAllResources();
@ -431,7 +431,7 @@ public class ResourceManager {
// POI INDEX //
public List<String> indexingPoi(final IProgress progress) {
File file = OsmandSettings.extendOsmandPath(context, POI_PATH);
File file = context.getSettings().extendOsmandPath(POI_PATH);
file.mkdirs();
List<String> warnings = new ArrayList<String>();
closeAmenities();

View file

@ -0,0 +1,26 @@
package net.osmand.plus.activities;
import net.osmand.plus.R;
import android.content.Context;
public enum ApplicationMode {
/*
* DEFAULT("Default"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian");
*/
DEFAULT(R.string.app_mode_default),
CAR(R.string.app_mode_car),
BICYCLE(R.string.app_mode_bicycle),
PEDESTRIAN(R.string.app_mode_pedestrian);
private final int key;
ApplicationMode(int key) {
this.key = key;
}
public static String toHumanString(ApplicationMode m, Context ctx) {
return ctx.getResources().getString(m.key);
}
}

View file

@ -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.getPrefs(this).edit().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 {

View file

@ -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;

View file

@ -308,7 +308,7 @@ public class DownloadIndexActivity extends ListActivity {
private List<String> listAlreadyDownloadedWithAlternatives() {
List<String> files = new ArrayList<String>();
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;

View file

@ -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);

View file

@ -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();

View file

@ -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<FavouritePoint>(){
@ -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));

View file

@ -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);
@ -87,10 +87,10 @@ public class MainMenuActivity extends Activity {
});
builder.show();
}
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit();
} else {
if (size > 0) {
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
getPreferences(MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
}
}
}
@ -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();

View file

@ -31,7 +31,6 @@ import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchPoiFilterActivity;
import net.osmand.plus.activities.search.SearchTransportActivity;
@ -64,8 +63,6 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.hardware.Sensor;
@ -158,10 +155,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(){
@ -179,7 +176,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = OsmandSettings.getPrefs(this);
settings = ((OsmandApplication) getApplication()).getSettings();
// for voice navigation
setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -193,7 +190,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();
}
}
@ -273,7 +270,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
@ -282,9 +279,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);
@ -298,7 +295,9 @@ 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);
settings.APPLICATION_MODE.set(ApplicationMode.DEFAULT);
updateApplicationModeSettings();
routingHelper.setFinalLocation(null);
mapView.refreshMap();
}
@ -309,8 +308,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
navigationLayer.setPointToNavigate(pointToNavigate);
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
if(prefs == null || !prefs.contains(OsmandSettings.LAST_KNOWN_MAP_LAT)){
if(!settings.isLastKnownMapLocation()){
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
Location location = null;
try {
@ -345,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);
}
}
@ -358,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);
}
}
@ -411,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);
@ -482,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();
@ -530,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);
}
@ -543,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();
@ -588,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(settings);
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);
}
@ -728,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()){
@ -805,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();
}
@ -821,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();
}
@ -836,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);
@ -863,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());
}
@ -876,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 latLon = OsmandSettings.getAndClearMapLocationToShow(settings);
LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
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);
}
@ -947,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() {
@ -999,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);
@ -1071,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);
@ -1096,7 +1094,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
return ApplicationMode.values()[i];
}
}
return OsmandSettings.getApplicationMode(settings);
return settings.getApplicationMode();
}
@ -1112,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;
@ -1158,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);
}
@ -1169,12 +1167,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
public void onClick(DialogInterface dialog, int which) {
ApplicationMode mode = getAppMode(buttons);
// change global settings
ApplicationMode old = OsmandSettings.getApplicationMode(settings);
if (old != mode) {
Editor edit = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_WRITEABLE).edit();
edit.putString(OsmandSettings.APPLICATION_MODE, mode.name());
SettingsActivity.setAppMode(mode, edit, (OsmandApplication) getApplication(), old);
edit.commit();
boolean changed = settings.APPLICATION_MODE.set(mode);
if (changed) {
updateApplicationModeSettings();
mapView.refreshMap();
}
@ -1186,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);
@ -1235,15 +1229,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
try {
double lt = Double.parseDouble(lat);
double ln = Double.parseDouble(lon);
SharedPreferences prefs = OsmandSettings.getSharedPreferences(this);
Editor edit = prefs.edit();
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) {
}
}
@ -1273,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){
@ -1298,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();
@ -1318,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();
@ -1329,7 +1319,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private void useGPXFileLayer(final boolean useRouting, final LatLon endForRouting) {
final List<String> list = new ArrayList<String>();
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) {
@ -1389,7 +1379,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
}
});
} else {
OsmandSettings.setShowingFavorites(MapActivity.this, true);
settings.SHOW_FAVORITES.set(true);
List<FavouritePoint> pts = new ArrayList<FavouritePoint>();
for(WptPt p : res.wayPoints){
FavouritePoint pt = new FavouritePoint();
@ -1442,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);
@ -1492,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();
}
@ -1503,7 +1493,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
}
private void selectMapLayer(){
Map<String, String> entriesMap = SettingsActivity.getTileSourceEntries(this);
Map<String, String> entriesMap = settings.getTileSourceEntries();
Builder builder = new AlertDialog.Builder(this);
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
String[] items = new String[entriesMap.size() + 1];
@ -1515,20 +1505,18 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
builder.setItems(items, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
Editor edit = OsmandSettings.getWriteableEditor(MapActivity.this);
if(which == 0){
MapRenderRepositories r = ((OsmandApplication)getApplication()).getResourceManager().getRenderer();
if(r.isEmpty()){
Toast.makeText(MapActivity.this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
return;
} else {
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, true);
settings.setUsingMapVectorData(true);
}
} else {
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, false);
edit.putString(OsmandSettings.MAP_TILE_SOURCES, keys.get(which - 1));
settings.setMapTileSource(keys.get(which - 1));
settings.setUsingMapVectorData(false);
}
edit.commit();
updateMapSource();
}

View file

@ -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();

View file

@ -18,6 +18,7 @@ import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.voice.CommandPlayer;
import android.app.AlertDialog;
import android.app.Application;
@ -26,7 +27,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 +41,10 @@ public class OsmandApplication extends Application {
RoutingHelper routingHelper = null;
FavouritesDbHelper favorites = null;
CommandPlayer player = null;
OsmandSettings osmandSettings;
DayNightHelper daynightHelper;
NavigationService navigationService;
RendererRegistry rendererRegistry;
// start variables
@ -48,22 +52,31 @@ public class OsmandApplication extends Application {
private List<String> startingWarnings;
private ProgressDialog progressDlg;
private Handler uiHandler;
private DayNightHelper daynightHelper;
private NavigationService navigationService;
private boolean applicationInitializing = false;
private Locale prefferedLocale = null;
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();
rendererRegistry = new RendererRegistry();
checkPrefferedLocale();
startApplication();
}
public RendererRegistry getRendererRegistry() {
return rendererRegistry;
}
public OsmandSettings getSettings() {
return osmandSettings;
}
public PoiFiltersHelper getPoiFilters() {
if(poiFilters == null){
poiFilters = new PoiFiltersHelper(this);
@ -103,9 +116,8 @@ public class OsmandApplication extends Application {
}
public void checkPrefferedLocale() {
SharedPreferences settings = OsmandSettings.getSharedPreferences(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 +156,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 +203,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 +300,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);

View file

@ -25,7 +25,6 @@ import net.osmand.binary.BinaryRouteDataReader.RoutingContext;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.plus.R;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo;
import net.osmand.plus.activities.RoutingHelper.TurnType;
import net.osmand.plus.render.MapRenderRepositories;

View file

@ -10,7 +10,6 @@ import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.activities.RouteProvider.RouteCalculationResult;
import net.osmand.plus.activities.RouteProvider.RouteService;
import net.osmand.plus.voice.CommandPlayer;
@ -61,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);
}
@ -139,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
@ -426,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));
@ -439,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

View file

@ -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<String> saveDataToGpx(){
SQLiteDatabase db = getReadableDatabase();
List<String> warnings = new ArrayList<String>();
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 });

View file

@ -1,30 +1,23 @@
package net.osmand.plus.activities;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashMap;
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;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.OsmandSettings.DayNightMode;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.activities.RouteProvider.RouteService;
import net.osmand.plus.render.BaseOsmandRender;
import net.osmand.plus.render.RendererRegistry;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
@ -34,11 +27,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@ -54,142 +44,210 @@ 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;
private Preference saveCurrentTrack;
private Preference reloadIndexes;
private Preference downloadIndexes;
private ListPreference applicationMode;
private ListPreference daynightMode;
private ListPreference saveTrackInterval;
private ListPreference rotateMap;
private EditTextPreference applicationDir;
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 BroadcastReceiver broadcastReceiver;
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<String, Preference> screenPreferences = new LinkedHashMap<String, Preference>();
private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
private Map<String, OsmandPreference<?>> listPreferences = new LinkedHashMap<String, OsmandPreference<?>>();
private Map<String, OsmandPreference<String>> editTextPreferences = new LinkedHashMap<String, OsmandPreference<String>>();
private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>();
private void registerBooleanPreference(OsmandPreference<Boolean> b, PreferenceScreen screen){
CheckBoxPreference p = (CheckBoxPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
booleanPreferences.put(b.getId(), b);
}
private <T> void registerListPreference(OsmandPreference<T> b, PreferenceScreen screen, String[] names, T[] values){
ListPreference p = (ListPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this);
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
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<names.length; i++){
vals.put(names[i], values[i]);
}
}
private void registerEditTextPreference(OsmandPreference<String> b, PreferenceScreen screen){
EditTextPreference p = (EditTextPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
editTextPreferences.put(b.getId(), b);
}
private void registerTimeListPreference(OsmandPreference<Integer> b, PreferenceScreen screen, int[] seconds, int[] minutes, int coeff){
int minutesLength = minutes == null? 0 : minutes.length;
int secondsLength = seconds == null? 0 : seconds.length;
Integer[] ints = new Integer[secondsLength + minutesLength];
String[] intDescriptions = new String[ints.length];
for (int i = 0; i < secondsLength; i++) {
ints[i] = seconds[i] * coeff;
intDescriptions[i] = seconds[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
}
for (int i = 0; i < minutesLength; i++) {
ints[secondsLength + i] = (minutes[i] * 60) * coeff;
intDescriptions[secondsLength + i] = minutes[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
}
registerListPreference(b, screen, intDescriptions, ints);
}
private Set<String> getVoiceFiles(){
// read available voice data
File extStorage = osmandSettings.extendOsmandPath(ResourceManager.VOICE_PATH);
Set<String> setFiles = new LinkedHashSet<String>();
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);
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);
registerEditTextPreference(osmandSettings.USER_NAME, screen);
registerEditTextPreference(osmandSettings.USER_PASSWORD, screen);
// 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<entries.length; i++){
entries[i] = DayNightMode.values()[i].toHumanString(this);
}
registerListPreference(osmandSettings.DAYNIGHT_MODE, screen, entries,DayNightMode.values());
useInternetToDownload =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_INTERNET_TO_DOWNLOAD_TILES);
useInternetToDownload.setOnPreferenceChangeListener(this);
entries = new String[MetricsConstants.values().length];
for(int i=0; i<entries.length; i++){
entries[i] = MetricsConstants.values()[i].toHumanString(this);
}
registerListPreference(osmandSettings.METRIC_SYSTEM, screen, entries, MetricsConstants.values());
//getResources().getAssets().getLocales();
entrieValues = new String[] { "", "en", "cs", "de", "es", "fr", "hu", "it", "pt", "ru", "sk" };
entries = new String[entrieValues.length];
entries[0] = getString(R.string.system_locale);
for (int i = 1; i < entries.length; i++) {
entries[i] = entrieValues[i];
}
registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);
Set<String> 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, entrieValues);
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<entries.length; i++){
entries[i] = RouteService.values()[i].getName();
}
registerListPreference(osmandSettings.ROUTER_SERVICE, screen, entries, RouteService.values());
entries = new String[]{getString(R.string.gps_provider), getString(R.string.network_provider)};
entrieValues = new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER};
registerListPreference(osmandSettings.SERVICE_OFF_PROVIDER, screen, entries, entrieValues);
registerTimeListPreference(osmandSettings.SAVE_TRACK_INTERVAL, screen, new int[]{1, 2, 3, 5, 10, 15, 20, 30}, new int[]{1, 2, 3, 5}, 1);
registerTimeListPreference(osmandSettings.SERVICE_OFF_INTERVAL, screen,
new int[]{0, 30, 45, 60}, new int[]{2, 3, 5, 8, 10, 15, 20, 30, 40, 50, 70, 90}, 1000);
registerTimeListPreference(osmandSettings.SERVICE_OFF_WAIT_INTERVAL, screen,
new int[]{15, 30, 45, 60, 90}, new int[]{2, 3, 5, 10}, 1000);
entries = new String[ApplicationMode.values().length];
for(int i=0; i<entries.length; i++){
entries[i] = ApplicationMode.toHumanString(ApplicationMode.values()[i], this);
}
registerListPreference(osmandSettings.APPLICATION_MODE, screen, entries, ApplicationMode.values());
Collection<String> rendererNames = getMyApplication().getRendererRegistry().getRendererNames();
entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
registerListPreference(osmandSettings.RENDERER, screen, entries, entries);
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
tileSourcePreference.setOnPreferenceChangeListener(this);
reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES);
reloadIndexes.setOnPreferenceClickListener(this);
downloadIndexes =(Preference) screen.findPreference(OsmandSettings.DOWNLOAD_INDEXES);
downloadIndexes.setOnPreferenceClickListener(this);
saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK);
saveCurrentTrack.setOnPreferenceClickListener(this);
userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME);
userName.setOnPreferenceChangeListener(this);
userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD);
userPassword.setOnPreferenceChangeListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
applicationDir.setOnPreferenceChangeListener(this);
applicationMode =(ListPreference) screen.findPreference(OsmandSettings.APPLICATION_MODE);
applicationMode.setOnPreferenceChangeListener(this);
daynightMode =(ListPreference) screen.findPreference(OsmandSettings.DAYNIGHT_MODE);
daynightMode.setOnPreferenceChangeListener(this);
rotateMap =(ListPreference) screen.findPreference(OsmandSettings.ROTATE_MAP);
rotateMap.setOnPreferenceChangeListener(this);
saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL);
saveTrackInterval.setOnPreferenceChangeListener(this);
positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP);
positionOnMap.setOnPreferenceChangeListener(this);
mapScreenOrientation = (ListPreference) screen.findPreference(OsmandSettings.MAP_SCREEN_ORIENTATION);
mapScreenOrientation.setOnPreferenceChangeListener(this);
maxLevelToDownload = (ListPreference) screen.findPreference(OsmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE);
maxLevelToDownload.setOnPreferenceChangeListener(this);
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
tileSourcePreference.setOnPreferenceChangeListener(this);
routerPreference = (ListPreference) screen.findPreference(OsmandSettings.ROUTER_SERVICE);
routerPreference.setOnPreferenceChangeListener(this);
voicePreference = (ListPreference) screen.findPreference(OsmandSettings.VOICE_PROVIDER);
voicePreference.setOnPreferenceChangeListener(this);
metricPreference = (ListPreference) screen.findPreference(OsmandSettings.DEFAULT_METRIC_SYSTEM);
metricPreference.setOnPreferenceChangeListener(this);
preferredLocale = (ListPreference) screen.findPreference(OsmandSettings.PREFERRED_LOCALE);
preferredLocale.setOnPreferenceChangeListener(this);
rendererPreference =(ListPreference) screen.findPreference(OsmandSettings.RENDERER);
rendererPreference.setOnPreferenceChangeListener(this);
routeServiceInterval =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_INTERVAL);
routeServiceInterval.setOnPreferenceChangeListener(this);
routeServiceWaitInterval =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL);
routeServiceWaitInterval.setOnPreferenceChangeListener(this);
routeServiceProvider =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_PROVIDER);
routeServiceProvider.setOnPreferenceChangeListener(this);
routeServiceEnabled =(CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
routeServiceEnabled.setOnPreferenceChangeListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
applicationDir.setOnPreferenceChangeListener(this);
broadcastReceiver = new BroadcastReceiver(){
@ -202,8 +260,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.OSMAND_STOP_SERVICE_ACTION));
}
private void updateApplicationDirSummary() {
String storageDir = OsmandSettings.getExternalStorageDirectory(getApplicationContext()).getAbsolutePath();
private void updateApplicationDirTextAndSummary() {
String storageDir = osmandSettings.getExternalStorageDirectory().getAbsolutePath();
applicationDir.setText(storageDir);
applicationDir.setSummary(storageDir);
}
@ -221,160 +279,39 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
private void fillTime(ListPreference component, int[] seconds, int[] minutes, int currentSeconds){
int minutesLength = minutes == null? 0 : minutes.length;
int secondsLength = seconds == null? 0 : seconds.length;
String[] ints = new String[secondsLength + minutesLength];
String[] intDescriptions = new String[ints.length];
for (int i = 0; i < secondsLength; i++) {
ints[i] = seconds[i] + "";
intDescriptions[i] = ints[i] + " " + getString(R.string.int_seconds); //$NON-NLS-1$
}
for (int i = 0; i < minutesLength; i++) {
ints[secondsLength + i] = (minutes[i] * 60) + "";
intDescriptions[secondsLength + i] = minutes[i] + " " + getString(R.string.int_min); //$NON-NLS-1$
}
fill(component, intDescriptions, ints, currentSeconds+"");
}
public void updateAllSettings(){
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
for(BooleanPreference b : booleanPreferences){
b.getPref().setChecked(prefs.getBoolean(b.getId(), b.getDefValue()));
for(OsmandPreference<Boolean> b : booleanPreferences.values()){
CheckBoxPreference pref = (CheckBoxPreference) screenPreferences.get(b.getId());
pref.setChecked(b.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$
fillTime(routeServiceInterval, new int[]{0, 30, 45, 60}, new int[]{2, 3, 5, 8, 10, 15, 20, 30, 40, 50, 70, 90}, OsmandSettings.getServiceOffInterval(prefs)/1000); //$NON-NLS-1$
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));
for(OsmandPreference<?> p : listPreferences.values()){
ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
Map<String, ?> prefValues = listPrefValues.get(p.getId());
String[] entryValues = new String[prefValues.size()];
String[] entries = new String[prefValues.size()];
int i = 0;
for(Entry<String, ?> 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() + "");
}
for(OsmandPreference<String> s : editTextPreferences.values()){
EditTextPreference pref = (EditTextPreference) screenPreferences.get(s.getId());
pref.setText(s.get());
}
// Specific properties
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];
String[] values = new String[presets.length];
for(int i=0; i<presets.length; i++){
names[i] = ApplicationMode.toHumanString(presets[i], this);
values[i] = presets[i].name();
}
fill(applicationMode, names, values, OsmandSettings.getApplicationMode(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<String> setFiles = new LinkedHashSet<String>();
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<String> rendererNames = RendererRegistry.getRegistry().getRendererNames();
entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]);
rendererPreference.setEntries(entries);
rendererPreference.setEntryValues(entries);
if(rendererNames.contains(vectorRenderer)){
rendererPreference.setValue(vectorRenderer);
} else {
rendererPreference.setValueIndex(0);
}
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<String, String> entriesMap = getTileSourceEntries(this);
entries = new String[entriesMap.size() + 1];
values = new String[entriesMap.size() + 1];
Map<String, String> entriesMap = osmandSettings.getTileSourceEntries();
String[] entries = new String[entriesMap.size() + 1];
String[] values = new String[entriesMap.size() + 1];
values[0] = VECTOR_MAP;
entries[0] = getString(R.string.vector_data);
int ki = 1;
@ -383,19 +320,23 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
values[ki] = es.getKey();
ki++;
}
String value = OsmandSettings.isUsingMapVectorData(prefs)? VECTOR_MAP : OsmandSettings.getMapTileSourceName(prefs);
String value = osmandSettings.isUsingMapVectorData()? VECTOR_MAP : osmandSettings.getMapTileSourceName();
fill(tileSourcePreference, entries, values, value);
String mapName = " " + (OsmandSettings.isUsingMapVectorData(prefs) ? getString(R.string.vector_data) : //$NON-NLS-1$
OsmandSettings.getMapTileSourceName(prefs));
updateTileSourceSummary();
updateApplicationDirTextAndSummary();
}
private void updateTileSourceSummary() {
String mapName = " " + (osmandSettings.isUsingMapVectorData() ? getString(R.string.vector_data) : //$NON-NLS-1$
osmandSettings.getMapTileSourceName());
String summary = tileSourcePreference.getSummary().toString();
if (summary.lastIndexOf(':') != -1) {
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
tileSourcePreference.setSummary(summary + mapName);
updateApplicationDirSummary();
}
}
private void fill(ListPreference component, String[] list, String[] values, String selected) {
component.setEntries(list);
@ -403,108 +344,49 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
component.setValue(selected);
}
public static Map<String, String> getTileSourceEntries(Context ctx){
Map<String, String> map = new LinkedHashMap<String, String>();
File dir = OsmandSettings.extendOsmandPath(ctx, ResourceManager.TILES_PATH);
if (dir != null && dir.canRead()) {
File[] files = dir.listFiles();
Arrays.sort(files, new Comparator<File>(){
@Override
public int compare(File object1, File object2) {
if(object1.lastModified() > object2.lastModified()){
return -1;
} else if(object1.lastModified() == object2.lastModified()){
return 0;
}
return 1;
}
});
if (files != null) {
for (File f : files) {
if (f.getName().endsWith(SQLiteTileSource.EXT)) {
String n = f.getName();
map.put(f.getName(), n.substring(0, n.lastIndexOf('.')));
} else if (f.isDirectory() && !f.getName().equals(ResourceManager.TEMP_SOURCE_TO_LOAD)) {
map.put(f.getName(), f.getName());
}
}
}
}
for(TileSourceTemplate l : TileSourceManager.getKnownSourceTemplates()){
map.put(l.getName(), l.getName());
}
return map;
}
@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit();
// handle boolean prefences
BooleanPreference p = null;
for(BooleanPreference b : booleanPreferences){
if(b.getPref() == preference){
p = b;
break;
}
}
if(p != null){
edit.putBoolean(p.getId(), (Boolean)newValue);
if(p.getId() == OsmandSettings.SHOW_POI_OVER_MAP && ((Boolean) newValue)){
edit.putString(OsmandSettings.SELECTED_POI_FILTER_FOR_MAP, PoiFiltersHelper.getOsmDefinedFilterId(null));
}
OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey());
OsmandPreference<Object> listPref = (OsmandPreference<Object>) listPreferences.get(preference.getKey());
OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
if(boolPref != null){
boolPref.set((Boolean)newValue);
} else if (editPref != null) {
editPref.set((String) newValue);
} else if (listPref != null) {
int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
CharSequence entry = ((ListPreference) preference).getEntries()[ind];
Map<String, ?> map = listPrefValues.get(preference.getKey());
Object obj = map.get(entry);
boolean changed = listPref.set(obj);
edit.commit();
} else if(preference == applicationMode){
ApplicationMode old = OsmandSettings.getApplicationMode(prefs);
edit.putString(OsmandSettings.APPLICATION_MODE, (String) newValue);
setAppMode(ApplicationMode.valueOf(newValue.toString()), edit, getMyApplication(), old);
edit.commit();
updateAllSettings();
} else if(preference == daynightMode){
edit.putString(OsmandSettings.DAYNIGHT_MODE, (String) newValue);
getMyApplication().getDaynightHelper().setDayNightMode(DayNightMode.valueOf(newValue.toString()));
edit.commit();
} else if(preference == mapScreenOrientation){
edit.putInt(OsmandSettings.MAP_SCREEN_ORIENTATION, Integer.parseInt(newValue.toString()));
edit.commit();
} else if(preference == saveTrackInterval){
edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, Integer.parseInt(newValue.toString()));
edit.commit();
} else if(preference == userPassword){
edit.putString(OsmandSettings.USER_PASSWORD, (String) newValue);
edit.commit();
} else if(preference == useInternetToDownload){
OsmandSettings.setUseInternetToDownloadTiles((Boolean) newValue, edit);
edit.commit();
} else if(preference == userName){
edit.putString(OsmandSettings.USER_NAME, (String) newValue);
edit.commit();
// Specific actions after list preference changed
if (changed) {
if (listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())) {
getMyApplication().initCommandPlayer();
} else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
updateAllSettings();
} else if (listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())) {
// restart application to update locale
getMyApplication().checkPrefferedLocale();
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
if (listPref.getId().equals(osmandSettings.RENDERER.getId())) {
if(changed){
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
}
} else if(preference == applicationDir){
warnAboutChangingStorage(edit, (String) newValue);
warnAboutChangingStorage((String) newValue);
return false;
} else if(preference == positionOnMap){
edit.putInt(OsmandSettings.POSITION_ON_MAP, positionOnMap.findIndexOfValue((String) newValue));
edit.commit();
} else if (preference == maxLevelToDownload) {
edit.putInt(OsmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE, Integer.parseInt((String) newValue));
edit.commit();
} else if (preference == routeServiceInterval) {
edit.putInt(OsmandSettings.SERVICE_OFF_INTERVAL, Integer.parseInt((String) newValue) * 1000);
edit.commit();
} else if (preference == routeServiceWaitInterval) {
edit.putInt(OsmandSettings.SERVICE_OFF_WAIT_INTERVAL, Integer.parseInt((String) newValue) * 1000);
edit.commit();
} else if (preference == rotateMap) {
edit.putInt(OsmandSettings.ROTATE_MAP, Integer.parseInt((String) newValue));
edit.commit();
} else if (preference == routeServiceProvider) {
edit.putString(OsmandSettings.SERVICE_OFF_PROVIDER, (String) newValue);
edit.commit();
} else if (preference == routeServiceEnabled) {
Intent serviceIntent = new Intent(this, NavigationService.class);
if ((Boolean) newValue) {
@ -517,70 +399,19 @@ 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){
edit.putInt(OsmandSettings.ROUTER_SERVICE, s.ordinal());
}
edit.commit();
} else if (preference == rendererPreference) {
BaseOsmandRender loaded = RendererRegistry.getRegistry().getRenderer((String) newValue);
if(loaded == null){
Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
} else {
RendererRegistry.getRegistry().setCurrentSelectedRender(loaded);
edit.putString(OsmandSettings.RENDERER, (String) newValue);
Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
getMyApplication().getResourceManager().getRenderer().clearCache();
}
edit.commit();
} else if (preference == voicePreference) {
int i = voicePreference.findIndexOfValue((String) newValue);
if (i == 0) {
edit.putString(OsmandSettings.VOICE_PROVIDER, null);
} else {
edit.putString(OsmandSettings.VOICE_PROVIDER, (String) newValue);
}
edit.commit();
getMyApplication().initCommandPlayer();
} else if (preference == metricPreference) {
MetricsConstants mc = MetricsConstants.valueOf((String) newValue);
OsmandSettings.setDefaultMetricConstants(edit, mc);
} else if (preference == preferredLocale) {
edit.putString(OsmandSettings.PREFERRED_LOCALE, (String) newValue);
edit.commit();
// restart activity
getMyApplication().checkPrefferedLocale();
Intent intent = getIntent();
finish();
startActivity(intent);
} else if (preference == tileSourcePreference) {
if(VECTOR_MAP.equals((String) newValue)){
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, true);
osmandSettings.setUsingMapVectorData(true);
} else {
edit.putString(OsmandSettings.MAP_TILE_SOURCES, (String) newValue);
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, false);
osmandSettings.setUsingMapVectorData(true);
osmandSettings.setMapTileSource((String) newValue);
}
edit.commit();
String summary = tileSourcePreference.getSummary().toString();
if (summary.lastIndexOf(':') != -1) {
summary = summary.substring(0, summary.lastIndexOf(':') + 1);
}
summary += " " + (OsmandSettings.isUsingMapVectorData(prefs) ? getString(R.string.vector_data) : //$NON-NLS-1$
OsmandSettings.getMapTileSourceName(prefs));
tileSourcePreference.setSummary(summary);
updateTileSourceSummary();
}
return true;
}
private void warnAboutChangingStorage(final Editor edit, final String newValue) {
private void warnAboutChangingStorage(final String newValue) {
final String newDir = newValue != null ? newValue.trim(): newValue;
File path = new File(newDir);
path.mkdirs();
@ -595,11 +426,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
@Override
public void onClick(DialogInterface dialog, int which) {
//edit the preference
edit.putString(OsmandSettings.EXTERNAL_STORAGE_DIR, newDir);
edit.commit();
osmandSettings.setExternalStorageDirectory(newDir);
getMyApplication().getResourceManager().resetStoreDirectory();
reloadIndexes();
updateApplicationDirSummary();
updateApplicationDirTextAndSummary();
}
});
builder.setNegativeButton(R.string.default_buttons_cancel, null);
@ -659,85 +489,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
}
public static void setAppMode(ApplicationMode preset, Editor edit, OsmandApplication application, ApplicationMode old){
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);
application.getResourceManager().getRenderer().clearCache();
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,

View file

@ -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));
}
}

View file

@ -1,6 +1,5 @@
package net.osmand.plus.activities;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo;
import net.osmand.plus.activities.RoutingHelper.TurnType;
import net.osmand.plus.voice.CommandPlayer;

View file

@ -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 = getMyApplication().getSettings().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()
getMyApplication().getSettings().setMapLocationToShow(item.getLocation()
.getLatitude(), item.getLocation().getLongitude(),
getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$
startActivity(new Intent(this, MapActivity.class));

View file

@ -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);
}
}

View file

@ -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));
}

View file

@ -20,18 +20,19 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
private City city;
private Street street;
private PostCode postcode;
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){
street = region.getStreetByName(postcode, OsmandSettings.getLastSearchedStreet(prefs));
street = region.getStreetByName(postcode, settings.getLastSearchedStreet());
} else if(city != null){
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(prefs));
street = region.getStreetByName(city, settings.getLastSearchedStreet());
}
}
super.onCreate(savedInstanceState);
@ -54,7 +55,7 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
@Override
public void itemSelected(Building obj) {
OsmandSettings.setLastSearchedBuilding(this, obj.getName(region.useEnglishNames()));
settings.setLastSearchedBuilding(obj.getName(region.useEnglishNames()));
finish();
}

View file

@ -19,11 +19,13 @@ import android.widget.TextView;
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> {
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<MapOb
@Override
public void itemSelected(MapObject obj) {
if (obj instanceof City) {
OsmandSettings.setLastSearchedCity(this, obj.getId());
settings.setLastSearchedCity(obj.getId());
if (region.getCityById(obj.getId()) == null) {
region.addCityToPreloadedList((City) obj);
}
} else if(obj instanceof PostCode){
OsmandSettings.setLastSearchedPostcode(this, obj.getName());
settings.setLastSearchedPostcode(obj.getName());
}
finish();

View file

@ -36,7 +36,7 @@ public class SearchHistoryActivity extends ListActivity {
lv.setId(android.R.id.list);
setContentView(lv);
location = OsmandSettings.getLastKnownMapLocation(OsmandSettings.getPrefs(this));
location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
helper = SearchHistoryHelper.getInstance();
@ -79,9 +79,9 @@ public class SearchHistoryActivity extends ListActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
OsmandSettings.setMapLocationToShow(SearchHistoryActivity.this, entry.getLat(), entry.getLon());
OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(entry.getLat(), entry.getLon());
} else if (which == 1) {
OsmandSettings.setPointToNavigate(SearchHistoryActivity.this, entry.getLat(), entry.getLon());
OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setPointToNavigate(entry.getLat(), entry.getLon());
}
Intent newIntent = new Intent(SearchHistoryActivity.this, MapActivity.class);
@ -103,7 +103,7 @@ public class SearchHistoryActivity extends ListActivity {
private void selectModel(HistoryEntry model) {
helper.selectEntry(model, this);
OsmandSettings.setMapLocationToShow(this, model.getLat(), model.getLon());
OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(model.getLat(), model.getLon());
startActivity(new Intent(this, MapActivity.class));
}

View file

@ -96,7 +96,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
private String currentLocationProvider = null;
private boolean sensorRegistered = false;
private Handler uiHandler;
private SharedPreferences settings;
private OsmandSettings settings;
@ -116,7 +116,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
searchFilterLayout = findViewById(R.id.SearchFilterLayout);
showOnMap = (Button) findViewById(R.id.ShowOnMap);
settings = OsmandSettings.getPrefs(this);
settings = OsmandSettings.getOsmandSettings(this);
searchPOILevel.setOnClickListener(new OnClickListener() {
@Override
@ -185,10 +185,10 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
showOnMap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
OsmandSettings.setPoiFilterForMap(SearchPOIActivity.this, filter.getFilterId());
OsmandSettings.setShowPoiOverMap(SearchPOIActivity.this, true);
settings.setPoiFilterForMap(filter.getFilterId());
settings.SHOW_POI_OVER_MAP.set(true);
if(/*searchNearBy && */location != null){
OsmandSettings.setMapLocationToShow(SearchPOIActivity.this, location.getLatitude(), location.getLongitude(), 15);
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
}
Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class);
startActivity(newIntent);
@ -216,7 +216,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
@Override
public boolean onItemLongClick(AdapterView<?> 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<Amenity> filter = new ArrayList<Amenity>();
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);
}

View file

@ -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();
}

View file

@ -35,7 +35,7 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
@Override
public void itemSelected(RegionAddressRepository obj) {
OsmandSettings.setLastSearchedRegion(this, obj.getName());
OsmandSettings.getOsmandSettings(this).setLastSearchedRegion(obj.getName());
finish();
}

View file

@ -11,7 +11,6 @@ import net.osmand.plus.R;
import net.osmand.plus.RegionAddressRepository;
import net.osmand.plus.activities.OsmandApplication;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
@ -22,21 +21,22 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
private Street street1;
private List<Street> initialList = new ArrayList<Street>();
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<St
@Override
public void itemSelected(Street obj) {
OsmandSettings.setLastSearchedIntersectedStreet(this, obj.getName(region.useEnglishNames()));
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()));
finish();
}

View file

@ -18,14 +18,16 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
private RegionAddressRepository region;
private City city;
private PostCode postcode;
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));
postcode = region.getPostcode(settings.getLastSearchedPostcode());
if (postcode == null) {
city = region.getCityById(OsmandSettings.getLastSearchedCity(prefs));
city = region.getCityById(settings.getLastSearchedCity());
}
}
super.onCreate(savedInstanceState);
@ -48,7 +50,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
@Override
public void itemSelected(Street obj) {
OsmandSettings.setLastSearchedStreet(this, obj.getName(region.useEnglishNames()));
settings.setLastSearchedStreet(obj.getName(region.useEnglishNames()));
finish();
}

View file

@ -66,7 +66,7 @@ public class SearchTransportActivity extends ListActivity {
private TransportStopAdapter stopsAdapter;
private TransportRouteAdapter intermediateListAdapater;
private SharedPreferences settings;
private OsmandSettings settings;
@ -74,12 +74,12 @@ public class SearchTransportActivity extends ListActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
settings = OsmandSettings.getPrefs(this);
settings = OsmandSettings.getOsmandSettings(this);
Bundle extras = getIntent().getExtras();
if(extras != null && extras.containsKey(LAT_KEY) && extras.containsKey(LON_KEY)){
lastKnownMapLocation = new LatLon(extras.getDouble(LAT_KEY), extras.getDouble(LON_KEY));
} else {
lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(settings);
lastKnownMapLocation = settings.getLastKnownMapLocation();
}
setContentView(R.layout.search_transport);
searchTransportLevel = (Button) findViewById(R.id.SearchTransportLevelButton);
@ -132,7 +132,7 @@ public class SearchTransportActivity extends ListActivity {
@Override
protected void onResume() {
super.onResume();
LatLon pointToNavigate = OsmandSettings.getPointToNavigate(OsmandSettings.getPrefs(this));
LatLon pointToNavigate = settings.getPointToNavigate();
if(!Algoritms.objectEquals(pointToNavigate, this.destinationLocation)){
destinationLocation = pointToNavigate;
selectedDestinationLocation = destinationLocation;
@ -265,7 +265,7 @@ public class SearchTransportActivity extends ListActivity {
} else {
n.append(". "); //$NON-NLS-1$
}
String name = st.getName(OsmandSettings.usingEnglishNames(settings));
String name = st.getName(settings.usingEnglishNames());
if(locationToGo != null){
n.append(name).append(" - ["); //$NON-NLS-1$
n.append(OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(locationToGo, st.getLocation()), SearchTransportActivity.this)).append("]"); //$NON-NLS-1$
@ -323,7 +323,7 @@ public class SearchTransportActivity extends ListActivity {
public void showContextMenuOnRoute(final RouteInfoLocation route, final int routeInd) {
Builder b = new AlertDialog.Builder(this);
List<TransportStop> 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) {

View file

@ -39,7 +39,6 @@ import net.osmand.render.OsmandRenderingRulesParser;
import org.apache.commons.logging.Log;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.RectF;
import android.graphics.Bitmap.Config;
@ -73,12 +72,12 @@ public class MapRenderRepositories {
private boolean interrupted = false;
private RenderingContext currentRenderingContext;
private SearchRequest<BinaryMapDataObject> 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() {
@ -306,11 +305,12 @@ public class MapRenderRepositories {
currentRenderingContext = null;
}
try {
// find selected rendering type
Boolean renderDay = ((OsmandApplication)context.getApplicationContext()).getDaynightHelper().getDayNightRenderer();
BaseOsmandRender renderingType = RendererRegistry.getRegistry().getCurrentSelectedRenderer();
// find selected rendering type
OsmandApplication app = ((OsmandApplication)context.getApplicationContext());
Boolean renderDay = app.getDaynightHelper().getDayNightRenderer();
BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer();
if(renderDay != null && renderingType != null && renderDay.booleanValue() != renderingType.isDayRender()){
renderingType = RendererRegistry.getRegistry().getOppositeRendererForDayNight(renderingType);
renderingType = app.getRendererRegistry().getOppositeRendererForDayNight(renderingType);
}
// prevent editing
@ -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

View file

@ -21,7 +21,6 @@ import org.xml.sax.SAXException;
public class RendererRegistry {
private final static RendererRegistry registry = new RendererRegistry();
private final static Log log = LogUtil.getLog(RendererRegistry.class);
public final static String DEFAULT_RENDER = "default"; //$NON-NLS-1$
@ -33,9 +32,6 @@ public class RendererRegistry {
public final static String CAR_NIGHT_RENDER = CAR_RENDER + NIGHT_SUFFIX;
public static RendererRegistry getRegistry() {
return registry;
}
public RendererRegistry(){
internalRenderers.put(DEFAULT_RENDER, "default.render.xml"); //$NON-NLS-1$

View file

@ -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(),

View file

@ -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();

View file

@ -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++) {

View file

@ -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;
}

View file

@ -1,7 +1,7 @@
package net.osmand.plus.views;
import net.osmand.osm.MapUtils;
import net.osmand.plus.OsmandSettings.ApplicationMode;
import net.osmand.plus.activities.ApplicationMode;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;

View file

@ -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;

View file

@ -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<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(
n.getLocation().getLatitude(), n.getLocation().getLongitude());
@ -91,7 +91,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
List<String> 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$

View file

@ -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;