diff --git a/OsmAnd/res/layout/coordinate_input_data_area.xml b/OsmAnd/res/layout/coordinate_input_data_area.xml index 746e73203f..e6a4818f2d 100644 --- a/OsmAnd/res/layout/coordinate_input_data_area.xml +++ b/OsmAnd/res/layout/coordinate_input_data_area.xml @@ -164,7 +164,6 @@ pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE; pref.set(!pref.get()); - listener.onTwoDigitsLongtitudeChanged(); + listener.onInputSettingsChanged(); } dismiss(); } @@ -113,7 +112,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia int format = (int) v.getTag(); settings.COORDS_INPUT_FORMAT.set(format); if (listener != null) { - listener.onFormatChanged(); + listener.onInputSettingsChanged(); } dismiss(); } @@ -150,12 +149,10 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia interface CoordinateInputFormatChangeListener { - void onTwoDigitsLongtitudeChanged(); - void onKeyboardChanged(); void onHandChanged(); - void onFormatChanged(); + void onInputSettingsChanged(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index a84cfce59c..0d8820cc6c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -5,6 +5,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.res.ColorStateList; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -35,6 +36,7 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -88,8 +90,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean lightTheme; private boolean orientationPortrait; - private boolean isSoftKeyboardShown = true; - private boolean useTwoDigitsLongtitude; + private boolean isSoftKeyboardShown; private boolean north = true; private boolean east = true; @@ -107,7 +108,6 @@ 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); - useTwoDigitsLongtitude = getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get(); } @NonNull @@ -253,7 +253,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } - editTexts.get(6).requestFocus(); + for (EditText et : editTexts) { + if (et.getId() == R.id.point_name_et) { + et.requestFocus(); + } + } final View focusedView = getDialog().getCurrentFocus(); if (focusedView != null) { new Handler().postDelayed(new Runnable() { @@ -261,19 +265,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm public void run() { isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); + showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); } }, 200); } } }); - editTexts.get(6).setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus && isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { - AndroidUtils.hideSoftKeyboard(getActivity(), v); - } - } - }); adapter = new CoordinateInputAdapter(mapActivity, mapMarkers); RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(ctx)); @@ -372,12 +369,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (isSoftKeyboardShown) { isSoftKeyboardShown = false; AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); + showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_show)); } else { new Handler().postDelayed(new Runnable() { @Override public void run() { isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); + showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); } }, 200); } @@ -386,6 +385,22 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } } }); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + Rect r = new Rect(); + mainView.getWindowVisibleDisplayFrame(r); + int screenHeight = mainView.getRootView().getHeight(); + int keypadHeight = screenHeight - r.bottom; + if (keypadHeight > screenHeight * 0.15) { + isSoftKeyboardShown = true; + showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); + } else { + isSoftKeyboardShown = false; + } + } + }); } private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) { @@ -615,6 +630,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (focusedView != null && focusedView instanceof EditTextEx) { EditTextEx et = (EditTextEx) focusedView; int currentLength = et.getText().length(); + if (et.getId() == R.id.lon_first_input_et) { + String lonFirstInput = et.getText().toString(); + if (currentLength == 2) { + if (lonFirstInput.charAt(0) != '1' && lonFirstInput.charAt(0) != '0') { + switchEditText(et.getId(), true); + } + } + } if (et.getMaxSymbolsCount() > 0 && currentLength > strLength && currentLength >= et.getMaxSymbolsCount()) { switchEditText(et.getId(), true); } @@ -718,7 +741,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm clearInputs(); int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get(); - + boolean useTwoDigitsLongtitude = getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get(); 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); @@ -754,6 +777,15 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm for (EditText et : editTexts) { if (et.getId() != R.id.point_name_et) { et.addTextChangedListener(textWatcher); + }else { + et.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (!hasFocus && isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { + AndroidUtils.hideSoftKeyboard(getActivity(), v); + } + } + }); } et.setOnTouchListener(inputEditTextOnTouchListener); et.setOnLongClickListener(inputEditTextOnLongClickListener); @@ -813,11 +845,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() { return new CoordinateInputFormatChangeListener() { - @Override - public void onTwoDigitsLongtitudeChanged() { - changeTwoDigitsLongtitude(); - } - @Override public void onKeyboardChanged() { changeKeyboard(); @@ -829,7 +856,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } @Override - public void onFormatChanged() { + public void onInputSettingsChanged() { registerInputs(); } }; @@ -841,13 +868,6 @@ 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());