From 29eff9e62018a746266bdda5d3b11ec7e59e7b3b Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 24 Mar 2017 11:38:27 +0300 Subject: [PATCH] Fix auto-zoom --- OsmAnd/res/xml/navigation_settings.xml | 2 +- .../src/net/osmand/plus/OsmandSettings.java | 25 +++--- .../SettingsNavigationActivity.java | 88 ++++++++++++++++--- .../plus/base/MapViewTrackingUtilities.java | 8 +- .../actions/NavAutoZoomMapAction.java | 17 ++-- 5 files changed, 98 insertions(+), 42 deletions(-) diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index f917c24286..b3dc364cdd 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -12,7 +12,7 @@ - diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index fd4fc57677..4651784fe8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -955,18 +955,20 @@ public class OsmandSettings { RouteService.values()).makeProfile(); // this value string is synchronized with settings_pref.xml preference name - public final CommonPreference AUTO_ZOOM_MAP_PREV = - new EnumIntPreference("auto_zoom_map_new_prev", AutoZoomMap.NONE, - AutoZoomMap.values()).makeProfile().cache(); - - public final CommonPreference AUTO_ZOOM_MAP = - new EnumIntPreference("auto_zoom_map_new", AutoZoomMap.NONE, - AutoZoomMap.values()).makeProfile().cache(); - + public final CommonPreference AUTO_ZOOM_MAP = new BooleanPreference("auto_zoom_map_on_off", false).makeProfile().cache(); { - AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.CAR, AutoZoomMap.FAR); - AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.BICYCLE, AutoZoomMap.NONE); - AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.PEDESTRIAN, AutoZoomMap.NONE); + AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.CAR, true); + AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.BICYCLE, false); + AUTO_ZOOM_MAP.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false); + } + + public final CommonPreference AUTO_ZOOM_MAP_SCALE = + new EnumIntPreference("auto_zoom_map_scale", AutoZoomMap.FAR, + AutoZoomMap.values()).makeProfile().cache(); + { + AUTO_ZOOM_MAP_SCALE.setModeDefaultValue(ApplicationMode.CAR, AutoZoomMap.FAR); + AUTO_ZOOM_MAP_SCALE.setModeDefaultValue(ApplicationMode.BICYCLE, AutoZoomMap.CLOSE); + AUTO_ZOOM_MAP_SCALE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, AutoZoomMap.CLOSE); } public final CommonPreference DELAY_TO_START_NAVIGATION = new IntPreference("delay_to_start_navigation", -1) { @@ -3016,7 +3018,6 @@ public class OsmandSettings { } public enum AutoZoomMap { - NONE(R.string.auto_zoom_none, 0f, 18), FARTHEST(R.string.auto_zoom_farthest, 1f, 15.5f), FAR(R.string.auto_zoom_far, 1.4f, 17f), CLOSE(R.string.auto_zoom_close, 2f, 19f); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 1aa15a7620..f3ca8bb4d8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -47,10 +47,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { private Preference avoidRouting; private Preference preferRouting; private Preference reliefFactorRouting; + private Preference autoZoom; private Preference showAlarms; private Preference speakAlarms; private ListPreference routerServicePreference; - private ListPreference autoZoomMapPreference; private ListPreference speedLimitExceed; private ComponentName mDeviceAdmin; @@ -133,13 +133,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { } registerListPreference(settings.AUTO_FOLLOW_ROUTE, screen, entries, intValues); - entries = new String[AutoZoomMap.values().length]; - for(int i=0; i listAdapter = new ArrayAdapter(this, layout, R.id.text1, + adapter.getItemNames()) { + @NonNull + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + // User super class to create the View + View v = convertView; + if (v == null) { + v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null); + } + final ContextMenuItem item = adapter.getItem(position); + TextView tv = (TextView) v.findViewById(R.id.text1); + tv.setText(item.getTitle()); + tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f); + + return v; + } + }; + + final int[] selectedPosition = {selectedIndex}; + builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int position) { + selectedPosition[0] = position; + } + }); + builder.setTitle(R.string.auto_zoom_map) + .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + + int position = selectedPosition[0]; + if (position == 0) { + settings.AUTO_ZOOM_MAP.set(false); + } else { + settings.AUTO_ZOOM_MAP.set(true); + settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position -1]); + } + } + }) + .setNegativeButton(R.string.shared_string_cancel, null); + + builder.create().show(); + return true; } else if (preference == reliefFactorRouting) { final ApplicationMode am = settings.getApplicationMode(); final ContextMenuAdapter adapter = new ContextMenuAdapter(); diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 949d5a9fbb..da47505924 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -19,8 +19,6 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.AutoZoomMap; -import net.osmand.plus.OsmandSettings.DrivingRegion; import net.osmand.plus.R; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -173,7 +171,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc if (mapView != null) { RotatedTileBox tb = mapView.getCurrentRotatedTileBox(); if (isMapLinkedToLocation() && location != null) { - if (settings.AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE) { + if (settings.AUTO_ZOOM_MAP.get()) { autozoom(location); } int currentMapRotation = settings.ROTATE_MAP.get(); @@ -268,7 +266,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc if (speed < 83f / 3.6) { time = 60f; } - time /= settings.AUTO_ZOOM_MAP.get().coefficient; + time /= settings.AUTO_ZOOM_MAP_SCALE.get().coefficient; double distToSee = speed * time; float zoomDelta = (float) (Math.log(visibleDist / distToSee) / Math.log(2.0f)); // check if 17, 18 is correct? @@ -289,7 +287,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc // decrease a bit zdelta += 1; } - double targetZoom = Math.min(tb.getZoom() + tb.getZoomFloatPart() + zdelta, settings.AUTO_ZOOM_MAP.get().maxZoom); + double targetZoom = Math.min(tb.getZoom() + tb.getZoomFloatPart() + zdelta, settings.AUTO_ZOOM_MAP_SCALE.get().maxZoom); int threshold = settings.AUTO_FOLLOW_ROUTE.get(); if (now - lastTimeAutoZooming > 4500 && (now - lastTimeAutoZooming > threshold || !isUserZoomed)) { isUserZoomed = false; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java index ddc1cedbfd..1b1026be51 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java @@ -8,7 +8,6 @@ import android.widget.Toast; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.AutoZoomMap; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; @@ -29,13 +28,8 @@ public class NavAutoZoomMapAction extends QuickAction { public void execute(MapActivity activity) { OsmandSettings settings = activity.getMyApplication().getSettings(); - if (settings.AUTO_ZOOM_MAP.get() == AutoZoomMap.NONE) { - settings.AUTO_ZOOM_MAP.set(settings.AUTO_ZOOM_MAP_PREV.get()); - } else { - settings.AUTO_ZOOM_MAP_PREV.set(settings.AUTO_ZOOM_MAP.get()); - settings.AUTO_ZOOM_MAP.set(AutoZoomMap.NONE); - } - Toast.makeText(activity, activity.getString(settings.AUTO_ZOOM_MAP.get() == AutoZoomMap.NONE + settings.AUTO_ZOOM_MAP.set(!settings.AUTO_ZOOM_MAP.get()); + Toast.makeText(activity, activity.getString(!settings.AUTO_ZOOM_MAP.get() ? R.string.quick_action_auto_zoom_off : R.string.quick_action_auto_zoom_on), Toast.LENGTH_SHORT).show(); } @@ -54,14 +48,13 @@ public class NavAutoZoomMapAction extends QuickAction { @Override public String getActionText(OsmandApplication application) { - return application.getSettings().AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE - ? application.getString(R.string.quick_action_auto_zoom_off) - : application.getString(R.string.quick_action_auto_zoom_on); + return application.getSettings().AUTO_ZOOM_MAP.get() + ? application.getString(R.string.quick_action_auto_zoom_off) : application.getString(R.string.quick_action_auto_zoom_on); } @Override public boolean isActionWithSlash(OsmandApplication application) { - return application.getSettings().AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE; + return application.getSettings().AUTO_ZOOM_MAP.get(); } }