am 176e6e22: Merge "[ML19] Actually switch the language when appropriate"

* commit '176e6e22cff8a3f77e121371a91419aa295abb65':
  [ML19] Actually switch the language when appropriate
This commit is contained in:
Jean Chalard 2014-10-09 12:02:02 +00:00 committed by Android Git Automerger
commit 12250e2492
4 changed files with 27 additions and 8 deletions

View file

@ -16,6 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion; import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
@ -36,19 +37,19 @@ public abstract class Dictionary {
// The following types do not actually come from real dictionary instances, so we create // The following types do not actually come from real dictionary instances, so we create
// corresponding instances. // corresponding instances.
public static final String TYPE_USER_TYPED = "user_typed"; public static final String TYPE_USER_TYPED = "user_typed";
public static final Dictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED); public static final PhonyDictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);
public static final String TYPE_APPLICATION_DEFINED = "application_defined"; public static final String TYPE_APPLICATION_DEFINED = "application_defined";
public static final Dictionary DICTIONARY_APPLICATION_DEFINED = public static final PhonyDictionary DICTIONARY_APPLICATION_DEFINED =
new PhonyDictionary(TYPE_APPLICATION_DEFINED); new PhonyDictionary(TYPE_APPLICATION_DEFINED);
public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such
public static final Dictionary DICTIONARY_HARDCODED = public static final PhonyDictionary DICTIONARY_HARDCODED =
new PhonyDictionary(TYPE_HARDCODED); new PhonyDictionary(TYPE_HARDCODED);
// Spawned by resuming suggestions. Comes from a span that was in the TextView. // Spawned by resuming suggestions. Comes from a span that was in the TextView.
public static final String TYPE_RESUMED = "resumed"; public static final String TYPE_RESUMED = "resumed";
public static final Dictionary DICTIONARY_RESUMED = public static final PhonyDictionary DICTIONARY_RESUMED =
new PhonyDictionary(TYPE_RESUMED); new PhonyDictionary(TYPE_RESUMED);
// The following types of dictionary have actual functional instances. We don't need final // The following types of dictionary have actual functional instances. We don't need final
@ -182,9 +183,10 @@ public abstract class Dictionary {
* Not a true dictionary. A placeholder used to indicate suggestions that don't come from any * Not a true dictionary. A placeholder used to indicate suggestions that don't come from any
* real dictionary. * real dictionary.
*/ */
private static class PhonyDictionary extends Dictionary { @UsedForTesting
// This class is not publicly instantiable. static class PhonyDictionary extends Dictionary {
private PhonyDictionary(final String type) { @UsedForTesting
PhonyDictionary(final String type) {
super(type, null); super(type, null);
} }

View file

@ -257,6 +257,12 @@ public class DictionaryFacilitator {
} }
public void switchMostProbableLanguage(final Locale locale) { public void switchMostProbableLanguage(final Locale locale) {
if (null == locale) {
// In many cases, there is no locale to a committed word. For example, a typed word
// that does not auto-correct has no locale. In this case we simply do not change
// the most probable language.
return;
}
final DictionaryGroup newMostProbableDictionaryGroup = final DictionaryGroup newMostProbableDictionaryGroup =
findDictionaryGroupWithLocale(mDictionaryGroups, locale); findDictionaryGroupWithLocale(mDictionaryGroups, locale);
mMostProbableDictionaryGroup.mWeightForTypingInLocale = mMostProbableDictionaryGroup.mWeightForTypingInLocale =

View file

@ -305,6 +305,7 @@ public final class InputLogic {
currentKeyboardScriptId, handler); currentKeyboardScriptId, handler);
} }
mDictionaryFacilitator.switchMostProbableLanguage(suggestionInfo.mSourceDict.mLocale);
final Event event = Event.createSuggestionPickedEvent(suggestionInfo); final Event event = Event.createSuggestionPickedEvent(suggestionInfo);
final InputTransaction inputTransaction = new InputTransaction(settingsValues, final InputTransaction inputTransaction = new InputTransaction(settingsValues,
event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState); event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState);
@ -2100,6 +2101,10 @@ public final class InputLogic {
final boolean isBatchMode = mWordComposer.isBatchMode(); final boolean isBatchMode = mWordComposer.isBatchMode();
commitChosenWord(settingsValues, stringToCommit, commitChosenWord(settingsValues, stringToCommit,
LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separator); LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separator);
if (null != autoCorrectionOrNull) {
mDictionaryFacilitator.switchMostProbableLanguage(
autoCorrectionOrNull.mSourceDict.mLocale);
}
if (!typedWord.equals(stringToCommit)) { if (!typedWord.equals(stringToCommit)) {
// This will make the correction flash for a short while as a visual clue // This will make the correction flash for a short while as a visual clue
// to the user that auto-correction happened. It has no other effect; in particular // to the user that auto-correction happened. It has no other effect; in particular

View file

@ -39,6 +39,8 @@ import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.event.Event; import com.android.inputmethod.event.Event;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.Dictionary.PhonyDictionary;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.settings.DebugSettings; import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
@ -61,6 +63,10 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200; protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200;
private final int TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS = 60; private final int TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS = 60;
// Type for a test phony dictionary
private static final String TYPE_TEST = "test";
private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST);
protected LatinIME mLatinIME; protected LatinIME mLatinIME;
protected Keyboard mKeyboard; protected Keyboard mKeyboard;
protected MyEditText mEditText; protected MyEditText mEditText;
@ -353,7 +359,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected void pickSuggestionManually(final String suggestion) { protected void pickSuggestionManually(final String suggestion) {
mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion, 1, mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion, 1,
SuggestedWordInfo.KIND_CORRECTION, null /* sourceDict */, SuggestedWordInfo.KIND_CORRECTION, DICTIONARY_TEST,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */)); SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
} }