Copy message text selection with style

pull/184/head
M66B 4 years ago
parent a013f500f0
commit 71f1b34eca

@ -180,7 +180,7 @@ public class EditTextCompose extends FixedEditText {
at android.widget.TextView.paste(TextView.java:8891)
at android.widget.TextView.onTextContextMenuItem(TextView.java:8706)
*/
Log.w(ex);
Log.e(ex);
return false;
}
}

@ -56,7 +56,7 @@ public class EditTextPlain extends FixedEditText {
return super.onTextContextMenuItem(id);
} catch (Throwable ex) {
Log.w(ex);
Log.e(ex);
return false;
}
}

@ -19,9 +19,14 @@ package eu.faircode.email;
Copyright 2018-2020 by Marcel Bokhorst (M66B)
*/
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.text.Selection;
import android.text.Spannable;
import android.text.Spanned;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@ -231,4 +236,37 @@ public class FixedTextView extends AppCompatTextView {
*/
}
}
@Override
public boolean onTextContextMenuItem(int id) {
try {
if (id == android.R.id.copy) {
int start = getSelectionStart();
int end = getSelectionEnd();
if (start > end) {
int s = start;
start = end;
end = s;
}
Context context = getContext();
ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (start != end && cbm != null) {
CharSequence selected = getText().subSequence(start, end);
if (selected instanceof Spanned) {
String html = HtmlHelper.toHtml((Spanned) selected, context);
cbm.setPrimaryClip(ClipData.newHtmlText(context.getString(R.string.app_name), selected, html));
if (getText() instanceof Spannable)
Selection.removeSelection((Spannable) getText());
return false;
}
}
}
return super.onTextContextMenuItem(id);
} catch (Throwable ex) {
Log.e(ex);
return false;
}
}
}

Loading…
Cancel
Save