Start committing hardware events (B4)
Essentially this does activate auto-correction with a hardware keyboard, although a lot of things are still left to implement. No proximity is used yet which means only missing and excessive letters are considered. Dead keys are not handled. No combiner is supported. No suggestions are displayed. Resuming suggestions does not work correctly with a hardware key (because the view holds a temporary hardware event 'onKeyPreIme' and the event from the IME won't be handled until this is handled which won't happen until after the IME said that it did handle the event). Bug: 5037589 Change-Id: Idcb5c7b26d56717ed772d53c062362807f11cdaemain
parent
581f324ed8
commit
997cba7dec
|
@ -81,4 +81,12 @@ public class Event {
|
||||||
mType = EVENT_NOT_HANDLED;
|
mType = EVENT_NOT_HANDLED;
|
||||||
mCodePoint = NOT_A_CODE_POINT; // Just in case
|
mCodePoint = NOT_A_CODE_POINT; // Just in case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCommittable() {
|
||||||
|
return EVENT_COMMITTABLE == mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCodePoint() {
|
||||||
|
return mCodePoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ package com.android.inputmethod.event;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
import com.android.inputmethod.latin.LatinIME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the logic between receiving events and generating code points.
|
* This class implements the logic between receiving events and generating code points.
|
||||||
*
|
*
|
||||||
|
@ -36,6 +39,7 @@ public class EventInterpreter {
|
||||||
final EventDecoderSpec mDecoderSpec;
|
final EventDecoderSpec mDecoderSpec;
|
||||||
final SparseArray<HardwareEventDecoder> mHardwareEventDecoders;
|
final SparseArray<HardwareEventDecoder> mHardwareEventDecoders;
|
||||||
final SoftwareEventDecoder mSoftwareEventDecoder;
|
final SoftwareEventDecoder mSoftwareEventDecoder;
|
||||||
|
final LatinIME mLatinIme;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default interpreter.
|
* Create a default interpreter.
|
||||||
|
@ -43,9 +47,10 @@ public class EventInterpreter {
|
||||||
* This creates a default interpreter that does nothing. A default interpreter should normally
|
* This creates a default interpreter that does nothing. A default interpreter should normally
|
||||||
* only be used for fallback purposes, when we really don't know what we want to do with input.
|
* only be used for fallback purposes, when we really don't know what we want to do with input.
|
||||||
*
|
*
|
||||||
|
* @param latinIme a reference to the ime.
|
||||||
*/
|
*/
|
||||||
public EventInterpreter() {
|
public EventInterpreter(final LatinIME latinIme) {
|
||||||
this(null);
|
this(null, latinIme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,13 +66,15 @@ public class EventInterpreter {
|
||||||
* interpreter that does no specific combining, and assumes the most common cases.
|
* interpreter that does no specific combining, and assumes the most common cases.
|
||||||
*
|
*
|
||||||
* @param specification the specification for event interpretation. null for default.
|
* @param specification the specification for event interpretation. null for default.
|
||||||
|
* @param latinIme a reference to the ime.
|
||||||
*/
|
*/
|
||||||
public EventInterpreter(final EventDecoderSpec specification) {
|
public EventInterpreter(final EventDecoderSpec specification, final LatinIME latinIme) {
|
||||||
mDecoderSpec = null != specification ? specification : new EventDecoderSpec();
|
mDecoderSpec = null != specification ? specification : new EventDecoderSpec();
|
||||||
// For both, we expect to have only one decoder in almost all cases, hence the default
|
// For both, we expect to have only one decoder in almost all cases, hence the default
|
||||||
// capacity of 1.
|
// capacity of 1.
|
||||||
mHardwareEventDecoders = new SparseArray<HardwareEventDecoder>(1);
|
mHardwareEventDecoders = new SparseArray<HardwareEventDecoder>(1);
|
||||||
mSoftwareEventDecoder = new SoftwareKeyboardEventDecoder();
|
mSoftwareEventDecoder = new SoftwareKeyboardEventDecoder();
|
||||||
|
mLatinIme = latinIme;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to decode a hardware key event into a generic event, and execute any
|
// Helper method to decode a hardware key event into a generic event, and execute any
|
||||||
|
@ -99,6 +106,11 @@ public class EventInterpreter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onEvent(final Event event) {
|
private boolean onEvent(final Event event) {
|
||||||
|
if (event.isCommittable()) {
|
||||||
|
mLatinIme.onCodeInput(event.getCodePoint(),
|
||||||
|
Constants.EXTERNAL_KEYBOARD_COORDINATE, Constants.EXTERNAL_KEYBOARD_COORDINATE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// TODO: Classify the event - input or non-input (see design doc)
|
// TODO: Classify the event - input or non-input (see design doc)
|
||||||
// TODO: IF action event
|
// TODO: IF action event
|
||||||
// Send decoded action back to LatinIME
|
// Send decoded action back to LatinIME
|
||||||
|
|
|
@ -19,6 +19,8 @@ package com.android.inputmethod.event;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hardware event decoder for a hardware qwerty-ish keyboard.
|
* A hardware event decoder for a hardware qwerty-ish keyboard.
|
||||||
*
|
*
|
||||||
|
@ -41,7 +43,16 @@ public class HardwareKeyboardEventDecoder implements HardwareEventDecoder {
|
||||||
// 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.
|
||||||
final int codePointAndFlags = keyEvent.getUnicodeChar();
|
final int codePointAndFlags = keyEvent.getUnicodeChar();
|
||||||
if (keyEvent.isPrintingKey()) {
|
// The keyCode is the abstraction used by the KeyEvent to represent different keys that
|
||||||
|
// do not necessarily map to a unicode character. This represents a physical key, like
|
||||||
|
// the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
|
||||||
|
final int keyCode = keyEvent.getKeyCode();
|
||||||
|
if (KeyEvent.KEYCODE_DEL == keyCode) {
|
||||||
|
event.setCommittableEvent(Constants.CODE_DELETE);
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == 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);
|
event.setDeadEvent(codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK);
|
||||||
|
|
|
@ -139,6 +139,7 @@ public final class Constants {
|
||||||
public static final int NOT_A_COORDINATE = -1;
|
public static final int NOT_A_COORDINATE = -1;
|
||||||
public static final int SUGGESTION_STRIP_COORDINATE = -2;
|
public static final int SUGGESTION_STRIP_COORDINATE = -2;
|
||||||
public static final int SPELL_CHECKER_COORDINATE = -3;
|
public static final int SPELL_CHECKER_COORDINATE = -3;
|
||||||
|
public static final int EXTERNAL_KEYBOARD_COORDINATE = -4;
|
||||||
|
|
||||||
public static boolean isValidCoordinate(final int coordinate) {
|
public static boolean isValidCoordinate(final int coordinate) {
|
||||||
// Detect {@link NOT_A_COORDINATE}, {@link SUGGESTION_STRIP_COORDINATE},
|
// Detect {@link NOT_A_COORDINATE}, {@link SUGGESTION_STRIP_COORDINATE},
|
||||||
|
|
|
@ -145,7 +145,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
private final SubtypeState mSubtypeState = new SubtypeState();
|
private final SubtypeState mSubtypeState = new SubtypeState();
|
||||||
// At start, create a default event interpreter that does nothing by passing it no decoder spec.
|
// At start, create a default event interpreter that does nothing by passing it no decoder spec.
|
||||||
// The event interpreter should never be null.
|
// The event interpreter should never be null.
|
||||||
private EventInterpreter mEventInterpreter = new EventInterpreter();
|
private EventInterpreter mEventInterpreter = new EventInterpreter(this);
|
||||||
|
|
||||||
private boolean mIsMainDictionaryAvailable;
|
private boolean mIsMainDictionaryAvailable;
|
||||||
private UserBinaryDictionary mUserDictionary;
|
private UserBinaryDictionary mUserDictionary;
|
||||||
|
|
Loading…
Reference in New Issue