add check dor soft keyboard

This commit is contained in:
Chumva 2018-04-02 15:03:12 +03:00
parent 5ffd860a63
commit 920de4ca44
2 changed files with 43 additions and 21 deletions

View file

@ -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"

View file

@ -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
@ -261,19 +261,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 +365,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 +381,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 +626,15 @@ 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();
String lonFirstInput;
if (et.getId() == R.id.lon_first_input_et) {
lonFirstInput = editable.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 +738,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);
@ -755,6 +775,16 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
if (et.getId() != R.id.point_name_et) { if (et.getId() != R.id.point_name_et) {
et.addTextChangedListener(textWatcher); et.addTextChangedListener(textWatcher);
} }
if (et.getId() == R.id.point_name_et) {
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);
et.setOnEditorActionListener(inputTextViewOnEditorActionListener); et.setOnEditorActionListener(inputTextViewOnEditorActionListener);
@ -815,7 +845,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override @Override
public void onTwoDigitsLongtitudeChanged() { public void onTwoDigitsLongtitudeChanged() {
changeTwoDigitsLongtitude(); registerInputs();
} }
@Override @Override
@ -841,13 +871,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());