From fe2273f1547f49d72be078786fde6546ff003a78 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 30 Mar 2018 19:06:05 +0300 Subject: [PATCH] add two digit option --- .../res/layout/coordinate_input_data_area.xml | 1 + OsmAnd/res/values/strings.xml | 3 +- .../src/net/osmand/plus/OsmandSettings.java | 2 +- ...rdinateInputBottomSheetDialogFragment.java | 22 +++++++ .../CoordinateInputDialogFragment.java | 57 ++++++++++++------- .../mapmarkers/CoordinateInputFormats.java | 8 ++- 6 files changed, 68 insertions(+), 25 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index e6a4818f2d..746e73203f 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -164,6 +164,7 @@ - Travel + Use two digits longitude + Travel Waypoints removed from map markers Nothing found within the radius: You can add all of the track\'s waypoints, or select separate categories. diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index f2e41fe60e..a631100e19 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -722,7 +722,7 @@ public class OsmandSettings { public final CommonPreference COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal(); public final CommonPreference COORDS_INPUT_FORMAT = new IntPreference("coords_input_format", CoordinateInputFormats.DD_MM_MMM); public final CommonPreference COORDS_INPUT_USE_OSMAND_KEYBOARD = new BooleanPreference("coords_input_use_osmand_keyboard", Build.VERSION.SDK_INT >= 16).makeGlobal(); - public final CommonPreference COORDS_INPUT_TWO_DIGITS_LONGTITUDE = new BooleanPreference("coords_input_two_digits_longitude", true).makeGlobal(); + public final CommonPreference COORDS_INPUT_TWO_DIGITS_LONGTITUDE = new BooleanPreference("coords_input_two_digits_longitude", false).makeGlobal(); public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 3c2056336e..010c31ac0c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -55,6 +55,26 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia .create(); items.add(useSystemKeyboardItem); + boolean useTwoDigitsLogtitude = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get(); + BaseBottomSheetItem twoDigitsLongtitudeItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(useTwoDigitsLogtitude) + .setIcon(getContentIcon(R.drawable.ic_action_next_field_stroke)) + .setTitle(getString(R.string.use_two_digits_longitude)) + .setLayoutId(R.layout.bottom_sheet_item_with_switch) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + OsmandSettings.CommonPreference pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE; + pref.set(!pref.get()); + listener.onTwoDigitsLongtitudeChanged(); + } + dismiss(); + } + }) + .create(); + items.add(twoDigitsLongtitudeItem); + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get(); @@ -130,6 +150,8 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia interface CoordinateInputFormatChangeListener { + void onTwoDigitsLongtitudeChanged(); + void onKeyboardChanged(); void onHandChanged(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 590021418f..a84cfce59c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -89,6 +89,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean orientationPortrait; private boolean isSoftKeyboardShown = true; + private boolean useTwoDigitsLongtitude; private boolean north = true; private boolean east = true; @@ -106,7 +107,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm super.onCreate(savedInstanceState); lightTheme = getMyApplication().getSettings().isLightContent(); setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); - isSoftKeyboardShown = !getMyApplication().getSettings().COORDS_INPUT_USE_OSMAND_KEYBOARD.get(); + useTwoDigitsLongtitude = getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get(); } @NonNull @@ -363,28 +364,29 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onClick(View view) { boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible(); - if (isOsmandKeyboardOn()&&!isSoftKeyboardShown) { + if (isOsmandKeyboardOn() && !isSoftKeyboardShown) { changeOsmandKeyboardVisibility(!isCurrentlyVisible); - }else { - final View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null) { - if (isSoftKeyboardShown) { - isSoftKeyboardShown = false; - AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); - } else { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - isSoftKeyboardShown = true; - AndroidUtils.showSoftKeyboard(focusedView); - } - }, 200); + } else { + final View focusedView = getDialog().getCurrentFocus(); + if (focusedView != null) { + if (isSoftKeyboardShown) { + isSoftKeyboardShown = false; + AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); + } else { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + isSoftKeyboardShown = true; + AndroidUtils.showSoftKeyboard(focusedView); + } + }, 200); + } + changeEditTextSelections(); } - changeEditTextSelections(); - }} + } } }); -} + } private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) { @DrawableRes int itemBg = lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg; @@ -489,6 +491,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm new Handler().postDelayed(new Runnable() { @Override public void run() { + isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); } }, 200); @@ -716,8 +719,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get(); - setupEditTextEx(R.id.lat_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, true), true); - setupEditTextEx(R.id.lon_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, false), false); + setupEditTextEx(R.id.lat_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, true, useTwoDigitsLongtitude), true); + setupEditTextEx(R.id.lon_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, false, useTwoDigitsLongtitude), false); String firstSeparator = CoordinateInputFormats.getFirstSeparator(format); ((TextView) mainView.findViewById(R.id.lat_first_separator_tv)).setText(firstSeparator); @@ -810,6 +813,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() { return new CoordinateInputFormatChangeListener() { + @Override + public void onTwoDigitsLongtitudeChanged() { + changeTwoDigitsLongtitude(); + } + @Override public void onKeyboardChanged() { changeKeyboard(); @@ -833,6 +841,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm registerMainView(); } + private void changeTwoDigitsLongtitude() { + editTexts.get(3).setMaxSymbolsCount(getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get() ? 2 : 3); + ((LinearLayout)mainView.findViewById(R.id.longitude_row)).removeView(editTexts.get(3)); +// editTexts.get(3).invalidate(); + registerMainView(); + } + private void changeEditTextSelections() { for (EditText et : editTexts) { et.setSelection(et.getText().length()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java index 758e1add9b..f7d0d4cfbd 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java @@ -43,8 +43,12 @@ public class CoordinateInputFormats { return format == DD_MM_MMM || format == DD_MM_MMMM || format == DD_MM_SS; } - public static int getFirstPartSymbolsCount(@CoordinateInputFormatDef int format, boolean latitude) { - return latitude ? 2 : 3; + public static int getFirstPartSymbolsCount(@CoordinateInputFormatDef int format, boolean latitude, boolean isTwoDigitsLongtitute) { + if (latitude) { + return 2; + } else { + return isTwoDigitsLongtitute ? 2 : 3; + } } public static int getSecondPartSymbolsCount(@CoordinateInputFormatDef int format) {