diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 31 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java | 27 |
2 files changed, 46 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 968129a96..de10a290d 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -46,6 +46,7 @@ import com.android.inputmethod.latin.WordComposer; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.SettingsValues; +import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import com.android.inputmethod.latin.suggestions.SuggestionStripView; import com.android.inputmethod.latin.utils.AsyncResultHolder; import com.android.inputmethod.latin.utils.CollectionUtils; @@ -68,7 +69,8 @@ public final class InputLogic { // TODO : Remove this member when we can. private final LatinIME mLatinIME; - private InputLogicHandler mInputLogicHandler; + // Never null. + private InputLogicHandler mInputLogicHandler = InputLogicHandler.NULL_HANDLER; // 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. @@ -104,7 +106,7 @@ public final class InputLogic { mWordComposer = new WordComposer(); mEventInterpreter = new EventInterpreter(latinIME); mConnection = new RichInputConnection(latinIME); - mInputLogicHandler = null; + mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } /** @@ -131,6 +133,7 @@ public final class InputLogic { mLastSelectionEnd = editorInfo.initialSelEnd; // In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying // so we try using some heuristics to find out about these and fix them. + mConnection.tryFixLyingCursorPosition(); tryFixLyingCursorPosition(); mInputLogicHandler = new InputLogicHandler(mLatinIME, this); } @@ -144,7 +147,7 @@ public final class InputLogic { } resetComposingState(true /* alsoResetLastComposedWord */); mInputLogicHandler.destroy(); - mInputLogicHandler = null; + mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } /** @@ -369,7 +372,8 @@ public final class InputLogic { mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( getActualCapsMode(settingsValues, keyboardSwitcher.getKeyboardShiftMode()), // Prev word is 1st word before cursor - getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */)); + getNthPreviousWordForSuggestion( + settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */)); } /* The sequence number member is only used in onUpdateBatchInput. It is increased each time @@ -555,7 +559,8 @@ public final class InputLogic { // yet, so the word we want is the 1st word before the cursor. mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( getActualCapsMode(settingsValues, keyboardSwitcher.getKeyboardShiftMode()), - getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */)); + getNthPreviousWordForSuggestion( + settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */)); } mConnection.setComposingText(getTextWithUnderline( mWordComposer.getTypedWord()), 1); @@ -1107,7 +1112,7 @@ public final class InputLogic { } } mWordComposer.setComposingWord(typedWord, - getNthPreviousWordForSuggestion(settingsValues, + getNthPreviousWordForSuggestion(settingsValues.mSpacingAndPunctuations, // We want the previous word for suggestion. If we have chars in the word // before the cursor, then we want the word before that, hence 2; otherwise, // we want the word immediately before the cursor, hence 1. @@ -1301,17 +1306,17 @@ public final class InputLogic { /** * Get the nth previous word before the cursor as context for the suggestion process. - * @param currentSettings the current settings values. + * @param spacingAndPunctuations the current spacing and punctuations settings. * @param nthPreviousWord reverse index of the word to get (1-indexed) * @return the nth previous word before the cursor. */ // TODO: Make this private - public String getNthPreviousWordForSuggestion(final SettingsValues currentSettings, - final int nthPreviousWord) { - if (currentSettings.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) { + public String getNthPreviousWordForSuggestion( + final SpacingAndPunctuations spacingAndPunctuations, final int nthPreviousWord) { + if (spacingAndPunctuations.mCurrentLanguageHasSpaces) { // If we are typing in a language with spaces we can just look up the previous // word from textview. - return mConnection.getNthPreviousWord(currentSettings, nthPreviousWord); + return mConnection.getNthPreviousWord(spacingAndPunctuations, nthPreviousWord); } else { return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null : mLastComposedWord.mCommittedWord; @@ -1659,7 +1664,8 @@ public final class InputLogic { mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord, suggestedWords), 1); // TODO: we pass 2 here, but would it be better to move this above and pass 1 instead? - final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2); + final String prevWord = mConnection.getNthPreviousWord( + settingsValues.mSpacingAndPunctuations, 2); // Add the word to the user history dictionary performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord); // TODO: figure out here if this is an auto-correct or if the best word is actually @@ -1745,6 +1751,7 @@ public final class InputLogic { // If remainingTries is 0, we should stop waiting for new tries, but it's still // better to load the keyboard (less things will be broken). } + mConnection.tryFixLyingCursorPosition(); tryFixLyingCursorPosition(); keyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), settingsValues); if (tryResumeSuggestions) { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java index 3258dcdfb..ea010b6f5 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java @@ -40,6 +40,33 @@ public class InputLogicHandler implements Handler.Callback { private static final int MSG_GET_SUGGESTED_WORDS = 1; + // A handler that never does anything. This is used for cases where events come before anything + // is initialized, though probably only the monkey can actually do this. + public static final InputLogicHandler NULL_HANDLER = new InputLogicHandler() { + @Override + public void destroy() {} + @Override + public boolean handleMessage(final Message msg) { return true; } + @Override + public void onStartBatchInput() {} + @Override + public void onUpdateBatchInput(final InputPointers batchPointers, + final int sequenceNumber) {} + @Override + public void onCancelBatchInput() {} + @Override + public void onEndBatchInput(final InputPointers batchPointers, final int sequenceNumber) {} + @Override + public void getSuggestedWords(final int sessionId, final int sequenceNumber, + final OnGetSuggestedWordsCallback callback) {} + }; + + private InputLogicHandler() { + mNonUIThreadHandler = null; + mLatinIME = null; + mInputLogic = null; + } + public InputLogicHandler(final LatinIME latinIME, final InputLogic inputLogic) { final HandlerThread handlerThread = new HandlerThread( InputLogicHandler.class.getSimpleName()); |