Personalization dictionary updater.
Bug: 14161647
Change-Id: I7ab3d701525e9a19bc100aa577527e332bb2ad95
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 8b671a9..b0774c4 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.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 @@
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 @@
}
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 @@
@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 @@
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/PersonalizationDictionarySessionRegistrar.java
deleted file mode 100644
index 4506440..0000000
--- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.personalization;
-
-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,
- final DictionaryFacilitator dictionaryFacilitator) {
- }
-
- public static void onConfigurationChanged(final Context context, final Configuration conf,
- final DictionaryFacilitator dictionaryFacilitator) {
- }
-
- public static void onUpdateData(final Context context, final String type) {
- }
-
- public static void onRemoveData(final Context context, final String type) {
- }
-
- public static void resetAll(final Context context) {
- }
-
- public static void close(final Context context) {
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java
new file mode 100644
index 0000000..07bcf98
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryUpdater.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.personalization;
+
+import java.util.Locale;
+
+import android.content.Context;
+
+import com.android.inputmethod.latin.DictionaryFacilitator;
+
+public class PersonalizationDictionaryUpdater {
+ public PersonalizationDictionaryUpdater(final Context context,
+ final DictionaryFacilitator dictionaryFacilitator) {
+ // Clear and never update the personalization dictionary.
+ PersonalizationHelper.removeAllPersonalizationDictionaries(context);
+ dictionaryFacilitator.clearPersonalizationDictionary();
+ }
+
+ public Locale getLocale() {
+ return null;
+ }
+
+ public void onLoadSettings(final boolean usePersonalizedDicts,
+ final boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes) {
+ }
+
+ public void onDestroy() {
+ }
+}