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/BinaryDictionaryGetter.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/BinaryDictionaryGetter.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index bce787db2..989a0e9a0 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.res.AssetFileDescriptor; +import android.content.res.Resources; import android.util.Log; import java.io.FileNotFoundException; @@ -42,8 +43,13 @@ class BinaryDictionaryGetter { /** * Returns a file address from a resource, or null if it cannot be opened. */ - private static AssetFileAddress loadFallbackResource(Context context, int fallbackResId) { - final AssetFileDescriptor afd = context.getResources().openRawResourceFd(fallbackResId); + private static AssetFileAddress loadFallbackResource(final Context context, + final int fallbackResId, final Locale locale) { + final Resources res = context.getResources(); + final Locale savedLocale = Utils.setSystemLocale(res, locale); + final AssetFileDescriptor afd = res.openRawResourceFd(fallbackResId); + Utils.setSystemLocale(res, savedLocale); + if (afd == null) { Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId=" + fallbackResId); @@ -91,7 +97,8 @@ class BinaryDictionaryGetter { Log.e(TAG, "Unable to read source data for locale " + locale.toString() + ": falling back to internal dictionary"); } - final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId); + final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId, + locale); if (null == fallbackAsset) return null; return Arrays.asList(fallbackAsset); } |