Search in sources :

Example 91 with URLSpan

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;
}
Also used : MainActivity(com.hippo.ehviewer.ui.MainActivity) Activity(android.app.Activity) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) URLSpan(android.text.style.URLSpan) ClickableSpan(android.text.style.ClickableSpan)

Example 92 with URLSpan

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);
}
Also used : Layout(android.text.Layout) URLSpan(android.text.style.URLSpan) ClickableSpan(android.text.style.ClickableSpan)

Example 93 with URLSpan

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);
    }
}
Also used : SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) SuppressLint(android.annotation.SuppressLint)

Example 94 with URLSpan

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 });
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Example 95 with URLSpan

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;
}
Also used : URLSpan(android.text.style.URLSpan) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) SuppressLint(android.annotation.SuppressLint)

Aggregations

URLSpan (android.text.style.URLSpan)134 SpannableString (android.text.SpannableString)36 Spannable (android.text.Spannable)22 SpannableStringBuilder (android.text.SpannableStringBuilder)21 TextPaint (android.text.TextPaint)21 Spanned (android.text.Spanned)20 TextView (android.widget.TextView)19 ForegroundColorSpan (android.text.style.ForegroundColorSpan)16 StyleSpan (android.text.style.StyleSpan)16 UnderlineSpan (android.text.style.UnderlineSpan)14 Paint (android.graphics.Paint)13 ImageSpan (android.text.style.ImageSpan)13 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)13 View (android.view.View)13 Intent (android.content.Intent)12 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)12 ClickableSpan (android.text.style.ClickableSpan)12 SubscriptSpan (android.text.style.SubscriptSpan)12