Merge "Quit recording LastUserHistoryWriteTime."
This commit is contained in:
commit
545e4191b3
10 changed files with 34 additions and 169 deletions
|
@ -53,6 +53,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
|
|
||||||
/** Whether to print debug output to log */
|
/** Whether to print debug output to log */
|
||||||
private static boolean DEBUG = false;
|
private static boolean DEBUG = false;
|
||||||
|
private static final boolean DBG_STRESS_TEST = false;
|
||||||
|
|
||||||
private static final int TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS = 100;
|
private static final int TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS = 100;
|
||||||
|
|
||||||
|
@ -496,6 +497,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
+ mFilenameDictionaryUpdateController.mLastUpdateRequestTime + " update="
|
+ mFilenameDictionaryUpdateController.mLastUpdateRequestTime + " update="
|
||||||
+ mFilenameDictionaryUpdateController.mLastUpdateTime);
|
+ mFilenameDictionaryUpdateController.mLastUpdateTime);
|
||||||
}
|
}
|
||||||
|
if (DBG_STRESS_TEST) {
|
||||||
|
// Test if this class does not cause problems when it takes long time to load binary
|
||||||
|
// dictionary.
|
||||||
|
try {
|
||||||
|
Log.w(TAG, "Start stress in loading: " + mFilename);
|
||||||
|
Thread.sleep(15000);
|
||||||
|
Log.w(TAG, "End stress in loading");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final File file = new File(mContext.getFilesDir(), mFilename
|
final File file = new File(mContext.getFilesDir(), mFilename
|
||||||
+ getFileNameExtentionToOpenDict());
|
+ getFileNameExtentionToOpenDict());
|
||||||
|
|
|
@ -649,14 +649,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(
|
mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(this, localeStr);
|
||||||
this, localeStr, prefs);
|
|
||||||
newSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
|
newSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
|
||||||
mPersonalizationDictionary = PersonalizationHelper
|
mPersonalizationDictionary =
|
||||||
.getPersonalizationDictionary(this, localeStr, prefs);
|
PersonalizationHelper.getPersonalizationDictionary(this, localeStr);
|
||||||
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
|
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
|
||||||
mPersonalizationPredictionDictionary = PersonalizationHelper
|
mPersonalizationPredictionDictionary =
|
||||||
.getPersonalizationPredictionDictionary(this, localeStr, prefs);
|
PersonalizationHelper.getPersonalizationPredictionDictionary(this, localeStr);
|
||||||
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);
|
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);
|
||||||
|
|
||||||
final Suggest oldSuggest = mSuggest;
|
final Suggest oldSuggest = mSuggest;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package com.android.inputmethod.latin.personalization;
|
package com.android.inputmethod.latin.personalization;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
@ -25,11 +24,9 @@ import com.android.inputmethod.latin.BinaryDictionary.LanguageModelParam;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.Dictionary;
|
import com.android.inputmethod.latin.Dictionary;
|
||||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
|
||||||
import com.android.inputmethod.latin.makedict.DictDecoder;
|
import com.android.inputmethod.latin.makedict.DictDecoder;
|
||||||
import com.android.inputmethod.latin.makedict.FormatSpec;
|
import com.android.inputmethod.latin.makedict.FormatSpec;
|
||||||
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
|
||||||
import com.android.inputmethod.latin.utils.CollectionUtils;
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils;
|
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils;
|
||||||
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener;
|
import com.android.inputmethod.latin.utils.UserHistoryDictIOUtils.OnAddWordListener;
|
||||||
|
@ -47,9 +44,7 @@ import java.util.Map;
|
||||||
public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableBinaryDictionary {
|
public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableBinaryDictionary {
|
||||||
private static final String TAG = DecayingExpandableBinaryDictionaryBase.class.getSimpleName();
|
private static final String TAG = DecayingExpandableBinaryDictionaryBase.class.getSimpleName();
|
||||||
public static final boolean DBG_SAVE_RESTORE = false;
|
public static final boolean DBG_SAVE_RESTORE = false;
|
||||||
private static final boolean DBG_STRESS_TEST = false;
|
|
||||||
private static final boolean DBG_DUMP_ON_CLOSE = false;
|
private static final boolean DBG_DUMP_ON_CLOSE = false;
|
||||||
private static final boolean PROFILE_SAVE_RESTORE = LatinImeLogger.sDBG;
|
|
||||||
|
|
||||||
/** Any pair being typed or picked */
|
/** Any pair being typed or picked */
|
||||||
public static final int FREQUENCY_FOR_TYPED = 2;
|
public static final int FREQUENCY_FOR_TYPED = 2;
|
||||||
|
@ -64,8 +59,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
|
|
||||||
private final String mFileName;
|
private final String mFileName;
|
||||||
|
|
||||||
private final SharedPreferences mPrefs;
|
|
||||||
|
|
||||||
private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions =
|
private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions =
|
||||||
CollectionUtils.newArrayList();
|
CollectionUtils.newArrayList();
|
||||||
|
|
||||||
|
@ -73,12 +66,10 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
@UsedForTesting boolean mIsTest = false;
|
@UsedForTesting boolean mIsTest = false;
|
||||||
|
|
||||||
/* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
|
/* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
|
||||||
final String locale, final SharedPreferences sp, final String dictionaryType,
|
final String locale, final String dictionaryType, final String fileName) {
|
||||||
final String fileName) {
|
|
||||||
super(context, fileName, dictionaryType, true);
|
super(context, fileName, dictionaryType, true);
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mFileName = fileName;
|
mFileName = fileName;
|
||||||
mPrefs = sp;
|
|
||||||
if (mLocale != null && mLocale.length() > 1) {
|
if (mLocale != null && mLocale.length() > 1) {
|
||||||
reloadDictionaryIfRequired();
|
reloadDictionaryIfRequired();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +83,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
// Flush pending writes.
|
// Flush pending writes.
|
||||||
// TODO: Remove after this class become to use a dynamic binary dictionary.
|
// TODO: Remove after this class become to use a dynamic binary dictionary.
|
||||||
asyncFlashAllBinaryDictionary();
|
asyncFlashAllBinaryDictionary();
|
||||||
Settings.writeLastUserHistoryWriteTime(mPrefs, mLocale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,67 +161,7 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadDictionaryAsync() {
|
protected void loadDictionaryAsync() {
|
||||||
final int[] profTotalCount = { 0 };
|
// Never loaded to memory in Java side.
|
||||||
final String locale = getLocale();
|
|
||||||
if (DBG_STRESS_TEST) {
|
|
||||||
try {
|
|
||||||
Log.w(TAG, "Start stress in loading: " + locale);
|
|
||||||
Thread.sleep(15000);
|
|
||||||
Log.w(TAG, "End stress in loading");
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final long last = Settings.readLastUserHistoryWriteTime(mPrefs, locale);
|
|
||||||
final long now = System.currentTimeMillis();
|
|
||||||
final ExpandableBinaryDictionary dictionary = this;
|
|
||||||
final OnAddWordListener listener = new OnAddWordListener() {
|
|
||||||
@Override
|
|
||||||
public void setUnigram(final String word, final String shortcutTarget,
|
|
||||||
final int frequency, final int shortcutFreq) {
|
|
||||||
if (DBG_SAVE_RESTORE) {
|
|
||||||
Log.d(TAG, "load unigram: " + word + "," + frequency);
|
|
||||||
}
|
|
||||||
addWord(word, shortcutTarget, frequency, shortcutFreq, false /* isNotAWord */);
|
|
||||||
++profTotalCount[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBigram(final String word0, final String word1, final int frequency) {
|
|
||||||
if (word0.length() < Constants.DICTIONARY_MAX_WORD_LENGTH
|
|
||||||
&& word1.length() < Constants.DICTIONARY_MAX_WORD_LENGTH) {
|
|
||||||
if (DBG_SAVE_RESTORE) {
|
|
||||||
Log.d(TAG, "load bigram: " + word0 + "," + word1 + "," + frequency);
|
|
||||||
}
|
|
||||||
++profTotalCount[0];
|
|
||||||
addBigram(word0, word1, frequency, last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load the dictionary from binary file
|
|
||||||
final File dictFile = new File(mContext.getFilesDir(), mFileName);
|
|
||||||
final DictDecoder dictDecoder = FormatSpec.getDictDecoder(dictFile,
|
|
||||||
DictDecoder.USE_BYTEARRAY);
|
|
||||||
if (dictDecoder == null) {
|
|
||||||
// This is an expected condition: we don't have a user history dictionary for this
|
|
||||||
// language yet. It will be created sometime later.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
dictDecoder.openDictBuffer();
|
|
||||||
UserHistoryDictIOUtils.readDictionaryBinary(dictDecoder, listener);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "IOException on opening a bytebuffer", e);
|
|
||||||
} catch (UnsupportedFormatException e) {
|
|
||||||
Log.d(TAG, "Unsupported format, can't read the dictionary", e);
|
|
||||||
} finally {
|
|
||||||
if (PROFILE_SAVE_RESTORE) {
|
|
||||||
final long diff = System.currentTimeMillis() - now;
|
|
||||||
Log.d(TAG, "PROF: Load UserHistoryDictionary: "
|
|
||||||
+ locale + ", " + diff + "ms. load " + profTotalCount[0] + "entries.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getLocale() {
|
protected String getLocale() {
|
||||||
|
|
|
@ -36,8 +36,7 @@ public class PersonalizationDictionary extends ExpandableBinaryDictionary {
|
||||||
/** Locale for which this user history dictionary is storing words */
|
/** Locale for which this user history dictionary is storing words */
|
||||||
private final String mLocale;
|
private final String mLocale;
|
||||||
|
|
||||||
public PersonalizationDictionary(final Context context, final String locale,
|
public PersonalizationDictionary(final Context context, final String locale) {
|
||||||
final SharedPreferences prefs) {
|
|
||||||
// TODO: Make isUpdatable true.
|
// TODO: Make isUpdatable true.
|
||||||
super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_PERSONALIZATION,
|
super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_PERSONALIZATION,
|
||||||
false /* isUpdatable */);
|
false /* isUpdatable */);
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class PersonalizationHelper {
|
||||||
CollectionUtils.newConcurrentHashMap();
|
CollectionUtils.newConcurrentHashMap();
|
||||||
|
|
||||||
public static UserHistoryDictionary getUserHistoryDictionary(
|
public static UserHistoryDictionary getUserHistoryDictionary(
|
||||||
final Context context, final String locale, final SharedPreferences sp) {
|
final Context context, final String locale) {
|
||||||
synchronized (sLangUserHistoryDictCache) {
|
synchronized (sLangUserHistoryDictCache) {
|
||||||
if (sLangUserHistoryDictCache.containsKey(locale)) {
|
if (sLangUserHistoryDictCache.containsKey(locale)) {
|
||||||
final SoftReference<UserHistoryDictionary> ref =
|
final SoftReference<UserHistoryDictionary> ref =
|
||||||
|
@ -55,7 +55,7 @@ public class PersonalizationHelper {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale, sp);
|
final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale);
|
||||||
sLangUserHistoryDictCache.put(locale, new SoftReference<UserHistoryDictionary>(dict));
|
sLangUserHistoryDictCache.put(locale, new SoftReference<UserHistoryDictionary>(dict));
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
@ -76,17 +76,14 @@ public class PersonalizationHelper {
|
||||||
public static void registerPersonalizationDictionaryUpdateSession(final Context context,
|
public static void registerPersonalizationDictionaryUpdateSession(final Context context,
|
||||||
final PersonalizationDictionaryUpdateSession session, String locale) {
|
final PersonalizationDictionaryUpdateSession session, String locale) {
|
||||||
final PersonalizationPredictionDictionary predictionDictionary =
|
final PersonalizationPredictionDictionary predictionDictionary =
|
||||||
getPersonalizationPredictionDictionary(context, locale,
|
getPersonalizationPredictionDictionary(context, locale);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context));
|
|
||||||
predictionDictionary.registerUpdateSession(session);
|
predictionDictionary.registerUpdateSession(session);
|
||||||
final PersonalizationDictionary dictionary =
|
final PersonalizationDictionary dictionary = getPersonalizationDictionary(context, locale);
|
||||||
getPersonalizationDictionary(context, locale,
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context));
|
|
||||||
dictionary.registerUpdateSession(session);
|
dictionary.registerUpdateSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PersonalizationDictionary getPersonalizationDictionary(
|
public static PersonalizationDictionary getPersonalizationDictionary(
|
||||||
final Context context, final String locale, final SharedPreferences sp) {
|
final Context context, final String locale) {
|
||||||
synchronized (sLangPersonalizationDictCache) {
|
synchronized (sLangPersonalizationDictCache) {
|
||||||
if (sLangPersonalizationDictCache.containsKey(locale)) {
|
if (sLangPersonalizationDictCache.containsKey(locale)) {
|
||||||
final SoftReference<PersonalizationDictionary> ref =
|
final SoftReference<PersonalizationDictionary> ref =
|
||||||
|
@ -99,8 +96,7 @@ public class PersonalizationHelper {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final PersonalizationDictionary dict =
|
final PersonalizationDictionary dict = new PersonalizationDictionary(context, locale);
|
||||||
new PersonalizationDictionary(context, locale, sp);
|
|
||||||
sLangPersonalizationDictCache.put(
|
sLangPersonalizationDictCache.put(
|
||||||
locale, new SoftReference<PersonalizationDictionary>(dict));
|
locale, new SoftReference<PersonalizationDictionary>(dict));
|
||||||
return dict;
|
return dict;
|
||||||
|
@ -108,7 +104,7 @@ public class PersonalizationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(
|
public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(
|
||||||
final Context context, final String locale, final SharedPreferences sp) {
|
final Context context, final String locale) {
|
||||||
synchronized (sLangPersonalizationPredictionDictCache) {
|
synchronized (sLangPersonalizationPredictionDictCache) {
|
||||||
if (sLangPersonalizationPredictionDictCache.containsKey(locale)) {
|
if (sLangPersonalizationPredictionDictCache.containsKey(locale)) {
|
||||||
final SoftReference<PersonalizationPredictionDictionary> ref =
|
final SoftReference<PersonalizationPredictionDictionary> ref =
|
||||||
|
@ -122,7 +118,7 @@ public class PersonalizationHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final PersonalizationPredictionDictionary dict =
|
final PersonalizationPredictionDictionary dict =
|
||||||
new PersonalizationPredictionDictionary(context, locale, sp);
|
new PersonalizationPredictionDictionary(context, locale);
|
||||||
sLangPersonalizationPredictionDictCache.put(
|
sLangPersonalizationPredictionDictCache.put(
|
||||||
locale, new SoftReference<PersonalizationPredictionDictionary>(dict));
|
locale, new SoftReference<PersonalizationPredictionDictionary>(dict));
|
||||||
return dict;
|
return dict;
|
||||||
|
|
|
@ -20,14 +20,12 @@ import com.android.inputmethod.latin.Dictionary;
|
||||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase {
|
public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase {
|
||||||
private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName();
|
private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName();
|
||||||
|
|
||||||
/* package */ PersonalizationPredictionDictionary(final Context context, final String locale,
|
/* package */ PersonalizationPredictionDictionary(final Context context, final String locale) {
|
||||||
final SharedPreferences sp) {
|
super(context, locale, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA,
|
||||||
super(context, locale, sp, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA,
|
|
||||||
getDictionaryFileName(locale));
|
getDictionaryFileName(locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import com.android.inputmethod.latin.Dictionary;
|
||||||
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locally gathers stats about the words user types and various other signals like auto-correction
|
* Locally gathers stats about the words user types and various other signals like auto-correction
|
||||||
|
@ -29,9 +28,8 @@ import android.content.SharedPreferences;
|
||||||
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
|
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
|
||||||
/* package for tests */ static final String NAME =
|
/* package for tests */ static final String NAME =
|
||||||
UserHistoryDictionary.class.getSimpleName();
|
UserHistoryDictionary.class.getSimpleName();
|
||||||
/* package */ UserHistoryDictionary(final Context context, final String locale,
|
/* package */ UserHistoryDictionary(final Context context, final String locale) {
|
||||||
final SharedPreferences sp) {
|
super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictionaryFileName(locale));
|
||||||
super(context, locale, sp, Dictionary.TYPE_USER_HISTORY, getDictionaryFileName(locale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDictionaryFileName(final String locale) {
|
private static String getDictionaryFileName(final String locale) {
|
||||||
|
|
|
@ -53,8 +53,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold";
|
public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold";
|
||||||
public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting";
|
public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting";
|
||||||
public static final String PREF_MISC_SETTINGS = "misc_settings";
|
public static final String PREF_MISC_SETTINGS = "misc_settings";
|
||||||
public static final String PREF_LAST_USER_DICTIONARY_WRITE_TIME =
|
|
||||||
"last_user_dictionary_write_time";
|
|
||||||
public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings";
|
public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings";
|
||||||
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
|
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
|
||||||
public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD =
|
public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD =
|
||||||
|
@ -333,25 +331,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
return prefs.getBoolean(DebugSettings.PREF_USABILITY_STUDY_MODE, true);
|
return prefs.getBoolean(DebugSettings.PREF_USABILITY_STUDY_MODE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long readLastUserHistoryWriteTime(final SharedPreferences prefs,
|
|
||||||
final String locale) {
|
|
||||||
final String str = prefs.getString(PREF_LAST_USER_DICTIONARY_WRITE_TIME, "");
|
|
||||||
final HashMap<String, Long> map = LocaleUtils.localeAndTimeStrToHashMap(str);
|
|
||||||
if (map.containsKey(locale)) {
|
|
||||||
return map.get(locale);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeLastUserHistoryWriteTime(final SharedPreferences prefs,
|
|
||||||
final String locale) {
|
|
||||||
final String oldStr = prefs.getString(PREF_LAST_USER_DICTIONARY_WRITE_TIME, "");
|
|
||||||
final HashMap<String, Long> map = LocaleUtils.localeAndTimeStrToHashMap(oldStr);
|
|
||||||
map.put(locale, System.currentTimeMillis());
|
|
||||||
final String newStr = LocaleUtils.localeAndTimeHashMapToStr(map);
|
|
||||||
prefs.edit().putString(PREF_LAST_USER_DICTIONARY_WRITE_TIME, newStr).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean readUseFullscreenMode(final Resources res) {
|
public static boolean readUseFullscreenMode(final Resources res) {
|
||||||
return res.getBoolean(R.bool.config_use_fullscreen_mode);
|
return res.getBoolean(R.bool.config_use_fullscreen_mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,6 @@ import java.util.Locale;
|
||||||
* dictionary pack.
|
* dictionary pack.
|
||||||
*/
|
*/
|
||||||
public final class LocaleUtils {
|
public final class LocaleUtils {
|
||||||
private static final HashMap<String, Long> EMPTY_LT_HASH_MAP = CollectionUtils.newHashMap();
|
|
||||||
private static final String LOCALE_AND_TIME_STR_SEPARATER = ",";
|
|
||||||
|
|
||||||
private LocaleUtils() {
|
private LocaleUtils() {
|
||||||
// Intentional empty constructor for utility class.
|
// Intentional empty constructor for utility class.
|
||||||
}
|
}
|
||||||
|
@ -188,38 +185,4 @@ public final class LocaleUtils {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, Long> localeAndTimeStrToHashMap(String str) {
|
|
||||||
if (TextUtils.isEmpty(str)) {
|
|
||||||
return EMPTY_LT_HASH_MAP;
|
|
||||||
}
|
|
||||||
final String[] ss = str.split(LOCALE_AND_TIME_STR_SEPARATER);
|
|
||||||
final int N = ss.length;
|
|
||||||
if (N < 2 || N % 2 != 0) {
|
|
||||||
return EMPTY_LT_HASH_MAP;
|
|
||||||
}
|
|
||||||
final HashMap<String, Long> retval = CollectionUtils.newHashMap();
|
|
||||||
for (int i = 0; i < N / 2; ++i) {
|
|
||||||
final String localeStr = ss[i * 2];
|
|
||||||
final long time = Long.valueOf(ss[i * 2 + 1]);
|
|
||||||
retval.put(localeStr, time);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String localeAndTimeHashMapToStr(HashMap<String, Long> map) {
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
for (String localeStr : map.keySet()) {
|
|
||||||
if (builder.length() > 0) {
|
|
||||||
builder.append(LOCALE_AND_TIME_STR_SEPARATER);
|
|
||||||
}
|
|
||||||
final Long time = map.get(localeStr);
|
|
||||||
builder.append(localeStr).append(LOCALE_AND_TIME_STR_SEPARATER);
|
|
||||||
builder.append(String.valueOf(time));
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.personalization;
|
package com.android.inputmethod.latin.personalization;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
import android.test.suitebuilder.annotation.LargeTest;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -38,7 +36,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public class UserHistoryDictionaryTests extends AndroidTestCase {
|
public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
|
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
|
||||||
private SharedPreferences mPrefs;
|
|
||||||
|
|
||||||
private static final String[] CHARACTERS = {
|
private static final String[] CHARACTERS = {
|
||||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
||||||
|
@ -48,11 +45,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
private static final int MIN_USER_HISTORY_DICTIONARY_FILE_SIZE = 1000;
|
private static final int MIN_USER_HISTORY_DICTIONARY_FILE_SIZE = 1000;
|
||||||
private static final int WAIT_TERMINATING_IN_MILLISECONDS = 100;
|
private static final int WAIT_TERMINATING_IN_MILLISECONDS = 100;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() {
|
|
||||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random word.
|
* Generates a random word.
|
||||||
*/
|
*/
|
||||||
|
@ -92,7 +84,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
final List<String> words = generateWords(numberOfWords, random);
|
final List<String> words = generateWords(numberOfWords, random);
|
||||||
final UserHistoryDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix /* locale */, mPrefs);
|
testFilenameSuffix /* locale */);
|
||||||
// Add random words to the user history dictionary.
|
// Add random words to the user history dictionary.
|
||||||
addToDict(dict, words);
|
addToDict(dict, words);
|
||||||
if (checkContents) {
|
if (checkContents) {
|
||||||
|
@ -116,7 +108,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
private void clearHistory(final String testFilenameSuffix) {
|
private void clearHistory(final String testFilenameSuffix) {
|
||||||
final UserHistoryDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix /* locale */, mPrefs);
|
testFilenameSuffix /* locale */);
|
||||||
dict.clearAndFlushDictionary();
|
dict.clearAndFlushDictionary();
|
||||||
dict.close();
|
dict.close();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +121,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
try {
|
try {
|
||||||
final UserHistoryDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
PersonalizationHelper.getUserHistoryDictionary(getContext(),
|
||||||
testFilenameSuffix, mPrefs);
|
testFilenameSuffix);
|
||||||
dict.shutdownExecutorForTests();
|
dict.shutdownExecutorForTests();
|
||||||
while (!dict.isTerminatedForTests()) {
|
while (!dict.isTerminatedForTests()) {
|
||||||
Thread.sleep(WAIT_TERMINATING_IN_MILLISECONDS);
|
Thread.sleep(WAIT_TERMINATING_IN_MILLISECONDS);
|
||||||
|
|
Loading…
Reference in a new issue