Fix keyboard in landscape

This commit is contained in:
PavelRatushny 2017-11-06 14:08:20 +02:00
parent 039e212666
commit 0bda792186
2 changed files with 41 additions and 38 deletions

View file

@ -189,20 +189,19 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
final OsmandTextFieldBoxes longitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box); final OsmandTextFieldBoxes longitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box);
textFieldBoxes.add(longitudeBox); textFieldBoxes.add(longitudeBox);
final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box); final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box);
if (orientationPortrait) { nameBox.setEndIcon(iconsCache.getIcon(R.drawable.ic_action_keyboard, R.color.coordinate_input_keyboard_icon_color));
nameBox.setEndIcon(iconsCache.getIcon(R.drawable.ic_action_keyboard, R.color.coordinate_input_keyboard_icon_color)); nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() {
nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() { @Override
@Override public void onClick(View view) {
public void onClick(View view) { View focusedView = getDialog().getCurrentFocus();
View focusedView = getDialog().getCurrentFocus(); if (focusedView != null) {
if (focusedView != null) { useOsmandKeyboard = false;
useOsmandKeyboard = false; changeKeyboard();
changeKeyboard(); AndroidUtils.showSoftKeyboard(focusedView);
AndroidUtils.showSoftKeyboard(focusedView);
}
} }
}); }
} });
textFieldBoxes.add(nameBox); textFieldBoxes.add(nameBox);
registerTextFieldBoxes(); registerTextFieldBoxes();
@ -287,27 +286,29 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
keyboardGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { keyboardGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
View focusedView = getDialog().getCurrentFocus(); if (useOsmandKeyboard) {
if (focusedView != null && focusedView instanceof EditText) { View focusedView = getDialog().getCurrentFocus();
EditText focusedEditText = (EditText) focusedView; if (focusedView != null && focusedView instanceof EditText) {
switch (i) { EditText focusedEditText = (EditText) focusedView;
case CLEAR_BUTTON_POSITION: switch (i) {
clearInputs(); case CLEAR_BUTTON_POSITION:
break; clearInputs();
case BACKSPACE_BUTTON_POSITION: break;
String str = focusedEditText.getText().toString(); case BACKSPACE_BUTTON_POSITION:
if (str.length() > 0) { String str = focusedEditText.getText().toString();
str = str.substring(0, str.length() - 1); if (str.length() > 0) {
focusedEditText.setText(str); str = str.substring(0, str.length() - 1);
focusedEditText.setSelection(str.length()); focusedEditText.setText(str);
} focusedEditText.setSelection(str.length());
break; }
case SWITCH_TO_NEXT_INPUT_BUTTON_POSITION: break;
switchToNextInput(focusedEditText.getId()); case SWITCH_TO_NEXT_INPUT_BUTTON_POSITION:
break; switchToNextInput(focusedEditText.getId());
default: break;
focusedEditText.setText(focusedEditText.getText().toString() + keyboardAdapter.getItem(i)); default:
focusedEditText.setSelection(focusedEditText.getText().length()); focusedEditText.setText(focusedEditText.getText().toString() + keyboardAdapter.getItem(i));
focusedEditText.setSelection(focusedEditText.getText().length());
}
} }
} }
} }
@ -423,7 +424,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
View.OnTouchListener inputEditTextOnTouchListener = new View.OnTouchListener() { View.OnTouchListener inputEditTextOnTouchListener = new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
if (useOsmandKeyboard || !orientationPortrait) { if (useOsmandKeyboard) {
if (orientationPortrait && !isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && !isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(true); changeOsmandKeyboardVisibility(true);
} }
@ -438,7 +439,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
editText.setInputType(inputType); editText.setInputType(inputType);
return true; return true;
} else { } else {
if (isOsmandKeyboardCurrentlyVisible()) { if (orientationPortrait && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false); changeOsmandKeyboardVisibility(false);
} }
return false; return false;
@ -449,7 +450,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
View.OnLongClickListener inputEditTextOnLongClickListener = new View.OnLongClickListener() { View.OnLongClickListener inputEditTextOnLongClickListener = new View.OnLongClickListener() {
@Override @Override
public boolean onLongClick(final View view) { public boolean onLongClick(final View view) {
if (useOsmandKeyboard || !orientationPortrait) { if (useOsmandKeyboard) {
final EditText inputEditText = (EditText) view; final EditText inputEditText = (EditText) view;
PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText); PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText);
Menu menu = popupMenu.getMenu(); Menu menu = popupMenu.getMenu();
@ -495,8 +496,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
inputEditText.setSelection(inputEditText.getText().length()); inputEditText.setSelection(inputEditText.getText().length());
} }
return true; return true;
default:
return false;
} }
return false;
} }
}); });
popupMenu.show(); popupMenu.show();

View file

@ -41,6 +41,7 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes {
}); });
this.iconImageButton.setOnClickListener(new OnClickListener() { this.iconImageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
select(); select();
} }