Here are the examples of the java api class android.text.style.UnderlineSpan taken from open source projects.
1. KnifeText#underlineInvalid()
Project: Knife
File: KnifeText.java
File: KnifeText.java
protected void underlineInvalid(int start, int end) { if (start >= end) { return; } UnderlineSpan[] spans = getEditableText().getSpans(start, end, UnderlineSpan.class); List<KnifePart> list = new ArrayList<>(); for (UnderlineSpan span : spans) { list.add(new KnifePart(getEditableText().getSpanStart(span), getEditableText().getSpanEnd(span))); getEditableText().removeSpan(span); } for (KnifePart part : list) { if (part.isValid()) { if (part.getStart() < start) { underlineValid(part.getStart(), start); } if (part.getEnd() > end) { underlineValid(end, part.getEnd()); } } } }
2. ReactTextTest#testTextDecorationLineUnderlineLineThroughApplied()
Project: react-native
File: ReactTextTest.java
File: ReactTextTest.java
@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(); }
3. ReactTextTest#testTextDecorationLineLineThroughApplied()
Project: react-native
File: ReactTextTest.java
File: ReactTextTest.java
@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(); }
4. ReactTextTest#testTextDecorationLineUnderlineApplied()
Project: react-native
File: ReactTextTest.java
File: ReactTextTest.java
@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); }
5. WebvttCueParserTest#testParseMalformedNestedElements()
Project: ExoPlayer
File: WebvttCueParserTest.java
File: WebvttCueParserTest.java
public void testParseMalformedNestedElements() throws Exception { Spanned text = parseCueText("<b><u>An unclosed u tag with <i>italic</u> inside</i></b>"); 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(2, styleSpans.length); // all tags applied until matching start tag found assertEquals(0, text.getSpanStart(underlineSpans[0])); assertEquals(29, text.getSpanEnd(underlineSpans[0])); if (styleSpans[0].getStyle() == Typeface.BOLD) { assertEquals(0, text.getSpanStart(styleSpans[0])); assertEquals(23, text.getSpanStart(styleSpans[1])); assertEquals(29, text.getSpanEnd(styleSpans[1])); assertEquals(36, text.getSpanEnd(styleSpans[0])); } else { assertEquals(0, text.getSpanStart(styleSpans[1])); assertEquals(23, text.getSpanStart(styleSpans[0])); assertEquals(29, text.getSpanEnd(styleSpans[0])); assertEquals(36, text.getSpanEnd(styleSpans[1])); } }
6. WebvttCueParserTest#testParseWellFormedUnclosedEndAtParent()
Project: ExoPlayer
File: WebvttCueParserTest.java
File: WebvttCueParserTest.java
public void testParseWellFormedUnclosedEndAtParent() throws Exception { Spanned text = parseCueText("An unclosed u tag with <i><u>underline and italic</i> inside"); assertEquals("An unclosed u tag with underline and 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(23, text.getSpanStart(underlineSpans[0])); assertEquals(23, text.getSpanStart(styleSpans[0])); assertEquals(43, text.getSpanEnd(underlineSpans[0])); assertEquals(43, text.getSpanEnd(styleSpans[0])); assertEquals(Typeface.ITALIC, styleSpans[0].getStyle()); }
7. WebvttCueParserTest#testParseWellFormedUnclosedEndAtCueEnd()
Project: ExoPlayer
File: WebvttCueParserTest.java
File: WebvttCueParserTest.java
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])); }
8. WebvttCueParserTest#testParseStrictValidClassesAndTrailingTokens()
Project: ExoPlayer
File: WebvttCueParserTest.java
File: WebvttCueParserTest.java
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])); }
9. MakeUp#underline()
Project: RxAndroidBootstrap
File: MakeUp.java
File: MakeUp.java
public MakeUp underline(int start, int length) { final UnderlineSpan span = new UnderlineSpan(); sb.setSpan(span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return this; }
10. MakeUp#underline()
Project: MVPAndroidBootstrap
File: MakeUp.java
File: MakeUp.java
public MakeUp underline(int start, int length) { final UnderlineSpan span = new UnderlineSpan(); sb.setSpan(span, start, start + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return this; }
11. TtmlParserTest#assertUnderline()
Project: ExoPlayer
File: TtmlParserTest.java
File: TtmlParserTest.java
private void assertUnderline(Spannable spannable, boolean isUnderline) { UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class); assertEquals(isUnderline ? "must be underlined" : "must not be underlined", isUnderline ? 1 : 0, underlineSpans.length); }