aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
diff options
context:
space:
mode:
authorJatin Matani <jatinm@google.com>2014-10-23 17:50:35 -0700
committerJatin Matani <jatinm@google.com>2014-11-13 14:21:38 -0800
commit5365191a9d850362f41eedf3f95adb5c80cceb8f (patch)
treebc518473448b34fc635af0600d28dfefc3e36b62 /java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
parentb050b458dc1eac06412d116d6b57b849d3ccb06d (diff)
downloadlatinime-5365191a9d850362f41eedf3f95adb5c80cceb8f.tar.gz
latinime-5365191a9d850362f41eedf3f95adb5c80cceb8f.tar.xz
latinime-5365191a9d850362f41eedf3f95adb5c80cceb8f.zip
Implement UserHistoryDictionary for each user account.
UserHistoryDictionary currently uses locale to determine the UserHistoryDictionary on the filesystem. With this change we use the account name as well. Thus each UserHistoryDictionary would following the following spec: UserHistoryDictionary.<locale>.<account>.dict. In case no account is selected, we default to the existing spec: UserHistoryDictionary.<locale>.dict Example UserHistoryDictionary.en_US.testaccount@example.com.dict Bug: 18104749 Change-Id: Iab031e166b55cf2ded68275a7e9be22475737b37
Diffstat (limited to 'java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java60
1 files changed, 55 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
index 58782c646..946835cbc 100644
--- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
@@ -17,30 +17,73 @@
package com.android.inputmethod.latin.personalization;
import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
import com.android.inputmethod.annotations.ExternallyReferenced;
+import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.define.ProductionFlags;
+import com.android.inputmethod.latin.settings.LocalSettingsConstants;
import com.android.inputmethod.latin.utils.DistracterFilter;
import java.io.File;
import java.util.Locale;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* Locally gathers stats about the words user types and various other signals like auto-correction
* cancellation or manual picks. This allows the keyboard to adapt to the typist over time.
*/
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
- /* package */ static final String NAME = UserHistoryDictionary.class.getSimpleName();
+ static final String NAME = UserHistoryDictionary.class.getSimpleName();
// TODO: Make this constructor private
- /* package */ UserHistoryDictionary(final Context context, final Locale locale) {
- super(context, getDictName(NAME, locale, null /* dictFile */), locale,
- Dictionary.TYPE_USER_HISTORY, null /* dictFile */);
+ UserHistoryDictionary(final Context context, final Locale locale) {
+ super(context,
+ getUserHistoryDictName(
+ NAME,
+ locale,
+ null /* dictFile */,
+ context),
+ locale,
+ Dictionary.TYPE_USER_HISTORY,
+ null /* dictFile */);
+ }
+
+ /**
+ * @returns the name of the {@link UserHistoryDictionary}.
+ */
+ @UsedForTesting
+ static String getUserHistoryDictName(final String name, final Locale locale,
+ @Nullable final File dictFile, final Context context) {
+ if (!ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) {
+ return getDictName(name, locale, dictFile);
+ }
+ return getUserHistoryDictNamePerAccount(name, locale, dictFile, context);
+ }
+
+ /**
+ * Uses the currently signed in account to determine the dictionary name.
+ */
+ private static String getUserHistoryDictNamePerAccount(final String name, final Locale locale,
+ @Nullable final File dictFile, final Context context) {
+ if (dictFile != null) {
+ return dictFile.getName();
+ }
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ final String account = prefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME,
+ null /* default */);
+ String dictName = name + "." + locale.toString();
+ if (account != null) {
+ dictName += "." + account;
+ }
+ return dictName;
}
// Note: This method is called by {@link DictionaryFacilitator} using Java reflection.
@@ -48,7 +91,14 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
@ExternallyReferenced
public static UserHistoryDictionary getDictionary(final Context context, final Locale locale,
final File dictFile, final String dictNamePrefix) {
- return PersonalizationHelper.getUserHistoryDictionary(context, locale);
+ final String account;
+ if (ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) {
+ account = PreferenceManager.getDefaultSharedPreferences(context)
+ .getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null /* default */);
+ } else {
+ account = null;
+ }
+ return PersonalizationHelper.getUserHistoryDictionary(context, locale, account);
}
/**