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/>.
|
|
|
|
|
2022-01-01 08:46:36 +00:00
|
|
|
Copyright 2018-2022 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;
|
2021-02-12 07:44:37 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputConnection;
|
|
|
|
import android.view.inputmethod.InputConnectionWrapper;
|
2020-03-18 07:38:04 +00:00
|
|
|
|
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);
|
2021-01-17 08:56:37 +00:00
|
|
|
Helper.setKeyboardIncognitoMode(this, context);
|
2020-03-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public EditTextPlain(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2021-01-17 08:56:37 +00:00
|
|
|
Helper.setKeyboardIncognitoMode(this, context);
|
2020-03-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public EditTextPlain(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
2021-01-17 08:56:37 +00:00
|
|
|
Helper.setKeyboardIncognitoMode(this, context);
|
2020-03-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-02-12 07:44:37 +00:00
|
|
|
@Override
|
|
|
|
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
|
|
|
|
InputConnection ic = super.onCreateInputConnection(editorInfo);
|
|
|
|
if (ic == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return new InputConnectionWrapper(ic, true) {
|
|
|
|
@Override
|
|
|
|
public boolean commitText(CharSequence text, int newCursorPosition) {
|
2022-01-20 14:07:20 +00:00
|
|
|
try {
|
|
|
|
return super.commitText(text.toString(), newCursorPosition);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
return false;
|
|
|
|
/*
|
2022-01-30 15:12:12 +00:00
|
|
|
https://issuetracker.google.com/issues/216891011
|
2022-01-20 14:07:20 +00:00
|
|
|
java.lang.IndexOutOfBoundsException: 199, -198
|
|
|
|
at android.text.PackedIntVector.deleteAt(PackedIntVector.java:222)
|
|
|
|
at android.text.DynamicLayout.reflow(DynamicLayout.java:317)
|
|
|
|
at android.text.DynamicLayout.-wrap0(Unknown Source:0)
|
|
|
|
at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:750)
|
|
|
|
at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:779)
|
|
|
|
at androidx.emoji2.text.SpannableBuilder$WatcherWrapper.onSpanChanged(SourceFile:2)
|
|
|
|
at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1296)
|
|
|
|
at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:651)
|
|
|
|
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:581)
|
|
|
|
at androidx.emoji2.text.SpannableBuilder.replace(SourceFile:7)
|
|
|
|
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:504)
|
|
|
|
at androidx.emoji2.text.SpannableBuilder.replace(SourceFile:4)
|
|
|
|
at androidx.emoji2.text.SpannableBuilder.replace(SourceFile:1)
|
|
|
|
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:848)
|
|
|
|
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:197)
|
|
|
|
at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:183)
|
|
|
|
at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:158)
|
|
|
|
at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:158)
|
|
|
|
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:344)
|
|
|
|
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
|
|
|
|
*/
|
|
|
|
}
|
2021-02-12 07:44:37 +00:00
|
|
|
}
|
2021-06-13 15:16:18 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getSelectedText(int flags) {
|
|
|
|
try {
|
|
|
|
return super.getSelectedText(flags);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
return null;
|
|
|
|
/*
|
|
|
|
java.lang.IndexOutOfBoundsException: getChars (-1 ... 52) starts before 0
|
|
|
|
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
|
|
|
|
at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:1191)
|
|
|
|
at android.text.TextUtils.getChars(TextUtils.java:100)
|
|
|
|
at android.text.SpannableStringBuilder.<init>(SpannableStringBuilder.java:67)
|
|
|
|
at android.text.SpannableStringBuilder.subSequence(SpannableStringBuilder.java:1183)
|
|
|
|
at android.view.inputmethod.BaseInputConnection.getSelectedText(BaseInputConnection.java:528)
|
|
|
|
at android.view.inputmethod.InputConnectionWrapper.getSelectedText(InputConnectionWrapper.java:94)
|
|
|
|
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:286)
|
|
|
|
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
|
|
|
|
at android.os.Handler.dispatchMessage(Handler.java:106)
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 07:44:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|