diff options
author | 2014-10-15 23:23:30 +0900 | |
---|---|---|
committer | 2014-10-16 17:09:27 +0900 | |
commit | f13487dfbf2b7547b48a5e9123235ee8a1d660c8 (patch) | |
tree | ab2dedb692c67f475ba9e9ef9759675eb71d19b3 /java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java | |
parent | 8fff6ae68b3c2e31687370fc867d3b6098938be7 (diff) | |
download | latinime-f13487dfbf2b7547b48a5e9123235ee8a1d660c8.tar.gz latinime-f13487dfbf2b7547b48a5e9123235ee8a1d660c8.tar.xz latinime-f13487dfbf2b7547b48a5e9123235ee8a1d660c8.zip |
[ML25] Add an hasDict method.
We used to have separate methods for existence of dicts
according to whether it's a file or a resource. This unifies both.
Bug: 11230254
Bug: 17979623
Change-Id: I728773461f3465f756d06297c3f3bee34390c3e6
Diffstat (limited to 'java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index 249478785..e29aabacd 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -230,6 +230,7 @@ public class DictionaryInfoUtils { /** * Helper method to return a dictionary res id for a locale, or 0 if none. + * @param res resources for the app * @param locale dictionary locale * @return main dictionary resource id */ @@ -258,6 +259,7 @@ public class DictionaryInfoUtils { /** * Returns a main dictionary resource id + * @param res resources for the app * @param locale dictionary locale * @return main dictionary resource id */ @@ -283,6 +285,25 @@ public class DictionaryInfoUtils { BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + locale.getLanguage().toString(); } + /** + * Returns whether a main dictionary is readily available for this locale. + * + * This does not query the content provider. + * + * @param context context to open files upon + * @param locale dictionary locale + * @return true if a dictionary is available right away, false otherwise + */ + public static boolean hasReadilyAvailableMainDictionaryForLocale(final Context context, + final Locale locale) { + final Resources res = context.getResources(); + if (0 != getMainDictionaryResourceIdIfAvailableForLocale(res, locale)) { + return true; + } + final String fileName = getCacheFileName(getMainDictId(locale), locale.toString(), context); + return new File(fileName).exists(); + } + public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file) { return getDictionaryFileHeaderOrNull(file, 0, file.length()); } |