Example usage for android.text SpannableStringBuilder length

List of usage examples for android.text SpannableStringBuilder length

Introduction

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

Prototype

public int length() 

Source Link

Document

Return the number of chars in the buffer.

Usage

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;//from   w ww.j  a v  a 2  s . c o m
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

/** 
 *  ?? (URLSpan)  ClickableURLSpan ? ?  ?
 * @param listener    ?? //from w ww.ja v a 2 s.c o  m
 */
private static void replaceUrls(SpannableStringBuilder builder, URLSpanClickListener listener,
        ThemeColors themeColors, String referer) {
    URLSpan[] spans = builder.getSpans(0, builder.length(), URLSpan.class);
    if (spans.length > 0) {
        for (URLSpan span : spans) {
            ClickableURLSpan.replaceURLSpan(builder, span, themeColors.urlLinkForeground)
                    .setOnClickListener(listener).setReferer(referer);
        }
    }
}

From source file:com.madgag.agit.RepoListFragment.java

private void applyToEntireString(SpannableStringBuilder string, CharacterStyle style) {
    string.setSpan(style, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyParagraphSpacing(TextView textView, float multiplier) {
    final SpannableStringBuilder builder = SpannableStringBuilder.valueOf(textView.getText());
    int prevLineBreak, currLineBreak = 0;
    for (int i = 0, j = builder.length(); i < j; i++) {
        if (builder.charAt(i) == '\n') {
            prevLineBreak = currLineBreak;
            currLineBreak = i;//from   w  ww. j  av  a  2  s.co  m
            if (currLineBreak > 0) {
                builder.setSpan(new ParagraphSpacingSpan(multiplier), prevLineBreak, currLineBreak,
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }
        }
    }
    textView.setText(builder);
}

From source file:com.robomorphine.fragment.AboutDialogFragment.java

private CharSequence linkify(String text, String link) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    URLSpan span = new URLSpan(link);

    builder.append(text);/*www.  j  a  v  a  2s  .co m*/
    builder.setSpan(span, 0, builder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return builder;
}

From source file:com.irccloud.android.fragment.TextListFragment.java

private void setText(String text) {
    SpannableStringBuilder sb = new SpannableStringBuilder(text);
    for (int i = 0; i < 100; i++)
        sb.setSpan(new TabStopSpan.Standard(i * 300), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(sb, TextView.BufferType.SPANNABLE);
}

From source file:com.android.tv.dvr.ui.DvrUiHelper.java

@NonNull
public static CharSequence getStyledTitleWithEpisodeNumber(Context context, String title, String seasonNumber,
        String episodeNumber, int episodeNumberStyleResId) {
    if (TextUtils.isEmpty(title)) {
        return "";
    }//w ww. j a va  2s  . c o m
    SpannableStringBuilder builder;
    if (TextUtils.isEmpty(seasonNumber) || seasonNumber.equals("0")) {
        builder = TextUtils.isEmpty(episodeNumber) ? new SpannableStringBuilder(title)
                : new SpannableStringBuilder(Html.fromHtml(context.getString(
                        R.string.program_title_with_episode_number_no_season, title, episodeNumber)));
    } else {
        builder = new SpannableStringBuilder(Html.fromHtml(context
                .getString(R.string.program_title_with_episode_number, title, seasonNumber, episodeNumber)));
    }
    Object[] spans = builder.getSpans(0, builder.length(), Object.class);
    if (spans.length > 0) {
        if (episodeNumberStyleResId != 0) {
            builder.setSpan(new TextAppearanceSpan(context, episodeNumberStyleResId),
                    builder.getSpanStart(spans[0]), builder.getSpanEnd(spans[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.removeSpan(spans[0]);
    }
    return new SpannableString(builder);
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void startFont(SpannableStringBuilder text, Attributes attributes) {
    String color = attributes.getValue("", "color");
    String face = attributes.getValue("", "face");
    String style = attributes.getValue("", "style");

    int len = text.length();
    text.setSpan(new Font(color, face, style), len, len, Spannable.SPAN_MARK_MARK);
}

From source file:com.none.tom.simplerssreader.view.ReadMoreTextView.java

@SuppressWarnings("SameParameterValue")
public void setText(final CharSequence text, final int maxEms) {
    if (!TextUtils.isEmpty(text) && text.length() > maxEms) {
        final SpannableStringBuilder ssb = new SpannableStringBuilder(text.subSequence(0, maxEms));

        ssb.append('\u2026');

        final int textLength = ssb.length();

        ssb.append('\n');
        ssb.append(getContext().getString(R.string.read_more));

        final int readMoreLength = ssb.length() - textLength;

        ssb.setSpan(new ReadMoreClickableSpan(), textLength, textLength + readMoreLength,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        super.setText(ssb);

        setMaxEms(maxEms + readMoreLength);
        setMovementMethod(LinkMovementMethod.getInstance());

        mText = text;//from   w ww  . j a  v a 2  s . c om
    } else {
        super.setText(text);
    }
}

From source file:com.abcs.haiwaigou.yyg.view.ReadMoreTextView.java

private CharSequence addClickableSpan(SpannableStringBuilder s, CharSequence trimText) {
    s.setSpan(viewMoreSpan, s.length() - trimText.length(), s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return s;//  w w  w .j  a  v a  2s .com
}