From 79eefda0d3ab5e03c2d012ed8ea1898004781871 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 8 Aug 2012 15:55:26 +0900 Subject: [PATCH] Add SuggestInitializationListener to BinaryDictionary.resetMainDict() Change-Id: I4c01f172ddb2ca60fa6e604384610c90b76e5457 --- .../android/inputmethod/latin/LatinIME.java | 2 +- .../android/inputmethod/latin/Suggest.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 455086015..43901bab4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -517,7 +517,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen /* package private */ void resetSuggestMainDict() { final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); - mSuggest.resetMainDict(this, subtypeLocale); + mSuggest.resetMainDict(this, subtypeLocale, this /* SuggestInitializationListener */); mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 5e2a04124..a65d36adb 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -60,13 +60,11 @@ public class Suggest { // Locale used for upper- and title-casing words private final Locale mLocale; - private final SuggestInitializationListener mListener; public Suggest(final Context context, final Locale locale, final SuggestInitializationListener listener) { - initAsynchronously(context, locale); + initAsynchronously(context, locale, listener); mLocale = locale; - mListener = listener; } /* package for test */ Suggest(final Context context, final File dictionary, @@ -74,7 +72,6 @@ public class Suggest { final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary, startOffset, length /* useFullEditDistance */, false, locale); mLocale = locale; - mListener = null; mMainDictionary = mainDict; addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); initWhitelistAndAutocorrectAndPool(context, locale); @@ -85,8 +82,9 @@ public class Suggest { addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_WHITELIST, mWhiteListDictionary); } - private void initAsynchronously(final Context context, final Locale locale) { - resetMainDict(context, locale); + private void initAsynchronously(final Context context, final Locale locale, + final SuggestInitializationListener listener) { + resetMainDict(context, locale, listener); // TODO: read the whitelist and init the pool asynchronously too. // 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; - if (mListener != null) { - mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); + if (listener != null) { + listener.onUpdateMainDictionaryAvailability(hasMainDictionary()); } new Thread("InitializeBinaryDictionary") { @Override @@ -116,8 +115,8 @@ public class Suggest { DictionaryFactory.createMainDictionaryFromManager(context, locale); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict); mMainDictionary = newMainDict; - if (mListener != null) { - mListener.onUpdateMainDictionaryAvailability(hasMainDictionary()); + if (listener != null) { + listener.onUpdateMainDictionaryAvailability(hasMainDictionary()); } } }.start();