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.java218
1 files changed, 16 insertions, 202 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 33f09e45b..5a5674f8f 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -35,8 +35,6 @@ import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Debug;
-import android.os.Handler;
-import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
@@ -137,7 +135,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final boolean mIsHardwareAcceleratedDrawingEnabled;
public final UIHandler mHandler = new UIHandler(this);
- private InputUpdater mInputUpdater;
public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIME> {
private static final int MSG_UPDATE_SHIFT_STATE = 0;
@@ -183,8 +180,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP:
latinIme.mInputLogic.performUpdateSuggestionStripSync(
- latinIme.mSettings.getCurrent(), this /* handler */,
- latinIme.mInputUpdater);
+ latinIme.mSettings.getCurrent(), this /* handler */);
break;
case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState();
@@ -205,8 +201,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
break;
case MSG_RESUME_SUGGESTIONS:
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
- latinIme.mSettings.getCurrent(), latinIme.mKeyboardSwitcher,
- latinIme.mInputUpdater);
+ latinIme.mSettings.getCurrent(), 0 /* offset */,
+ false /* includeResumedWordInSuggestions */, latinIme.mKeyboardSwitcher);
break;
case MSG_REOPEN_DICTIONARIES:
latinIme.initSuggest();
@@ -216,7 +212,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
postUpdateSuggestionStrip();
break;
case MSG_ON_END_BATCH_INPUT:
- latinIme.onEndBatchInputAsyncInternal((SuggestedWords) msg.obj);
+ latinIme.mInputLogic.endBatchInputAsyncInternal(latinIme.mSettings.getCurrent(),
+ (SuggestedWords) msg.obj, latinIme.mKeyboardSwitcher);
break;
case MSG_RESET_CACHES:
latinIme.mInputLogic.retryResetCaches(latinIme.mSettings.getCurrent(),
@@ -495,8 +492,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this);
-
- mInputUpdater = new InputUpdater(this);
}
// Has to be package-visible for unit tests
@@ -594,9 +589,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
suggest.close();
mInputLogic.mSuggest = null;
}
- if (mInputUpdater != null) {
- mInputUpdater.quitLooper();
- }
mSettings.onDestroy();
unregisterReceiver(mReceiver);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
@@ -754,12 +746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// The app calling setText() has the effect of clearing the composing
// span, so we should reset our state unconditionally, even if restarting is true.
- mInputLogic.mEnteredText = null;
- mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
- mInputLogic.mDeleteCount = 0;
- mInputLogic.mSpaceState = SpaceState.NONE;
- mInputLogic.mRecapitalizeStatus.deactivate();
- mInputLogic.mCurrentlyPressedHardwareKeys.clear();
+ mInputLogic.startInput(restarting, editorInfo);
// Note: the following does a round-trip IPC on the main thread: be careful
final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
@@ -772,11 +759,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// otherwise it will clear the suggestion strip.
setPunctuationSuggestions();
}
- mInputLogic.mSuggestedWords = SuggestedWords.EMPTY;
// Sometimes, while rotating, for some reason the framework tells the app we are not
// connected to it and that means we can't refresh the cache. In this case, schedule a
// refresh later.
+ // TODO[IL]: Can the following be moved to InputLogic#startInput?
final boolean canReachInputConnection;
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
editorInfo.initialSelStart, editorInfo.initialSelEnd,
@@ -823,12 +810,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setSuggestionStripShownInternal(
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
- mInputLogic.mLastSelectionStart = editorInfo.initialSelStart;
- mInputLogic.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.
- mInputLogic.tryFixLyingCursorPosition();
-
mHandler.cancelUpdateSuggestionStrip();
mHandler.cancelDoubleSpacePeriodTimer();
@@ -872,10 +853,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Remove pending messages related to update suggestions
mHandler.cancelUpdateSuggestionStrip();
// Should do the following in onFinishInputInternal but until JB MR2 it's not called :(
- if (mInputLogic.mWordComposer.isComposingWord()) {
- mInputLogic.mConnection.finishComposingText();
- }
- mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
+ mInputLogic.finishInput();
// Notify ResearchLogger
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput,
@@ -1252,166 +1230,35 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Implementation of {@link KeyboardActionListener}.
@Override
public void onCodeInput(final int primaryCode, final int x, final int y) {
- mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mInputUpdater,
- mKeyboardSwitcher, mSubtypeSwitcher);
+ mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher);
}
// Called from PointerTracker through the KeyboardActionListener interface
@Override
public void onTextInput(final String rawText) {
- mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler, mInputUpdater);
+ mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler);
mKeyboardSwitcher.updateShiftState();
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
}
@Override
public void onStartBatchInput() {
- mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler,
- mInputUpdater);
+ mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
}
@Override
public void onUpdateBatchInput(final InputPointers batchPointers) {
- mInputLogic.onUpdateBatchInput(mSettings.getCurrent(), batchPointers, mKeyboardSwitcher,
- mInputUpdater);
+ mInputLogic.onUpdateBatchInput(mSettings.getCurrent(), batchPointers, mKeyboardSwitcher);
}
@Override
public void onEndBatchInput(final InputPointers batchPointers) {
- mInputLogic.onEndBatchInput(mSettings.getCurrent(), batchPointers, mInputUpdater);
+ mInputLogic.onEndBatchInput(mSettings.getCurrent(), batchPointers);
}
@Override
public void onCancelBatchInput() {
- mInputLogic.onCancelBatchInput(mHandler, mInputUpdater);
- }
-
- // TODO[IL]: Make this a package-private standalone class in inputlogic/ and remove all
- // references to it in LatinIME
- public static final class InputUpdater implements Handler.Callback {
- private final Handler mHandler;
- private final LatinIME mLatinIme;
- private final Object mLock = new Object();
- private boolean mInBatchInput; // synchronized using {@link #mLock}.
-
- InputUpdater(final LatinIME latinIme) {
- final HandlerThread handlerThread = new HandlerThread(
- InputUpdater.class.getSimpleName());
- handlerThread.start();
- mHandler = new Handler(handlerThread.getLooper(), this);
- mLatinIme = latinIme;
- }
-
- private static final int MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP = 1;
- private static final int MSG_GET_SUGGESTED_WORDS = 2;
-
- @Override
- public boolean handleMessage(final Message msg) {
- // TODO: straighten message passing - we don't need two kinds of messages calling
- // each other.
- switch (msg.what) {
- case MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
- updateBatchInput((InputPointers)msg.obj, msg.arg2 /* sequenceNumber */);
- break;
- case MSG_GET_SUGGESTED_WORDS:
- mLatinIme.getSuggestedWords(msg.arg1 /* sessionId */,
- msg.arg2 /* sequenceNumber */, (OnGetSuggestedWordsCallback) msg.obj);
- break;
- }
- return true;
- }
-
- // Run on the UI thread.
- public void onStartBatchInput() {
- synchronized (mLock) {
- mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
- mInBatchInput = true;
- }
- }
-
- // Run on the Handler thread.
- private void updateBatchInput(final InputPointers batchPointers, final int sequenceNumber) {
- synchronized (mLock) {
- if (!mInBatchInput) {
- // Batch input has ended or canceled while the message was being delivered.
- return;
- }
-
- getSuggestedWordsGestureLocked(batchPointers, sequenceNumber,
- new OnGetSuggestedWordsCallback() {
- @Override
- public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
- mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
- suggestedWords, false /* dismissGestureFloatingPreviewText */);
- }
- });
- }
- }
-
- // Run on the UI thread.
- public void onUpdateBatchInput(final InputPointers batchPointers,
- final int sequenceNumber) {
- if (mHandler.hasMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP)) {
- return;
- }
- mHandler.obtainMessage(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, 0 /* arg1 */,
- sequenceNumber /* arg2 */, batchPointers /* obj */).sendToTarget();
- }
-
- public void onCancelBatchInput() {
- synchronized (mLock) {
- mInBatchInput = false;
- }
- }
-
- // Run on the UI thread.
- public void onEndBatchInput(final InputPointers batchPointers) {
- synchronized(mLock) {
- getSuggestedWordsGestureLocked(batchPointers, SuggestedWords.NOT_A_SEQUENCE_NUMBER,
- new OnGetSuggestedWordsCallback() {
- @Override
- public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
- mInBatchInput = false;
- mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(suggestedWords,
- true /* dismissGestureFloatingPreviewText */);
- mLatinIme.mHandler.onEndBatchInput(suggestedWords);
- }
- });
- }
- }
-
- // {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to
- // be synchronized.
- private void getSuggestedWordsGestureLocked(final InputPointers batchPointers,
- final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
- mLatinIme.mInputLogic.mWordComposer.setBatchInputPointers(batchPointers);
- getSuggestedWords(Suggest.SESSION_GESTURE, sequenceNumber,
- new OnGetSuggestedWordsCallback() {
- @Override
- public void onGetSuggestedWords(SuggestedWords suggestedWords) {
- if (suggestedWords.isEmpty()) {
- // Previous suggestions are found in InputLogic#mSuggestedWords.
- // Since these are the most recent ones and we just recomputed new
- // ones to update them, it means the previous ones are there.
- callback.onGetSuggestedWords(mLatinIme.mInputLogic.mSuggestedWords);
- } else {
- callback.onGetSuggestedWords(suggestedWords);
- }
- }
- });
- }
-
- public void getSuggestedWords(final int sessionId, final int sequenceNumber,
- final OnGetSuggestedWordsCallback callback) {
- mHandler.obtainMessage(MSG_GET_SUGGESTED_WORDS, sessionId, sequenceNumber, callback)
- .sendToTarget();
- }
-
- void quitLooper() {
- mHandler.removeMessages(MSG_GET_SUGGESTED_WORDS);
- mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
- mHandler.getLooper().quit();
- }
+ mInputLogic.onCancelBatchInput(mHandler);
}
// This method must run on the UI Thread.
@@ -1425,40 +1272,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- // This method must run on the UI Thread.
- public void onEndBatchInputAsyncInternal(final SuggestedWords suggestedWords) {
- final String batchInputText = suggestedWords.isEmpty() ? null : suggestedWords.getWord(0);
- if (TextUtils.isEmpty(batchInputText)) {
- return;
- }
- mInputLogic.mConnection.beginBatchEdit();
- if (SpaceState.PHANTOM == mInputLogic.mSpaceState) {
- mInputLogic.promotePhantomSpace(mSettings.getCurrent());
- }
- if (mSettings.getCurrent().mPhraseGestureEnabled) {
- // Find the last space
- final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
- if (0 != indexOfLastSpace) {
- mInputLogic.mConnection.commitText(batchInputText.substring(0, indexOfLastSpace),
- 1);
- showSuggestionStrip(suggestedWords.getSuggestedWordsForLastWordOfPhraseGesture());
- }
- final String lastWord = batchInputText.substring(indexOfLastSpace);
- mInputLogic.mWordComposer.setBatchInputWord(lastWord);
- mInputLogic.mConnection.setComposingText(lastWord, 1);
- } else {
- mInputLogic.mWordComposer.setBatchInputWord(batchInputText);
- mInputLogic.mConnection.setComposingText(batchInputText, 1);
- }
- mInputLogic.mConnection.endBatchEdit();
- if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0, suggestedWords);
- }
- // Space state must be updated before calling updateShiftState
- mInputLogic.mSpaceState = SpaceState.PHANTOM;
- mKeyboardSwitcher.updateShiftState();
- }
-
// Called from PointerTracker through the KeyboardActionListener interface
@Override
public void onFinishSlidingInput() {
@@ -1533,7 +1346,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void getSuggestedWords(final int sessionId, final int sequenceNumber,
+ // TODO[IL]: Move this out of LatinIME.
+ public void getSuggestedWords(final int sessionId, final int sequenceNumber,
final OnGetSuggestedWordsCallback callback) {
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final Suggest suggest = mInputLogic.mSuggest;