aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java8
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java30
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java86
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java3
4 files changed, 75 insertions, 52 deletions
diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
index a01c301ee..ab7bd4914 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
@@ -52,6 +52,10 @@ public final class InputMethodManagerCompatWrapper {
sInstance.mImm = ImfUtils.getInputMethodManager(context);
}
+ public InputMethodSubtype getCurrentInputMethodSubtype() {
+ return mImm.getCurrentInputMethodSubtype();
+ }
+
public InputMethodSubtype getLastInputMethodSubtype() {
return mImm.getLastInputMethodSubtype();
}
@@ -65,6 +69,10 @@ public final class InputMethodManagerCompatWrapper {
onlyCurrentIme);
}
+ public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
+ mImm.setInputMethodAndSubtype(token, id, subtype);
+ }
+
public void showInputMethodPicker() {
mImm.showInputMethodPicker();
}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
index b0b65edb6..9a3f88f52 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
@@ -154,6 +154,9 @@ public final class BinaryDictionaryFileDumper {
for (int mode = MODE_MIN; mode <= MODE_MAX; ++mode) {
InputStream originalSourceStream = null;
InputStream inputStream = null;
+ InputStream uncompressedStream = null;
+ InputStream decryptedStream = null;
+ BufferedInputStream bufferedStream = null;
File outputFile = null;
FileOutputStream outputStream = null;
AssetFileDescriptor afd = null;
@@ -173,18 +176,19 @@ public final class BinaryDictionaryFileDumper {
// Get the appropriate decryption method for this try
switch (mode) {
case COMPRESSED_CRYPTED_COMPRESSED:
- inputStream = FileTransforms.getUncompressedStream(
- FileTransforms.getDecryptedStream(
- FileTransforms.getUncompressedStream(
- originalSourceStream)));
+ uncompressedStream =
+ FileTransforms.getUncompressedStream(originalSourceStream);
+ decryptedStream = FileTransforms.getDecryptedStream(uncompressedStream);
+ inputStream = FileTransforms.getUncompressedStream(decryptedStream);
break;
case CRYPTED_COMPRESSED:
- inputStream = FileTransforms.getUncompressedStream(
- FileTransforms.getDecryptedStream(originalSourceStream));
+ decryptedStream = FileTransforms.getDecryptedStream(originalSourceStream);
+ inputStream = FileTransforms.getUncompressedStream(decryptedStream);
break;
case COMPRESSED_CRYPTED:
- inputStream = FileTransforms.getDecryptedStream(
- FileTransforms.getUncompressedStream(originalSourceStream));
+ uncompressedStream =
+ FileTransforms.getUncompressedStream(originalSourceStream);
+ inputStream = FileTransforms.getDecryptedStream(uncompressedStream);
break;
case COMPRESSED_ONLY:
inputStream = FileTransforms.getUncompressedStream(originalSourceStream);
@@ -195,8 +199,9 @@ public final class BinaryDictionaryFileDumper {
case NONE:
inputStream = originalSourceStream;
break;
- }
- checkMagicAndCopyFileTo(new BufferedInputStream(inputStream), outputStream);
+ }
+ bufferedStream = new BufferedInputStream(inputStream);
+ checkMagicAndCopyFileTo(bufferedStream, outputStream);
outputStream.flush();
outputStream.close();
final File finalFile = new File(finalFileName);
@@ -228,8 +233,11 @@ public final class BinaryDictionaryFileDumper {
try {
// inputStream.close() will close afd, we should not call afd.close().
if (null != inputStream) inputStream.close();
+ if (null != uncompressedStream) uncompressedStream.close();
+ if (null != decryptedStream) decryptedStream.close();
+ if (null != bufferedStream) bufferedStream.close();
} catch (Exception e) {
- Log.e(TAG, "Exception while closing a cross-process file descriptor : " + e);
+ Log.e(TAG, "Exception while closing a file descriptor : " + e);
}
try {
if (null != outputStream) outputStream.close();
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3dca9f4fe..f416396e8 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -141,7 +141,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private SharedPreferences mPrefs;
/* package for tests */ final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher;
- private boolean mShouldSwitchToLastSubtype = true;
+ private final SubtypeState mSubtypeState = new SubtypeState();
private boolean mIsMainDictionaryAvailable;
private UserBinaryDictionary mUserDictionary;
@@ -365,6 +365,34 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
}
+ static final class SubtypeState {
+ private InputMethodSubtype mLastActiveSubtype;
+ private boolean mCurrentSubtypeUsed;
+
+ public void currentSubtypeUsed() {
+ mCurrentSubtypeUsed = true;
+ }
+
+ public void switchSubtype(final IBinder token, final InputMethodManagerCompatWrapper imm,
+ final Context context) {
+ final InputMethodSubtype currentSubtype = imm.getCurrentInputMethodSubtype();
+ final InputMethodSubtype lastActiveSubtype = mLastActiveSubtype;
+ final boolean currentSubtypeUsed = mCurrentSubtypeUsed;
+ if (currentSubtypeUsed) {
+ mLastActiveSubtype = currentSubtype;
+ mCurrentSubtypeUsed = false;
+ }
+ if (currentSubtypeUsed
+ && ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(context, lastActiveSubtype)
+ && !currentSubtype.equals(lastActiveSubtype)) {
+ final String id = ImfUtils.getInputMethodIdOfThisIme(context);
+ imm.setInputMethodAndSubtype(token, id, lastActiveSubtype);
+ return;
+ }
+ imm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
+ }
+ }
+
public LatinIME() {
super();
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
@@ -683,8 +711,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting);
}
- final boolean selectionChanged = mLastSelectionStart != editorInfo.initialSelStart
- || mLastSelectionEnd != editorInfo.initialSelEnd;
final boolean inputTypeChanged = !mCurrentSettings.isSameInputType(editorInfo);
final boolean isDifferentTextField = !restarting || inputTypeChanged;
if (isDifferentTextField) {
@@ -704,21 +730,17 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
updateFullscreenMode();
mApplicationSpecifiedCompletions = null;
- if (isDifferentTextField || selectionChanged) {
- // If the selection changed, we reset the input state. Essentially, we come here with
- // restarting == true when the app called setText() or similar. We should reset the
- // state if the app set the text to something else, but keep it if it set a suggestion
- // or something.
- mEnteredText = null;
- resetComposingState(true /* alsoResetLastComposedWord */);
- mDeleteCount = 0;
- mSpaceState = SPACE_STATE_NONE;
+ // The app calling setText() has the effect of clearing the composing
+ // span, so we should reset our state unconditionally, even if restarting is true.
+ mEnteredText = null;
+ resetComposingState(true /* alsoResetLastComposedWord */);
+ mDeleteCount = 0;
+ mSpaceState = SPACE_STATE_NONE;
- if (mSuggestionStripView != null) {
- // This will set the punctuation suggestions if next word suggestion is off;
- // otherwise it will clear the suggestion strip.
- setPunctuationSuggestions();
- }
+ if (mSuggestionStripView != null) {
+ // This will set the punctuation suggestions if next word suggestion is off;
+ // otherwise it will clear the suggestion strip.
+ setPunctuationSuggestions();
}
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
@@ -736,20 +758,17 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// 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.
switcher.resetKeyboardStateToAlphabet();
+ // In apps like Talk, we come here when the text is sent and the field gets emptied and
+ // we need to re-evaluate the shift state, but not the whole layout which would be
+ // disruptive.
+ // Space state must be updated before calling updateShiftState
+ switcher.updateShiftState();
}
setSuggestionStripShownInternal(
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
mLastSelectionStart = editorInfo.initialSelStart;
mLastSelectionEnd = editorInfo.initialSelEnd;
- // If we come here something in the text state is very likely to have changed.
- // We should update the shift state regardless of whether we are restarting or not, because
- // this is not perceived as a layout change that may be disruptive like we may have with
- // switcher.loadKeyboard; in apps like Talk, we come here when the text is sent and the
- // field gets emptied and we need to re-evaluate the shift state, but not the whole layout
- // which would be disruptive.
- // Space state must be updated before calling updateShiftState
- mKeyboardSwitcher.updateShiftState();
mHandler.cancelUpdateSuggestionStrip();
mHandler.cancelDoubleSpacesTimer();
@@ -891,6 +910,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Make a note of the cursor position
mLastSelectionStart = newSelStart;
mLastSelectionEnd = newSelEnd;
+ mSubtypeState.currentSubtypeUsed();
}
/**
@@ -1239,19 +1259,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return;
}
- if (mShouldSwitchToLastSubtype) {
- final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
- final boolean lastSubtypeBelongsToThisIme =
- ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(this, lastSubtype);
- if (lastSubtypeBelongsToThisIme && mImm.switchToLastInputMethod(token)) {
- mShouldSwitchToLastSubtype = false;
- } else {
- mImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
- mShouldSwitchToLastSubtype = true;
- }
- } else {
- mImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
- }
+ mSubtypeState.switchSubtype(token, mImm, this);
}
private void sendDownUpKeyEventForBackwardCompatibility(final int code) {
@@ -1320,7 +1328,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleBackspace(spaceState);
mDeleteCount++;
mExpectingUpdateSelection = true;
- mShouldSwitchToLastSubtype = true;
LatinImeLogger.logOnDelete(x, y);
break;
case Keyboard.CODE_SHIFT:
@@ -1376,7 +1383,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleCharacter(primaryCode, keyX, keyY, spaceState);
}
mExpectingUpdateSelection = true;
- mShouldSwitchToLastSubtype = true;
break;
}
switcher.onCodeInput(primaryCode);
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 21441369e..75b67bfc6 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -145,7 +145,8 @@ public final class RichInputConnection {
mCurrentCursorPosition = newCursorPosition;
mComposingText.setLength(0);
mCommittedTextBeforeComposingText.setLength(0);
- mCommittedTextBeforeComposingText.append(getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE, 0));
+ final CharSequence textBeforeCursor = getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE, 0);
+ if (null != textBeforeCursor) mCommittedTextBeforeComposingText.append(textBeforeCursor);
mCharAfterTheCursor = getTextAfterCursor(1, 0);
if (null != mIC) {
mIC.finishComposingText();