Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it would be more useful to build <code>Spannable</code>.</p> <pre><code>private static final Factory spannableFactory = Spannable.Factory .getInstance(); private static final Map&lt;Pattern, Integer&gt; emoticons = new HashMap&lt;Pattern, Integer&gt;(); static { addPattern(emoticons, ":)", R.drawable.emo_im_happy); addPattern(emoticons, ":-)", R.drawable.emo_im_happy); // ... } private static void addPattern(Map&lt;Pattern, Integer&gt; map, String smile, int resource) { map.put(Pattern.compile(Pattern.quote(smile)), resource); } public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry&lt;Pattern, Integer&gt; 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) &gt;= matcher.start() &amp;&amp; spannable.getSpanEnd(span) &lt;= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; } public static Spannable getSmiledText(Context context, CharSequence text) { Spannable spannable = spannableFactory.newSpannable(text); addSmiles(context, spannable); return spannable; } </code></pre> <p>Actualy this code based on sources from native <code>Html</code> class.</p> <p><strong>Edit: Updated version has dramatic speed improvement.</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload