My AndEngine app does not show options menu - andengine

I'm using AndEngine to develop a simple test application. Everything is good, but the menu options does not show up. I don't know why I don't see the options menu button (the 3-dots touch button on bottom right). Help is much appreciated.
Here is the piece of code corresponding to the MenuScene:
public class MainActivity extends SimpleBaseGameActivity implements IOnMenuItemClickListener {
private static int CAMERA_WIDTH ;
private static int CAMERA_HEIGHT;
protected static final int MENU_ADD = 0;
protected static final int MENU_QUIT = MENU_ADD + 1;
private Font mFont,menuFont;
private MenuScene mMenuScene;
Camera camera;
Scene scene;
#Override
public EngineOptions onCreateEngineOptions() {
//default code
}
#Override
public void onCreateResources() throws IOException {
//some code
}
#Override
public Scene onCreateScene() {
//some code
}
#Override
public boolean onMenuItemClicked(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pMenuItemLocalX, final float pMenuItemLocalY) {
switch(pMenuItem.getID()) {
case MENU_ADD:
/* Restart the animation. */
Log.i("hello", "Menu ADD CLICKED");
return true;
case MENU_QUIT:
/* End Activity. */
this.finish();
return true;
default:
return false;
}
}
protected MenuScene createMenuScene() {
final MenuScene menuScene = new MenuScene(this.camera, new AlphaMenuSceneAnimator());
final IMenuItem resetMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_ADD, this.menuFont, "ADD ITEM", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
menuScene.addMenuItem(resetMenuItem);
final IMenuItem quitMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_QUIT, this.menuFont, "QUIT", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
menuScene.addMenuItem(quitMenuItem);
menuScene.buildAnimations();
menuScene.setBackgroundEnabled(false);
menuScene.setOnMenuItemClickListener(this);
return menuScene;
}
#Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) {
if(pKeyCode == KeyEvent.KEYCODE_MENU && pEvent.getAction() == KeyEvent.ACTION_DOWN) {
if(this.scene.hasChildScene()) {
/* Remove the menu and reset it. */
this.mMenuScene.back();
} else {
/* Attach the menu. */
this.scene.setChildScene(this.mMenuScene, false, true, true);
}
return true;
} else {
return super.onKeyDown(pKeyCode, pEvent);
}
}
}

Related

Marshmallow does not show my custom analog clock widget

I have created custom analog clock which I want to display in the widget. This analog clock is visible in Api 16+ but not visible in Marshmallow (Api 23). Marshmallow allowing to create the widget but does not display my analog clock on the home screen.
Is there any permission in marshmallow to show my custom analog widget??
This is my Widget Class
'public class Widget extends AppWidgetProvider {
private Intent mUpdateService;
#Override
public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_DISABLED)) {
mUpdateService = new Intent();}else{
if (mUpdateService == null)
mUpdateService = new Intent(context, UpdateService.class);
context.startService(mUpdateService);
}
}
public static class UpdateService extends Service {
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
private boolean isScreenOn = true;
#Override
public void onReceive(Context context, Intent intent) {
String key = intent.getAction();
if (key.equals(Intent.ACTION_SCREEN_ON)) {
isScreenOn = true;
updateWidget();
} else if (key.equals(Intent.ACTION_SCREEN_OFF)) {
isScreenOn = false;
} else if (isScreenOn) {
updateWidget();
}
}
};
public RemoteViews mRemoteViews;
public WidgetAnalogClock widgetAnalogClock;
#Override
public void onCreate() {
mRemoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout);
widgetAnalogClock = new WidgetAnalogClock(getApplicationContext());
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(mReceiver, filter);
}
#Override
public void onDestroy() {
unregisterReceiver(mReceiver);}
#Override
public void onStart(Intent intent, int startId) {
updateWidget();}
private void updateWidget(){
WidgetAnalogClock myView=new WidgetAnalogClock(getApplicationContext());
mRemoteViews=new RemoteViews(getApplicationContext().getPackageName(),R.layout.widget_layout);
myView.measure(150, 150);
myView.layout(0, 0, 750, 750);
myView.setDrawingCacheEnabled(true);
Bitmap bitmap = myView.getDrawingCache();
mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);
AppWidgetManager.getInstName(this, Widget.class), mRemoteViews);
bitmap = myView.getDrawingCache();
mRemoteViews.setImageViewBitmap(R.id.customClock, bitmap);}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
}`

how to chage media soures by using sceentap gesture?

I want to change media source and restart mediaplayer in javafx by using leap motion gesture.
how to decribe screentap gesture case in LeapListener for restart mediaplayer?
hot to change media source by using swipe gesture?
and is there anything to fix plz help (I'm beginner in java & this is the first time of programming)
here is my code
public class Leaptest extends Application{
private final LeapListener listener = new LeapListener();
private final Controller leapcontroller = new Controller();
private Media media = new Media("file:///C:/Users/halim.shin/workspace/Movie/flower.mp4");
private MediaPlayer player = new MediaPlayer(media);
private MediaView view = new MediaView(player);
#Override
public void start(Stage Stage) throws Exception {
leapcontroller.addListener(listener);
BorderPane root = new BorderPane();
int key_move_delta = 10;
double size_delta = 1.05;
root.setCenter(view);
Scene scene = new Scene(root,500,500,Color.BLACK);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
scene.setOnKeyPressed(new EventHandler<KeyEvent>(){
#Override
public void handle(KeyEvent event) {
// TODO Auto-generated method stub
switch(event.getCode()){
case UP : view.setTranslateY(view.getTranslateY() - key_move_delta); break;
case RIGHT : view.setTranslateX(view.getTranslateX() + key_move_delta); break;
case DOWN : view.setTranslateY(view.getTranslateY() + key_move_delta); break;
case LEFT : view.setTranslateX(view.getTranslateX() - key_move_delta); break;
case PAGE_UP : view.setScaleX(view.getScaleX()*size_delta); view.setScaleY(view.getScaleY()*size_delta); break;
case PAGE_DOWN : view.setScaleX(view.getScaleX()/size_delta); view.setScaleY(view.getScaleY()/size_delta); break;
case ENTER : player.pause(); break;
case SPACE : player.play(); break;
}
}
});
player.setCycleCount(MediaPlayer.INDEFINITE);
player.setMute(true);
// player.play(); //
Stage.setFullScreen(false);
Stage.setScene(scene);
Stage.show();
}
public void stop(){
leapcontroller.removeListener(listener);
}
public static void main(String[] args){
launch(args);
}
}
public class LeapListener extends Listener {
public void onConnect(Controller controller){
controller.enableGesture(Gesture.Type.TYPE_SWIPE);
controller.enableGesture(Gesture.Type.TYPE_CIRCLE);
controller.enableGesture(Gesture.Type.TYPE_SCREEN_TAP);
controller.enableGesture(Gesture.Type.TYPE_KEY_TAP);
}
public void onFrame(Controller controller){
Frame frame = controller.frame();
GestureList gestures = frame.gestures();
for(int i=0; i<gestures.count(); i++){
Gesture gesture = gestures.get(i);
**switch (gesture.type()){
case TYPE_SCREEN_TAP :
??????????????????
System.out.println("Key");
break;
default :
break;**
}
}
}
}
You have to communicate two different threads: the JavaFX thread and the Leap Motion one.
For that, you can easily add ObjectProperty<T> objects to the LeapListener class in order to set desired values at every frame for given gestures. Then you have to implement their related public ObservableValue<T> methods.
On the JavaFX thread, an anonimous ChangeListener<T> class can be added to listen for any change in the ObservableValue. Note you'll have to use Platform.runLater().
Starting with the LeapListener class:
public class LeapListener extends Listener {
private final BooleanProperty keyTap= new SimpleBooleanProperty(false);
public BooleanProperty keyTapProperty() { return keyTap; }
public enum DIRECTION { NONE,LEFT,RIGHT,UP,DOWN }
public ObjectProperty<DIRECTION> swipeGesture=new SimpleObjectProperty<>();
#Override
public void onConnect(Controller controller){
controller.enableGesture(Gesture.Type.TYPE_KEY_TAP);
controller.enableGesture(Gesture.Type.TYPE_SWIPE);
}
#Override
public void onFrame(Controller controller){
Frame frame = controller.frame();
// reset properties
keyTap.set(false);
swipeGesture.set(DIRECTION.NONE);
GestureList gestures = frame.gestures();
for(int i=0; i<gestures.count(); i++){
Gesture gesture = gestures.get(i);
switch (gesture.type()){
case TYPE_SCREEN_TAP :
keyTap.set(true);
break;
case TYPE_SWIPE:
SwipeGesture swipe = new SwipeGesture(gesture);
if(Math.abs(swipe.direction().getX()) >
Math.abs(swipe.direction().getY())){
if(swipe.direction().getX() > 0){
swipeGesture.set(DIRECTION.RIGHT);
} else {
swipeGesture.set(DIRECTION.LEFT);
}
} else {
if(swipe.direction().getY() > 0){
swipeGesture.set(DIRECTION.UP);
} else {
swipeGesture.set(DIRECTION.DOWN);
}
}
break;
default :
break;
}
}
}
}
While in your JavaFX class:
#Override
public void start(Stage stage) {
...
LeapListener leapListener=new LeapListener();
leapListener.keyTapProperty().addListener(
(ObservableValue<? extends Boolean> ov, Boolean t, final Boolean t1) -> {
if(t1){
Platform.runLater(() -> {
// React to Tap Gesture...
player.play();
});
}
});
leapListener.swipeGesture.addListener(
(ObservableValue<? extends LeapListener.DIRECTION> observable,
LeapListener.DIRECTION oldValue, LeapListener.DIRECTION newValue) -> {
Platform.runLater(()->{
// React to Swipe Gesture ...
switch(newValue){
case UP : break;
case RIGHT : break;
case DOWN : break;
case LEFT : break;
}
});
});
player.setCycleCount(MediaPlayer.INDEFINITE);
player.setMute(true);
// player.play(); //
stage.setFullScreen(false);
stage.setScene(scene);
stage.show();
}
Just note that whenever a Tap/Swipe gesture is detected by the Leap Motion controller, the properties are updated, and the listener is triggered. In the JavaFX thread now you can respond to that gestures.

Preference activity seekbar

I have created a custom android seek bar from lukehorvat tutorial
and added to my preference xml file as below
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto" >
<PreferenceCategory
android:title="Color RGB channels"
android:order="100">
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:id="#+id/redchannel"
android:key="redchannel"
android:dialogMessage="Please select red channel:"
android:max="50"
android:title="Red channel"
custom:progressTextSuffix="%"
custom:min="1" />
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:dialogMessage="Please select green channel:"
android:max="50"
android:title="Select green channel"
custom:progressTextSuffix="%"
custom:min="1" />
<com.heroku.android.SeekBarDialogPreference
android:defaultValue="20"
android:dialogMessage="Please select blue channel:"
android:max="50"
android:title="Select blue channel"
custom:progressTextSuffix="%"
custom:min="1" />
</PreferenceCategory>
</PreferenceScreen>
And I have added to my preference activity these three seekbars as below
package com.heroku.android;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.View;
import android.widget.SeekBar;
public class Preferences extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(com.yuldashev.android.R.xml.preferences);
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
this);
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onDestroy() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
}
}
The problem is all of them refers to the same seekbardialog custom class and I cannot get the values for these three seekbars seperately. I have tried to seperate them by entitling #+id in xml file but it does not works for me by findviewbyID because the custom SeekBardialogPreference does not support such an option. For example if you adding and single SeekBar by id you do
SeekBar seek1=(SeekBar)findviewByID(resource)
and you get the progress value from seek1 object.
Is there any suggestion how to do the same with custom seekbardialog below
package com.heroku.android;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
/**
* A {#link DialogPreference} that provides a user with the means to select an integer from a {#link SeekBar}, and persist it.
*
* #author lukehorvat
*
*/
public class SeekBarDialogPreference extends DialogPreference
{
private static final int DEFAULT_MIN_PROGRESS = 0;
private static final int DEFAULT_MAX_PROGRESS = 100;
private static final int DEFAULT_PROGRESS = 0;
private int mMinProgress;
private int mMaxProgress;
private int mProgress;
private CharSequence mProgressTextSuffix;
private TextView mProgressText;
private SeekBar mSeekBar;
public SeekBarDialogPreference(Context context)
{
this(context, null);
}
public SeekBarDialogPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
// get attributes specified in XML
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, com.yuldashev.android.R.styleable.SeekBarDialogPreference, 0, 0);
try
{
setMinProgress(a.getInteger(com.yuldashev.android.R.styleable.SeekBarDialogPreference_min, DEFAULT_MIN_PROGRESS));
setMaxProgress(a.getInteger(com.yuldashev.android.R.styleable.SeekBarDialogPreference_android_max, DEFAULT_MAX_PROGRESS));
setProgressTextSuffix(a.getString(com.yuldashev.android.R.styleable.SeekBarDialogPreference_progressTextSuffix));
}
finally
{
a.recycle();
}
// set layout
setDialogLayoutResource(com.yuldashev.android.R.layout.preference_seek_bar_dialog);
setPositiveButtonText(android.R.string.ok);
setNegativeButtonText(android.R.string.cancel);
setDialogIcon(null);
}
#Override
protected void onSetInitialValue(boolean restore, Object defaultValue)
{
setProgress(restore ? getPersistedInt(DEFAULT_PROGRESS) : (Integer) defaultValue);
}
#Override
protected Object onGetDefaultValue(TypedArray a, int index)
{
return a.getInt(index, DEFAULT_PROGRESS);
}
#Override
protected void onBindDialogView(View view)
{
super.onBindDialogView(view);
TextView dialogMessageText = (TextView) view.findViewById(com.yuldashev.android.R.id.text_dialog_message);
dialogMessageText.setText(getDialogMessage());
mProgressText = (TextView) view.findViewById(com.yuldashev.android.R.id.text_progress);
mSeekBar = (SeekBar) view.findViewById(com.yuldashev.android.R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
// update text that displays the current SeekBar progress value
// note: this does not persist the progress value. that is only ever done in setProgress()
String progressStr = String.valueOf(progress + mMinProgress);
mProgressText.setText(mProgressTextSuffix == null ? progressStr : progressStr.concat(mProgressTextSuffix.toString()));
}
});
mSeekBar.setMax(mMaxProgress - mMinProgress);
mSeekBar.setProgress(mProgress - mMinProgress);
}
public int getMinProgress()
{
return mMinProgress;
}
public void setMinProgress(int minProgress)
{
mMinProgress = minProgress;
setProgress(Math.max(mProgress, mMinProgress));
}
public int getMaxProgress()
{
return mMaxProgress;
}
public void setMaxProgress(int maxProgress)
{
mMaxProgress = maxProgress;
setProgress(Math.min(mProgress, mMaxProgress));
}
public int getProgress()
{
return mProgress;
}
public void setProgress(int progress)
{
progress = Math.max(Math.min(progress, mMaxProgress), mMinProgress);
if (progress != mProgress)
{
mProgress = progress;
persistInt(progress);
notifyChanged();
}
}
public CharSequence getProgressTextSuffix()
{
return mProgressTextSuffix;
}
public void setProgressTextSuffix(CharSequence progressTextSuffix)
{
mProgressTextSuffix = progressTextSuffix;
}
#Override
protected void onDialogClosed(boolean positiveResult)
{
super.onDialogClosed(positiveResult);
// when the user selects "OK", persist the new value
if (positiveResult)
{
int seekBarProgress = mSeekBar.getProgress() + mMinProgress;
if (callChangeListener(seekBarProgress))
{
setProgress(seekBarProgress);
}
}
}
#Override
protected Parcelable onSaveInstanceState()
{
// save the instance state so that it will survive screen orientation changes and other events that may temporarily destroy it
final Parcelable superState = super.onSaveInstanceState();
// set the state's value with the class member that holds current setting value
final SavedState myState = new SavedState(superState);
myState.minProgress = getMinProgress();
myState.maxProgress = getMaxProgress();
myState.progress = getProgress();
return myState;
}
#Override
protected void onRestoreInstanceState(Parcelable state)
{
// check whether we saved the state in onSaveInstanceState()
if (state == null || !state.getClass().equals(SavedState.class))
{
// didn't save the state, so call superclass
super.onRestoreInstanceState(state);
return;
}
// restore the state
SavedState myState = (SavedState) state;
setMinProgress(myState.minProgress);
setMaxProgress(myState.maxProgress);
setProgress(myState.progress);
super.onRestoreInstanceState(myState.getSuperState());
}
private static class SavedState extends BaseSavedState
{
int minProgress;
int maxProgress;
int progress;
public SavedState(Parcelable superState)
{
super(superState);
}
public SavedState(Parcel source)
{
super(source);
minProgress = source.readInt();
maxProgress = source.readInt();
progress = source.readInt();
}
#Override
public void writeToParcel(Parcel dest, int flags)
{
super.writeToParcel(dest, flags);
dest.writeInt(minProgress);
dest.writeInt(maxProgress);
dest.writeInt(progress);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>()
{
#Override
public SavedState createFromParcel(Parcel in)
{
return new SavedState(in);
}
#Override
public SavedState[] newArray(int size)
{
return new SavedState[size];
}
};
}
}
Thank you all!

GXT: LayoutContainer does not respond to ESC Key or "X" button to close

I have a GXT 2.x application with a Menubar Item that renders a separate LayoutContainer.
Here's the hierarchy
MainUI.java -> MenuBar.java -> ReservationPopUp.java
I have replaced my contents of ReservationPopUp.java with KNOWN working examples of LayoutContainer implementations and they respond to the ESC key and "X" button.
Here's how the MenuItem renders the ReservationPopUp.java
MenuItem mntmReserve = new MenuItem("Reserve");
mntmReserve.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
RootPanel.get().add(new ReservationPopUp());
}
Here's a slimmed down version of my ReservationPopUp.java
public class ReservationPopUp extends LayoutContainer {
public ReservationPopUp() {
}
#Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setSize("1024", "809");
final Window window = new Window();
window.setDraggable(false);
window.setSize(537, 399);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setHeading("Reserve A Server");
window.setClosable(true);
window.setOnEsc(true);
window.setSize("465", "345");
window.setLayout(new AbsoluteLayout());
LabelField lblfldUsers = new LabelField("Users");
window.add(lblfldUsers, new AbsoluteData(43, 218));
final ComboBox<AsyncUser> userList = new ComboBox<AsyncUser>();
window.add(userList, new AbsoluteData(81, 218));
userList.setEmptyText("Select a User...");
userList.setSize("347px", "24px");
LabelField labelServers = new LabelField("Servers");
window.add(labelServers, new AbsoluteData(32, 6));
final DualListField<AsyncServer> serverList = new DualListField<AsyncServer>();
....
window.add(serverList, new AbsoluteData(81, 6));
serverList.setSize("347px", "206px");
window.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent ce) {
ReservationPopUp.this.hide();
}
}));
window.addButton(new Button("Reserve", new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent ce) {
if (serverList.getToList().getListView().getItemCount() == 0 ) {
MessageBox.alert("Invalid Selection","No Server(s) Selected", null);
} else if ( userList.getValue() == null) {
} else {
// DO some stuff
ReservationPopUp.this.hide();
}
}
}));
window.addWindowListener(new WindowListener() {
#Override
public void windowHide(WindowEvent we) {
ReservationPopUp.this.hide();
}
});
window.setFocusWidget(window.getButtonBar().getItem(0));
add(window);
}
}
Window is a popup, it doesn't need to be (and shouldn't be) added to anything. Extend the Window class instead of the LayoutContainer, and instead of adding the ReservationPopup to the page, just call Window.show().

How to disable copy/paste from/to EditText

In my application, there is a registration screen, where i do not want the user to be able to copy/paste text into the EditText field. I have set an onLongClickListener on each EditText so that the context menu showing copy/paste/inputmethod and other options does not show up. So the user won't be able to copy/ paste into the Edit fields.
OnLongClickListener mOnLongClickListener = new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// prevent context menu from being popped up, so that user
// cannot copy/paste from/into any EditText fields.
return true;
}
};
But the problem arises if the user has enabled a third-party keyboard other than the Android default, which may have a button to copy/paste or which may show the same context menu. So how do i disable copy/paste in that scenario ?
Please let me know if there are other ways to copy/paste as well. (and possibly how to disable them)
Any help would be appreciated.
Best method is to use:
etUsername.setLongClickable(false);
If you are using API level 11 or above then you can stop copy,paste,cut and custom context menus from appearing by.
edittext.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
Returning false from onCreateActionMode(ActionMode, Menu) will prevent the action mode from being started(Select All, Cut, Copy and Paste actions).
You can do this by disabling the long press of the EditText
To implement it, just add the following line in the xml -
android:longClickable="false"
I am able to disable copy-and-paste functionality with the following:
textField.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
return false;
}
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) {
return false;
}
public void onDestroyActionMode(ActionMode actionMode) {
}
});
textField.setLongClickable(false);
textField.setTextIsSelectable(false);
Hope it works for you ;-)
Kotlin solution:
fun TextView.disableCopyPaste() {
isLongClickable = false
setTextIsSelectable(false)
customSelectionActionModeCallback = object : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode?, menu: Menu): Boolean {
return false
}
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu): Boolean {
return false
}
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem): Boolean {
return false
}
override fun onDestroyActionMode(mode: ActionMode?) {}
}
}
Then you can simply call this method on your TextView:
override fun onCreate() {
priceEditText.disableCopyPaste()
}
here is a best way to disable cut copy paste of editText work in all version
if (android.os.Build.VERSION.SDK_INT < 11) {
editText.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
#Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
menu.clear();
}
});
} else {
editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
public boolean onActionItemClicked(ActionMode mode,
MenuItem item) {
// TODO Auto-generated method stub
return false;
}
});
}
In addition to the setCustomSelectionActionModeCallback, and disabled long-click solutions, it's necessary to prevent the PASTE/REPLACE menus from appearing when the text selection handle is clicked, as per the image below:
The solution lies in preventing PASTE/REPLACE menu from appearing in the show() method of the (non-documented) android.widget.Editor class. Before the menu appears, a check is done to if (!canPaste && !canSuggest) return;. The two methods that are used as the basis to set these variables are both in the EditText class:
isSuggestionsEnabled() is public, and may thus be overridden.
canPaste() is not, and thus must be hidden by introducing a function of the same name in the derived class.
A more complete answer is available here.
If you don't wan't to disable long click because you need to perform some functionality on long click than returning true is a better option to do so.
Your edittext long click will be like this.
edittext.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// Do Something or Don't
return true;
}
});
As per documentation
Returning "True" will indicate that long click have been handled so no need to perform default operations.
I tested this on API level 16, 22 and 25. Its working fine for me. Hope this will help.
Here is a hack to disable "paste" popup. You have to override EditText method:
#Override
public int getSelectionStart() {
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (element.getMethodName().equals("canPaste")) {
return -1;
}
}
return super.getSelectionStart();
}
Similar can be done for the other actions.
I've tested this solution and this works
mSubdomainEditText.setLongClickable(false);
mSubdomainEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
i added Extension Function in Kotlin language :
fun EditText.disableTextSelection() {
this.setCustomSelectionActionModeCallback(object : android.view.ActionMode.Callback {
override fun onActionItemClicked(mode: android.view.ActionMode?, item: MenuItem?): Boolean {
return false
}
override fun onCreateActionMode(mode: android.view.ActionMode?, menu: Menu?): Boolean {
return false
}
override fun onPrepareActionMode(mode: android.view.ActionMode?, menu: Menu?): Boolean {
return false
}
override fun onDestroyActionMode(mode: android.view.ActionMode?) {
}
})
}
you can use it like this :
edit_text.disableTextSelection()
also added below line in your xml :
android:longClickable="false"
android:textIsSelectable="false"
https://github.com/neopixl/PixlUI provides an EditText with a method
myEditText.disableCopyAndPaste().
And it's works on the old API
If you want to disable ActionMode for copy/pasting, you need to override 2 callbacks. This works for both TextView and EditText (or TextInputEditText)
import android.view.ActionMode
fun TextView.disableCopyPaste() {
isLongClickable = false
setTextIsSelectable(false)
customSelectionActionModeCallback = object : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode?, menu: Menu) = false
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu) = false
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem) = false
override fun onDestroyActionMode(mode: ActionMode?) {}
}
//disable action mode when edittext gain focus at first
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
customInsertionActionModeCallback = object : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode?, menu: Menu) = false
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu) = false
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem) = false
override fun onDestroyActionMode(mode: ActionMode?) {}
}
}
}
This extension is based off above #Alexandr solution and worked fine for me.
#Zain Ali, your answer works on API 11. I just wanted to suggest a way to do in on API 10 as well. Since I had to maintain my project API on that version, I was constantly playing with the functions available in 2.3.3 and got a possibility to do it. I have share the snippet below. I tested the code and it was working for me. I did this snippet on an urgency. Feel free to improve the code if there are any changes that can be done..
// A custom TouchListener is being implemented which will clear out the focus
// and gain the focus for the EditText, in few milliseconds so the selection
// will be cleared and hence the copy paste option wil not pop up.
// the respective EditText should be set with this listener
// tmpEditText.setOnTouchListener(new MyTouchListener(tmpEditText, tmpImm));
public class MyTouchListener implements View.OnTouchListener {
long click = 0;
EditText mEtView;
InputMethodManager imm;
public MyTouchListener(EditText etView, InputMethodManager im) {
mEtView = etView;
imm = im;
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
long curr = System.currentTimeMillis();
if (click !=0 && ( curr - click) < 30) {
mEtView.setSelected(false);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mEtView.setSelected(true);
mEtView.requestFocusFromTouch();
imm.showSoftInput(mEtView, InputMethodManager.RESULT_SHOWN);
}
},25);
return true;
}
else {
if (click == 0)
click = curr;
else
click = 0;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mEtView.requestFocusFromTouch();
mEtView.requestFocusFromTouch();
imm.showSoftInput(mEtView, InputMethodManager.RESULT_SHOWN);
}
},25);
return true;
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
mEtView.setSelected(false);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mEtView.setSelected(true);
mEtView.requestFocusFromTouch();
mEtView.requestFocusFromTouch();
imm.showSoftInput(mEtView, InputMethodManager.RESULT_SHOWN);
}
},25);
return true;
}
return false;
}
For smartphone with clipboard, is possible prevent like this.
editText.setFilters(new InputFilter[]{new InputFilter() {
#Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source.length() > 1) {
return "";
} return null;
}
}});
Read the Clipboard, check against the input and the time the input is "typed". If the Clipboard has the same text and it is too fast, delete the pasted input.
the solution is very simple
public class MainActivity extends AppCompatActivity {
EditText et_0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_0 = findViewById(R.id.et_0);
et_0.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
//to keep the text selection capability available ( selection cursor)
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
//to prevent the menu from appearing
menu.clear();
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
});
}
}
--------> preview <---------
Try Following custome class for prevant copy and paste in Edittext
public class SegoeUiEditText extends AppCompatEditText {
private final Context context;
#Override
public boolean isSuggestionsEnabled() {
return false;
}
public SegoeUiEditText(Context context) {
super(context);
this.context = context;
init();
}
public SegoeUiEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}
public SegoeUiEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
init();
}
private void setFonts(Context context) {
this.setTypeface(Typeface.createFromAsset(context.getAssets(), "Fonts/Helvetica-Normal.ttf"));
}
private void init() {
setTextIsSelectable(false);
this.setCustomSelectionActionModeCallback(new ActionModeCallbackInterceptor());
this.setLongClickable(false);
}
#Override
public int getSelectionStart() {
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (element.getMethodName().equals("canPaste")) {
return -1;
}
}
return super.getSelectionStart();
}
/**
* Prevents the action bar (top horizontal bar with cut, copy, paste, etc.) from appearing
* by intercepting the callback that would cause it to be created, and returning false.
*/
private class ActionModeCallbackInterceptor implements ActionMode.Callback, android.view.ActionMode.Callback {
private final String TAG = SegoeUiEditText.class.getSimpleName();
public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; }
public void onDestroyActionMode(ActionMode mode) {}
#Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
menu.clear();
return false;
}
#Override
public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(android.view.ActionMode mode) {
}
}
}
The solutions above do not take into account pasting with hardware keyboards (Ctrl+v). The easiest solution is to set a TextWatcher on your EditText, and filter characters you want or don't want in the afterTextChanged method. This works for all situations, i.e. typed characters, pastes, auto suggestions and auto corrections.
Rather than completely disabling all actions on the EditText, you may want to prevent only certain actions (like cut/copy, but not paste):
/**
* Prevent copy/cut of the (presumably sensitive) contents of this TextView.
*/
fun TextView.disableCopyCut() {
setCustomSelectionActionModeCallback(
object : Callback {
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?) = false
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
menu?.apply {
removeItem(android.R.id.copy)
removeItem(android.R.id.cut)
}
return true
}
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
override fun onDestroyActionMode(mode: ActionMode?) {
// no-op
}
}
)
}
Actions that can be selectively removed:
removeItem(android.R.id.copy)
removeItem(android.R.id.cut)
removeItem(android.R.id.paste)
removeItem(android.R.id.shareText) // Share
removeItem(android.R.id.textAssist) // Open with Chrome
its very late but may it help someone .
add these lines in your edittext xml
android:longClickable="false"
android:textIsSelectable="false"
android:importantForAutofill="no"
I found that when you create an input filter to avoid entry of unwanted characters, pasting such characters into the edit text is having no effect. So this sort of solves my problem as well.
Solution that worked for me was to create custom Edittext and override following method:
public class MyEditText extends EditText {
private int mPreviousCursorPosition;
#Override
protected void onSelectionChanged(int selStart, int selEnd) {
CharSequence text = getText();
if (text != null) {
if (selStart != selEnd) {
setSelection(mPreviousCursorPosition, mPreviousCursorPosition);
return;
}
}
mPreviousCursorPosition = selStart;
super.onSelectionChanged(selStart, selEnd);
}
}
Try to use.
myEditext.setCursorVisible(false);
myEditext.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
public boolean onActionItemClicked(ActionMode mode,
MenuItem item) {
// TODO Auto-generated method stub
return false;
}
});
Who is looking for a solution in Kotlin use the below class as a custom widget and use it in the xml.
class SecureEditText : TextInputEditText {
/** This is a replacement method for the base TextView class' method of the same name. This method
* is used in hidden class android.widget.Editor to determine whether the PASTE/REPLACE popup
* appears when triggered from the text insertion handle. Returning false forces this window
* to never appear.
* #return false
*/
override fun isSuggestionsEnabled(): Boolean {
return false
}
override fun getSelectionStart(): Int {
for (element in Thread.currentThread().stackTrace) {
if (element.methodName == "canPaste") {
return -1
}
}
return super.getSelectionStart()
}
public override fun onSelectionChanged(start: Int, end: Int) {
val text = text
if (text != null) {
if (start != text.length || end != text.length) {
setSelection(text.length, text.length)
return
}
}
super.onSelectionChanged(start, end)
}
companion object {
private val EDITTEXT_ATTRIBUTE_COPY_AND_PASTE = "isCopyPasteDisabled"
private val PACKAGE_NAME = "http://schemas.android.com/apk/res-auto"
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
disableCopyAndPaste(context, attrs)
}
/**
* Disable Copy and Paste functionality on EditText
*
* #param context Context object
* #param attrs AttributeSet Object
*/
private fun disableCopyAndPaste(context: Context, attrs: AttributeSet) {
val isDisableCopyAndPaste = attrs.getAttributeBooleanValue(
PACKAGE_NAME,
EDITTEXT_ATTRIBUTE_COPY_AND_PASTE, true
)
if (isDisableCopyAndPaste && !isInEditMode()) {
val inputMethodManager =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
this.setLongClickable(false)
this.setOnTouchListener(BlockContextMenuTouchListener(inputMethodManager))
}
}
/**
* Perform Focus Enabling Task to the widget with the help of handler object
* with some delay
* #param inputMethodManager is used to show the key board
*/
private fun performHandlerAction(inputMethodManager: InputMethodManager) {
val postDelayedIntervalTime: Long = 25
Handler().postDelayed(Runnable {
this#SecureEditText.setSelected(true)
this#SecureEditText.requestFocusFromTouch()
inputMethodManager.showSoftInput(
this#SecureEditText,
InputMethodManager.RESULT_SHOWN
)
}, postDelayedIntervalTime)
}
/**
* Class to Block Context Menu on double Tap
* A custom TouchListener is being implemented which will clear out the focus
* and gain the focus for the EditText, in few milliseconds so the selection
* will be cleared and hence the copy paste option wil not pop up.
* the respective EditText should be set with this listener
*
* #param inputMethodManager is used to show the key board
*/
private inner class BlockContextMenuTouchListener internal constructor(private val inputMethodManager: InputMethodManager) :
View.OnTouchListener {
private var lastTapTime: Long = 0
val TIME_INTERVAL_BETWEEN_DOUBLE_TAP = 30
override fun onTouch(v: View, event: MotionEvent): Boolean {
if (event.getAction() === MotionEvent.ACTION_DOWN) {
val currentTapTime = System.currentTimeMillis()
if (lastTapTime != 0L && currentTapTime - lastTapTime < TIME_INTERVAL_BETWEEN_DOUBLE_TAP) {
this#SecureEditText.setSelected(false)
performHandlerAction(inputMethodManager)
return true
} else {
if (lastTapTime == 0L) {
lastTapTime = currentTapTime
} else {
lastTapTime = 0
}
performHandlerAction(inputMethodManager)
return true
}
} else if (event.getAction() === MotionEvent.ACTION_MOVE) {
this#SecureEditText.setSelected(false)
performHandlerAction(inputMethodManager)
}
return false
}
}
}
A widely compatible solution (from Android 1.5 onwards) is
#Override
public boolean onTextContextMenuItem(int id) {
switch (id){
case android.R.id.cut:
onTextCut();
return false;
case android.R.id.paste:
onTextPaste();
return false;
case android.R.id.copy:
onTextCopy();
return false;
}
return true;
}
After spending a lot of time, removing the paste option in ContextMenu of EditText I have followed the below code in Java.
NoMenuEditText.Java
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.widget.AppCompatEditText;
/**
* custom edit text
*/
public class NoMenuEditText extends AppCompatEditText {
private static final String EDITTEXT_ATTRIBUTE_COPY_AND_PASTE = "isCopyPasteDisabled";
private static final String PACKAGE_NAME = "http://schemas.android.com/apk/res-auto";
public NoMenuEditText(Context context) {
super(context);
}
public NoMenuEditText(Context context, AttributeSet attrs) {
super(context, attrs);
EnableDisableCopyAndPaste(context, attrs);
}
/**
* Enable/Disable Copy and Paste functionality on EditText
*
* #param context Context object
* #param attrs AttributeSet Object
*/
private void EnableDisableCopyAndPaste(Context context, AttributeSet attrs) {
boolean isDisableCopyAndPaste = attrs.getAttributeBooleanValue(PACKAGE_NAME,
EDITTEXT_ATTRIBUTE_COPY_AND_PASTE, false);
if (isDisableCopyAndPaste && !isInEditMode()) {
InputMethodManager inputMethodManager = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
this.setLongClickable(false);
this.setOnTouchListener(new BlockContextMenuTouchListener
(inputMethodManager));
}
}
/**
* Perform Focus Enabling Task to the widget with the help of handler object
* with some delay
*/
private void performHandlerAction(final InputMethodManager inputMethodManager) {
int postDelayedIntervalTime = 25;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
NoMenuEditText.this.setSelected(true);
NoMenuEditText.this.requestFocusFromTouch();
inputMethodManager.showSoftInput(NoMenuEditText.this,
InputMethodManager.RESULT_SHOWN);
}
}, postDelayedIntervalTime);
}
/**
* Class to Block Context Menu on double Tap
* A custom TouchListener is being implemented which will clear out the focus
* and gain the focus for the EditText, in few milliseconds so the selection
* will be cleared and hence the copy paste option wil not pop up.
* the respective EditText should be set with this listener
*/
private class BlockContextMenuTouchListener implements View.OnTouchListener {
private static final int TIME_INTERVAL_BETWEEN_DOUBLE_TAP = 30;
private InputMethodManager inputMethodManager;
private long lastTapTime = 0;
BlockContextMenuTouchListener(InputMethodManager inputMethodManager) {
this.inputMethodManager = inputMethodManager;
}
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
long currentTapTime = System.currentTimeMillis();
if (lastTapTime != 0 && (currentTapTime - lastTapTime)
< TIME_INTERVAL_BETWEEN_DOUBLE_TAP) {
NoMenuEditText.this.setSelected(false);
performHandlerAction(inputMethodManager);
return true;
} else {
if (lastTapTime == 0) {
lastTapTime = currentTapTime;
} else {
lastTapTime = 0;
}
performHandlerAction(inputMethodManager);
return true;
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
NoMenuEditText.this.setSelected(false);
performHandlerAction(inputMethodManager);
}
return false;
}
}
#Override
protected void onSelectionChanged(int selStart, int selEnd) {
CharSequence text = getText();
if (text != null) {
if (selStart != text.length() || selEnd != text.length()) {
setSelection(text.length(), text.length());
return;
}
}
super.onSelectionChanged(selStart, selEnd);
}
#Override
public boolean isSuggestionsEnabled() {
return false;
}
#Override
public int getSelectionStart() {
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (element.getMethodName().equals("canPaste")) {
return -1;
}
}
return super.getSelectionStart();
}
}
MainActivity
import androidx.appcompat.app.AppCompatActivity;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends AppCompatActivity {
NoMenuEditText edt_username;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt_username = (NoMenuEditText) findViewById(R.id.edt_username);
edt_username.setLongClickable(false);
edt_username.setTextIsSelectable(false);
edt_username.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode actionMode) {
}
});
}
}
drawable- zeropx.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="0dp"
android:height="0dp"/>
</shape>
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="NoMenuEditText">
<attr name="isCopyPasteDisabled" format="boolean" />
</declare-styleable>
</resources>
At Last, I finally Removed the paste option from the Context Menu of EditText
Thank you StackOverflow posts and http://androidinformative.com/disabling-context-menu/
editText.apply {
setOnTouchListener { v, event ->
if (event.action == KeyEvent.ACTION_DOWN) {
requestFocus()
setSelection(text.toString().length)
showKeyboard()
return#setOnTouchListener true
}
}
}
fun View.showKeyboard() {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(this, 0)
}
Actually in my case i had to set the callback for both selection and insertion and only then i got the copy/paste pop-up to not appear anymore.
Something like this :
private void disableCopyPaste() {
input.setLongClickable(false);
input.setTextIsSelectable(false);
final ActionMode.Callback disableCopyPasteCallback = new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode actionMode) {
}
};
input.setCustomSelectionActionModeCallback(disableCopyPasteCallback);
input.setCustomInsertionActionModeCallback(disableCopyPasteCallback);
}
Similar to GnrlKnowledge, you can clear the Clipboard
http://developer.android.com/reference/android/text/ClipboardManager.html
If you want, preserve the text in the Clipboard, and on onDestroy, you can set it again.