List of usage examples for android.text SpannableStringBuilder length
public int length()
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);/*from ww w.j a v a2s.c om*/ 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); } } 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 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 w w w . j a v a 2 s .co m*/ if (where != len) { text.setSpan(repl, 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);/*from w w w . j ava 2 s.c o m*/ if (where != len) { for (Object repl : replArray) { text.setSpan(repl, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void startSpan(SpannableStringBuilder text, Attributes attributes) { String email = attributes.getValue("data-user-email"); int len = text.length(); text.setSpan(new Href(email), len, len, Spannable.SPAN_MARK_MARK); }
From source file:piuk.blockchain.android.util.WalletUtils.java
public static Editable formatAddress(final String address, final int groupSize, final int lineSize) { final SpannableStringBuilder builder = new SpannableStringBuilder(); final int len = address.length(); for (int i = 0; i < len; i += groupSize) { final int end = i + groupSize; final String part = address.substring(i, end < len ? end : len); builder.append(part);// w w w.j av a 2s .c o m builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (end < len) { final boolean endOfLine = end % lineSize == 0; builder.append(endOfLine ? "\n" : Constants.THIN_SPACE); } } return builder; }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void startFont(SpannableStringBuilder text, Attributes attributes) { String color = attributes.getValue("", "color"); String face = attributes.getValue("", "face"); int len = text.length(); text.setSpan(new Font(color, face), len, len, Spannable.SPAN_MARK_MARK); }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void startImg(SpannableStringBuilder text, Attributes attributes, Html.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null;/*from w w w . java 2 s. c o m*/ if (img != null) { d = img.getDrawable(src); } if (d == null) { // don't draw anything return; } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
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 w w w. j a va2 s . 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:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void start(SpannableStringBuilder text, Object mark) { int len = text.length(); text.setSpan(mark, len, len, Spannable.SPAN_MARK_MARK); }
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);//from w w w . j a va2 s . c om // Back off not to change only the text, not the blank line. while (len > where && text.charAt(len - 1) == '\n') { len--; } 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); } }