diff options
author | 2011-07-21 17:36:57 +0900 | |
---|---|---|
committer | 2011-07-21 19:14:16 +0900 | |
commit | e150ef98569d61078e0f8c67ded8364a9c3d4a20 (patch) | |
tree | 5ce9e15775f09f98d78cd5745e7c5712c0111ebe /java/src/com/android/inputmethod/latin/DictionaryFactory.java | |
parent | 728ab86f8c8a94beee1fe1581eb1c51757b84d56 (diff) | |
download | latinime-e150ef98569d61078e0f8c67ded8364a9c3d4a20.tar.gz latinime-e150ef98569d61078e0f8c67ded8364a9c3d4a20.tar.xz latinime-e150ef98569d61078e0f8c67ded8364a9c3d4a20.zip |
Set the locale for opening an asset
This is necessary because we don't know any more whether the
locale of the process is the expected one when the dictionary
is loaded asynchronously.
Bug: 5023141
Change-Id: Ia9e4741f3b4a04a9f085f5b65ec122471b0c2dff
Diffstat (limited to 'java/src/com/android/inputmethod/latin/DictionaryFactory.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/DictionaryFactory.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index f0637b8ce..39b4f63a5 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -48,7 +48,7 @@ public class DictionaryFactory { int fallbackResId) { if (null == locale) { Log.e(TAG, "No locale defined for dictionary"); - return new DictionaryCollection(createBinaryDictionary(context, fallbackResId)); + return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale)); } final List<Dictionary> dictList = new LinkedList<Dictionary>(); @@ -76,7 +76,8 @@ public class DictionaryFactory { // 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)); + return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, + locale)); } else { return new DictionaryCollection(dictList); } @@ -87,12 +88,21 @@ public class DictionaryFactory { * Initializes a dictionary from a raw resource file * @param context application context for reading resources * @param resId the resource containing the raw binary dictionary + * @param locale the locale to use for the resource * @return an initialized instance of BinaryDictionary */ - protected static BinaryDictionary createBinaryDictionary(Context context, int resId) { + protected static BinaryDictionary createBinaryDictionary(final Context context, + final int resId, final Locale locale) { AssetFileDescriptor afd = null; try { - afd = context.getResources().openRawResourceFd(resId); + final Resources res = context.getResources(); + if (null != locale) { + final Locale savedLocale = Utils.setSystemLocale(res, locale); + afd = res.openRawResourceFd(resId); + Utils.setSystemLocale(res, savedLocale); + } else { + afd = res.openRawResourceFd(resId); + } if (afd == null) { Log.e(TAG, "Found the resource but it is compressed. resId=" + resId); return null; |