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
This commit is contained in:
Gilles Debunne
2012-02-24 16:07:09 -08:00
parent a16c98c155
commit 9d69ecbf61
3 changed files with 27 additions and 19 deletions

View File

@@ -151,6 +151,15 @@ public class BaseInputConnection implements InputConnection {
return false;
}
/**
* 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)

View File

@@ -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();
}
}
}

View File

@@ -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.
@@ -82,6 +82,19 @@ public class EditableInputConnection extends BaseInputConnection {
return false;
}
@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();
@@ -98,23 +111,6 @@ public class EditableInputConnection extends BaseInputConnection {
return true;
}
@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);