android.text.style.UnderlineSpan Java Examples

The following examples show how to use android.text.style.UnderlineSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: MediaSDK   Author: JeffMony   File: Tx3gDecoder.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #2
Source Project: arcusandroid   Author: arcus-smart-home   File: ScleraLinkView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setText(CharSequence text, BufferType type) {
    if (!isInEditMode()) { // Normal use case.
        super.setText(text, type);
    } else {
        int length;
        if (text == null) {
            length = 0;
        } else {
            length = text.length();
        }

        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new UnderlineSpan(), 0, length, 0);
        super.setText(spannableString, BufferType.SPANNABLE);
    }
}
 
Example #3
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: UndoRedoSupportEditText.java    License: Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example #4
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: UndoRedoSupportEditText.java    License: Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example #5
Source Project: timecat   Author: triline3   File: UndoRedoHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform undo.
 */
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.mmStart;
    int end = start + (edit.mmAfter != null ? edit.mmAfter.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.mmBefore);
    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.mmBefore == null ? start
            : (start + edit.mmBefore.length()));
}
 
Example #6
Source Project: timecat   Author: triline3   File: UndoRedoHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform redo.
 */
public void redo() {
    EditItem edit = mEditHistory.getNext();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.mmStart;
    int end = start + (edit.mmBefore != null ? edit.mmBefore.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.mmAfter);
    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.mmAfter == null ? start
            : (start + edit.mmAfter.length()));
}
 
Example #7
Source Project: mua   Author: vejei   File: UndoRedoHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Perform undo.
 */
public void undo() {
    EditItem edit = mEditHistory.getPrevious();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.mmStart;
    int end = start + (edit.mmAfter != null ? edit.mmAfter.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.mmBefore);
    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.mmBefore == null ? start
            : (start + edit.mmBefore.length()));
}
 
Example #8
Source Project: mua   Author: vejei   File: UndoRedoHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Perform redo.
 */
public void redo() {
    EditItem edit = mEditHistory.getNext();
    if (edit == null) {
        return;
    }

    Editable text = mTextView.getEditableText();
    int start = edit.mmStart;
    int end = start + (edit.mmBefore != null ? edit.mmBefore.length() : 0);

    mIsUndoOrRedo = true;
    text.replace(start, end, edit.mmAfter);
    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.mmAfter == null ? start
            : (start + edit.mmAfter.length()));
}
 
Example #9
Source Project: TelePlus-Android   Author: TelePlusDev   File: Tx3gDecoder.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #10
Source Project: react-native-GPay   Author: hellochirag   File: ReactTextTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactRawTextShadowNode.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);
}
 
Example #11
Source Project: react-native-GPay   Author: hellochirag   File: ReactTextTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testTextDecorationLineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
      JavaOnlyMap.of(ReactRawTextShadowNode.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();
}
 
Example #12
Source Project: react-native-GPay   Author: hellochirag   File: ReactTextTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactRawTextShadowNode.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();
}
 
Example #13
Source Project: Markwon   Author: noties   File: UnderlineHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handle(
        @NonNull MarkwonVisitor visitor,
        @NonNull MarkwonHtmlRenderer renderer,
        @NonNull HtmlTag tag) {

    // as parser doesn't treat U tag as an inline one,
    // thus doesn't allow children, we must visit them first

    if (tag.isBlock()) {
        visitChildren(visitor, renderer, tag.getAsBlock());
    }

    SpannableBuilder.setSpans(
            visitor.builder(),
            new UnderlineSpan(),
            tag.start(),
            tag.end()
    );
}
 
Example #14
Source Project: easyweather   Author: byhieg   File: AboutFragment.java    License: MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    getActivity().setTheme(R.style.DayTheme);
    if (MyApplication.nightMode2()) {
        initNightView(R.layout.night_mode_overlay);
    }

    View view = inflater.inflate(R.layout.fragment_about, container, false);
    TextView tv = (TextView) view.findViewById(R.id.link);
    String textStr = "https://github.com/byhieg/easyweather";
    tv.setAutoLinkMask(Linkify.WEB_URLS);
    tv.setText(textStr);
    Spannable s = (Spannable) tv.getText();
    s.setSpan(new UnderlineSpan() {
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(ds.linkColor);
            ds.setUnderlineText(false);
        }
    }, 0, textStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return view;
}
 
Example #15
Source Project: Tok-Android   Author: InsightIM   File: OfflineBotDetailActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void initLink() {
    final String github = StringUtils.getTextFromResId(R.string.git_hub);
    String copyLink = StringUtils.getTextFromResId(R.string.copy_link);
    String content = StringUtils.getTextFromResId(R.string.more_about_offline_bot_6)
        + github
        + "  "
        + copyLink;

    SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(content);

    int gitHubStart = content.indexOf(github);
    int gitHubEnd = gitHubStart + github.length();
    sb.setSpan(new UnderlineSpan(), gitHubStart, gitHubEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    int copyStart = content.indexOf(copyLink);
    int copyEnd = copyStart + copyLink.length();
    ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
    sb.setSpan(redSpan, copyStart, copyEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    final ClickableSpan clickSpan = new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            SystemUtils.copyTxt2Clipboard(OfflineBotDetailActivity.this, github);
            ToastUtils.show(R.string.copy_success);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(getResources().getColor(R.color.auto_link_color));
            ds.setUnderlineText(false);
        }
    };
    sb.setSpan(clickSpan, copyStart, copyEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mGitHubTv.setMovementMethod(LinkMovementMethod.getInstance());
    mGitHubTv.setText(sb);
}
 
Example #16
Source Project: MediaSDK   Author: JeffMony   File: WebvttCueParser.java    License: Apache License 2.0 5 votes vote down vote up
private static void applySpansForTag(
    @Nullable String cueId,
    StartTag startTag,
    SpannableStringBuilder text,
    List<WebvttCssStyle> styles,
    List<StyleMatch> scratchStyleMatches) {
  int start = startTag.position;
  int end = text.length();
  switch(startTag.name) {
    case TAG_BOLD:
      text.setSpan(new StyleSpan(STYLE_BOLD), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_ITALIC:
      text.setSpan(new StyleSpan(STYLE_ITALIC), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_UNDERLINE:
      text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_CLASS:
    case TAG_LANG:
    case TAG_VOICE:
    case "": // Case of the "whole cue" virtual tag.
      break;
    default:
      return;
  }
  scratchStyleMatches.clear();
  getApplicableStyles(styles, cueId, startTag, scratchStyleMatches);
  int styleMatchesCount = scratchStyleMatches.size();
  for (int i = 0; i < styleMatchesCount; i++) {
    applyStyleToText(text, scratchStyleMatches.get(i).style, start, end);
  }
}
 
Example #17
Source Project: MediaSDK   Author: JeffMony   File: Cea708Decoder.java    License: Apache License 2.0 5 votes vote down vote up
public void setPenAttributes(int textTag, int offset, int penSize, boolean italicsToggle,
    boolean underlineToggle, int edgeType, int fontStyle) {
  // TODO: Add support for text tags.
  // TODO: Add support for other offsets.
  // TODO: Add support for other pen sizes.

  if (italicsStartPosition != C.POSITION_UNSET) {
    if (!italicsToggle) {
      captionStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      italicsStartPosition = C.POSITION_UNSET;
    }
  } else if (italicsToggle) {
    italicsStartPosition = captionStringBuilder.length();
  }

  if (underlineStartPosition != C.POSITION_UNSET) {
    if (!underlineToggle) {
      captionStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      underlineStartPosition = C.POSITION_UNSET;
    }
  } else if (underlineToggle) {
    underlineStartPosition = captionStringBuilder.length();
  }

  // TODO: Add support for edge types.
  // TODO: Add support for other font styles.
}
 
Example #18
Source Project: MediaSDK   Author: JeffMony   File: Cea708Decoder.java    License: Apache License 2.0 5 votes vote down vote up
public SpannableString buildSpannableString() {
  SpannableStringBuilder spannableStringBuilder =
      new SpannableStringBuilder(captionStringBuilder);
  int length = spannableStringBuilder.length();

  if (length > 0) {
    if (italicsStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (underlineStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new ForegroundColorSpan(foregroundColor),
          foregroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor),
          backgroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }

  return new SpannableString(spannableStringBuilder);
}
 
Example #19
Source Project: arcusandroid   Author: arcus-smart-home   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void removeUnderlines(@NonNull Spannable span) {
    for (URLSpan u: span.getSpans(0, span.length(), URLSpan.class)) {
        span.setSpan(new UnderlineSpan() {
            public void updateDrawState(TextPaint tp) {
                tp.setUnderlineText(false);
            }
        }, span.getSpanStart(u), span.getSpanEnd(u), 0);
    }
}
 
Example #20
Source Project: nono-android   Author: tianyuan168326   File: BaseRichEditText.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param type UnderlineSpan and StrikethroughSpan
 * */
public void applySelectionSpan(Class type){
    int selStart=getSelectionStart();
    int selEnd=getSelectionEnd();
    if(selEnd-selStart>0){
        Object[] ss = getEditableText().getSpans(selStart, selEnd, type);
        for (Object span:ss) {
            removeSpan(span,selStart,selEnd);
        }
        if (type == UnderlineSpan.class) {
            //toggleUnderLine();
            if(isUnderLine){
                setSpan(new UnderlineSpan(),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } else if (type == StrikethroughSpan.class) {
            //toggleStrikethrough();
            if(isStrikethrough){
                setSpan(new StrikethroughSpan(),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    //}else if(selEnd==selStart){
    //    if (type == UnderlineSpan.class) {
    //        toggleUnderLine();
    //    } else if (type == StrikethroughSpan.class) {
    //        toggleStrikethrough();
    //    }
    }
}
 
Example #21
Source Project: TelePlus-Android   Author: TelePlusDev   File: WebvttCueParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void applySpansForTag(String cueId, StartTag startTag, SpannableStringBuilder text,
    List<WebvttCssStyle> styles, List<StyleMatch> scratchStyleMatches) {
  int start = startTag.position;
  int end = text.length();
  switch(startTag.name) {
    case TAG_BOLD:
      text.setSpan(new StyleSpan(STYLE_BOLD), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_ITALIC:
      text.setSpan(new StyleSpan(STYLE_ITALIC), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_UNDERLINE:
      text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_CLASS:
    case TAG_LANG:
    case TAG_VOICE:
    case "": // Case of the "whole cue" virtual tag.
      break;
    default:
      return;
  }
  scratchStyleMatches.clear();
  getApplicableStyles(styles, cueId, startTag, scratchStyleMatches);
  int styleMatchesCount = scratchStyleMatches.size();
  for (int i = 0; i < styleMatchesCount; i++) {
    applyStyleToText(text, scratchStyleMatches.get(i).style, start, end);
  }
}
 
Example #22
Source Project: TelePlus-Android   Author: TelePlusDev   File: Cea708Decoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setPenAttributes(int textTag, int offset, int penSize, boolean italicsToggle,
    boolean underlineToggle, int edgeType, int fontStyle) {
  // TODO: Add support for text tags.
  // TODO: Add support for other offsets.
  // TODO: Add support for other pen sizes.

  if (italicsStartPosition != C.POSITION_UNSET) {
    if (!italicsToggle) {
      captionStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      italicsStartPosition = C.POSITION_UNSET;
    }
  } else if (italicsToggle) {
    italicsStartPosition = captionStringBuilder.length();
  }

  if (underlineStartPosition != C.POSITION_UNSET) {
    if (!underlineToggle) {
      captionStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      underlineStartPosition = C.POSITION_UNSET;
    }
  } else if (underlineToggle) {
    underlineStartPosition = captionStringBuilder.length();
  }

  // TODO: Add support for edge types.
  // TODO: Add support for other font styles.
}
 
Example #23
Source Project: TelePlus-Android   Author: TelePlusDev   File: Cea708Decoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
public SpannableString buildSpannableString() {
  SpannableStringBuilder spannableStringBuilder =
      new SpannableStringBuilder(captionStringBuilder);
  int length = spannableStringBuilder.length();

  if (length > 0) {
    if (italicsStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (underlineStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new ForegroundColorSpan(foregroundColor),
          foregroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor),
          backgroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }

  return new SpannableString(spannableStringBuilder);
}
 
Example #24
Source Project: DoraemonKit   Author: didi   File: SquigglySpan.java    License: Apache License 2.0 5 votes vote down vote up
public static void replaceUnderlineSpans(SpannableStringBuilder builder, Resources resources) {
  UnderlineSpan[] underlineSpans = builder.getSpans(0, builder.length(), UnderlineSpan.class);
  for (UnderlineSpan span : underlineSpans) {
    int start = builder.getSpanStart(span);
    int end = builder.getSpanEnd(span);
    builder.removeSpan(span);
    builder.setSpan(new SquigglySpan(resources), start, end, 0);
  }
}
 
Example #25
Source Project: secure-quick-reliable-login   Author: kalaspuffar   File: IdentitySelector.java    License: MIT License 5 votes vote down vote up
/**
 * Re-reads the identity database and updates the identity selector accordingly.
 * This is useful when an "external" change has occurred, for example an addition,
 * removal or renaming of an identity.
 * It is generally a good idea to call this method in the onResume() event of an activity
 * where an IdentitySelector is deployed.
 */
public void update() {
    long currentId = SqrlApplication.getCurrentId(mContext);
    String currentName = mDbHelper.getIdentityName(currentId);
    if (currentName == null) currentName = "";

    if (currentName.length() > ID_NAME_MAX_LEN) {
        currentName = currentName.substring(0, ID_NAME_MAX_LEN) + "...";
    }
    SpannableString ssCurrentName = new SpannableString(currentName);
    ssCurrentName.setSpan(new UnderlineSpan(), 0, ssCurrentName.length(), 0);
    mTxtSelectedIdentity.setText(ssCurrentName);
    mLastId = currentId;
    mIdentities = mDbHelper.getIdentities();

    if (mHideOnSingleIdentity && mIdentities.size() < 2) {
        mIdentitySelectorLayout.setVisibility(View.GONE);
        return;
    } else {
        mIdentitySelectorLayout.setVisibility(View.VISIBLE);
    }

    if (!mEnableIdentityChange || mIdentities.size() < 2) {
        if (mImgListIdentities != null) mImgListIdentities.setVisibility(View.GONE);
        mTxtSelectedIdentity.setOnClickListener(null);
    } else {
        if (mImgListIdentities != null) mImgListIdentities.setVisibility(View.VISIBLE);
        mTxtSelectedIdentity.setOnClickListener(mOnListIdentitiesClickListener);
    }

    if (mImgIdentityOptions != null)
        mImgIdentityOptions.setVisibility( mEnableIdentityOptions ? View.VISIBLE : View.GONE);
}
 
Example #26
Source Project: TelePlus-Android   Author: TelePlusDev   File: WebvttCueParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void applySpansForTag(String cueId, StartTag startTag, SpannableStringBuilder text,
    List<WebvttCssStyle> styles, List<StyleMatch> scratchStyleMatches) {
  int start = startTag.position;
  int end = text.length();
  switch(startTag.name) {
    case TAG_BOLD:
      text.setSpan(new StyleSpan(STYLE_BOLD), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_ITALIC:
      text.setSpan(new StyleSpan(STYLE_ITALIC), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_UNDERLINE:
      text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_CLASS:
    case TAG_LANG:
    case TAG_VOICE:
    case "": // Case of the "whole cue" virtual tag.
      break;
    default:
      return;
  }
  scratchStyleMatches.clear();
  getApplicableStyles(styles, cueId, startTag, scratchStyleMatches);
  int styleMatchesCount = scratchStyleMatches.size();
  for (int i = 0; i < styleMatchesCount; i++) {
    applyStyleToText(text, scratchStyleMatches.get(i).style, start, end);
  }
}
 
Example #27
Source Project: TelePlus-Android   Author: TelePlusDev   File: Cea708Decoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setPenAttributes(int textTag, int offset, int penSize, boolean italicsToggle,
    boolean underlineToggle, int edgeType, int fontStyle) {
  // TODO: Add support for text tags.
  // TODO: Add support for other offsets.
  // TODO: Add support for other pen sizes.

  if (italicsStartPosition != C.POSITION_UNSET) {
    if (!italicsToggle) {
      captionStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      italicsStartPosition = C.POSITION_UNSET;
    }
  } else if (italicsToggle) {
    italicsStartPosition = captionStringBuilder.length();
  }

  if (underlineStartPosition != C.POSITION_UNSET) {
    if (!underlineToggle) {
      captionStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      underlineStartPosition = C.POSITION_UNSET;
    }
  } else if (underlineToggle) {
    underlineStartPosition = captionStringBuilder.length();
  }

  // TODO: Add support for edge types.
  // TODO: Add support for other font styles.
}
 
Example #28
Source Project: TelePlus-Android   Author: TelePlusDev   File: Cea708Decoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
public SpannableString buildSpannableString() {
  SpannableStringBuilder spannableStringBuilder =
      new SpannableStringBuilder(captionStringBuilder);
  int length = spannableStringBuilder.length();

  if (length > 0) {
    if (italicsStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (underlineStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new ForegroundColorSpan(foregroundColor),
          foregroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor),
          backgroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }

  return new SpannableString(spannableStringBuilder);
}
 
Example #29
Source Project: RichEditor   Author: DrownCoder   File: MarkDownParser.java    License: Apache License 2.0 5 votes vote down vote up
private String spanToMarkDown(List<Object> mSpans, String source, int start, int end) {
    if (mSpans == null || mSpans.size() == 0) {
        return source.substring(start, end);
    }
    String str = source.substring(start, end);
    for (Object obj : mSpans) {
        if (obj instanceof StyleSpan) {
            StyleSpan objSpan = (StyleSpan) obj;
            switch (objSpan.getStyle()) {
                case Typeface.BOLD:
                    str = formater.formatBold(str);
                    break;
                case Typeface.ITALIC:
                    str = formater.formatItalics(str);
                    break;
            }
        } else if (obj instanceof UnderlineSpan) {
            //markdown是不支持下划线的!!!,后期考虑注释掉
            str = formater.formatUnderLine(str);
        } else if (obj instanceof StrikethroughSpan) {
            str = formater.formatCenterLine(str);
        } else if (obj instanceof URLSpanNoUnderline) {
            URLSpanNoUnderline url = (URLSpanNoUnderline) obj;
            str = formater.formatLink(str, url.getURL());
        }
    }
    return str;
}
 
Example #30
Source Project: spanner   Author: neworld   File: Spans.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see UnderlineSpan#UnderlineSpan()
 */
public static Span underline() {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new UnderlineSpan();
        }
    });
}