Merge pull request #9362 from osmandapp/Fix_vehicle_parameters

Fix vehicle parameters numeric dialog
This commit is contained in:
Vitaliy 2020-07-02 18:08:12 +03:00 committed by GitHub
commit 09c6366d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 9 deletions

View file

@ -89,8 +89,6 @@
<dimen name="measurement_tool_button_padding">12dp</dimen>
<dimen name="measurement_tool_button_height">54dp</dimen>
<dimen name="shadow_height">8dp</dimen>
<!--Route info-->
<dimen name="route_info_buttons_padding_left_right">33dp</dimen>
<dimen name="route_info_button_go_margin">5dp</dimen>

View file

@ -275,6 +275,7 @@
<dimen name="bottom_sheet_text_spacing_multiplier" format="float">1.25</dimen>
<dimen name="bottom_sheet_info_spacing_multiplier" format="float">1.5</dimen>
<dimen name="bottom_sheet_big_item_height">128dp</dimen>
<dimen name="bottom_sheet_top_shadow_height">8dp</dimen>
<dimen name="action_bar_image_width_land">236dp</dimen>
<dimen name="action_bar_image_top_margin_land">68dp</dimen>
@ -285,7 +286,6 @@
<dimen name="map_markers_recycler_view_padding_bottom">52dp</dimen>
<dimen name="map_markers_recycler_view_padding_top">10dp</dimen>
<dimen name="shadow_height">5dp</dimen>
<dimen name="map_marker_title_height">28dp</dimen>
<dimen name="fab_recycler_view_padding_bottom">88dp</dimen>

View file

@ -39,7 +39,9 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
@ -78,7 +80,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
final TextView metric = mainView.findViewById(R.id.metric);
metric.setText(app.getString(preference.getAssets().getMetricRes()));
final RecyclerView recyclerView = mainView.findViewById(R.id.recycler_view);
final DecimalFormat df = new DecimalFormat("#.####");
final DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.US));
text = mainView.findViewById(R.id.text_edit);
try {
currentValue = Float.parseFloat(preference.getValue());
@ -86,7 +88,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
currentValue = 0.0f;
}
selectedItem = preference.getEntryFromValue(preference.getValue());
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(df.format(currentValue + 0.01f));
String currentValueStr = currentValue == 0.0f ? "" : df.format(currentValue + 0.01f);
text.setText(currentValueStr);
text.clearFocus();
text.setOnTouchListener(new View.OnTouchListener() {
@ -133,7 +135,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
selectedItem = item;
currentValue = preference.getValueFromEntries(selectedItem);
String currentValueStr = currentValue == 0.0f
? "" : String.valueOf(df.format(currentValue + 0.01f));
? "" : df.format(currentValue + 0.01f);
text.setText(currentValueStr);
if (text.hasFocus()) {
text.setSelection(text.getText().length());
@ -157,17 +159,18 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
}
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
final int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
boolean showTopShadow;
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
if (scrollView.getHeight() > contentHeight) {
if (scrollView.getHeight() + shadowHeight > contentHeight) {
scrollView.getLayoutParams().height = contentHeight;
showTopShadow = false;
} else {

View file

@ -7,6 +7,10 @@ import androidx.preference.DialogPreference;
import net.osmand.plus.R;
import net.osmand.plus.settings.bottomsheets.VehicleSizeAssets;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
public class SizePreference extends DialogPreference {
private String[] entries;
@ -85,7 +89,8 @@ public class SizePreference extends DialogPreference {
String persistedString = getValue();
if (!persistedString.equals(defaultValue)) {
try {
persistedString = String.valueOf(Float.parseFloat(persistedString) + 0.01f);
final DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.US));
persistedString = df.format(Float.parseFloat(persistedString) + 0.01f);
summary = String.format(getContext().getString(R.string.ltr_or_rtl_combine_via_space),
persistedString, getContext().getString(assets.getMetricShortRes()));
} catch (NumberFormatException e) {