diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index 09d0ea210..30b3433bb 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -61,9 +61,6 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { /** The number of contacts in the most recent dictionary rebuild. */ static private int sContactCountAtLastRebuild = 0; - /** The locale for this contacts dictionary. Controls name bigram predictions. */ - public final Locale mLocale; - private ContentObserver mObserver; /** @@ -71,11 +68,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { */ private final boolean mUseFirstLastBigrams; - public ContactsBinaryDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); - } - - public ContactsBinaryDictionary(final Context context, final Locale locale, + private ContactsBinaryDictionary(final Context context, final Locale locale, final File dictFile) { this(context, locale, dictFile, NAME); } @@ -84,12 +77,16 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { final File dictFile, final String name) { super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS, dictFile); - mLocale = locale; mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale); registerObserver(context); reloadDictionaryIfRequired(); } + public static ContactsBinaryDictionary getDictionary(final Context context, final Locale locale, + final File dictFile) { + return new ContactsBinaryDictionary(context, locale, dictFile); + } + private synchronized void registerObserver(final Context context) { if (mObserver != null) return; ContentResolver cres = context.getContentResolver(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index c6b0d3514..061910775 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -23,8 +23,7 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.personalization.DecayingExpandableBinaryDictionaryBase; -import com.android.inputmethod.latin.personalization.PersonalizationHelper; +import com.android.inputmethod.latin.personalization.PersonalizationDictionary; import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ExecutorUtils; @@ -147,13 +146,13 @@ public class DictionaryFacilitatorForSuggest { private static ExpandableBinaryDictionary getSubDict(final String dictType, final Context context, final Locale locale, final File dictFile) { if (Dictionary.TYPE_CONTACTS.equals(dictType)) { - return new ContactsBinaryDictionary(context, locale, dictFile); + return ContactsBinaryDictionary.getDictionary(context, locale, dictFile); } else if (Dictionary.TYPE_USER.equals(dictType)) { - return new UserBinaryDictionary(context, locale, dictFile); + return UserBinaryDictionary.getDictionary(context, locale, dictFile); } else if (Dictionary.TYPE_USER_HISTORY.equals(dictType)) { - return PersonalizationHelper.getUserHistoryDictionary(context, locale); + return UserHistoryDictionary.getDictionary(context, locale, dictFile); } else if (Dictionary.TYPE_PERSONALIZATION.equals(dictType)) { - return PersonalizationHelper.getPersonalizationDictionary(context, locale); + return PersonalizationDictionary.getDictionary(context, locale, dictFile); } else { return null; } diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 2006a5c89..f99896109 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -66,17 +66,8 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { final private String mLocale; final private boolean mAlsoUseMoreRestrictiveLocales; - public UserBinaryDictionary(final Context context, final Locale locale) { - this(context, locale, false /* alsoUseMoreRestrictiveLocales */, null /* dictFile */); - } - - public UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) { - this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile); - } - - public UserBinaryDictionary(final Context context, final Locale locale, - final boolean alsoUseMoreRestrictiveLocales, final File dictFile) { - this(context, locale, alsoUseMoreRestrictiveLocales, dictFile, NAME); + private UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) { + this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile, NAME); } protected UserBinaryDictionary(final Context context, final Locale locale, @@ -113,6 +104,11 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { reloadDictionaryIfRequired(); } + public static UserBinaryDictionary getDictionary(final Context context, final Locale locale, + final File dictFile) { + return new UserBinaryDictionary(context, locale, dictFile); + } + @Override public synchronized void close() { if (mObserver != null) { diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java index 4afd5b4c9..3f879f0f0 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java @@ -26,14 +26,15 @@ import java.util.Locale; public class PersonalizationDictionary extends DecayingExpandableBinaryDictionaryBase { /* package */ static final String NAME = PersonalizationDictionary.class.getSimpleName(); + // TODO: Make this constructor private /* package */ PersonalizationDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); + super(context, getDictName(NAME, locale, null /* dictFile */), locale, + Dictionary.TYPE_PERSONALIZATION, null /* dictFile */); } - public PersonalizationDictionary(final Context context, final Locale locale, - final File dictFile) { - super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_PERSONALIZATION, - dictFile); + public static PersonalizationDictionary getDictionary(final Context context, + final Locale locale, final File dictFile) { + return PersonalizationHelper.getPersonalizationDictionary(context, locale); } @Override diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index 8a29c354d..36e59e931 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -32,14 +32,15 @@ import java.util.Locale; public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase { /* package */ static final String NAME = UserHistoryDictionary.class.getSimpleName(); + // TODO: Make this constructor private /* package */ UserHistoryDictionary(final Context context, final Locale locale) { - this(context, locale, null /* dictFile */); + super(context, getDictName(NAME, locale, null /* dictFile */), locale, + Dictionary.TYPE_USER_HISTORY, null /* dictFile */); } - public UserHistoryDictionary(final Context context, final Locale locale, + public static UserHistoryDictionary getDictionary(final Context context, final Locale locale, final File dictFile) { - super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_USER_HISTORY, - dictFile); + return PersonalizationHelper.getUserHistoryDictionary(context, locale); } @Override