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.java114
1 files changed, 47 insertions, 67 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 7be60fd31..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) {
@@ -289,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;
}
@@ -334,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
@@ -503,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
@@ -584,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;
}
@@ -657,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);
@@ -699,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;
}
@@ -781,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
@@ -876,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
@@ -887,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.
}
@@ -1204,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()) {
@@ -1228,10 +1216,15 @@ public final class InputLogic {
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
- final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
- 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));
+ }
}
}
);
@@ -1621,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) {
@@ -1647,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;
@@ -1656,32 +1646,24 @@ public final class InputLogic {
}
/**
- * Given a typed word and computed suggested words, return an object that may or may not
- * contain older suggestions according to the contents of the current suggestions.
+ * 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 suggestedWords The computed suggested words for this typed word.
- * @param previousSuggestedWords The previous suggested words.
- * @return suggestions possibly enriched with older suggestions.
+ * @param previousSuggestedWords The previously suggested words.
+ * @return Obsolete suggestions with the newly typed word.
*/
- private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
- final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) {
- // TODO: consolidate this into performUpdateSuggestionStripSync?
- // We update the suggestion strip only when we have some suggestions to show, i.e. when
- // the suggestion count is > 1; else, we leave the old suggestions, with the typed word
- // replaced with the new one. However, when the length of the typed word is 1 or 0 (after
- // a deletion typically), we do want to remove the old suggestions.
- if (suggestedWords.size() > 1 || typedWord.length() <= 1) {
- return suggestedWords;
- } else {
- 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 */);
- }
+ 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 */);
}
/**
@@ -1701,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;
@@ -1768,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()) {
@@ -1875,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();
@@ -1919,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 =