diff options
author | 2011-03-14 11:46:15 -0700 | |
---|---|---|
committer | 2011-03-18 12:16:50 -0700 | |
commit | cba93f50c3d46ada773ec49435689dc3e2094385 (patch) | |
tree | fc39bc20d316c6ff17af226e7f64a750edb1866e /java/src/com/android/inputmethod/latin/BinaryDictionary.java | |
parent | 9807ab27eac3a10b299382af8280eb54dca50608 (diff) | |
download | latinime-cba93f50c3d46ada773ec49435689dc3e2094385.tar.gz latinime-cba93f50c3d46ada773ec49435689dc3e2094385.tar.xz latinime-cba93f50c3d46ada773ec49435689dc3e2094385.zip |
Add different ways of reading the dictionary file.
This change adds basic support for an external dictionary provider.
It adds methods for reading the dictionary itself from an asset in
the dictionary provider package directly, obtaining the file name
through the ContentProvider interface; it also adds a way of getting
the data through an InputStream and copying the file locally.
Incidentally this change also adds the code needed to listen for
updating the dictionary provider package and reloading it in time.
This change also goes hand-in-hand with Iab31db6e, which implements
the small closed part of this.
Issue: 3414944
Change-Id: I5e4fff99a59bb99dbdb002102db6c90e6cb41c8a
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionary.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index ca7261b43..fa90fce67 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -26,14 +26,18 @@ import android.util.Log; import java.io.File; import java.util.Arrays; +import java.util.Locale; /** * Implements a static, compacted, binary dictionary of standard words. */ public class BinaryDictionary extends Dictionary { + public static final String DICTIONARY_PACK_AUTHORITY = + "com.android.inputmethod.latin.dictionarypack"; + /** - * There is difference between what java and native code can handle. + * There is a difference between what java and native code can handle. * This value should only be used in BinaryDictionary.java * It is necessary to keep it at this value because some languages e.g. German have * really long words. @@ -85,10 +89,11 @@ public class BinaryDictionary extends Dictionary { } /** - * Initialize a dictionary from a raw resource file + * Initializes a dictionary from a raw resource file * @param context application context for reading resources * @param resId the resource containing the raw binary dictionary - * @return initialized instance of BinaryDictionary + * @param dicTypeId the type of the dictionary being created, out of the list in Suggest.DIC_* + * @return an initialized instance of BinaryDictionary */ public static BinaryDictionary initDictionary(Context context, int resId, int dicTypeId) { synchronized (sInstance) { @@ -146,6 +151,37 @@ public class BinaryDictionary extends Dictionary { Utils.loadNativeLibrary(); } + /** + * Initializes a dictionary from a dictionary pack. + * + * This searches for a content provider providing a dictionary pack for the specified + * locale. If none is found, it falls back to using the resource passed as fallBackResId + * as a dictionary. + * @param context application context for reading resources + * @param dicTypeId the type of the dictionary being created, out of the list in Suggest.DIC_* + * @param locale the locale for which to create the dictionary + * @param fallBackResId the id of the resource to use as a fallback if no pack is found + * @return an initialized instance of BinaryDictionary + */ + public static BinaryDictionary initDictionaryFromManager(Context context, int dicTypeId, + Locale locale, int fallbackResId) { + if (null == locale) { + Log.e(TAG, "No locale defined for dictionary"); + return initDictionary(context, fallbackResId, dicTypeId); + } + synchronized (sInstance) { + sInstance.closeInternal(); + + final AssetFileAddress dictFile = BinaryDictionaryGetter.getDictionaryFile(locale, + context, fallbackResId); + if (null != dictFile) { + sInstance.loadDictionary(dictFile.mFilename, dictFile.mOffset, dictFile.mLength); + sInstance.mDicTypeId = dicTypeId; + } + } + return sInstance; + } + private native int openNative(String sourceDir, long dictOffset, long dictSize, int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords, int maxAlternatives); |