本文整理汇总了Java中android.text.Spanned.getSpanFlags方法的典型用法代码示例。如果您正苦于以下问题:Java Spanned.getSpanFlags方法的具体用法?Java Spanned.getSpanFlags怎么用?Java Spanned.getSpanFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spanned
的用法示例。
在下文中一共展示了Spanned.getSpanFlags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyNonParagraphSuggestionSpansFrom
import android.text.Spanned; //导入方法依赖的package包/类
/**
* Copies the spans from the region <code>start...end</code> in
* <code>source</code> to the region
* <code>destoff...destoff+end-start</code> in <code>dest</code>.
* Spans in <code>source</code> that begin before <code>start</code>
* or end after <code>end</code> but overlap this range are trimmed
* as if they began at <code>start</code> or ended at <code>end</code>.
* Only SuggestionSpans that don't have the SPAN_PARAGRAPH span are copied.
*
* This code is almost entirely taken from {@link TextUtils#copySpansFrom}, except for the
* kind of span that is copied.
*
* @throws IndexOutOfBoundsException if any of the copied spans
* are out of range in <code>dest</code>.
*/
public static void copyNonParagraphSuggestionSpansFrom(Spanned source, int start, int end,
Spannable dest, int destoff) {
Object[] spans = source.getSpans(start, end, SuggestionSpan.class);
for (int i = 0; i < spans.length; i++) {
int fl = source.getSpanFlags(spans[i]);
// We don't care about the PARAGRAPH flag in LatinIME code. However, if this flag
// is set, Spannable#setSpan will throw an exception unless the span is on the edge
// of a word. But the spans have been split into two by the getText{Before,After}Cursor
// methods, so after concatenation they may end in the middle of a word.
// Since we don't use them, we can just remove them and avoid crashing.
fl &= ~Spanned.SPAN_PARAGRAPH;
int st = source.getSpanStart(spans[i]);
int en = source.getSpanEnd(spans[i]);
if (st < start)
st = start;
if (en > end)
en = end;
dest.setSpan(spans[i], st - start + destoff, en - start + destoff,
fl);
}
}
示例2: getTextStyles
import android.text.Spanned; //导入方法依赖的package包/类
private static String getTextStyles(Spanned text, int start, int end,
boolean forceNoVerticalMargin, boolean includeTextAlign) {
String margin = null;
String textAlign = null;
if (forceNoVerticalMargin) {
margin = "margin-top:0; margin-bottom:0;";
}
if (includeTextAlign) {
final AlignmentSpan[] alignmentSpans = text.getSpans(start, end, AlignmentSpan.class);
// Only use the last AlignmentSpan with flag SPAN_PARAGRAPH
for (int i = alignmentSpans.length - 1; i >= 0; i--) {
AlignmentSpan s = alignmentSpans[i];
if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH) {
final Layout.Alignment alignment = s.getAlignment();
if (alignment == Layout.Alignment.ALIGN_NORMAL) {
textAlign = "text-align:start;";
} else if (alignment == Layout.Alignment.ALIGN_CENTER) {
textAlign = "text-align:center;";
} else if (alignment == Layout.Alignment.ALIGN_OPPOSITE) {
textAlign = "text-align:end;";
}
break;
}
}
}
if (margin == null && textAlign == null) {
return "";
}
final StringBuilder style = new StringBuilder(" style=\"");
if (margin != null && textAlign != null) {
style.append(margin).append(" ").append(textAlign);
} else if (margin != null) {
style.append(margin);
} else if (textAlign != null) {
style.append(textAlign);
}
return style.append("\"").toString();
}
示例3: isNonIntermediateSelectionSpan
import android.text.Spanned; //导入方法依赖的package包/类
private boolean isNonIntermediateSelectionSpan(final Spanned text, final Object span) {
return (Selection.SELECTION_START == span || Selection.SELECTION_END == span)
&& (text.getSpanFlags(span) & Spanned.SPAN_INTERMEDIATE) == 0;
}
示例4: withinBlockquoteIndividual
import android.text.Spanned; //导入方法依赖的package包/类
private static void withinBlockquoteIndividual(Context context, StringBuilder out, Spanned text,
int start, int end) {
boolean isInList = false;
int next;
for (int i = start; i <= end; i = next) {
next = TextUtils.indexOf(text, '\n', i, end);
if (next < 0) {
next = end;
}
if (next == i) {
if (isInList) {
// Current paragraph is no longer a list item; close the previously opened list
isInList = false;
out.append("</ul>\n");
}
out.append("<br>\n");
} else {
boolean isListItem = false;
ParagraphStyle[] paragraphStyles = text.getSpans(i, next, ParagraphStyle.class);
for (ParagraphStyle paragraphStyle : paragraphStyles) {
final int spanFlags = text.getSpanFlags(paragraphStyle);
if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH
&& paragraphStyle instanceof BulletSpan) {
isListItem = true;
break;
}
}
if (isListItem && !isInList) {
// Current paragraph is the first item in a list
isInList = true;
out.append("<ul")
.append(getTextStyles(text, i, next, true, false))
.append(">\n");
}
if (isInList && !isListItem) {
// Current paragraph is no longer a list item; close the previously opened list
isInList = false;
out.append("</ul>\n");
}
String tagType = isListItem ? "li" : "p";
out.append("<").append(tagType)
.append(getTextDirection(text, i, next))
.append(getTextStyles(text, i, next, !isListItem, true))
.append(">");
withinParagraph(context, out, text, i, next);
out.append("</");
out.append(tagType);
out.append(">\n");
if (next == end && isInList) {
isInList = false;
out.append("</ul>\n");
}
}
next++;
}
}