Merge pull request #5196 from osmandapp/CoordinateInputSaveKeyboard
Coordinate input keyboard fixes
This commit is contained in:
commit
d1f4ac1c6f
3 changed files with 49 additions and 33 deletions
|
@ -164,7 +164,6 @@
|
||||||
<!-- Longitude row: -->
|
<!-- Longitude row: -->
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/longitude_row"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/content_padding_small"
|
android:layout_marginTop="@dimen/content_padding_small"
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.content.res.ColorStateList;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.ColorRes;
|
import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
@ -67,7 +66,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
|
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
|
||||||
pref.set(!pref.get());
|
pref.set(!pref.get());
|
||||||
listener.onTwoDigitsLongtitudeChanged();
|
listener.onInputSettingsChanged();
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
@ -113,7 +112,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
|
||||||
int format = (int) v.getTag();
|
int format = (int) v.getTag();
|
||||||
settings.COORDS_INPUT_FORMAT.set(format);
|
settings.COORDS_INPUT_FORMAT.set(format);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onFormatChanged();
|
listener.onInputSettingsChanged();
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
@ -150,12 +149,10 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
|
||||||
|
|
||||||
interface CoordinateInputFormatChangeListener {
|
interface CoordinateInputFormatChangeListener {
|
||||||
|
|
||||||
void onTwoDigitsLongtitudeChanged();
|
|
||||||
|
|
||||||
void onKeyboardChanged();
|
void onKeyboardChanged();
|
||||||
|
|
||||||
void onHandChanged();
|
void onHandChanged();
|
||||||
|
|
||||||
void onFormatChanged();
|
void onInputSettingsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -35,6 +36,7 @@ import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
@ -88,8 +90,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
private boolean lightTheme;
|
private boolean lightTheme;
|
||||||
private boolean orientationPortrait;
|
private boolean orientationPortrait;
|
||||||
|
|
||||||
private boolean isSoftKeyboardShown = true;
|
private boolean isSoftKeyboardShown;
|
||||||
private boolean useTwoDigitsLongtitude;
|
|
||||||
private boolean north = true;
|
private boolean north = true;
|
||||||
private boolean east = true;
|
private boolean east = true;
|
||||||
|
|
||||||
|
@ -107,7 +108,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
lightTheme = getMyApplication().getSettings().isLightContent();
|
lightTheme = getMyApplication().getSettings().isLightContent();
|
||||||
setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
|
setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
|
||||||
useTwoDigitsLongtitude = getMyApplication().getSettings().COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -253,7 +253,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
if (isOsmandKeyboardCurrentlyVisible()) {
|
if (isOsmandKeyboardCurrentlyVisible()) {
|
||||||
changeOsmandKeyboardVisibility(false);
|
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();
|
final View focusedView = getDialog().getCurrentFocus();
|
||||||
if (focusedView != null) {
|
if (focusedView != null) {
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
@ -261,19 +265,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
public void run() {
|
public void run() {
|
||||||
isSoftKeyboardShown = true;
|
isSoftKeyboardShown = true;
|
||||||
AndroidUtils.showSoftKeyboard(focusedView);
|
AndroidUtils.showSoftKeyboard(focusedView);
|
||||||
|
showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 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);
|
adapter = new CoordinateInputAdapter(mapActivity, mapMarkers);
|
||||||
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
|
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||||
|
@ -372,12 +369,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
if (isSoftKeyboardShown) {
|
if (isSoftKeyboardShown) {
|
||||||
isSoftKeyboardShown = false;
|
isSoftKeyboardShown = false;
|
||||||
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
|
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
|
||||||
|
showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_show));
|
||||||
} else {
|
} else {
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
isSoftKeyboardShown = true;
|
isSoftKeyboardShown = true;
|
||||||
AndroidUtils.showSoftKeyboard(focusedView);
|
AndroidUtils.showSoftKeyboard(focusedView);
|
||||||
|
showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide));
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 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) {
|
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) {
|
if (focusedView != null && focusedView instanceof EditTextEx) {
|
||||||
EditTextEx et = (EditTextEx) focusedView;
|
EditTextEx et = (EditTextEx) focusedView;
|
||||||
int currentLength = et.getText().length();
|
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()) {
|
if (et.getMaxSymbolsCount() > 0 && currentLength > strLength && currentLength >= et.getMaxSymbolsCount()) {
|
||||||
switchEditText(et.getId(), true);
|
switchEditText(et.getId(), true);
|
||||||
}
|
}
|
||||||
|
@ -718,7 +741,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
clearInputs();
|
clearInputs();
|
||||||
|
|
||||||
int format = getMyApplication().getSettings().COORDS_INPUT_FORMAT.get();
|
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.lat_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, true, useTwoDigitsLongtitude), true);
|
||||||
setupEditTextEx(R.id.lon_first_input_et, CoordinateInputFormats.getFirstPartSymbolsCount(format, false, useTwoDigitsLongtitude), false);
|
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) {
|
for (EditText et : editTexts) {
|
||||||
if (et.getId() != R.id.point_name_et) {
|
if (et.getId() != R.id.point_name_et) {
|
||||||
et.addTextChangedListener(textWatcher);
|
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.setOnTouchListener(inputEditTextOnTouchListener);
|
||||||
et.setOnLongClickListener(inputEditTextOnLongClickListener);
|
et.setOnLongClickListener(inputEditTextOnLongClickListener);
|
||||||
|
@ -813,11 +845,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
private CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() {
|
private CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() {
|
||||||
return new CoordinateInputFormatChangeListener() {
|
return new CoordinateInputFormatChangeListener() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTwoDigitsLongtitudeChanged() {
|
|
||||||
changeTwoDigitsLongtitude();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyboardChanged() {
|
public void onKeyboardChanged() {
|
||||||
changeKeyboard();
|
changeKeyboard();
|
||||||
|
@ -829,7 +856,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFormatChanged() {
|
public void onInputSettingsChanged() {
|
||||||
registerInputs();
|
registerInputs();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -841,13 +868,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
registerMainView();
|
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() {
|
private void changeEditTextSelections() {
|
||||||
for (EditText et : editTexts) {
|
for (EditText et : editTexts) {
|
||||||
et.setSelection(et.getText().length());
|
et.setSelection(et.getText().length());
|
||||||
|
|
Loading…
Reference in a new issue