本文整理匯總了Java中android.text.Spannable.getSpanFlags方法的典型用法代碼示例。如果您正苦於以下問題:Java Spannable.getSpanFlags方法的具體用法?Java Spannable.getSpanFlags怎麽用?Java Spannable.getSpanFlags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.Spannable
的用法示例。
在下文中一共展示了Spannable.getSpanFlags方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: replaceQuoteSpans
import android.text.Spannable; //導入方法依賴的package包/類
/**
* Replaces the blue line produced by <blockquote>s with something more visible
*
* @param spannable parsed comment text #fromHtml
*/
private void replaceQuoteSpans(Spannable spannable) {
QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
final int start = spannable.getSpanStart(quoteSpan);
final int end = spannable.getSpanEnd(quoteSpan);
final int flags = spannable.getSpanFlags(quoteSpan);
spannable.removeSpan(quoteSpan);
//If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
final int barColor =
(SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
? ContextCompat.getColor(getContext(), R.color.md_blue_600)
: ContextCompat.getColor(getContext(), R.color.md_blue_400);
final int BAR_WIDTH = 4;
final int GAP = 5;
spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
barColor, //bar color
BAR_WIDTH, //bar width
GAP), //bar + text gap
start, end, flags);
}
}
示例2: setAndMergeSpans
import android.text.Spannable; //導入方法依賴的package包/類
public static void setAndMergeSpans(Spannable text, Object what, int start, int end, int flags) {
Object[] spans = text.getSpans(Math.max(start - 1, 0), Math.min(end + 1, 0), what.getClass());
for (Object span : spans) {
if (!areSpansEqual(span, what))
continue;
int sFlags = text.getSpanFlags(span);
if ((sFlags & Spanned.SPAN_COMPOSING) != 0)
continue;
int sStart = text.getSpanStart(span);
int sEnd = text.getSpanEnd(span);
if (sEnd < start || sStart > end)
continue;
text.removeSpan(span);
if (sStart < start)
start = sStart;
if (sEnd > end)
end = sEnd;
}
text.setSpan(what, start, end, flags);
}
示例3: convertSpannableToIRCString
import android.text.Spannable; //導入方法依賴的package包/類
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();
}
示例4: removeLocaleSpanFromRange
import android.text.Spannable; //導入方法依賴的package包/類
private static void removeLocaleSpanFromRange(final Object localeSpan,
final Spannable spannable, final int removeStart, final int removeEnd) {
if (!isLocaleSpanAvailable()) {
return;
}
final int spanStart = spannable.getSpanStart(localeSpan);
final int spanEnd = spannable.getSpanEnd(localeSpan);
if (spanStart > spanEnd) {
Log.e(TAG, "Invalid span: spanStart=" + spanStart + " spanEnd=" + spanEnd);
return;
}
if (spanEnd < removeStart) {
// spanStart < spanEnd < removeStart < removeEnd
return;
}
if (removeEnd < spanStart) {
// spanStart < removeEnd < spanStart < spanEnd
return;
}
final int spanFlags = spannable.getSpanFlags(localeSpan);
if (spanStart < removeStart) {
if (removeEnd < spanEnd) {
// spanStart < removeStart < removeEnd < spanEnd
final Locale locale = getLocaleFromLocaleSpan(localeSpan);
spannable.setSpan(localeSpan, spanStart, removeStart, spanFlags);
final Object attionalLocaleSpan = newLocaleSpan(locale);
spannable.setSpan(attionalLocaleSpan, removeEnd, spanEnd, spanFlags);
return;
}
// spanStart < removeStart < spanEnd <= removeEnd
spannable.setSpan(localeSpan, spanStart, removeStart, spanFlags);
return;
}
if (removeEnd < spanEnd) {
// removeStart <= spanStart < removeEnd < spanEnd
spannable.setSpan(localeSpan, removeEnd, spanEnd, spanFlags);
return;
}
// removeStart <= spanStart < spanEnd < removeEnd
spannable.removeSpan(localeSpan);
}