Create copy paste menu

This commit is contained in:
PavelRatushny 2017-10-24 17:26:30 +03:00
parent dbd56ddfe6
commit 8a75f7f527
3 changed files with 44 additions and 1 deletions

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_copy"
android:title="@string/shared_string_copy"/>
<item
android:id="@+id/action_paste"
android:title="@string/shared_string_paste"/>
</menu>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="shared_string_paste">Paste</string>
<string name="view">View</string>
<string name="waypoints_added_to_map_markers">Waypoints added to map markers</string>
<string name="wrong_input">Wrong input</string>

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -14,6 +15,8 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -32,12 +35,15 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandTextFieldBoxes;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.widgets.IconPopupMenu;
import java.util.ArrayList;
import java.util.List;
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
import static android.content.Context.CLIPBOARD_SERVICE;
public class CoordinateInputDialogFragment extends DialogFragment {
public static final String TAG = "CoordinateInputDialogFragment";
@ -307,7 +313,33 @@ public class CoordinateInputDialogFragment extends DialogFragment {
View.OnLongClickListener editTextOnLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return useOsmandKeyboard;
if (useOsmandKeyboard) {
View focusedView = getDialog().getCurrentFocus();
if (focusedView != null) {
IconPopupMenu popupMenu = new IconPopupMenu(getContext(), focusedView);
Menu menu = popupMenu.getMenu();
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
popupMenu.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
switch (item.getItemId()) {
case R.id.action_copy:
return true;
case R.id.action_paste:
return true;
}
return false;
}
});
popupMenu.show();
}
return true;
} else {
return false;
}
}
};