Merge "Extend onTextInput to be able to inject suggestions"

This commit is contained in:
Tadashi G. Takaoka 2012-07-06 03:40:03 -07:00 committed by Android (Google) Code Review
commit 36311cacd6
3 changed files with 62 additions and 1 deletions

View file

@ -64,6 +64,20 @@ public interface KeyboardActionListener {
*/ */
public void onTextInput(CharSequence text); public void onTextInput(CharSequence text);
// TODO: Should move this method to some more appropriate interface.
/**
* Called when user started batch input.
*/
public void onStartBatchInput();
// TODO: Should move this method to some more appropriate interface.
/**
* Sends a sequence of characters to the listener as batch input.
*
* @param text the sequence of characters to be displayed as composing text.
*/
public void onEndBatchInput(CharSequence text);
/** /**
* Called when user released a finger outside any key. * Called when user released a finger outside any key.
*/ */
@ -85,6 +99,10 @@ public interface KeyboardActionListener {
@Override @Override
public void onTextInput(CharSequence text) {} public void onTextInput(CharSequence text) {}
@Override @Override
public void onStartBatchInput() {}
@Override
public void onEndBatchInput(CharSequence text) {}
@Override
public void onCancelInput() {} public void onCancelInput() {}
@Override @Override
public boolean onCustomRequest(int requestCode) { public boolean onCustomRequest(int requestCode) {

View file

@ -57,6 +57,16 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
mListener.onTextInput(text); mListener.onTextInput(text);
} }
@Override
public void onStartBatchInput() {
mListener.onStartBatchInput();
}
@Override
public void onEndBatchInput(CharSequence text) {
mListener.onEndBatchInput(text);
}
@Override @Override
public void onCancelInput() { public void onCancelInput() {
mListener.onCancelInput(); mListener.onCancelInput();

View file

@ -1272,6 +1272,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mCurrentSettings.isWordSeparator(primaryCode)) { if (mCurrentSettings.isWordSeparator(primaryCode)) {
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState); didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
} else { } else {
if (SPACE_STATE_PHANTOM == spaceState) {
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
}
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
if (keyboard != null && keyboard.hasProximityCharsCorrection(primaryCode)) { if (keyboard != null && keyboard.hasProximityCharsCorrection(primaryCode)) {
handleCharacter(primaryCode, x, y, spaceState); handleCharacter(primaryCode, x, y, spaceState);
@ -1313,6 +1316,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
resetComposingState(true /* alsoResetLastComposedWord */); resetComposingState(true /* alsoResetLastComposedWord */);
} }
@Override
public void onStartBatchInput() {
mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) {
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
mExpectingUpdateSelection = true;
// TODO: Can we remove this?
mSpaceState = SPACE_STATE_PHANTOM;
}
mConnection.endBatchEdit();
}
@Override
public void onEndBatchInput(CharSequence text) {
mConnection.beginBatchEdit();
if (SPACE_STATE_PHANTOM == mSpaceState) {
sendKeyCodePoint(Keyboard.CODE_SPACE);
}
mConnection.setComposingText(text, 1);
mExpectingUpdateSelection = true;
mConnection.endBatchEdit();
mKeyboardSwitcher.updateShiftState();
mSpaceState = SPACE_STATE_PHANTOM;
}
private CharSequence specificTldProcessingOnTextInput(final CharSequence text) { private CharSequence specificTldProcessingOnTextInput(final CharSequence text) {
if (text.length() <= 1 || text.charAt(0) != Keyboard.CODE_PERIOD if (text.length() <= 1 || text.charAt(0) != Keyboard.CODE_PERIOD
|| !Character.isLetter(text.charAt(1))) { || !Character.isLetter(text.charAt(1))) {
@ -1359,7 +1387,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mWordComposer.isComposingWord()) { if (mWordComposer.isComposingWord()) {
final int length = mWordComposer.size(); final int length = mWordComposer.size();
if (length > 0) { if (length > 0) {
mWordComposer.deleteLast(); // Immediately after a batch input.
if (SPACE_STATE_PHANTOM == spaceState) {
mWordComposer.reset();
} else {
mWordComposer.deleteLast();
}
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
// If we have deleted the last remaining character of a word, then we are not // If we have deleted the last remaining character of a word, then we are not
// isComposingWord() any more. // isComposingWord() any more.