Create factory methods for sub dicts.

Bug: 13755213
Change-Id: I046af54b4860d2839328f2089ea785d81d04cf43
This commit is contained in:
Keisuke Kuroyanagi 2014-05-01 17:22:23 +09:00
parent 1ab6bfdc60
commit 98e358a936
5 changed files with 29 additions and 35 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -74,17 +74,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,
@ -121,6 +112,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) {

View file

@ -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

View file

@ -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