aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java109
1 files changed, 58 insertions, 51 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index f2f9f1e68..0e4374aa3 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -74,7 +74,7 @@ public final class InputLogic {
// TODO : make all these fields private as soon as possible.
// Current space state of the input method. This can be any of the above constants.
- public int mSpaceState;
+ private int mSpaceState;
// Never null
public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
// TODO: mSuggest should be touched by a single thread.
@@ -85,7 +85,7 @@ public final class InputLogic {
public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
public final WordComposer mWordComposer;
public final RichInputConnection mConnection;
- public final RecapitalizeStatus mRecapitalizeStatus = new RecapitalizeStatus();
+ private final RecapitalizeStatus mRecapitalizeStatus = new RecapitalizeStatus();
private int mDeleteCount;
private long mLastKeyTime;
@@ -96,7 +96,7 @@ public final class InputLogic {
// TODO: This boolean is persistent state and causes large side effects at unexpected times.
// Find a way to remove it for readability.
- public boolean mIsAutoCorrectionIndicatorOn;
+ private boolean mIsAutoCorrectionIndicatorOn;
public InputLogic(final LatinIME latinIME,
final SuggestionStripViewAccessor suggestionStripViewAccessor) {
@@ -227,17 +227,16 @@ public final class InputLogic {
}
}
- // TODO: stop relying on mApplicationSpecifiedCompletions. The SuggestionInfo object
- // should contain a reference to the CompletionInfo instead.
- if (settingsValues.isApplicationSpecifiedCompletionsOn()
- && mLatinIME.mApplicationSpecifiedCompletions != null
- && index >= 0 && index < mLatinIME.mApplicationSpecifiedCompletions.length) {
+ // TODO: We should not need the following branch. We should be able to take the same
+ // code path as for other kinds, use commitChosenWord, and do everything normally. We will
+ // however need to reset the suggestion strip right away, because we know we can't take
+ // the risk of calling commitCompletion twice because we don't know how the app will react.
+ if (SuggestedWordInfo.KIND_APP_DEFINED == suggestionInfo.mKind) {
mSuggestedWords = SuggestedWords.EMPTY;
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
keyboardSwitcher.updateShiftState();
resetComposingState(true /* alsoResetLastComposedWord */);
- final CompletionInfo completionInfo = mLatinIME.mApplicationSpecifiedCompletions[index];
- mConnection.commitCompletion(completionInfo);
+ mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo);
mConnection.endBatchEdit();
return;
}
@@ -290,19 +289,14 @@ public final class InputLogic {
* Consider an update to the cursor position. Evaluate whether this update has happened as
* part of normal typing or whether it was an explicit cursor move by the user. In any case,
* do the necessary adjustments.
- * @param settingsValues the current settings
* @param oldSelStart old selection start
* @param oldSelEnd old selection end
* @param newSelStart new selection start
* @param newSelEnd new selection end
- * @param composingSpanStart composing span start
- * @param composingSpanEnd composing span end
* @return whether the cursor has moved as a result of user interaction.
*/
- public boolean onUpdateSelection(final SettingsValues settingsValues,
- final int oldSelStart, final int oldSelEnd,
- final int newSelStart, final int newSelEnd,
- final int composingSpanStart, final int composingSpanEnd) {
+ public boolean onUpdateSelection(final int oldSelStart, final int oldSelEnd,
+ final int newSelStart, final int newSelEnd) {
if (mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart, oldSelEnd, newSelEnd)) {
return false;
}
@@ -335,8 +329,7 @@ public final class InputLogic {
// we'd have the suggestion strip noticeably janky. To avoid that, we don't clear
// it here, which means we'll keep outdated suggestions for a split second but the
// visual result is better.
- resetEntireInputState(settingsValues, newSelStart, newSelEnd,
- false /* clearSuggestionStrip */);
+ resetEntireInputState(newSelStart, newSelEnd, false /* clearSuggestionStrip */);
} else {
// resetEntireInputState calls resetCachesUponCursorMove, but forcing the
// composition to end. But in all cases where we don't reset the entire input
@@ -504,7 +497,7 @@ public final class InputLogic {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the batch input at the current cursor position.
- resetEntireInputState(settingsValues, mConnection.getExpectedSelectionStart(),
+ resetEntireInputState(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */);
} else if (wordComposerSize <= 1) {
// We auto-correct the previous (typed, not gestured) string iff it's one character
@@ -585,8 +578,7 @@ public final class InputLogic {
mInputLogicHandler.onUpdateBatchInput(batchPointers, mAutoCommitSequenceNumber);
}
- public void onEndBatchInput(final SettingsValues settingValues,
- final InputPointers batchPointers) {
+ public void onEndBatchInput(final InputPointers batchPointers) {
mInputLogicHandler.onEndBatchInput(batchPointers, mAutoCommitSequenceNumber);
++mAutoCommitSequenceNumber;
}
@@ -658,7 +650,7 @@ public final class InputLogic {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the character at the current cursor position.
- resetEntireInputState(settingsValues, mConnection.getExpectedSelectionStart(),
+ resetEntireInputState(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */);
} else {
commitTyped(settingsValues, LastComposedWord.NOT_A_SEPARATOR);
@@ -700,7 +692,7 @@ public final class InputLogic {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the character at the current cursor position.
- resetEntireInputState(settingsValues, mConnection.getExpectedSelectionStart(),
+ resetEntireInputState(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */);
isComposingWord = false;
}
@@ -782,7 +774,7 @@ public final class InputLogic {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can insert the separator at the current cursor position.
- resetEntireInputState(settingsValues, mConnection.getExpectedSelectionStart(),
+ resetEntireInputState(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */);
}
// isComposingWord() may have changed since we stored wasComposing
@@ -877,7 +869,6 @@ public final class InputLogic {
// TODO: remove these arguments
final LatinIME.UIHandler handler, final KeyboardSwitcher keyboardSwitcher) {
mSpaceState = SpaceState.NONE;
- final int deleteCountAtStart = mDeleteCount;
mDeleteCount++;
// In many cases, we may have to put the keyboard in auto-shift state again. However
@@ -888,7 +879,7 @@ public final class InputLogic {
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
// If we are in the middle of a recorrection, we need to commit the recorrection
// first so that we can remove the character at the current cursor position.
- resetEntireInputState(settingsValues, mConnection.getExpectedSelectionStart(),
+ resetEntireInputState(mConnection.getExpectedSelectionStart(),
mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */);
// When we exit this if-clause, mWordComposer.isComposingWord() will return false.
}
@@ -1205,11 +1196,7 @@ public final class InputLogic {
timeStampInSeconds);
}
- public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
- // TODO: Remove this argument
- final LatinIME.UIHandler handler) {
- handler.cancelUpdateSuggestionStrip();
-
+ public void performUpdateSuggestionStripSync(final SettingsValues settingsValues) {
// Check if we have a suggestion engine attached.
if (mSuggest == null || !settingsValues.isSuggestionsRequested()) {
if (mWordComposer.isComposingWord()) {
@@ -1229,11 +1216,15 @@ public final class InputLogic {
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
- final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
- mLatinIME.maybeRetrieveOlderSuggestions(
- mWordComposer.getTypedWord(), suggestedWords,
- mSuggestedWords);
- holder.set(suggestedWordsWithMaybeOlderSuggestions);
+ final String typedWord = mWordComposer.getTypedWord();
+ // Show new suggestions if we have at least one. Otherwise keep the old
+ // suggestions with the new typed word. Exception: if the length of the
+ // typed word is <= 1 (after a deletion typically) we clear old suggestions.
+ if (suggestedWords.size() > 1 || typedWord.length() <= 1) {
+ holder.set(suggestedWords);
+ } else {
+ holder.set(retrieveOlderSuggestions(typedWord, mSuggestedWords));
+ }
}
}
);
@@ -1623,15 +1614,13 @@ public final class InputLogic {
* This will clear the composing word, reset the last composed word, clear the suggestion
* strip and tell the input connection about it so that it can refresh its caches.
*
- * @param settingsValues the current values of the settings.
* @param newSelStart the new selection start, in java characters.
* @param newSelEnd the new selection end, in java characters.
* @param clearSuggestionStrip whether this method should clear the suggestion strip.
*/
// TODO: how is this different from startInput ?!
- // TODO: remove all references to this in LatinIME and make this private
- public void resetEntireInputState(final SettingsValues settingsValues,
- final int newSelStart, final int newSelEnd, final boolean clearSuggestionStrip) {
+ private void resetEntireInputState(final int newSelStart, final int newSelEnd,
+ final boolean clearSuggestionStrip) {
final boolean shouldFinishComposition = mWordComposer.isComposingWord();
resetComposingState(true /* alsoResetLastComposedWord */);
if (clearSuggestionStrip) {
@@ -1649,8 +1638,7 @@ public final class InputLogic {
*
* @param alsoResetLastComposedWord whether to also reset the last composed word.
*/
- // TODO: remove all references to this in LatinIME and make this private.
- public void resetComposingState(final boolean alsoResetLastComposedWord) {
+ private void resetComposingState(final boolean alsoResetLastComposedWord) {
mWordComposer.reset();
if (alsoResetLastComposedWord) {
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
@@ -1658,6 +1646,27 @@ public final class InputLogic {
}
/**
+ * Make a {@link com.android.inputmethod.latin.SuggestedWords} object containing a typed word
+ * and obsolete suggestions.
+ * See {@link com.android.inputmethod.latin.SuggestedWords#getTypedWordAndPreviousSuggestions(
+ * String, com.android.inputmethod.latin.SuggestedWords)}.
+ * @param typedWord The typed word as a string.
+ * @param previousSuggestedWords The previously suggested words.
+ * @return Obsolete suggestions with the newly typed word.
+ */
+ private SuggestedWords retrieveOlderSuggestions(final String typedWord,
+ final SuggestedWords previousSuggestedWords) {
+ final SuggestedWords oldSuggestedWords =
+ previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY
+ : previousSuggestedWords;
+ final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
+ SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
+ return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
+ false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
+ true /* isObsoleteSuggestions */, false /* isPrediction */);
+ }
+
+ /**
* Gets a chunk of text with or the auto-correction indicator underline span as appropriate.
*
* This method looks at the old state of the auto-correction indicator to put or not put
@@ -1674,9 +1683,8 @@ public final class InputLogic {
* @param text the text on which to maybe apply the span.
* @return the same text, with the auto-correction underline span if that's appropriate.
*/
- // TODO: remove all references to this in LatinIME and make this private. Also, shouldn't
- // this go in some *Utils class instead?
- public CharSequence getTextWithUnderline(final String text) {
+ // TODO: Shouldn't this go in some *Utils class instead?
+ private CharSequence getTextWithUnderline(final String text) {
return mIsAutoCorrectionIndicatorOn
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(mLatinIME, text)
: text;
@@ -1741,8 +1749,7 @@ public final class InputLogic {
*
* @param settingsValues the current values of the settings.
*/
- // TODO: Make this private.
- public void promotePhantomSpace(final SettingsValues settingsValues) {
+ private void promotePhantomSpace(final SettingsValues settingsValues) {
if (settingsValues.shouldInsertSpacesAutomatically()
&& settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
&& !mConnection.textBeforeCursorLooksLikeURL()) {
@@ -1848,7 +1855,8 @@ public final class InputLogic {
final LatinIME.UIHandler handler) {
// Complete any pending suggestions query first
if (handler.hasPendingUpdateSuggestions()) {
- performUpdateSuggestionStripSync(settingsValues, handler);
+ handler.cancelUpdateSuggestionStrip();
+ performUpdateSuggestionStripSync(settingsValues);
}
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord();
@@ -1892,8 +1900,7 @@ public final class InputLogic {
* @param commitType the type of the commit, as one of LastComposedWord.COMMIT_TYPE_*
* @param separatorString the separator that's causing the commit, or NOT_A_SEPARATOR if none.
*/
- // TODO: Make this private
- public void commitChosenWord(final SettingsValues settingsValues, final String chosenWord,
+ private void commitChosenWord(final SettingsValues settingsValues, final String chosenWord,
final int commitType, final String separatorString) {
final SuggestedWords suggestedWords = mSuggestedWords;
final CharSequence chosenWordWithSuggestions =