Fix default routing config builder

This commit is contained in:
vshcherb 2014-03-22 01:45:42 +01:00
parent 1840f61f72
commit 4624a5811a
5 changed files with 35 additions and 25 deletions

View file

@ -36,7 +36,7 @@ public class CurrentPositionHelper {
} else {
return;
}
RoutingConfiguration cfg = RoutingConfiguration.getDefault().build(p.name().toLowerCase(), 10);
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10);
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles());
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
@ -39,7 +40,11 @@ import net.osmand.plus.voice.CommandPlayer;
import net.osmand.plus.voice.CommandPlayerException;
import net.osmand.plus.voice.CommandPlayerFactory;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
@ -100,6 +105,7 @@ public class OsmandApplication extends Application implements ClientContext {
private SavingTrackHelper savingTrackHelper;
private LiveMonitoringHelper liveMonitoringHelper;
private TargetPointsHelper targetPointsHelper;
private RoutingConfiguration.Builder defaultRoutingConfig;
private boolean applicationInitializing = false;
private Locale prefferedLocale = null;
@ -795,6 +801,24 @@ public class OsmandApplication extends Application implements ClientContext {
}
}
public RoutingConfiguration.Builder getDefaultRoutingConfig() {
if (defaultRoutingConfig == null) {
File routingXml = getAppPath(IndexConstants.ROUTING_XML_FILE);
if (routingXml.exists() && routingXml.canRead()) {
try {
defaultRoutingConfig = RoutingConfiguration.parseFromInputStream(new FileInputStream(routingXml));
} catch (XmlPullParserException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
defaultRoutingConfig = RoutingConfiguration.getDefault();
}
}
return defaultRoutingConfig;
}
public boolean accessibilityExtensions() {
return (Build.VERSION.SDK_INT < 14) ? getSettings().ACCESSIBILITY_EXTENSIONS.get() : false;
}

View file

@ -18,7 +18,6 @@ import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.router.RoutingConfiguration;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
@ -128,7 +127,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
cat.addPreference(fastRoute);
} else {
ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(am);
GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();
@ -189,10 +188,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
public static GeneralRouter getRouter(ApplicationMode am) {
GeneralRouter router = RoutingConfiguration.getDefault().getRouter(am.getStringKey());
public static GeneralRouter getRouter(net.osmand.router.RoutingConfiguration.Builder builder, ApplicationMode am) {
GeneralRouter router = builder.getRouter(am.getStringKey());
if(router == null && am.getParent() != null) {
router = RoutingConfiguration.getDefault().getRouter(am.getParent().getStringKey());
router = builder.getRouter(am.getParent().getStringKey());
}
return router;
}

View file

@ -1,8 +1,6 @@
package net.osmand.plus.routing;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
@ -23,7 +21,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
@ -53,6 +50,7 @@ import net.osmand.router.RoutePlannerFrontEnd;
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingConfiguration.Builder;
import net.osmand.router.RoutingContext;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
@ -65,7 +63,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import btools.routingapp.IBRouterService;
@ -462,11 +459,12 @@ public class RouteProvider {
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
OsmandSettings settings = params.ctx.getSettings();
GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(params.mode);
RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(config, params.mode);
if(generalRouter == null) {
return applicationModeNotSupported(params);
}
RoutingConfiguration cf = initOsmAndRoutingConfig(params, settings, generalRouter);
RoutingConfiguration cf = initOsmAndRoutingConfig(config, params, settings, generalRouter);
if(cf == null){
return applicationModeNotSupported(params);
}
@ -512,19 +510,8 @@ public class RouteProvider {
private RoutingConfiguration initOsmAndRoutingConfig(final RouteCalculationParams params, OsmandSettings settings,
private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings,
GeneralRouter generalRouter) throws IOException, FileNotFoundException {
File routingXml = params.ctx.getAppPath(IndexConstants.ROUTING_XML_FILE);
RoutingConfiguration.Builder config ;
if (routingXml.exists() && routingXml.canRead()) {
try {
config = RoutingConfiguration.parseFromInputStream(new FileInputStream(routingXml));
} catch (XmlPullParserException e) {
throw new IllegalStateException(e);
}
} else {
config = RoutingConfiguration.getDefault();
}
GeneralRouterProfile p ;
if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
p = GeneralRouterProfile.BICYCLE;

View file

@ -175,7 +175,7 @@ public class MapRoutePreferencesControl extends MapControls {
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GeneralRouter rm = SettingsNavigationActivity.getRouter(am);
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
if(rparams != null) {
list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route,