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). 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 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="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="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> <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_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> 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> 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(); 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 { } else {
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication() GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication()
.getSettings()); .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.setAnnounceWaypoints(settings.SPEAK_GPX_WPT.get());
params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get()); params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get());
List<Location> ps = params.getPoints(); List<Location> ps = params.getPoints();

View file

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

View file

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

View file

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

View file

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

View file

@ -199,7 +199,7 @@ public class RouteLayer extends OsmandMapLayer {
previousVisible = true; previousVisible = true;
} }
} }
List<Location> routeNodes = helper.getRoute().getNextLocations(); List<Location> routeNodes = helper.getRoute().getRouteLocations();
for (int i = 0; i < routeNodes.size(); i++) { for (int i = 0; i < routeNodes.size(); i++) {
Location ls = routeNodes.get(i); Location ls = routeNodes.get(i);
if (leftLongitude <= ls.getLongitude() && ls.getLongitude() <= rightLongitude && bottomLatitude <= ls.getLatitude() 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.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; 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;
@ -162,7 +163,7 @@ public class MapRoutePreferencesControl extends MapControls {
rp.setReverse(selected); rp.setReverse(selected);
} 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.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) { } else if (gpxParam.id == R.string.gpx_option_from_start_point) {
rp.setPassWholeRoute(selected); rp.setPassWholeRoute(selected);
} else if (gpxParam.id == R.string.announce_gpx_waypoints) { } else if (gpxParam.id == R.string.announce_gpx_waypoints) {
@ -172,6 +173,8 @@ 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);
} }
} }
} }
@ -179,8 +182,13 @@ 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>();
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute(); 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) { if(rparams != null) {
list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route, list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route,
getString(R.string.gpx_option_reverse_route), rparams.isReverse())); 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, // list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
// getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute())); // getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
} }
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
if(rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) { if(rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) {
return list; return list;
} }