mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-13 02:57:42 +00:00
change(android): Move isCustom to FileUtils.isCustomKeyboard()
This commit is contained in:
parent
cfc85771a5
commit
078af940c5
4 changed files with 43 additions and 15 deletions
|
|
@ -552,7 +552,7 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
}
|
||||
if (url != null) {
|
||||
// URL contains KMP to download in background.
|
||||
boolean isCustom = KMKeyboardDownloaderActivity.isCustom(url);
|
||||
boolean isCustom = FileUtils.isCustomKeyboard(url);
|
||||
|
||||
String filename = data.getQueryParameter("filename");
|
||||
if (filename == null) {
|
||||
|
|
|
|||
|
|
@ -41,10 +41,8 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
public static final String ARG_URL = "KMKeyboardActivity.url";
|
||||
public static final String ARG_FILENAME = "KMKeyboardActivity.filename";
|
||||
|
||||
public static final String kKeymanBaseURL = "https://keyman.com";
|
||||
public static final String kKeymanApiBaseURL = "https://api.keyman.com/cloud/4.0/languages";
|
||||
public static final String kKeymanApiModelURL = "https://api.keyman.com/model";
|
||||
public static final String kKeymanApiRemoteURL = "https://r.keymanweb.com/api/2.0/remote?url=";
|
||||
|
||||
private static final String TAG = "KMKbdDownloaderActivity"; // TAG needs to be less than 28 chars
|
||||
|
||||
|
|
@ -283,18 +281,6 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
((AppCompatActivity) context).finish();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isCustom(String u) {
|
||||
boolean ret = false;
|
||||
if (u != null && !u.contains(KMKeyboardDownloaderActivity.kKeymanApiBaseURL) &&
|
||||
!u.contains(KMKeyboardDownloaderActivity.kKeymanApiRemoteURL) && !u.contains(kKeymanBaseURL)) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void addKeyboardDownloadEventListener(KeyboardEventHandler.OnKeyboardDownloadEventListener listener) {
|
||||
if (kbDownloadEventListeners == null) {
|
||||
kbDownloadEventListeners = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Limitations:
|
||||
|
|
@ -227,6 +229,24 @@ public final class FileUtils {
|
|||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to parse a URL and determine if it's a custom keyboard
|
||||
* @param u String of the URL
|
||||
* @return boolean false if URL matches [*.]keyman.com/
|
||||
*/
|
||||
public static boolean isCustomKeyboard(String u) {
|
||||
boolean ret = true;
|
||||
if (u == null) {
|
||||
return ret;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("^http(s)?://(.+\\.)?keyman.com/.*");
|
||||
Matcher matcher = pattern.matcher(u);
|
||||
if (matcher.matches()) {
|
||||
ret = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to compare two version strings
|
||||
* @param v1 String
|
||||
|
|
|
|||
|
|
@ -31,6 +31,28 @@ public class FileUtilsTest {
|
|||
Assert.assertEquals("Could not download filename ", logs.get(3).msg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isCustomKeyboard() {
|
||||
// True because URL is null or empty (doesn't match *.keyman.com)
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard(null));
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard(""));
|
||||
|
||||
Assert.assertFalse(FileUtils.isCustomKeyboard("http://keyman.com/"));
|
||||
Assert.assertFalse(FileUtils.isCustomKeyboard("https://keyman.com/"));
|
||||
Assert.assertFalse(FileUtils.isCustomKeyboard("http://api.keyman.com/"));
|
||||
Assert.assertFalse(FileUtils.isCustomKeyboard("https://api.keyman.com/"));
|
||||
Assert.assertFalse(FileUtils.isCustomKeyboard("https://keyman.com/keyboard/khmer_angkor"));
|
||||
|
||||
// True because trailing slash is missing
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard("http://keyman.com"));
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard("https://keyman.com"));
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard("http://api.keyman.com"));
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard("https://api.keyman.com"));
|
||||
|
||||
// "custom" site
|
||||
Assert.assertTrue(FileUtils.isCustomKeyboard("https://amerikeyman.com/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_compareVersions() {
|
||||
Assert.assertEquals(FileUtils.VERSION_INVALID, FileUtils.compareVersions(null, "1.0"));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue