aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-08-16 21:41:12 +0900
committerJean Chalard <jchalard@google.com>2011-08-17 11:25:21 +0900
commitc11c4fd61b3574f3647299ec0f19ee01ecaabf52 (patch)
tree2dcf5ffff9083afe61164a52f43704114e3e945f /java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
parent29ea7b79c70ef46e9144c0b12a5e0e681646101d (diff)
downloadlatinime-c11c4fd61b3574f3647299ec0f19ee01ecaabf52.tar.gz
latinime-c11c4fd61b3574f3647299ec0f19ee01ecaabf52.tar.xz
latinime-c11c4fd61b3574f3647299ec0f19ee01ecaabf52.zip
Factor dict pack settings reading into a static inner class
This is essentially refactoring to help next steps Bug: 5095140 Change-Id: Ic97044d2ed354027bac4f84e6ce69d20ef6da092
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java51
1 files changed, 37 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 360cf21ca..a13e9f2c9 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -158,6 +158,41 @@ class BinaryDictionaryGetter {
context.getApplicationInfo().sourceDir, afd.getStartOffset(), afd.getLength());
}
+ static private class DictPackSettings {
+ final SharedPreferences mDictPreferences;
+ public DictPackSettings(final Context context) {
+ Context dictPackContext = null;
+ try {
+ final String dictPackName =
+ context.getString(R.string.dictionary_pack_package_name);
+ dictPackContext = context.createPackageContext(dictPackName, 0);
+ } catch (NameNotFoundException e) {
+ // The dictionary pack is not installed...
+ // TODO: fallback on the built-in dict, see the TODO above
+ Log.e(TAG, "Could not find a dictionary pack");
+ }
+ mDictPreferences = null == dictPackContext ? null
+ : dictPackContext.getSharedPreferences(COMMON_PREFERENCES_NAME,
+ Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
+ }
+ public boolean isWordListActive(final String dictId) {
+ if (null == mDictPreferences) {
+ // If we don't have preferences it basically means we can't find the dictionary
+ // pack - either it's not installed, or it's disabled, or there is some strange
+ // bug. Either way, a word list with no settings should be on by default: default
+ // dictionaries in LatinIME are on if there is no settings at all, and if for some
+ // reason some dictionaries have been installed BUT the dictionary pack can't be
+ // found anymore it's safer to actually supply installed dictionaries.
+ return true;
+ } else {
+ // The default is true here for the same reasons as above. We got the dictionary
+ // pack but if we don't have any settings for it it means the user has never been
+ // to the settings yet. So by default, the main dictionaries should be on.
+ return mDictPreferences.getBoolean(dictId, true);
+ }
+ }
+ }
+
/**
* Returns the list of cached files for a specific locale.
*
@@ -173,24 +208,12 @@ class BinaryDictionaryGetter {
// not present or disabled, then return an empty list.
if (null == cacheFiles) return null;
- final SharedPreferences dictPackSettings;
- try {
- final String dictPackName = context.getString(R.string.dictionary_pack_package_name);
- final Context dictPackContext = context.createPackageContext(dictPackName, 0);
- dictPackSettings = dictPackContext.getSharedPreferences(COMMON_PREFERENCES_NAME,
- Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
- } catch (NameNotFoundException e) {
- // The dictionary pack is not installed...
- // TODO: fallback on the built-in dict, see the TODO above
- Log.e(TAG, "Could not find a dictionary pack");
- return null;
- }
+ final DictPackSettings dictPackSettings = new DictPackSettings(context);
final ArrayList<AssetFileAddress> fileList = new ArrayList<AssetFileAddress>();
for (File f : cacheFiles) {
final String wordListId = getWordListIdFromFileName(f.getName());
- final boolean isActive = dictPackSettings.getBoolean(wordListId, true);
- if (!isActive) continue;
+ if (!dictPackSettings.isWordListActive(wordListId)) continue;
if (f.canRead()) {
fileList.add(AssetFileAddress.makeFromFileName(f.getPath()));
} else {