Merge "InputConnection is warned when finished"

This commit is contained in:
Gilles Debunne
2012-02-28 18:05:28 -08:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 18 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

@@ -708,6 +708,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);