Example usage for android.text SpannableStringBuilder removeSpan

List of usage examples for android.text SpannableStringBuilder removeSpan

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder removeSpan.

Prototype

public void removeSpan(Object what) 

Source Link

Document

Remove the specified markup object from the buffer.

Usage

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

private static void endSpan(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Href.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        Href h = (Href) obj;/*  w  ww. j a v a2s.  c o m*/
        if (h != null && h.mHref != null) {
            if (ZulipApp.get().getEmail().equals(h.mHref)) {
                text.setSpan(new ForegroundColorSpan(userMentionSelfColor), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                text.setSpan(new ProfileSpan(h.mHref, userMentionColor), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

private static void end(SpannableStringBuilder text, Class kind, Object repl) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    if (where != len) {
        text.setSpan(repl, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/*from   ww  w .  ja v  a2 s.c  o  m*/

}

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

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

    text.removeSpan(obj);

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = res.getColorStateList(colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }/*  w  w w. j a  v a 2  s  . c  o m*/
            } else {
                int c = getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

private static void endMultiple(SpannableStringBuilder text, Class kind, Object[] replArray) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    if (where != len) {
        for (Object repl : replArray) {
            text.setSpan(repl, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from   w w w  .j a  v  a 2 s.  c  om*/
    }

}

From source file:Main.java

/**
 * Make UI TextView a html link./*from   w w  w.  j  ava  2s.co m*/
 * 
 * @param context the context
 * @param textView the text view
 * @param html the html containing link info
 */
public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) {
    textView.setLinksClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (final URLSpan urlSpan : urls) {
        int start = spannableStringBuilder.getSpanStart(urlSpan);
        int end = spannableStringBuilder.getSpanEnd(urlSpan);
        int flags = spannableStringBuilder.getSpanFlags(urlSpan);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL()));
                context.startActivity(intent);
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setUnderlineText(false);
            }
        };
        spannableStringBuilder.removeSpan(urlSpan);
        spannableStringBuilder.setSpan(clickable, start, end, flags);
    }
    textView.setText(spannableStringBuilder);
}

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);

    if (where != len) {
        Href h = (Href) obj;/*from  w ww.  ja v a  2  s.  c o  m*/

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

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

private static void endHeader(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Header.class);

    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    // Back off not to change only the text, not the blank line.
    while (len > where && text.charAt(len - 1) == '\n') {
        len--;//from w w w.ja va 2s.  c  om
    }

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

        text.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new StyleSpan(Typeface.BOLD), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

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

private static void end(SpannableStringBuilder text, Class<?> kind, Object repl) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    if (where != len) {
        text.setSpan(repl, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/*from   w w  w  .j  av a  2 s.c o  m*/
}

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

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

    text.removeSpan(obj);

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = CompatibilityUtils.getColorStateList(res, colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }//ww w . j a v a  2s.c om
            } else {
                int c = ColorHidden.getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if (f.mStyle != null) {
            List<Object> styleSpans = parseStyleAttributes(f.mStyle);
            for (Object span : styleSpans) {
                text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}

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

private static void endBlockquote(SpannableStringBuilder text, ThemeColors colors) {
    int len = text.length();
    Object obj = getLast(text, Blockquote.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);

    if (where != len) {
        Blockquote b = (Blockquote) obj;
        if (b.mIsUnkfunc) {
            if (colors != null) {
                text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }/*www  .ja  va  2s. c  o m*/
        } else {
            text.setSpan(new QuoteSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}