diff options
author | lookshe <github@lookshe.org> | 2015-08-21 20:08:23 +0200 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2015-08-21 20:08:23 +0200 |
commit | 2dac6c8f3624d659e45fa332bd4fe163ca3a8309 (patch) | |
tree | 71a00e24c19d8178f0e2890c4d3191a62bf92393 /libs/emojicon | |
parent | 075448f764ba7178b3a02f3cd40941655afe6208 (diff) | |
parent | ef0f8d4507391dafba2fc9d2b691a117e84b40fc (diff) |
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to '')
-rw-r--r-- | libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java index 958ac760..bc1d670d 100644 --- a/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java +++ b/libs/emojicon/src/main/java/github/ankushsachdeva/emojicon/EmojiconHandler.java @@ -19,10 +19,16 @@ import github.ankushsachdeva.emojicon.R; import android.content.Context; import android.text.Spannable; +import android.util.Pair; +import android.util.Patterns; import android.util.SparseIntArray; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1440,13 +1446,20 @@ public final class EmojiconHandler { spannable.removeSpan(oldSpans[i]); } boolean hasChanges = false; + + Matcher webUrlMatcher = Patterns.WEB_URL.matcher(spannable); + Set<Pair<Integer, Integer>> webUrls = new HashSet<Pair<Integer, Integer>>(); + while (webUrlMatcher.find()) { + webUrls.add(Pair.create(webUrlMatcher.start(), webUrlMatcher.end())); + } + Map<Pattern, Integer> emoticons = ANDROID_EMOTICONS; for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (EmojiconImageSpan span : spannable.getSpans(matcher.start(), - matcher.end(), EmojiconImageSpan.class)) + matcher.end(), EmojiconImageSpan.class)) { if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); @@ -1454,6 +1467,17 @@ public final class EmojiconHandler { set = false; break; } + } + if (set) { + // check that found emojicon is not in an web url + for (Pair<Integer, Integer> webUrl : webUrls) { + if ((matcher.start() >= webUrl.first && matcher.start() <= webUrl.second) + || (matcher.end() >= webUrl.first && matcher.end() <= webUrl.second)) { + set = false; + break; + } + } + } if (set) { spannable.setSpan(new EmojiconImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), |