aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/UserBinaryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
index 21014b378..2d2b3d0a6 100644
--- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
@@ -28,7 +28,7 @@ import android.provider.UserDictionary.Words;
import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.annotations.UsedForTesting;
+import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.compat.UserDictionaryCompatUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@@ -36,6 +36,8 @@ import java.io.File;
import java.util.Arrays;
import java.util.Locale;
+import javax.annotation.Nullable;
+
/**
* An expandable dictionary that stores the words in the user dictionary provider into a binary
* dictionary file to use it from native code.
@@ -64,7 +66,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
private static final String NAME = "userunigram";
private ContentObserver mObserver;
- final private String mLocale;
+ final private String mLocaleString;
final private boolean mAlsoUseMoreRestrictiveLocales;
protected UserBinaryDictionary(final Context context, final Locale locale,
@@ -74,9 +76,9 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
final String localeStr = locale.toString();
if (SubtypeLocaleUtils.NO_LANGUAGE.equals(localeStr)) {
// If we don't have a locale, insert into the "all locales" user dictionary.
- mLocale = USER_DICTIONARY_ALL_LANGUAGES;
+ mLocaleString = USER_DICTIONARY_ALL_LANGUAGES;
} else {
- mLocale = localeStr;
+ mLocaleString = localeStr;
}
mAlsoUseMoreRestrictiveLocales = alsoUseMoreRestrictiveLocales;
ContentResolver cres = context.getContentResolver();
@@ -101,9 +103,10 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
reloadDictionaryIfRequired();
}
- @UsedForTesting
+ // Note: This method is called by {@link DictionaryFacilitator} using Java reflection.
+ @ExternallyReferenced
public static UserBinaryDictionary getDictionary(final Context context, final Locale locale,
- final File dictFile, final String dictNamePrefix) {
+ final File dictFile, final String dictNamePrefix, @Nullable final String account) {
return new UserBinaryDictionary(context, locale, false /* alsoUseMoreRestrictiveLocales */,
dictFile, dictNamePrefix + NAME);
}
@@ -124,7 +127,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
// This is correct for locale processing.
// For this example, we'll look at the "en_US_POSIX" case.
final String[] localeElements =
- TextUtils.isEmpty(mLocale) ? new String[] {} : mLocale.split("_", 3);
+ TextUtils.isEmpty(mLocaleString) ? new String[] {} : mLocaleString.split("_", 3);
final int length = localeElements.length;
final StringBuilder request = new StringBuilder("(locale is NULL)");
@@ -207,9 +210,8 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
if (client != null) {
client.release();
return true;
- } else {
- return false;
}
+ return false;
}
/**
@@ -227,17 +229,16 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY, null, locale);
}
- private int scaleFrequencyFromDefaultToLatinIme(final int defaultFrequency) {
+ private static int scaleFrequencyFromDefaultToLatinIme(final int defaultFrequency) {
// The default frequency for the user dictionary is 250 for historical reasons.
// Latin IME considers a good value for the default user dictionary frequency
// is about 160 considering the scale we use. So we are scaling down the values.
if (defaultFrequency > Integer.MAX_VALUE / LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY) {
return (defaultFrequency / HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY)
* LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY;
- } else {
- return (defaultFrequency * LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY)
- / HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY;
}
+ return (defaultFrequency * LATINIME_DEFAULT_USER_DICTIONARY_FREQUENCY)
+ / HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY;
}
private void addWordsLocked(final Cursor cursor) {
@@ -257,12 +258,14 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
runGCIfRequiredLocked(true /* mindsBlockByGC */);
addUnigramLocked(word, adjustedFrequency, null /* shortcutTarget */,
0 /* shortcutFreq */, false /* isNotAWord */,
- false /* isBlacklisted */, BinaryDictionary.NOT_A_VALID_TIMESTAMP);
+ false /* isPossiblyOffensive */,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP);
if (null != shortcut && shortcut.length() <= MAX_WORD_LENGTH) {
runGCIfRequiredLocked(true /* mindsBlockByGC */);
addUnigramLocked(shortcut, adjustedFrequency, word,
USER_DICT_SHORTCUT_FREQUENCY, true /* isNotAWord */,
- false /* isBlacklisted */, BinaryDictionary.NOT_A_VALID_TIMESTAMP);
+ false /* isPossiblyOffensive */,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP);
}
}
cursor.moveToNext();