Calculate osmand route if internet not available

This commit is contained in:
vshcherb 2014-03-31 22:44:54 +02:00
parent abc6ba1d6c
commit 2be1d5a1c0
9 changed files with 53 additions and 25 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="calculate_osmand_route_without_internet">Calculate OsmAnd route segment without internet</string>
<string name="gpx_option_calculate_first_last_segment">Calculate OsmAnd route for first and last route segment</string>
<string name="use_displayed_track_for_navigation">Do you want to use displayed track for navigation?</string>
<string name="keep_and_add_destination_point">Add as destination point</string>

View file

@ -741,7 +741,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", true).makeProfile().cache();
public final OsmandPreference<Boolean> SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache();
public final OsmandPreference<Boolean> GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
public final OsmandPreference<Boolean> ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
public final OsmandPreference<Boolean> SPEAK_GPX_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
public final OsmandPreference<Boolean> CALC_GPX_ROUTE = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();

View file

@ -455,7 +455,7 @@ public class MapActivityActions implements DialogProvider {
} else {
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication()
.getSettings());
params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
params.setCalculateOsmAndRouteParts(settings.ROUTE_CALC_OSMAND_PARTS.get());
params.setAnnounceWaypoints(settings.SPEAK_GPX_WPT.get());
params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get());
List<Location> ps = params.getPoints();

View file

@ -131,7 +131,7 @@ public class FailSafeFuntions {
if (settings.SPEAK_GPX_WPT.get()) {
gpxRoute.setAnnounceWaypoints(true);
}
if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
if (settings.ROUTE_CALC_OSMAND_PARTS.get()) {
gpxRoute.setCalculateOsmAndRouteParts(true);
}
if(settings.CALC_GPX_ROUTE.get()) {

View file

@ -654,16 +654,16 @@ public class RouteCalculationResult {
//////////////////// MUST BE ALL SYNCHRONIZED ??? //////////////////////
public List<Location> getImmutableLocations() {
public List<Location> getImmutableAllLocations() {
return locations;
}
public List<RouteDirectionInfo> getDirections() {
public List<RouteDirectionInfo> getImmutableAllDirections() {
return directions;
}
public List<Location> getNextLocations() {
public List<Location> getRouteLocations() {
if(currentRoute < locations.size()) {
return locations.subList(currentRoute, locations.size());
}
@ -844,6 +844,8 @@ public class RouteCalculationResult {
return null;
}
public List<RouteDirectionInfo> getRouteDirections() {
if(currentDirectionInfo < directions.size() - 1){
if(cacheCurrentTextDirectionInfo != currentDirectionInfo) {

View file

@ -301,19 +301,19 @@ public class RouteProvider {
res = calculateGpxRoute(params);
} else if (params.type == RouteService.OSMAND) {
res = findVectorMapsRoute(params, calcGPXRoute);
} else if (params.type == RouteService.BROUTER) {
res = findBROUTERRoute(params);
} else if (params.type == RouteService.YOURS) {
res = findYOURSRoute(params);
} else if (params.type == RouteService.ORS) {
res = findORSRoute(params);
} else if (params.type == RouteService.OSRM) {
res = findOSRMRoute(params);
} else if (params.type == RouteService.BROUTER) {
res = findBROUTERRoute(params);
} else {
res = new RouteCalculationResult("Selected route service is not available");
res = new RouteCalculationResult("Selected route service is not available");
}
if(log.isInfoEnabled() ){
log.info("Finding route contained " + res.getImmutableLocations().size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
log.info("Finding route contained " + res.getImmutableAllLocations().size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return res;
} catch (IOException e) {
@ -384,8 +384,8 @@ public class RouteProvider {
List<Location> loct;
List<RouteDirectionInfo> dt;
if (newRes != null && newRes.isCalculated()) {
loct = newRes.getImmutableLocations();
dt = newRes.getDirections();
loct = newRes.getImmutableAllLocations();
dt = newRes.getImmutableAllDirections();
} else {
loct = new ArrayList<Location>();
Location l = new Location("");
@ -403,7 +403,7 @@ public class RouteProvider {
}
}
private void insertInitialSegment(RouteCalculationParams routeParams, List<Location> points,
public void insertInitialSegment(RouteCalculationParams routeParams, List<Location> points,
List<RouteDirectionInfo> directions, boolean calculateOsmAndRouteParts) {
Location realStart = routeParams.start;
if (realStart != null && points.size() > 0 && realStart.distanceTo(points.get(0)) > 60) {
@ -416,8 +416,8 @@ public class RouteProvider {
List<Location> loct;
List<RouteDirectionInfo> dt;
if (newRes != null && newRes.isCalculated()) {
loct = newRes.getImmutableLocations();
dt = newRes.getDirections();
loct = newRes.getImmutableAllLocations();
dt = newRes.getImmutableAllDirections();
} else {
loct = new ArrayList<Location>();
loct.add(realStart);
@ -929,8 +929,8 @@ public class RouteProvider {
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx){
TargetPointsHelper helper = ctx.getTargetPointsHelper();
int currentRoute = srcRoute.currentRoute;
List<Location> routeNodes = srcRoute.getImmutableLocations();
List<RouteDirectionInfo> directionInfo = srcRoute.getDirections();
List<Location> routeNodes = srcRoute.getImmutableAllLocations();
List<RouteDirectionInfo> directionInfo = srcRoute.getImmutableAllDirections();
int currentDirectionInfo = srcRoute.currentDirectionInfo;
GPXFile gpx = new GPXFile();

View file

@ -163,7 +163,7 @@ public class RoutingHelper {
}
public List<Location> getCurrentCalculatedRoute() {
return route.getImmutableLocations();
return route.getImmutableAllLocations();
}
public void setAppMode(ApplicationMode mode){
@ -232,7 +232,7 @@ public class RoutingHelper {
if (finished) {
return null;
}
List<Location> routeNodes = route.getImmutableLocations();
List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute;
// 2. Analyze if we need to recalculate route
@ -344,7 +344,7 @@ public class RoutingHelper {
}
private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
List<Location> routeNodes = route.getImmutableLocations();
List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute;
// 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
while (currentRoute + 1 < routeNodes.size()) {
@ -522,7 +522,7 @@ public class RoutingHelper {
}
// try remove false route-recalculated prompts by checking direction to second route node
boolean wrongMovementDirection = false;
List<Location> routeNodes = res.getImmutableLocations();
List<Location> routeNodes = res.getImmutableAllLocations();
if (routeNodes != null && !routeNodes.isEmpty()) {
int newCurrentRoute = lookAheadFindMinOrthogonalDistance(start, routeNodes, res.currentRoute, 15);
if (newCurrentRoute + 1 < routeNodes.size()) {
@ -769,8 +769,23 @@ public class RoutingHelper {
}
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) {
showMessage(app.getString(R.string.error_calculating_route)
+ ":\n" + app.getString(R.string.internet_connection_required_for_online_route)); //$NON-NLS-1$
+ ":\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$

View file

@ -199,7 +199,7 @@ public class RouteLayer extends OsmandMapLayer {
previousVisible = true;
}
}
List<Location> routeNodes = helper.getRoute().getNextLocations();
List<Location> routeNodes = helper.getRoute().getRouteLocations();
for (int i = 0; i < routeNodes.size(); i++) {
Location ls = routeNodes.get(i);
if (leftLongitude <= ls.getLongitude() && ls.getLongitude() <= rightLongitude && bottomLatitude <= ls.getLatitude()

View file

@ -20,6 +20,7 @@ import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
@ -162,7 +163,7 @@ public class MapRoutePreferencesControl extends MapControls {
rp.setReverse(selected);
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
rp.setCalculateOsmAndRouteParts(selected);
settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
settings.ROUTE_CALC_OSMAND_PARTS.set(selected);
} else if (gpxParam.id == R.string.gpx_option_from_start_point) {
rp.setPassWholeRoute(selected);
} else if (gpxParam.id == R.string.announce_gpx_waypoints) {
@ -172,6 +173,8 @@ 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);
}
}
}
@ -179,8 +182,13 @@ public class MapRoutePreferencesControl extends MapControls {
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() != RouteService.OSMAND ;
if(!osmandRouter) {
list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
getString(R.string.calculate_osmand_route_without_internet), settings.ROUTE_CALC_OSMAND_PARTS.get()));
return list;
}
if(rparams != null) {
list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route,
getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
@ -194,6 +202,7 @@ public class MapRoutePreferencesControl extends MapControls {
// list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
// getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
}
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
if(rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) {
return list;
}