aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java38
-rw-r--r--java/src/com/android/inputmethod/latin/utils/RunInLocale.java14
2 files changed, 43 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 38359fc15..b88509fde 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
/**
* Implements a static, compacted, binary dictionary of standard words.
@@ -123,8 +124,7 @@ public final class BinaryDictionary extends Dictionary {
}
/**
- * Constructor for the binary dictionary. This is supposed to be called from the
- * dictionary factory.
+ * Constructs binary dictionary using existing dictionary file.
* @param filename the name of the file to read through native code.
* @param offset the offset of the dictionary data within the file.
* @param length the length of the binary data.
@@ -145,12 +145,46 @@ public final class BinaryDictionary extends Dictionary {
loadDictionary(filename, offset, length, isUpdatable);
}
+ /**
+ * Constructs binary dictionary on memory.
+ * @param filename the name of the file used to flush.
+ * @param useFullEditDistance whether to use the full edit distance in suggestions
+ * @param dictType the dictionary type, as a human-readable string
+ * @param formatVersion the format version of the dictionary
+ * @param attributeMap the attributes of the dictionary
+ */
+ @UsedForTesting
+ public BinaryDictionary(final String filename, final boolean useFullEditDistance,
+ final Locale locale, final String dictType, final long formatVersion,
+ final Map<String, String> attributeMap) {
+ super(dictType);
+ mLocale = locale;
+ mDictSize = 0;
+ mDictFilePath = filename;
+ // On memory dictionary is always updatable.
+ mIsUpdatable = true;
+ mHasUpdated = false;
+ mNativeSuggestOptions.setUseFullEditDistance(useFullEditDistance);
+ final String[] keyArray = new String[attributeMap.size()];
+ final String[] valueArray = new String[attributeMap.size()];
+ int index = 0;
+ for (final String key : attributeMap.keySet()) {
+ keyArray[index] = key;
+ valueArray[index] = attributeMap.get(key);
+ index++;
+ }
+ mNativeDict = createOnMemoryNative(formatVersion, locale.toString(), keyArray, valueArray);
+ }
+
+
static {
JniUtils.loadNativeLibrary();
}
private static native long openNative(String sourceDir, long dictOffset, long dictSize,
boolean isUpdatable);
+ private static native long createOnMemoryNative(long formatVersion,
+ String locale, String[] attributeKeyStringArray, String[] attributeValueStringArray);
private static native void getHeaderInfoNative(long dict, int[] outHeaderSize,
int[] outFormatVersion, ArrayList<int[]> outAttributeKeys,
ArrayList<int[]> outAttributeValues);
diff --git a/java/src/com/android/inputmethod/latin/utils/RunInLocale.java b/java/src/com/android/inputmethod/latin/utils/RunInLocale.java
index 3c632bbc3..1ea16e6ef 100644
--- a/java/src/com/android/inputmethod/latin/utils/RunInLocale.java
+++ b/java/src/com/android/inputmethod/latin/utils/RunInLocale.java
@@ -35,18 +35,18 @@ public abstract class RunInLocale<T> {
*/
public T runInLocale(final Resources res, final Locale newLocale) {
synchronized (sLockForRunInLocale) {
- final Configuration savedConf = res.getConfiguration();
- if (newLocale == null || newLocale.equals(savedConf.locale)) {
+ final Configuration conf = res.getConfiguration();
+ if (newLocale == null || newLocale.equals(conf.locale)) {
return job(res);
}
- final Configuration newConf = new Configuration();
- newConf.setTo(savedConf);
- newConf.setLocale(newLocale);
+ final Locale savedLocale = conf.locale;
try {
- res.updateConfiguration(newConf, null);
+ conf.locale = newLocale;
+ res.updateConfiguration(conf, null);
return job(res);
} finally {
- res.updateConfiguration(savedConf, null);
+ conf.locale = savedLocale;
+ res.updateConfiguration(conf, null);
}
}
}