Show last valid suggestions when gesture typing gets no suggestion

Bug: 7679566
Change-Id: Ie68c7698144c7576b5814ee35664309bcfdcbf0f
This commit is contained in:
Tadashi G. Takaoka 2012-12-17 15:11:44 +09:00
parent b808188b2f
commit f21a491ad8

View file

@ -1462,7 +1462,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
@Override @Override
public void onStartBatchInput() { public void onStartBatchInput() {
BatchInputUpdater.getInstance().onStartBatchInput(); BatchInputUpdater.getInstance().onStartBatchInput(this);
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) { if (mWordComposer.isComposingWord()) {
if (ProductionFlag.IS_INTERNAL) { if (ProductionFlag.IS_INTERNAL) {
@ -1528,34 +1528,32 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
public boolean handleMessage(final Message msg) { public boolean handleMessage(final Message msg) {
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP: case MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
updateBatchInput((InputPointers)msg.obj, mLatinIme); updateBatchInput((InputPointers)msg.obj);
break; break;
} }
return true; return true;
} }
// Run in the UI thread. // Run in the UI thread.
public synchronized void onStartBatchInput() { public synchronized void onStartBatchInput(final LatinIME latinIme) {
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP); mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
mLatinIme = latinIme;
mInBatchInput = true; mInBatchInput = true;
} }
// Run in the Handler thread. // Run in the Handler thread.
private synchronized void updateBatchInput(final InputPointers batchPointers, private synchronized void updateBatchInput(final InputPointers batchPointers) {
final LatinIME latinIme) {
if (!mInBatchInput) { if (!mInBatchInput) {
// Batch input has ended or canceled while the message was being delivered. // Batch input has ended or canceled while the message was being delivered.
return; return;
} }
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked( final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
batchPointers, latinIme); mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
latinIme.mHandler.showGesturePreviewAndSuggestionStrip(
suggestedWords, false /* dismissGestureFloatingPreviewText */); suggestedWords, false /* dismissGestureFloatingPreviewText */);
} }
// Run in the UI thread. // Run in the UI thread.
public void onUpdateBatchInput(final InputPointers batchPointers, final LatinIME latinIme) { public void onUpdateBatchInput(final InputPointers batchPointers) {
mLatinIme = latinIme;
if (mHandler.hasMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP)) { if (mHandler.hasMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP)) {
return; return;
} }
@ -1564,29 +1562,34 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
.sendToTarget(); .sendToTarget();
} }
public synchronized void onCancelBatchInput(final LatinIME latinIme) { public synchronized void onCancelBatchInput() {
mInBatchInput = false; mInBatchInput = false;
latinIme.mHandler.showGesturePreviewAndSuggestionStrip( mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */); SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */);
} }
// Run in the UI thread. // Run in the UI thread.
public synchronized SuggestedWords onEndBatchInput(final InputPointers batchPointers, public synchronized SuggestedWords onEndBatchInput(final InputPointers batchPointers) {
final LatinIME latinIme) {
mInBatchInput = false; mInBatchInput = false;
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked( final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
batchPointers, latinIme); mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
latinIme.mHandler.showGesturePreviewAndSuggestionStrip(
suggestedWords, true /* dismissGestureFloatingPreviewText */); suggestedWords, true /* dismissGestureFloatingPreviewText */);
return suggestedWords; return suggestedWords;
} }
// {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to // {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to
// be synchronized. // be synchronized.
private static SuggestedWords getSuggestedWordsGestureLocked( private SuggestedWords getSuggestedWordsGestureLocked(final InputPointers batchPointers) {
final InputPointers batchPointers, final LatinIME latinIme) { mLatinIme.mWordComposer.setBatchInputPointers(batchPointers);
latinIme.mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords =
return latinIme.getSuggestedWords(Suggest.SESSION_GESTURE); mLatinIme.getSuggestedWords(Suggest.SESSION_GESTURE);
final int suggestionCount = suggestedWords.size();
if (suggestionCount <= 1) {
final String mostProbableSuggestion = (suggestionCount == 0) ? null
: suggestedWords.getWord(0);
return mLatinIme.getOlderSuggestions(mostProbableSuggestion);
}
return suggestedWords;
} }
} }
@ -1605,13 +1608,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
@Override @Override
public void onUpdateBatchInput(final InputPointers batchPointers) { public void onUpdateBatchInput(final InputPointers batchPointers) {
BatchInputUpdater.getInstance().onUpdateBatchInput(batchPointers, this); BatchInputUpdater.getInstance().onUpdateBatchInput(batchPointers);
} }
@Override @Override
public void onEndBatchInput(final InputPointers batchPointers) { public void onEndBatchInput(final InputPointers batchPointers) {
final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput( final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput(
batchPointers, this); batchPointers);
final String batchInputText = suggestedWords.isEmpty() final String batchInputText = suggestedWords.isEmpty()
? null : suggestedWords.getWord(0); ? null : suggestedWords.getWord(0);
if (TextUtils.isEmpty(batchInputText)) { if (TextUtils.isEmpty(batchInputText)) {
@ -1658,7 +1661,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
@Override @Override
public void onCancelBatchInput() { public void onCancelBatchInput() {
BatchInputUpdater.getInstance().onCancelBatchInput(this); BatchInputUpdater.getInstance().onCancelBatchInput();
} }
private void handleBackspace(final int spaceState) { private void handleBackspace(final int spaceState) {
@ -2024,22 +2027,28 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|| mSuggestionStripView.isShowingAddToDictionaryHint()) { || mSuggestionStripView.isShowingAddToDictionaryHint()) {
return suggestedWords; return suggestedWords;
} else { } else {
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions(); return getOlderSuggestions(typedWord);
if (previousSuggestions == mCurrentSettings.mSuggestPuncList) {
previousSuggestions = SuggestedWords.EMPTY;
}
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(
typedWord, previousSuggestions);
return new SuggestedWords(typedWordAndPreviousSuggestions,
false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */,
false /* isPunctuationSuggestions */,
true /* isObsoleteSuggestions */,
false /* isPrediction */);
} }
} }
private SuggestedWords getOlderSuggestions(final String typedWord) {
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
if (previousSuggestions == mCurrentSettings.mSuggestPuncList) {
previousSuggestions = SuggestedWords.EMPTY;
}
if (typedWord == null) {
return previousSuggestions;
}
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
return new SuggestedWords(typedWordAndPreviousSuggestions,
false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */,
false /* isPunctuationSuggestions */,
true /* isObsoleteSuggestions */,
false /* isPrediction */);
}
private void showSuggestionStrip(final SuggestedWords suggestedWords, final String typedWord) { private void showSuggestionStrip(final SuggestedWords suggestedWords, final String typedWord) {
if (suggestedWords.isEmpty()) { if (suggestedWords.isEmpty()) {
clearSuggestionStrip(); clearSuggestionStrip();