Add a constructor for testing to non-main dictionaries.

The new constructor is used for creating dictionary instance
that uses a given file.

Bug: 11956652
Change-Id: Ifbf420a1a768eb95a5c3a58eeb1be5936b306d35
main
Keisuke Kuroyanagi 2013-12-12 20:14:06 +09:00
parent d06de553b2
commit 9bd6dac470
4 changed files with 46 additions and 1 deletions

View File

@ -105,6 +105,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Whether to support dynamically updating the dictionary */
private final boolean mIsUpdatable;
/** Dictionary file */
private final File mDictFile;
// TODO: remove, once dynamic operations is serialized
/** Controls updating the shared binary dictionary file across multiple instances. */
private final DictionaryUpdateController mDictNameDictionaryUpdateController;
@ -146,7 +149,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
private File getDictFile() {
return new File(mContext.getFilesDir(), mDictName + DICT_FILE_EXTENSION);
return mDictFile;
}
/**
@ -200,11 +203,20 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/
public ExpandableBinaryDictionary(final Context context, final String dictName,
final Locale locale, final String dictType, final boolean isUpdatable) {
this(context, dictName, locale, dictType, isUpdatable,
new File(context.getFilesDir(), dictName + DICT_FILE_EXTENSION));
}
// Creates an instance that uses a given dictionary file.
public ExpandableBinaryDictionary(final Context context, final String dictName,
final Locale locale, final String dictType, final boolean isUpdatable,
final File dictFile) {
super(dictType);
mDictName = dictName;
mContext = context;
mLocale = locale;
mIsUpdatable = isUpdatable;
mDictFile = dictFile;
mBinaryDictionary = null;
mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
// Currently, only dynamic personalization dictionary is updatable.

View File

@ -70,6 +70,19 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
}
}
// Creates an instance that uses a given dictionary file for testing.
@UsedForTesting
/* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
final Locale locale, final String dictionaryType, final String dictName,
final File dictFile) {
super(context, dictName, locale, dictionaryType, true, dictFile);
mLocale = locale;
mDictName = dictName;
if (mLocale != null && mLocale.toString().length() > 1) {
reloadDictionaryIfRequired();
}
}
@Override
public void close() {
if (DBG_DUMP_ON_CLOSE) {

View File

@ -16,9 +16,11 @@
package com.android.inputmethod.latin.personalization;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.utils.CollectionUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
@ -35,6 +37,14 @@ public class PersonalizationDictionary extends DecayingExpandableBinaryDictionar
getDictNameWithLocale(NAME, locale));
}
// Creates an instance that uses a given dictionary file for testing.
@UsedForTesting
public PersonalizationDictionary(final Context context, final Locale locale,
final File dictFile) {
super(context, locale, Dictionary.TYPE_PERSONALIZATION, getDictNameWithLocale(NAME, locale),
dictFile);
}
public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) {
session.setPredictionDictionary(this);
mSessions.add(session);

View File

@ -16,8 +16,10 @@
package com.android.inputmethod.latin.personalization;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Dictionary;
import java.io.File;
import java.util.Locale;
import android.content.Context;
@ -33,6 +35,14 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictNameWithLocale(NAME, locale));
}
// Creates an instance that uses a given dictionary file for testing.
@UsedForTesting
public UserHistoryDictionary(final Context context, final Locale locale,
final File dictFile) {
super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictNameWithLocale(NAME, locale),
dictFile);
}
public void cancelAddingUserHistory(final String word0, final String word1) {
removeBigramDynamically(word0, word1);
}