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

@ -344,9 +344,7 @@ public class RouteProvider {
}
List<RouteDirectionInfo> gpxDirections = new ArrayList<RouteDirectionInfo>();
if (gpxParams.directions != null) {
gpxDirections.addAll(gpxParams.directions);
}
for (RouteDirectionInfo info : gpxDirections) {
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];
@ -354,6 +352,7 @@ public class RouteProvider {
gpxDirections.add(ch);
}
}
}
boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts;
insertInitialSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);
insertFinalSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);

View file

@ -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<Location> locs = rcr.getRouteLocations();
List<RouteDirectionInfo> 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<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) {
} 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<LatLon> intermediates,

View file

@ -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();
if (rp != null) {
boolean selected = gpxParam.isSelected(settings);
if (rp != null) {
if (gpxParam.id == R.string.gpx_option_reverse_route) {
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) {
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) {
}
}
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) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
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();
}