Fix long press
This commit is contained in:
parent
c399209855
commit
0443bdfeb1
1 changed files with 54 additions and 51 deletions
|
@ -403,59 +403,62 @@ 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) {
|
||||||
final EditText inputEditText = (EditText) view;
|
if (useOsmandKeyboard || !orientationPortrait) {
|
||||||
PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText);
|
final EditText inputEditText = (EditText) view;
|
||||||
Menu menu = popupMenu.getMenu();
|
PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText);
|
||||||
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
|
Menu menu = popupMenu.getMenu();
|
||||||
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
|
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
|
||||||
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
|
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
|
||||||
if (clipboardManager == null || !clipboardManager.hasPrimaryClip() ||
|
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
|
||||||
!clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
if (clipboardManager == null || !clipboardManager.hasPrimaryClip() ||
|
||||||
pasteMenuItem.setEnabled(false);
|
!clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
||||||
} else {
|
pasteMenuItem.setEnabled(false);
|
||||||
pasteMenuItem.setEnabled(true);
|
} else {
|
||||||
}
|
pasteMenuItem.setEnabled(true);
|
||||||
if (clipboardManager != null) {
|
}
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
if (clipboardManager != null) {
|
||||||
@Override
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
@Override
|
||||||
switch (item.getItemId()) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
case R.id.action_copy:
|
switch (item.getItemId()) {
|
||||||
String labelText;
|
case R.id.action_copy:
|
||||||
switch (view.getId()) {
|
String labelText;
|
||||||
case R.id.latitude_edit_text:
|
switch (view.getId()) {
|
||||||
labelText = LATITUDE_LABEL;
|
case R.id.latitude_edit_text:
|
||||||
break;
|
labelText = LATITUDE_LABEL;
|
||||||
case R.id.longitude_edit_text:
|
break;
|
||||||
labelText = LONGITUDE_LABEL;
|
case R.id.longitude_edit_text:
|
||||||
break;
|
labelText = LONGITUDE_LABEL;
|
||||||
case R.id.name_edit_text:
|
break;
|
||||||
labelText = NAME_LABEL;
|
case R.id.name_edit_text:
|
||||||
break;
|
labelText = NAME_LABEL;
|
||||||
default:
|
break;
|
||||||
labelText = "";
|
default:
|
||||||
break;
|
labelText = "";
|
||||||
}
|
break;
|
||||||
ClipData clip = ClipData.newPlainText(labelText, inputEditText.getText().toString());
|
}
|
||||||
clipboardManager.setPrimaryClip(clip);
|
ClipData clip = ClipData.newPlainText(labelText, inputEditText.getText().toString());
|
||||||
return true;
|
clipboardManager.setPrimaryClip(clip);
|
||||||
case R.id.action_paste:
|
return true;
|
||||||
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
|
case R.id.action_paste:
|
||||||
CharSequence pasteData = pasteItem.getText();
|
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
|
||||||
if (pasteData != null) {
|
CharSequence pasteData = pasteItem.getText();
|
||||||
String str = inputEditText.getText().toString();
|
if (pasteData != null) {
|
||||||
inputEditText.setText(str + pasteData.toString());
|
String str = inputEditText.getText().toString();
|
||||||
inputEditText.setSelection(inputEditText.getText().length());
|
inputEditText.setText(str + pasteData.toString());
|
||||||
}
|
inputEditText.setSelection(inputEditText.getText().length());
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
});
|
||||||
}
|
popupMenu.show();
|
||||||
});
|
}
|
||||||
popupMenu.show();
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue