Example usage for android.text.style URLSpan URLSpan

List of usage examples for android.text.style URLSpan URLSpan

Introduction

In this page you can find the example usage for android.text.style URLSpan URLSpan.

Prototype

public URLSpan(@NonNull Parcel src) 

Source Link

Document

Constructs a URLSpan from a parcel.

Usage

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endA(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Href.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);/*from ww  w .  ja v  a  2s .  c o  m*/

    if (where != len) {
        Href h = (Href) obj;

        if (h.mHref != null) {
            text.setSpan(new URLSpan(h.mHref), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:org.miaowo.miaowo.util.Html.java

private static void endA(Editable text) {
    int len = text.length();
    Href h = getLast(text, Href.class);
    if (h != null) {
        if (h.mHref != null) {
            setSpanFromMark(text, h, new URLSpan((h.mHref)));
        }//w w  w  . j a  va 2s  .  c o  m
    }
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void onUploadSuccess(final QueuedMedia item, Media media) {
    item.id = media.id;/*from w  ww. j  a v a  2s .c o  m*/

    /* 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, 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textEditor.append(builder);

    waitForMediaLatch.countDown();
}

From source file:ru.valle.btc.MainActivity.java

private static void setUrlSpanForAddress(String domain, String address, SpannableStringBuilder builder) {
    int spanBegin = builder.toString().indexOf(domain);
    if (spanBegin >= 0) {
        URLSpan urlSpan = new URLSpan("http://" + domain + "/address/" + address);
        builder.setSpan(urlSpan, spanBegin, spanBegin + domain.length(),
                SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
    }/*ww w .  j  ava 2 s.co m*/
}

From source file:ru.valle.btc.MainActivity.java

private void showSpendPanelForKeyPair(KeyPair keyPair) {
    if (keyPair != null && keyPair.privateKey.privateKeyDecoded == null) {
        keyPair = null;// w  ww.j  a  v  a 2  s  . co  m
    }
    if (keyPair != null && !TextUtils.isEmpty(keyPair.address)) {
        currentKeyPair = keyPair;
        final String address = keyPair.address;
        String descStr = getString(R.string.raw_tx_description_header, address);
        SpannableStringBuilder builder = new SpannableStringBuilder(descStr);
        int spanBegin = descStr.indexOf(address);
        if (spanBegin >= 0) {
            ForegroundColorSpan addressColorSpan = new ForegroundColorSpan(
                    getColor(MainActivity.this, R.color.dark_orange));
            builder.setSpan(addressColorSpan, spanBegin, spanBegin + address.length(),
                    SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
        }
        rawTxDescriptionHeaderView.setText(builder);
        String wutLink = getString(R.string.raw_tx_description_wut_link);
        String jsonLink = getString(R.string.raw_tx_description_json_link);
        builder = new SpannableStringBuilder(getString(R.string.raw_tx_description, wutLink, jsonLink));

        spanBegin = builder.toString().indexOf(wutLink);
        ClickableSpan urlSpan = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                SpannableStringBuilder builder = new SpannableStringBuilder(
                        getText(R.string.raw_tx_description_wut));
                setUrlSpanForAddress("blockexplorer.com", address, builder);
                setUrlSpanForAddress("blockchain.info", address, builder);
                TextView messageView = new TextView(MainActivity.this);
                messageView.setText(builder);
                messageView.setMovementMethod(LinkMovementMethod.getInstance());
                int padding = (int) (16 * (getResources().getDisplayMetrics().densityDpi / 160f));
                messageView.setPadding(padding, padding, padding, padding);
                new AlertDialog.Builder(MainActivity.this).setView(messageView)
                        .setPositiveButton(android.R.string.ok, null).show();
            }
        };
        builder.setSpan(urlSpan, spanBegin, spanBegin + wutLink.length(),
                SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);

        spanBegin = builder.toString().indexOf(jsonLink);
        urlSpan = new URLSpan("http://blockchain.info/unspent?active=" + address);
        builder.setSpan(urlSpan, spanBegin, spanBegin + jsonLink.length(),
                SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);

        rawTxDescriptionView.setText(builder);
        rawTxDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
        onUnspentOutputsInfoChanged();
    }
    sendLayout.setVisibility(keyPair != null ? View.VISIBLE : View.GONE);
    enterPrivateKeyAck.setVisibility(keyPair == null ? View.VISIBLE : View.GONE);
}