List of usage examples for android.text SpannableStringBuilder length
public int length()
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 . j a v a 2 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:Main.java
public static void appendSpannable(SpannableStringBuilder builder, String text, Object[] styles) { final int from = builder.length(); builder.append(text);/* w ww. j a va 2 s. c o m*/ final int to = builder.length(); for (Object style : styles) { builder.setSpan(style, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:Main.java
public static void makeTextViewHyperlink(TextView tv) { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(tv.getText());/* w ww. j a v a 2 s . c o m*/ 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);/*from ww w . j a v a2s. c o m*/ sb.setSpan(what, start, sb.length(), flags); return sb; }
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:codepath.watsiapp.utils.Util.java
/** * Sets a hyperlink style to the textview. *///from w w w. j av a 2s. c o m 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.android.mail.browse.SendersView.java
private static void appendMessageInfo(SpannableStringBuilder sb, CharSequence text, Object span, boolean appendSplitToken, boolean convRead) { int startIndex = sb.length(); if (appendSplitToken) { sb.append(sSendersSplitToken);// w w w . j av a 2 s .c o m sb.setSpan(CharacterStyle.wrap(convRead ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan), startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } startIndex = sb.length(); sb.append(text); sb.setSpan(span, startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Show "donate" dialog.//w w w . j a v a 2 s . co m * * @param context * {@link Context} * @param title * title * @param btnDonate * button text for donate * @param btnNoads * button text for "i did a donation" * @param messages * messages for dialog body */ public static void showDonationDialog(final Activity context, final String title, final String btnDonate, final String btnNoads, final String[] messages) { final Intent marketIntent = Market.getInstallAppIntent(context, DONATOR_PACKAGE, null); String btnTitle = String.format(btnDonate, "Play Store"); SpannableStringBuilder sb = new SpannableStringBuilder(); for (String m : messages) { sb.append(m); sb.append("\n"); } sb.delete(sb.length() - 1, sb.length()); sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(title); b.setMessage(sb); b.setCancelable(true); b.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { context.startActivity(marketIntent); } catch (ActivityNotFoundException e) { Log.e(TAG, "activity not found", e); Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show(); } } }); b.setNeutralButton(btnNoads, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://code.google.com/p/ub0rapps/downloads/list?" + "can=3&q=Product%3DDonator"))); } catch (ActivityNotFoundException e) { Log.e(TAG, "activity not found", e); Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show(); } } }); b.show(); }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void handleP(SpannableStringBuilder text) { int len = text.length(); if (len >= 1 && text.charAt(len - 1) == '\n') { if (len >= 2 && text.charAt(len - 2) == '\n') { return; }//from ww w . j a v a 2 s . c o m text.append("\n"); return; } if (len != 0) { text.append("\n\n"); } }
From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java
private static void endSpan(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Href.class); int where = text.getSpanStart(obj); text.removeSpan(obj);/*from w ww . ja v a 2 s . c o m*/ if (where != len) { Href h = (Href) obj; if (h != null && h.mHref != null) { if (ZulipApp.get().getEmail().equals(h.mHref)) { text.setSpan(new ForegroundColorSpan(userMentionSelfColor), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new ProfileSpan(h.mHref, userMentionColor), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } }