Update routing providers for new application modes

This commit is contained in:
vshcherb 2013-11-29 23:52:40 +01:00
parent f741c04755
commit 739d42581b
4 changed files with 73 additions and 27 deletions

View file

@ -256,6 +256,10 @@ public class ApplicationMode {
return ctx.getString(key);
}
public String toHumanStringCtx(ClientContext ctx) {
return ctx.getString(key);
}
public static ApplicationMode valueOfStringKey(String key, ApplicationMode def) {
for(ApplicationMode p : values) {
if(p.getStringKey().equals(key)) {
@ -274,6 +278,10 @@ public class ApplicationMode {
}
public boolean isDerivedRoutingFrom(ApplicationMode mode) {
return this == mode || getParent() == mode;
}

View file

@ -27,12 +27,14 @@ public class CurrentPositionHelper {
private void initCtx(ClientContext app) {
am = app.getSettings().getApplicationMode();
GeneralRouterProfile p ;
if (am == ApplicationMode.BICYCLE) {
if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
p = GeneralRouterProfile.BICYCLE;
} else if (am == ApplicationMode.PEDESTRIAN) {
} else if (am.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
p = GeneralRouterProfile.PEDESTRIAN;
} else {
} else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
p = GeneralRouterProfile.CAR;
} else {
return;
}
RoutingConfiguration cfg = RoutingConfiguration.getDefault().build(p.name().toLowerCase(), 10);
ctx = new RoutingContext(cfg, null, app.getTodoAPI().getRoutingMapFiles());
@ -43,6 +45,9 @@ public class CurrentPositionHelper {
try {
if(ctx == null || am != app.getSettings().getApplicationMode()) {
initCtx(app);
if(ctx == null) {
return null;
}
}
RouteSegment sg = rp.findRouteSegment(loc.getLatitude(), loc.getLongitude(), ctx);
if(sg == null) {

View file

@ -282,12 +282,14 @@ public class RouteProvider {
uri.append("&flon=").append(params.start.getLongitude()); //$NON-NLS-1$
uri.append("&tlat=").append(params.end.getLatitude()); //$NON-NLS-1$
uri.append("&tlon=").append(params.end.getLongitude()); //$NON-NLS-1$
if(ApplicationMode.PEDESTRIAN == params.mode){
uri.append("&v=foot") ; //$NON-NLS-1$
} else if(ApplicationMode.BICYCLE == params.mode){
if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
uri.append("&v=bicycle") ; //$NON-NLS-1$
} else {
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
uri.append("&v=foot") ; //$NON-NLS-1$
} else if(params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)){
uri.append("&v=motorcar"); //$NON-NLS-1$
} else {
return applicationModeNotSupported(params);
}
uri.append("&fast=").append(params.fast ? "1" : "0").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.info("URL route " + uri);
@ -349,12 +351,14 @@ public class RouteProvider {
config = RoutingConfiguration.getDefault();
}
GeneralRouterProfile p ;
if (params.mode == ApplicationMode.BICYCLE) {
if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
p = GeneralRouterProfile.BICYCLE;
} else if (params.mode == ApplicationMode.PEDESTRIAN) {
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
p = GeneralRouterProfile.PEDESTRIAN;
} else {
} else if(params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)){
p = GeneralRouterProfile.CAR;
} else {
return applicationModeNotSupported(params);
}
// order matters
List<String> specs = new ArrayList<String>();
@ -417,10 +421,10 @@ public class RouteProvider {
return new RouteCalculationResult("Route can not be found from end point (" +ctx.calculationProgress.distanceFromEnd/1000f+" km)");
}
if(ctx.calculationProgress.isCancelled) {
return new RouteCalculationResult("Route calculation was interrupted");
return interrupted();
}
// something really strange better to see that message on the scren
return new RouteCalculationResult("Empty result");
return emptyResult();
} else {
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
params.intermediates, params.ctx, params.leftSide, ctx.routingTime);
@ -429,7 +433,7 @@ public class RouteProvider {
} catch (RuntimeException e) {
return new RouteCalculationResult(e.getMessage() );
} catch (InterruptedException e) {
return new RouteCalculationResult("Route calculation was interrupted");
return interrupted();
} catch (OutOfMemoryError e) {
// ActivityManager activityManager = (ActivityManager)app.getSystemService(Context.ACTIVITY_SERVICE);
// ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
@ -443,6 +447,21 @@ public class RouteProvider {
}
private RouteCalculationResult applicationModeNotSupported(RouteCalculationParams params) {
return new RouteCalculationResult("Application mode '"+ params.mode.toHumanStringCtx(params.ctx)+ "'is not supported.");
}
private RouteCalculationResult interrupted() {
return new RouteCalculationResult("Route calculation was interrupted");
}
private RouteCalculationResult emptyResult() {
return new RouteCalculationResult("Empty result");
}
protected RouteCalculationResult findCloudMadeRoute(RouteCalculationParams params)
throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
List<Location> res = new ArrayList<Location>();
@ -470,27 +489,27 @@ public class RouteProvider {
uri.append(params.end.getLatitude() + "").append(","); //$NON-NLS-1$//$NON-NLS-2$
uri.append(params.end.getLongitude() + "").append("/"); //$NON-NLS-1$ //$NON-NLS-2$
float speed = 1.5f;
if (ApplicationMode.PEDESTRIAN == params.mode) {
if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
uri.append("foot.gpx"); //$NON-NLS-1$
} else if (ApplicationMode.BICYCLE == params.mode) {
speed = 4.2f;
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
uri.append("bicycle.gpx"); //$NON-NLS-1$
} else {
speed = 15.3f;
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
if (params.fast) {
uri.append("car.gpx"); //$NON-NLS-1$
} else {
uri.append("car/shortest.gpx"); //$NON-NLS-1$
}
} else {
return applicationModeNotSupported(params);
}
uri.append("?lang=").append(Locale.getDefault().getLanguage()); //$NON-NLS-1$
log.info("URL route " + uri);
URL url = new URL(uri.toString());
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", Version.getFullVersion(params.ctx));
GPXFile gpxFile = GPXUtilities.loadGPXFile(params.ctx, connection.getInputStream(), false);
directions = parseCloudmadeRoute(res, gpxFile, false, params.leftSide, speed);
directions = parseCloudmadeRoute(res, gpxFile, false, params.leftSide, params.mode.getDefaultSpeed());
return new RouteCalculationResult(res, directions, params, null);
}
@ -616,9 +635,9 @@ public class RouteProvider {
List<Location> res = new ArrayList<Location>();
String rpref = "Fastest";
if (ApplicationMode.PEDESTRIAN == params.mode) {
if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
rpref = "Pedestrian";
} else if (ApplicationMode.BICYCLE == params.mode) {
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
rpref = "Bicycle";
// } else if (ApplicationMode.LOWTRAFFIC == mode) {
// rpref = "BicycleSafety";
@ -628,9 +647,13 @@ public class RouteProvider {
// rpref = "BicycleRoute";
// } else if (ApplicationMode.MTBIKE == mode) {
// rpref = "BicycleMTB";
} else if (!params.fast) {
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
if (!params.fast) {
rpref = "Shortest";
}
} else {
return applicationModeNotSupported(params);
}
StringBuilder request = new StringBuilder();
request.append("http://openls.geog.uni-heidelberg.de/osm/eu/routing?").append("start=").append(params.start.getLongitude()).append(',')

View file

@ -104,7 +104,7 @@ public class VoiceRouter {
// lead time criterion only for TURN_IN and TURN
PREPARE_LONG_DISTANCE = 3500; // [105 sec] - 120 km/h
PREPARE_LONG_DISTANCE_END = 3000; // [ 90 sec] - 120 km/h
if(router.getAppMode() == ApplicationMode.PEDESTRIAN){
if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)){
// prepare_long_distance warning not needed for pedestrian
PREPARE_LONG_DISTANCE_END = PREPARE_LONG_DISTANCE + 100; // do not play
// prepare distance is not needed for pedestrian
@ -116,7 +116,7 @@ public class VoiceRouter {
TURN_IN_DISTANCE_END = 30; // 15 sec (was 70m, 35 sec)
TURN_DISTANCE = 15; // 7,5sec (was 25m, 12 sec). Check if this works with GPS accuracy!
TURN_DEFAULT_SPEED = DEFAULT_SPEED = 2f; // 7,2 km/h
} else if(router.getAppMode() == ApplicationMode.BICYCLE){
} else if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.BICYCLE)){
PREPARE_LONG_DISTANCE = 500; // [100 sec]
PREPARE_LONG_DISTANCE_END = 300; // [ 60 sec]
PREPARE_DISTANCE = 200; // [ 40 sec] (was 500m, 100sec)
@ -125,7 +125,7 @@ public class VoiceRouter {
TURN_IN_DISTANCE_END = 60; // 12 sec (was 80m, 16sec)
TURN_DISTANCE = 30; // 6 sec (was 45m, 9sec). Check if this works with GPS accuracy!
TURN_DEFAULT_SPEED = DEFAULT_SPEED = 5; // 18 km/h
} else {
} else if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.CAR)){
PREPARE_DISTANCE = 1500; // [125 sec]
PREPARE_DISTANCE_END = 1200; // [100 sec]
TURN_IN_DISTANCE = 390; // 30 sec
@ -133,6 +133,16 @@ public class VoiceRouter {
TURN_DISTANCE = 50; // 7 sec
TURN_DEFAULT_SPEED = 7f; // 25 km/h
DEFAULT_SPEED = 13; // 48 km/h
} else {
DEFAULT_SPEED = router.getAppMode().getDefaultSpeed();
TURN_DEFAULT_SPEED = DEFAULT_SPEED / 2;
PREPARE_LONG_DISTANCE = (int) (DEFAULT_SPEED * 305);
PREPARE_LONG_DISTANCE_END = (int) (DEFAULT_SPEED * 225);
PREPARE_DISTANCE = (int) (DEFAULT_SPEED * 125);
PREPARE_DISTANCE_END = (int) (DEFAULT_SPEED * 100);
TURN_IN_DISTANCE = (int) (DEFAULT_SPEED * 30);
TURN_IN_DISTANCE_END = (int) (DEFAULT_SPEED * 14);
TURN_DISTANCE = (int) (DEFAULT_SPEED * 7);
}
}