From a414b81a6c69e89ce36c3756560062af84af4027 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 21 Nov 2014 17:58:50 +0900 Subject: [PATCH] Remove unused code from DictionaryFactory Change-Id: I666308ada968ee7993235ad98b92f2ad522af122 --- .../latin/BinaryDictionaryGetter.java | 3 +- .../inputmethod/latin/DictionaryFactory.java | 55 +------------------ .../latin/utils/DictionaryInfoUtils.java | 11 ++++ 3 files changed, 16 insertions(+), 53 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 5afb62b69..9c70cad0a 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -263,7 +263,8 @@ final public class BinaryDictionaryGetter { public static ArrayList getDictionaryFiles(final Locale locale, final Context context) { - final boolean hasDefaultWordList = DictionaryFactory.isDictionaryAvailable(context, locale); + final boolean hasDefaultWordList = DictionaryInfoUtils.isDictionaryAvailable( + context, locale); BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context, hasDefaultWordList); final File[] cachedWordLists = getCachedWordLists(locale.toString(), context); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 3459b426d..4de1f99af 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -19,10 +19,8 @@ package com.android.inputmethod.latin; import android.content.ContentProviderClient; import android.content.Context; import android.content.res.AssetFileDescriptor; -import android.content.res.Resources; import android.util.Log; -import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import java.io.File; @@ -43,11 +41,10 @@ public final class DictionaryFactory { * locale. If none is found, it falls back to the built-in dictionary - if any. * @param context application context for reading resources * @param locale the locale for which to create the dictionary - * @param useFullEditDistance whether to use the full edit distance in suggestions * @return an initialized instance of DictionaryCollection */ public static DictionaryCollection createMainDictionaryFromManager(final Context context, - final Locale locale, final boolean useFullEditDistance) { + final Locale locale) { if (null == locale) { Log.e(TAG, "No locale defined for dictionary"); return new DictionaryCollection(Dictionary.TYPE_MAIN, locale, @@ -61,7 +58,7 @@ public final class DictionaryFactory { for (final AssetFileAddress f : assetFileList) { final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = new ReadOnlyBinaryDictionary(f.mFilename, f.mOffset, f.mLength, - useFullEditDistance, locale, Dictionary.TYPE_MAIN); + false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN); if (readOnlyBinaryDictionary.isValidDictionary()) { dictList.add(readOnlyBinaryDictionary); } else { @@ -123,27 +120,13 @@ public final class DictionaryFactory { } } - /** - * Initializes a main dictionary collection from a dictionary pack, with default flags. - * - * This searches for a content provider providing a dictionary pack for the specified - * locale. If none is found, it falls back to the built-in dictionary, if any. - * @param context application context for reading resources - * @param locale the locale for which to create the dictionary - * @return an initialized instance of DictionaryCollection - */ - public static DictionaryCollection createMainDictionaryFromManager(final Context context, - final Locale locale) { - return createMainDictionaryFromManager(context, locale, false /* useFullEditDistance */); - } - /** * Initializes a read-only binary dictionary from a raw resource file * @param context application context for reading resources * @param locale the locale to use for the resource * @return an initialized instance of ReadOnlyBinaryDictionary */ - protected static ReadOnlyBinaryDictionary createReadOnlyBinaryDictionary(final Context context, + private static ReadOnlyBinaryDictionary createReadOnlyBinaryDictionary(final Context context, final Locale locale) { AssetFileDescriptor afd = null; try { @@ -177,36 +160,4 @@ public final class DictionaryFactory { } } } - - /** - * Create a dictionary from passed data. This is intended for unit tests only. - * @param dictionaryList the list of files to read, with their offsets and lengths - * @param useFullEditDistance whether to use the full edit distance in suggestions - * @return the created dictionary, or null. - */ - @UsedForTesting - public static Dictionary createDictionaryForTest(final AssetFileAddress[] dictionaryList, - final boolean useFullEditDistance, Locale locale) { - final DictionaryCollection dictionaryCollection = - new DictionaryCollection(Dictionary.TYPE_MAIN, locale); - for (final AssetFileAddress address : dictionaryList) { - final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = new ReadOnlyBinaryDictionary( - address.mFilename, address.mOffset, address.mLength, useFullEditDistance, - locale, Dictionary.TYPE_MAIN); - dictionaryCollection.addDictionary(readOnlyBinaryDictionary); - } - return dictionaryCollection; - } - - /** - * Find out whether a dictionary is available for this locale. - * @param context the context on which to check resources. - * @param locale the locale to check for. - * @return whether a (non-placeholder) dictionary is available or not. - */ - public static boolean isDictionaryAvailable(Context context, Locale locale) { - final Resources res = context.getResources(); - return 0 != DictionaryInfoUtils.getMainDictionaryResourceIdIfAvailableForLocale( - res, locale); - } } diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index 81c3e3c61..71d724d74 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -229,6 +229,17 @@ public class DictionaryInfoUtils { return BinaryDictionaryGetter.MAIN_DICTIONARY_CATEGORY.equals(idArray[0]); } + /** + * Find out whether a dictionary is available for this locale. + * @param context the context on which to check resources. + * @param locale the locale to check for. + * @return whether a (non-placeholder) dictionary is available or not. + */ + public static boolean isDictionaryAvailable(final Context context, final Locale locale) { + final Resources res = context.getResources(); + return 0 != getMainDictionaryResourceIdIfAvailableForLocale(res, locale); + } + /** * Helper method to return a dictionary res id for a locale, or 0 if none. * @param res resources for the app