@@ -65,7 +65,6 @@ import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.ui.util.MyLinkify;
import eu.siacs.conversations.ui.util.ViewUtil;
import eu.siacs.conversations.ui.widget.ClickableMovementMethod;
-import eu.siacs.conversations.ui.widget.CopyTextView;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.EmojiWrapper;
import eu.siacs.conversations.utils.Emoticons;
@@ -77,7 +76,7 @@ import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.mam.MamReference;
-public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
+public class MessageAdapter extends ArrayAdapter<Message> {
public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR";
private static final int SENT = 0;
@@ -671,9 +670,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
default:
throw new AssertionError("Unknown view type");
}
- if (viewHolder.messageBody != null) {
- viewHolder.messageBody.setCopyHandler(this);
- }
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
@@ -868,38 +864,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void promptOpenKeychainInstall(View view) {
activity.showInstallPgpDialog();
}
-
- private String transformText(CharSequence text, int start, int end, boolean forCopy) {
- SpannableStringBuilder builder = new SpannableStringBuilder(text);
- Object copySpan = new Object();
- builder.setSpan(copySpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- DividerSpan[] dividerSpans = builder.getSpans(0, builder.length(), DividerSpan.class);
- for (DividerSpan dividerSpan : dividerSpans) {
- builder.replace(builder.getSpanStart(dividerSpan), builder.getSpanEnd(dividerSpan),
- dividerSpan.isLarge() ? "\n\n" : "\n");
- }
- start = builder.getSpanStart(copySpan);
- end = builder.getSpanEnd(copySpan);
- if (start == -1 || end == -1) return "";
- builder = new SpannableStringBuilder(builder, start, end);
- if (forCopy) {
- QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
- for (QuoteSpan quoteSpan : quoteSpans) {
- builder.insert(builder.getSpanStart(quoteSpan), "> ");
- }
- }
- return builder.toString();
- }
-
- @Override
- public String transformTextForCopy(CharSequence text, int start, int end) {
- if (text instanceof Spanned) {
- return transformText(text, start, end, true);
- } else {
- return text.toString().substring(start, end);
- }
- }
-
+
public FileBackend getFileBackend() {
return activity.xmppConnectionService.getFileBackend();
}
@@ -969,56 +934,9 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
protected ImageView indicator;
protected ImageView indicatorReceived;
protected TextView time;
- protected CopyTextView messageBody;
+ protected TextView messageBody;
protected ImageView contact_picture;
protected TextView status_message;
protected TextView encryption;
}
-
-
- private class MessageBodyActionModeCallback implements ActionMode.Callback {
-
- private final TextView textView;
-
- public MessageBodyActionModeCallback(TextView textView) {
- this.textView = textView;
- }
-
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- if (onQuoteListener != null) {
- int quoteResId = activity.getThemeResource(R.attr.icon_quote, R.drawable.ic_action_reply);
- // 3rd item is placed after "copy" item
- menu.add(0, android.R.id.button1, 3, R.string.quote).setIcon(quoteResId)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
- return false;
- }
-
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false;
- }
-
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- if (item.getItemId() == android.R.id.button1) {
- int start = textView.getSelectionStart();
- int end = textView.getSelectionEnd();
- if (end > start) {
- String text = transformText(textView.getText(), start, end, false);
- if (onQuoteListener != null) {
- onQuoteListener.onQuote(text);
- }
- mode.finish();
- }
- return true;
- }
- return false;
- }
-
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- }
- }
}
@@ -1,58 +0,0 @@
-package eu.siacs.conversations.ui.widget;
-
-import android.content.ClipData;
-import android.content.ClipboardManager;
-import android.content.Context;
-import android.support.v7.widget.AppCompatTextView;
-import android.util.AttributeSet;
-
-public class CopyTextView extends AppCompatTextView {
-
- public CopyTextView(Context context) {
- super(context);
- }
-
- public CopyTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public CopyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-
- public interface CopyHandler {
- String transformTextForCopy(CharSequence text, int start, int end);
- }
-
- private CopyHandler copyHandler;
-
- public void setCopyHandler(CopyHandler copyHandler) {
- this.copyHandler = copyHandler;
- }
-
- @Override
- public boolean onTextContextMenuItem(int id) {
- final CharSequence text = getText();
- int min = 0;
- int max = text.length();
- if (isFocused()) {
- final int selStart = getSelectionStart();
- final int selEnd = getSelectionEnd();
- min = Math.max(0, Math.min(selStart, selEnd));
- max = Math.max(0, Math.max(selStart, selEnd));
- }
- String textForCopy = null;
- if (id == android.R.id.copy && copyHandler != null) {
- textForCopy = copyHandler.transformTextForCopy(getText(), min, max);
- }
- try {
- return super.onTextContextMenuItem(id);
- } finally {
- if (textForCopy != null) {
- ClipboardManager clipboard = (ClipboardManager) getContext().
- getSystemService(Context.CLIPBOARD_SERVICE);
- clipboard.setPrimaryClip(ClipData.newPlainText(null, textForCopy));
- }
- }
- }
-}
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <eu.siacs.conversations.ui.widget.CopyTextView
+ <TextView
android:id="@+id/message_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
- android:longClickable="true"
+ android:longClickable="false"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/>
<ImageView