Add showSuggestionStripWithTypedWord.
Bug: 10814472 Change-Id: I3a150124baf7a9b7889b033089a859ff9c11e206
This commit is contained in:
parent
80f934af54
commit
a469743e33
1 changed files with 49 additions and 15 deletions
|
@ -46,6 +46,7 @@ import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.SuggestionSpan;
|
import android.text.style.SuggestionSpan;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
import android.util.PrintWriterPrinter;
|
import android.util.PrintWriterPrinter;
|
||||||
import android.util.Printer;
|
import android.util.Printer;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
|
@ -236,6 +237,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
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;
|
||||||
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
|
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
|
||||||
|
private static final int ARG2_WITHOUT_TYPED_WORD = 0;
|
||||||
|
private static final int ARG2_WITH_TYPED_WORD = 1;
|
||||||
|
|
||||||
private int mDelayUpdateSuggestions;
|
private int mDelayUpdateSuggestions;
|
||||||
private int mDelayUpdateShiftState;
|
private int mDelayUpdateShiftState;
|
||||||
|
@ -269,7 +272,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
break;
|
break;
|
||||||
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
||||||
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
|
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
|
||||||
latinIme.showSuggestionStrip((SuggestedWords) msg.obj);
|
if (msg.arg2 == ARG2_WITH_TYPED_WORD) {
|
||||||
|
final Pair<SuggestedWords, String> p =
|
||||||
|
(Pair<SuggestedWords, String>) msg.obj;
|
||||||
|
latinIme.showSuggestionStripWithTypedWord(p.first, p.second);
|
||||||
|
} else {
|
||||||
|
latinIme.showSuggestionStrip((SuggestedWords) msg.obj);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
|
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
|
||||||
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
|
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
|
||||||
|
@ -331,14 +340,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final int arg1 = dismissGestureFloatingPreviewText
|
final int arg1 = dismissGestureFloatingPreviewText
|
||||||
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT
|
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT
|
||||||
: ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT;
|
: ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT;
|
||||||
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, arg1, 0, suggestedWords)
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, arg1,
|
||||||
.sendToTarget();
|
ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
||||||
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
||||||
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP,
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP,
|
||||||
ARG1_NOT_GESTURE_INPUT, 0, suggestedWords).sendToTarget();
|
ARG1_NOT_GESTURE_INPUT, ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
|
public void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
|
||||||
|
final String typedWord) {
|
||||||
|
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
||||||
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, ARG1_NOT_GESTURE_INPUT,
|
||||||
|
ARG2_WITH_TYPED_WORD,
|
||||||
|
new Pair<SuggestedWords, String>(suggestedWords, typedWord)).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEndBatchInput(final SuggestedWords suggestedWords) {
|
public void onEndBatchInput(final SuggestedWords suggestedWords) {
|
||||||
|
@ -2468,27 +2486,39 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
false /* isPrediction */);
|
false /* isPrediction */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAutoCorrection(final SuggestedWords suggestedWords) {
|
private void setAutoCorrection(final SuggestedWords suggestedWords, final String typedWord) {
|
||||||
if (suggestedWords.isEmpty()) return;
|
if (suggestedWords.isEmpty()) return;
|
||||||
final String autoCorrection;
|
final String autoCorrection;
|
||||||
if (suggestedWords.mWillAutoCorrect) {
|
if (suggestedWords.mWillAutoCorrect) {
|
||||||
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
|
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
|
||||||
} else {
|
} else {
|
||||||
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD);
|
// We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
|
||||||
|
// because it may differ from mWordComposer.mTypedWord.
|
||||||
|
autoCorrection = typedWord;
|
||||||
}
|
}
|
||||||
mWordComposer.setAutoCorrection(autoCorrection);
|
mWordComposer.setAutoCorrection(autoCorrection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
|
||||||
|
final String typedWord) {
|
||||||
|
if (suggestedWords.isEmpty()) {
|
||||||
|
clearSuggestionStrip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAutoCorrection(suggestedWords, typedWord);
|
||||||
|
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
||||||
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
||||||
|
setAutoCorrectionIndicator(isAutoCorrection);
|
||||||
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||||
|
}
|
||||||
|
|
||||||
private void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
private void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
||||||
if (suggestedWords.isEmpty()) {
|
if (suggestedWords.isEmpty()) {
|
||||||
clearSuggestionStrip();
|
clearSuggestionStrip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setAutoCorrection(suggestedWords);
|
showSuggestionStripWithTypedWord(suggestedWords,
|
||||||
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
|
||||||
setSuggestedWords(suggestedWords, isAutoCorrection);
|
|
||||||
setAutoCorrectionIndicator(isAutoCorrection);
|
|
||||||
setSuggestionStripShown(isSuggestionsStripVisible());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commitCurrentAutoCorrection(final String separator) {
|
private void commitCurrentAutoCorrection(final String separator) {
|
||||||
|
@ -2766,7 +2796,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// Since there is only one word, willAutoCorrect is false.
|
// Since there is only one word, willAutoCorrect is false.
|
||||||
suggestedWords = suggestedWordsIncludingTypedWord;
|
suggestedWords = suggestedWordsIncludingTypedWord;
|
||||||
}
|
}
|
||||||
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords);
|
// We need to pass typedWord because mWordComposer.mTypedWord may differ from
|
||||||
|
// typedWord.
|
||||||
|
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords,
|
||||||
|
typedWord);
|
||||||
}});
|
}});
|
||||||
} else {
|
} else {
|
||||||
// We found suggestion spans in the word. We'll create the SuggestedWords out of
|
// We found suggestion spans in the word. We'll create the SuggestedWords out of
|
||||||
|
@ -2775,12 +2808,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
true /* typedWordValid */, false /* willAutoCorrect */,
|
true /* typedWordValid */, false /* willAutoCorrect */,
|
||||||
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
|
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
|
||||||
false /* isPrediction */);
|
false /* isPrediction */);
|
||||||
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords);
|
// We need to pass typedWord because mWordComposer.mTypedWord may differ from typedWord.
|
||||||
|
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords, typedWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
|
public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
|
||||||
final SuggestedWords suggestedWords) {
|
final SuggestedWords suggestedWords, final String typedWord) {
|
||||||
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
|
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
|
||||||
// We never want to auto-correct on a resumed suggestion. Please refer to the three places
|
// We never want to auto-correct on a resumed suggestion. Please refer to the three places
|
||||||
// above in restartSuggestionsOnWordTouchedByCursor() where suggestedWords is affected.
|
// above in restartSuggestionsOnWordTouchedByCursor() where suggestedWords is affected.
|
||||||
|
@ -2788,7 +2822,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// the text to adapt it.
|
// the text to adapt it.
|
||||||
// TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
|
// TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
|
||||||
mIsAutoCorrectionIndicatorOn = false;
|
mIsAutoCorrectionIndicatorOn = false;
|
||||||
mHandler.showSuggestionStrip(suggestedWords);
|
mHandler.showSuggestionStripWithTypedWord(suggestedWords, typedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue