change keyboard buttons behaviour

This commit is contained in:
Chumva 2018-03-30 17:40:38 +03:00
parent 208832e0cc
commit 533d3bda64
2 changed files with 76 additions and 9 deletions

View file

@ -721,7 +721,8 @@ public class OsmandSettings {
public final CommonPreference<Boolean> COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal();
public final CommonPreference<Integer> COORDS_INPUT_FORMAT = new IntPreference("coords_input_format", CoordinateInputFormats.DD_MM_MMM);
public final CommonPreference<Boolean> COORDS_INPUT_USE_OSMAND_KEYBOARD = new BooleanPreference("coords_input_use_osmand_keyboard", true).makeGlobal();
public final CommonPreference<Boolean> COORDS_INPUT_USE_OSMAND_KEYBOARD = new BooleanPreference("coords_input_use_osmand_keyboard", Build.VERSION.SDK_INT >= 16).makeGlobal();
public final CommonPreference<Boolean> COORDS_INPUT_TWO_DIGITS_LONGTITUDE = new BooleanPreference("coords_input_two_digits_longitude", true).makeGlobal();
public final CommonPreference<Boolean> USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal();
public final CommonPreference<String> MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal();

View file

@ -88,6 +88,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean lightTheme;
private boolean orientationPortrait;
private boolean isSoftKeyboardShown = true;
private boolean north = true;
private boolean east = true;
@ -105,6 +106,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();
}
@NonNull
@ -247,12 +249,30 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
pointNameKeyboardBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isOsmandKeyboardOn()) {
changeKeyboard();
if (isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false);
}
editTexts.get(6).requestFocus();
final View focusedView = getDialog().getCurrentFocus();
if (focusedView != null) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
isSoftKeyboardShown = true;
AndroidUtils.showSoftKeyboard(focusedView);
}
}, 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));
@ -343,14 +363,28 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override
public void onClick(View view) {
boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible();
if (!isCurrentlyVisible && !isOsmandKeyboardOn()) {
changeKeyboard();
} else {
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);
}
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;
@ -448,6 +482,18 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
super.onResume();
adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity()));
startLocationUpdate();
final View focusedView = getDialog().getCurrentFocus();
if (focusedView != null) {
if (!isOsmandKeyboardOn()) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
AndroidUtils.showSoftKeyboard(focusedView);
}
}, 200);
}
}
}
@Override
@ -761,6 +807,26 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
changeEditTextSelections();
}
private void changeSoftKeyboardVisibility() {
changeOsmandKeyboardSetting();
boolean useOsmandKeyboard = isOsmandKeyboardOn();
changeOsmandKeyboardVisibility(useOsmandKeyboard);
final View focusedView = getDialog().getCurrentFocus();
if (focusedView != null) {
if (useOsmandKeyboard) {
AndroidUtils.hideSoftKeyboard(getActivity(), focusedView);
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
AndroidUtils.showSoftKeyboard(focusedView);
}
}, 200);
}
}
changeEditTextSelections();
}
private CoordinateInputFormatChangeListener createCoordinateInputFormatChangeListener() {
return new CoordinateInputFormatChangeListener() {