Consolidate two methods (A68)

Change-Id: I4b91414190b3786065ebd962a76299b605e5797e
This commit is contained in:
Jean Chalard 2012-07-06 11:31:52 +09:00
parent 146bd2e456
commit 8f9c9377fc

View file

@ -217,12 +217,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
} }
// isComposing is always true public void postUpdateSuggestionStrip(final boolean isComposing) {
public void postUpdateSuggestions(final boolean isComposing) {
// TODO: remove this test
if (!isComposing) throw new RuntimeException("We are not composing a word");
cancelUpdateSuggestionStrip(); cancelUpdateSuggestionStrip();
if (isComposing) {
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions); sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions);
} else {
sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS),
mDelayUpdateSuggestions);
}
} }
public void cancelUpdateSuggestionStrip() { public void cancelUpdateSuggestionStrip() {
@ -243,14 +245,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
removeMessages(MSG_UPDATE_SHIFT_STATE); removeMessages(MSG_UPDATE_SHIFT_STATE);
} }
// isComposing is always false
public void postUpdateBigramPredictions(final boolean isComposing) {
// TODO: remove this test
if (isComposing) throw new RuntimeException("We are composing a word");
cancelUpdateSuggestionStrip();
sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), mDelayUpdateSuggestions);
}
public void startDoubleSpacesTimer() { public void startDoubleSpacesTimer() {
mDoubleSpaceTimerStart = SystemClock.uptimeMillis(); mDoubleSpaceTimerStart = SystemClock.uptimeMillis();
} }
@ -1400,15 +1394,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mWordComposer.deleteLast(); mWordComposer.deleteLast();
} }
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
// If we have deleted the last remaining character of a word, then we are not mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
// isComposingWord() any more.
if (!mWordComposer.isComposingWord()) {
// Not composing word any more, so we can show bigrams.
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
} else {
// Still composing a word, so we still have letters to deduce a suggestion from.
mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
}
} else { } else {
mConnection.deleteSurroundingText(1, 0); mConnection.deleteSurroundingText(1, 0);
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
@ -1551,8 +1537,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF); getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
} }
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
// We just added a character, so isComposingWord() is true
mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
} else { } else {
final boolean swapWeakSpace = maybeStripSpace(primaryCode, final boolean swapWeakSpace = maybeStripSpace(primaryCode,
spaceState, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x); spaceState, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
@ -1563,14 +1547,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
swapSwapperAndSpace(); swapSwapperAndSpace();
mSpaceState = SPACE_STATE_WEAK; mSpaceState = SPACE_STATE_WEAK;
} }
// We may need to update predictions, if the "add to dictionary" hint was displayed // In case the "add to dictionary" hint was still displayed.
// for example.
if (null != mSuggestionsView) mSuggestionsView.dismissAddToDictionaryHint(); if (null != mSuggestionsView) mSuggestionsView.dismissAddToDictionaryHint();
// Here we know we are not composing a word: if we were, then we can't come here because
// isComposingWord is still true; if we weren't, and we now are, then isComposingWord
// has been turned to true, so we can't come here either.
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
} }
mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
Utils.Stats.onNonSeparator((char)primaryCode, x, y); Utils.Stats.onNonSeparator((char)primaryCode, x, y);
} }
@ -1612,9 +1592,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.startDoubleSpacesTimer(); mHandler.startDoubleSpacesTimer();
if (!mConnection.isCursorTouchingWord(mCurrentSettings)) { if (!mConnection.isCursorTouchingWord(mCurrentSettings)) {
// We know mWordComposer.isComposingWord() is false here, since if it was true, mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
// we committed the text, making it false.
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
} }
} else { } else {
if (swapWeakSpace) { if (swapWeakSpace) {
@ -1898,10 +1876,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) { if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) {
mSuggestionsView.showAddToDictionaryHint(suggestion, mCurrentSettings.mHintToSaveText); mSuggestionsView.showAddToDictionaryHint(suggestion, mCurrentSettings.mHintToSaveText);
} else { } else {
// If we're not showing the "Touch again to save", then show predictions. // If we're not showing the "Touch again to save", then update the suggestion strip.
// We just called commitChosenWord, which ensures mWordComposer#isComposingWord() mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
// returns false.
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
} }
} }
@ -1993,8 +1969,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ResearchLogger.latinIME_deleteSurroundingText(length); ResearchLogger.latinIME_deleteSurroundingText(length);
} }
mConnection.setComposingText(word, 1); mConnection.setComposingText(word, 1);
// We just set a composing word, so isComposingWord() is true mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
} }
private void revertCommit() { private void revertCommit() {
@ -2039,9 +2014,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// separator. // separator.
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
// We have a separator between the word and the cursor: we should show predictions. // We have a separator between the word and the cursor: we should show predictions.
// We know we are not composing a word here (there is even a test that throws an exception mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
// in debug mode in here)
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
} }
public boolean isWordSeparator(int code) { public boolean isWordSeparator(int code) {
@ -2065,12 +2038,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
loadSettings(); loadSettings();
// Since we just changed languages, we should re-evaluate suggestions with whatever word // Since we just changed languages, we should re-evaluate suggestions with whatever word
// we are currently composing. If we are not composing anything, we may want to display // we are currently composing. If we are not composing anything, we may want to display
// predictions or punctuation signs (which is done by updateBigramPredictions anyway). // predictions or punctuation signs (which is done by the updateSuggestionStrip anyway).
if (mWordComposer.isComposingWord()) { mHandler.postUpdateSuggestionStrip(mWordComposer.isComposingWord());
mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
} else {
mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
}
} }
// TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to // TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to