Merge "[CB10] Add an event for string input"

main
Jean Chalard 2014-03-20 11:34:16 +00:00 committed by Android (Google) Code Review
commit 4df6bc0853
3 changed files with 37 additions and 17 deletions

View File

@ -52,6 +52,8 @@ public class Event {
final public static int EVENT_GESTURE = 4; final public static int EVENT_GESTURE = 4;
// An event corresponding to the manual pick of a suggestion. // An event corresponding to the manual pick of a suggestion.
final public static int EVENT_SUGGESTION_PICKED = 5; final public static int EVENT_SUGGESTION_PICKED = 5;
// An event corresponding to a string generated by some software process.
final public static int EVENT_SOFTWARE_GENERATED_STRING = 6;
// 0 is a valid code point, so we use -1 here. // 0 is a valid code point, so we use -1 here.
final public static int NOT_A_CODE_POINT = -1; final public static int NOT_A_CODE_POINT = -1;
@ -71,6 +73,9 @@ public class Event {
// it's not relevant. // it's not relevant.
final public int mCodePoint; final public int mCodePoint;
// If applicable, this contains the string that should be input.
final public CharSequence mText;
// The key code associated with the event, if relevant. This is relevant whenever this event // The key code associated with the event, if relevant. This is relevant whenever this event
// has been triggered by a key press, but not for a gesture for example. This has conceptually // has been triggered by a key press, but not for a gesture for example. This has conceptually
// no link to the code point, although keys that enter a straight code point may often set // no link to the code point, although keys that enter a straight code point may often set
@ -96,9 +101,11 @@ public class Event {
final public Event mNextEvent; final public Event mNextEvent;
// This method is private - to create a new event, use one of the create* utility methods. // This method is private - to create a new event, use one of the create* utility methods.
private Event(final int type, final int codePoint, final int keyCode, final int x, final int y, private Event(final int type, final CharSequence text, final int codePoint, final int keyCode,
final SuggestedWordInfo suggestedWordInfo, final int flags, final Event next) { final int x, final int y, final SuggestedWordInfo suggestedWordInfo, final int flags,
final Event next) {
mType = type; mType = type;
mText = text;
mCodePoint = codePoint; mCodePoint = codePoint;
mKeyCode = keyCode; mKeyCode = keyCode;
mX = x; mX = x;
@ -123,13 +130,13 @@ public class Event {
public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode, public static Event createSoftwareKeypressEvent(final int codePoint, final int keyCode,
final int x, final int y) { final int x, final int y) {
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, x, y, return new Event(EVENT_INPUT_KEYPRESS, null /* text */, codePoint, keyCode, x, y,
null /* suggestedWordInfo */, FLAG_NONE, null); null /* suggestedWordInfo */, FLAG_NONE, null);
} }
public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode, public static Event createHardwareKeypressEvent(final int codePoint, final int keyCode,
final Event next) { final Event next) {
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, return new Event(EVENT_INPUT_KEYPRESS, null /* text */, codePoint, keyCode,
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
null /* suggestedWordInfo */, FLAG_NONE, next); null /* suggestedWordInfo */, FLAG_NONE, next);
} }
@ -137,7 +144,7 @@ public class Event {
// This creates an input event for a dead character. @see {@link #FLAG_DEAD} // This creates an input event for a dead character. @see {@link #FLAG_DEAD}
public static Event createDeadEvent(final int codePoint, final int keyCode, final Event next) { public static Event createDeadEvent(final int codePoint, final int keyCode, final Event next) {
// TODO: add an argument or something if we ever create a software layout with dead keys. // TODO: add an argument or something if we ever create a software layout with dead keys.
return new Event(EVENT_INPUT_KEYPRESS, codePoint, keyCode, return new Event(EVENT_INPUT_KEYPRESS, null /* text */, codePoint, keyCode,
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE,
null /* suggestedWordInfo */, FLAG_DEAD, next); null /* suggestedWordInfo */, FLAG_DEAD, next);
} }
@ -151,7 +158,7 @@ public class Event {
*/ */
public static Event createEventForCodePointFromUnknownSource(final int codePoint) { public static Event createEventForCodePointFromUnknownSource(final int codePoint) {
// TODO: should we have a different type of event for this? After all, it's not a key press. // TODO: should we have a different type of event for this? After all, it's not a key press.
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, return new Event(EVENT_INPUT_KEYPRESS, null /* text */, codePoint, NOT_A_KEY_CODE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
null /* suggestedWordInfo */, FLAG_NONE, null /* next */); null /* suggestedWordInfo */, FLAG_NONE, null /* next */);
} }
@ -167,7 +174,7 @@ public class Event {
public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint, public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint,
final int x, final int y) { final int x, final int y) {
// TODO: should we have a different type of event for this? After all, it's not a key press. // TODO: should we have a different type of event for this? After all, it's not a key press.
return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, x, y, return new Event(EVENT_INPUT_KEYPRESS, null /* text */, codePoint, NOT_A_KEY_CODE, x, y,
null /* suggestedWordInfo */, FLAG_NONE, null /* next */); null /* suggestedWordInfo */, FLAG_NONE, null /* next */);
} }
@ -176,13 +183,28 @@ public class Event {
* @return an event for this suggestion pick. * @return an event for this suggestion pick.
*/ */
public static Event createSuggestionPickedEvent(final SuggestedWordInfo suggestedWordInfo) { public static Event createSuggestionPickedEvent(final SuggestedWordInfo suggestedWordInfo) {
return new Event(EVENT_SUGGESTION_PICKED, NOT_A_CODE_POINT, NOT_A_KEY_CODE, return new Event(EVENT_SUGGESTION_PICKED, suggestedWordInfo.mWord,
NOT_A_CODE_POINT, NOT_A_KEY_CODE,
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE,
suggestedWordInfo, FLAG_NONE, null); suggestedWordInfo, FLAG_NONE, null);
} }
/**
* Creates an input event with a CharSequence. This is used by some software processes whose
* output is a string, possibly with styling. Examples include press on a multi-character key,
* or combination that outputs a string.
* @param text the CharSequence associated with this event.
* @param keyCode the key code, or NOT_A_KEYCODE if not applicable.
* @return an event for this text.
*/
public static Event createSoftwareTextEvent(final CharSequence text, final int keyCode) {
return new Event(EVENT_SOFTWARE_GENERATED_STRING, text, NOT_A_CODE_POINT, keyCode,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
null /* suggestedWordInfo */, FLAG_NONE, null /* next */);
}
public static Event createNotHandledEvent() { public static Event createNotHandledEvent() {
return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE, return new Event(EVENT_NOT_HANDLED, null /* text */, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
null /* suggestedWordInfo */, FLAG_NONE, null); null /* suggestedWordInfo */, FLAG_NONE, null);
} }
@ -198,11 +220,6 @@ public class Event {
return EVENT_INPUT_KEYPRESS == mType && Constants.SUGGESTION_STRIP_COORDINATE == mX; return EVENT_INPUT_KEYPRESS == mType && Constants.SUGGESTION_STRIP_COORDINATE == mX;
} }
// TODO: remove this method - we should not have to test this
public boolean isCommittable() {
return EVENT_INPUT_KEYPRESS == mType || EVENT_MODE_KEY == mType || EVENT_TOGGLE == mType;
}
public boolean isHandled() { public boolean isHandled() {
return EVENT_NOT_HANDLED != mType; return EVENT_NOT_HANDLED != mType;
} }

View File

@ -1277,7 +1277,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Called from PointerTracker through the KeyboardActionListener interface // Called from PointerTracker through the KeyboardActionListener interface
@Override @Override
public void onTextInput(final String rawText) { public void onTextInput(final String rawText) {
mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler); // TODO: have the keyboard pass the correct key code when we need it.
final Event event = Event.createSoftwareTextEvent(rawText, Event.NOT_A_KEY_CODE);
mInputLogic.onTextInput(mSettings.getCurrent(), event, mHandler);
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT); mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
} }

View File

@ -161,11 +161,12 @@ public final class InputLogic {
* some additional keys for example. * some additional keys for example.
* *
* @param settingsValues the current values of the settings. * @param settingsValues the current values of the settings.
* @param rawText the text to input. * @param event the input event containing the data.
*/ */
public void onTextInput(final SettingsValues settingsValues, final String rawText, public void onTextInput(final SettingsValues settingsValues, final Event event,
// TODO: remove this argument // TODO: remove this argument
final LatinIME.UIHandler handler) { final LatinIME.UIHandler handler) {
final String rawText = event.mText.toString();
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) { if (mWordComposer.isComposingWord()) {
commitCurrentAutoCorrection(settingsValues, rawText, handler); commitCurrentAutoCorrection(settingsValues, rawText, handler);