List of usage examples for android.text Spannable removeSpan
public void removeSpan(Object what);
From source file:Main.java
private static void addStyleSpan(@Nonnull final Spannable text, final CharacterStyle style) { text.removeSpan(style); text.setSpan(style, 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }
From source file:Main.java
/** * Remove all spans./*from ww w.j a v a 2 s . c o m*/ */ 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. *//* ww w. j a v a 2 s . co 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: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); s.setSpan(span, start, end, 0);//from w ww. ja v a2 s .c om } textView.setText(s); }
From source file:de.schildbach.wallet.util.MonetarySpannable.java
public static void applyMarkup(final Spannable spannable, @Nullable final Object[] prefixSpans, @Nullable final Object[] significantSpans, @Nullable final Object[] insignificantSpans) { if (prefixSpans != null) for (final Object span : prefixSpans) spannable.removeSpan(span); if (significantSpans != null) for (final Object span : significantSpans) spannable.removeSpan(span);//from w ww . j av a2s . c o m if (insignificantSpans != null) for (final Object span : insignificantSpans) spannable.removeSpan(span); final Matcher m = Formats.PATTERN_MONETARY_SPANNABLE.matcher(spannable); if (m.find()) { int i = 0; if (m.group(Formats.PATTERN_GROUP_PREFIX) != null) { final int end = m.end(Formats.PATTERN_GROUP_PREFIX); if (prefixSpans != null) for (final Object span : prefixSpans) spannable.setSpan(span, i, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); i = end; } if (m.group(Formats.PATTERN_GROUP_SIGNIFICANT) != null) { final int end = m.end(Formats.PATTERN_GROUP_SIGNIFICANT); if (significantSpans != null) for (final Object span : significantSpans) spannable.setSpan(span, i, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); i = end; } if (m.group(Formats.PATTERN_GROUP_INSIGNIFICANT) != null) { final int end = m.end(Formats.PATTERN_GROUP_INSIGNIFICANT); if (insignificantSpans != null) for (final Object span : insignificantSpans) spannable.setSpan(span, i, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); i = end; } } }
From source file:cn.dreamtobe.emoji.ellipsize.helper.SpanEllipsizeEndHelper.java
private static void removeClickableSpan(Spannable content) { ClickableSpan[] clickSpans = content.getSpans(0, content.length(), ClickableSpan.class); for (int i = 0; i < clickSpans.length; i++) { content.removeSpan(clickSpans[i]); }//from ww w .ja va 2 s. c om }
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./* w ww . j a v a 2 s .co m*/ */ 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.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); span = new URLSpanNoUnderline(span.getURL()); s.setSpan(span, start, end, 0);/*from ww w .j a va 2 s . co m*/ } textView.setText(s); }
From source file:Main.java
public static boolean addEmoticons(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false;/*from w w w . j a v a 2 s. c om*/ break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; }
From source file:Main.java
public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false;/*from w w w . j av a 2 s . co m*/ break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; }