Java Code Examples for android.text.SpannableStringBuilder#valueOf()

The following examples show how to use android.text.SpannableStringBuilder#valueOf() . 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 File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder quota(CharSequence charSequence) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    QuoteSpan span = new MarkDownQuoteSpan(quota_color);
    spannableStringBuilder.setSpan(span, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.setSpan(new ForegroundColorSpan(quota_text_color), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 2
Source File: Utils.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
/**
 * 返回未读主题标题后面的 星号 ※
 *
 * @param title
 * @return
 */
public static CharSequence getNewTitleSpan(String title) {
    Spannable span = SpannableStringBuilder.valueOf(title + Api.NEW_SIGN);
    int start = title.length();
    int end = span.length();
    // ff0099cc
    span.setSpan(new ForegroundColorSpan(0xff0099cc), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(new AbsoluteSizeSpan(22, true), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return span;
}
 
Example 3
Source File: ConverterHtmlToSpanned.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
private void removeTrailingLineBreaks() {
    int end = mResult.length();
    while (end > 0 && mResult.charAt(end - 1) == '\n') {
        end--;
    }
    if (end < mResult.length()) {
        mResult = SpannableStringBuilder.valueOf(mResult.subSequence(0, end));
    }
}
 
Example 4
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
protected SpannableStringBuilder h(CharSequence charSequence, float s, int color) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    FontSpan fontSpan = new FontSpan(s, Typeface.BOLD, color);
    spannableStringBuilder.setSpan(fontSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 5
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder codeBlock(CharSequence... charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf("$");
    CodeBlockSpan codeBlockSpan = new CodeBlockSpan(getTextViewRealWidth(), code_background_color, code_text_color, charSequence);
    builder.setSpan(codeBlockSpan, 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 6
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder ol2(CharSequence charSequence, int quotaLevel, int bulletLevel, int index) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    QuotaBulletSpan bulletSpan = new QuotaBulletSpan(quotaLevel, bulletLevel, quota_color, quota_text_color, index);
    spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.setSpan(new ForegroundColorSpan(quota_text_color), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 7
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder ul2(CharSequence charSequence, int quotaLevel, int bulletLevel) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    QuotaBulletSpan bulletSpan = new QuotaBulletSpan(quotaLevel, bulletLevel, quota_color, quota_text_color, 0);
    spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.setSpan(new ForegroundColorSpan(quota_text_color), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 8
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder ol(CharSequence charSequence, int level, int index) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    BulletSpan bulletSpan = new MarkDownBulletSpan(level, h1_text_color, index);
    spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 9
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder ul(CharSequence charSequence, int level) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    BulletSpan bulletSpan = new MarkDownBulletSpan(level, h1_text_color, 0);
    spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 10
Source File: RuleTemplateView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void setRuleTemplate (@NonNull List<TemplateTextField> fields, OnTemplateFieldClickListener listener) {

        this.setText("");

        for (TemplateTextField thisField : fields) {

            // Capitalize proper nouns; lowercase all other editable fields.
            String displayText = thisField.getText();
            if (thisField.isEditable()) {
                displayText = thisField.isProperName() ? WordUtils.capitalizeFully(displayText) : displayText.toLowerCase();
            }

            SpannableStringBuilder span = SpannableStringBuilder.valueOf(displayText);

            if (thisField.isEditable()) {
                span.setSpan(new EditableSpan(thisField, listener), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            int textColor = thisField.isEditable() ? Color.BLACK : Color.GRAY;
            span.setSpan(new ForegroundColorSpan(textColor), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            this.append(span);
        }

        this.setHighlightColor(Color.TRANSPARENT);

        if (enabled) {
            this.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
 
Example 11
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder code(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    CodeSpan span = new CodeSpan(code_background_color, code_text_color);
    builder.setSpan(span, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 12
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder email(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    EmailSpan emailSpan = new EmailSpan(charSequence.toString(), link_color);
    builder.setSpan(emailSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 13
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder delete(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    StrikethroughSpan span = new StrikethroughSpan();
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(h1_text_color);
    builder.setSpan(colorSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(span, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 14
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder emItalic(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    FontSpan fontSpan = new FontSpan(scale_normal, Typeface.BOLD_ITALIC, h1_text_color);
    builder.setSpan(fontSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 15
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder italic(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    FontSpan fontSpan = new FontSpan(scale_normal, Typeface.ITALIC, h1_text_color);
    builder.setSpan(fontSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 16
Source File: StyleBuilderImpl.java    From Markdown with MIT License 5 votes vote down vote up
@Override
public SpannableStringBuilder em(CharSequence charSequence) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence);
    FontSpan fontSpan = new FontSpan(scale_normal, Typeface.BOLD, h1_text_color);
    builder.setSpan(fontSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}
 
Example 17
Source File: ConverterHtmlToSpanned.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void removeTrailingLineBreaks() {
    int end = mResult.length();
    while (end > 0 && mResult.charAt(end - 1) == '\n') {
        end--;
    }
    if (end < mResult.length()) {
        mResult = SpannableStringBuilder.valueOf(mResult.subSequence(0, end));
    }
}
 
Example 18
Source File: ConverterHtmlToSpanned.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void removeTrailingLineBreaks() {
    int end = mResult.length();
    while (end > 0 && mResult.charAt(end - 1) == '\n') {
        end--;
    }
    if (end < mResult.length()) {
        mResult = SpannableStringBuilder.valueOf(mResult.subSequence(0, end));
    }
}
 
Example 19
Source File: CommentParser.java    From Ouroboros with GNU General Public License v3.0 4 votes vote down vote up
public Spannable parseCom(String rawCom, int viewState, String currentBoard, String resto, FragmentManager fragmentManager, InfiniteDbHelper infiniteDbHelper){
    CharSequence processedText = new SpannableString("");
    Document doc = Jsoup.parse(rawCom);
    int parseLimit = 4;
    int limit = 0;

    if (doc.select("p").size() == 0) {
        return new SpannableString("LEGACY COMMENT SYSTEM!\n " + doc.body().text());
    } else {
        for (Element bodyLine : doc.body().children()){
            //This speeds up swiping on catalogview without risking an error
            if (viewState == CATALOG_VIEW && limit == parseLimit){
                break;
            }
            limit++;

            if (bodyLine.className().equals("body-line ltr quote")){
                processedText = TextUtils.concat(processedText, parseGreenText(new SpannableString(parseFormatting(bodyLine, currentBoard, resto, fragmentManager, infiniteDbHelper))));
                processedText = TextUtils.concat(processedText, "\n");
            } else if (bodyLine.className().equals("body-line ltr")){
                if (bodyLine.children().size() == 0){
                    //Normal Text
                    processedText = TextUtils.concat(processedText, parseNormalText(new SpannableString(bodyLine.text())));
                } else {
                    processedText = TextUtils.concat(processedText, parseFormatting(bodyLine, currentBoard, resto, fragmentManager, infiniteDbHelper));
                }
                processedText = TextUtils.concat(processedText, "\n");
            } else if (bodyLine.className().equals("body-line empty")){
                processedText = TextUtils.concat(processedText, "\n");
            } else if (bodyLine.tagName().equals("pre")){
                processedText = TextUtils.concat(processedText, parseCodeText(bodyLine));
            }

        }
    }

    //trim trailing newline.
    if (processedText.length() > 0 ){
        processedText = processedText.subSequence(0, processedText.length() - 1);
    }
    return SpannableStringBuilder.valueOf(processedText);
}