diff options
author | 2014-11-14 00:46:36 +0000 | |
---|---|---|
committer | 2014-11-14 00:46:37 +0000 | |
commit | d60f9c046e6e0ce8d3b04f93506f553f22af6240 (patch) | |
tree | cb007e562a82d80b018007eb038f7eaa4843af87 /java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java | |
parent | 80c4e0f68a1c7444f3394df8c15f53c420b99792 (diff) | |
parent | 5365191a9d850362f41eedf3f95adb5c80cceb8f (diff) | |
download | latinime-d60f9c046e6e0ce8d3b04f93506f553f22af6240.tar.gz latinime-d60f9c046e6e0ce8d3b04f93506f553f22af6240.tar.xz latinime-d60f9c046e6e0ce8d3b04f93506f553f22af6240.zip |
Merge "Implement UserHistoryDictionary for each user account."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java | 60 |
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); } /** |