mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
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
This commit is contained in:
parent
d06de553b2
commit
9bd6dac470
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user