Move main dictionary availability check to LatinIME

Change-Id: Ib6183fec833d87bc32514b03bb691fec0a1e6ff8
This commit is contained in:
Tadashi G. Takaoka 2012-04-19 23:11:31 +09:00
parent 65e93e352f
commit 6a7019ff5d
2 changed files with 18 additions and 19 deletions

View file

@ -154,6 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final SubtypeSwitcher mSubtypeSwitcher; private final SubtypeSwitcher mSubtypeSwitcher;
private boolean mShouldSwitchToLastSubtype = true; private boolean mShouldSwitchToLastSubtype = true;
private boolean mIsMainDictionaryAvailable;
private UserDictionary mUserDictionary; private UserDictionary mUserDictionary;
private UserHistoryDictionary mUserHistoryDictionary; private UserHistoryDictionary mUserHistoryDictionary;
private boolean mIsUserDictionaryAvailable; private boolean mIsUserDictionaryAvailable;
@ -449,14 +450,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return new SettingsValues(mPrefs, LatinIME.this); return new SettingsValues(mPrefs, LatinIME.this);
} }
}; };
mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getInputLocale()); mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
} }
private void initSuggest() { private void initSuggest() {
final Locale keyboardLocale = mSubtypeSwitcher.getInputLocale(); final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
final String localeStr = keyboardLocale.toString(); final String localeStr = subtypeLocale.toString();
final Dictionary oldContactsDictionary; final Dictionary oldContactsDictionary;
if (mSuggest != null) { if (mSuggest != null) {
@ -465,11 +466,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else { } else {
oldContactsDictionary = null; oldContactsDictionary = null;
} }
mSuggest = new Suggest(this, keyboardLocale); mSuggest = new Suggest(this, subtypeLocale);
if (mSettingsValues.mAutoCorrectEnabled) { if (mSettingsValues.mAutoCorrectEnabled) {
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
} }
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
mUserDictionary = new UserDictionary(this, localeStr); mUserDictionary = new UserDictionary(this, localeStr);
mSuggest.setUserDictionary(mUserDictionary); mSuggest.setUserDictionary(mUserDictionary);
mIsUserDictionaryAvailable = mUserDictionary.isEnabled(); mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
@ -511,7 +514,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else { } else {
if (USE_BINARY_CONTACTS_DICTIONARY) { if (USE_BINARY_CONTACTS_DICTIONARY) {
dictionaryToUse = new ContactsBinaryDictionary(this, Suggest.DIC_CONTACTS, dictionaryToUse = new ContactsBinaryDictionary(this, Suggest.DIC_CONTACTS,
mSubtypeSwitcher.getInputLocale()); mSubtypeSwitcher.getCurrentSubtypeLocale());
} else { } else {
dictionaryToUse = new ContactsDictionary(this, Suggest.DIC_CONTACTS); dictionaryToUse = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
} }
@ -523,7 +526,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
/* package private */ void resetSuggestMainDict() { /* package private */ void resetSuggestMainDict() {
mSuggest.resetMainDict(this, mSubtypeSwitcher.getInputLocale()); final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
mSuggest.resetMainDict(this, subtypeLocale);
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
} }
@Override @Override
@ -603,7 +608,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
SubtypeSwitcher.getInstance().updateSubtype(subtype); mSubtypeSwitcher.updateSubtype(subtype);
} }
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) { private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
@ -1894,7 +1899,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mSettingsValues.mEnableSuggestionSpanInsertion) { if (mSettingsValues.mEnableSuggestionSpanInsertion) {
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
this, bestWord, suggestedWords, mSubtypeSwitcher.isDictionaryAvailable()), this, bestWord, suggestedWords, mIsMainDictionaryAvailable),
1); 1);
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_commitText(bestWord); ResearchLogger.latinIME_commitText(bestWord);
@ -1972,7 +1977,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final String secondWord; final String secondWord;
if (mWordComposer.isAutoCapitalized() && !mWordComposer.isMostlyCaps()) { if (mWordComposer.isAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
secondWord = suggestion.toString().toLowerCase(mSubtypeSwitcher.getInputLocale()); secondWord = suggestion.toString().toLowerCase(
mSubtypeSwitcher.getCurrentSubtypeLocale());
} else { } else {
secondWord = suggestion.toString(); secondWord = suggestion.toString();
} }
@ -2300,8 +2306,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
private void showOptionDialogInternal(AlertDialog dialog) { private void showOptionDialogInternal(AlertDialog dialog) {
final IBinder windowToken = KeyboardSwitcher.getInstance().getKeyboardView() final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken();
.getWindowToken();
if (windowToken == null) return; if (windowToken == null) return;
dialog.setCancelable(true); dialog.setCancelable(true);

View file

@ -50,7 +50,6 @@ public class SubtypeSwitcher {
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
// Variants which should be changed only by reload functions. // Variants which should be changed only by reload functions.
private NeedsToDisplayLanguage mNeedsToDisplayLanguage = new NeedsToDisplayLanguage(); private NeedsToDisplayLanguage mNeedsToDisplayLanguage = new NeedsToDisplayLanguage();
private boolean mIsDictionaryAvailable;
private InputMethodInfo mShortcutInputMethodInfo; private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype; private InputMethodSubtype mShortcutSubtype;
private InputMethodSubtype mNoLanguageSubtype; private InputMethodSubtype mNoLanguageSubtype;
@ -188,7 +187,6 @@ public class SubtypeSwitcher {
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype); final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage( mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage(
mCurrentSystemLocale.equals(newLocale)); mCurrentSystemLocale.equals(newLocale));
mIsDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(mService, newLocale);
mCurrentSubtype = newSubtype; mCurrentSubtype = newSubtype;
updateShortcutIME(); updateShortcutIME();
@ -267,13 +265,13 @@ public class SubtypeSwitcher {
if (keyboardLocale.toString().equals(SubtypeLocale.NO_LANGUAGE)) { if (keyboardLocale.toString().equals(SubtypeLocale.NO_LANGUAGE)) {
return true; return true;
} }
if (!keyboardLocale.equals(getInputLocale())) { if (!keyboardLocale.equals(getCurrentSubtypeLocale())) {
return false; return false;
} }
return mNeedsToDisplayLanguage.getValue(); return mNeedsToDisplayLanguage.getValue();
} }
public Locale getInputLocale() { public Locale getCurrentSubtypeLocale() {
return SubtypeLocale.getSubtypeLocale(mCurrentSubtype); return SubtypeLocale.getSubtypeLocale(mCurrentSubtype);
} }
@ -285,10 +283,6 @@ public class SubtypeSwitcher {
} }
} }
public boolean isDictionaryAvailable() {
return mIsDictionaryAvailable;
}
public InputMethodSubtype getCurrentSubtype() { public InputMethodSubtype getCurrentSubtype() {
return mCurrentSubtype; return mCurrentSubtype;
} }