mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-10 19:05:31 +00:00
Merge pull request #2928 from keymanapp/modify/android/sil-eurolatin
modify(android) Install default asset kmp's
This commit is contained in:
commit
a6717bce1e
15 changed files with 195 additions and 192 deletions
|
|
@ -12,6 +12,10 @@ android {
|
|||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
|
||||
// Don't compress kmp files so they can be copied via AssetManager
|
||||
aaptOptions {
|
||||
noCompress "kmp"
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
|
|
|||
BIN
android/KMAPro/kMAPro/src/main/assets/sil_euro_latin.kmp
Normal file
BIN
android/KMAPro/kMAPro/src/main/assets/sil_euro_latin.kmp
Normal file
Binary file not shown.
|
|
@ -24,6 +24,7 @@ import com.tavultesoft.kmea.KMManager.KeyboardType;
|
|||
import com.tavultesoft.kmea.KMTextView;
|
||||
import com.tavultesoft.kmea.KeyboardEventHandler.OnKeyboardDownloadEventListener;
|
||||
import com.tavultesoft.kmea.KeyboardEventHandler.OnKeyboardEventListener;
|
||||
import com.tavultesoft.kmea.packages.PackageProcessor;
|
||||
import com.tavultesoft.kmea.util.FileUtils;
|
||||
import com.tavultesoft.kmea.util.FileProviderUtils;
|
||||
import com.tavultesoft.kmea.util.DownloadIntentService;
|
||||
|
|
@ -31,6 +32,7 @@ import com.tavultesoft.kmea.util.DownloadIntentService;
|
|||
import android.Manifest;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
|
@ -104,6 +106,8 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
private int textSize = minTextSize;
|
||||
private static final String defaultKeyboardInstalled = "DefaultKeyboardInstalled";
|
||||
private static final String defaultDictionaryInstalled = "DefaultDictionaryInstalled";
|
||||
private static final String defaultKeyboardPath = "sil_euro_latin.kmp";
|
||||
private static final String defaultDictionaryPath = "nrc.en.mtnt.model.kmp";
|
||||
private static final String userTextKey = "UserText";
|
||||
private static final String userTextSizeKey = "UserTextSize";
|
||||
protected static final String didCheckUserDataKey = "DidCheckUserData";
|
||||
|
|
@ -161,6 +165,52 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
|
||||
KMManager.initialize(getApplicationContext(), KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
KMManager.executeResourceUpdate(this);
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
// Add default keyboard
|
||||
boolean installDefaultKeyboard = prefs.getBoolean(defaultKeyboardInstalled, false);
|
||||
if (!installDefaultKeyboard) {
|
||||
HashMap<String, String> kbInfo = new HashMap<String, String>();
|
||||
kbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_PackageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardID, KMManager.KMDefault_KeyboardID);
|
||||
kbInfo.put(KMManager.KMKey_LanguageID, KMManager.KMDefault_LanguageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardName, KMManager.KMDefault_KeyboardName);
|
||||
kbInfo.put(KMManager.KMKey_LanguageName, KMManager.KMDefault_LanguageName);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardVersion,
|
||||
KMManager.getLatestKeyboardFileVersion(context, KMManager.KMDefault_PackageID, KMManager.KMDefault_KeyboardID));
|
||||
kbInfo.put(KMManager.KMKey_Font, KMManager.KMDefault_KeyboardFont);
|
||||
File welcomeFile = new File(KMManager.getPackagesDir(), KMManager.KMDefault_PackageID + File.separator + FileUtils.WELCOME_HTM);
|
||||
kbInfo.put(KMManager.KMKey_CustomHelpLink, welcomeFile.getPath());
|
||||
KMManager.addKeyboard(this, kbInfo);
|
||||
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(defaultKeyboardInstalled, true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
// Add default dictionary
|
||||
boolean installDefaultDictionary = prefs.getBoolean(defaultDictionaryInstalled, false);
|
||||
if (!installDefaultDictionary) {
|
||||
HashMap<String, String> lexicalModelInfo = new HashMap<String, String>();
|
||||
lexicalModelInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_DictionaryPackageID);
|
||||
lexicalModelInfo.put(KMManager.KMKey_LanguageID, KMManager.KMDefault_LanguageID);
|
||||
lexicalModelInfo.put(KMManager.KMKey_LexicalModelID, KMManager.KMDefault_DictionaryModelID);
|
||||
lexicalModelInfo.put(KMManager.KMKey_LexicalModelName, KMManager.KMDefault_DictionaryModelName);
|
||||
lexicalModelInfo.put(KMManager.KMKey_LexicalModelVersion,
|
||||
KMManager.getLexicalModelPackageVersion(context, KMManager.KMDefault_DictionaryPackageID));
|
||||
/*
|
||||
// If welcome.htm exists, add custom help link
|
||||
welcomeFile = new File(KMManager.getLexicalModelsDir(), KMManager.KMDefault_DictionaryPackageID + File.separator + FileUtils.WELCOME_HTM);
|
||||
lexicalModelInfo.put(KMManager.KMKey_CustomHelpLink, welcomeFile.getPath());
|
||||
*/
|
||||
KMManager.addLexicalModel(context, lexicalModelInfo);
|
||||
KMManager.registerAssociatedLexicalModel(KMManager.KMDefault_LanguageID);
|
||||
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(defaultDictionaryInstalled, true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
toolbar = (Toolbar) findViewById(R.id.titlebar);
|
||||
|
|
@ -173,7 +223,6 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
getSupportActionBar().setBackgroundDrawable(getActionBarDrawable(this));
|
||||
|
||||
textView = (KMTextView) findViewById(R.id.kmTextView);
|
||||
SharedPreferences prefs = getSharedPreferences(getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
textView.setText(prefs.getString(userTextKey, ""));
|
||||
textSize = prefs.getInt(userTextSizeKey, minTextSize);
|
||||
textView.setTextSize((float) textSize);
|
||||
|
|
@ -258,36 +307,10 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
KMManager.onResume();
|
||||
KMManager.hideSystemKeyboard();
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
|
||||
// Check if default keyboard should be added
|
||||
if (!KMManager.keyboardExists(this, KMManager.KMDefault_UndefinedPackageID,
|
||||
KMManager.KMDefault_KeyboardID, KMManager.KMDefault_LanguageID)) {
|
||||
boolean installDefaultKeyboard = prefs.getBoolean(defaultKeyboardInstalled, false);
|
||||
if (!installDefaultKeyboard) {
|
||||
HashMap<String, String> kbInfo = new HashMap<String, String>();
|
||||
kbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_UndefinedPackageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardID, KMManager.KMDefault_KeyboardID);
|
||||
kbInfo.put(KMManager.KMKey_LanguageID, KMManager.KMDefault_LanguageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardName, KMManager.KMDefault_KeyboardName);
|
||||
kbInfo.put(KMManager.KMKey_LanguageName, KMManager.KMDefault_LanguageName);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardVersion, KMManager.getLatestKeyboardFileVersion(
|
||||
this, KMManager.KMDefault_UndefinedPackageID, KMManager.KMDefault_KeyboardID));
|
||||
kbInfo.put(KMManager.KMKey_Font, KMManager.KMDefault_KeyboardFont);
|
||||
KMManager.addKeyboard(this, kbInfo);
|
||||
}
|
||||
|
||||
editor.putBoolean(defaultKeyboardInstalled, true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
KMManager.addKeyboardEventListener(this);
|
||||
KMKeyboardDownloaderActivity.addKeyboardDownloadEventListener(this);
|
||||
PackageActivity.addKeyboardDownloadEventListener(this);
|
||||
|
||||
checkAndInstallDefaultDictionary();
|
||||
|
||||
Intent intent = getIntent();
|
||||
data = intent.getData();
|
||||
|
||||
|
|
@ -519,29 +542,6 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi
|
|||
resizeTextView(false);
|
||||
}
|
||||
|
||||
private void checkAndInstallDefaultDictionary() {
|
||||
SharedPreferences prefs = getSharedPreferences(getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
|
||||
// Check if default dictionary model package should be installed
|
||||
// This also depends on a current keyboard being loaded
|
||||
HashMap<String, String> curKbInfo = KMManager.getCurrentKeyboardInfo(this);
|
||||
if (!KMManager.lexicalModelExists(this, KMManager.KMDefault_DictionaryPackageID,
|
||||
KMManager.KMDefault_LanguageID, KMManager.KMDefault_DictionaryModelID) && curKbInfo != null) {
|
||||
boolean installDefaultDictionary = prefs.getBoolean(defaultDictionaryInstalled, false);
|
||||
if (!installDefaultDictionary) {
|
||||
File defaultDictionaryKMP = new File(
|
||||
new File(KMManager.getResourceRoot(), KMManager.KMDefault_DictionaryKMP).getAbsolutePath());
|
||||
Uri uri = FileProvider.getUriForFile(
|
||||
context, FileProviderUtils.getAuthority(context), defaultDictionaryKMP);
|
||||
useLocalKMP(context, uri, true);
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(defaultDictionaryInstalled, true);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the URI data to determine the URL for the .kmp keyboard package.
|
||||
*
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because one or more lines are too long
|
|
@ -149,7 +149,7 @@ final class KMKeyboard extends WebView {
|
|||
Toast.makeText(context, "Fatal Error with " + currentKeyboard +
|
||||
". Loading default keyboard", Toast.LENGTH_LONG).show();
|
||||
|
||||
setKeyboard(KMManager.KMDefault_UndefinedPackageID, KMManager.KMDefault_KeyboardID,
|
||||
setKeyboard(KMManager.KMDefault_PackageID, KMManager.KMDefault_KeyboardID,
|
||||
KMManager.KMDefault_LanguageID, KMManager.KMDefault_KeyboardName,
|
||||
KMManager.KMDefault_LanguageName, KMManager.KMDefault_KeyboardFont, null);
|
||||
}
|
||||
|
|
@ -372,6 +372,7 @@ final class KMKeyboard extends WebView {
|
|||
if (!KMManager.shouldAllowSetKeyboard() || keyboardVersion == null) {
|
||||
Toast.makeText(context, "Can't set " + packageID + "::" + keyboardID + " for " +
|
||||
languageID + " language. Loading default keyboard", Toast.LENGTH_LONG).show();
|
||||
packageID = KMManager.KMDefault_PackageID;
|
||||
keyboardID = KMManager.KMDefault_KeyboardID;
|
||||
languageID = KMManager.KMDefault_LanguageID;
|
||||
retVal = false;
|
||||
|
|
@ -473,6 +474,7 @@ final class KMKeyboard extends WebView {
|
|||
if (!KMManager.shouldAllowSetKeyboard() || keyboardVersion == null) {
|
||||
Toast.makeText(context, "Can't set " + packageID + "::" + keyboardID + " for " +
|
||||
languageID + " language. Loading default keyboard", Toast.LENGTH_LONG).show();
|
||||
packageID = KMManager.KMDefault_PackageID;
|
||||
keyboardID = KMManager.KMDefault_KeyboardID;
|
||||
languageID = KMManager.KMDefault_LanguageID;
|
||||
retVal = false;
|
||||
|
|
@ -506,7 +508,7 @@ final class KMKeyboard extends WebView {
|
|||
if (!KMManager.shouldAllowSetKeyboard() || keyboardVersion == null) {
|
||||
Toast.makeText(context, "Can't set " + packageID + "::" + keyboardID + " for " +
|
||||
languageID + " language. Loading default keyboard", Toast.LENGTH_LONG).show();
|
||||
packageID = KMManager.KMDefault_UndefinedPackageID;
|
||||
packageID = KMManager.KMDefault_PackageID;
|
||||
keyboardID = KMManager.KMDefault_KeyboardID;
|
||||
languageID = KMManager.KMDefault_LanguageID;
|
||||
keyboardName = KMManager.KMDefault_KeyboardName;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -63,6 +65,7 @@ import com.tavultesoft.kmea.cloud.CloudDownloadMgr;
|
|||
import com.tavultesoft.kmea.data.Dataset;
|
||||
import com.tavultesoft.kmea.logic.ResourcesUpdateTool;
|
||||
import com.tavultesoft.kmea.packages.JSONUtils;
|
||||
import com.tavultesoft.kmea.packages.LexicalModelPackageProcessor;
|
||||
import com.tavultesoft.kmea.packages.PackageProcessor;
|
||||
import com.tavultesoft.kmea.util.CharSequenceUtil;
|
||||
import com.tavultesoft.kmea.util.FileUtils;
|
||||
|
|
@ -178,17 +181,19 @@ public final class KMManager {
|
|||
// Keyman internal keys
|
||||
protected static final String KMKey_ShouldShowHelpBubble = "ShouldShowHelpBubble";
|
||||
|
||||
// Default Asset Paths
|
||||
// Default Legacy Asset Paths
|
||||
// Previous keyboards installed from the cloud went to /languages/ and /fonts/
|
||||
// Keyboards now get installed into /packages/packageID/
|
||||
// Keyboards that have an undefined packageID are installed into /cloud/
|
||||
// Keyboards that have an undefined packageID were installed into /cloud/
|
||||
public static final String KMDefault_LegacyAssetLanguages = "languages";
|
||||
public static final String KMDefault_LegacyAssetFonts = "fonts";
|
||||
public static final String KMDefault_UndefinedPackageID = "cloud";
|
||||
|
||||
// Keyboards now get installed into /packages/packageID/
|
||||
public static final String KMDefault_AssetPackages = "packages";
|
||||
public static final String KMDefault_LexicalModelPackages = "models";
|
||||
|
||||
// Default Keyboard Info
|
||||
public static final String KMDefault_PackageID = "sil_euro_latin";
|
||||
public static final String KMDefault_KeyboardID = "sil_euro_latin";
|
||||
public static final String KMDefault_LanguageID = "en";
|
||||
public static final String KMDefault_KeyboardName = "EuroLatin (SIL) Keyboard";
|
||||
|
|
@ -198,6 +203,7 @@ public final class KMManager {
|
|||
// Default Dictionary Info
|
||||
public static final String KMDefault_DictionaryPackageID = "nrc.en.mtnt";
|
||||
public static final String KMDefault_DictionaryModelID = "nrc.en.mtnt";
|
||||
public static final String KMDefault_DictionaryModelName = "English dictionary (MTNT)";
|
||||
public static final String KMDefault_DictionaryKMP = KMDefault_DictionaryPackageID + FileUtils.MODELPACKAGE;
|
||||
|
||||
// Keyman files
|
||||
|
|
@ -256,7 +262,9 @@ public final class KMManager {
|
|||
appContext = context.getApplicationContext();
|
||||
|
||||
if (!didCopyAssets || isTestMode()) {
|
||||
// Copy and install assets
|
||||
copyAssets(appContext);
|
||||
|
||||
migrateOldKeyboardFiles(appContext);
|
||||
updateOldKeyboardsList(appContext);
|
||||
didCopyAssets = true;
|
||||
|
|
@ -464,8 +472,7 @@ public final class KMManager {
|
|||
private static void copyAssets(Context context) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
try {
|
||||
// Copy main files
|
||||
copyAsset(context, KMDefault_DictionaryKMP, "", true);
|
||||
// Copy KMW files
|
||||
copyAsset(context, KMFilename_KeyboardHtml, "", true);
|
||||
copyAsset(context, KMFilename_JSEngine, "", true);
|
||||
if(KMManager.isDebugMode()) {
|
||||
|
|
@ -481,7 +488,10 @@ public final class KMManager {
|
|||
packagesDir.mkdir();
|
||||
}
|
||||
|
||||
// Copy default cloud keyboard
|
||||
/*
|
||||
// default cloud keyboard
|
||||
// Intend to deprecate cloud/keyboards in Keyman 15.0
|
||||
*/
|
||||
File cloudDir = new File(getCloudDir());
|
||||
if (!cloudDir.exists()) {
|
||||
cloudDir.mkdir();
|
||||
|
|
@ -496,6 +506,7 @@ public final class KMManager {
|
|||
if (!lexicalModelsDir.exists()) {
|
||||
lexicalModelsDir.mkdir();
|
||||
}
|
||||
|
||||
String[] modelNames = assetManager.list(KMDefault_LexicalModelPackages);
|
||||
for (String modelName : modelNames) {
|
||||
File lexicalModelDir = new File(lexicalModelsDir, modelName);
|
||||
|
|
@ -507,6 +518,31 @@ public final class KMManager {
|
|||
copyAsset(context, modelFile, KMDefault_LexicalModelPackages + File.separator + modelName, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy and install all KMP files (Issue for FV app?)
|
||||
File resourceRoot = new File(getResourceRoot());
|
||||
PackageProcessor kmpProcessor = new PackageProcessor(resourceRoot);
|
||||
LexicalModelPackageProcessor lmkmpProcessor = new LexicalModelPackageProcessor(resourceRoot);
|
||||
String assetFiles[] = assetManager.list("");
|
||||
for (String assetFile : assetFiles) {
|
||||
File kmpFile, tempPackagePath;
|
||||
boolean installAsset = FileUtils.hasKeymanPackageExtension(assetFile) ||
|
||||
FileUtils.hasLexicalModelPackageExtension(assetFile);
|
||||
|
||||
if (installAsset) {
|
||||
copyAsset(context, assetFile, "", true);
|
||||
kmpFile = new File(getResourceRoot(), assetFile);
|
||||
tempPackagePath = kmpProcessor.unzipKMP(kmpFile);
|
||||
|
||||
if (FileUtils.hasLexicalModelPackageExtension(assetFile)) {
|
||||
lmkmpProcessor.processKMP(kmpFile, tempPackagePath, PackageProcessor.PP_LEXICAL_MODELS_KEY);
|
||||
} else {
|
||||
// Not using the list of entries returned from processKMP()
|
||||
// because the main App will add the keyboard/lexical model info
|
||||
kmpProcessor.processKMP(kmpFile, tempPackagePath, PackageProcessor.PP_KEYBOARDS_KEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to copy assets. Error: " + e);
|
||||
}
|
||||
|
|
@ -555,6 +591,9 @@ public final class KMManager {
|
|||
*
|
||||
* Fonts used in legacy keyboards are also migrated from /fonts/ to /cloud/
|
||||
*
|
||||
* At some point, we might migrate /cloud/ keyboards into packages
|
||||
* 5) For now, delete cloud/sil_euro_latin*.js
|
||||
*
|
||||
* Assumption: No legacy keyboards exist in /packages/*.js
|
||||
* @param context
|
||||
*/
|
||||
|
|
@ -563,26 +602,28 @@ public final class KMManager {
|
|||
String legacyFontsPath = getResourceRoot() + KMDefault_LegacyAssetFonts + File.separator;
|
||||
File legacyLanguagesDir = new File(legacyLanguagesPath);
|
||||
File legacyFontsDir = new File(legacyFontsPath);
|
||||
if (!legacyLanguagesDir.exists() && !legacyFontsDir.exists()) {
|
||||
File migratedDir = new File(getCloudDir());
|
||||
if (!legacyLanguagesDir.exists() && !legacyFontsDir.exists() && !migratedDir.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
File migratedDir = new File(getCloudDir());
|
||||
if (!migratedDir.exists()) {
|
||||
migratedDir.mkdir();
|
||||
}
|
||||
|
||||
FileFilter keyboardFilter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.isFile() && FileUtils.hasJavaScriptExtension(pathname.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
if (legacyLanguagesDir.exists()) {
|
||||
FileFilter keyboardFilter = new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.isFile() && FileUtils.hasJavaScriptExtension(pathname.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
File[] files = legacyLanguagesDir.listFiles(keyboardFilter);
|
||||
for (File file : files) {
|
||||
|
|
@ -630,6 +671,18 @@ public final class KMManager {
|
|||
FileUtils.copyDirectory(legacyFontsDir, migratedDir);
|
||||
FileUtils.deleteDirectory(legacyFontsDir);
|
||||
}
|
||||
|
||||
// TODO: Investigate how to migrate cloud/ keyboards to packages/ ?
|
||||
// Would need to query what associated files get moved
|
||||
// For now, can delete sil_euro_latin because it will be in packages/
|
||||
File[] files = migratedDir.listFiles(keyboardFilter);
|
||||
for (File file: files) {
|
||||
String filename = file.getName();
|
||||
if (filename.startsWith(KMDefault_KeyboardID)) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to migrate assets. Error: " + e);
|
||||
}
|
||||
|
|
@ -641,16 +694,18 @@ public final class KMManager {
|
|||
boolean shouldUpdateList = false;
|
||||
boolean shouldClearCache = false;
|
||||
HashMap<String, String> kbInfo = kbList.get(0);
|
||||
String pkgID = kbInfo.get(KMKey_PackageID);
|
||||
String kbID = kbInfo.get(KMKey_KeyboardID);
|
||||
if (kbID.equals("us") || (kbID.equals("european2"))) {
|
||||
if ( kbID.equals("us") || kbID.equals("european2") ||
|
||||
(pkgID.equals(KMDefault_UndefinedPackageID) && kbID.equals(KMDefault_KeyboardID)) ) {
|
||||
HashMap<String, String> newKbInfo = new HashMap<String, String>();
|
||||
newKbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_UndefinedPackageID);
|
||||
newKbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_PackageID);
|
||||
newKbInfo.put(KMManager.KMKey_KeyboardID, KMManager.KMDefault_KeyboardID);
|
||||
newKbInfo.put(KMManager.KMKey_LanguageID, KMManager.KMDefault_LanguageID);
|
||||
newKbInfo.put(KMManager.KMKey_KeyboardName, KMManager.KMDefault_KeyboardName);
|
||||
newKbInfo.put(KMManager.KMKey_LanguageName, KMManager.KMDefault_LanguageName);
|
||||
newKbInfo.put(KMManager.KMKey_KeyboardVersion,
|
||||
getLatestKeyboardFileVersion(context, KMManager.KMDefault_UndefinedPackageID,
|
||||
getLatestKeyboardFileVersion(context, KMManager.KMDefault_PackageID,
|
||||
KMManager.KMDefault_KeyboardID));
|
||||
newKbInfo.put(KMManager.KMKey_CustomKeyboard, "N");
|
||||
newKbInfo.put(KMManager.KMKey_Font, KMManager.KMDefault_KeyboardFont);
|
||||
|
|
@ -665,7 +720,7 @@ public final class KMManager {
|
|||
kbInfo = kbList.get(i);
|
||||
|
||||
kbID = kbInfo.get(KMKey_KeyboardID);
|
||||
String pkgID = kbInfo.get(KMKey_PackageID);
|
||||
pkgID = kbInfo.get(KMKey_PackageID);
|
||||
if (pkgID == null || pkgID.isEmpty()) {
|
||||
pkgID = KMDefault_UndefinedPackageID;
|
||||
kbInfo.put(KMManager.KMKey_PackageID, pkgID);
|
||||
|
|
@ -911,7 +966,7 @@ public final class KMManager {
|
|||
String keyboardID = keyboardInfo.get(KMManager.KMKey_KeyboardID);
|
||||
|
||||
// Log Sentry analytic event, ignoring default keyboard
|
||||
if (Sentry.isEnabled() && !(packageID.equalsIgnoreCase(KMManager.KMDefault_UndefinedPackageID) &&
|
||||
if (Sentry.isEnabled() && !(packageID.equalsIgnoreCase(KMManager.KMDefault_PackageID) &&
|
||||
keyboardID.equalsIgnoreCase(KMManager.KMDefault_KeyboardID))) {
|
||||
Breadcrumb breadcrumb = new Breadcrumb();
|
||||
breadcrumb.setMessage("KMManager.addKeyboard");
|
||||
|
|
@ -1208,6 +1263,29 @@ public final class KMManager {
|
|||
return kbFileVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the latest version number for an installed lexical model by parsing kmp.json.
|
||||
* @param context
|
||||
* @param packageID
|
||||
* @return String.
|
||||
*/
|
||||
public static String getLexicalModelPackageVersion(Context context, final String packageID) {
|
||||
String path = getLexicalModelsDir() + packageID + File.separator + PackageProcessor.PP_DEFAULT_METADATA;
|
||||
|
||||
try {
|
||||
File kmpJSONFile = new File(path);
|
||||
if (!kmpJSONFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONObject kmpObject = jsonParser.getJSONObjectFromFile(kmpJSONFile);
|
||||
|
||||
return LexicalModelPackageProcessor.getPackageVersion(kmpObject);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addKeyboardDownloadEventListener(OnKeyboardDownloadEventListener listener) {
|
||||
KMKeyboardDownloaderActivity.addKeyboardDownloadEventListener(listener);
|
||||
}
|
||||
|
|
@ -1256,7 +1334,7 @@ public final class KMManager {
|
|||
public static void setShouldAllowSetKeyboard(boolean value) {
|
||||
shouldAllowSetKeyboard = value;
|
||||
if (shouldAllowSetKeyboard == false) {
|
||||
setKeyboard(KMDefault_UndefinedPackageID, KMDefault_KeyboardID,
|
||||
setKeyboard(KMDefault_PackageID, KMDefault_KeyboardID,
|
||||
KMDefault_LanguageID, KMDefault_KeyboardName, KMDefault_LanguageName, KMDefault_KeyboardFont, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -1529,7 +1607,7 @@ public final class KMManager {
|
|||
String kOskFont = keyboardInfo.get(KMManager.KMKey_OskFont);
|
||||
InAppKeyboard.setKeyboard(pkgId, kbId, langId, kbName, langName, kFont, kOskFont);
|
||||
} else {
|
||||
InAppKeyboard.setKeyboard(KMDefault_UndefinedPackageID, KMDefault_KeyboardID,
|
||||
InAppKeyboard.setKeyboard(KMDefault_PackageID, KMDefault_KeyboardID,
|
||||
KMDefault_LanguageID, KMDefault_KeyboardName, KMDefault_LanguageName, KMDefault_KeyboardFont, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,13 +110,13 @@ public final class KeyboardPickerActivity extends AppCompatActivity {
|
|||
if (keyboardsList == null) {
|
||||
keyboardsList = new ArrayList<HashMap<String, String>>();
|
||||
HashMap<String, String> kbInfo = new HashMap<String, String>();
|
||||
kbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_UndefinedPackageID);
|
||||
kbInfo.put(KMManager.KMKey_PackageID, KMManager.KMDefault_PackageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardID, KMManager.KMDefault_KeyboardID);
|
||||
kbInfo.put(KMManager.KMKey_LanguageID, KMManager.KMDefault_LanguageID);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardName, KMManager.KMDefault_KeyboardName);
|
||||
kbInfo.put(KMManager.KMKey_LanguageName, KMManager.KMDefault_LanguageName);
|
||||
kbInfo.put(KMManager.KMKey_KeyboardVersion, KMManager.getLatestKeyboardFileVersion(
|
||||
context, KMManager.KMDefault_UndefinedPackageID, KMManager.KMDefault_KeyboardID));
|
||||
context, KMManager.KMDefault_PackageID, KMManager.KMDefault_KeyboardID));
|
||||
kbInfo.put(KMManager.KMKey_CustomKeyboard, "N");
|
||||
kbInfo.put(KMManager.KMKey_Font, KMManager.KMDefault_KeyboardFont);
|
||||
keyboardsList.add(kbInfo);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
infoList.add(hashMap);
|
||||
|
||||
// Display uninstall keyboard
|
||||
if (!packageID.equalsIgnoreCase(KMManager.KMDefault_UndefinedPackageID) ||
|
||||
if (!packageID.equalsIgnoreCase(KMManager.KMDefault_PackageID) ||
|
||||
!kbID.equalsIgnoreCase(KMManager.KMDefault_KeyboardID)) {
|
||||
hashMap = new HashMap<>();
|
||||
hashMap.put(titleKey, getString(R.string.uninstall_keyboard));
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ public final class LanguageSettingsActivity extends AppCompatActivity {
|
|||
|
||||
lgCode = bundle.getString(KMManager.KMKey_LanguageID);
|
||||
lgName = bundle.getString(KMManager.KMKey_LanguageName);
|
||||
customHelpLink = bundle.getString(KMManager.KMKey_CustomHelpLink);
|
||||
customHelpLink = bundle.getString(KMManager.KMKey_CustomHelpLink, "");
|
||||
|
||||
// Necessary to properly insert a language name into the title. (Has a %s slot for it.)
|
||||
String title = String.format(getString(R.string.title_language_settings), lgName);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public final class ModelPickerActivity extends AppCompatActivity {
|
|||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
String newLanguageID = bundle.getString(KMManager.KMKey_LanguageID);
|
||||
String newCustomHelpLink = bundle.getString(KMManager.KMKey_CustomHelpLink);
|
||||
String newCustomHelpLink = bundle.getString(KMManager.KMKey_CustomHelpLink, "");
|
||||
|
||||
// Sometimes we need to re-initialize the list of models that are displayed in the ListView
|
||||
languageID = newLanguageID;
|
||||
|
|
|
|||
|
|
@ -414,6 +414,11 @@ public final class FileUtils {
|
|||
return f.endsWith(LEXICALMODEL);
|
||||
}
|
||||
|
||||
public static boolean hasLexicalModelPackageExtension(String filename) {
|
||||
String f = filename.toLowerCase();
|
||||
return f.endsWith(MODELPACKAGE);
|
||||
}
|
||||
|
||||
public static boolean hasKeymanPackageExtension(String filename) {
|
||||
String f = filename.toLowerCase();
|
||||
return f.endsWith(KEYMANPACKAGE);
|
||||
|
|
|
|||
|
|
@ -190,6 +190,30 @@ public class FileUtilsTest {
|
|||
Assert.assertFalse(FileUtils.hasLexicalModelExtension(filename));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hasLexicalModelPackageExtension() {
|
||||
String filename = "test/abc.kmp";
|
||||
Assert.assertFalse(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "test/abc.KMP";
|
||||
Assert.assertFalse(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "test/abc.kmpo";
|
||||
Assert.assertFalse(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "test/abc.model.kmp";
|
||||
Assert.assertTrue(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "test/abc.MODEL.KMP";
|
||||
Assert.assertTrue(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "test/abc.MODEL.KMPO";
|
||||
Assert.assertFalse(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
|
||||
filename = "";
|
||||
Assert.assertFalse(FileUtils.hasLexicalModelPackageExtension(filename));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hasKeymanPackageExtension() {
|
||||
String filename = "test/abc.kmp";
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class FunctionalTestHelper {
|
|||
*/
|
||||
static void setInitialKeyboard()
|
||||
{
|
||||
KMManager.setKeyboard(KMManager.KMDefault_UndefinedPackageID,
|
||||
KMManager.setKeyboard(KMManager.KMDefault_PackageID,
|
||||
KMManager.KMDefault_KeyboardID,
|
||||
KMManager.KMDefault_LanguageID,
|
||||
KMManager.KMDefault_KeyboardName,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue