Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#17096: Changed setting max speed for vehicle #17589

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ApplicationMode {

private ApplicationMode parentAppMode;
private int iconRes = R.drawable.ic_world_globe_dark;
private float maxSpeedConfigLimit = 0f;

private ApplicationMode(int key, @NonNull String stringKey) {
this.keyName = key;
Expand All @@ -65,49 +66,62 @@ private ApplicationMode(int key, @NonNull String stringKey) {

public static final ApplicationMode CAR = createBase(R.string.app_mode_car, "car")
.icon(R.drawable.ic_action_car_dark)
.setMaxSpeedConfigLimit(36.11111f)
.description(R.string.base_profile_descr_car).reg();

public static final ApplicationMode BICYCLE = createBase(R.string.app_mode_bicycle, "bicycle")
.icon(R.drawable.ic_action_bicycle_dark)
.setMaxSpeedConfigLimit(9.166667f)
.description(R.string.base_profile_descr_bicycle).reg();

public static final ApplicationMode PEDESTRIAN = createBase(R.string.app_mode_pedestrian, "pedestrian")
.icon(R.drawable.ic_action_pedestrian_dark)
.setMaxSpeedConfigLimit(2.777778f)
.description(R.string.base_profile_descr_pedestrian).reg();

public static final ApplicationMode TRUCK = create(CAR, R.string.app_mode_truck, "truck")
.icon(R.drawable.ic_action_truck_dark)
.setMaxSpeedConfigLimit(36.11111f)
.description(R.string.app_mode_truck).reg();

public static final ApplicationMode MOTORCYCLE = create(CAR, R.string.app_mode_motorcycle, "motorcycle")
.icon(R.drawable.ic_action_motorcycle_dark)
.setMaxSpeedConfigLimit(36.11111f)
.description(R.string.app_mode_motorcycle).reg();

public static final ApplicationMode MOPED = create(BICYCLE, R.string.app_mode_moped, "moped")
.setMaxSpeedConfigLimit(12.96296f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speed limit ?

.icon(R.drawable.ic_action_motor_scooter)
.description(R.string.app_mode_bicycle).reg();

public static final ApplicationMode PUBLIC_TRANSPORT = createBase(R.string.app_mode_public_transport, "public_transport")
.icon(R.drawable.ic_action_bus_dark)
.setMaxSpeedConfigLimit(26.388889f)
.description(R.string.base_profile_descr_public_transport).reg();

public static final ApplicationMode TRAIN = createBase(R.string.app_mode_train, "train")
.icon(R.drawable.ic_action_train)
.setMaxSpeedConfigLimit(47.222225f)
.description(R.string.app_mode_train).reg();

public static final ApplicationMode BOAT = createBase(R.string.app_mode_boat, "boat")
.icon(R.drawable.ic_action_sail_boat_dark)
.setMaxSpeedConfigLimit(18.527777f)
.description(R.string.base_profile_descr_boat).reg();

public static final ApplicationMode AIRCRAFT = createBase(R.string.app_mode_aircraft, "aircraft")
.icon(R.drawable.ic_action_aircraft)
.setMaxSpeedConfigLimit(200f)
.description(R.string.base_profile_descr_aircraft).reg();

public static final ApplicationMode SKI = createBase(R.string.app_mode_skiing, "ski")
.icon(R.drawable.ic_action_skiing)
.setMaxSpeedConfigLimit(41.666668f)
.description(R.string.base_profile_descr_ski).reg();

public static final ApplicationMode HORSE = createBase(R.string.horseback_riding, "horse")
.icon(R.drawable.ic_action_horse)
.setMaxSpeedConfigLimit(8.333334f)
.description(R.string.horseback_riding).reg();

public static List<ApplicationMode> values(@NonNull OsmandApplication app) {
Expand Down Expand Up @@ -455,6 +469,10 @@ public void setVersion(int version) {
app.getSettings().APP_MODE_VERSION.setModeValue(this, version);
}

public float getMaxSpeedConfigLimit() {
return maxSpeedConfigLimit;
}

public static void onApplicationStart(OsmandApplication app) {
initCustomModes(app);
initModesParams(app);
Expand Down Expand Up @@ -733,6 +751,11 @@ public ApplicationModeBuilder icon(int iconRes) {
return this;
}

public ApplicationModeBuilder setMaxSpeedConfigLimit(float maxSpeedConfigLimit) {
applicationMode.maxSpeedConfigLimit = maxSpeedConfigLimit;
return this;
}

public ApplicationModeBuilder description(int strId) {
applicationMode.descriptionId = strId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private void showSeekbarSettingsDialog(@NonNull Activity activity, boolean defau
float settingsDefaultSpeed = mode.getDefaultSpeed();
boolean decimalPrecision = !defaultSpeedOnly
&& router != null
&& router.getMaxSpeed() <= ApplicationMode.FAST_SPEED_THRESHOLD;
&& mode.getMaxSpeedConfigLimit() <= ApplicationMode.FAST_SPEED_THRESHOLD;

float[] defaultValue = {roundSpeed(settingsDefaultSpeed * ratio[0], decimalPrecision)};
float[] minValue = new float[1];
Expand All @@ -284,17 +284,17 @@ private void showSeekbarSettingsDialog(@NonNull Activity activity, boolean defau
minValue[0] = Math.round(Math.min(1, settingsDefaultSpeed) * ratio[0]);
maxValue[0] = Math.round(Math.max(300, settingsDefaultSpeed) * ratio[0]);
min = (int) minValue[0];
max = (int) maxValue[0];
} else {
float minSpeedValue = settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed();
float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed();
float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : mode.getMaxSpeedConfigLimit();

minValue[0] = roundSpeed(Math.min(minSpeedValue, settingsDefaultSpeed) * ratio[0], decimalPrecision);
maxValue[0] = roundSpeed(Math.max(maxSpeedValue, settingsDefaultSpeed) * ratio[0], decimalPrecision);

min = Math.round(Math.min(minValue[0], router.getMinSpeed() * ratio[0] / 2f));
max = Math.round(Math.max(maxValue[0], router.getMaxSpeed() * ratio[0] * 1.5f));
}
max = Math.round(Math.max(maxValue[0], mode.getMaxSpeedConfigLimit() * ratio[0] * 1.5f));
max = Math.max(min, max);

boolean nightMode = !app.getSettings().isLightContentForMode(mode);
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
Expand Down