Introduced mix/max speed adjustment

This commit is contained in:
crimean 2019-06-25 23:35:43 +03:00
parent 87b0180fb4
commit d378fe9e5a
8 changed files with 356 additions and 130 deletions

View file

@ -1,14 +1,144 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/seekbar_view" android:id="@+id/seekbar_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical"
android:padding="@dimen/list_content_padding">
<LinearLayout <LinearLayout
android:id="@+id/text_input_lane" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:text="@string/minmax_speed_dialog_title"
android:textColor="?android:textColorPrimary"
app:typeface="@string/font_roboto_medium"
android:textSize="@dimen/default_list_text_size_large" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/content_padding_half"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_half"
android:text="@string/default_speed_dialog_msg"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size" />
<LinearLayout
android:id="@+id/min_speed_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/content_padding">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:text="@string/shared_string_min_speed"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" />
<TextView
android:id="@+id/min_speed_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:maxLength="3"
android:maxLines="1"
android:paddingRight="4dp"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="60" />
<TextView
android:id="@+id/min_speed_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="km/h" />
</LinearLayout>
<LinearLayout
android:id="@+id/min_speed_seekbar_lane"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/content_padding">
<TextView
android:id="@+id/min_speed_seekbar_min_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="0" />
<TextView
android:id="@+id/min_speed_seekbar_max_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
tools:text="100" />
</LinearLayout>
<SeekBar
android:id="@+id/min_speed_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="@dimen/content_padding" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding">
<LinearLayout
android:id="@+id/max_speed_header"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
@ -19,12 +149,12 @@
android:layout_weight="2" android:layout_weight="2"
android:paddingStart="@dimen/content_padding_small" android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small" android:paddingLeft="@dimen/content_padding_small"
android:text="@string/shared_string_speed" android:text="@string/shared_string_max_speed"
android:textColor="?attr/main_font_color_basic" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" /> android:textSize="@dimen/default_list_text_size" />
<TextView <TextView
android:id="@+id/speed_text" android:id="@+id/max_speed_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
@ -32,58 +162,63 @@
android:maxLength="3" android:maxLength="3"
android:maxLines="1" android:maxLines="1"
android:paddingRight="4dp" android:paddingRight="4dp"
android:textColor="?attr/main_font_color_basic" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="60" /> tools:text="60" />
<TextView <TextView
android:id="@+id/speed_units" android:id="@+id/max_speed_units"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingEnd="@dimen/content_padding_small" android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small"
android:textColor="?attr/dialog_text_description_color" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="km/h" /> tools:text="km/h" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/seekbar_lane" android:id="@+id/max_speed_seekbar_lane"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="24dp"> android:paddingTop="@dimen/content_padding">
<TextView <TextView
android:id="@+id/seekbar_min_text" android:id="@+id/max_speed_seekbar_min_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:gravity="start" android:gravity="start"
android:paddingStart="@dimen/content_padding_small" android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small" android:paddingLeft="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="0" /> tools:text="0" />
<TextView <TextView
android:id="@+id/seekbar_max_text" android:id="@+id/max_speed_seekbar_max_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:gravity="end" android:gravity="end"
android:paddingEnd="@dimen/content_padding_small" android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="100" /> tools:text="100" />
</LinearLayout> </LinearLayout>
<SeekBar <SeekBar
android:id="@+id/max_speed_seekbar"
android:id="@+id/speed_seekbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:max="100" android:max="100"
android:paddingBottom="@dimen/content_padding" /> android:paddingBottom="@dimen/content_padding" />
</LinearLayout> </LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -11,10 +11,11 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="shared_string_speed">Speed</string> <string name="shared_string_min_speed">Min. speed</string>
<string name="shared_string_max_speed">Max. speed</string>
<string name="default_speed_setting_title">Default speed</string> <string name="default_speed_setting_title">Default speed</string>
<string name="default_speed_setting_descr">Change default speed settings</string> <string name="default_speed_setting_descr">Change default speed settings</string>
<string name="default_speed_dialog_title">Set default speed</string> <string name="minmax_speed_dialog_title">Set min/max speed</string>
<string name="default_speed_dialog_msg">Used for calculations of expected arrival time during routing</string> <string name="default_speed_dialog_msg">Used for calculations of expected arrival time during routing</string>
<string name="new_profile">New Profile</string> <string name="new_profile">New Profile</string>
<string name="shared_string_crash">Crash</string> <string name="shared_string_crash">Crash</string>

View file

@ -1,34 +1,51 @@
package net.osmand.plus; package net.osmand.plus;
import android.content.Context; import android.content.Context;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.LinkedHashSet;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.osmand.plus.routing.RouteProvider.RouteService; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_ALTITUDE;
import net.osmand.util.Algorithms; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_BATTERY;
import net.sf.junidecode.App; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_BEARING;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_COMPASS;
import org.apache.commons.logging.Log; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_DISTANCE;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.*; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_GPS_INFO;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_INTERMEDIATE_DISTANCE;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_INTERMEDIATE_TIME;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_MARKER_1;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_MARKER_2;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_MAX_SPEED;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_NEXT_NEXT_TURN;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_NEXT_TURN;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_NEXT_TURN_SMALL;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_PLAIN_TIME;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_RULER;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_SPEED;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_TIME;
public class ApplicationMode { public class ApplicationMode {
@ -57,6 +74,7 @@ public class ApplicationMode {
private float defaultSpeed = 10f; private float defaultSpeed = 10f;
private float initialDefaultSpeed = defaultSpeed;
private int minDistanceForTurn = 50; private int minDistanceForTurn = 50;
private int arrivalDistance = 90; private int arrivalDistance = 90;
private int offRouteDistance = 350; private int offRouteDistance = 350;
@ -81,25 +99,25 @@ public class ApplicationMode {
public static final ApplicationMode DEFAULT = createBase( R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation(). public static final ApplicationMode DEFAULT = createBase( R.string.app_mode_default, "default").speed(1.5f, 5).arrivalDistance(90).defLocation().
icon(R.drawable.ic_world_globe_dark, "map_world_globe_dark").reg(); icon(R.drawable.ic_world_globe_dark, "map_world_globe_dark").reg();
public static final ApplicationMode CAR = createBase( R.string.app_mode_car, "car").speed(15.3f, 35).carLocation(). public static final ApplicationMode CAR = createBase( R.string.app_mode_car, "car").speed(12.5f, 35).carLocation().
icon(R.drawable.ic_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg(); icon(R.drawable.ic_action_car_dark, "ic_action_car_dark").setRoutingProfile("car").reg();
public static final ApplicationMode BICYCLE = createBase( R.string.app_mode_bicycle, "bicycle").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation(). public static final ApplicationMode BICYCLE = createBase( R.string.app_mode_bicycle, "bicycle").speed(2.77f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
icon(R.drawable.ic_action_bicycle_dark, "ic_action_bicycle_dark").setRoutingProfile("bicycle").reg(); icon(R.drawable.ic_action_bicycle_dark, "ic_action_bicycle_dark").setRoutingProfile("bicycle").reg();
public static final ApplicationMode PEDESTRIAN = createBase( R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).arrivalDistance(45).offRouteDistance(20). public static final ApplicationMode PEDESTRIAN = createBase( R.string.app_mode_pedestrian, "pedestrian").speed(1.11f, 5).arrivalDistance(45).offRouteDistance(20).
icon(R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg(); icon(R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();
public static final ApplicationMode PUBLIC_TRANSPORT = createBase( R.string.app_mode_public_transport, "public_transport"). public static final ApplicationMode PUBLIC_TRANSPORT = createBase( R.string.app_mode_public_transport, "public_transport").
icon(R.drawable.ic_action_bus_dark, "ic_action_bus_dark").setRoutingProfile("public_transport").reg(); icon(R.drawable.ic_action_bus_dark, "ic_action_bus_dark").setRoutingProfile("public_transport").reg();
public static final ApplicationMode BOAT = createBase( R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation(). public static final ApplicationMode BOAT = createBase( R.string.app_mode_boat, "boat").speed(1.38f, 20).nauticalLocation().
icon(R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg(); icon(R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg();
public static final ApplicationMode AIRCRAFT = createBase( R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation(). public static final ApplicationMode AIRCRAFT = createBase( R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
icon(R.drawable.ic_action_aircraft, "ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").reg(); icon(R.drawable.ic_action_aircraft, "ic_action_aircraft").setRouteService(RouteService.STRAIGHT).setRoutingProfile("STRAIGHT_LINE_MODE").reg();
public static final ApplicationMode SKI = createBase( R.string.app_mode_skiing, "ski").speed(5.5f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation(). public static final ApplicationMode SKI = createBase( R.string.app_mode_skiing, "ski").speed(1.38f, 15).arrivalDistance(60).offRouteDistance(50).bicycleLocation().
icon(R.drawable.ic_plugin_skimaps, "ic_plugin_skimaps").setRoutingProfile("ski").reg(); icon(R.drawable.ic_plugin_skimaps, "ic_plugin_skimaps").setRoutingProfile("ski").reg();
@ -136,9 +154,9 @@ public class ApplicationMode {
regWidgetVisibility(WIDGET_DISTANCE, all); regWidgetVisibility(WIDGET_DISTANCE, all);
regWidgetVisibility(WIDGET_TIME, all); regWidgetVisibility(WIDGET_TIME, all);
regWidgetVisibility(WIDGET_INTERMEDIATE_TIME, all); regWidgetVisibility(WIDGET_INTERMEDIATE_TIME, all);
regWidgetVisibility(WIDGET_SPEED, new ApplicationMode[]{CAR, BICYCLE, BOAT, SKI, PUBLIC_TRANSPORT, AIRCRAFT} ); regWidgetVisibility(WIDGET_SPEED, CAR, BICYCLE, BOAT, SKI, PUBLIC_TRANSPORT, AIRCRAFT);
regWidgetVisibility(WIDGET_MAX_SPEED, CAR); regWidgetVisibility(WIDGET_MAX_SPEED, CAR);
regWidgetVisibility(WIDGET_ALTITUDE, new ApplicationMode[] {PEDESTRIAN, BICYCLE}); regWidgetVisibility(WIDGET_ALTITUDE, PEDESTRIAN, BICYCLE);
regWidgetAvailability(WIDGET_INTERMEDIATE_DISTANCE, all); regWidgetAvailability(WIDGET_INTERMEDIATE_DISTANCE, all);
regWidgetAvailability(WIDGET_DISTANCE, all); regWidgetAvailability(WIDGET_DISTANCE, all);
regWidgetAvailability(WIDGET_TIME, all); regWidgetAvailability(WIDGET_TIME, all);
@ -177,6 +195,7 @@ public class ApplicationMode {
private ApplicationMode customReg() { private ApplicationMode customReg() {
ApplicationMode m = applicationMode; ApplicationMode m = applicationMode;
m.defaultSpeed = m.parentAppMode.defaultSpeed; m.defaultSpeed = m.parentAppMode.defaultSpeed;
m.initialDefaultSpeed = m.parentAppMode.initialDefaultSpeed;
m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn; m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn;
m.arrivalDistance = m.parentAppMode.arrivalDistance; m.arrivalDistance = m.parentAppMode.arrivalDistance;
m.offRouteDistance = m.parentAppMode.offRouteDistance; m.offRouteDistance = m.parentAppMode.offRouteDistance;
@ -222,7 +241,6 @@ public class ApplicationMode {
return this; return this;
} }
public ApplicationModeBuilder carLocation() { public ApplicationModeBuilder carLocation() {
applicationMode.bearingIconDay = R.drawable.map_car_bearing; applicationMode.bearingIconDay = R.drawable.map_car_bearing;
applicationMode.bearingIconNight = R.drawable.map_car_bearing_night; applicationMode.bearingIconNight = R.drawable.map_car_bearing_night;
@ -271,6 +289,7 @@ public class ApplicationMode {
public ApplicationModeBuilder speed(float defSpeed, int distForTurn) { public ApplicationModeBuilder speed(float defSpeed, int distForTurn) {
applicationMode.defaultSpeed = defSpeed; applicationMode.defaultSpeed = defSpeed;
applicationMode.initialDefaultSpeed = defSpeed;
applicationMode.minDistanceForTurn = distForTurn; applicationMode.minDistanceForTurn = distForTurn;
return this; return this;
} }
@ -522,6 +541,17 @@ public class ApplicationMode {
return defaultSpeed; return defaultSpeed;
} }
public void setDefaultSpeed(OsmandApplication app, float defaultSpeed) {
this.defaultSpeed = defaultSpeed;
app.getSettings().DEFAULT_SPEED.set(defaultSpeed);
}
public void resetDefaultSpeed(OsmandApplication app) {
this.defaultSpeed = initialDefaultSpeed;
app.getSettings().DEFAULT_SPEED.setModeValue(this, 0f);
}
public int getMinDistanceForTurn() { public int getMinDistanceForTurn() {
return minDistanceForTurn; return minDistanceForTurn;
} }

View file

@ -1015,6 +1015,12 @@ public class OsmandSettings {
public final OsmandPreference<Float> DEFAULT_SPEED = new FloatPreference( public final OsmandPreference<Float> DEFAULT_SPEED = new FloatPreference(
"default_speed", 0f).makeProfile().cache(); "default_speed", 0f).makeProfile().cache();
public final OsmandPreference<Float> MIN_SPEED = new FloatPreference(
"min_speed", 0f).makeProfile().cache();
public final OsmandPreference<Float> MAX_SPEED = new FloatPreference(
"max_speed", 0f).makeProfile().cache();
public final OsmandPreference<Float> SWITCH_MAP_DIRECTION_TO_COMPASS = public final OsmandPreference<Float> SWITCH_MAP_DIRECTION_TO_COMPASS =
new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile(); new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile();

View file

@ -31,14 +31,14 @@ import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.views.SeekBarPreference; import net.osmand.plus.views.SeekBarPreference;
import org.apache.commons.logging.Log;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
@ -374,7 +374,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
} }
final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter( final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter(
SettingsBaseActivity.this, R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes); SettingsBaseActivity.this, R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes, isModeSelected);
singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel, singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
new OnClickListener() { new OnClickListener() {

View file

@ -17,6 +17,8 @@ import android.preference.PreferenceScreen;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -250,7 +252,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
clearParameters(); clearParameters();
if (router != null) { if (router != null) {
GeneralRouterProfile routerProfile = router.getProfile(); GeneralRouterProfile routerProfile = router.getProfile();
if (routerProfile == GeneralRouterProfile.PEDESTRIAN || routerProfile == GeneralRouterProfile.BICYCLE || routerProfile == GeneralRouterProfile.BOAT) { if (routerProfile != GeneralRouterProfile.PUBLIC_TRANSPORT) {
defaultSpeed = new Preference(this); defaultSpeed = new Preference(this);
defaultSpeed.setTitle(R.string.default_speed_setting_title); defaultSpeed.setTitle(R.string.default_speed_setting_title);
defaultSpeed.setSummary(R.string.default_speed_setting_descr); defaultSpeed.setSummary(R.string.default_speed_setting_descr);
@ -652,7 +654,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
private void showSeekbarSettingsDialog() { private void showSeekbarSettingsDialog() {
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), settings.getApplicationMode()); final ApplicationMode mode = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), mode);
SpeedConstants units = settings.SPEED_SYSTEM.get(); SpeedConstants units = settings.SPEED_SYSTEM.get();
String speedUnits = units.toShortString(this); String speedUnits = units.toShortString(this);
final float[] ratio = new float[1]; final float[] ratio = new float[1];
@ -672,53 +675,59 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
break; break;
} }
final int min = (int) (router.getMinSpeed() * ratio[0]); float settingsMinSpeed = settings.MIN_SPEED.get();
final int[] def = new int[1]; float settingsMaxSpeed = settings.MAX_SPEED.get();
final int max = Math.round(router.getMaxSpeed() * ratio[0]);
if (settings.DEFAULT_SPEED.get() > 0) { final int min = (int) ((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]);
def[0] = Math.round(settings.DEFAULT_SPEED.get() * ratio[0]); final int[] defaultValue = { Math.round(mode.getDefaultSpeed() * ratio[0]) };
} else { final int[] maxValue = { Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]) };
def[0] = Math.round(router.getDefaultSpeed() * ratio[0]); final int max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f);
}
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.default_speed_dialog_title); boolean lightMode = getMyApplication().getSettings().isLightContent();
builder.setMessage(R.string.default_speed_dialog_msg); int themeRes = lightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
View seekbarView = LayoutInflater.from(new ContextThemeWrapper(this, themeRes))
View seekbarView = getLayoutInflater().inflate(R.layout.default_speed_dialog, null); .inflate(R.layout.default_speed_dialog, null, false);
builder.setView(seekbarView); builder.setView(seekbarView);
builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() { builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
settings.DEFAULT_SPEED.set(def[0] / ratio[0]); mode.setDefaultSpeed(getMyApplication(), defaultValue[0] / ratio[0]);
settings.MAX_SPEED.set(maxValue[0] / ratio[0]);
} }
}); });
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setNeutralButton("Revert", new OnClickListener() { builder.setNeutralButton("Revert", new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
settings.DEFAULT_SPEED.set(0f); mode.resetDefaultSpeed(getMyApplication());
settings.MIN_SPEED.set(0f);
settings.MAX_SPEED.set(0f);
} }
}); });
final SeekBar seekBar = seekbarView.findViewById(R.id.speed_seekbar); final SeekBar minSpeedSeekBar = seekbarView.findViewById(R.id.min_speed_seekbar);
final TextView speedMinTv = seekbarView.findViewById(R.id.seekbar_min_text); final TextView minSpeedMinTv = seekbarView.findViewById(R.id.min_speed_seekbar_min_text);
final TextView speedMaxTv = seekbarView.findViewById(R.id.seekbar_max_text); final TextView minSpeedMaxTv = seekbarView.findViewById(R.id.min_speed_seekbar_max_text);
final TextView speedUnitsTv = seekbarView.findViewById(R.id.speed_units); final TextView minSpeedUnitsTv = seekbarView.findViewById(R.id.min_speed_units);
final TextView speedTv = seekbarView.findViewById(R.id.speed_text); final TextView minSpeedTv = seekbarView.findViewById(R.id.min_speed_text);
speedMinTv.setText(String.valueOf(min)); minSpeedMinTv.setText(String.valueOf(min));
speedMaxTv.setText(String.valueOf(max)); minSpeedMaxTv.setText(String.valueOf(max));
speedTv.setText(String.valueOf(def[0])); minSpeedTv.setText(String.valueOf(defaultValue[0]));
speedUnitsTv.setText(speedUnits); minSpeedUnitsTv.setText(speedUnits);
seekBar.setMax(max - min); minSpeedSeekBar.setMax(max - min);
seekBar.setProgress(Math.max(def[0] - min, 0)); minSpeedSeekBar.setProgress(Math.max(defaultValue[0] - min, 0));
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { minSpeedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
def[0] = progress + min; int value = progress + min;
speedTv.setText(String.valueOf(progress + min)); if (value > maxValue[0]) {
value = maxValue[0];
minSpeedSeekBar.setProgress(Math.max(value - min, 0));
}
defaultValue[0] = value;
minSpeedTv.setText(String.valueOf(value));
} }
@Override @Override
@ -730,7 +739,40 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
}); });
AlertDialog dialog = builder.create(); final SeekBar maxSpeedSeekBar = seekbarView.findViewById(R.id.max_speed_seekbar);
dialog.show(); final TextView maxSpeedMinTv = seekbarView.findViewById(R.id.max_speed_seekbar_min_text);
final TextView maxSpeedMaxTv = seekbarView.findViewById(R.id.max_speed_seekbar_max_text);
final TextView maxSpeedUnitsTv = seekbarView.findViewById(R.id.max_speed_units);
final TextView maxSpeedTv = seekbarView.findViewById(R.id.max_speed_text);
maxSpeedMinTv.setText(String.valueOf(min));
maxSpeedMaxTv.setText(String.valueOf(max));
maxSpeedTv.setText(String.valueOf(maxValue[0]));
maxSpeedUnitsTv.setText(speedUnits);
maxSpeedSeekBar.setMax(max - min);
maxSpeedSeekBar.setProgress(Math.max(maxValue[0] - min, 0));
maxSpeedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int value = progress + min;
if (value < defaultValue[0]) {
value = defaultValue[0];
maxSpeedSeekBar.setProgress(Math.max(value - min, 0));
}
maxValue[0] = value;
maxSpeedTv.setText(String.valueOf(value));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
builder.show();
} }
} }

View file

@ -22,13 +22,15 @@ public class AppProfileArrayAdapter extends ArrayAdapter<ProfileDataObject> {
private List<ProfileDataObject> modes; private List<ProfileDataObject> modes;
private int layout; private int layout;
private OsmandApplication app; private OsmandApplication app;
private boolean isModeSelected;
public AppProfileArrayAdapter(@NonNull Activity context, int resource, @NonNull List<ProfileDataObject> objects) { public AppProfileArrayAdapter(@NonNull Activity context, int resource, @NonNull List<ProfileDataObject> objects, boolean isModeSelected) {
super(context, resource, objects); super(context, resource, objects);
this.context = context; this.context = context;
this.modes = objects; this.modes = objects;
this.layout = resource; this.layout = resource;
app = (OsmandApplication) context.getApplication(); this.app = (OsmandApplication) context.getApplication();
this.isModeSelected = isModeSelected;
} }
public long getItemId(int position) { public long getItemId(int position) {
@ -71,7 +73,11 @@ public class AppProfileArrayAdapter extends ArrayAdapter<ProfileDataObject> {
viewHolder.title.setText(mode.getName()); viewHolder.title.setText(mode.getName());
viewHolder.description.setText(mode.getDescription()); viewHolder.description.setText(mode.getDescription());
viewHolder.icon.setImageDrawable(iconDrawable); viewHolder.icon.setImageDrawable(iconDrawable);
if (isModeSelected) {
viewHolder.compoundButton.setChecked(mode.isSelected()); viewHolder.compoundButton.setChecked(mode.isSelected());
} else {
viewHolder.compoundButton.setVisibility(View.GONE);
}
return rowView; return rowView;
} }

View file

@ -700,9 +700,15 @@ public class RouteProvider {
if (defaultSpeed > 0) { if (defaultSpeed > 0) {
paramsR.put(GeneralRouter.DEFAULT_SPEED, String.valueOf(defaultSpeed)); paramsR.put(GeneralRouter.DEFAULT_SPEED, String.valueOf(defaultSpeed));
} }
if (params.inSnapToRoadMode) { Float minSpeed = settings.MIN_SPEED.getModeValue(params.mode);
paramsR.put(GeneralRouter.ALLOW_PRIVATE, "true"); if (minSpeed > 0) {
paramsR.put(GeneralRouter.MIN_SPEED, String.valueOf(minSpeed));
} }
Float maxSpeed = settings.MAX_SPEED.getModeValue(params.mode);
if (maxSpeed > 0) {
paramsR.put(GeneralRouter.MAX_SPEED, String.valueOf(maxSpeed));
}
float mb = (1 << 20); float mb = (1 << 20);
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
// make visible // make visible