am 125ad223: Merge "Abandon the idea of an Event pool and make Event immutable (B1)"

* commit '125ad2237072745e4800b7a3907d5507024f35e5':
  Abandon the idea of an Event pool and make Event immutable (B1)
main
Jean Chalard 2013-01-09 05:11:26 -08:00 committed by Android Git Automerger
commit 02f580022d
3 changed files with 18 additions and 27 deletions

View File

@ -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;
}
public void setDeadEvent(final int codePoint) {
mType = EVENT_DEAD;
mCodePoint = codePoint; mCodePoint = codePoint;
} }
public void setCommittableEvent(final int codePoint) { public static Event createDeadEvent(final int codePoint) {
mType = EVENT_COMMITTABLE; return new Event(EVENT_DEAD, codePoint);
mCodePoint = codePoint;
} }
public void setNotHandledEvent() { public static Event createCommittableEvent(final int codePoint) {
mType = EVENT_NOT_HANDLED; return new Event(EVENT_COMMITTABLE, codePoint);
mCodePoint = NOT_A_CODE_POINT; // Just in case }
public static Event createNotHandledEvent() {
return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT);
} }
public boolean isCommittable() { public boolean isCommittable() {
return EVENT_COMMITTABLE == mType; return EVENT_COMMITTABLE == mType;
} }
public int getCodePoint() {
return mCodePoint;
}
} }

View File

@ -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;
} }

View File

@ -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.
@ -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;
} }
} }