Fallback to the included dict if the passed one is invalid
If all dictionaries returned by the dictionary pack are invalid, then fallback to the dictionary included in the resources for this locale. Bug: 5052486 Change-Id: Id875194ca56a74b2ed6f5b0b4fdd55475f6842c8main
parent
597b115797
commit
7e19a64c86
|
@ -56,8 +56,11 @@ public class DictionaryFactory {
|
||||||
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
|
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
|
||||||
if (null != assetFileList) {
|
if (null != assetFileList) {
|
||||||
for (final AssetFileAddress f : assetFileList) {
|
for (final AssetFileAddress f : assetFileList) {
|
||||||
dictList.add(
|
final BinaryDictionary binaryDictionary =
|
||||||
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null));
|
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null);
|
||||||
|
if (binaryDictionary.isValidDictionary()) {
|
||||||
|
dictList.add(binaryDictionary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +69,19 @@ public class DictionaryFactory {
|
||||||
// to return an empty DictionaryCollection.
|
// to return an empty DictionaryCollection.
|
||||||
if (null == dictList) {
|
if (null == dictList) {
|
||||||
return new DictionaryCollection();
|
return new DictionaryCollection();
|
||||||
|
} else {
|
||||||
|
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 {
|
} else {
|
||||||
return new DictionaryCollection(dictList);
|
return new DictionaryCollection(dictList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a dictionary from a raw resource file
|
* Initializes a dictionary from a raw resource file
|
||||||
|
|
Loading…
Reference in New Issue