From d7a22c8439c77f2bf81b5dc60d58cf65d129da81 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Fri, 13 Jun 2014 16:31:12 +0900 Subject: [PATCH] Personalization dictionary updater. Bug: 14161647 Change-Id: I7ab3d701525e9a19bc100aa577527e332bb2ad95 --- .../android/inputmethod/latin/LatinIME.java | 33 +++++++++---------- ... => PersonalizationDictionaryUpdater.java} | 27 ++++++++------- 2 files changed, 28 insertions(+), 32 deletions(-) rename java/src/com/android/inputmethod/latin/personalization/{PersonalizationDictionarySessionRegistrar.java => PersonalizationDictionaryUpdater.java} (55%) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8b671a94b..b0774c49d 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -70,7 +70,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.inputlogic.InputLogic; import com.android.inputmethod.latin.personalization.DictionaryDecayBroadcastReciever; -import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegistrar; +import com.android.inputmethod.latin.personalization.PersonalizationDictionaryUpdater; import com.android.inputmethod.latin.personalization.PersonalizationHelper; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.SettingsActivity; @@ -122,6 +122,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private final Settings mSettings; private final DictionaryFacilitator mDictionaryFacilitator = new DictionaryFacilitator(new DistracterFilterCheckingExactMatches(this /* context */)); + // TODO: Move from LatinIME. + private final PersonalizationDictionaryUpdater mPersonalizationDictionaryUpdater = + new PersonalizationDictionaryUpdater(this /* context */, mDictionaryFacilitator); private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */, this /* SuggestionStripViewAccessor */, mDictionaryFacilitator); // We expect to have only one decoder in almost all cases, hence the default capacity of 1. @@ -540,34 +543,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList( true /* allowsImplicitlySelectedSubtypes */)); - refreshPersonalizationDictionarySession(); + refreshPersonalizationDictionarySession(currentSettingsValues); StatsUtils.onLoadSettings(currentSettingsValues); } - private void refreshPersonalizationDictionarySession() { + private void refreshPersonalizationDictionarySession( + final SettingsValues currentSettingsValues) { + mPersonalizationDictionaryUpdater.onLoadSettings( + currentSettingsValues.mUsePersonalizedDicts, + mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes()); final boolean shouldKeepUserHistoryDictionaries; - final boolean shouldKeepPersonalizationDictionaries; if (mSettings.getCurrent().mUsePersonalizedDicts) { shouldKeepUserHistoryDictionaries = true; - // TODO: Eliminate this restriction - shouldKeepPersonalizationDictionaries = - mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes(); } else { shouldKeepUserHistoryDictionaries = false; - shouldKeepPersonalizationDictionaries = false; } if (!shouldKeepUserHistoryDictionaries) { // Remove user history dictionaries. PersonalizationHelper.removeAllUserHistoryDictionaries(this); mDictionaryFacilitator.clearUserHistoryDictionary(); } - if (!shouldKeepPersonalizationDictionaries) { - // Remove personalization dictionaries. - PersonalizationHelper.removeAllPersonalizationDictionaries(this); - PersonalizationDictionarySessionRegistrar.resetAll(this); - } else { - PersonalizationDictionarySessionRegistrar.init(this, mDictionaryFacilitator); - } } // Note that this method is called from a non-UI thread. @@ -627,11 +622,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onDestroy() { mDictionaryFacilitator.closeDictionaries(); + mPersonalizationDictionaryUpdater.onDestroy(); mSettings.onDestroy(); unregisterReceiver(mConnectivityAndRingerModeChangeReceiver); unregisterReceiver(mDictionaryPackInstallReceiver); unregisterReceiver(mDictionaryDumpBroadcastReceiver); - PersonalizationDictionarySessionRegistrar.close(this); StatsUtils.onDestroy(); super.onDestroy(); } @@ -660,8 +655,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.mConnection.endBatchEdit(); } } - PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf, - mDictionaryFacilitator); + // TODO: Remove this test. + if (!conf.locale.equals(mPersonalizationDictionaryUpdater.getLocale())) { + refreshPersonalizationDictionarySession(settingsValues); + } super.onConfigurationChanged(conf); } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java similarity index 55% rename from java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java rename to java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java index 450644032..07bcf98cb 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,29 +16,28 @@ package com.android.inputmethod.latin.personalization; +import java.util.Locale; + import android.content.Context; -import android.content.res.Configuration; import com.android.inputmethod.latin.DictionaryFacilitator; -public class PersonalizationDictionarySessionRegistrar { - public static void init(final Context context, +public class PersonalizationDictionaryUpdater { + public PersonalizationDictionaryUpdater(final Context context, final DictionaryFacilitator dictionaryFacilitator) { + // Clear and never update the personalization dictionary. + PersonalizationHelper.removeAllPersonalizationDictionaries(context); + dictionaryFacilitator.clearPersonalizationDictionary(); } - public static void onConfigurationChanged(final Context context, final Configuration conf, - final DictionaryFacilitator dictionaryFacilitator) { + public Locale getLocale() { + return null; } - public static void onUpdateData(final Context context, final String type) { + public void onLoadSettings(final boolean usePersonalizedDicts, + final boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes) { } - public static void onRemoveData(final Context context, final String type) { - } - - public static void resetAll(final Context context) { - } - - public static void close(final Context context) { + public void onDestroy() { } }