changing route reading

fix getRouting method (now it looks for routing profile name, not application profile stringKey
This commit is contained in:
madwasp79 2019-05-16 17:24:48 +03:00
parent 00d38d5170
commit d70dfd129b
7 changed files with 55 additions and 108 deletions

View file

@ -22,8 +22,7 @@ import java.util.Stack;
public class RoutingConfiguration { public class RoutingConfiguration {
private static final Log LOG = PlatformUtil.getLog(RoutingConfiguration.class); private static final Log LOG = PlatformUtil.getLog(RoutingConfiguration.class);
public static final String DEFAULT_ROUTING_PROFILES = "default_routing_profiles";
public static final int DEFAULT_MEMORY_LIMIT = 30; public static final int DEFAULT_MEMORY_LIMIT = 30;
public final float DEVIATION_RADIUS = 3000; public final float DEVIATION_RADIUS = 3000;
public Map<String, String> attributes = new LinkedHashMap<String, String>(); public Map<String, String> attributes = new LinkedHashMap<String, String>();
@ -50,14 +49,14 @@ public class RoutingConfiguration {
// 1.5 Recalculate distance help // 1.5 Recalculate distance help
public float recalculateDistance = 20000f; public float recalculateDistance = 20000f;
public static class Builder { public static class Builder {
// Design time storage // Design time storage
private static String defaultRouter = ""; private String defaultRouter = "";
private static Map<String, GeneralRouter> routers = new LinkedHashMap<>(); private Map<String, GeneralRouter> routers = new LinkedHashMap<>();
private static Map<String, String> attributes = new LinkedHashMap<>(); private Map<String, String> attributes = new LinkedHashMap<>();
private static HashMap<Long, Location> impassableRoadLocations = new HashMap<>(); private HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
// Example // Example
// { // {
@ -129,9 +128,9 @@ public class RoutingConfiguration {
public String getDefaultRouter() { public String getDefaultRouter() {
return defaultRouter; return defaultRouter;
} }
public GeneralRouter getRouter(String applicationMode) { public GeneralRouter getRouter(String routingProfileName) {
return routers.get(applicationMode); return routers.get(routingProfileName);
} }
@ -173,14 +172,12 @@ public class RoutingConfiguration {
return DEFAULT; return DEFAULT;
} }
public static RoutingConfiguration.Builder parseFromInputStream(InputStream is) throws IOException, XmlPullParserException { static RoutingConfiguration.Builder parseFromInputStream(InputStream is) throws IOException, XmlPullParserException {
return parseFromInputStream(is, null, new RoutingConfiguration.Builder());
return parseFromInputStream(is, null);
} }
public static RoutingConfiguration.Builder parseFromInputStream(InputStream is, String filename) throws IOException, XmlPullParserException { public static RoutingConfiguration.Builder parseFromInputStream(InputStream is, String filename, RoutingConfiguration.Builder config) throws IOException, XmlPullParserException {
XmlPullParser parser = PlatformUtil.newXMLPullParser(); XmlPullParser parser = PlatformUtil.newXMLPullParser();
RoutingConfiguration.Builder config = new RoutingConfiguration.Builder();
GeneralRouter currentRouter = null; GeneralRouter currentRouter = null;
RouteDataObjectAttribute currentAttribute = null; RouteDataObjectAttribute currentAttribute = null;
String preType = null; String preType = null;
@ -191,7 +188,7 @@ public class RoutingConfiguration {
if (tok == XmlPullParser.START_TAG) { if (tok == XmlPullParser.START_TAG) {
String name = parser.getName(); String name = parser.getName();
if ("osmand_routing_config".equals(name)) { if ("osmand_routing_config".equals(name)) {
Builder.defaultRouter = parser.getAttributeValue("", "defaultProfile"); config.defaultRouter = parser.getAttributeValue("", "defaultProfile");
} else if ("routingProfile".equals(name)) { } else if ("routingProfile".equals(name)) {
currentRouter = parseRoutingProfile(parser, config, filename); currentRouter = parseRoutingProfile(parser, config, filename);
} else if ("attribute".equals(name)) { } else if ("attribute".equals(name)) {
@ -308,10 +305,8 @@ public class RoutingConfiguration {
} }
} }
private static int count = 0;
private static GeneralRouter parseRoutingProfile(XmlPullParser parser, final RoutingConfiguration.Builder config, String filename) { private static GeneralRouter parseRoutingProfile(XmlPullParser parser, final RoutingConfiguration.Builder config, String filename) {
String currentSelectedRouter = parser.getAttributeValue("", "name"); String currentSelectedRouterName = parser.getAttributeValue("", "name");
Map<String, String> attrs = new LinkedHashMap<String, String>(); Map<String, String> attrs = new LinkedHashMap<String, String>();
for(int i=0; i< parser.getAttributeCount(); i++) { for(int i=0; i< parser.getAttributeCount(); i++) {
attrs.put(parser.getAttributeName(i), parser.getAttributeValue(i)); attrs.put(parser.getAttributeName(i), parser.getAttributeValue(i));
@ -319,15 +314,13 @@ public class RoutingConfiguration {
GeneralRouterProfile c = Algorithms.parseEnumValue(GeneralRouterProfile.values(), GeneralRouterProfile c = Algorithms.parseEnumValue(GeneralRouterProfile.values(),
parser.getAttributeValue("", "baseProfile"), GeneralRouterProfile.CAR); parser.getAttributeValue("", "baseProfile"), GeneralRouterProfile.CAR);
GeneralRouter currentRouter = new GeneralRouter(c, attrs); GeneralRouter currentRouter = new GeneralRouter(c, attrs);
currentRouter.setProfileName(currentSelectedRouter); currentRouter.setProfileName(currentSelectedRouterName);
if (filename != null) { if (filename != null) {
currentRouter.setFilename(filename); currentRouter.setFilename(filename);
currentSelectedRouterName = filename + "//" + currentSelectedRouterName;
} }
if (Builder.routers.containsKey(currentSelectedRouter)) {
count++; config.routers.put(currentSelectedRouterName, currentRouter);
currentSelectedRouter = currentSelectedRouter + currentRouter.hashCode();
}
Builder.routers.put(currentSelectedRouter, currentRouter);
return currentRouter; return currentRouter;
} }
@ -336,7 +329,7 @@ public class RoutingConfiguration {
currentRouter.addAttribute(parser.getAttributeValue("", "name"), currentRouter.addAttribute(parser.getAttributeValue("", "name"),
parser.getAttributeValue("", "value")); parser.getAttributeValue("", "value"));
} else { } else {
Builder.attributes.put(parser.getAttributeValue("", "name"), config.attributes.put(parser.getAttributeValue("", "name"),
parser.getAttributeValue("", "value")); parser.getAttributeValue("", "value"));
} }
} }

View file

@ -551,41 +551,35 @@ public class AppInitializer implements IProgress {
} }
@SuppressLint("StaticFieldLeak")
net.osmand.router.RoutingConfiguration.Builder getLazyDefaultRoutingConfig() { net.osmand.router.RoutingConfiguration.Builder getLazyRoutingConfig() {
long tm = System.currentTimeMillis(); long tm = System.currentTimeMillis();
try { try {
new AsyncTask<Void, Void, Void>() { RoutingConfiguration.Builder config = RoutingConfiguration.getDefault();
@Override File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
protected Void doInBackground(Void... voids) { if (routingFolder.isDirectory() && routingFolder.listFiles().length > 0) {
RoutingConfiguration.getDefault(); File[] fl = routingFolder.listFiles();
final File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR); for (File f : fl) {
if (routingFolder.isDirectory() && routingFolder.listFiles().length > 0) { if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
File[] fl = routingFolder.listFiles(); try {
for (File f : fl) { RoutingConfiguration
if (f.isFile() && f.canRead()) { .parseFromInputStream(new FileInputStream(f), f.getName(), config);
try { } catch (XmlPullParserException | IOException e) {
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName()); throw new IllegalStateException(e);
} catch (XmlPullParserException | IOException e) {
throw new IllegalStateException(e);
}
}
} }
} }
return null;
} }
}.executeOnExecutor(Executors.newSingleThreadExecutor(), (Void) null); }
return config;
return new RoutingConfiguration.Builder();
} finally { } finally {
long te = System.currentTimeMillis(); long te = System.currentTimeMillis();
if(te - tm > 30) { if (te - tm > 30) {
System.err.println("Default routing config init took " + (te - tm) + " ms"); System.err.println("Default routing config init took " + (te - tm) + " ms");
} }
} }
} }
public synchronized void initVoiceDataInDifferentThread(final Activity uiContext, public synchronized void initVoiceDataInDifferentThread(final Activity uiContext,
final ApplicationMode applicationMode, final ApplicationMode applicationMode,
final String voiceProvider, final String voiceProvider,

View file

@ -38,39 +38,23 @@ public class ApplicationMode {
icon(R.drawable.map_world_globe_dark, R.drawable.ic_world_globe_dark).reg(); icon(R.drawable.map_world_globe_dark, R.drawable.ic_world_globe_dark).reg();
public static final ApplicationMode CAR = create(R.string.app_mode_car, "car").speed(15.3f, 35).carLocation(). public static final ApplicationMode CAR = create(R.string.app_mode_car, "car").speed(15.3f, 35).carLocation().
icon(R.drawable.map_action_car_dark, R.drawable.ic_action_car_dark).reg(); icon(R.drawable.map_action_car_dark, R.drawable.ic_action_car_dark).setRoutingProfile("car").reg();
public static final ApplicationMode BICYCLE = create(R.string.app_mode_bicycle, "bicycle").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation(). public static final ApplicationMode BICYCLE = create(R.string.app_mode_bicycle, "bicycle").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
icon(R.drawable.map_action_bicycle_dark, R.drawable.ic_action_bicycle_dark).reg(); icon(R.drawable.map_action_bicycle_dark, R.drawable.ic_action_bicycle_dark).setRoutingProfile("bicycle").reg();
public static final ApplicationMode PEDESTRIAN = create(R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).arrivalDistance(45).offRouteDistance(20). public static final ApplicationMode PEDESTRIAN = create(R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).arrivalDistance(45).offRouteDistance(20).
icon(R.drawable.map_action_pedestrian_dark, R.drawable.ic_action_pedestrian_dark).reg(); icon(R.drawable.map_action_pedestrian_dark, R.drawable.ic_action_pedestrian_dark).setRoutingProfile("pedestrian").reg();
public static final ApplicationMode PUBLIC_TRANSPORT = create(R.string.app_mode_public_transport, "public_transport"). public static final ApplicationMode PUBLIC_TRANSPORT = create(R.string.app_mode_public_transport, "public_transport").
icon(R.drawable.map_action_bus_dark, R.drawable.ic_action_bus_dark).reg(); icon(R.drawable.map_action_bus_dark, R.drawable.ic_action_bus_dark).setRoutingProfile("public_transport").reg();
public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation(). public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation().
icon(R.drawable.map_action_sail_boat_dark, R.drawable.ic_action_sail_boat_dark).reg(); icon(R.drawable.map_action_sail_boat_dark, R.drawable.ic_action_sail_boat_dark).setRoutingProfile("boat").reg();
public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation(). public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
icon(R.drawable.map_action_aircraft, R.drawable.ic_action_aircraft).reg(); icon(R.drawable.map_action_aircraft, R.drawable.ic_action_aircraft).reg();
//---------------------------------------------------------------------------------------------------------------
// public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN).
// icon(R.drawable.map_action_trekking_dark, R.drawable.ic_action_trekking_dark).reg();
//
// public static final ApplicationMode MOTORCYCLE = create(R.string.app_mode_motorcycle, "motorcycle").speed(15.3f, 40).
// carLocation().parent(CAR).
// icon(R.drawable.map_action_motorcycle_dark, R.drawable.ic_action_motorcycle_dark).reg();
//
// public static final ApplicationMode TRUCK = create(R.string.app_mode_truck, "truck").speed(15.3f, 40).
// carLocation().parent(CAR).
// icon(R.drawable.map_action_truck_dark, R.drawable.ic_action_truck_dark).reg();
//
// public static final ApplicationMode TRAIN = create(R.string.app_mode_train, "train").speed(25f, 40).
// carLocation().icon(R.drawable.map_action_train, R.drawable.ic_action_train).reg();
String profile = "profile: ";
static { static {
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT}; ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT};
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, PUBLIC_TRANSPORT}; ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, PUBLIC_TRANSPORT};
@ -115,8 +99,6 @@ public class ApplicationMode {
regWidgetVisibility("bgService", none); regWidgetVisibility("bgService", none);
} }
public static class ApplicationModeBuilder { public static class ApplicationModeBuilder {
private ApplicationMode applicationMode; private ApplicationMode applicationMode;
@ -137,29 +119,21 @@ public class ApplicationMode {
return this; return this;
} }
public ApplicationModeBuilder parent(ApplicationMode parent) { public ApplicationModeBuilder parent(ApplicationMode parent) {
applicationMode.parent = parent; applicationMode.parent = parent;
String parentTypeName = parent.getStringKey();
if (parentTypeName.equals("car") || parentTypeName.equals("aircraft")) {
this.carLocation();
} else if (parentTypeName.equals("bicycle")) {
this.bicycleLocation();
} else if (parentTypeName.equals("boat")) {
this.nauticalLocation();
} else {
this.defLocation();
}
return this; return this;
} }
/**
* @param type - id of set of icons for different navigation styles:
* 1 - car, 2 - bicicle, 3 - nautical, any other - default
*/
public ApplicationModeBuilder setLocationAndBearingIcons(int type) {
applicationMode.mapIconsSetId = type;
switch (type) {
case 1:
return this.carLocation();
case 2:
return this.bicycleLocation();
case 3:
return this.nauticalLocation();
default:
return this.defLocation();
}
}
public ApplicationModeBuilder carLocation() { public ApplicationModeBuilder carLocation() {
applicationMode.bearingIconDay = R.drawable.map_car_bearing; applicationMode.bearingIconDay = R.drawable.map_car_bearing;
@ -477,7 +451,6 @@ public class ApplicationMode {
@Expose private final int key; @Expose private final int key;
@Expose private final String stringKey; @Expose private final String stringKey;
@Expose private String userProfileName; @Expose private String userProfileName;
@Expose private int mapIconsSetId = 0;
@Expose private ApplicationMode parent; @Expose private ApplicationMode parent;
@Expose private int mapIconId = R.drawable.map_world_globe_dark; @Expose private int mapIconId = R.drawable.map_world_globe_dark;
@Expose private int smallIconDark = R.drawable.ic_world_globe_dark; @Expose private int smallIconDark = R.drawable.ic_world_globe_dark;

View file

@ -809,7 +809,7 @@ public class OsmandApplication extends MultiDexApplication {
public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() { public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() {
if(defaultRoutingConfig == null) { if(defaultRoutingConfig == null) {
defaultRoutingConfig = appInitializer.getLazyDefaultRoutingConfig(); defaultRoutingConfig = appInitializer.getLazyRoutingConfig();
} }
return defaultRoutingConfig; return defaultRoutingConfig;
} }

View file

@ -358,9 +358,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
public static GeneralRouter getRouter(net.osmand.router.RoutingConfiguration.Builder builder, ApplicationMode am) { public static GeneralRouter getRouter(net.osmand.router.RoutingConfiguration.Builder builder, ApplicationMode am) {
GeneralRouter router = builder.getRouter(am.getStringKey()); GeneralRouter router = builder.getRouter(am.getRoutingProfile());
if(router == null && am.getParent() != null) { if(router == null && am.getParent() != null) {
router = builder.getRouter(am.getParent().getStringKey()); router = builder.getRouter(am.getParent().getRoutingProfile());
} }
return router; return router;
} }

View file

@ -635,19 +635,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
.parent(profile.parent) .parent(profile.parent)
.icon(profile.iconId, profile.iconId); .icon(profile.iconId, profile.iconId);
switch (profile.parent.getStringKey()) {
case "car":
case "aircraft":
builder.setLocationAndBearingIcons(1);
break;
case "bicycle":
builder.setLocationAndBearingIcons(2);
break;
case "boat":
builder.setLocationAndBearingIcons(3);
break;
}
if (profile.getRoutingProfile() != null) { if (profile.getRoutingProfile() != null) {
builder.setRoutingProfile(profile.getRoutingProfile().getStringKey()); builder.setRoutingProfile(profile.getRoutingProfile().getStringKey());
} }

View file

@ -447,7 +447,7 @@ public class TransportRoutingHelper {
BinaryMapIndexReader[] files = params.ctx.getResourceManager().getTransportRoutingMapFiles(); BinaryMapIndexReader[] files = params.ctx.getResourceManager().getTransportRoutingMapFiles();
params.params.clear(); params.params.clear();
OsmandSettings settings = params.ctx.getSettings(); OsmandSettings settings = params.ctx.getSettings();
for(Map.Entry<String, GeneralRouter.RoutingParameter> e : config.getRouter(params.mode.getStringKey()).getParameters().entrySet()){ for(Map.Entry<String, GeneralRouter.RoutingParameter> e : config.getRouter(params.mode.getRoutingProfile()).getParameters().entrySet()){
String key = e.getKey(); String key = e.getKey();
GeneralRouter.RoutingParameter pr = e.getValue(); GeneralRouter.RoutingParameter pr = e.getValue();
String vl; String vl;