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.java86
1 files changed, 62 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 0f3d28976..b668a7770 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -605,8 +605,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void initSuggest() {
- final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
- final String localeStr = subtypeLocale.toString();
+ final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
+ final String switcherLocaleStr = switcherSubtypeLocale.toString();
+ final Locale subtypeLocale;
+ final String localeStr;
+ if (TextUtils.isEmpty(switcherLocaleStr)) {
+ // This happens in very rare corner cases - for example, immediately after a switch
+ // to LatinIME has been requested, about a frame later another switch happens. In this
+ // case, we are about to go down but we still don't know it, however the system tells
+ // us there is no current subtype so the locale is the empty string. Take the best
+ // possible guess instead -- it's bound to have no consequences, and we have no way
+ // of knowing anyway.
+ Log.e(TAG, "System is reporting no current subtype.");
+ subtypeLocale = getResources().getConfiguration().locale;
+ localeStr = subtypeLocale.toString();
+ } else {
+ subtypeLocale = switcherSubtypeLocale;
+ localeStr = switcherLocaleStr;
+ }
final Suggest newSuggest = new Suggest(this /* Context */, subtypeLocale,
this /* SuggestInitializationListener */);
@@ -792,6 +808,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@SuppressWarnings("deprecation")
private void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
super.onStartInputView(editorInfo, restarting);
+ mRichImm.clearSubtypeCaches();
final KeyboardSwitcher switcher = mKeyboardSwitcher;
final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
// If we are starting input in a different text field from before, we'll have to reload
@@ -887,12 +904,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// 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.
+ final boolean canReachInputConnection;
if (!mConnection.resetCachesUponCursorMoveAndReturnSuccess(editorInfo.initialSelStart,
false /* shouldFinishComposition */)) {
// We try resetting the caches up to 5 times before giving up.
mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
+ canReachInputConnection = false;
} else {
- if (isDifferentTextField) mHandler.postResumeSuggestions();
+ if (isDifferentTextField) {
+ mHandler.postResumeSuggestions();
+ }
+ canReachInputConnection = true;
}
if (isDifferentTextField) {
@@ -905,6 +927,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
switcher.loadKeyboard(editorInfo, currentSettingsValues);
+ if (!canReachInputConnection) {
+ // 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();
+ }
} else if (restarting) {
// TODO: Come up with a more comprehensive way to reset the keyboard layout when
// a keyboard layout set doesn't get reloaded in this method.
@@ -1023,17 +1050,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void onFinishInputViewInternal(final boolean finishingInput) {
super.onFinishInputView(finishingInput);
mKeyboardSwitcher.onFinishInputView();
- final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
- if (mainKeyboardView != null) {
- mainKeyboardView.cancelAllOngoingEvents();
- mainKeyboardView.deallocateMemory();
- }
+ mKeyboardSwitcher.deallocateMemory();
// Remove pending messages related to update suggestions
mHandler.cancelUpdateSuggestionStrip();
// Should do the following in onFinishInputInternal but until JB MR2 it's not called :(
if (mWordComposer.isComposingWord()) mConnection.finishComposingText();
resetComposingState(true /* alsoResetLastComposedWord */);
- mRichImm.clearSubtypeCaches();
// Notify ResearchLogger
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput, mLastSelectionStart,
@@ -1386,14 +1408,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Called from the KeyboardSwitcher which needs to know auto caps state to display
// the right layout.
public int getCurrentAutoCapsState() {
- if (!mSettings.getCurrent().mAutoCap) return Constants.TextUtils.CAP_MODE_OFF;
+ final SettingsValues currentSettingsValues = mSettings.getCurrent();
+ if (!currentSettingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF;
final EditorInfo ei = getCurrentInputEditorInfo();
if (ei == null) return Constants.TextUtils.CAP_MODE_OFF;
final int inputType = ei.inputType;
// Warning: this depends on mSpaceState, which may not be the most current value. If
// mSpaceState gets updated later, whoever called this may need to be told about it.
- return mConnection.getCursorCapsMode(inputType, mSubtypeSwitcher.getCurrentSubtypeLocale(),
+ return mConnection.getCursorCapsMode(inputType, currentSettingsValues,
SPACE_STATE_PHANTOM == mSpaceState);
}
@@ -1434,18 +1457,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private boolean maybeDoubleSpacePeriod() {
- final SettingsValues settingsValues = mSettings.getCurrent();
- if (!settingsValues.mCorrectionEnabled) return false;
- if (!settingsValues.mUseDoubleSpacePeriod) return false;
+ final SettingsValues currentSettingsValues = mSettings.getCurrent();
+ if (!currentSettingsValues.mCorrectionEnabled) return false;
+ if (!currentSettingsValues.mUseDoubleSpacePeriod) return false;
if (!mHandler.isAcceptingDoubleSpacePeriod()) return false;
- final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0);
- if (lastThree != null && lastThree.length() == 3
- && canBeFollowedByDoubleSpacePeriod(lastThree.charAt(0))
- && lastThree.charAt(1) == Constants.CODE_SPACE
- && lastThree.charAt(2) == Constants.CODE_SPACE) {
+ // We only do this when we see two spaces and an accepted code point before the cursor.
+ // The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
+ final CharSequence lastThree = mConnection.getTextBeforeCursor(4, 0);
+ if (null == lastThree) return false;
+ final int length = lastThree.length();
+ if (length < 3) return false;
+ if (lastThree.charAt(length - 1) != Constants.CODE_SPACE) return false;
+ if (lastThree.charAt(length - 2) != Constants.CODE_SPACE) return false;
+ // We know there are spaces in pos -1 and -2, and we have at least three chars.
+ // If we have only three chars, isSurrogatePairs can't return true as charAt(1) is a space,
+ // so this is fine.
+ final int firstCodePoint =
+ Character.isSurrogatePair(lastThree.charAt(0), lastThree.charAt(1)) ?
+ Character.codePointAt(lastThree, 0) : lastThree.charAt(length - 3);
+ if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) {
mHandler.cancelDoubleSpacePeriodTimer();
mConnection.deleteSurroundingText(2, 0);
- final String textToInsert = ". ";
+ final String textToInsert = new String(
+ new int[] { currentSettingsValues.mSentenceSeparator, Constants.CODE_SPACE },
+ 0, 2);
mConnection.commitText(textToInsert, 1);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
@@ -1467,7 +1502,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|| codePoint == Constants.CODE_CLOSING_SQUARE_BRACKET
|| codePoint == Constants.CODE_CLOSING_CURLY_BRACKET
|| codePoint == Constants.CODE_CLOSING_ANGLE_BRACKET
- || codePoint == Constants.CODE_PLUS;
+ || codePoint == Constants.CODE_PLUS
+ || Character.getType(codePoint) == Character.OTHER_SYMBOL;
}
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
@@ -2269,9 +2305,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
- mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
}
}
+ mConnection.finishComposingText();
mRecapitalizeStatus.rotate();
final int numCharsDeleted = mLastSelectionEnd - mLastSelectionStart;
mConnection.setSelection(mLastSelectionEnd, mLastSelectionEnd);
@@ -2928,11 +2964,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!mConnection.resetCachesUponCursorMoveAndReturnSuccess(mLastSelectionStart, false)) {
if (0 < remainingTries) {
mHandler.postResetCaches(tryResumeSuggestions, remainingTries - 1);
+ return;
}
- return;
+ // 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).
}
tryFixLyingCursorPosition();
- mKeyboardSwitcher.updateShiftState();
+ mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent());
if (tryResumeSuggestions) mHandler.postResumeSuggestions();
}