More clean ups
parent
088368769d
commit
ddd7338853
@ -1,61 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
|
||||||
|
|
||||||
import android.content.ClipData;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.TextPaint;
|
|
||||||
import android.text.style.URLSpan;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.ColorInt;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class LongClickCopySpan extends URLSpan {
|
|
||||||
private static final String PREFIX_MAILTO = "mailto:";
|
|
||||||
private static final String PREFIX_TEL = "tel:";
|
|
||||||
|
|
||||||
private boolean isHighlighted;
|
|
||||||
@ColorInt
|
|
||||||
private int highlightColor;
|
|
||||||
|
|
||||||
public LongClickCopySpan(String url) {
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onLongClick(View widget) {
|
|
||||||
Context context = widget.getContext();
|
|
||||||
String preparedUrl = prepareUrl(getURL());
|
|
||||||
copyUrl(context, preparedUrl);
|
|
||||||
Toast.makeText(context,
|
|
||||||
context.getString(R.string.ConversationItem_copied_text, preparedUrl), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDrawState(@NonNull TextPaint ds) {
|
|
||||||
super.updateDrawState(ds);
|
|
||||||
ds.bgColor = highlightColor;
|
|
||||||
ds.setUnderlineText(!isHighlighted);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyUrl(Context context, String url) {
|
|
||||||
copyUriSdk11(context, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyUriSdk11(Context context, String url) {
|
|
||||||
android.content.ClipboardManager clipboard =
|
|
||||||
(android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
ClipData clip = ClipData.newPlainText(context.getString(R.string.app_name), url);
|
|
||||||
clipboard.setPrimaryClip(clip);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String prepareUrl(String url) {
|
|
||||||
if (url.startsWith(PREFIX_MAILTO)) {
|
|
||||||
return url.substring(PREFIX_MAILTO.length());
|
|
||||||
} else if (url.startsWith(PREFIX_TEL)) {
|
|
||||||
return url.substring(PREFIX_TEL.length());
|
|
||||||
}
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue