use of net.osmand.router.GeneralRouter.RoutingParameter in project Osmand by osmandapp.
the class SettingsNavigationActivity method prepareRoutingPrefs.
private void prepareRoutingPrefs(PreferenceScreen screen) {
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
cat.removeAll();
CheckBoxPreference fastRoute = createCheckBoxPreference(settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
if (settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
cat.addPreference(fastRoute);
} else {
ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();
if (parameters.containsKey("short_way")) {
cat.addPreference(fastRoute);
}
List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey();
RoutingParameter routingParameter = e.getValue();
if (param.startsWith("avoid_")) {
avoidParameters.add(routingParameter);
} else if (param.startsWith("prefer_")) {
preferParameters.add(routingParameter);
} else if ("relief_smoothness_factor".equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter);
} else if (!param.equals("short_way") && !"driving_style".equals(routingParameter.getGroup())) {
others.add(routingParameter);
}
}
if (avoidParameters.size() > 0) {
avoidRouting = new Preference(this);
avoidRouting.setTitle(R.string.avoid_in_routing_title);
avoidRouting.setSummary(R.string.avoid_in_routing_descr);
avoidRouting.setOnPreferenceClickListener(this);
cat.addPreference(avoidRouting);
}
if (preferParameters.size() > 0) {
preferRouting = new Preference(this);
preferRouting.setTitle(R.string.prefer_in_routing_title);
preferRouting.setSummary(R.string.prefer_in_routing_descr);
preferRouting.setOnPreferenceClickListener(this);
cat.addPreference(preferRouting);
}
if (reliefFactorParameters.size() > 0) {
reliefFactorRouting = new Preference(this);
reliefFactorRouting.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))));
reliefFactorRouting.setSummary(R.string.relief_smoothness_factor_descr);
reliefFactorRouting.setOnPreferenceClickListener(this);
cat.addPreference(reliefFactorRouting);
}
for (RoutingParameter p : others) {
Preference basePref;
if (p.getType() == RoutingParameterType.BOOLEAN) {
basePref = createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()));
} else {
Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length];
int i = 0;
for (Object o : vls) {
svlss[i++] = o.toString();
}
basePref = createListPreference(settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-"), p.getPossibleValueDescriptions(), svlss, SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()), SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
}
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
cat.addPreference(basePref);
}
}
ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.addPreference(speedLimitExceed);
} else {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.removePreference(speedLimitExceed);
}
}
}
use of net.osmand.router.GeneralRouter.RoutingParameter in project Osmand by osmandapp.
the class RoutePreferencesMenu method getRoutingParametersInner.
private List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
RouteProvider.GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.getModeValue(am) == RouteProvider.RouteService.OSMAND;
if (!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get()));
return list;
}
if (rparams != null) {
GPXUtilities.GPXFile fl = rparams.getFile();
if (fl.hasRtePt()) {
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates, getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
}
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
if (!rparams.isUseIntermediatePointsRTE()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
}
}
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getDefaultRoutingConfig(), am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return list;
}
for (RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
if ("relief_smoothness_factor".equals(r.getGroup())) {
continue;
}
if (!Algorithms.isEmpty(r.getGroup())) {
LocalRoutingParameterGroup rpg = getLocalRoutingParameterGroup(list, r.getGroup());
if (rpg == null) {
rpg = new LocalRoutingParameterGroup(am, r.getGroup());
list.add(rpg);
}
rpg.addRoutingParameter(r);
} else {
LocalRoutingParameter rp = new LocalRoutingParameter(am);
rp.routingParameter = r;
list.add(rp);
}
}
}
return list;
}
use of net.osmand.router.GeneralRouter.RoutingParameter in project Osmand by osmandapp.
the class SettingsNavigationActivity method onPreferenceClick.
@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == avoidRouting || preference == preferRouting) {
List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
String[] vals = new String[prms.size()];
OsmandPreference[] bls = new OsmandPreference[prms.size()];
for (int i = 0; i < prms.size(); i++) {
RoutingParameter p = prms.get(i);
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
}
showBooleanSettings(vals, bls, preference.getTitle());
return true;
} else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)).setSelected(false).createItem());
if (!settings.AUTO_ZOOM_MAP.get()) {
selectedIndex = 0;
}
i++;
for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
adapter.addItem(ContextMenuItem.createBuilder(getString(autoZoomMap.name)).setSelected(false).createItem());
if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(R.string.auto_zoom_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position == 0) {
settings.AUTO_ZOOM_MAP.set(false);
} else {
settings.AUTO_ZOOM_MAP.set(true);
settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position - 1]);
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == reliefFactorRouting) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
for (RoutingParameter p : reliefFactorParameters) {
adapter.addItem(ContextMenuItem.createBuilder(getRoutinParameterTitle(this, p)).setSelected(false).createItem());
if (isRoutingParameterSelected(settings, am, p)) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' ')))).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position >= 0 && position < reliefFactorParameters.size()) {
for (int i = 0; i < reliefFactorParameters.size(); i++) {
setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position);
}
// mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
// updateParameters();
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == showAlarms) {
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
return true;
} else if (preference == speakAlarms) {
AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.announce_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.speak_poi) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, settings.SPEAK_PEDESTRIAN, settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA, settings.ANNOUNCE_WPT, settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI }, preference.getTitle());
final boolean initialSpeedCam = settings.SPEAK_SPEED_CAMERA.get();
final boolean initialFavorites = settings.ANNOUNCE_NEARBY_FAVORITES.get();
final boolean initialPOI = settings.ANNOUNCE_NEARBY_POI.get();
// final boolean initialWpt = settings.ANNOUNCE_WPT.get();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (settings.ANNOUNCE_NEARBY_POI.get() != initialPOI) {
settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
}
if (settings.ANNOUNCE_NEARBY_FAVORITES.get() != initialFavorites) {
settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
}
if (settings.ANNOUNCE_WPT.get()) {
settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
}
if (!initialSpeedCam) {
if (settings.SPEAK_SPEED_CAMERA.get()) {
settings.SPEAK_SPEED_CAMERA.set(false);
confirmSpeedCamerasDlg();
}
}
}
});
return true;
}
return false;
}
use of net.osmand.router.GeneralRouter.RoutingParameter in project Osmand by osmandapp.
the class RouteProvider method initOsmAndRoutingConfig.
private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings, GeneralRouter generalRouter) throws IOException, FileNotFoundException {
GeneralRouterProfile p;
if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
p = GeneralRouterProfile.BICYCLE;
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
p = GeneralRouterProfile.PEDESTRIAN;
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
p = GeneralRouterProfile.CAR;
} else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BOAT)) {
p = GeneralRouterProfile.BOAT;
} else {
return null;
}
Map<String, String> paramsR = new LinkedHashMap<String, String>();
for (Map.Entry<String, RoutingParameter> e : generalRouter.getParameters().entrySet()) {
String key = e.getKey();
RoutingParameter pr = e.getValue();
String vl;
if (key.equals(GeneralRouter.USE_SHORTEST_WAY)) {
Boolean bool = !settings.FAST_ROUTE_MODE.getModeValue(params.mode);
vl = bool ? "true" : null;
} else if (pr.getType() == RoutingParameterType.BOOLEAN) {
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean());
Boolean bool = pref.getModeValue(params.mode);
vl = bool ? "true" : null;
} else {
vl = settings.getCustomRoutingProperty(key, "").getModeValue(params.mode);
}
if (vl != null && vl.length() > 0) {
paramsR.put(key, vl);
}
}
if (params.inSnapToRoadMode) {
paramsR.put(GeneralRouter.ALLOW_PRIVATE, "true");
}
float mb = (1 << 20);
Runtime rt = Runtime.getRuntime();
// make visible
int memoryLimit = (int) (0.95 * ((rt.maxMemory() - rt.totalMemory()) + rt.freeMemory()) / mb);
log.warn("Use " + memoryLimit + " MB Free " + rt.freeMemory() / mb + " of " + rt.totalMemory() / mb + " max " + rt.maxMemory() / mb);
RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ? params.start.getBearing() / 180d * Math.PI : null, memoryLimit, paramsR);
return cf;
}
Aggregations