aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java64
1 files changed, 41 insertions, 23 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 5ef2120c6..347a4c63a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -90,7 +90,7 @@ import java.util.TreeSet;
/**
* Input method implementation for Qwerty'ish keyboard.
*/
-public final class LatinIME extends InputMethodService implements KeyboardActionListener,
+public class LatinIME extends InputMethodService implements KeyboardActionListener,
SuggestionStripView.Listener, TargetApplicationGetter.OnTargetApplicationKnownListener,
Suggest.SuggestInitializationListener {
private static final String TAG = LatinIME.class.getSimpleName();
@@ -188,6 +188,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Keeps track of most recently inserted text (multi-character key) for reverting
private String mEnteredText;
+ // TODO: This boolean is persistent state and causes large side effects at unexpected times.
+ // Find a way to remove it for readability.
private boolean mIsAutoCorrectionIndicatorOn;
private AlertDialog mOptionsDialog;
@@ -250,6 +252,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
public void postResumeSuggestions() {
+ removeMessages(MSG_RESUME_SUGGESTIONS);
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS), mDelayUpdateSuggestions);
}
@@ -759,7 +762,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
mSuggestedWords = SuggestedWords.EMPTY;
- mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
+ mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart,
+ false /* shouldFinishComposition */);
if (isDifferentTextField) {
mainKeyboardView.closing();
@@ -900,7 +904,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// we know for sure the cursor moved while we were composing and we should reset
// the state.
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
- if (!mExpectingUpdateSelection
+ // If the keyboard is not visible, we don't need to do all the housekeeping work, as it
+ // will be reset when the keyboard shows up anyway.
+ // TODO: revisit this when LatinIME supports hardware keyboards.
+ // NOTE: the test harness subclasses LatinIME and overrides isInputViewShown().
+ // TODO: find a better way to simulate actual execution.
+ if (isInputViewShown() && !mExpectingUpdateSelection
&& !mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart)) {
// TAKE CARE: there is a race condition when we enter this test even when the user
// did not explicitly move the cursor. This happens when typing fast, where two keys
@@ -1148,13 +1157,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// This will reset the whole input state to the starting state. It will clear
// the composing word, reset the last composed word, tell the inputconnection about it.
private void resetEntireInputState(final int newCursorPosition) {
+ final boolean shouldFinishComposition = mWordComposer.isComposingWord();
resetComposingState(true /* alsoResetLastComposedWord */);
if (mSettings.getCurrent().mBigramPredictionEnabled) {
clearSuggestionStrip();
} else {
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
}
- mConnection.resetCachesUponCursorMove(newCursorPosition);
+ mConnection.resetCachesUponCursorMove(newCursorPosition, shouldFinishComposition);
}
private void resetComposingState(final boolean alsoResetLastComposedWord) {
@@ -1577,21 +1587,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
}
mExpectingUpdateSelection = true;
- // The following is necessary for the case where the user typed something but didn't
- // manual pick it and didn't input any separator: we want to put a space between what
- // has been entered and the coming gesture input result, so we go into phantom space
- // state, which will be promoted to a space when the gesture result is committed. But if
- // the current input ends in a word connector on the other hand, then we want to have
- // the next input stick to the current input so we don't switch to phantom space state.
- if (!mSettings.getCurrent().isWordConnector(lastChar)) {
- mSpaceState = SPACE_STATE_PHANTOM;
- }
- } else {
- final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
- if (Character.isLetter(codePointBeforeCursor)
- || mSettings.getCurrent().isUsuallyFollowedBySpace(codePointBeforeCursor)) {
- mSpaceState = SPACE_STATE_PHANTOM;
- }
+ }
+ final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
+ if (Character.isLetterOrDigit(codePointBeforeCursor)
+ || mSettings.getCurrent().isUsuallyFollowedBySpace(codePointBeforeCursor)) {
+ mSpaceState = SPACE_STATE_PHANTOM;
}
mConnection.endBatchEdit();
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
@@ -1759,9 +1759,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Called from PointerTracker through the KeyboardActionListener interface
@Override
+ public void onFinishSlidingInput() {
+ // User finished sliding input.
+ mKeyboardSwitcher.onFinishSlidingInput();
+ }
+
+ // Called from PointerTracker through the KeyboardActionListener interface
+ @Override
public void onCancelInput() {
// User released a finger outside any key
- mKeyboardSwitcher.onCancelInput();
+ // Nothing to do so far.
}
@Override
@@ -1905,6 +1912,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
final int y, final int spaceState) {
boolean isComposingWord = mWordComposer.isComposingWord();
+ // TODO: remove isWordConnector() and use isUsuallyFollowedBySpace() instead.
+ // See onStartBatchInput() to see how to do it.
if (SPACE_STATE_PHANTOM == spaceState &&
!mSettings.getCurrent().isWordConnector(primaryCode)) {
if (isComposingWord) {
@@ -2185,6 +2194,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators,
mWordComposer.isComposingWord() ? 2 : 1);
return mSuggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(),
+ mSettings.getBlockPotentiallyOffensive(),
mSettings.getCurrent().mCorrectionEnabled, sessionId);
}
@@ -2443,10 +2453,15 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void restartSuggestionsOnWordTouchedByCursor() {
// If the cursor is not touching a word, or if there is a selection, return right away.
if (mLastSelectionStart != mLastSelectionEnd) return;
+ // If we don't know the cursor location, return.
+ if (mLastSelectionStart < 0) return;
if (!mConnection.isCursorTouchingWord(mSettings.getCurrent())) return;
final Range range = mConnection.getWordRangeAtCursor(mSettings.getWordSeparators(),
0 /* additionalPrecedingWordsCount */);
if (null == range) return; // Happens if we don't have an input connection at all
+ // If for some strange reason (editor bug or so) we measure the text before the cursor as
+ // longer than what the entire text is supposed to be, the safe thing to do is bail out.
+ if (range.mCharsBefore > mLastSelectionStart) return;
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
final String typedWord = range.mWord.toString();
if (range.mWord instanceof SpannableString) {
@@ -2499,7 +2514,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// 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 above where suggestedWords is affected.
+ // places above where suggestedWords is affected. We also need to reset
+ // mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching the text to adapt it.
+ // TODO: remove mIsAutoCorrectionIndicator on (see comment on definition)
+ mIsAutoCorrectionIndicatorOn = false;
showSuggestionStrip(suggestedWords, typedWord);
}
@@ -2611,8 +2629,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Callback called by PointerTracker through the KeyboardActionListener. This is called when a
// key is depressed; release matching call is onReleaseKey below.
@Override
- public void onPressKey(final int primaryCode) {
- mKeyboardSwitcher.onPressKey(primaryCode);
+ public void onPressKey(final int primaryCode, final boolean isSinglePointer) {
+ mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer);
}
// Callback by PointerTracker through the KeyboardActionListener. This is called when a key