use of org.thoughtcrime.securesms.util.LongClickCopySpan in project Signal-Android by signalapp.
the class SubmitDebugLogActivity method presentResultDialog.
private void presentResultDialog(@NonNull String url) {
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.SubmitDebugLogActivity_success).setCancelable(false).setNeutralButton(android.R.string.ok, (d, w) -> finish()).setPositiveButton(R.string.SubmitDebugLogActivity_share, (d, w) -> {
ShareCompat.IntentBuilder.from(this).setText(url).setType("text/plain").setEmailTo(new String[] { "support@signal.org" }).startChooser();
});
String dialogText = getResources().getString(R.string.SubmitDebugLogActivity_copy_this_url_and_add_it_to_your_issue, url);
SpannableString spannableDialogText = new SpannableString(dialogText);
TextView dialogView = new TextView(builder.getContext());
LongClickCopySpan longClickUrl = new LongClickCopySpan(url);
LinkifyCompat.addLinks(spannableDialogText, Linkify.WEB_URLS);
URLSpan[] spans = spannableDialogText.getSpans(0, spannableDialogText.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = spannableDialogText.getSpanStart(span);
int end = spannableDialogText.getSpanEnd(span);
spannableDialogText.setSpan(longClickUrl, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
dialogView.setText(spannableDialogText);
dialogView.setMovementMethod(LongClickMovementMethod.getInstance(this));
ViewUtil.setPadding(dialogView, (int) ThemeUtil.getThemedDimen(this, R.attr.dialogPreferredPadding));
builder.setView(dialogView);
builder.show();
}
use of org.thoughtcrime.securesms.util.LongClickCopySpan in project Signal-Android by signalapp.
the class ConversationItem method linkifyMessageBody.
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);
if (hasLinks) {
URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = messageBody.getSpanStart(urlSpan);
int end = messageBody.getSpanEnd(urlSpan);
messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return messageBody;
}
use of org.thoughtcrime.securesms.util.LongClickCopySpan in project Signal-Android by WhisperSystems.
the class SubmitDebugLogActivity method presentResultDialog.
private void presentResultDialog(@NonNull String url) {
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.SubmitDebugLogActivity_success).setCancelable(false).setNeutralButton(android.R.string.ok, (d, w) -> finish()).setPositiveButton(R.string.SubmitDebugLogActivity_share, (d, w) -> {
ShareCompat.IntentBuilder.from(this).setText(url).setType("text/plain").setEmailTo(new String[] { "support@signal.org" }).startChooser();
});
String dialogText = getResources().getString(R.string.SubmitDebugLogActivity_copy_this_url_and_add_it_to_your_issue, url);
SpannableString spannableDialogText = new SpannableString(dialogText);
TextView dialogView = new TextView(builder.getContext());
LongClickCopySpan longClickUrl = new LongClickCopySpan(url);
LinkifyCompat.addLinks(spannableDialogText, Linkify.WEB_URLS);
URLSpan[] spans = spannableDialogText.getSpans(0, spannableDialogText.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = spannableDialogText.getSpanStart(span);
int end = spannableDialogText.getSpanEnd(span);
spannableDialogText.setSpan(longClickUrl, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
dialogView.setText(spannableDialogText);
dialogView.setMovementMethod(LongClickMovementMethod.getInstance(this));
ViewUtil.setPadding(dialogView, (int) ThemeUtil.getThemedDimen(this, R.attr.dialogPreferredPadding));
builder.setView(dialogView);
builder.show();
}
use of org.thoughtcrime.securesms.util.LongClickCopySpan in project Signal-Android by WhisperSystems.
the class GroupDescriptionUtil method setText.
/**
* Set a group description.
*
* @param description full description
* @param emojiTextView Text view to update with description
* @param linkify flag indicating if web urls should be linkified
* @param moreClick Callback for when truncating and need to show more via another means. Required to enable truncating.
*/
public static void setText(@NonNull Context context, @NonNull EmojiTextView emojiTextView, @NonNull String description, boolean linkify, @Nullable Runnable moreClick) {
boolean shouldEllipsize = moreClick != null;
String scrubbedDescription = shouldEllipsize ? description.replaceAll("\\n", " ") : description;
SpannableString descriptionSpannable = new SpannableString(scrubbedDescription);
if (linkify) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = LinkifyCompat.addLinks(descriptionSpannable, linkPattern);
if (hasLinks) {
Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class)).filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL())).forEach(descriptionSpannable::removeSpan);
URLSpan[] urlSpans = descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = descriptionSpannable.getSpanStart(urlSpan);
int end = descriptionSpannable.getSpanEnd(urlSpan);
URLSpan span = new LongClickCopySpan(urlSpan.getURL());
descriptionSpannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
if (shouldEllipsize) {
ClickableSpan style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
moreClick.run();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
emojiTextView.setEllipsize(TextUtils.TruncateAt.END);
emojiTextView.setMaxLines(2);
SpannableString overflowText = new SpannableString(context.getString(R.string.ManageGroupActivity_more));
overflowText.setSpan(style, 0, overflowText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiTextView.setOverflowText(overflowText);
}
emojiTextView.setText(descriptionSpannable);
}
use of org.thoughtcrime.securesms.util.LongClickCopySpan in project Signal-Android by signalapp.
the class GroupDescriptionUtil method setText.
/**
* Set a group description.
*
* @param description full description
* @param emojiTextView Text view to update with description
* @param linkify flag indicating if web urls should be linkified
* @param moreClick Callback for when truncating and need to show more via another means. Required to enable truncating.
*/
public static void setText(@NonNull Context context, @NonNull EmojiTextView emojiTextView, @NonNull String description, boolean linkify, @Nullable Runnable moreClick) {
boolean shouldEllipsize = moreClick != null;
String scrubbedDescription = shouldEllipsize ? description.replaceAll("\\n", " ") : description;
SpannableString descriptionSpannable = new SpannableString(scrubbedDescription);
if (linkify) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = LinkifyCompat.addLinks(descriptionSpannable, linkPattern);
if (hasLinks) {
Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class)).filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL())).forEach(descriptionSpannable::removeSpan);
URLSpan[] urlSpans = descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = descriptionSpannable.getSpanStart(urlSpan);
int end = descriptionSpannable.getSpanEnd(urlSpan);
URLSpan span = new LongClickCopySpan(urlSpan.getURL());
descriptionSpannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
if (shouldEllipsize) {
ClickableSpan style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
moreClick.run();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
emojiTextView.setEllipsize(TextUtils.TruncateAt.END);
emojiTextView.setMaxLines(2);
SpannableString overflowText = new SpannableString(context.getString(R.string.ManageGroupActivity_more));
overflowText.setSpan(style, 0, overflowText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiTextView.setOverflowText(overflowText);
}
emojiTextView.setText(descriptionSpannable);
}
Aggregations