List of usage examples for android.text SpannableStringBuilder length
public int length()
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);/*from w ww .ja v a 2 s . c o m*/ 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); } } else { text.setSpan(new QuoteSpan(), 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);//from www . j ava 2 s. c o m if (where != len) { text.setSpan(repl, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
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);/*from w w w .j a va 2 s. co m*/ 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); } } 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 endAibspoiler(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) { int len = text.length(); Object obj = getLast(text, Aibspoiler.class); int where = text.getSpanStart(obj); text.removeSpan(obj);// w ww . j ava2 s . co m if (where != len && colors != null) { if (openSpoilers) { text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void handleP(SpannableStringBuilder text, int startLength, int[] lastPTagLengthRefs) { lastPTagLengthRefs[0] = text.length(); int len = text.length() - startLength; if (len >= 1 && text.charAt(text.length() - 1) == '\n') { if (len >= 2 && text.charAt(text.length() - 2) == '\n') { lastPTagLengthRefs[1] = text.length(); return; }//from www . java 2 s . co m text.append("\n"); lastPTagLengthRefs[1] = text.length(); return; } if (len != 0) { text.append("\n\n"); } lastPTagLengthRefs[1] = text.length(); }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
/** * ? ? SpoilerSpan ForegroundColorSpan ?? ? ?? ? */// www .ja va 2 s . co m private static void fixSpoilerSpans(SpannableStringBuilder builder, ThemeColors themeColors) { SpoilerSpan[] spoilers = builder.getSpans(0, builder.length(), SpoilerSpan.class); for (SpoilerSpan span : spoilers) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); builder.removeSpan(span); builder.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } ClickableURLSpan[] urls = builder.getSpans(0, builder.length(), ClickableURLSpan.class); for (ClickableURLSpan span : urls) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); builder.setSpan(new ForegroundColorSpan(themeColors.urlLinkForeground), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void handleLi(SpannableStringBuilder text, Object tag, int level) { if (tag == null) return;//w w w. ja v a 2s . com int len = text.length(); if (len >= 1 && text.charAt(len - 1) != '\n') text.append("\n"); for (int i = 1; i < level; ++i) text.append("\t"); if (tag instanceof OlTag) text.append(Integer.toString(((OlTag) tag).curIndex++) + ". "); else if (tag instanceof UlTag) text.append("\u2022 "); }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void startA(SpannableStringBuilder text, Attributes attributes) { String href = attributes.getValue("", "href"); int len = text.length(); text.setSpan(new Href(href), len, len, Spannable.SPAN_MARK_MARK); }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endSpan(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) { int len = text.length(); Object obj = getLast(text, Span.class); int where = text.getSpanStart(obj); text.removeSpan(obj);// w w w .j a v a 2 s .co m if (where != len) { Span s = (Span) obj; if (s.mStyle != null) { List<Object> styleSpans = parseStyleAttributes(s.mStyle); for (Object span : styleSpans) { text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (colors != null && s.mIsAibquote) { text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (colors != null && s.mIsAibspoiler) { if (openSpoilers) { text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (s.mIsUnderline) { text.setSpan(new UnderlineSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (s.mIsStrike) { text.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void startA(SpannableStringBuilder text, Attributes attributes, String baseUri) { String href = attributes.getValue("", "href"); if (href != null && !href.startsWith("http")) { String prefix;/*from ww w . j av a2 s . c o m*/ if (!href.startsWith("/")) { prefix = baseUri + "/"; } else { prefix = baseUri; } href = prefix + href; } int len = text.length(); text.setSpan(new Href(href), len, len, Spannable.SPAN_MARK_MARK); }