This commit is contained in:
vshcherb 2014-03-31 23:24:51 +02:00
parent 2be1d5a1c0
commit 91b3eb56d8
3 changed files with 71 additions and 43 deletions

View file

@ -343,15 +343,14 @@ public class RouteProvider {
routeParams.start, routeParams.end, startI, endI); routeParams.start, routeParams.end, startI, endI);
} }
List<RouteDirectionInfo> gpxDirections = new ArrayList<RouteDirectionInfo>(); List<RouteDirectionInfo> gpxDirections = new ArrayList<RouteDirectionInfo>();
if(gpxParams.directions != null) { if (gpxParams.directions != null) {
gpxDirections.addAll(gpxParams.directions); for (RouteDirectionInfo info : gpxParams.directions) {
} if (info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]) {
for (RouteDirectionInfo info : gpxDirections) { RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType());
if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){ ch.routePointOffset = info.routePointOffset - startI[0];
RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); ch.setDescriptionRoute(info.getDescriptionRoutePart());
ch.routePointOffset = info.routePointOffset - startI[0]; gpxDirections.add(ch);
ch.setDescriptionRoute(info.getDescriptionRoutePart()); }
gpxDirections.add(ch);
} }
} }
boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts; boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts;

View file

@ -750,6 +750,19 @@ public class RoutingHelper {
currentRunningJob = null; currentRunningJob = null;
return; 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<Location> locs = rcr.getRouteLocations();
List<RouteDirectionInfo> routeDirections = rcr.getRouteDirections();
try {
provider.insertInitialSegment(params, locs, routeDirections, true);
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
synchronized (RoutingHelper.this) { synchronized (RoutingHelper.this) {
if (res.isCalculated()) { if (res.isCalculated()) {
@ -768,24 +781,9 @@ public class RoutingHelper {
msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime()) + ")"; msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime()) + ")";
} }
showMessage(msg); showMessage(msg);
} else if (params.type.isOnline() && !settings.isInternetConnectionAvailable()) { } else if (onlineSourceWithoutInternet) {
boolean showMsg = true; showMessage(app.getString(R.string.error_calculating_route)
if (settings.ROUTE_CALC_OSMAND_PARTS.get() && params.previousToRecalculate != null + ":\n" + app.getString(R.string.internet_connection_required_for_online_route)); //$NON-NLS-1$
&& params.previousToRecalculate.isCalculated()) {
RouteCalculationResult rcr = params.previousToRecalculate;
List<Location> locs = rcr.getRouteLocations();
List<RouteDirectionInfo> 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 { } else {
if (res.getErrorMessage() != null) { if (res.getErrorMessage() != null) {
showMessage(app.getString(R.string.error_calculating_route) + ":\n" + res.getErrorMessage()); //$NON-NLS-1$ showMessage(app.getString(R.string.error_calculating_route) + ":\n" + res.getErrorMessage()); //$NON-NLS-1$
@ -798,7 +796,7 @@ public class RoutingHelper {
} }
public void recalculateRouteDueToSettingsChange() { 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<LatLon> intermediates, private void recalculateRouteInBackground(boolean force, final Location start, final LatLon end, final List<LatLon> intermediates,

View file

@ -7,9 +7,12 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; 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;
import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType; import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.util.MapUtils;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; 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 String text;
public boolean selected; public boolean selected;
public int id; public int id;
public GPXLocalRoutingParameter(int id, String text, boolean selected) { public OtherLocalRoutingParameter(int id, String text, boolean selected) {
this.text = text; this.text = text;
this.selected = selected; this.selected = selected;
this.id = id; 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(); GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean selected = gpxParam.isSelected(settings);
if (rp != null) { if (rp != null) {
boolean selected = gpxParam.isSelected(settings);
if (gpxParam.id == R.string.gpx_option_reverse_route) { if (gpxParam.id == R.string.gpx_option_reverse_route) {
rp.setReverse(selected); rp.setReverse(selected);
TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper();
List<Location> 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) { } else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
rp.setCalculateOsmAndRouteParts(selected); rp.setCalculateOsmAndRouteParts(selected);
settings.ROUTE_CALC_OSMAND_PARTS.set(selected); settings.ROUTE_CALC_OSMAND_PARTS.set(selected);
@ -173,9 +198,13 @@ public class MapRoutePreferencesControl extends MapControls {
settings.CALC_GPX_ROUTE.set(selected); settings.CALC_GPX_ROUTE.set(selected);
rp.setCalculateOsmAndRoute(selected); rp.setCalculateOsmAndRoute(selected);
updateParameters(); 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<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) { private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>(); List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute(); GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() != RouteService.OSMAND ; boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
if(!osmandRouter) { 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())); 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; return list;
} }
if(rparams != null) { 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())); 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())); 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())); 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())); getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
// Temporary disabled // Temporary disabled
// list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx, // list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
@ -247,8 +278,8 @@ public class MapRoutePreferencesControl extends MapControls {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
rp.setSelected(settings, isChecked); rp.setSelected(settings, isChecked);
if(rp instanceof GPXLocalRoutingParameter) { if(rp instanceof OtherLocalRoutingParameter) {
updateGpxRoutingParameter((GPXLocalRoutingParameter) rp); updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
} }
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
} }