當前位置: 首頁>>代碼示例>>Java>>正文


Java URLSpan類代碼示例

本文整理匯總了Java中android.text.style.URLSpan的典型用法代碼示例。如果您正苦於以下問題:Java URLSpan類的具體用法?Java URLSpan怎麽用?Java URLSpan使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


URLSpan類屬於android.text.style包,在下文中一共展示了URLSpan類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setHtmlWithLinkClickHandler

import android.text.style.URLSpan; //導入依賴的package包/類
public static void setHtmlWithLinkClickHandler(TextView tv, String html,
                                        Action1<String> linkClickHandler) {
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (URLSpan span : urls) {
        int start = strBuilder.getSpanStart(span);
        int end = strBuilder.getSpanEnd(span);
        int flags = strBuilder.getSpanFlags(span);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                linkClickHandler.call(span.getURL());
            }
        };
        strBuilder.setSpan(clickable, start, end, flags);
        strBuilder.removeSpan(span);
    }
    tv.setText(strBuilder);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:21,代碼來源:AppUtils.java

示例2: getText

import android.text.style.URLSpan; //導入依賴的package包/類
/**
 * @param context
 * @param spannable
 * @param title
 * @return
 */
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
	if (spannable == null || spannable.length() <= 0) {
		Log.e(TAG, "getText  spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
		return new SpannableStringBuilder();
	}

	SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
	builder.clearSpans();// should clear old spans
	URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
	if (urls != null) {
		for (URLSpan urlSpan : urls) {
			if (urlSpan != null) {
				MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
				builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
						.getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			}
		}
	}

	return builder;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:MyURLSpan.java

示例3: linkifyHtml

import android.text.style.URLSpan; //導入依賴的package包/類
/**
 * Taken from Stack Overflow - https://stackoverflow.com/a/17201376/6052295
 * Adds links to a HTML string
 *
 * @param html        the HTML string to add links to
 * @param linkifyMask the link type
 * @return The spannable text with clickable links
 */

public static Spannable linkifyHtml(String html, int linkifyMask) {
    Spanned text = fromHtml(fromHtml(html).toString());
    URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class);

    SpannableString buffer = new SpannableString(text);
    Linkify.addLinks(buffer, linkifyMask);

    for (URLSpan span : currentSpans) {
        int end = text.getSpanEnd(span);
        int start = text.getSpanStart(span);
        buffer.setSpan(span, start, end, 0);
    }
    return buffer;
}
 
開發者ID:jthomperoo,項目名稱:Forge,代碼行數:24,代碼來源:GeneratorFragment.java

示例4: dealUnderLinesData

import android.text.style.URLSpan; //導入依賴的package包/類
/**
 * 解析link
 *
 * @param tv_content
 * @param context
 */
private static void dealUnderLinesData(TextView tv_content, Context context) {
    CharSequence charSequence = tv_content.getText();
    if (charSequence instanceof Spannable) {
        tv_content.setText("");
        Spannable s = EmojiDisplay.spannableFilter(tv_content.getContext(),
                new SpannableStringBuilder(charSequence),
                charSequence,
                EmoticonsKeyboardUtils.getFontHeight(tv_content));
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            String clickText = s.subSequence(start, end).toString();
            URLSpanNoUnderline urlSpanNoUnderline = new URLSpanNoUnderline(context, span.getURL(), clickText);
            s.setSpan(urlSpanNoUnderline, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        tv_content.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:26,代碼來源:CustomTextView.java

示例5: dealAILink

import android.text.style.URLSpan; //導入依賴的package包/類
/**
 * 解析機器人對話link
 *
 * @param textView
 */
private static void dealAILink(TextView textView, String type) {
    CharSequence charSequence = textView.getText();
    if (charSequence instanceof Spannable) {
        textView.setText("");
        Spannable s = (Spannable) charSequence;
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            String clickContent = s.subSequence(start, end).toString();
            AIURLSpan myURLSpan = new AIURLSpan(span.getURL(), type, clickContent, textView.getContext());
            s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:22,代碼來源:CustomTextView.java

示例6: dealCustomLink

import android.text.style.URLSpan; //導入依賴的package包/類
/**
 * 解析富文本link
 *
 * @param textView
 */
private static void dealCustomLink(TextView textView) {
    CharSequence charSequence = textView.getText();
    if (charSequence instanceof Spannable) {
        textView.setText("");
        Spannable s = (Spannable) charSequence;
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            CustomClickSpan myURLSpan = new CustomClickSpan(textView.getContext(), span.getURL());
            s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.append(s);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:21,代碼來源:CustomTextView.java

示例7: onLongPress

import android.text.style.URLSpan; //導入依賴的package包/類
@Override
protected void onLongPress() {
    if (pressedLink instanceof URLSpanNoUnderline) {
        URLSpanNoUnderline url = (URLSpanNoUnderline) pressedLink;
        if (url.getURL().startsWith("/")) {
            delegate.didPressedUrl(currentMessageObject, pressedLink, true);
            return;
        }
    } else if (pressedLink instanceof URLSpan) {
        delegate.didPressedUrl(currentMessageObject, pressedLink, true);
        return;
    }
    resetPressedLink(-1);
    if (buttonPressed != 0 || pressedBotButton != -1) {
        buttonPressed = 0;
        pressedBotButton = -1;
        invalidate();
    }
    if (delegate != null) {
        delegate.didLongPressed(this);
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:23,代碼來源:ChatMessageCell.java

示例8: makeLinksClickable

import android.text.style.URLSpan; //導入依賴的package包/類
public static void makeLinksClickable(TextView v) {
	SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
	URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
	for (URLSpan span : spans) {
		int start = ssb.getSpanStart(span);
		int end = ssb.getSpanEnd(span);
		final String url = span.getURL();
		ssb.removeSpan(span);
		ClickableSpan cSpan = new ClickableSpan() {
			@Override
			public void onClick(View v2) {
				LinkDialogFragment f = LinkDialogFragment.newInstance(url);
				FragmentManager fm = ((AppCompatActivity) v2.getContext())
						.getSupportFragmentManager();
				f.show(fm, f.getUniqueTag());
			}
		};
		ssb.setSpan(cSpan, start, end, 0);
	}
	v.setText(ssb);
	v.setMovementMethod(ArticleMovementMethod.getInstance());
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:UiUtils.java

示例9: OrgSpannable

import android.text.style.URLSpan; //導入依賴的package包/類
public OrgSpannable(String str) {
    SpannableStringBuilder ssb = OrgFormatter.INSTANCE.parse(context, str);

    string = ssb.toString();

    Object[] allSpans = ssb.getSpans(0, ssb.length() - 1, Object.class);

    spans = new OrgSpan[allSpans.length];

    for (int i = 0; i < allSpans.length; i++) {
        spans[i] = new OrgSpan();

        spans[i].start = ssb.getSpanStart(allSpans[i]);
        spans[i].end = ssb.getSpanEnd(allSpans[i]);
        spans[i].className = allSpans[i].getClass().getSimpleName();

        if (allSpans[i] instanceof URLSpan) {
            spans[i].url = ((URLSpan)allSpans[i]).getURL();
        }
    }
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:22,代碼來源:OrgFormatterTest.java

示例10: setHtmlFromHelpFile

import android.text.style.URLSpan; //導入依賴的package包/類
private void setHtmlFromHelpFile(String file) {
    htmltv.setHtml(getHelpFileContents(file));
    htmltv.setText(RichTextUtils.replaceAll((Spanned) htmltv.getText(), URLSpan.class, new RichTextUtils.URLSpanConverter(), new RichTextUtils.ClickSpan.OnClickListener() {
        @Override
        public void onClick(String url) {
            if(mListener == null) {
                return;
            }
            if (url.startsWith("help:")) {
                mListener.onHelpLinkClicked(url.substring(5));
            } else if (url.startsWith("station:")) {
                mListener.onStationLinkClicked(url.substring(8));
            } else if (url.startsWith("mailto:")) {
                mListener.onMailtoLinkClicked(url.substring(7));
            } else {
                mListener.onLinkClicked(url);
            }
        }
    }));
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:21,代碼來源:HelpFragment.java

示例11: setApplication

import android.text.style.URLSpan; //導入依賴的package包/類
private void setApplication(@Nullable Status.Application app) {
    if (app != null) {

        timestampInfo.append("  •  ");

        if (app.website != null) {
            URLSpan span = new CustomURLSpan(app.website);

            SpannableStringBuilder text = new SpannableStringBuilder(app.name);
            text.setSpan(span, 0, app.name.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            timestampInfo.append(text);
            timestampInfo.setMovementMethod(LinkMovementMethod.getInstance());
        } else {
            timestampInfo.append(app.name);
        }
    }
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:18,代碼來源:StatusDetailedViewHolder.java

示例12: onUploadSuccess

import android.text.style.URLSpan; //導入依賴的package包/類
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
    item.id = media.id;
    item.preview.setProgress(-1);
    item.readyStage = QueuedMedia.ReadyStage.UPLOADED;

    /* Add the upload URL to the text field. Also, keep a reference to the span so if the user
     * chooses to remove the media, the URL is also automatically removed. */
    item.uploadUrl = new URLSpan(media.textUrl);
    int end = 1 + media.textUrl.length();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(' ');
    builder.append(media.textUrl);
    builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    int cursorStart = textEditor.getSelectionStart();
    int cursorEnd = textEditor.getSelectionEnd();
    textEditor.append(builder);
    textEditor.setSelection(cursorStart, cursorEnd);

    waitForMediaLatch.countDown();
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:21,代碼來源:ComposeActivity.java

示例13: onCreate

import android.text.style.URLSpan; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_invite_friends);
    ButterKnife.bind(this);
    Intent intent = getIntent();
    String addresseeName = intent.getStringExtra("contactName");
    addresseePhone = intent.getStringExtra("contactPhone");
    mAddresseeName.setText(addresseeName);
    SpannableString  inviteMessage = new SpannableString(this.getResources().getString(R.string.mine_send_message));
    message = this.getResources().getString(R.string.mine_send_message);
    inviteMessage.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 54, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    inviteMessage.setSpan(new URLSpan("http://www.xingka.cc"), 54, 74,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    inviteMessage.setSpan(new ForegroundColorSpan(Color.BLACK), 74, 88, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mInviteMessage.setText(inviteMessage);
    mInviteMessage.setMovementMethod(LinkMovementMethod.getInstance());

}
 
開發者ID:LegendKe,項目名稱:MyTravelingDiary,代碼行數:19,代碼來源:InviteFriendsActivity.java

示例14: convertToLinkSpan

import android.text.style.URLSpan; //導入依賴的package包/類
public static void convertToLinkSpan(Context context, TextView textView) {
    Spannable s = new SpannableString(textView.getText());

    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);

    for (URLSpan span : spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);

        s.removeSpan(span);
        span = new LinkSpan(context, span.getURL());
        s.setSpan(span, start, end, 0);
    }

    textView.setText(s);
}
 
開發者ID:tomatrocho,項目名稱:insapp-android,代碼行數:17,代碼來源:Utils.java

示例15: getTransformation

import android.text.style.URLSpan; //導入依賴的package包/類
@Override
public CharSequence getTransformation(CharSequence src, View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        Linkify.addLinks(textView, Linkify.WEB_URLS);

        if (textView.getText() != null && textView.getText() instanceof Spannable) {
            Spannable text = (Spannable) textView.getText();
            URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
            for (int i = spans.length - 1; i >= 0; i--) {
                URLSpan oldSpan = spans[i];
                int start = text.getSpanStart(oldSpan), end = text.getSpanEnd(oldSpan);
                String url = oldSpan.getURL();

                text.removeSpan(oldSpan);
                text.setSpan(new CustomTabsURLSpan(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            return text;
        }
    }
    return src;
}
 
開發者ID:TheAndroidMaster,項目名稱:Paper-Tales,代碼行數:23,代碼來源:WallActivity.java


注:本文中的android.text.style.URLSpan類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。