am 96f0ae5e: [ML6] Have asyncReloadMainDictionary support multiple locales

* commit '96f0ae5e68a865d390e3623eebe0fda30c3a62a8':
  [ML6] Have asyncReloadMainDictionary support multiple locales
main
Jean Chalard 2014-09-11 10:44:50 +00:00 committed by Android Git Automerger
commit decce7ff27
1 changed files with 14 additions and 11 deletions

View File

@ -309,7 +309,7 @@ public class DictionaryFacilitator {
mDictionaryGroup = newDictionaryGroup; mDictionaryGroup = newDictionaryGroup;
mIsUserDictEnabled = UserBinaryDictionary.isEnabled(context); mIsUserDictEnabled = UserBinaryDictionary.isEnabled(context);
if (null == newDictionaryGroup.getDict(Dictionary.TYPE_MAIN)) { if (null == newDictionaryGroup.getDict(Dictionary.TYPE_MAIN)) {
asyncReloadMainDictionary(context, newLocaleToUse, listener); asyncReloadUninitializedMainDictionaries(context, newLocales, listener);
} }
} }
if (listener != null) { if (listener != null) {
@ -327,23 +327,26 @@ public class DictionaryFacilitator {
} }
} }
private void asyncReloadMainDictionary(final Context context, final Locale locale, private void asyncReloadUninitializedMainDictionaries(final Context context,
final DictionaryInitializationListener listener) { final Locale[] locales, final DictionaryInitializationListener listener) {
final CountDownLatch latchForWaitingLoadingMainDictionary = new CountDownLatch(1); final CountDownLatch latchForWaitingLoadingMainDictionary = new CountDownLatch(1);
mLatchForWaitingLoadingMainDictionary = latchForWaitingLoadingMainDictionary; mLatchForWaitingLoadingMainDictionary = latchForWaitingLoadingMainDictionary;
ExecutorUtils.getExecutor("InitializeBinaryDictionary").execute(new Runnable() { ExecutorUtils.getExecutor("InitializeBinaryDictionary").execute(new Runnable() {
@Override @Override
public void run() { public void run() {
for (final Locale locale : locales) {
final DictionaryGroup dictionaryGroup = mDictionaryGroup;
final Dictionary mainDict = final Dictionary mainDict =
DictionaryFactory.createMainDictionaryFromManager(context, locale); DictionaryFactory.createMainDictionaryFromManager(context, locale);
synchronized (mLock) { synchronized (mLock) {
if (locale.equals(mDictionaryGroup.mLocale)) { if (locale.equals(dictionaryGroup.mLocale)) {
mDictionaryGroup.setMainDict(mainDict); dictionaryGroup.setMainDict(mainDict);
} else { } else {
// Dictionary facilitator has been reset for another locale. // Dictionary facilitator has been reset for another locale.
mainDict.close(); mainDict.close();
} }
} }
}
if (listener != null) { if (listener != null) {
listener.onUpdateMainDictionaryAvailability(hasInitializedMainDictionary()); listener.onUpdateMainDictionaryAvailability(hasInitializedMainDictionary());
} }