Merge "Introduce onEvent() to improve testability"
This commit is contained in:
commit
1a31d784cd
2 changed files with 34 additions and 21 deletions
|
@ -1271,10 +1271,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mSubtypeState.switchSubtype(token, mRichImm);
|
mSubtypeState.switchSubtype(token, mRichImm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
|
||||||
|
// alphabetic shift and shift while in symbol layout and get rid of this method.
|
||||||
|
private int getCodePointForKeyboard(final int codePoint) {
|
||||||
|
if (Constants.CODE_SHIFT == codePoint) {
|
||||||
|
final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
|
||||||
|
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
|
||||||
|
return codePoint;
|
||||||
|
} else {
|
||||||
|
return Constants.CODE_SYMBOL_SHIFT;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return codePoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of {@link KeyboardActionListener}.
|
// Implementation of {@link KeyboardActionListener}.
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(final int codePoint, final int x, final int y,
|
public void onCodeInput(final int codePoint, final int x, final int y,
|
||||||
final boolean isKeyRepeat) {
|
final boolean isKeyRepeat) {
|
||||||
|
// TODO: this processing does not belong inside LatinIME, the caller should be doing this.
|
||||||
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||||
// x and y include some padding, but everything down the line (especially native
|
// x and y include some padding, but everything down the line (especially native
|
||||||
// code) needs the coordinates in the keyboard frame.
|
// code) needs the coordinates in the keyboard frame.
|
||||||
|
@ -1283,36 +1299,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// this transformation, it should be done already before calling onCodeInput.
|
// this transformation, it should be done already before calling onCodeInput.
|
||||||
final int keyX = mainKeyboardView.getKeyX(x);
|
final int keyX = mainKeyboardView.getKeyX(x);
|
||||||
final int keyY = mainKeyboardView.getKeyY(y);
|
final int keyY = mainKeyboardView.getKeyY(y);
|
||||||
final int codeToSend;
|
final Event event = createSoftwareKeypressEvent(getCodePointForKeyboard(codePoint),
|
||||||
if (Constants.CODE_SHIFT == codePoint) {
|
keyX, keyY, isKeyRepeat);
|
||||||
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
|
onEvent(event);
|
||||||
// alphabetic shift and shift while in symbol layout.
|
}
|
||||||
final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
|
|
||||||
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
|
// This method is public for testability of LatinIME, but also in the future it should
|
||||||
codeToSend = codePoint;
|
// completely replace #onCodeInput.
|
||||||
} else {
|
public void onEvent(final Event event) {
|
||||||
codeToSend = Constants.CODE_SYMBOL_SHIFT;
|
if (Constants.CODE_SHORTCUT == event.mCodePoint) {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
codeToSend = codePoint;
|
|
||||||
}
|
|
||||||
if (Constants.CODE_SHORTCUT == codePoint) {
|
|
||||||
mSubtypeSwitcher.switchToShortcutIME(this);
|
mSubtypeSwitcher.switchToShortcutIME(this);
|
||||||
// Still call the *#onCodeInput methods for readability.
|
|
||||||
}
|
}
|
||||||
final Event event = createSoftwareKeypressEvent(codeToSend, keyX, keyY, isKeyRepeat);
|
|
||||||
final InputTransaction completeInputTransaction =
|
final InputTransaction completeInputTransaction =
|
||||||
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
||||||
mKeyboardSwitcher.getKeyboardShiftMode(),
|
mKeyboardSwitcher.getKeyboardShiftMode(),
|
||||||
mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
|
mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
|
||||||
updateStateAfterInputTransaction(completeInputTransaction);
|
updateStateAfterInputTransaction(completeInputTransaction);
|
||||||
mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState(),
|
mKeyboardSwitcher.onCodeInput(event.mCodePoint, getCurrentAutoCapsState(),
|
||||||
getCurrentRecapitalizeState());
|
getCurrentRecapitalizeState());
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper method to split the code point and the key code. Ultimately, they should not be
|
// A helper method to split the code point and the key code. Ultimately, they should not be
|
||||||
// squashed into the same variable, and this method should be removed.
|
// squashed into the same variable, and this method should be removed.
|
||||||
private static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX,
|
// public for testing, as we don't want to copy the same logic into test code
|
||||||
|
public static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX,
|
||||||
final int keyY, final boolean isKeyRepeat) {
|
final int keyY, final boolean isKeyRepeat) {
|
||||||
final int keyCode;
|
final int keyCode;
|
||||||
final int codePoint;
|
final int codePoint;
|
||||||
|
|
|
@ -36,6 +36,7 @@ import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
||||||
|
import com.android.inputmethod.event.Event;
|
||||||
import com.android.inputmethod.keyboard.Key;
|
import com.android.inputmethod.keyboard.Key;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
@ -263,14 +264,16 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||||
// but keep them in mind if something breaks. Commenting them out as is should work.
|
// but keep them in mind if something breaks. Commenting them out as is should work.
|
||||||
//mLatinIME.onPressKey(codePoint, 0 /* repeatCount */, true /* isSinglePointer */);
|
//mLatinIME.onPressKey(codePoint, 0 /* repeatCount */, true /* isSinglePointer */);
|
||||||
final Key key = mKeyboard.getKey(codePoint);
|
final Key key = mKeyboard.getKey(codePoint);
|
||||||
|
final Event event;
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
mLatinIME.onCodeInput(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
|
event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE,
|
||||||
isKeyRepeat);
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, isKeyRepeat);
|
||||||
} else {
|
} else {
|
||||||
final int x = key.getX() + key.getWidth() / 2;
|
final int x = key.getX() + key.getWidth() / 2;
|
||||||
final int y = key.getY() + key.getHeight() / 2;
|
final int y = key.getY() + key.getHeight() / 2;
|
||||||
mLatinIME.onCodeInput(codePoint, x, y, isKeyRepeat);
|
event = mLatinIME.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat);
|
||||||
}
|
}
|
||||||
|
mLatinIME.onEvent(event);
|
||||||
// Also see the comment at the top of this function about onReleaseKey
|
// Also see the comment at the top of this function about onReleaseKey
|
||||||
//mLatinIME.onReleaseKey(codePoint, false /* withSliding */);
|
//mLatinIME.onReleaseKey(codePoint, false /* withSliding */);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue