use of android.text.style.URLSpan in project EhViewer by seven332.
the class GalleryCommentsScene method onItemClick.
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
Activity activity = getActivity2();
if (null == activity) {
return false;
}
RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
if (holder instanceof CommentHolder) {
CommentHolder commentHolder = (CommentHolder) holder;
ClickableSpan span = commentHolder.comment.getCurrentSpan();
commentHolder.comment.clearCurrentSpan();
if (span instanceof URLSpan) {
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true);
return true;
}
}
showCommentDialog(position);
return true;
}
use of android.text.style.URLSpan in project EhViewer by seven332.
the class LinkMovementMethod2 method onTouchEvent.
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
ClickableSpan span = link[0];
if (span instanceof URLSpan) {
UrlOpener.openUrl(widget.getContext(), ((URLSpan) span).getURL(), true);
} else {
span.onClick(widget);
}
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return super.onTouchEvent(widget, buffer, event);
}
use of android.text.style.URLSpan in project instructure-android by instructure.
the class ViewUtils method linkifyTextView.
/**
* Parse the links to make them clickable and override what they do (so we don't just open a different app)
* @param tv
*/
public static void linkifyTextView(TextView tv) {
SpannableString current = (SpannableString) tv.getText();
URLSpan[] spans = current.getSpans(0, current.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = current.getSpanStart(span);
int end = current.getSpanEnd(span);
current.removeSpan(span);
current.setSpan(new DefensiveURLSpan(span.getURL()), start, end, 0);
}
}
use of android.text.style.URLSpan in project android-zxing by PearceXu.
the class SupplementalInfoRetriever method append.
final void append(String itemID, String source, String[] newTexts, String linkURL) {
StringBuilder newTextCombined = new StringBuilder();
if (source != null) {
newTextCombined.append(source).append(' ');
}
int linkStart = newTextCombined.length();
boolean first = true;
for (String newText : newTexts) {
if (first) {
newTextCombined.append(newText);
first = false;
} else {
newTextCombined.append(" [");
newTextCombined.append(newText);
newTextCombined.append(']');
}
}
int linkEnd = newTextCombined.length();
String newText = newTextCombined.toString();
Spannable content = new SpannableString(newText + "\n\n");
if (linkURL != null) {
// Lower-case these as it should always be OK to lower-case these schemes.
if (linkURL.startsWith("HTTP://")) {
linkURL = "http" + linkURL.substring(4);
} else if (linkURL.startsWith("HTTPS://")) {
linkURL = "https" + linkURL.substring(5);
}
content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newContents.add(content);
newHistories.add(new String[] { itemID, newText });
}
use of android.text.style.URLSpan in project twicalico by moko256.
the class TwitterStringUtils method convertUrlSpanToCustomTabs.
public static SpannableStringBuilder convertUrlSpanToCustomTabs(Spanned spanned, Context context) {
SpannableStringBuilder builder = SpannableStringBuilder.valueOf(spanned);
URLSpan[] spans = builder.getSpans(0, builder.length(), URLSpan.class);
for (URLSpan span : spans) {
int spanStart = builder.getSpanStart(span);
int spanEnd = builder.getSpanEnd(span);
ClickableSpan span1;
String firstChar = String.valueOf(builder.subSequence(spanStart, spanStart + 1));
switch(firstChar) {
case "#":
span1 = new ClickableSpan() {
@Override
public void onClick(View widget) {
context.startActivity(SearchResultActivity.getIntent(context, String.valueOf(builder.subSequence(spanStart + 1, spanEnd))));
}
};
break;
case "@":
span1 = new ClickableSpan() {
@Override
public void onClick(View widget) {
context.startActivity(ShowUserActivity.getIntent(context, String.valueOf(builder.subSequence(spanStart + 1, spanEnd))));
}
};
break;
default:
span1 = new ClickableSpan() {
@Override
public void onClick(View view) {
AppCustomTabsKt.launchChromeCustomTabs(context, span.getURL());
}
};
break;
}
builder.removeSpan(span);
builder.setSpan(span1, spanStart, spanEnd, builder.getSpanFlags(span));
}
return builder;
}
Aggregations