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.java172
1 files changed, 53 insertions, 119 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a4253bb3b..ba7503dae 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -59,7 +59,6 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
-import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -790,7 +789,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mSuggestionStripView != null) {
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
- setPunctuationSuggestions();
+ setNeutralSuggestionStrip();
}
// Sometimes, while rotating, for some reason the framework tells the app we are not
@@ -889,10 +888,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.finishInput();
// Notify ResearchLogger
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput,
- // TODO[IL]: mInputLogic.mConnection should be private
- mInputLogic.mConnection.getExpectedSelectionStart(),
- mInputLogic.mConnection.getExpectedSelectionEnd(), getCurrentInputConnection());
+ ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput);
}
}
@@ -916,63 +912,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
composingSpanEnd, mInputLogic.mConnection);
}
- final boolean selectionChanged = oldSelStart != newSelStart || oldSelEnd != newSelEnd;
-
- // if composingSpanStart and composingSpanEnd are -1, it means there is no composing
- // span in the view - we can use that to narrow down whether the cursor was moved
- // by us or not. If we are composing a word but there is no composing span, then
- // we know for sure the cursor moved while we were composing and we should reset
- // the state. TODO: rescind this policy: the framework never removes the composing
- // span on its own accord while editing. This test is useless.
- final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
-
// 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() && !mInputLogic.mConnection.isBelatedExpectedUpdate(oldSelStart,
- newSelStart, oldSelEnd, newSelEnd)) {
- // TODO: the following is probably better done in resetEntireInputState().
- // it should only happen when the cursor moved, and the very purpose of the
- // test below is to narrow down whether this happened or not. Likewise with
- // the call to updateShiftState.
- // We set this to NONE because after a cursor move, we don't want the space
- // state-related special processing to kick in.
- mInputLogic.mSpaceState = SpaceState.NONE;
-
- // TODO: is it still necessary to test for composingSpan related stuff?
- final boolean selectionChangedOrSafeToReset = selectionChanged
- || (!mInputLogic.mWordComposer.isComposingWord()) || noComposingSpan;
- final boolean hasOrHadSelection = (oldSelStart != oldSelEnd
- || newSelStart != newSelEnd);
- final int moveAmount = newSelStart - oldSelStart;
- if (selectionChangedOrSafeToReset && (hasOrHadSelection
- || !mInputLogic.mWordComposer.moveCursorByAndReturnIfInsideComposingWord(
- moveAmount))) {
- // If we are composing a word and moving the cursor, we would want to set a
- // suggestion span for recorrection to work correctly. Unfortunately, that
- // would involve the keyboard committing some new text, which would move the
- // cursor back to where it was. Latin IME could then fix the position of the cursor
- // again, but the asynchronous nature of the calls results in this wreaking havoc
- // with selection on double tap and the like.
- // Another option would be to send suggestions each time we set the composing
- // text, but that is probably too expensive to do, so we decided to leave things
- // as is.
- mInputLogic.resetEntireInputState(mSettings.getCurrent(), newSelStart, newSelEnd);
- } else {
- // resetEntireInputState calls resetCachesUponCursorMove, but forcing the
- // composition to end. But in all cases where we don't reset the entire input
- // state, we still want to tell the rich input connection about the new cursor
- // position so that it can update its caches.
- mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
- newSelStart, newSelEnd, false /* shouldFinishComposition */);
- }
-
- // We moved the cursor. If we are touching a word, we need to resume suggestion.
- mHandler.postResumeSuggestions();
- // Reset the last recapitalization.
- mInputLogic.mRecapitalizeStatus.deactivate();
+ if (isInputViewShown() &&
+ mInputLogic.onUpdateSelection(mSettings.getCurrent(), oldSelStart, oldSelEnd,
+ newSelStart, newSelEnd, composingSpanStart, composingSpanEnd)) {
mKeyboardSwitcher.updateShiftState();
}
@@ -1043,7 +990,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return;
if (applicationSpecifiedCompletions == null) {
- clearSuggestionStrip();
+ setNeutralSuggestionStrip();
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onDisplayCompletions(null);
}
@@ -1058,7 +1005,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SuggestedWords suggestedWords = new SuggestedWords(
applicationSuggestedWords,
false /* typedWordValid */,
- false /* hasAutoCorrectionCandidate */,
+ false /* willAutoCorrect */,
false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */,
false /* isPrediction */);
@@ -1187,7 +1134,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// the right layout.
// TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead?
public int getCurrentAutoCapsState() {
- return mInputLogic.getCurrentAutoCapsState(null /* optionalSettingsValues */);
+ return mInputLogic.getCurrentAutoCapsState(mSettings.getCurrent());
}
// Called from the KeyboardSwitcher which needs to know recaps state to display
@@ -1206,23 +1153,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
* @return x,y coordinates for this keyboard, as a flattened array.
*/
public int[] getCoordinatesForCurrentKeyboard(final int[] codePoints) {
- return getCoordinatesForKeyboard(codePoints, mKeyboardSwitcher.getKeyboard());
- }
-
- public static int[] getCoordinatesForKeyboard(final int[] codePoints, final Keyboard keyboard) {
- final int length = codePoints.length;
- final int[] coordinates = CoordinateUtils.newCoordinateArray(length);
- Key key;
- for (int i = 0; i < length; ++i) {
- if (keyboard != null && (key = keyboard.getKey(codePoints[i])) != null) {
- CoordinateUtils.setXYInArray(coordinates, i,
- key.getX() + key.getWidth() / 2, key.getY() + key.getHeight() / 2);
- } else {
- CoordinateUtils.setXYInArray(coordinates, i,
- Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
- }
+ final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
+ if (null == keyboard) {
+ return CoordinateUtils.newCoordinateArray(codePoints.length,
+ Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
+ } else {
+ return keyboard.getCoordinates(codePoints);
}
- return coordinates;
}
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
@@ -1299,8 +1236,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else {
codeToSend = codePoint;
}
- mInputLogic.onCodeInput(codeToSend, keyX, keyY, mHandler, mKeyboardSwitcher,
- mSubtypeSwitcher);
+ if (Constants.CODE_SHORTCUT == codePoint) {
+ mSubtypeSwitcher.switchToShortcutIME(this);
+ // Still call the *#onCodeInput methods for readability.
+ }
+ mInputLogic.onCodeInput(codeToSend, keyX, keyY, mSettings.getCurrent(),
+ mHandler, mKeyboardSwitcher);
mKeyboardSwitcher.onCodeInput(codePoint);
}
@@ -1389,12 +1330,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Define a clear interface for this
- public void clearSuggestionStrip() {
- setSuggestedWords(SuggestedWords.EMPTY);
- setAutoCorrectionIndicator(false);
- }
-
- // TODO[IL]: Define a clear interface for this
public void setSuggestedWords(final SuggestedWords words) {
mInputLogic.mSuggestedWords = words;
if (mSuggestionStripView != null) {
@@ -1477,10 +1412,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SuggestedWords punctuationList =
mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList;
final SuggestedWords oldSuggestedWords = previousSuggestedWords == punctuationList
- ? SuggestedWords.EMPTY : previousSuggestedWords;
- if (TextUtils.isEmpty(typedWord)) {
- return oldSuggestedWords;
- }
+ ? SuggestedWords.EMPTY : previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions,
@@ -1492,39 +1424,39 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
+ private void showSuggestionStripWithTypedWord(final SuggestedWords sourceSuggestedWords,
final String typedWord) {
- if (suggestedWords.isEmpty()) {
- // No auto-correction is available, clear the cached values.
- AccessibilityUtils.getInstance().setAutoCorrection(null, null);
- clearSuggestionStrip();
- return;
- }
- final String autoCorrection;
- if (suggestedWords.mWillAutoCorrect) {
- autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
- } else {
- // We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
- // because it may differ from mWordComposer.mTypedWord.
- autoCorrection = typedWord;
- }
- mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
- setSuggestedWords(suggestedWords);
- setAutoCorrectionIndicator(suggestedWords.mWillAutoCorrect);
- setSuggestionStripShown(isSuggestionsStripVisible());
- // An auto-correction is available, cache it in accessibility code so
- // we can be speak it if the user touches a key that will insert it.
- AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
+ // TODO: refactor this
+ final SuggestedWords suggestedWords =
+ sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
+ if (suggestedWords.isEmpty()) {
+ // No auto-correction is available, clear the cached values.
+ AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
+ setSuggestedWords(suggestedWords);
+ setAutoCorrectionIndicator(false);
+ return;
+ }
+ final String autoCorrection;
+ if (suggestedWords.mWillAutoCorrect) {
+ autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
+ } else {
+ // We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
+ // because it may differ from mWordComposer.mTypedWord.
+ autoCorrection = typedWord;
+ }
+ mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
+ setSuggestedWords(suggestedWords);
+ setAutoCorrectionIndicator(suggestedWords.mWillAutoCorrect);
+ setSuggestionStripShown(isSuggestionsStripVisible());
+ // An auto-correction is available, cache it in accessibility code so
+ // we can be speak it if the user touches a key that will insert it.
+ AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
}
// TODO[IL]: Define a clean interface for this
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
- if (suggestedWords.isEmpty()) {
- clearSuggestionStrip();
- return;
- }
- showSuggestionStripWithTypedWord(suggestedWords,
- suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
+ showSuggestionStripWithTypedWord(suggestedWords, suggestedWords.isEmpty() ? null
+ : suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
}
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
@@ -1623,10 +1555,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Define a clean interface for this
- public void setPunctuationSuggestions() {
+ // This will show either an empty suggestion strip (if prediction is enabled) or
+ // punctuation suggestions (if it's disabled).
+ public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent();
if (currentSettings.mBigramPredictionEnabled) {
- clearSuggestionStrip();
+ setSuggestedWords(SuggestedWords.EMPTY);
} else {
setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList);
}