settings change

This commit is contained in:
MadWasp79 2020-02-14 11:16:06 +02:00
parent 640fb6af3d
commit 1578f4c91c
8 changed files with 40 additions and 26 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="no_recalculation_setting">Disable recalculation</string>
<string name="open_settings">Open settings</string> <string name="open_settings">Open settings</string>
<string name="plugin_disabled">Plugin disabled</string> <string name="plugin_disabled">Plugin disabled</string>
<string name="plugin_disabled_descr">This plugin is a separate application, you will need to remove it separately if you no longer plan to use it.\n\nThe plugin will remain on the device after removing OsmAnd.</string> <string name="plugin_disabled_descr">This plugin is a separate application, you will need to remove it separately if you no longer plan to use it.\n\nThe plugin will remain on the device after removing OsmAnd.</string>

View file

@ -451,7 +451,7 @@ public class OsmandSettings {
public void copyProfilePreferences(ApplicationMode modeFrom, ApplicationMode modeTo, List<OsmandPreference> profilePreferences) { public void copyProfilePreferences(ApplicationMode modeFrom, ApplicationMode modeTo, List<OsmandPreference> profilePreferences) {
for (OsmandPreference pref : profilePreferences) { for (OsmandPreference pref : profilePreferences) {
if (prefCanBeCopiedOrReset(pref) && !USER_PROFILE_NAME.getId().equals(pref.getId())) { if (prefCanBeCopiedOrReset(pref) && !USER_PROFILE_NAME.getId().equals(pref.getId()) && !ROUTE_RECALCULATION_DISTANCE.getId().equals(pref.getId())) {
CommonPreference profilePref = (CommonPreference) pref; CommonPreference profilePref = (CommonPreference) pref;
if (PARENT_APP_MODE.getId().equals(pref.getId())) { if (PARENT_APP_MODE.getId().equals(pref.getId())) {
if (modeTo.isCustomProfile()) { if (modeTo.isCustomProfile()) {
@ -1465,7 +1465,7 @@ public class OsmandSettings {
@Override @Override
public SpeedConstants getProfileDefaultValue(ApplicationMode mode) { public SpeedConstants getProfileDefaultValue(ApplicationMode mode) {
MetricsConstants mc = METRIC_SYSTEM.get(); MetricsConstants mc = METRIC_SYSTEM.getModeValue(mode);
if (mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { if (mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
if (mc == MetricsConstants.KILOMETERS_AND_METERS) { if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
return SpeedConstants.MINUTES_PER_KILOMETER; return SpeedConstants.MINUTES_PER_KILOMETER;
@ -3282,7 +3282,15 @@ public class OsmandSettings {
return customBooleanRoutingProps.get(attrName); return customBooleanRoutingProps.get(attrName);
} }
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", -1.f).makeProfile(); public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference("routing_recalc_distance", 0.f){
@Override
public Float getProfileDefaultValue(ApplicationMode mode) {
if (mode.getRouteService() == RouteService.DIRECT_TO) {
return -1.0f;
}
return super.getProfileDefaultValue(mode);
}
}.makeProfile();
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference("enable_osmc_routing", true).makeGlobal(); public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference("enable_osmc_routing", true).makeGlobal();

View file

@ -353,7 +353,8 @@ public class MeasurementEditingContext {
} }
} }
}; };
params.routeRecalculationDistance
= application.getSettings().ROUTE_RECALCULATION_DISTANCE.getModeValue(snapToRoadAppMode);
return params; return params;
} }

View file

@ -35,7 +35,6 @@ public class RouteCalculationParams {
public RouteCalculationResultListener resultListener; public RouteCalculationResultListener resultListener;
public boolean showOriginalRoute; public boolean showOriginalRoute;
public boolean noRecalculations;
public float routeRecalculationDistance; public float routeRecalculationDistance;
public interface RouteCalculationResultListener { public interface RouteCalculationResultListener {

View file

@ -63,9 +63,9 @@ public class RouteCalculationResult {
protected int currentWaypointGPX = 0; protected int currentWaypointGPX = 0;
protected int lastWaypointGPX = 0; protected int lastWaypointGPX = 0;
protected ApplicationMode appMode; protected ApplicationMode appMode;
protected boolean noRecalculations = false;
protected boolean showOriginalRoute = false; protected boolean showOriginalRoute = false;
protected float routeRecalcDistance = -1f; protected float routeRecalcDistance = 0.f;
public RouteCalculationResult(String errorMessage) { public RouteCalculationResult(String errorMessage) {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
@ -114,9 +114,10 @@ public class RouteCalculationResult {
updateDirectionsTime(this.directions, this.listDistance); updateDirectionsTime(this.directions, this.listDistance);
this.showOriginalRoute = params.showOriginalRoute; this.showOriginalRoute = params.showOriginalRoute;
this.noRecalculations = params.noRecalculations;
if (params.routeRecalculationDistance != 0) if (params.routeRecalculationDistance != 0.f) {
this.routeRecalcDistance = params.routeRecalculationDistance; this.routeRecalcDistance = params.routeRecalculationDistance;
}
} }
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates, public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,

View file

@ -1262,7 +1262,6 @@ public class RouteProvider {
private RouteCalculationResult findDirectTo(RouteCalculationParams params) { private RouteCalculationResult findDirectTo(RouteCalculationParams params) {
params.showOriginalRoute = true; params.showOriginalRoute = true;
params.noRecalculations = true;
double[] lats = new double[] { params.start.getLatitude(), params.end.getLatitude() }; double[] lats = new double[] { params.start.getLatitude(), params.end.getLatitude() };
double[] lons = new double[] { params.start.getLongitude(), params.end.getLongitude() }; double[] lons = new double[] { params.start.getLongitude(), params.end.getLongitude() };
List<LatLon> intermediates = params.intermediates; List<LatLon> intermediates = params.intermediates;

View file

@ -441,8 +441,8 @@ public class RoutingHelper {
// 2. Analyze if we need to recalculate route // 2. Analyze if we need to recalculate route
// >100m off current route (sideways) or parameter (for Straight line) // >100m off current route (sideways) or parameter (for Straight line)
if (currentRoute > 0 && !route.noRecalculations) { if (currentRoute > 0 && route.getRouteRecalcDistance() >= 0.f) {
double allowableDeviation = route.routeRecalcDistance <= 0 ? (1.7 * posTolerance) : route.routeRecalcDistance; double allowableDeviation = route.routeRecalcDistance == 0 ? (1.7 * posTolerance) : route.routeRecalcDistance;
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute)); distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > allowableDeviation)) { if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > allowableDeviation)) {
log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$ log.info("Recalculate route, because correlation : " + distOrth); //$NON-NLS-1$
@ -453,9 +453,9 @@ public class RoutingHelper {
// 3. Identify wrong movement direction // 3. Identify wrong movement direction
Location next = route.getNextRouteLocation(); Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next); boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
double allowableDeviation = route.routeRecalcDistance <= 0 ? (2 * posTolerance) : route.routeRecalcDistance; double allowableDeviation = route.routeRecalcDistance == 0.f ? (2 * posTolerance) : route.routeRecalcDistance;
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection
&& (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation) && !route.noRecalculations) { && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > allowableDeviation) && route.getRouteRecalcDistance() >= 0) {
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$ log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute))); //$NON-NLS-1$
isDeviatedFromRoute = true; isDeviatedFromRoute = true;
calculateRoute = true; calculateRoute = true;
@ -467,15 +467,15 @@ public class RoutingHelper {
// 5. Update Voice router // 5. Update Voice router
// Do not update in route planning mode // Do not update in route planning mode
if (isFollowingMode) { if (isFollowingMode) {
boolean inRecalc = calculateRoute || isRouteBeingCalculated(); boolean inRecalc = (calculateRoute || isRouteBeingCalculated());
if (!inRecalc && !wrongMovementDirection) { if (!inRecalc && !wrongMovementDirection) {
voiceRouter.updateStatus(currentLocation, false); voiceRouter.updateStatus(currentLocation, false);
voiceRouterStopped = false; voiceRouterStopped = false;
} else if (isDeviatedFromRoute && !voiceRouterStopped && !route.noRecalculations) { } else if (isDeviatedFromRoute && !voiceRouterStopped && route.getRouteRecalcDistance() >= 0.f) {
voiceRouter.interruptRouteCommands(); voiceRouter.interruptRouteCommands();
voiceRouterStopped = true; // Prevents excessive execution of stop() code voiceRouterStopped = true; // Prevents excessive execution of stop() code
} }
if (distOrth > mode.getOffRouteDistance() && !route.noRecalculations) { if (distOrth > mode.getOffRouteDistance() && route.getRouteRecalcDistance() >= 0.f) {
voiceRouter.announceOffRoute(distOrth); voiceRouter.announceOffRoute(distOrth);
} }
} }

View file

@ -143,7 +143,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
if (am.getRouteService() != RouteProvider.RouteService.OSMAND) { if (am.getRouteService() != RouteProvider.RouteService.OSMAND) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
if (am.getRouteService() == RouteProvider.RouteService.STRAIGHT) { if (am.getRouteService() == RouteProvider.RouteService.STRAIGHT) {
setupSelectRouteRecalcDistance(screen); setupSelectRouteRecalcDistance(screen, 1);
} else if (am.getRouteService() == RouteProvider.RouteService.DIRECT_TO) {
setupSelectRouteRecalcDistance(screen, 0);
} }
} else { } else {
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am); GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
@ -234,29 +236,32 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
} }
} }
private void setupSelectRouteRecalcDistance(PreferenceScreen screen) { private void setupSelectRouteRecalcDistance(PreferenceScreen screen, int defaultValue) {
Float[] entryValues; Float[] entryValues;
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get(); OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
entryValues = new Float[] {-1.0f, 10.f, 20.0f, 30.0f, 50.0f, 100.0f, 200.0f, 500.0f, 1000.0f, 1500.0f}; entryValues = new Float[] {-1.0f, 0.f, 10.f, 20.0f, 30.0f, 50.0f, 100.0f, 200.0f, 500.0f, 1000.0f, 1500.0f};
} else { } else {
entryValues = new Float[] {-1.0f, 9.1f, 18.3f, 30.5f, 45.7f, 91.5f, 183.0f, 482.0f, 965.0f, 1609.0f}; entryValues = new Float[] {-1.0f, 0.f, 9.1f, 18.3f, 30.5f, 45.7f, 91.5f, 183.0f, 482.0f, 965.0f, 1609.0f};
} }
String[] entries = new String[entryValues.length]; String[] entries = new String[entryValues.length];
entries[0] = getString(R.string.shared_string_not_selected); entries[0] = getString(R.string.no_recalculation_setting);
for (int i = 1; i < entryValues.length; i++) { entries[1] = getString(R.string.shared_string_default);
for (int i = 2; i < entryValues.length; i++) {
entries[i] = OsmAndFormatter.getFormattedDistance(entryValues[i], app, false); entries[i] = OsmAndFormatter.getFormattedDistance(entryValues[i], app, false);
} }
ListPreferenceEx routeRecalculationDist = createListPreferenceEx(settings.ROUTE_RECALCULATION_DISTANCE.getId(), ListPreferenceEx routeRecalculationDist = createListPreferenceEx(settings.ROUTE_RECALCULATION_DISTANCE.getId(),
entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr); entries, entryValues, R.string.route_recalculation_dist_title, R.layout.preference_with_descr);
routeRecalculationDist.setEntries(entries); routeRecalculationDist.setEntries(entries);
routeRecalculationDist.setEntryValues(entryValues); routeRecalculationDist.setEntryValues(entryValues);
routeRecalculationDist.setDescription(getString(R.string.route_recalculation_dist_descr)); routeRecalculationDist.setDescription(getString(R.string.route_recalculation_dist_descr));
routeRecalculationDist.setIcon(getRoutingPrefIcon("routing_recalc_distance")); routeRecalculationDist.setIcon(getRoutingPrefIcon("routing_recalc_distance"));
screen.addPreference(routeRecalculationDist); screen.addPreference(routeRecalculationDist);
} }