aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-08-06 02:16:57 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-08-05 00:07:36 +0000
commit50c12c83b322f78c90e3f72d1fa4422d13bfa7c6 (patch)
tree5f578a59cdf057ea836ccc0c67efa65828a403fa /java/src/com/android/inputmethod
parentda8cda0578a0ec8738d054d25e2e922d1f0e6ca8 (diff)
parent93b00a314e307cb257abf1cab88cb24d57ff3885 (diff)
downloadlatinime-50c12c83b322f78c90e3f72d1fa4422d13bfa7c6.tar.gz
latinime-50c12c83b322f78c90e3f72d1fa4422d13bfa7c6.tar.xz
latinime-50c12c83b322f78c90e3f72d1fa4422d13bfa7c6.zip
Merge "[HS2] Move more stuff to onStartInput" into lmp-dev
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java111
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java2
2 files changed, 62 insertions, 51 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 4adc28d7a..c1adc12f9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -295,7 +295,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
+ public void postResetInputConnectionCaches(final boolean tryResumeSuggestions,
+ final int remainingTries) {
removeMessages(MSG_RESET_CACHES);
sendMessage(obtainMessage(MSG_RESET_CACHES, tryResumeSuggestions ? 1 : 0,
remainingTries, null));
@@ -762,9 +763,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private static class EditorChangeInfo {
public final boolean mIsSameInputType;
public final boolean mHasSameOrientation;
- public EditorChangeInfo(final boolean isSameInputType, final boolean hasSameOrientation) {
+ public final boolean mCanReachInputConnection;
+ public EditorChangeInfo(final boolean isSameInputType, final boolean hasSameOrientation,
+ final boolean canReachInputConnection) {
mIsSameInputType = isSameInputType;
mHasSameOrientation = hasSameOrientation;
+ mCanReachInputConnection = canReachInputConnection;
}
}
@@ -773,15 +777,65 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) {
super.onStartInput(editorInfo, restarting);
SettingsValues currentSettingsValues = mSettings.getCurrent();
- mLastEditorChangeInfo = new EditorChangeInfo(
- currentSettingsValues.isSameInputType(editorInfo),
- currentSettingsValues.hasSameOrientation(getResources().getConfiguration()));
+ final boolean isSameInputType = currentSettingsValues.isSameInputType(editorInfo);
+ final boolean hasSameOrientation =
+ currentSettingsValues.hasSameOrientation(getResources().getConfiguration());
+ mRichImm.clearSubtypeCaches();
+ if (editorInfo == null) {
+ Log.e(TAG, "Null EditorInfo in onStartInput()");
+ return;
+ }
+ final boolean inputTypeChanged = !isSameInputType;
+ final boolean isDifferentTextField = !restarting || inputTypeChanged;
+ if (isDifferentTextField || !hasSameOrientation) {
+ loadSettings();
+ currentSettingsValues = mSettings.getCurrent();
+ }
+
+ // Note: the following does a round-trip IPC on the main thread: be careful
+ final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
+ final Suggest suggest = mInputLogic.mSuggest;
+ if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) {
+ // TODO: Do this automatically.
+ resetSuggest();
+ }
+ if (isDifferentTextField && currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
+ suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold);
+ }
+
+ // The app calling setText() has the effect of clearing the composing
+ // span, so we should reset our state unconditionally, even if restarting is true.
+ // We also tell the input logic about the combining rules for the current subtype, so
+ // it can adjust its combiners if needed.
+ mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype());
+ // TODO[IL]: Can the following be moved to InputLogic#startInput?
+ final boolean canReachInputConnection;
+ if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
+ editorInfo.initialSelStart, editorInfo.initialSelEnd,
+ false /* shouldFinishComposition */)) {
+ // 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.
+ // We try resetting the caches up to 5 times before giving up.
+ mHandler.postResetInputConnectionCaches(isDifferentTextField || !hasSameOrientation,
+ 5 /* remainingTries */);
+ canReachInputConnection = false;
+ } else {
+ // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
+ // effort to work around this bug.
+ mInputLogic.mConnection.tryFixLyingCursorPosition();
+ mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
+ true /* shouldDelay */);
+ canReachInputConnection = true;
+ }
+
+ mLastEditorChangeInfo = new EditorChangeInfo(isSameInputType, hasSameOrientation,
+ canReachInputConnection);
}
@SuppressWarnings("deprecation")
private void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
super.onStartInputView(editorInfo, restarting);
- mRichImm.clearSubtypeCaches();
final KeyboardSwitcher switcher = mKeyboardSwitcher;
switcher.updateKeyboardTheme();
final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
@@ -837,56 +891,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Note: This call should be done by InputMethodService?
updateFullscreenMode();
- // The app calling setText() has the effect of clearing the composing
- // span, so we should reset our state unconditionally, even if restarting is true.
- // We also tell the input logic about the combining rules for the current subtype, so
- // it can adjust its combiners if needed.
- mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype());
-
- // Note: the following does a round-trip IPC on the main thread: be careful
- final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
- final Suggest suggest = mInputLogic.mSuggest;
- if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) {
- // TODO: Do this automatically.
- resetSuggest();
- }
-
- // TODO[IL]: Can the following be moved to InputLogic#startInput?
- final boolean canReachInputConnection;
- if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
- editorInfo.initialSelStart, editorInfo.initialSelEnd,
- false /* shouldFinishComposition */)) {
- // 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.
- // We try resetting the caches up to 5 times before giving up.
- mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
- // mLastSelection{Start,End} are reset later in this method, don't need to do it here
- canReachInputConnection = false;
- } else {
- // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
- // effort to work around this bug.
- mInputLogic.mConnection.tryFixLyingCursorPosition();
- mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
- true /* shouldDelay */);
- canReachInputConnection = true;
- }
-
- if (isDifferentTextField || !mLastEditorChangeInfo.mHasSameOrientation) {
- loadSettings();
- }
final SettingsValues currentSettingsValues = mSettings.getCurrent();
if (isDifferentTextField) {
mainKeyboardView.closing();
- if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
- suggest.setAutoCorrectionThreshold(
- currentSettingsValues.mAutoCorrectionThreshold);
- }
-
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
getCurrentRecapitalizeState());
- if (!canReachInputConnection) {
+ if (!mLastEditorChangeInfo.mCanReachInputConnection) {
// If we can't reach the input connection, we will call loadKeyboard again later,
// so we need to save its state now. The call will be done in #retryResetCaches.
switcher.saveKeyboardState();
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 97457b2f7..b511f69a6 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -2034,7 +2034,7 @@ public final class InputLogic {
mConnection.getExpectedSelectionStart(), mConnection.getExpectedSelectionEnd(),
shouldFinishComposition)) {
if (0 < remainingTries) {
- handler.postResetCaches(tryResumeSuggestions, remainingTries - 1);
+ handler.postResetInputConnectionCaches(tryResumeSuggestions, remainingTries - 1);
return false;
}
// If remainingTries is 0, we should stop waiting for new tries, however we'll still