Change the batch input methods of KeyboardActionListener

This change also removes the reference of SuggestedWords from
GestureTracker and KeyboardActionListener.

Change-Id: I25ef8756007986abf99a931afd665bbfe6fa387f
main
Tadashi G. Takaoka 2012-07-18 18:14:51 +09:00
parent f39fccbd0f
commit 10102f02af
4 changed files with 33 additions and 23 deletions

View File

@ -17,7 +17,6 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.SuggestedWords;
public interface KeyboardActionListener { public interface KeyboardActionListener {
@ -73,18 +72,17 @@ public interface KeyboardActionListener {
public void onStartBatchInput(); public void onStartBatchInput();
/** /**
* Sends the batch input points data to get updated suggestions * Sends the ongoing batch input points data.
* @param batchPointers the batch input points representing the user input * @param batchPointers the batch input points representing the user input
* @return updated suggestions that reflects the user input
*/ */
public SuggestedWords onUpdateBatchInput(InputPointers batchPointers); public void onUpdateBatchInput(InputPointers batchPointers);
/** /**
* Sends a sequence of characters to the listener as batch input. * Sends the final batch input points data.
* *
* @param text the sequence of characters to be displayed as composing text. * @param batchPointers the batch input points representing the user input
*/ */
public void onEndBatchInput(CharSequence text); public void onEndBatchInput(InputPointers batchPointers);
/** /**
* Called when user released a finger outside any key. * Called when user released a finger outside any key.
@ -109,9 +107,9 @@ public interface KeyboardActionListener {
@Override @Override
public void onStartBatchInput() {} public void onStartBatchInput() {}
@Override @Override
public SuggestedWords onUpdateBatchInput(InputPointers batchPointers) { return null; } public void onUpdateBatchInput(InputPointers batchPointers) {}
@Override @Override
public void onEndBatchInput(CharSequence text) {} public void onEndBatchInput(InputPointers batchPointers) {}
@Override @Override
public void onCancelInput() {} public void onCancelInput() {}
@Override @Override

View File

@ -25,6 +25,7 @@ import android.widget.PopupWindow;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
/** /**
@ -63,8 +64,13 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
} }
@Override @Override
public void onEndBatchInput(CharSequence text) { public void onUpdateBatchInput(InputPointers batchPointers) {
mListener.onEndBatchInput(text); mListener.onUpdateBatchInput(batchPointers);
}
@Override
public void onEndBatchInput(InputPointers batchPointers) {
mListener.onEndBatchInput(batchPointers);
} }
@Override @Override

View File

@ -21,7 +21,6 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.SuggestedWords;
// TODO: Remove this class by consolidating with PointerTracker // TODO: Remove this class by consolidating with PointerTracker
public class GestureTracker { public class GestureTracker {
@ -40,7 +39,6 @@ public class GestureTracker {
private boolean mInGesture = false; private boolean mInGesture = false;
private KeyboardActionListener mListener; private KeyboardActionListener mListener;
private SuggestedWords mSuggestions;
private int mLastRecognitionPointSize = 0; private int mLastRecognitionPointSize = 0;
private long mLastRecognitionTime = 0; private long mLastRecognitionTime = 0;
@ -66,17 +64,16 @@ public class GestureTracker {
} }
mInGesture = true; mInGesture = true;
mListener.onStartBatchInput(); mListener.onStartBatchInput();
mSuggestions = null;
} }
// TODO: The corresponding startBatchInput() is a private method. Reorganize the code. // TODO: The corresponding startBatchInput() is a private method. Reorganize the code.
public void endBatchInput() { public void endBatchInput() {
if (isInGesture() && mSuggestions != null && mSuggestions.size() > 0) { if (isInGesture()) {
final CharSequence text = mSuggestions.getWord(0); final InputPointers batchPoints = PointerTracker.getAllBatchPoints();
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onEndBatchInput: text=" + text); Log.d(TAG, "onEndBatchInput: batchPoints=" + batchPoints.getPointerSize());
} }
mListener.onEndBatchInput(text); mListener.onEndBatchInput(batchPoints);
} }
mInGesture = false; mInGesture = false;
clearBatchInputPoints(); clearBatchInputPoints();
@ -117,7 +114,7 @@ public class GestureTracker {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize()); Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize());
} }
mSuggestions = mListener.onUpdateBatchInput(batchPoints); mListener.onUpdateBatchInput(batchPoints);
} }
} }
} }
@ -128,7 +125,7 @@ public class GestureTracker {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize()); Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize());
} }
mSuggestions = mListener.onUpdateBatchInput(batchPoints); mListener.onUpdateBatchInput(batchPoints);
} }
} }

View File

@ -1329,13 +1329,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
@Override @Override
public SuggestedWords onUpdateBatchInput(InputPointers batchPointers) { public void onUpdateBatchInput(InputPointers batchPointers) {
mWordComposer.setBatchInputPointers(batchPointers); mWordComposer.setBatchInputPointers(batchPointers);
return updateSuggestionsOrPredictions(); updateSuggestionsOrPredictions();
} }
@Override @Override
public void onEndBatchInput(CharSequence text) { public void onEndBatchInput(InputPointers batchPointers) {
mWordComposer.setBatchInputPointers(batchPointers);
final SuggestedWords suggestedWords = updateSuggestionsOrPredictions();
if (suggestedWords == null || suggestedWords.size() == 0) {
return;
}
final CharSequence text = suggestedWords.getWord(0);
if (TextUtils.isEmpty(text)) {
return;
}
mWordComposer.setBatchInputWord(text); mWordComposer.setBatchInputWord(text);
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
if (SPACE_STATE_PHANTOM == mSpaceState) { if (SPACE_STATE_PHANTOM == mSpaceState) {