本文整理汇总了Java中android.text.Spanned.getSpans方法的典型用法代码示例。如果您正苦于以下问题:Java Spanned.getSpans方法的具体用法?Java Spanned.getSpans怎么用?Java Spanned.getSpans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spanned
的用法示例。
在下文中一共展示了Spanned.getSpans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpan
import android.text.Spanned; //导入方法依赖的package包/类
Object getSpan(Spanned spanned) {
final Object out;
final Object[] spans;
final int length = spanned != null ? spanned.length() : 0;
if (length == 0) {
spans = null;
} else {
spans = spanned.getSpans(0, length, Object.class);
}
if (spans != null
&& spans.length > 0) {
out = spans[0];
} else {
out = null;
}
return out;
}
示例2: testTextDecorationLineLineThroughApplied
import android.text.Spanned; //导入方法依赖的package包/类
@Test
public void testTextDecorationLineLineThroughApplied() {
UIManagerModule uiManager = getUIManagerModule();
ReactRootView rootView = createText(
uiManager,
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
TextView textView = (TextView) rootView.getChildAt(0);
Spanned text = (Spanned) textView.getText();
UnderlineSpan[] underlineSpans =
text.getSpans(0, text.length(), UnderlineSpan.class);
StrikethroughSpan strikeThroughSpan =
getSingleSpan(textView, StrikethroughSpan.class);
assertThat(underlineSpans).hasSize(0);
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
示例3: onStartTemporaryDetach
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public void onStartTemporaryDetach() {
super.onStartTemporaryDetach();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
for (TextInlineImageSpan span : spans) {
span.onStartTemporaryDetach();
}
}
}
示例4: removeJumpingBeansSpansFrom
import android.text.Spanned; //导入方法依赖的package包/类
private static CharSequence removeJumpingBeansSpansFrom(Spanned text) {
SpannableStringBuilder sbb = new SpannableStringBuilder(text.toString());
Object[] spans = text.getSpans(0, text.length(), Object.class);
for (Object span : spans) {
if (!(span instanceof JumpingBeansSpan)) {
sbb.setSpan(span, text.getSpanStart(span), text.getSpanEnd(span), text.getSpanFlags(span));
}
}
return sbb;
}
示例5: getSpanLength
import android.text.Spanned; //导入方法依赖的package包/类
private static int getSpanLength(Spanned sp, int start, int end, Context context) {
// TODO: there's a situation where the span can lose its annotations:
// - add an auto-complete contact
// - add another auto-complete contact
// - delete that second contact and keep deleting into the first
// - we lose the annotation and can no longer get the span.
// Need to fix this case because it breaks auto-complete contacts with commas in the name.
Annotation[] a = sp.getSpans(start, end, Annotation.class);
if (a.length > 0) {
return sp.getSpanEnd(a[0]);
}
return 0;
}
示例6: verifyDrawable
import android.text.Spanned; //导入方法依赖的package包/类
@Override
protected boolean verifyDrawable(Drawable drawable) {
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
for (TextInlineImageSpan span : spans) {
if (span.getDrawable() == drawable) {
return true;
}
}
}
return super.verifyDrawable(drawable);
}
示例7: onAttachedToWindow
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
for (TextInlineImageSpan span : spans) {
span.onAttachedToWindow();
}
}
}
示例8: invalidateDrawable
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public void invalidateDrawable(Drawable drawable) {
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
for (TextInlineImageSpan span : spans) {
if (span.getDrawable() == drawable) {
invalidate();
}
}
}
super.invalidateDrawable(drawable);
}
示例9: drawStrikeThrough
import android.text.Spanned; //导入方法依赖的package包/类
private void drawStrikeThrough(Canvas canvas) {
if (!(text instanceof Spanned)) {
return;
}
Spanned spanned = (Spanned) text;
StrikethroughSpan[] spans = spanned.getSpans(start, end, StrikethroughSpan.class);
if (spans == null || spans.length == 0) {
return;
}
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2); // TODO
paint.setARGB(0xFF, 0, 0, 0); // TODO
for (StrikethroughSpan span : spans) {
RectF spanRect = getRect(span);
if (spanRect == null) {
continue;
}
spanRect.offset(originX, originY);
if (vertical) {
float lineX = (spanRect.left + spanRect.right) / 2;
canvas.drawLine(lineX, spanRect.top, lineX, spanRect.bottom, paint);
} else {
float lineY = (spanRect.top + spanRect.bottom + originY) / 3;
canvas.drawLine(spanRect.left, lineY, spanRect.right, lineY, paint);
}
}
}
示例10: draw
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
SimpleChipDrawable chipDrawable = ((SimpleChipDrawable) getDrawable());
Paint myPaint = chipDrawable.getPaint();
if (text instanceof Spanned) {
Spanned spannable = (Spanned) text;
int style = 0;
int fgColor = -1;
int fgColorS = -1;
for (Object o : spannable.getSpans(start, end, Object.class)) {
int spanStart = spannable.getSpanStart(o);
if (spanStart > start)
continue;
if (o instanceof ForegroundColorSpan) {
if (spanStart > fgColorS) {
fgColor = ((ForegroundColorSpan) o).getForegroundColor();
fgColorS = spanStart;
}
} else if (o instanceof BackgroundColorSpan) {
int c = paint.getColor();
paint.setColor(((BackgroundColorSpan) o).getBackgroundColor());
canvas.drawRect(x, top, x + chipDrawable.getBounds().width(), bottom, paint);
paint.setColor(c);
} else if (o instanceof StyleSpan) {
style |= ((StyleSpan) o).getStyle();
}
}
if (myPaint != null) {
if (fgColor != -1)
myPaint.setColor(fgColor);
else
chipDrawable.setDefaultTextColor();
myPaint.setTypeface(Typeface.create(Typeface.DEFAULT, style));
}
}
super.draw(canvas, text, start, end, x, top, y, bottom, paint);
}
示例11: removeJumpingBeansSpansFrom
import android.text.Spanned; //导入方法依赖的package包/类
private static CharSequence removeJumpingBeansSpansFrom(Spanned text) {
SpannableStringBuilder sbb = new SpannableStringBuilder(text.toString());
Object[] spans = text.getSpans(0, text.length(), Object.class);
for (Object span : spans) {
if (!(span instanceof JumpingBeansSpan)) {
sbb.setSpan(span, text.getSpanStart(span),
text.getSpanEnd(span), text.getSpanFlags(span));
}
}
return sbb;
}
示例12: encodeTextAlignmentByDiv
import android.text.Spanned; //导入方法依赖的package包/类
private static void encodeTextAlignmentByDiv(Context context, StringBuilder out, Spanned text, int option) {
int len = text.length();
int next;
for (int i = 0; i < len; i = next) {
next = text.nextSpanTransition(i, len, ParagraphStyle.class);
ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class);
String elements = " ";
boolean needDiv = false;
for (ParagraphStyle style : styles) {
if (style instanceof AlignmentSpan) {
Layout.Alignment align =
((AlignmentSpan) style).getAlignment();
needDiv = true;
if (align == Layout.Alignment.ALIGN_CENTER) {
elements = "align=\"center\" " + elements;
} else if (align == Layout.Alignment.ALIGN_OPPOSITE) {
elements = "align=\"right\" " + elements;
} else {
elements = "align=\"left\" " + elements;
}
}
}
if (needDiv) {
out.append("<div ").append(elements).append(">");
}
withinDiv(context, out, text, i, next, option);
if (needDiv) {
out.append("</div>");
}
}
}
示例13: 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();
}
示例14: getSingleSpan
import android.text.Spanned; //导入方法依赖的package包/类
/**
* Make sure TextView has exactly one span and that span has given type.
*/
private static <TSPAN> TSPAN getSingleSpan(TextView textView, Class<TSPAN> spanClass) {
Spanned text = (Spanned) textView.getText();
TSPAN[] spans = text.getSpans(0, text.length(), spanClass);
assertThat(spans).hasSize(1);
return spans[0];
}
示例15: getStrokeSpans
import android.text.Spanned; //导入方法依赖的package包/类
public static StrokeSpan[] getStrokeSpans(Spanned spanned) {
return spanned.getSpans(0, spanned.length(), StrokeSpan.class);
}