From f4d98743f9a1d39e11df6dbaa2b720727aa54bae Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 31 Aug 2015 23:37:36 +0200 Subject: [PATCH] Remembers last selected routing method --- .../src/net/osmand/plus/OsmandSettings.java | 1 + .../plus/activities/MapActivityActions.java | 23 ++++++++++++++++--- .../osmand/plus/routing/RoutingHelper.java | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index a8cbb7e7ff..cd1cefaba6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -167,6 +167,7 @@ public class OsmandSettings { return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode)); } + public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null; // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference APPLICATION_MODE = new PreferenceWithListener(){ diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 9e63f8a53b..f834a93631 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -40,6 +40,7 @@ import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.util.MapUtils; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -426,14 +427,29 @@ public class MapActivityActions implements DialogProvider { ApplicationMode mode = settings.DEFAULT_APPLICATION_MODE.get(); ApplicationMode selected = settings.APPLICATION_MODE.get(); + OsmandApplication app = mapActivity.getMyApplication(); + TargetPointsHelper targets = app.getTargetPointsHelper(); if( selected != ApplicationMode.DEFAULT) { mode = selected; } else if (mode == ApplicationMode.DEFAULT) { - mode = ApplicationMode.CAR ; + mode = ApplicationMode.CAR; + if(settings.LAST_ROUTING_APPLICATION_MODE != null && + settings.LAST_ROUTING_APPLICATION_MODE != ApplicationMode.DEFAULT) { + mode = settings.LAST_ROUTING_APPLICATION_MODE; + } + if(from != null && targets.getPointToNavigate() != null) { + double dist = MapUtils.getDistance(from, targets.getPointToNavigate().getLatitude(), + targets.getPointToNavigate().getLongitude()); + if(dist >= 50000 && mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { + mode = ApplicationMode.CAR ; + } else if(dist >= 300000 && mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { + mode = ApplicationMode.CAR ; + } else if(dist < 2000 && mode.isDerivedRoutingFrom(ApplicationMode.CAR)) { + mode = ApplicationMode.PEDESTRIAN ; + } + } } - OsmandApplication app = mapActivity.getMyApplication(); - TargetPointsHelper targets = app.getTargetPointsHelper(); app.getSettings().APPLICATION_MODE.set(mode); app.getRoutingHelper().setAppMode(mode); app.initVoiceCommandPlayer(mapActivity); @@ -732,6 +748,7 @@ public class MapActivityActions implements DialogProvider { routingHelper.getVoiceRouter().interruptRouteCommands(); routingHelper.clearCurrentRoute(null, new ArrayList()); routingHelper.setRoutePlanningMode(false); + settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get(); settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); mapActivity.updateApplicationModeSettings(); } diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index ff51863e39..12620c10c6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -496,6 +496,7 @@ public class RoutingHelper { app.runInUIThread(new Runnable() { @Override public void run() { + settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get(); settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); } });