am 72cbfdcd: am 2bcd913e: Merge "Add SuggestInitializationListener to BinaryDictionary.resetMainDict()" into jb-mr1-dev

* commit '72cbfdcd80210dc412b8094df1060b0685b356df':
  Add SuggestInitializationListener to BinaryDictionary.resetMainDict()
main
Tadashi G. Takaoka 2012-08-08 00:12:01 -07:00 committed by Android Git Automerger
commit 260250fb80
2 changed files with 11 additions and 12 deletions

View File

@ -517,7 +517,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
/* package private */ void resetSuggestMainDict() { /* package private */ void resetSuggestMainDict() {
final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
mSuggest.resetMainDict(this, subtypeLocale); mSuggest.resetMainDict(this, subtypeLocale, this /* SuggestInitializationListener */);
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
} }

View File

@ -60,13 +60,11 @@ public class Suggest {
// Locale used for upper- and title-casing words // Locale used for upper- and title-casing words
private final Locale mLocale; private final Locale mLocale;
private final SuggestInitializationListener mListener;
public Suggest(final Context context, final Locale locale, public Suggest(final Context context, final Locale locale,
final SuggestInitializationListener listener) { final SuggestInitializationListener listener) {
initAsynchronously(context, locale); initAsynchronously(context, locale, listener);
mLocale = locale; mLocale = locale;
mListener = listener;
} }
/* package for test */ Suggest(final Context context, final File dictionary, /* package for test */ Suggest(final Context context, final File dictionary,
@ -74,7 +72,6 @@ public class Suggest {
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary, final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary,
startOffset, length /* useFullEditDistance */, false, locale); startOffset, length /* useFullEditDistance */, false, locale);
mLocale = locale; mLocale = locale;
mListener = null;
mMainDictionary = mainDict; mMainDictionary = mainDict;
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict);
initWhitelistAndAutocorrectAndPool(context, locale); initWhitelistAndAutocorrectAndPool(context, locale);
@ -85,8 +82,9 @@ public class Suggest {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_WHITELIST, mWhiteListDictionary); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_WHITELIST, mWhiteListDictionary);
} }
private void initAsynchronously(final Context context, final Locale locale) { private void initAsynchronously(final Context context, final Locale locale,
resetMainDict(context, locale); final SuggestInitializationListener listener) {
resetMainDict(context, locale, listener);
// TODO: read the whitelist and init the pool asynchronously too. // TODO: read the whitelist and init the pool asynchronously too.
// initPool should be done asynchronously now that the pool is thread-safe. // initPool should be done asynchronously now that the pool is thread-safe.
@ -104,10 +102,11 @@ public class Suggest {
} }
} }
public void resetMainDict(final Context context, final Locale locale) { public void resetMainDict(final Context context, final Locale locale,
final SuggestInitializationListener listener) {
mMainDictionary = null; mMainDictionary = null;
if (mListener != null) { if (listener != null) {
mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); listener.onUpdateMainDictionaryAvailability(hasMainDictionary());
} }
new Thread("InitializeBinaryDictionary") { new Thread("InitializeBinaryDictionary") {
@Override @Override
@ -116,8 +115,8 @@ public class Suggest {
DictionaryFactory.createMainDictionaryFromManager(context, locale); DictionaryFactory.createMainDictionaryFromManager(context, locale);
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict);
mMainDictionary = newMainDict; mMainDictionary = newMainDict;
if (mListener != null) { if (listener != null) {
mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); listener.onUpdateMainDictionaryAvailability(hasMainDictionary());
} }
} }
}.start(); }.start();