Adjust min speed also

This commit is contained in:
crimean 2019-06-27 14:08:19 +03:00
parent 653094eb76
commit 8d36b64ad4
3 changed files with 212 additions and 227 deletions

View file

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/speed_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/speed_title"
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:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/map_widget_speed" />
<TextView
android:id="@+id/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/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/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/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/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/speed_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="@dimen/content_padding" />
</LinearLayout>

View file

@ -16,15 +16,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingTop="@dimen/content_padding" android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"> android:paddingBottom="@dimen/content_padding_half">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
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/minmax_speed_dialog_title" android:text="@string/default_speed_setting_title"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
app:typeface="@string/font_roboto_medium" app:typeface="@string/font_roboto_medium"
android:textSize="@dimen/default_list_text_size_large" /> android:textSize="@dimen/default_list_text_size_large" />
@ -35,91 +36,14 @@
android:paddingTop="@dimen/content_padding_half" android:paddingTop="@dimen/content_padding_half"
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:paddingBottom="@dimen/content_padding_half" android:paddingBottom="@dimen/content_padding"
android:text="@string/default_speed_dialog_msg" android:text="@string/default_speed_dialog_msg"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size" /> android:textSize="@dimen/default_list_text_size" />
<LinearLayout <include
android:id="@+id/min_speed_header" android:id="@+id/min_speed_layout"
android:layout_width="match_parent" layout="@layout/adjust_speed_slider" />
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> </LinearLayout>
@ -133,89 +57,33 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding"> android:paddingTop="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_half">
<LinearLayout <include
android:id="@+id/max_speed_header" android:id="@+id/default_speed_layout"
android:layout_width="match_parent" layout="@layout/adjust_speed_slider" />
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView </LinearLayout>
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_max_speed"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" />
<TextView <View
android:id="@+id/max_speed_text" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="1dp"
android:layout_height="wrap_content" android:background="?attr/dashboard_divider" />
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 <LinearLayout
android:id="@+id/max_speed_units" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical"
android:paddingEnd="@dimen/content_padding_small" android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorSecondary" android:paddingTop="@dimen/content_padding"
android:textSize="@dimen/default_list_text_size" android:paddingBottom="@dimen/content_padding_half">
tools:text="km/h" />
</LinearLayout>
<LinearLayout <include
android:id="@+id/max_speed_seekbar_lane" android:id="@+id/max_speed_layout"
android:layout_width="match_parent" layout="@layout/adjust_speed_slider" />
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/content_padding">
<TextView
android:id="@+id/max_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/max_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/max_speed_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:paddingBottom="@dimen/content_padding" />
</LinearLayout> </LinearLayout>

View file

@ -678,9 +678,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
float settingsMinSpeed = settings.MIN_SPEED.get(); float settingsMinSpeed = settings.MIN_SPEED.get();
float settingsMaxSpeed = settings.MAX_SPEED.get(); float settingsMaxSpeed = settings.MAX_SPEED.get();
final int min = (int) ((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]);
final int[] defaultValue = { Math.round(mode.getDefaultSpeed() * ratio[0]) }; final int[] defaultValue = { Math.round(mode.getDefaultSpeed() * ratio[0]) };
final int[] minValue = { Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]) };
final int[] maxValue = { Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]) }; final int[] maxValue = { Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]) };
final int min = Math.round(router.getMinSpeed() * ratio[0] / 2f);
final int max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f); 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);
@ -693,6 +694,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mode.setDefaultSpeed(getMyApplication(), defaultValue[0] / ratio[0]); mode.setDefaultSpeed(getMyApplication(), defaultValue[0] / ratio[0]);
settings.MIN_SPEED.set(minValue[0] / ratio[0]);
settings.MAX_SPEED.set(maxValue[0] / ratio[0]); settings.MAX_SPEED.set(maxValue[0] / ratio[0]);
} }
}); });
@ -706,73 +708,99 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
}); });
final SeekBar minSpeedSeekBar = seekbarView.findViewById(R.id.min_speed_seekbar); setupSpeedSlider(SpeedSliderType.MIN_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
final TextView minSpeedMinTv = seekbarView.findViewById(R.id.min_speed_seekbar_min_text); setupSpeedSlider(SpeedSliderType.DEFAULT_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
final TextView minSpeedMaxTv = seekbarView.findViewById(R.id.min_speed_seekbar_max_text); setupSpeedSlider(SpeedSliderType.MAX_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
final TextView minSpeedUnitsTv = seekbarView.findViewById(R.id.min_speed_units);
final TextView minSpeedTv = seekbarView.findViewById(R.id.min_speed_text);
minSpeedMinTv.setText(String.valueOf(min));
minSpeedMaxTv.setText(String.valueOf(max));
minSpeedTv.setText(String.valueOf(defaultValue[0]));
minSpeedUnitsTv.setText(speedUnits);
minSpeedSeekBar.setMax(max - min);
minSpeedSeekBar.setProgress(Math.max(defaultValue[0] - min, 0));
minSpeedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int value = 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
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
final SeekBar maxSpeedSeekBar = seekbarView.findViewById(R.id.max_speed_seekbar);
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(); builder.show();
} }
private enum SpeedSliderType {
DEFAULT_SPEED,
MIN_SPEED,
MAX_SPEED,
}
private void setupSpeedSlider(final SpeedSliderType type, String speedUnits, final int[] minValue, final int[] defaultValue, final int[] maxValue, final int min, final int max, View seekbarView) {
View seekbarLayout;
int titleId;
final int[] speedValue;
switch (type) {
case DEFAULT_SPEED:
speedValue = defaultValue;
seekbarLayout = seekbarView.findViewById(R.id.default_speed_layout);
titleId = R.string.default_speed_setting_title;
break;
case MIN_SPEED:
speedValue = minValue;
seekbarLayout = seekbarView.findViewById(R.id.min_speed_layout);
titleId = R.string.shared_string_min_speed;
break;
case MAX_SPEED:
speedValue = maxValue;
seekbarLayout = seekbarView.findViewById(R.id.max_speed_layout);
titleId = R.string.shared_string_max_speed;
break;
default:
speedValue = defaultValue;
seekbarLayout = seekbarView.findViewById(R.id.default_speed_layout);
titleId = R.string.default_speed_setting_title;
break;
}
final SeekBar speedSeekBar = seekbarLayout.findViewById(R.id.speed_seekbar);
final TextView speedTitleTv = seekbarLayout.findViewById(R.id.speed_title);
final TextView speedMinTv = seekbarLayout.findViewById(R.id.speed_seekbar_min_text);
final TextView speedMaxTv = seekbarLayout.findViewById(R.id.speed_seekbar_max_text);
final TextView speedUnitsTv = seekbarLayout.findViewById(R.id.speed_units);
final TextView speedTv = seekbarLayout.findViewById(R.id.speed_text);
speedTitleTv.setText(titleId);
speedMinTv.setText(String.valueOf(min));
speedMaxTv.setText(String.valueOf(max));
speedTv.setText(String.valueOf(speedValue[0]));
speedUnitsTv.setText(speedUnits);
speedSeekBar.setMax(max - min);
speedSeekBar.setProgress(Math.max(speedValue[0] - min, 0));
speedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int value = progress + min;
switch (type) {
case DEFAULT_SPEED:
if (value > maxValue[0]) {
value = maxValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0));
} else if (value < minValue[0]) {
value = minValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0));
}
break;
case MIN_SPEED:
if (value > defaultValue[0]) {
value = defaultValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0));
}
break;
case MAX_SPEED:
if (value < defaultValue[0]) {
value = defaultValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0));
}
break;
default:
break;
}
speedValue[0] = value;
speedTv.setText(String.valueOf(value));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
} }