From d6143e100e23142040ba92604372074fadacc1c5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 1 Jul 2020 17:28:39 +0300 Subject: [PATCH 1/3] Vehicle parameters numeric dialog --- OsmAnd/res/values-large/sizes.xml | 2 -- OsmAnd/res/values/sizes.xml | 2 +- .../bottomsheets/VehicleParametersBottomSheet.java | 9 ++++++--- .../osmand/plus/settings/preferences/SizePreference.java | 7 ++++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index f4c129da0e..94f7f9000f 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -89,8 +89,6 @@ 12dp 54dp - 8dp - 33dp 5dp diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 42b38e8c4b..19d8397db7 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -275,6 +275,7 @@ 1.25 1.5 128dp + 8dp 236dp 68dp @@ -285,7 +286,6 @@ 52dp 10dp - 5dp 28dp 88dp diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index e2274568c2..286896b77b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -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()); @@ -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 { diff --git a/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java b/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java index 553e6a46db..d4631622c5 100644 --- a/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java @@ -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 = String.valueOf(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) { From 6ceb385050136410171589a9aa5e15b7644b17d7 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 2 Jul 2020 10:26:14 +0300 Subject: [PATCH 2/3] Remove unnecessary conversion --- .../settings/bottomsheets/VehicleParametersBottomSheet.java | 2 +- .../net/osmand/plus/settings/preferences/SizePreference.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index 286896b77b..f674138b36 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -88,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() { diff --git a/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java b/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java index d4631622c5..67120bf7c6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/preferences/SizePreference.java @@ -90,7 +90,7 @@ public class SizePreference extends DialogPreference { if (!persistedString.equals(defaultValue)) { try { final DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.US)); - persistedString = String.valueOf(df.format(Float.parseFloat(persistedString) + 0.01f)); + 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) { From 883550a298000b22ad3c93ce3520a8738b89ac1d Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 2 Jul 2020 10:30:52 +0300 Subject: [PATCH 3/3] Remove unnecessary conversion --- .../settings/bottomsheets/VehicleParametersBottomSheet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index f674138b36..c57d1be8c1 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -135,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());