diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/util/MyLinkify.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java b/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java index 2817c55c7..8f2aa4e61 100644 --- a/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java +++ b/src/main/java/de/pixart/messenger/ui/util/MyLinkify.java @@ -40,6 +40,8 @@ import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.Patterns; import de.pixart.messenger.utils.XmppUri; +import static java.lang.Character.isAlphabetic; + public class MyLinkify { private static final Linkify.TransformFilter WEBURL_TRANSFORM_FILTER = (matcher, url) -> { @@ -81,7 +83,7 @@ public class MyLinkify { if (end < cs.length()) { // Reject strings that were probably matched only because they contain a dot followed by // by some known TLD (see also comment for WORD_BOUNDARY in Patterns.java) - if (Character.isAlphabetic(cs.charAt(end - 1)) && Character.isAlphabetic(cs.charAt(end))) { + if (isAlphabetic(cs.charAt(end - 1)) && isAlphabetic(cs.charAt(end))) { return false; } } @@ -95,6 +97,23 @@ public class MyLinkify { return uri.isJidValid(); }; + private static boolean isAlphabetic(final int code) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + return Character.isAlphabetic(code); + } + switch (Character.getType(code)) { + case Character.UPPERCASE_LETTER: + case Character.LOWERCASE_LETTER: + case Character.TITLECASE_LETTER: + case Character.MODIFIER_LETTER: + case Character.OTHER_LETTER: + case Character.LETTER_NUMBER: + return true; + default: + return false; + } + } + public static void addLinks(Editable body, boolean includeGeo) { Linkify.addLinks(body, Patterns.XMPP_PATTERN, "xmpp", XMPPURI_MATCH_FILTER, null); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); |