From 76df14c588546608428420cc80828eb7c0ed4942 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 28 Apr 2014 02:05:27 +0200 Subject: [PATCH] Add option to display position always in center --- OsmAnd/res/values/strings.xml | 3 +- .../src/net/osmand/plus/OsmandSettings.java | 7 +--- .../plus/base/MapViewTrackingUtilities.java | 6 ++- .../mapwidgets/AppearanceWidgetsFactory.java | 40 ++++++------------- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 19bfc5831c..85c498b469 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Display position always in center Voice Miscallenious Localization @@ -721,8 +722,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Map style Start\n online tracking Stop\n online tracking - Choose location of position marker on the map - Position marker Configure screen Show lanes Avoid unpaved roads diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 415d6cdf19..45d119a022 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -866,12 +866,7 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final int CENTER_CONSTANT = 0; public static final int BOTTOM_CONSTANT = 1; - public final CommonPreference POSITION_ON_MAP = new IntPreference("position_on_map", CENTER_CONSTANT).makeProfile(); - { - POSITION_ON_MAP.setModeDefaultValue(ApplicationMode.CAR, BOTTOM_CONSTANT); - POSITION_ON_MAP.setModeDefaultValue(ApplicationMode.BICYCLE, BOTTOM_CONSTANT); - POSITION_ON_MAP.setModeDefaultValue(ApplicationMode.PEDESTRIAN, CENTER_CONSTANT); - } + public final CommonPreference CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile(); // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference MAX_LEVEL_TO_DOWNLOAD_TILE = new IntPreference("max_level_download_tile", 18).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 66b0dddf27..c9a7eaf7b4 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -138,8 +138,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc if (settings.ROTATE_MAP.get() != OsmandSettings.ROTATE_MAP_COMPASS || routePlanningMode) { mapView.setRotate(0); } - mapView.setMapPosition(settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING && !routePlanningMode ? OsmandSettings.BOTTOM_CONSTANT - : OsmandSettings.CENTER_CONSTANT); + mapView.setMapPosition(settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING + && !routePlanningMode + && !settings.CENTER_POSITION_ON_MAP.get() ? + OsmandSettings.BOTTOM_CONSTANT : OsmandSettings.CENTER_CONSTANT); } registerUnregisterSensor(app.getLocationProvider().getLastKnownLocation()); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java index e38624ed1d..89bd76e591 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java @@ -72,34 +72,18 @@ public class AppearanceWidgetsFactory { mapInfoLayer.recreateControls(); } }); - - if (POSITION_ON_THE_MAP) { - final OsmandSettings.OsmandPreference posPref = view.getSettings().POSITION_ON_MAP; - final MapWidgetRegistry.MapWidgetRegInfo posMap = mapInfoControls.registerAppearanceWidget( - R.drawable.widget_position_marker, R.string.position_on_map, "position_on_map", posPref); - posMap.setStateChangeListener(new Runnable() { - @Override - public void run() { - String[] entries = new String[] { map.getString(R.string.position_on_map_center), - map.getString(R.string.position_on_map_bottom) }; - final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT, - OsmandSettings.BOTTOM_CONSTANT }; - AlertDialog.Builder b = new AlertDialog.Builder(view.getContext()); - int i = Arrays.binarySearch(vals, posPref.get()); - b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - posPref.set(vals[which]); - map.updateApplicationModeSettings(); - view.refreshMap(true); - dialog.dismiss(); - } - }); - b.show(); - } - }); - } - + final MapWidgetRegistry.MapWidgetRegInfo centerPosition = mapInfoControls.registerAppearanceWidget(R.drawable.widget_position_marker, + R.string.always_center_position_on_map, + "centerPosition", view.getSettings().CENTER_POSITION_ON_MAP); + centerPosition.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().CENTER_POSITION_ON_MAP.set(!view.getSettings().CENTER_POSITION_ON_MAP.get()); + map.updateApplicationModeSettings(); + view.refreshMap(true); + mapInfoLayer.recreateControls(); + } + }); } final MapWidgetRegistry.MapWidgetRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(R.drawable.widget_rendering_style, map.getString(R.string.map_widget_renderer),