summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gilles Debunne <debunne@google.com> 2012-02-24 16:07:09 -0800
committer Gilles Debunne <debunne@google.com> 2012-02-24 16:12:52 -0800
commit9d69ecbf61a4a142c3f4cbb9d5659faa6f85e832 (patch)
tree5ad899360d5ec59543d95a32685d8886982ca27d
parenta16c98c155a51a035719bef5b76e973ee2295795 (diff)
InputConnection is warned when finished
As said in https://android-git.corp.google.com/g/#/c/155992 finishComposingText is indeed too broad of a method. Introducing a new dedicated method to warn the InputConnection. Should solve the problems with a negative counter value. Change-Id: I5525d776916f0c42d5e6d4a4282aed590d7f0e9a
-rw-r--r--core/java/android/view/inputmethod/BaseInputConnection.java9
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java5
-rw-r--r--core/java/com/android/internal/widget/EditableInputConnection.java32
3 files changed, 27 insertions, 19 deletions
diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java
index 89aba3ca1e83..7ec53980876b 100644
--- a/core/java/android/view/inputmethod/BaseInputConnection.java
+++ b/core/java/android/view/inputmethod/BaseInputConnection.java
@@ -152,6 +152,15 @@ public class BaseInputConnection implements InputConnection {
}
/**
+ * Called when this InputConnection is no longer used by the InputMethodManager.
+ *
+ * @hide
+ */
+ protected void reportFinish() {
+ // Intentionaly empty
+ }
+
+ /**
* Default implementation uses
* {@link MetaKeyKeyListener#clearMetaKeyState(long, int)
* MetaKeyKeyListener.clearMetaKeyState(long, int)} to clear the state.
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index c51d2440f893..15afb394a91a 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -26,7 +26,6 @@ import com.android.internal.view.IInputMethodSession;
import com.android.internal.view.InputBindResult;
import android.content.Context;
-import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
@@ -690,6 +689,10 @@ public final class InputMethodManager {
public void reportFinishInputConnection(InputConnection ic) {
if (mServedInputConnection != ic) {
ic.finishComposingText();
+ // To avoid modifying the public InputConnection interface
+ if (ic instanceof BaseInputConnection) {
+ ((BaseInputConnection) ic).reportFinish();
+ }
}
}
diff --git a/core/java/com/android/internal/widget/EditableInputConnection.java b/core/java/com/android/internal/widget/EditableInputConnection.java
index 9579bce468da..4cbdf784e1a9 100644
--- a/core/java/com/android/internal/widget/EditableInputConnection.java
+++ b/core/java/com/android/internal/widget/EditableInputConnection.java
@@ -70,7 +70,7 @@ public class EditableInputConnection extends BaseInputConnection {
public boolean endBatchEdit() {
synchronized(this) {
if (mBatchEditNesting > 0) {
- // When the connection is reset by the InputMethodManager and finishComposingText
+ // When the connection is reset by the InputMethodManager and reportFinish
// is called, some endBatchEdit calls may still be asynchronously received from the
// IME. Do not take these into account, thus ensuring that this IC's final
// contribution to mTextView's nested batch edit count is zero.
@@ -83,6 +83,19 @@ public class EditableInputConnection extends BaseInputConnection {
}
@Override
+ protected void reportFinish() {
+ super.reportFinish();
+
+ synchronized(this) {
+ while (mBatchEditNesting > 0) {
+ endBatchEdit();
+ }
+ // Will prevent any further calls to begin or endBatchEdit
+ mBatchEditNesting = -1;
+ }
+ }
+
+ @Override
public boolean clearMetaKeyStates(int states) {
final Editable content = getEditable();
if (content == null) return false;
@@ -99,23 +112,6 @@ public class EditableInputConnection extends BaseInputConnection {
}
@Override
- public boolean finishComposingText() {
- final boolean superResult = super.finishComposingText();
- synchronized(this) {
- if (mBatchEditNesting < 0) {
- // The connection was already finished
- return false;
- }
- while (mBatchEditNesting > 0) {
- endBatchEdit();
- }
- // Will prevent any further calls to begin or endBatchEdit
- mBatchEditNesting = -1;
- }
- return superResult;
- }
-
- @Override
public boolean commitCompletion(CompletionInfo text) {
if (DEBUG) Log.v(TAG, "commitCompletion " + text);
mTextView.beginBatchEdit();