Merge "Have DictionaryFacilitator in LatinIME."

main
Keisuke Kuroyanagi 2014-05-23 02:06:33 +00:00 committed by Android (Google) Code Review
commit c1442aa282
9 changed files with 62 additions and 62 deletions

View File

@ -45,8 +45,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
// TODO: Consolidate dictionaries in native code. // TODO: Consolidate dictionaries in native code.
public class DictionaryFacilitatorForSuggest { public class DictionaryFacilitator {
public static final String TAG = DictionaryFacilitatorForSuggest.class.getSimpleName(); public static final String TAG = DictionaryFacilitator.class.getSimpleName();
// HACK: This threshold is being used when adding a capitalized entry in the User History // HACK: This threshold is being used when adding a capitalized entry in the User History
// dictionary. // dictionary.
@ -162,7 +162,7 @@ public class DictionaryFacilitatorForSuggest {
public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable); public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable);
} }
public DictionaryFacilitatorForSuggest() {} public DictionaryFacilitator() {}
public Locale getLocale() { public Locale getLocale() {
return mDictionaries.mLocale; return mDictionaries.mLocale;

View File

@ -103,7 +103,7 @@ import java.util.concurrent.TimeUnit;
*/ */
public class LatinIME extends InputMethodService implements KeyboardActionListener, public class LatinIME extends InputMethodService implements KeyboardActionListener,
SuggestionStripView.Listener, SuggestionStripViewAccessor, SuggestionStripView.Listener, SuggestionStripViewAccessor,
DictionaryFacilitatorForSuggest.DictionaryInitializationListener, DictionaryFacilitator.DictionaryInitializationListener,
ImportantNoticeDialog.ImportantNoticeDialogListener { ImportantNoticeDialog.ImportantNoticeDialogListener {
private static final String TAG = LatinIME.class.getSimpleName(); private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean TRACE = false; private static final boolean TRACE = false;
@ -122,8 +122,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final String SCHEME_PACKAGE = "package"; private static final String SCHEME_PACKAGE = "package";
private final Settings mSettings; private final Settings mSettings;
private final DictionaryFacilitator mDictionaryFacilitator = new DictionaryFacilitator();
private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */, private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
this /* SuggestionStripViewAccessor */); this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
// We expect to have only one decoder in almost all cases, hence the default capacity of 1. // We expect to have only one decoder in almost all cases, hence the default capacity of 1.
// If it turns out we need several, it will get grown seamlessly. // If it turns out we need several, it will get grown seamlessly.
final SparseArray<HardwareEventDecoder> mHardwareEventDecoders final SparseArray<HardwareEventDecoder> mHardwareEventDecoders
@ -493,8 +494,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.getInstance().init(this, mKeyboardSwitcher); ResearchLogger.getInstance().init(this, mKeyboardSwitcher);
ResearchLogger.getInstance().initDictionary( ResearchLogger.getInstance().initDictionary(mDictionaryFacilitator);
mInputLogic.mSuggest.mDictionaryFacilitator);
} }
// Register to receive ringer mode change and network state change. // Register to receive ringer mode change and network state change.
@ -543,8 +543,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
private void refreshPersonalizationDictionarySession() { private void refreshPersonalizationDictionarySession() {
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
mInputLogic.mSuggest.mDictionaryFacilitator;
final boolean shouldKeepUserHistoryDictionaries; final boolean shouldKeepUserHistoryDictionaries;
final boolean shouldKeepPersonalizationDictionaries; final boolean shouldKeepPersonalizationDictionaries;
if (mSettings.getCurrent().mUsePersonalizedDicts) { if (mSettings.getCurrent().mUsePersonalizedDicts) {
@ -559,7 +557,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!shouldKeepUserHistoryDictionaries) { if (!shouldKeepUserHistoryDictionaries) {
// Remove user history dictionaries. // Remove user history dictionaries.
PersonalizationHelper.removeAllUserHistoryDictionaries(this); PersonalizationHelper.removeAllUserHistoryDictionaries(this);
dictionaryFacilitator.clearUserHistoryDictionary(); mDictionaryFacilitator.clearUserHistoryDictionary();
} }
if (!shouldKeepPersonalizationDictionaries) { if (!shouldKeepPersonalizationDictionaries) {
// Remove personalization dictionaries. // Remove personalization dictionaries.
@ -568,7 +566,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else { } else {
final DistracterFilter distracterFilter = createDistracterFilter(); final DistracterFilter distracterFilter = createDistracterFilter();
PersonalizationDictionarySessionRegistrar.init( PersonalizationDictionarySessionRegistrar.init(
this, dictionaryFacilitator, distracterFilter); this, mDictionaryFacilitator, distracterFilter);
} }
} }
@ -606,10 +604,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
* @param locale the locale * @param locale the locale
*/ */
private void resetSuggestForLocale(final Locale locale) { private void resetSuggestForLocale(final Locale locale) {
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
mInputLogic.mSuggest.mDictionaryFacilitator;
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
dictionaryFacilitator.resetDictionaries(this /* context */, locale, mDictionaryFacilitator.resetDictionaries(this /* context */, locale,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, this); false /* forceReloadMainDictionary */, this);
if (settingsValues.mCorrectionEnabled) { if (settingsValues.mCorrectionEnabled) {
@ -622,17 +618,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
* Reset suggest by loading the main dictionary of the current locale. * Reset suggest by loading the main dictionary of the current locale.
*/ */
/* package private */ void resetSuggestMainDict() { /* package private */ void resetSuggestMainDict() {
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
mInputLogic.mSuggest.mDictionaryFacilitator;
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
dictionaryFacilitator.resetDictionaries(this /* context */, mDictionaryFacilitator.resetDictionaries(this /* context */,
dictionaryFacilitator.getLocale(), settingsValues.mUseContactsDict, mDictionaryFacilitator.getLocale(), settingsValues.mUseContactsDict,
settingsValues.mUsePersonalizedDicts, true /* forceReloadMainDictionary */, this); settingsValues.mUsePersonalizedDicts, true /* forceReloadMainDictionary */, this);
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
mInputLogic.mSuggest.mDictionaryFacilitator.closeDictionaries(); mDictionaryFacilitator.closeDictionaries();
mSettings.onDestroy(); mSettings.onDestroy();
unregisterReceiver(mConnectivityAndRingerModeChangeReceiver); unregisterReceiver(mConnectivityAndRingerModeChangeReceiver);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
@ -668,7 +662,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final DistracterFilter distracterFilter = createDistracterFilter(); final DistracterFilter distracterFilter = createDistracterFilter();
PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf, PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf,
mInputLogic.mSuggest.mDictionaryFacilitator, distracterFilter); mDictionaryFacilitator, distracterFilter);
super.onConfigurationChanged(conf); super.onConfigurationChanged(conf);
} }
@ -841,7 +835,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
currentSettingsValues = mSettings.getCurrent(); currentSettingsValues = mSettings.getCurrent();
if (currentSettingsValues.mCorrectionEnabled) { if (currentSettingsValues.mCorrectionEnabled) {
suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); suggest.setAutoCorrectionThreshold(
currentSettingsValues.mAutoCorrectionThreshold);
} }
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
@ -870,7 +865,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.cancelUpdateSuggestionStrip(); mHandler.cancelUpdateSuggestionStrip();
mainKeyboardView.setMainDictionaryAvailability( mainKeyboardView.setMainDictionaryAvailability(
suggest.mDictionaryFacilitator.hasInitializedMainDictionary()); mDictionaryFacilitator.hasInitializedMainDictionary());
mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn, mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn,
currentSettingsValues.mKeyPreviewPopupDismissDelay); currentSettingsValues.mKeyPreviewPopupDismissDelay);
mainKeyboardView.setSlidingKeyInputPreviewEnabled( mainKeyboardView.setSlidingKeyInputPreviewEnabled(
@ -1167,8 +1162,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else { } else {
wordToEdit = word; wordToEdit = word;
} }
mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary( mDictionaryFacilitator.addWordToUserDictionary(this /* context */, wordToEdit);
this /* context */, wordToEdit);
} }
// Callback for the {@link SuggestionStripView}, to call when the important notice strip is // Callback for the {@link SuggestionStripView}, to call when the important notice strip is
@ -1725,15 +1719,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@UsedForTesting @UsedForTesting
/* package for test */ void waitForLoadingDictionaries(final long timeout, final TimeUnit unit) /* package for test */ void waitForLoadingDictionaries(final long timeout, final TimeUnit unit)
throws InterruptedException { throws InterruptedException {
mInputLogic.mSuggest.mDictionaryFacilitator.waitForLoadingDictionariesForTesting( mDictionaryFacilitator.waitForLoadingDictionariesForTesting(timeout, unit);
timeout, unit);
} }
// DO NOT USE THIS for any other purpose than testing. This can break the keyboard badly. // DO NOT USE THIS for any other purpose than testing. This can break the keyboard badly.
@UsedForTesting @UsedForTesting
/* package for test */ void replaceDictionariesForTest(final Locale locale) { /* package for test */ void replaceDictionariesForTest(final Locale locale) {
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
mInputLogic.mSuggest.mDictionaryFacilitator.resetDictionaries(this, locale, mDictionaryFacilitator.resetDictionaries(this, locale,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, this /* listener */); false /* forceReloadMainDictionary */, this /* listener */);
} }
@ -1741,8 +1734,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// DO NOT USE THIS for any other purpose than testing. // DO NOT USE THIS for any other purpose than testing.
@UsedForTesting @UsedForTesting
/* package for test */ void clearPersonalizedDictionariesForTest() { /* package for test */ void clearPersonalizedDictionariesForTest() {
mInputLogic.mSuggest.mDictionaryFacilitator.clearUserHistoryDictionary(); mDictionaryFacilitator.clearUserHistoryDictionary();
mInputLogic.mSuggest.mDictionaryFacilitator.clearPersonalizationDictionary(); mDictionaryFacilitator.clearPersonalizationDictionary();
} }
@UsedForTesting @UsedForTesting
@ -1754,12 +1747,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
public void dumpDictionaryForDebug(final String dictName) { public void dumpDictionaryForDebug(final String dictName) {
final DictionaryFacilitatorForSuggest dictionaryFacilitator = if (mDictionaryFacilitator.getLocale() == null) {
mInputLogic.mSuggest.mDictionaryFacilitator;
if (dictionaryFacilitator.getLocale() == null) {
resetSuggest(); resetSuggest();
} }
mInputLogic.mSuggest.mDictionaryFacilitator.dumpDictionaryForDebug(dictName); mDictionaryFacilitator.dumpDictionaryForDebug(dictName);
} }
public void debugDumpStateAndCrashWithException(final String context) { public void debugDumpStateAndCrashWithException(final String context) {

View File

@ -52,11 +52,14 @@ public final class Suggest {
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000; private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
private static final boolean DBG = LatinImeLogger.sDBG; private static final boolean DBG = LatinImeLogger.sDBG;
public final DictionaryFacilitatorForSuggest mDictionaryFacilitator = private final DictionaryFacilitator mDictionaryFacilitator;
new DictionaryFacilitatorForSuggest();
private float mAutoCorrectionThreshold; private float mAutoCorrectionThreshold;
public Suggest(final DictionaryFacilitator dictionaryFacilitator) {
mDictionaryFacilitator = dictionaryFacilitator;
}
public Locale getLocale() { public Locale getLocale() {
return mDictionaryFacilitator.getLocale(); return mDictionaryFacilitator.getLocale();
} }

View File

@ -32,7 +32,7 @@ import com.android.inputmethod.event.InputTransaction;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LastComposedWord; import com.android.inputmethod.latin.LastComposedWord;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
@ -79,7 +79,8 @@ public final class InputLogic {
private int mSpaceState; private int mSpaceState;
// Never null // Never null
public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
public final Suggest mSuggest = new Suggest(); public final Suggest mSuggest;
private final DictionaryFacilitator mDictionaryFacilitator;
public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
public final WordComposer mWordComposer; public final WordComposer mWordComposer;
@ -102,14 +103,19 @@ public final class InputLogic {
* Create a new instance of the input logic. * Create a new instance of the input logic.
* @param latinIME the instance of the parent LatinIME. We should remove this when we can. * @param latinIME the instance of the parent LatinIME. We should remove this when we can.
* @param suggestionStripViewAccessor an object to access the suggestion strip view. * @param suggestionStripViewAccessor an object to access the suggestion strip view.
* @param dictionaryFacilitator facilitator for getting suggestions and updating user history
* dictionary.
*/ */
public InputLogic(final LatinIME latinIME, public InputLogic(final LatinIME latinIME,
final SuggestionStripViewAccessor suggestionStripViewAccessor) { final SuggestionStripViewAccessor suggestionStripViewAccessor,
final DictionaryFacilitator dictionaryFacilitator) {
mLatinIME = latinIME; mLatinIME = latinIME;
mSuggestionStripViewAccessor = suggestionStripViewAccessor; mSuggestionStripViewAccessor = suggestionStripViewAccessor;
mWordComposer = new WordComposer(); mWordComposer = new WordComposer();
mConnection = new RichInputConnection(latinIME); mConnection = new RichInputConnection(latinIME);
mInputLogicHandler = InputLogicHandler.NULL_HANDLER; mInputLogicHandler = InputLogicHandler.NULL_HANDLER;
mSuggest = new Suggest(dictionaryFacilitator);
mDictionaryFacilitator = dictionaryFacilitator;
} }
/** /**
@ -173,7 +179,7 @@ public final class InputLogic {
final InputLogicHandler inputLogicHandler = mInputLogicHandler; final InputLogicHandler inputLogicHandler = mInputLogicHandler;
mInputLogicHandler = InputLogicHandler.NULL_HANDLER; mInputLogicHandler = InputLogicHandler.NULL_HANDLER;
inputLogicHandler.destroy(); inputLogicHandler.destroy();
mSuggest.mDictionaryFacilitator.closeDictionaries(); mDictionaryFacilitator.closeDictionaries();
} }
/** /**
@ -295,18 +301,16 @@ public final class InputLogic {
// We should show the "Touch again to save" hint if the user pressed the first entry // We should show the "Touch again to save" hint if the user pressed the first entry
// AND it's in none of our current dictionaries (main, user or otherwise). // AND it's in none of our current dictionaries (main, user or otherwise).
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
mSuggest.mDictionaryFacilitator;
final boolean showingAddToDictionaryHint = final boolean showingAddToDictionaryHint =
(SuggestedWordInfo.KIND_TYPED == suggestionInfo.mKind (SuggestedWordInfo.KIND_TYPED == suggestionInfo.mKind
|| SuggestedWordInfo.KIND_OOV_CORRECTION == suggestionInfo.mKind) || SuggestedWordInfo.KIND_OOV_CORRECTION == suggestionInfo.mKind)
&& !dictionaryFacilitator.isValidWord(suggestion, true /* ignoreCase */); && !mDictionaryFacilitator.isValidWord(suggestion, true /* ignoreCase */);
if (settingsValues.mIsInternal) { if (settingsValues.mIsInternal) {
LatinImeLoggerUtils.onSeparator((char)Constants.CODE_SPACE, LatinImeLoggerUtils.onSeparator((char)Constants.CODE_SPACE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
} }
if (showingAddToDictionaryHint && dictionaryFacilitator.isUserDictionaryEnabled()) { if (showingAddToDictionaryHint && mDictionaryFacilitator.isUserDictionaryEnabled()) {
mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion); mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion);
} else { } else {
// If we're not showing the "Touch again to save", then update the suggestion strip. // If we're not showing the "Touch again to save", then update the suggestion strip.
@ -1250,7 +1254,7 @@ public final class InputLogic {
mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps(); mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps();
final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds( final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds(
System.currentTimeMillis()); System.currentTimeMillis());
mSuggest.mDictionaryFacilitator.addToUserHistory(suggestion, wasAutoCapitalized, mDictionaryFacilitator.addToUserHistory(suggestion, wasAutoCapitalized,
prevWordsInfo, timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive); prevWordsInfo, timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive);
} }
@ -1462,8 +1466,7 @@ public final class InputLogic {
} }
mConnection.deleteSurroundingText(deleteLength, 0); mConnection.deleteSurroundingText(deleteLength, 0);
if (!TextUtils.isEmpty(prevWordsInfo.mPrevWord) && !TextUtils.isEmpty(committedWord)) { if (!TextUtils.isEmpty(prevWordsInfo.mPrevWord) && !TextUtils.isEmpty(committedWord)) {
mSuggest.mDictionaryFacilitator.cancelAddingUserHistory( mDictionaryFacilitator.cancelAddingUserHistory(prevWordsInfo, committedWordString);
prevWordsInfo, committedWordString);
} }
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString; final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
final SpannableString textToCommit = new SpannableString(stringToCommit); final SpannableString textToCommit = new SpannableString(stringToCommit);

View File

@ -19,17 +19,17 @@ package com.android.inputmethod.latin.personalization;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.utils.DistracterFilter; import com.android.inputmethod.latin.utils.DistracterFilter;
public class PersonalizationDictionarySessionRegistrar { public class PersonalizationDictionarySessionRegistrar {
public static void init(final Context context, public static void init(final Context context,
final DictionaryFacilitatorForSuggest dictionaryFacilitator, final DictionaryFacilitator dictionaryFacilitator,
final DistracterFilter distracterFilter) { final DistracterFilter distracterFilter) {
} }
public static void onConfigurationChanged(final Context context, final Configuration conf, public static void onConfigurationChanged(final Context context, final Configuration conf,
final DictionaryFacilitatorForSuggest dictionaryFacilitator, final DictionaryFacilitator dictionaryFacilitator,
final DistracterFilter distracterFilter) { final DistracterFilter distracterFilter) {
} }

View File

@ -34,6 +34,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.PrevWordsInfo; import com.android.inputmethod.latin.PrevWordsInfo;
import com.android.inputmethod.latin.Suggest; import com.android.inputmethod.latin.Suggest;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback; import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
@ -53,6 +54,7 @@ public class DistracterFilter {
private final Context mContext; private final Context mContext;
private final Map<Locale, InputMethodSubtype> mLocaleToSubtypeMap; private final Map<Locale, InputMethodSubtype> mLocaleToSubtypeMap;
private final Map<Locale, Keyboard> mLocaleToKeyboardMap; private final Map<Locale, Keyboard> mLocaleToKeyboardMap;
private final DictionaryFacilitator mDictionaryFacilitator;
private final Suggest mSuggest; private final Suggest mSuggest;
private Keyboard mKeyboard; private Keyboard mKeyboard;
@ -89,7 +91,8 @@ public class DistracterFilter {
} }
} }
mLocaleToKeyboardMap = new HashMap<>(); mLocaleToKeyboardMap = new HashMap<>();
mSuggest = new Suggest(); mDictionaryFacilitator = new DictionaryFacilitator();
mSuggest = new Suggest(mDictionaryFacilitator);
mKeyboard = null; mKeyboard = null;
} }
@ -132,10 +135,10 @@ public class DistracterFilter {
} }
private void loadDictionariesForLocale(final Locale newlocale) throws InterruptedException { private void loadDictionariesForLocale(final Locale newlocale) throws InterruptedException {
mSuggest.mDictionaryFacilitator.resetDictionaries(mContext, newlocale, mDictionaryFacilitator.resetDictionaries(mContext, newlocale,
false /* useContactsDict */, false /* usePersonalizedDicts */, false /* useContactsDict */, false /* usePersonalizedDicts */,
false /* forceReloadMainDictionary */, null /* listener */); false /* forceReloadMainDictionary */, null /* listener */);
mSuggest.mDictionaryFacilitator.waitForLoadingMainDictionary( mDictionaryFacilitator.waitForLoadingMainDictionary(
TIMEOUT_TO_WAIT_LOADING_DICTIONARIES_IN_SECONDS, TimeUnit.SECONDS); TIMEOUT_TO_WAIT_LOADING_DICTIONARIES_IN_SECONDS, TimeUnit.SECONDS);
} }
@ -153,7 +156,7 @@ public class DistracterFilter {
if (locale == null) { if (locale == null) {
return false; return false;
} }
if (!locale.equals(mSuggest.mDictionaryFacilitator.getLocale())) { if (!locale.equals(mDictionaryFacilitator.getLocale())) {
if (!mLocaleToSubtypeMap.containsKey(locale)) { if (!mLocaleToSubtypeMap.containsKey(locale)) {
Log.e(TAG, "Locale " + locale + " is not enabled."); Log.e(TAG, "Locale " + locale + " is not enabled.");
// TODO: Investigate what we should do for disabled locales. // TODO: Investigate what we should do for disabled locales.

View File

@ -19,7 +19,7 @@ package com.android.inputmethod.latin.utils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.PrevWordsInfo; import com.android.inputmethod.latin.PrevWordsInfo;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
@ -80,7 +80,7 @@ public final class LanguageModelParam {
// Process a list of words and return a list of {@link LanguageModelParam} objects. // Process a list of words and return a list of {@link LanguageModelParam} objects.
public static ArrayList<LanguageModelParam> createLanguageModelParamsFrom( public static ArrayList<LanguageModelParam> createLanguageModelParamsFrom(
final ArrayList<String> tokens, final int timestamp, final ArrayList<String> tokens, final int timestamp,
final DictionaryFacilitatorForSuggest dictionaryFacilitator, final DictionaryFacilitator dictionaryFacilitator,
final SpacingAndPunctuations spacingAndPunctuations, final SpacingAndPunctuations spacingAndPunctuations,
final DistracterFilter distracterFilter) { final DistracterFilter distracterFilter) {
final ArrayList<LanguageModelParam> languageModelParams = final ArrayList<LanguageModelParam> languageModelParams =
@ -124,7 +124,7 @@ public final class LanguageModelParam {
private static LanguageModelParam detectWhetherVaildWordOrNotAndGetLanguageModelParam( private static LanguageModelParam detectWhetherVaildWordOrNotAndGetLanguageModelParam(
final PrevWordsInfo prevWordsInfo, final String targetWord, final int timestamp, final PrevWordsInfo prevWordsInfo, final String targetWord, final int timestamp,
final DictionaryFacilitatorForSuggest dictionaryFacilitator, final DictionaryFacilitator dictionaryFacilitator,
final DistracterFilter distracterFilter) { final DistracterFilter distracterFilter) {
final Locale locale = dictionaryFacilitator.getLocale(); final Locale locale = dictionaryFacilitator.getLocale();
if (locale == null) { if (locale == null) {

View File

@ -20,7 +20,7 @@ import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import java.io.IOException; import java.io.IOException;
@ -75,7 +75,7 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
// The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams. // The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams.
public static final int N_GRAM_SIZE = 2; public static final int N_GRAM_SIZE = 2;
private final DictionaryFacilitatorForSuggest mDictionaryFacilitator; private final DictionaryFacilitator mDictionaryFacilitator;
@UsedForTesting @UsedForTesting
private Dictionary mDictionaryForTesting; private Dictionary mDictionaryForTesting;
private boolean mIsStopping = false; private boolean mIsStopping = false;
@ -87,7 +87,7 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
/* package for test */ int mNumWordsUntilSafeToSample; /* package for test */ int mNumWordsUntilSafeToSample;
public MainLogBuffer(final int wordsBetweenSamples, final int numInitialWordsToIgnore, public MainLogBuffer(final int wordsBetweenSamples, final int numInitialWordsToIgnore,
final DictionaryFacilitatorForSuggest dictionaryFacilitator) { final DictionaryFacilitator dictionaryFacilitator) {
super(N_GRAM_SIZE + wordsBetweenSamples); super(N_GRAM_SIZE + wordsBetweenSamples);
mNumWordsBetweenNGrams = wordsBetweenSamples; mNumWordsBetweenNGrams = wordsBetweenSamples;
mNumWordsUntilSafeToSample = DEBUG ? 0 : numInitialWordsToIgnore; mNumWordsUntilSafeToSample = DEBUG ? 0 : numInitialWordsToIgnore;

View File

@ -52,7 +52,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputConnection; import com.android.inputmethod.latin.RichInputConnection;
@ -167,7 +167,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
protected static final int SUSPEND_DURATION_IN_MINUTES = 1; protected static final int SUSPEND_DURATION_IN_MINUTES = 1;
// used to check whether words are not unique // used to check whether words are not unique
private DictionaryFacilitatorForSuggest mDictionaryFacilitator; private DictionaryFacilitator mDictionaryFacilitator;
private MainKeyboardView mMainKeyboardView; private MainKeyboardView mMainKeyboardView;
// TODO: Check whether a superclass can be used instead of LatinIME. // TODO: Check whether a superclass can be used instead of LatinIME.
/* package for test */ LatinIME mLatinIME; /* package for test */ LatinIME mLatinIME;
@ -656,7 +656,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mInFeedbackDialog = false; mInFeedbackDialog = false;
} }
public void initDictionary(final DictionaryFacilitatorForSuggest dictionaryFacilitator) { public void initDictionary(final DictionaryFacilitator dictionaryFacilitator) {
mDictionaryFacilitator = dictionaryFacilitator; mDictionaryFacilitator = dictionaryFacilitator;
// MainLogBuffer now has an out-of-date Suggest object. Close down MainLogBuffer and create // MainLogBuffer now has an out-of-date Suggest object. Close down MainLogBuffer and create
// a new one. // a new one.