Merge "Fix a unit test"

main
Jean Chalard 2014-07-01 09:22:45 +00:00 committed by Android (Google) Code Review
commit e063e1b218
3 changed files with 52 additions and 14 deletions

View File

@ -112,6 +112,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final int PENDING_IMS_CALLBACK_DURATION = 800; private static final int PENDING_IMS_CALLBACK_DURATION = 800;
private static final int DELAY_WAIT_FOR_DICTIONARY_LOAD = 2000; // 2s
private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2; private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2;
/** /**
@ -171,8 +173,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static final int MSG_REOPEN_DICTIONARIES = 5; private static final int MSG_REOPEN_DICTIONARIES = 5;
private static final int MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED = 6; private static final int MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED = 6;
private static final int MSG_RESET_CACHES = 7; private static final int MSG_RESET_CACHES = 7;
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
// Update this when adding new messages // Update this when adding new messages
private static final int MSG_LAST = MSG_RESET_CACHES; private static final int MSG_LAST = MSG_WAIT_FOR_DICTIONARY_LOAD;
private static final int ARG1_NOT_GESTURE_INPUT = 0; private static final int ARG1_NOT_GESTURE_INPUT = 0;
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
@ -234,7 +237,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
latinIme.resetSuggest(); latinIme.resetSuggest();
// We need to re-evaluate the currently composing word in case the script has // We need to re-evaluate the currently composing word in case the script has
// changed. // changed.
postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */); postWaitForDictionaryLoad();
break; break;
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED: case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
latinIme.mInputLogic.onUpdateTailBatchInputCompleted( latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
@ -253,6 +256,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
latinIme.getCurrentRecapitalizeState()); latinIme.getCurrentRecapitalizeState());
} }
break; break;
case MSG_WAIT_FOR_DICTIONARY_LOAD:
Log.i(TAG, "Timeout waiting for dictionary load");
break;
} }
} }
@ -264,7 +270,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES)); sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
} }
public void postResumeSuggestions(final boolean shouldIncludeResumedWordInSuggestions) { public void postResumeSuggestions(final boolean shouldIncludeResumedWordInSuggestions,
final boolean shouldDelay) {
final LatinIME latinIme = getOwnerInstance(); final LatinIME latinIme = getOwnerInstance();
if (latinIme == null) { if (latinIme == null) {
return; return;
@ -274,10 +281,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return; return;
} }
removeMessages(MSG_RESUME_SUGGESTIONS); removeMessages(MSG_RESUME_SUGGESTIONS);
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS, if (shouldDelay) {
shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE, sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS,
0 /* ignored */), shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE,
mDelayUpdateSuggestions); 0 /* ignored */),
mDelayUpdateSuggestions);
} else {
sendMessage(obtainMessage(MSG_RESUME_SUGGESTIONS,
shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE,
0 /* ignored */));
}
} }
public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) { public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
@ -286,6 +299,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
remainingTries, null)); remainingTries, null));
} }
public void postWaitForDictionaryLoad() {
sendMessageDelayed(obtainMessage(MSG_WAIT_FOR_DICTIONARY_LOAD),
DELAY_WAIT_FOR_DICTIONARY_LOAD);
}
public void cancelWaitForDictionaryLoad() {
removeMessages(MSG_WAIT_FOR_DICTIONARY_LOAD);
}
public boolean hasPendingWaitForDictionaryLoad() {
return hasMessages(MSG_WAIT_FOR_DICTIONARY_LOAD);
}
public void cancelUpdateSuggestionStrip() { public void cancelUpdateSuggestionStrip() {
removeMessages(MSG_UPDATE_SUGGESTION_STRIP); removeMessages(MSG_UPDATE_SUGGESTION_STRIP);
} }
@ -582,6 +608,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mainKeyboardView != null) { if (mainKeyboardView != null) {
mainKeyboardView.setMainDictionaryAvailability(isMainDictionaryAvailable); mainKeyboardView.setMainDictionaryAvailability(isMainDictionaryAvailable);
} }
if (mHandler.hasPendingWaitForDictionaryLoad()) {
mHandler.cancelWaitForDictionaryLoad();
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
false /* shouldDelay */);
}
} }
private void resetSuggest() { private void resetSuggest() {
@ -821,7 +852,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
// effort to work around this bug. // effort to work around this bug.
mInputLogic.mConnection.tryFixLyingCursorPosition(); mInputLogic.mConnection.tryFixLyingCursorPosition();
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */); mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
true /* shouldDelay */);
canReachInputConnection = true; canReachInputConnection = true;
} }

View File

@ -362,7 +362,8 @@ public final class InputLogic {
// The cursor has been moved : we now accept to perform recapitalization // The cursor has been moved : we now accept to perform recapitalization
mRecapitalizeStatus.enable(); mRecapitalizeStatus.enable();
// We moved the cursor. If we are touching a word, we need to resume suggestion. // We moved the cursor. If we are touching a word, we need to resume suggestion.
mLatinIME.mHandler.postResumeSuggestions(false /* shouldIncludeResumedWordInSuggestions */); mLatinIME.mHandler.postResumeSuggestions(false /* shouldIncludeResumedWordInSuggestions */,
true /* shouldDelay */);
// Stop the last recapitalization, if started. // Stop the last recapitalization, if started.
mRecapitalizeStatus.stop(); mRecapitalizeStatus.stop();
return true; return true;
@ -1950,7 +1951,8 @@ public final class InputLogic {
if (tryResumeSuggestions) { if (tryResumeSuggestions) {
// This is triggered when starting input anew, so we want to include the resumed // This is triggered when starting input anew, so we want to include the resumed
// word in suggestions. // word in suggestions.
handler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */); handler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
true /* shouldDelay */);
} }
return true; return true;
} }

View File

@ -626,13 +626,17 @@ public class InputLogicTests extends InputTestsBase {
public void testSwitchLanguages() { public void testSwitchLanguages() {
final String WORD_TO_TYPE_FIRST_PART = "com"; final String WORD_TO_TYPE_FIRST_PART = "com";
final String WORD_TO_TYPE_SECOND_PART = "md "; final String WORD_TO_TYPE_SECOND_PART = "md";
final String EXPECTED_RESULT = "comme "; final String EXPECTED_RESULT = "comme";
changeLanguage("en"); changeLanguage("en");
type(WORD_TO_TYPE_FIRST_PART); type(WORD_TO_TYPE_FIRST_PART);
changeLanguage("fr"); changeLanguage("fr");
runMessages();
type(WORD_TO_TYPE_SECOND_PART); type(WORD_TO_TYPE_SECOND_PART);
assertEquals("Composing continues after switching languages", EXPECTED_RESULT, sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
mEditText.getText().toString()); runMessages();
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("Suggestions updated after switching languages",
EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(1) : null);
} }
} }