Loading java/src/com/android/inputmethod/event/Event.java +12 −18 Original line number Original line Diff line number Diff line Loading @@ -54,39 +54,33 @@ public class Event { final private static int NOT_A_CODE_POINT = 0; final private static int NOT_A_CODE_POINT = 0; private int mType; // The type of event - one of the constants above final private int mType; // The type of event - one of the constants above // The code point associated with the event, if relevant. This is a unicode code point, and // The code point associated with the event, if relevant. This is a unicode code point, and // has nothing to do with other representations of the key. It is only relevant if this event // has nothing to do with other representations of the key. It is only relevant if this event // is the right type: COMMITTABLE or DEAD or TOGGLE, but for a mode key like hankaku/zenkaku or // is the right type: COMMITTABLE or DEAD or TOGGLE, but for a mode key like hankaku/zenkaku or // ctrl, there is no code point associated so this should be NOT_A_CODE_POINT to avoid // ctrl, there is no code point associated so this should be NOT_A_CODE_POINT to avoid // unintentional use of its value when it's not relevant. // unintentional use of its value when it's not relevant. private int mCodePoint; final public int mCodePoint; static Event obtainEvent() { // This method is private - to create a new event, use one of the create* utility methods. // TODO: create an event pool instead private Event(final int type, final int codePoint) { return new Event(); mType = type; mCodePoint = codePoint; } } public void setDeadEvent(final int codePoint) { public static Event createDeadEvent(final int codePoint) { mType = EVENT_DEAD; return new Event(EVENT_DEAD, codePoint); mCodePoint = codePoint; } } public void setCommittableEvent(final int codePoint) { public static Event createCommittableEvent(final int codePoint) { mType = EVENT_COMMITTABLE; return new Event(EVENT_COMMITTABLE, codePoint); mCodePoint = codePoint; } } public void setNotHandledEvent() { public static Event createNotHandledEvent() { mType = EVENT_NOT_HANDLED; return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT); mCodePoint = NOT_A_CODE_POINT; // Just in case } } public boolean isCommittable() { public boolean isCommittable() { return EVENT_COMMITTABLE == mType; return EVENT_COMMITTABLE == mType; } } public int getCodePoint() { return mCodePoint; } } } java/src/com/android/inputmethod/event/EventInterpreter.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -107,7 +107,7 @@ public class EventInterpreter { private boolean onEvent(final Event event) { private boolean onEvent(final Event event) { if (event.isCommittable()) { if (event.isCommittable()) { mLatinIme.onCodeInput(event.getCodePoint(), mLatinIme.onCodeInput(event.mCodePoint, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE); Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE); return true; return true; } } Loading java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java +4 −7 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,6 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { @Override @Override public Event decodeHardwareKey(final KeyEvent keyEvent) { public Event decodeHardwareKey(final KeyEvent keyEvent) { final Event event = Event.obtainEvent(); // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. Loading @@ -48,22 +47,20 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. final int keyCode = keyEvent.getKeyCode(); final int keyCode = keyEvent.getKeyCode(); if (KeyEvent.KEYCODE_DEL == keyCode) { if (KeyEvent.KEYCODE_DEL == keyCode) { event.setCommittableEvent(Constants.CODE_DELETE); return Event.createCommittableEvent(Constants.CODE_DELETE); return event; } } if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode || KeyEvent.KEYCODE_ENTER == keyCode) { || KeyEvent.KEYCODE_ENTER == keyCode) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { // A dead key. // A dead key. event.setDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK); return Event.createDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK); } else { } else { // A committable character. This should be committed right away, taking into // A committable character. This should be committed right away, taking into // account the current state. // account the current state. event.setCommittableEvent(codePointAndFlags); return Event.createCommittableEvent(codePointAndFlags); } } } else { } else { event.setNotHandledEvent(); return Event.createNotHandledEvent(); } } return event; } } } } Loading
java/src/com/android/inputmethod/event/Event.java +12 −18 Original line number Original line Diff line number Diff line Loading @@ -54,39 +54,33 @@ public class Event { final private static int NOT_A_CODE_POINT = 0; final private static int NOT_A_CODE_POINT = 0; private int mType; // The type of event - one of the constants above final private int mType; // The type of event - one of the constants above // The code point associated with the event, if relevant. This is a unicode code point, and // The code point associated with the event, if relevant. This is a unicode code point, and // has nothing to do with other representations of the key. It is only relevant if this event // has nothing to do with other representations of the key. It is only relevant if this event // is the right type: COMMITTABLE or DEAD or TOGGLE, but for a mode key like hankaku/zenkaku or // is the right type: COMMITTABLE or DEAD or TOGGLE, but for a mode key like hankaku/zenkaku or // ctrl, there is no code point associated so this should be NOT_A_CODE_POINT to avoid // ctrl, there is no code point associated so this should be NOT_A_CODE_POINT to avoid // unintentional use of its value when it's not relevant. // unintentional use of its value when it's not relevant. private int mCodePoint; final public int mCodePoint; static Event obtainEvent() { // This method is private - to create a new event, use one of the create* utility methods. // TODO: create an event pool instead private Event(final int type, final int codePoint) { return new Event(); mType = type; mCodePoint = codePoint; } } public void setDeadEvent(final int codePoint) { public static Event createDeadEvent(final int codePoint) { mType = EVENT_DEAD; return new Event(EVENT_DEAD, codePoint); mCodePoint = codePoint; } } public void setCommittableEvent(final int codePoint) { public static Event createCommittableEvent(final int codePoint) { mType = EVENT_COMMITTABLE; return new Event(EVENT_COMMITTABLE, codePoint); mCodePoint = codePoint; } } public void setNotHandledEvent() { public static Event createNotHandledEvent() { mType = EVENT_NOT_HANDLED; return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT); mCodePoint = NOT_A_CODE_POINT; // Just in case } } public boolean isCommittable() { public boolean isCommittable() { return EVENT_COMMITTABLE == mType; return EVENT_COMMITTABLE == mType; } } public int getCodePoint() { return mCodePoint; } } }
java/src/com/android/inputmethod/event/EventInterpreter.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -107,7 +107,7 @@ public class EventInterpreter { private boolean onEvent(final Event event) { private boolean onEvent(final Event event) { if (event.isCommittable()) { if (event.isCommittable()) { mLatinIme.onCodeInput(event.getCodePoint(), mLatinIme.onCodeInput(event.mCodePoint, Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE); Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE); return true; return true; } } Loading
java/src/com/android/inputmethod/event/HardwareKeyboardEventDecoder.java +4 −7 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,6 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { @Override @Override public Event decodeHardwareKey(final KeyEvent keyEvent) { public Event decodeHardwareKey(final KeyEvent keyEvent) { final Event event = Event.obtainEvent(); // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. Loading @@ -48,22 +47,20 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder { // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. final int keyCode = keyEvent.getKeyCode(); final int keyCode = keyEvent.getKeyCode(); if (KeyEvent.KEYCODE_DEL == keyCode) { if (KeyEvent.KEYCODE_DEL == keyCode) { event.setCommittableEvent(Constants.CODE_DELETE); return Event.createCommittableEvent(Constants.CODE_DELETE); return event; } } if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode || KeyEvent.KEYCODE_ENTER == keyCode) { || KeyEvent.KEYCODE_ENTER == keyCode) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { // A dead key. // A dead key. event.setDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK); return Event.createDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK); } else { } else { // A committable character. This should be committed right away, taking into // A committable character. This should be committed right away, taking into // account the current state. // account the current state. event.setCommittableEvent(codePointAndFlags); return Event.createCommittableEvent(codePointAndFlags); } } } else { } else { event.setNotHandledEvent(); return Event.createNotHandledEvent(); } } return event; } } } }