List of usage examples for android.text Spannable length
int length();
From source file:Main.java
/** * Remove all spans./* w w w.j a v a 2s . c om*/ */ public static void removeSpans(Spannable spannable) { Object spansToRemove[] = spannable.getSpans(0, spannable.length(), Object.class); for (Object span : spansToRemove) { if (span instanceof CharacterStyle) { spannable.removeSpan(span); } } }
From source file:Main.java
/** * "Closes" the specified tags on a Spannable by updating the spans to be * endpoint-exclusive so that future text appended to the end will not take * on the same styling. Do not call this method directly. */// w ww. j a v a2 s . c o m private static void closeTags(Spannable text, Object[] tags) { int len = text.length(); for (Object tag : tags) { if (len > 0) { text.setSpan(tag, 0, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.removeSpan(tag); } } }
From source file:Main.java
/** * Returns a CharSequence containing a bulleted and properly indented list. * * @param leadingMargin//from w ww . ja v a 2s .com * 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; }
From source file:Main.java
private static void addStyleSpan(@Nonnull final Spannable text, final CharacterStyle style) { text.removeSpan(style);// ww w .j ava2s . c om text.setSpan(style, 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }
From source file:Main.java
public static Spanned toSpanned(final Context context, final String toastString, @ColorRes final int toastColor) { final String string = "" + context.getResources().getColor(toastColor); final Spannable spannable = (Spannable) Html .fromHtml(colorize_a(colorize_em(toastString, string, true), string)); for (final URLSpan urlSpan : (URLSpan[]) spannable.getSpans(0, spannable.length(), (Class) URLSpan.class)) { spannable.setSpan(urlSpan, spannable.getSpanStart(urlSpan), spannable.getSpanEnd(urlSpan), 0); }//from w w w. j a va 2 s. c o m return spannable; }
From source file:rosmi.acagild.alarmclock.utilities.GeneralUtilities.java
public static void stripUnderlines(TextView textView) { Spannable s = (Spannable) textView.getText(); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span : spans) { int start = s.getSpanStart(span); int end = s.getSpanEnd(span); s.removeSpan(span);/* ww w . java2 s. co m*/ s.setSpan(span, start, end, 0); } textView.setText(s); }
From source file:Main.java
/** * Returns the bulleted list based on the given {@code lines}. * If one of lines starts with {@link BulletListUtil#BAD_FIRST_SYMBOLS}, then such symbol is * removed from there (sometimes bad lines are received from the Food2Work). * Also if line consists of the upper case words, then this line is used like a header and is * underlined./*from www .ja va2 s . c o m*/ * * @param leadingMargin In pixels, the space between the left edge of the bullet and the left * edge of the text * @param lines List of strings. Each string will be a separate item in the bulleted list * @return The bulleted list based on the given {@code lines} */ public static CharSequence makeBulletList(List<String> lines, int leadingMargin) { List<Spanned> spanned = new ArrayList<>(lines.size()); for (String line : lines) { if (!line.trim().isEmpty()) { Spanned spannedLine = Html.fromHtml(removeBadFirstCharacters(line.trim())); spanned.add(spannedLine); } } SpannableStringBuilder sb = new SpannableStringBuilder(); for (int i = 0; i < spanned.size(); i++) { CharSequence line = spanned.get(i) + (i < spanned.size() - 1 ? "\n" : ""); boolean underlineNeeded = isUpperCase(line); Spannable spannable = new SpannableString(line); if (underlineNeeded) { spannable.setSpan(new UnderlineSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } else { spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } sb.append(spannable); } return sb; }
From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java
/** * Recycles objects owned by the spannable. In particular, any * accessibility nodes that have been associated with {@code spannable} * are recycled and removed./*from w w w . j a va2s.c om*/ */ public static void recycleSpans(CharSequence chars) { if (!(chars instanceof Spannable)) { return; } Spannable spannable = (Spannable) chars; AccessibilityNodeInfoCompat[] nodes = spannable.getSpans(0, spannable.length(), AccessibilityNodeInfoCompat.class); for (AccessibilityNodeInfoCompat node : nodes) { node.recycle(); spannable.removeSpan(node); } }
From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java
/** * Marks the whole of {@code spannable} as containing the content * coming from {@code node}. A copy of {@code node} is stored. * * @see #recycleSpans/*from ww w . j a va 2 s.com*/ */ public static void setAccessibilityNode(Spannable spannable, AccessibilityNodeInfoCompat node) { spannable.setSpan(AccessibilityNodeInfoCompat.obtain(node), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:com.microsoft.mimickeralarm.utilities.GeneralUtilities.java
public static void stripUnderlines(TextView textView) { Spannable s = (Spannable) textView.getText(); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span : spans) { int start = s.getSpanStart(span); int end = s.getSpanEnd(span); s.removeSpan(span);/*w ww .j ava2 s . c o m*/ span = new URLSpanNoUnderline(span.getURL()); s.setSpan(span, start, end, 0); } textView.setText(s); }