From 08529041a51ff8fc8f5e415581da0b59200e05ce Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Sat, 8 Dec 2018 19:50:13 +0000 Subject: [PATCH] Reduce `minSdkVersion` to 18, backfill missing methods This reduces the minimum SDK version to 18 (Android 4.3), which notably is the last supported version for the BlackBerry OS 10.3 Android compatibility layer. --- build.gradle | 2 +- .../conversations/ui/util/MyLinkify.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 87ed2ac3f..908fece82 100644 --- a/build.gradle +++ b/build.gradle @@ -73,7 +73,7 @@ android { compileSdkVersion 28 defaultConfig { - minSdkVersion 19 + minSdkVersion 18 targetSdkVersion 28 versionCode 307 versionName "2.3.9" diff --git a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java index d350e51f9..d944f2d08 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java @@ -29,6 +29,7 @@ package eu.siacs.conversations.ui.util; +import android.os.Build; import android.text.Editable; import android.text.util.Linkify; @@ -80,7 +81,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; } } @@ -93,6 +94,24 @@ 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);