[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
This commit is contained in:
parent
8fff6ae68b
commit
f13487dfbf
3 changed files with 25 additions and 5 deletions
|
@ -18,7 +18,6 @@ package com.android.inputmethod.latin.settings;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class AdditionalFeaturesSettingUtils {
|
||||||
public static RichInputMethodSubtype createRichInputMethodSubtype(
|
public static RichInputMethodSubtype createRichInputMethodSubtype(
|
||||||
@Nonnull final RichInputMethodManager imm,
|
@Nonnull final RichInputMethodManager imm,
|
||||||
@Nonnull final InputMethodSubtype subtype,
|
@Nonnull final InputMethodSubtype subtype,
|
||||||
final Resources resources) {
|
final Context context) {
|
||||||
return new RichInputMethodSubtype(subtype);
|
return new RichInputMethodSubtype(subtype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class RichInputMethodManager {
|
||||||
|
|
||||||
private static final RichInputMethodManager sInstance = new RichInputMethodManager();
|
private static final RichInputMethodManager sInstance = new RichInputMethodManager();
|
||||||
|
|
||||||
private Resources mResources;
|
private Context mContext;
|
||||||
private InputMethodManagerCompatWrapper mImmWrapper;
|
private InputMethodManagerCompatWrapper mImmWrapper;
|
||||||
private InputMethodInfoCache mInputMethodInfoCache;
|
private InputMethodInfoCache mInputMethodInfoCache;
|
||||||
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
|
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
|
||||||
|
@ -86,7 +86,7 @@ public class RichInputMethodManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mImmWrapper = new InputMethodManagerCompatWrapper(context);
|
mImmWrapper = new InputMethodManagerCompatWrapper(context);
|
||||||
mResources = context.getResources();
|
mContext = context;
|
||||||
mInputMethodInfoCache = new InputMethodInfoCache(
|
mInputMethodInfoCache = new InputMethodInfoCache(
|
||||||
mImmWrapper.mImm, context.getPackageName());
|
mImmWrapper.mImm, context.getPackageName());
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ public class RichInputMethodManager {
|
||||||
public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
|
public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
|
||||||
final InputMethodSubtype rawSubtype) {
|
final InputMethodSubtype rawSubtype) {
|
||||||
return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype,
|
return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype,
|
||||||
mResources);
|
mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
|
public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
|
||||||
|
|
|
@ -230,6 +230,7 @@ public class DictionaryInfoUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to return a dictionary res id for a locale, or 0 if none.
|
* 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
|
* @param locale dictionary locale
|
||||||
* @return main dictionary resource id
|
* @return main dictionary resource id
|
||||||
*/
|
*/
|
||||||
|
@ -258,6 +259,7 @@ public class DictionaryInfoUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a main dictionary resource id
|
* Returns a main dictionary resource id
|
||||||
|
* @param res resources for the app
|
||||||
* @param locale dictionary locale
|
* @param locale dictionary locale
|
||||||
* @return main dictionary resource id
|
* @return main dictionary resource id
|
||||||
*/
|
*/
|
||||||
|
@ -283,6 +285,25 @@ public class DictionaryInfoUtils {
|
||||||
BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + locale.getLanguage().toString();
|
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) {
|
public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file) {
|
||||||
return getDictionaryFileHeaderOrNull(file, 0, file.length());
|
return getDictionaryFileHeaderOrNull(file, 0, file.length());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue