diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 9ae2011485..f3c5f1241f 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -343,15 +343,14 @@ public class RouteProvider { routeParams.start, routeParams.end, startI, endI); } List gpxDirections = new ArrayList(); - if(gpxParams.directions != null) { - gpxDirections.addAll(gpxParams.directions); - } - for (RouteDirectionInfo info : gpxDirections) { - if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){ - RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); - ch.routePointOffset = info.routePointOffset - startI[0]; - ch.setDescriptionRoute(info.getDescriptionRoutePart()); - gpxDirections.add(ch); + if (gpxParams.directions != null) { + for (RouteDirectionInfo info : gpxParams.directions) { + if (info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]) { + RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); + ch.routePointOffset = info.routePointOffset - startI[0]; + ch.setDescriptionRoute(info.getDescriptionRoutePart()); + gpxDirections.add(ch); + } } } boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index bfa42c387c..2b11f72470 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -750,6 +750,19 @@ public class RoutingHelper { currentRunningJob = null; return; } + final boolean onlineSourceWithoutInternet = !res.isCalculated() && params.type.isOnline() && !settings.isInternetConnectionAvailable(); + if (onlineSourceWithoutInternet && settings.ROUTE_CALC_OSMAND_PARTS.get()) { + if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) { + RouteCalculationResult rcr = params.previousToRecalculate; + List locs = rcr.getRouteLocations(); + List routeDirections = rcr.getRouteDirections(); + try { + provider.insertInitialSegment(params, locs, routeDirections, true); + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + } synchronized (RoutingHelper.this) { if (res.isCalculated()) { @@ -768,24 +781,9 @@ public class RoutingHelper { msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime()) + ")"; } showMessage(msg); - } else if (params.type.isOnline() && !settings.isInternetConnectionAvailable()) { - boolean showMsg = true; - if (settings.ROUTE_CALC_OSMAND_PARTS.get() && params.previousToRecalculate != null - && params.previousToRecalculate.isCalculated()) { - RouteCalculationResult rcr = params.previousToRecalculate; - List locs = rcr.getRouteLocations(); - List routeDirections = rcr.getRouteDirections(); - try { - provider.insertInitialSegment(params, locs, routeDirections, true); - showMsg = false; - } catch(RuntimeException e) { - e.printStackTrace(); - } - } - if (showMsg) { - showMessage(app.getString(R.string.error_calculating_route) - + ":\n" + app.getString(R.string.internet_connection_required_for_online_route)); //$NON-NLS-1$ - } + } else if (onlineSourceWithoutInternet) { + showMessage(app.getString(R.string.error_calculating_route) + + ":\n" + app.getString(R.string.internet_connection_required_for_online_route)); //$NON-NLS-1$ } else { if (res.getErrorMessage() != null) { showMessage(app.getString(R.string.error_calculating_route) + ":\n" + res.getErrorMessage()); //$NON-NLS-1$ @@ -798,7 +796,7 @@ public class RoutingHelper { } public void recalculateRouteDueToSettingsChange() { - recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, null); + recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route); } private void recalculateRouteInBackground(boolean force, final Location start, final LatLon end, final List intermediates, diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java index 06b6cb077e..b462050ddc 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java @@ -7,9 +7,12 @@ import java.util.List; import java.util.Set; import net.osmand.CallbackWithObject; +import net.osmand.Location; +import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; @@ -25,6 +28,7 @@ import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameterType; +import net.osmand.util.MapUtils; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; @@ -80,12 +84,12 @@ public class MapRoutePreferencesControl extends MapControls { } - private static class GPXLocalRoutingParameter extends LocalRoutingParameter { + private static class OtherLocalRoutingParameter extends LocalRoutingParameter { public String text; public boolean selected; public int id; - public GPXLocalRoutingParameter(int id, String text, boolean selected) { + public OtherLocalRoutingParameter(int id, String text, boolean selected) { this.text = text; this.selected = selected; this.id = id; @@ -155,12 +159,33 @@ public class MapRoutePreferencesControl extends MapControls { } - private void updateGpxRoutingParameter(GPXLocalRoutingParameter gpxParam) { + private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) { GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute(); + boolean selected = gpxParam.isSelected(settings); if (rp != null) { - boolean selected = gpxParam.isSelected(settings); if (gpxParam.id == R.string.gpx_option_reverse_route) { rp.setReverse(selected); + TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper(); + List ps = rp.getPoints(); + if (ps.size() > 0) { + Location first = ps.get(0); + Location end = ps.get(ps.size() - 1); + LatLon pn = tg.getPointToNavigate(); + boolean update = false; + if (pn == null || + MapUtils.getDistance(tg.getPointToNavigate(), new LatLon(first.getLatitude(), first.getLongitude())) < 10) { + tg.navigateToPoint(new LatLon(end.getLatitude(), end.getLongitude()), false, -1); + update = true; + } + if (tg.getPointToStart() == null || + MapUtils.getDistance(tg.getPointToStart(), new LatLon(end.getLatitude(), end.getLongitude())) < 10) { + tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null); + update = true; + } + if(update) { + tg.updateRoutingHelper(); + } + } } else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) { rp.setCalculateOsmAndRouteParts(selected); settings.ROUTE_CALC_OSMAND_PARTS.set(selected); @@ -173,9 +198,13 @@ public class MapRoutePreferencesControl extends MapControls { settings.CALC_GPX_ROUTE.set(selected); rp.setCalculateOsmAndRoute(selected); updateParameters(); - } else if (gpxParam.id == R.string.calculate_osmand_route_without_internet) { - settings.ROUTE_CALC_OSMAND_PARTS.set(selected); - } + } + } + if (gpxParam.id == R.string.calculate_osmand_route_without_internet) { + settings.ROUTE_CALC_OSMAND_PARTS.set(selected); + } + if (gpxParam.id == R.string.fast_route_mode) { + settings.FAST_ROUTE_MODE.set(selected); } } @@ -183,20 +212,22 @@ public class MapRoutePreferencesControl extends MapControls { private List getRoutingParameters(ApplicationMode am) { List list = new ArrayList(); GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - boolean osmandRouter = settings.ROUTER_SERVICE.get() != RouteService.OSMAND ; + boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ; if(!osmandRouter) { - list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, + list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, getString(R.string.calculate_osmand_route_without_internet), settings.ROUTE_CALC_OSMAND_PARTS.get())); + list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, + getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get())); return list; } if(rparams != null) { - list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route, + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, getString(R.string.gpx_option_reverse_route), rparams.isReverse())); - list.add(new GPXLocalRoutingParameter(R.string.gpx_option_from_start_point, + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute())); - list.add(new GPXLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, + list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts())); - list.add(new GPXLocalRoutingParameter(R.string.announce_gpx_waypoints, + list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints, getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints())); // Temporary disabled // list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx, @@ -247,8 +278,8 @@ public class MapRoutePreferencesControl extends MapControls { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { rp.setSelected(settings, isChecked); - if(rp instanceof GPXLocalRoutingParameter) { - updateGpxRoutingParameter((GPXLocalRoutingParameter) rp); + if(rp instanceof OtherLocalRoutingParameter) { + updateGpxRoutingParameter((OtherLocalRoutingParameter) rp); } mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); }