diff options
-rw-r--r-- | java/res/values/donottranslate.xml | 4 | ||||
-rw-r--r-- | java/res/xml/prefs.xml | 4 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | 37 |
3 files changed, 38 insertions, 7 deletions
diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index fb28766e7..f55e9bf53 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -153,4 +153,8 @@ <!-- Generic subtype label --> <string name="subtype_generic">%s</string> + + <!-- dictionary pack package name /settings activity (for shared prefs and settings) --> + <string name="dictionary_pack_package_name">com.google.android.inputmethod.latin.dictionarypack</string> + <string name="dictionary_pack_settings_activity">com.google.android.inputmethod.latin.dictionarypack.DictionarySettingsActivity</string> </resources> diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 552e3cf4f..2ff82f93d 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -70,8 +70,8 @@ android:title="@string/configure_dictionaries_title"> <intent android:action="android.intent.action.MAIN" - android:targetPackage="com.google.android.inputmethod.latin.dictionarypack" - android:targetClass="com.google.android.inputmethod.latin.dictionarypack.DictionarySettingsActivity" /> + android:targetPackage="@string/dictionary_pack_package_name" + android:targetClass="@string/dictionary_pack_settings_activity" /> </PreferenceScreen> <ListPreference android:key="auto_correction_threshold" diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index b26731ac5..170edad99 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -121,6 +122,30 @@ class BinaryDictionaryGetter { } /** + * Returns the list of cached files for a specific locale. + * + * @param locale the locale to find the dictionary files for. + * @param context the context on which to open the files upon. + * @return a list of binary dictionary files, which may be null but may not be empty. + */ + private static List<AssetFileAddress> getCachedDictionaryList(final Locale locale, + final Context context) { + final String directoryName = getCacheDirectoryForLocale(locale, context); + final File[] cacheFiles = new File(directoryName).listFiles(); + if (null == cacheFiles) return null; + + final ArrayList<AssetFileAddress> fileList = new ArrayList<AssetFileAddress>(); + for (File f : cacheFiles) { + if (f.canRead()) { + fileList.add(AssetFileAddress.makeFromFileName(f.getPath())); + } else { + Log.e(TAG, "Found a cached dictionary file but cannot read it"); + } + } + return fileList.size() > 0 ? fileList : null; + } + + /** * Returns a list of file addresses for a given locale, trying relevant methods in order. * * Tries to get binary dictionaries from various sources, in order: @@ -132,12 +157,14 @@ class BinaryDictionaryGetter { * - Returns null. * @return The address of a valid file, or null. */ - public static List<AssetFileAddress> getDictionaryFiles(Locale locale, Context context, - int fallbackResId) { + public static List<AssetFileAddress> getDictionaryFiles(final Locale locale, + final Context context, final int fallbackResId) { try { - List<AssetFileAddress> cachedDictionaryList = - BinaryDictionaryFileDumper.cacheDictionariesFromContentProvider(locale, - context); + // cacheDictionariesFromContentProvider returns the list of files it copied to local + // storage, but we don't really care about what was copied NOW: what we want is the + // list of everything we ever cached, so we ignore the return value. + BinaryDictionaryFileDumper.cacheDictionariesFromContentProvider(locale, context); + List<AssetFileAddress> cachedDictionaryList = getCachedDictionaryList(locale, context); if (null != cachedDictionaryList) { return cachedDictionaryList; } |