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/Suggest.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/Suggest.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Suggest.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index a61a7f159..0cc9d4198 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -106,8 +107,9 @@ public class Suggest implements Dictionary.WordCallback { private int mCorrectionMode = CORRECTION_BASIC; - public Suggest(Context context, int dictionaryResId) { - init(context, BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN)); + public Suggest(Context context, int dictionaryResId, Locale locale) { + init(context, BinaryDictionary.initDictionaryFromManager(context, DIC_MAIN, locale, + dictionaryResId)); } /* package for test */ Suggest(File dictionary, long startOffset, long length, @@ -130,6 +132,19 @@ public class Suggest implements Dictionary.WordCallback { initPool(); } + public void resetMainDict(Context context, int dictionaryResId, Locale locale) { + final BinaryDictionary newMainDict = BinaryDictionary.initDictionaryFromManager(context, + DIC_MAIN, locale, dictionaryResId); + mMainDict = newMainDict; + if (null == newMainDict) { + mUnigramDictionaries.remove(DICT_KEY_MAIN); + mBigramDictionaries.remove(DICT_KEY_MAIN); + } else { + mUnigramDictionaries.put(DICT_KEY_MAIN, newMainDict); + mBigramDictionaries.put(DICT_KEY_MAIN, newMainDict); + } + } + private void initPool() { for (int i = 0; i < mPrefMaxSuggestions; i++) { StringBuilder sb = new StringBuilder(getApproxMaxWordLength()); |