Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder append.

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

From source file:Main.java

public static void makeTextViewHyperlink(TextView tv) {
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    ssb.append(tv.getText());
    ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ssb, TextView.BufferType.SPANNABLE);
}

From source file:Main.java

public static void appendSpannable(SpannableStringBuilder builder, String text, Object[] styles) {
    final int from = builder.length();
    builder.append(text);
    final int to = builder.length();

    for (Object style : styles) {
        builder.setSpan(style, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/*from www.  ja  v a 2s.co  m*/
}

From source file:Main.java

/**
 * Returns a CharSequence that concatenates the specified array of CharSequence
 * objects and then applies a list of zero or more tags to the entire range.
 *
 * @param content an array of character sequences to apply a style to
 * @param tags the styled span objects to apply to the content
 *        such as android.text.style.StyleSpan
 *
 *//*from ww  w  . j  a  v a 2s. co  m*/
private static CharSequence apply(CharSequence[] content, Object... tags) {
    SpannableStringBuilder text = new SpannableStringBuilder();
    openTags(text, tags);
    for (CharSequence item : content) {
        text.append(item);
    }
    closeTags(text, tags);
    return text;
}

From source file:Main.java

/**
 * Invoked when the end of a paragraph is encountered. Adds a newline if there are one or more
 * non-space characters since the previous newline.
 *
 * @param builder The builder.//from  w w  w. java2 s.  c om
 */
/* package */static void endParagraph(SpannableStringBuilder builder) {
    int position = builder.length() - 1;
    while (position >= 0 && builder.charAt(position) == ' ') {
        position--;
    }
    if (position >= 0 && builder.charAt(position) != '\n') {
        builder.append('\n');
    }
}

From source file:org.mariotaku.twidere.util.HtmlSpanBuilder.java

private static void applyTag(SpannableStringBuilder sb, int start, int end, TagInfo info) {
    if (info.name.equalsIgnoreCase("br")) {
        sb.append('\n');
    } else {/*  w  w  w  .  j  a v a  2 s.c  o m*/
        final Object span = createSpan(info);
        if (span == null)
            return;
        sb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

From source file:codepath.watsiapp.utils.Util.java

/**
 * Sets a hyperlink style to the textview.
 *///from  w w w  .  j  a v  a2 s .c  om
public static void makeTextViewHyperlink(TextView tv) {
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    ssb.append(tv.getText());
    ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ssb, TextView.BufferType.SPANNABLE);
}

From source file:com.frostwire.android.gui.views.KeywordTagView.java

private static SpannableStringBuilder append(SpannableStringBuilder sb, CharSequence text, Object what,
        int flags) {
    int start = sb.length();
    sb.append(text);
    sb.setSpan(what, start, sb.length(), flags);
    return sb;//  w ww.  j  a  v  a  2  s .co m
}

From source file:cn.edu.wyu.documentviewer.RecentsCreateFragment.java

private static void appendDrawable(SpannableStringBuilder b, Drawable d) {
    final int length = b.length();
    b.append("\u232a");
    b.setSpan(new ImageSpan(d), length, b.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:Main.java

public static SpannableStringBuilder getSpannableStringFromList(List<HashMap<String, Object>> list) {
    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    int position = 0;
    for (int i = 0; i < list.size(); i++) {
        HashMap<String, Object> map = list.get(i);
        try {/*w w  w. j a  v  a 2s .  com*/
            String st = (String) map.get(RICHTEXT_STRING);
            ssb.append(st);
            int len = st.length();
            if (map.containsKey(RICHTEXT_COLOR)) {
                int color = ((Integer) map.get(RICHTEXT_COLOR)).intValue();
                ssb.setSpan(new ForegroundColorSpan(color), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_SIZE)) {
                int size = ((Integer) map.get(RICHTEXT_SIZE)).intValue();
                ssb.setSpan(new AbsoluteSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_RSIZE)) {
                float size = ((Float) map.get(RICHTEXT_RSIZE)).floatValue();
                ssb.setSpan(new RelativeSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_DELETE)) {
                ssb.setSpan(new StrikethroughSpan(), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            //              android.text.style.RelativeSizeSpan
            position = position + len;
        } catch (Exception e) {
            return null;
        }
    }
    return ssb;
}

From source file:Main.java

/**
 * Returns a CharSequence containing a bulleted and properly indented list.
 *
 * @param leadingMargin// www.  j a v a2 s  .co  m
 *            In pixels, the space between the left edge of the bullet and
 *            the left edge of the text.
 * @param lines
 *            An array of CharSequences. Each CharSequences will be a
 *            separate line/bullet-point.
 * @return
 */
public static CharSequence makeBulletList(int leadingMargin, CharSequence... lines) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (int i = 0; i < lines.length; i++) {
        CharSequence line = lines[i] + (i < lines.length - 1 ? "\n" : "");
        Spannable spannable = new SpannableString(line);
        spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        sb.append(spannable);
    }
    return sb;
}