Java Code Examples for android.text.Spannable#SPAN_COMPOSING
The following examples show how to use
android.text.Spannable#SPAN_COMPOSING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageFormatSettingsActivity.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
private CharSequence prepareFormat(Spannable s) { SpannableString ret = new SpannableString(s.toString()); for (Object span : s.getSpans(0, s.length(), CharacterStyle.class)) { if ((ret.getSpanFlags(span) & Spannable.SPAN_COMPOSING) != 0) continue; ret.setSpan(span, s.getSpanStart(span), s.getSpanEnd(span), s.getSpanFlags(span) & Spanned.SPAN_PRIORITY); } return ret; }
Example 2
Source File: IRCColorUtils.java From revolution-irc with GNU General Public License v3.0 | 4 votes |
public static String convertSpannableToIRCString(Context context, Spannable spannable) { int n; int pFg = 99; int pBg = 99; boolean pBold = false; boolean pItalic = false; boolean pUnderline = false; StringBuilder ret = new StringBuilder(spannable.length()); for (int i = 0; i < spannable.length(); i = n) { n = spannable.nextSpanTransition(i, spannable.length(), Object.class); int fg = 99; int bg = 99; boolean bold = false; boolean italic = false; boolean underline = false; for (Object span : spannable.getSpans(i, n, Object.class)) { int flags = spannable.getSpanFlags(span); if ((flags & Spannable.SPAN_COMPOSING) != 0) continue; if (span instanceof ForegroundColorSpan) { fg = findNearestIRCColor(context, ((ForegroundColorSpan) span).getForegroundColor()); } else if (span instanceof BackgroundColorSpan) { bg = findNearestIRCColor(context, ((BackgroundColorSpan) span).getBackgroundColor()); } else if (span instanceof StyleSpan) { int style = ((StyleSpan) span).getStyle(); if (style == Typeface.BOLD || style == Typeface.BOLD_ITALIC) bold = true; if (style == Typeface.ITALIC || style == Typeface.BOLD_ITALIC) italic = true; } else if (span instanceof UnderlineSpan) { underline = true; } } if ((!bold && pBold) || (!italic && pItalic) || (!underline && pUnderline)) { ret.append((char) 0x0F); pFg = -1; pBg = -1; pBold = false; pItalic = false; pUnderline = false; } if (bold && !pBold) ret.append((char) 0x02); if (italic && !pItalic) ret.append((char) 0x1D); if (underline && !pUnderline) ret.append((char) 0x1F); if (fg != pFg || bg != pBg) { ret.append((char) 0x03); ret.append(fg); ret.append(','); ret.append(bg); } pFg = fg; pBg = bg; pBold = bold; pItalic = italic; pUnderline = underline; ret.append(spannable, i, n); } return ret.toString(); }