FairEmail/app/src/main/java/eu/faircode/email/EditTextPlain.java

73 lines
2.4 KiB
Java
Raw Normal View History

2020-03-18 07:38:04 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2021-01-01 07:56:36 +00:00
Copyright 2018-2021 by Marcel Bokhorst (M66B)
2020-03-18 07:38:04 +00:00
*/
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.util.AttributeSet;
2020-04-10 18:08:48 +00:00
public class EditTextPlain extends FixedEditText {
2020-03-18 07:38:04 +00:00
public EditTextPlain(Context context) {
super(context);
}
public EditTextPlain(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EditTextPlain(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
2020-11-28 11:25:17 +00:00
@Override
protected void onAttachedToWindow() {
// Spellchecker workaround
boolean enabled = isEnabled();
super.setEnabled(true);
super.onAttachedToWindow();
super.setEnabled(enabled);
}
2020-03-18 07:38:04 +00:00
@Override
public boolean onTextContextMenuItem(int id) {
try {
if (id == android.R.id.paste) {
Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (cbm != null && cbm.hasPrimaryClip()) {
ClipData data = cbm.getPrimaryClip();
2020-08-03 18:24:44 +00:00
ClipData.Item item = (data == null ? null : data.getItemAt(0));
CharSequence text = (item == null ? null : item.coerceToText(context));
if (text != null) {
data = ClipData.newPlainText("coerced_plain_text", text.toString());
cbm.setPrimaryClip(data);
}
2020-03-18 07:38:04 +00:00
}
}
return super.onTextContextMenuItem(id);
} catch (Throwable ex) {
2020-08-26 08:05:32 +00:00
Log.e(ex);
2020-03-18 07:38:04 +00:00
return false;
}
}
}