Reset default app mode speed in settings

This commit is contained in:
Vitaliy 2020-01-26 17:57:54 +02:00
parent a2facffc5c
commit 13b61b061e
2 changed files with 23 additions and 21 deletions

View file

@ -73,7 +73,6 @@ public class ApplicationMode {
private RouteService routeService = RouteService.OSMAND;
private float defaultSpeed = 10f;
private float initialDefaultSpeed = defaultSpeed;
private int minDistanceForTurn = 50;
private int arrivalDistance = 90;
private int offRouteDistance = 350;
@ -223,7 +222,6 @@ public class ApplicationMode {
private ApplicationMode customReg() {
ApplicationMode m = applicationMode;
m.defaultSpeed = m.parentAppMode.defaultSpeed;
m.initialDefaultSpeed = m.parentAppMode.initialDefaultSpeed;
m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn;
m.arrivalDistance = m.parentAppMode.arrivalDistance;
m.offRouteDistance = m.parentAppMode.offRouteDistance;
@ -253,17 +251,7 @@ public class ApplicationMode {
}
public ApplicationModeBuilder icon(Context app, String iconResName) {
try {
int iconRes = app.getResources().getIdentifier(iconResName, "drawable", app.getPackageName());
int iconMapRes = app.getResources().getIdentifier(iconResName.replace("ic_", "map_"), "drawable", app.getPackageName());
if (iconRes != 0 && iconMapRes != 0) {
applicationMode.iconResName = iconResName;
applicationMode.iconRes = iconRes;
applicationMode.iconMapRes = iconMapRes;
}
} catch (Exception e) {
// return R.drawable.map_world_globe_dark;
}
updateAppModeIcon(app, iconResName, applicationMode);
return this;
}
@ -284,7 +272,6 @@ public class ApplicationMode {
public ApplicationModeBuilder speed(float defSpeed, int distForTurn) {
applicationMode.defaultSpeed = defSpeed;
applicationMode.initialDefaultSpeed = defSpeed;
applicationMode.minDistanceForTurn = distForTurn;
return this;
}
@ -325,6 +312,20 @@ public class ApplicationMode {
}
}
private static void updateAppModeIcon(Context app, String iconResName, ApplicationMode mode) {
try {
int iconRes = app.getResources().getIdentifier(iconResName, "drawable", app.getPackageName());
int iconMapRes = app.getResources().getIdentifier(iconResName.replace("ic_", "map_"), "drawable", app.getPackageName());
if (iconRes != 0 && iconMapRes != 0) {
mode.iconResName = iconResName;
mode.iconRes = iconRes;
mode.iconMapRes = iconMapRes;
}
} catch (Exception e) {
// return R.drawable.map_world_globe_dark;
}
}
private static ApplicationModeBuilder create(ApplicationMode parent, int key, String stringKey) {
ApplicationModeBuilder builder = new ApplicationModeBuilder();
builder.applicationMode = new ApplicationMode(key, stringKey);
@ -544,8 +545,9 @@ public class ApplicationMode {
}
public void resetDefaultSpeed(OsmandApplication app) {
this.defaultSpeed = initialDefaultSpeed;
app.getSettings().DEFAULT_SPEED.setModeValue(this, 0f);
OsmandSettings settings = app.getSettings();
settings.DEFAULT_SPEED.resetModeToDefault(this);
this.defaultSpeed = settings.DEFAULT_SPEED.getModeValue(this);
}
public int getMinDistanceForTurn() {

View file

@ -1489,11 +1489,11 @@ public class OsmandSettings {
{
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.DEFAULT, "ic_world_globe_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.CAR, "ic_action_car");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.BICYCLE, "ic_action_bicycle");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.PEDESTRIAN, "ic_action_pedestrian");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.PUBLIC_TRANSPORT, "ic_action_bus");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.BOAT, "ic_action_sail_boat");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.CAR, "ic_action_car_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.BICYCLE, "ic_action_bicycle_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.PEDESTRIAN, "ic_action_pedestrian_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.PUBLIC_TRANSPORT, "ic_action_bus_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.BOAT, "ic_action_sail_boat_dark");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.AIRCRAFT, "ic_action_aircraft");
ICON_RES_NAME.setModeDefaultValue(ApplicationMode.SKI, "ic_action_skiing");
}