diff options
author | 2011-07-20 19:50:54 -0700 | |
---|---|---|
committer | 2011-07-20 19:50:54 -0700 | |
commit | 728ab86f8c8a94beee1fe1581eb1c51757b84d56 (patch) | |
tree | 480cb41cb685a070f63c7d978683f75485e4a50a /java/src/com/android/inputmethod | |
parent | 5f4ebfc67b38bbdc8612ec26af1d8e2cd065dd0f (diff) | |
parent | 7e19a64c86147967b39442ba78b175d4c8a0c860 (diff) | |
download | latinime-728ab86f8c8a94beee1fe1581eb1c51757b84d56.tar.gz latinime-728ab86f8c8a94beee1fe1581eb1c51757b84d56.tar.xz latinime-728ab86f8c8a94beee1fe1581eb1c51757b84d56.zip |
Merge "Fallback to the included dict if the passed one is invalid"
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r-- | java/src/com/android/inputmethod/latin/DictionaryFactory.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index a35b0f5b0..f0637b8ce 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -56,8 +56,11 @@ public class DictionaryFactory { BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId); if (null != assetFileList) { for (final AssetFileAddress f : assetFileList) { - dictList.add( - new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null)); + final BinaryDictionary binaryDictionary = + new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null); + if (binaryDictionary.isValidDictionary()) { + dictList.add(binaryDictionary); + } } } @@ -67,7 +70,16 @@ public class DictionaryFactory { if (null == dictList) { return new DictionaryCollection(); } else { - return new DictionaryCollection(dictList); + if (dictList.isEmpty()) { + // The list may be empty if no dictionaries have been added. The getter should not + // return an empty list, but if it does we end up here. Likewise, if the files + // we found could not be opened by the native code for any reason (format mismatch, + // file too big to fit in memory, etc) then we could have an empty list. In this + // case we want to fall back on the resource. + return new DictionaryCollection(createBinaryDictionary(context, fallbackResId)); + } else { + return new DictionaryCollection(dictList); + } } } |