本文整理汇总了Java中android.text.style.UnderlineSpan类的典型用法代码示例。如果您正苦于以下问题:Java UnderlineSpan类的具体用法?Java UnderlineSpan怎么用?Java UnderlineSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnderlineSpan类属于android.text.style包,在下文中一共展示了UnderlineSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applySpansForTag
import android.text.style.UnderlineSpan; //导入依赖的package包/类
private static void applySpansForTag(StartTag startTag, SpannableStringBuilder spannedText) {
switch(startTag.name) {
case TAG_BOLD:
spannedText.setSpan(new StyleSpan(STYLE_BOLD), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
case TAG_ITALIC:
spannedText.setSpan(new StyleSpan(STYLE_ITALIC), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
case TAG_UNDERLINE:
spannedText.setSpan(new UnderlineSpan(), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
default:
break;
}
}
示例2: undo
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void undo() {
EditItem edit = mEditHistory.getPrevious();
if (edit == null) {
return;
}
Editable editable = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.after != null ? edit.after.length() : 0);
mIsUndoOrRedo = true;
editable.replace(start, end, edit.before);
mIsUndoOrRedo = false;
for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
editable.removeSpan(o);
}
Selection.setSelection(editable, edit.before == null ? start : (start + edit.before.length()));
}
示例3: redo
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void redo() {
EditItem edit = mEditHistory.getNext();
if (edit == null) {
return;
}
Editable text = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.before != null ? edit.before.length() : 0);
mIsUndoOrRedo = true;
text.replace(start, end, edit.after);
mIsUndoOrRedo = false;
// This will get rid of underlines inserted when editor tries to come
// up with a suggestion.
for (Object o : text.getSpans(0, text.length(), UnderlineSpan.class)) {
text.removeSpan(o);
}
Selection.setSelection(text, edit.after == null ? start
: (start + edit.after.length()));
}
示例4: undo
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void undo() {
EditItem edit = mEditHistory.getPrevious();
if (edit == null) {
return;
}
Editable editable = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.after != null ? edit.after.length() : 0);
mIsUndoOrRedo = true;
editable.replace(start, end, edit.before);
mIsUndoOrRedo = false;
for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
editable.removeSpan(o);
}
Selection.setSelection(editable,
edit.before == null ? start : (start + edit.before.length()));
}
示例5: attachFontFace
import android.text.style.UnderlineSpan; //导入依赖的package包/类
private static void attachFontFace(SpannableStringBuilder cueText, int fontFace,
int defaultFontFace, int start, int end, int spanPriority) {
if (fontFace != defaultFontFace) {
final int flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority;
boolean isBold = (fontFace & FONT_FACE_BOLD) != 0;
boolean isItalic = (fontFace & FONT_FACE_ITALIC) != 0;
if (isBold) {
if (isItalic) {
cueText.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flags);
} else {
cueText.setSpan(new StyleSpan(Typeface.BOLD), start, end, flags);
}
} else if (isItalic) {
cueText.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flags);
}
boolean isUnderlined = (fontFace & FONT_FACE_UNDERLINE) != 0;
if (isUnderlined) {
cueText.setSpan(new UnderlineSpan(), start, end, flags);
}
if (!isUnderlined && !isBold && !isItalic) {
cueText.setSpan(new StyleSpan(Typeface.NORMAL), start, end, flags);
}
}
}
示例6: testTextDecorationLineUnderlineApplied
import android.text.style.UnderlineSpan; //导入依赖的package包/类
@Test
public void testTextDecorationLineUnderlineApplied() {
UIManagerModule uiManager = getUIManagerModule();
ReactRootView rootView = createText(
uiManager,
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
TextView textView = (TextView) rootView.getChildAt(0);
Spanned text = (Spanned) textView.getText();
UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
StrikethroughSpan[] strikeThroughSpans =
text.getSpans(0, text.length(), StrikethroughSpan.class);
assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
assertThat(strikeThroughSpans).hasSize(0);
}
示例7: testTextDecorationLineLineThroughApplied
import android.text.style.UnderlineSpan; //导入依赖的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();
}
示例8: testTextDecorationLineUnderlineLineThroughApplied
import android.text.style.UnderlineSpan; //导入依赖的package包/类
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
UIManagerModule uiManager = getUIManagerModule();
ReactRootView rootView = createText(
uiManager,
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
UnderlineSpan underlineSpan =
getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
StrikethroughSpan strikeThroughSpan =
getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
示例9: setPenAttr
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void setPenAttr(CaptionPenAttr penAttr) {
mCharacterStyles.clear();
if (penAttr.italic) {
mCharacterStyles.add(new StyleSpan(Typeface.ITALIC));
}
if (penAttr.underline) {
mCharacterStyles.add(new UnderlineSpan());
}
switch (penAttr.penSize) {
case CaptionPenAttr.PEN_SIZE_SMALL:
mCharacterStyles.add(new RelativeSizeSpan(PROPORTION_PEN_SIZE_SMALL));
break;
case CaptionPenAttr.PEN_SIZE_LARGE:
mCharacterStyles.add(new RelativeSizeSpan(PROPORTION_PEN_SIZE_LARGE));
break;
}
switch (penAttr.penOffset) {
case CaptionPenAttr.OFFSET_SUBSCRIPT:
mCharacterStyles.add(new SubscriptSpan());
break;
case CaptionPenAttr.OFFSET_SUPERSCRIPT:
mCharacterStyles.add(new SuperscriptSpan());
break;
}
}
示例10: handleEndTag
import android.text.style.UnderlineSpan; //导入依赖的package包/类
private void handleEndTag(String tag) {
if (tag.equalsIgnoreCase("br")) {
handleBr(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("p")) {
handleP(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("b")) {
end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
} else if (tag.equalsIgnoreCase("i")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("font")) {
endFont(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("blockquote")) {
handleP(mSpannableStringBuilder);
end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
} else if (tag.equalsIgnoreCase("tt")) {
end(mSpannableStringBuilder, Monospace.class,
new TypefaceSpan("monospace"));
} else if (tag.equalsIgnoreCase("u")) {
end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
} else if (mTagHandler != null) {
mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
}
}
示例11: clearTitle
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void clearTitle() {
ssbTitle = (SpannableStringBuilder) noteTitleText.getText();
StyleSpan[] ss = ssbTitle.getSpans(noteTitleText.getSelectionStart(), noteTitleText.getSelectionEnd(), StyleSpan.class);
UnderlineSpan[] us = ssbTitle.getSpans(noteTitleText.getSelectionStart(), noteTitleText.getSelectionEnd(), UnderlineSpan.class);
BackgroundColorSpan[] bgSpan = ssbTitle.getSpans(noteTitleText.getSelectionStart(), noteTitleText.getSelectionEnd(), BackgroundColorSpan.class);
for (int i = 0; i < bgSpan.length; i++) {
ssbTitle.removeSpan(bgSpan[i]);
}
for (int i = 0; i < ss.length; i++) {
if (ss[i].getStyle() == Typeface.BOLD_ITALIC || ss[i].getStyle() == Typeface.BOLD || ss[i].getStyle() == Typeface.ITALIC) {
ssbTitle.removeSpan(ss[i]);
}
}
for (int i = 0; i < us.length; i++) {
ssbTitle.removeSpan(us[i]);
}
noteTitleText.setText(ssbTitle);
}
示例12: clearContent
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void clearContent() {
ssbContent = (SpannableStringBuilder) noteContentText.getText();
StyleSpan[] ss = ssbContent.getSpans(noteContentText.getSelectionStart(), noteContentText.getSelectionEnd(), StyleSpan.class);
UnderlineSpan[] us = ssbContent.getSpans(noteContentText.getSelectionStart(), noteContentText.getSelectionEnd(), UnderlineSpan.class);
BackgroundColorSpan[] bgSpan = ssbContent.getSpans(noteContentText.getSelectionStart(), noteContentText.getSelectionEnd(), BackgroundColorSpan.class);
for (int i = 0; i < ss.length; i++) {
if (ss[i].getStyle() == Typeface.BOLD_ITALIC || ss[i].getStyle() == Typeface.BOLD || ss[i].getStyle() == Typeface.ITALIC) {
ssbContent.removeSpan(ss[i]);
}
}
for (int i = 0; i < us.length; i++) {
ssbContent.removeSpan(us[i]);
}
for (int i = 0; i < bgSpan.length; i++) {
ssbContent.removeSpan(bgSpan[i]);
}
noteContentText.setText(ssbContent);
}
示例13: boldItalicText
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void boldItalicText() {
tags(false);
if (noteContentText.hasSelection()) {
ssbContent = (SpannableStringBuilder) noteContentText.getText();
ssbContent.setSpan(new UnderlineSpan(), noteContentText.getSelectionStart(), noteContentText.getSelectionEnd(), 0);
ssbContent.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), noteContentText.getSelectionStart(), noteContentText.getSelectionEnd(), 0);
} else if (noteTitleText.hasSelection()) {
ssbTitle = (SpannableStringBuilder) noteTitleText.getText();
ssbTitle.setSpan(new UnderlineSpan(), noteTitleText.getSelectionStart(), noteTitleText.getSelectionEnd(), 0);
ssbTitle.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), noteTitleText.getSelectionStart(), noteTitleText.getSelectionEnd(), 0);
}
}
示例14: testParseStrictValidClassesAndTrailingTokens
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void testParseStrictValidClassesAndTrailingTokens() throws Exception {
Spanned text = parseCueText("<v.first.loud Esme>"
+ "This <u.style1.style2 some stuff>is</u> text with <b.foo><i.bar>html</i></b> tags");
assertEquals("This is text with html tags", text.toString());
UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
assertEquals(1, underlineSpans.length);
assertEquals(2, styleSpans.length);
assertEquals(Typeface.ITALIC, styleSpans[0].getStyle());
assertEquals(Typeface.BOLD, styleSpans[1].getStyle());
assertEquals(5, text.getSpanStart(underlineSpans[0]));
assertEquals(7, text.getSpanEnd(underlineSpans[0]));
assertEquals(18, text.getSpanStart(styleSpans[0]));
assertEquals(18, text.getSpanStart(styleSpans[1]));
assertEquals(22, text.getSpanEnd(styleSpans[0]));
assertEquals(22, text.getSpanEnd(styleSpans[1]));
}
示例15: testParseWellFormedUnclosedEndAtCueEnd
import android.text.style.UnderlineSpan; //导入依赖的package包/类
public void testParseWellFormedUnclosedEndAtCueEnd() throws Exception {
Spanned text = parseCueText("An <u some trailing stuff>unclosed u tag with "
+ "<i>italic</i> inside");
assertEquals("An unclosed u tag with italic inside", text.toString());
UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
assertEquals(1, underlineSpans.length);
assertEquals(1, styleSpans.length);
assertEquals(Typeface.ITALIC, styleSpans[0].getStyle());
assertEquals(3, text.getSpanStart(underlineSpans[0]));
assertEquals(23, text.getSpanStart(styleSpans[0]));
assertEquals(29, text.getSpanEnd(styleSpans[0]));
assertEquals(36, text.getSpanEnd(underlineSpans[0]));
}