Fix modelSpec passed for registration

* Also read in lexical models list
This commit is contained in:
Darcy Wong 2019-03-27 10:37:10 +07:00
parent 36f8edb875
commit 8cea2e07d7
2 changed files with 20 additions and 15 deletions

View file

@ -656,25 +656,27 @@ public final class KMManager {
String languageID = lexicalModelInfo.get(KMKey_LanguageID);
String path = "file://" + getLexicalModelsDir() + pkgID + File.separator + modelID + ".model.js";
JSONObject m = new JSONObject();
JSONArray languageArray = new JSONArray();
JSONObject modelObj = new JSONObject();
JSONArray languageJSONArray = new JSONArray();
try {
m.put("id", modelID);
languageArray.put(languageID);
m.put("languages", languageArray);
m.put("path", path);
modelObj.put("id", modelID);
languageJSONArray.put(languageID);
modelObj.put("languages", languageJSONArray);
modelObj.put("path", path);
} catch (JSONException e) {
}
// Escape quotes for javascript call
String model = String.valueOf(m).replaceAll("\"", "\\\\\"");
// Use single quotes in JSONobject for javascript call
String model = String.valueOf(modelObj);
model = model.replaceAll("\"", "'");
//model = "{'id': 'example.en.custom', 'languages': ['en'], 'path': 'file:///data/user/0/com.tavultesoft.kmapro.debug/app_data/models/example.en.custom.model/example.en.custom.model.js'}";
if (InAppKeyboard != null && InAppKeyboardLoaded && !InAppKeyboardShouldIgnoreTextChange) {
InAppKeyboard.loadUrl(String.format("javascript:registerModel('%s')", model));
InAppKeyboard.loadUrl(String.format("javascript:registerModel(%s)", model));
}
if (SystemKeyboard != null && SystemKeyboardLoaded && !SystemKeyboardShouldIgnoreTextChange) {
SystemKeyboard.loadUrl(String.format("javascript:registerModel('%s')", model));
SystemKeyboard.loadUrl(String.format("javascript:registerModel(%s)", model));
}
return true;
}

View file

@ -134,6 +134,7 @@ public final class KeyboardPickerActivity extends AppCompatActivity implements O
}
}
lexicalModelsList = getLexicalModelsList(context);
if (lexicalModelsList == null) {
lexicalModelsList = new ArrayList<HashMap<String, String>>();
@ -623,11 +624,13 @@ public final class KeyboardPickerActivity extends AppCompatActivity implements O
}
protected static HashMap<String, String> getAssociatedLexicalModel(String langId) {
int length = lexicalModelsList.size();
for( int i=0; i < length; i++) {
HashMap<String, String> lmInfo = lexicalModelsList.get(i);
if (langId.equalsIgnoreCase(lmInfo.get(KMManager.KMKey_LanguageID))) {
return lmInfo;
if (lexicalModelsList != null) {
int length = lexicalModelsList.size();
for (int i = 0; i < length; i++) {
HashMap<String, String> lmInfo = lexicalModelsList.get(i);
if (langId.equalsIgnoreCase(lmInfo.get(KMManager.KMKey_LanguageID))) {
return lmInfo;
}
}
}