changing route reading
fix getRouting method (now it looks for routing profile name, not application profile stringKey
This commit is contained in:
parent
00d38d5170
commit
d70dfd129b
7 changed files with 55 additions and 108 deletions
|
@ -22,8 +22,7 @@ import java.util.Stack;
|
|||
public class RoutingConfiguration {
|
||||
|
||||
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 final float DEVIATION_RADIUS = 3000;
|
||||
public Map<String, String> attributes = new LinkedHashMap<String, String>();
|
||||
|
@ -50,14 +49,14 @@ public class RoutingConfiguration {
|
|||
|
||||
// 1.5 Recalculate distance help
|
||||
public float recalculateDistance = 20000f;
|
||||
|
||||
|
||||
|
||||
public static class Builder {
|
||||
// Design time storage
|
||||
private static String defaultRouter = "";
|
||||
private static Map<String, GeneralRouter> routers = new LinkedHashMap<>();
|
||||
private static Map<String, String> attributes = new LinkedHashMap<>();
|
||||
private static HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
|
||||
private String defaultRouter = "";
|
||||
private Map<String, GeneralRouter> routers = new LinkedHashMap<>();
|
||||
private Map<String, String> attributes = new LinkedHashMap<>();
|
||||
private HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
|
||||
|
||||
// Example
|
||||
// {
|
||||
|
@ -129,9 +128,9 @@ public class RoutingConfiguration {
|
|||
public String getDefaultRouter() {
|
||||
return defaultRouter;
|
||||
}
|
||||
|
||||
public GeneralRouter getRouter(String applicationMode) {
|
||||
return routers.get(applicationMode);
|
||||
|
||||
public GeneralRouter getRouter(String routingProfileName) {
|
||||
return routers.get(routingProfileName);
|
||||
|
||||
}
|
||||
|
||||
|
@ -173,14 +172,12 @@ public class RoutingConfiguration {
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
public static RoutingConfiguration.Builder parseFromInputStream(InputStream is) throws IOException, XmlPullParserException {
|
||||
|
||||
return parseFromInputStream(is, null);
|
||||
static RoutingConfiguration.Builder parseFromInputStream(InputStream is) throws IOException, XmlPullParserException {
|
||||
return parseFromInputStream(is, null, new RoutingConfiguration.Builder());
|
||||
}
|
||||
|
||||
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();
|
||||
RoutingConfiguration.Builder config = new RoutingConfiguration.Builder();
|
||||
GeneralRouter currentRouter = null;
|
||||
RouteDataObjectAttribute currentAttribute = null;
|
||||
String preType = null;
|
||||
|
@ -191,7 +188,7 @@ public class RoutingConfiguration {
|
|||
if (tok == XmlPullParser.START_TAG) {
|
||||
String name = parser.getName();
|
||||
if ("osmand_routing_config".equals(name)) {
|
||||
Builder.defaultRouter = parser.getAttributeValue("", "defaultProfile");
|
||||
config.defaultRouter = parser.getAttributeValue("", "defaultProfile");
|
||||
} else if ("routingProfile".equals(name)) {
|
||||
currentRouter = parseRoutingProfile(parser, config, filename);
|
||||
} 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) {
|
||||
String currentSelectedRouter = parser.getAttributeValue("", "name");
|
||||
String currentSelectedRouterName = parser.getAttributeValue("", "name");
|
||||
Map<String, String> attrs = new LinkedHashMap<String, String>();
|
||||
for(int i=0; i< parser.getAttributeCount(); i++) {
|
||||
attrs.put(parser.getAttributeName(i), parser.getAttributeValue(i));
|
||||
|
@ -319,15 +314,13 @@ public class RoutingConfiguration {
|
|||
GeneralRouterProfile c = Algorithms.parseEnumValue(GeneralRouterProfile.values(),
|
||||
parser.getAttributeValue("", "baseProfile"), GeneralRouterProfile.CAR);
|
||||
GeneralRouter currentRouter = new GeneralRouter(c, attrs);
|
||||
currentRouter.setProfileName(currentSelectedRouter);
|
||||
currentRouter.setProfileName(currentSelectedRouterName);
|
||||
if (filename != null) {
|
||||
currentRouter.setFilename(filename);
|
||||
currentSelectedRouterName = filename + "//" + currentSelectedRouterName;
|
||||
}
|
||||
if (Builder.routers.containsKey(currentSelectedRouter)) {
|
||||
count++;
|
||||
currentSelectedRouter = currentSelectedRouter + currentRouter.hashCode();
|
||||
}
|
||||
Builder.routers.put(currentSelectedRouter, currentRouter);
|
||||
|
||||
config.routers.put(currentSelectedRouterName, currentRouter);
|
||||
return currentRouter;
|
||||
}
|
||||
|
||||
|
@ -336,7 +329,7 @@ public class RoutingConfiguration {
|
|||
currentRouter.addAttribute(parser.getAttributeValue("", "name"),
|
||||
parser.getAttributeValue("", "value"));
|
||||
} else {
|
||||
Builder.attributes.put(parser.getAttributeValue("", "name"),
|
||||
config.attributes.put(parser.getAttributeValue("", "name"),
|
||||
parser.getAttributeValue("", "value"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
try {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
RoutingConfiguration.getDefault();
|
||||
final File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
if (routingFolder.isDirectory() && routingFolder.listFiles().length > 0) {
|
||||
File[] fl = routingFolder.listFiles();
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName());
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
RoutingConfiguration.Builder config = RoutingConfiguration.getDefault();
|
||||
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
|
||||
if (routingFolder.isDirectory() && routingFolder.listFiles().length > 0) {
|
||||
File[] fl = routingFolder.listFiles();
|
||||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration
|
||||
.parseFromInputStream(new FileInputStream(f), f.getName(), config);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(Executors.newSingleThreadExecutor(), (Void) null);
|
||||
|
||||
return new RoutingConfiguration.Builder();
|
||||
|
||||
}
|
||||
return config;
|
||||
} finally {
|
||||
long te = System.currentTimeMillis();
|
||||
if(te - tm > 30) {
|
||||
if (te - tm > 30) {
|
||||
System.err.println("Default routing config init took " + (te - tm) + " ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void initVoiceDataInDifferentThread(final Activity uiContext,
|
||||
final ApplicationMode applicationMode,
|
||||
final String voiceProvider,
|
||||
|
|
|
@ -38,39 +38,23 @@ public class ApplicationMode {
|
|||
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().
|
||||
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().
|
||||
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).
|
||||
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").
|
||||
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().
|
||||
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().
|
||||
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 {
|
||||
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT};
|
||||
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, PUBLIC_TRANSPORT};
|
||||
|
@ -115,8 +99,6 @@ public class ApplicationMode {
|
|||
regWidgetVisibility("bgService", none);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class ApplicationModeBuilder {
|
||||
private ApplicationMode applicationMode;
|
||||
|
||||
|
@ -137,29 +119,21 @@ public class ApplicationMode {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationModeBuilder parent(ApplicationMode 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
applicationMode.bearingIconDay = R.drawable.map_car_bearing;
|
||||
|
@ -477,7 +451,6 @@ public class ApplicationMode {
|
|||
@Expose private final int key;
|
||||
@Expose private final String stringKey;
|
||||
@Expose private String userProfileName;
|
||||
@Expose private int mapIconsSetId = 0;
|
||||
@Expose private ApplicationMode parent;
|
||||
@Expose private int mapIconId = R.drawable.map_world_globe_dark;
|
||||
@Expose private int smallIconDark = R.drawable.ic_world_globe_dark;
|
||||
|
|
|
@ -809,7 +809,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
|
||||
public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() {
|
||||
if(defaultRoutingConfig == null) {
|
||||
defaultRoutingConfig = appInitializer.getLazyDefaultRoutingConfig();
|
||||
defaultRoutingConfig = appInitializer.getLazyRoutingConfig();
|
||||
}
|
||||
return defaultRoutingConfig;
|
||||
}
|
||||
|
|
|
@ -358,9 +358,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
|
||||
|
||||
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) {
|
||||
router = builder.getRouter(am.getParent().getStringKey());
|
||||
router = builder.getRouter(am.getParent().getRoutingProfile());
|
||||
}
|
||||
return router;
|
||||
}
|
||||
|
|
|
@ -635,19 +635,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
.parent(profile.parent)
|
||||
.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) {
|
||||
builder.setRoutingProfile(profile.getRoutingProfile().getStringKey());
|
||||
}
|
||||
|
|
|
@ -447,7 +447,7 @@ public class TransportRoutingHelper {
|
|||
BinaryMapIndexReader[] files = params.ctx.getResourceManager().getTransportRoutingMapFiles();
|
||||
params.params.clear();
|
||||
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();
|
||||
GeneralRouter.RoutingParameter pr = e.getValue();
|
||||
String vl;
|
||||
|
|
Loading…
Reference in a new issue