diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 41 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 12 |
2 files changed, 38 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 222e73529..4a18c2b3c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -45,6 +45,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.PrintWriterPrinter; import android.util.Printer; +import android.util.SparseArray; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; @@ -60,6 +61,8 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.dictionarypack.DictionaryPackConstants; import com.android.inputmethod.event.Event; +import com.android.inputmethod.event.HardwareEventDecoder; +import com.android.inputmethod.event.HardwareKeyboardEventDecoder; import com.android.inputmethod.event.InputTransaction; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; @@ -120,6 +123,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private final Settings mSettings; private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */, this /* SuggestionStripViewAccessor */); + // We expect to have only one decoder in almost all cases, hence the default capacity of 1. + // If it turns out we need several, it will get grown seamlessly. + final SparseArray<HardwareEventDecoder> mHardwareEventDecoders + = new SparseArray<HardwareEventDecoder>(1); private View mExtractArea; private View mKeyPreviewBackingView; @@ -643,9 +650,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().initDictionary(newSuggest.mDictionaryFacilitator); } - final Suggest oldSuggest = mInputLogic.mSuggest; - mInputLogic.mSuggest = newSuggest; - if (oldSuggest != null) oldSuggest.close(); + mInputLogic.replaceSuggest(newSuggest); refreshPersonalizationDictionarySession(); } @@ -1588,19 +1593,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } + private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) { + final HardwareEventDecoder decoder = mHardwareEventDecoders.get(deviceId); + if (null != decoder) return decoder; + // TODO: create the decoder according to the specification + final HardwareEventDecoder newDecoder = new HardwareKeyboardEventDecoder(deviceId); + mHardwareEventDecoders.put(deviceId, newDecoder); + return newDecoder; + } + // Hooks for hardware keyboard @Override - public boolean onKeyDown(final int keyCode, final KeyEvent event) { - if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) return super.onKeyDown(keyCode, event); - // onHardwareKeyEvent, like onKeyDown returns true if it handled the event, false if - // it doesn't know what to do with it and leave it to the application. For example, - // hardware key events for adjusting the screen's brightness are passed as is. - if (mInputLogic.mEventInterpreter.onHardwareKeyEvent(event)) { - final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); - mInputLogic.mCurrentlyPressedHardwareKeys.add(keyIdentifier); + public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) { + if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) { + return super.onKeyDown(keyCode, keyEvent); + } + final Event event = getHardwareKeyEventDecoder( + keyEvent.getDeviceId()).decodeHardwareKey(keyEvent); + // If the event is not handled by LatinIME, we just pass it to the parent implementation. + // If it's handled, we return true because we did handle it. + if (event.isHandled()) { + mInputLogic.onCodeInput(mSettings.getCurrent(), event, + mKeyboardSwitcher.getKeyboardShiftMode(), mHandler); return true; } - return super.onKeyDown(keyCode, event); + return super.onKeyDown(keyCode, keyEvent); } @Override diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index cb55aa06c..fa7c4b4fc 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -80,8 +80,6 @@ public final class InputLogic { public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; // TODO: mSuggest should be touched by a single thread. public volatile Suggest mSuggest; - // The event interpreter should never be null. - public final EventInterpreter mEventInterpreter; public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; public final WordComposer mWordComposer; @@ -104,11 +102,19 @@ public final class InputLogic { mLatinIME = latinIME; mSuggestionStripViewAccessor = suggestionStripViewAccessor; mWordComposer = new WordComposer(); - mEventInterpreter = new EventInterpreter(latinIME); mConnection = new RichInputConnection(latinIME); mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } + // Replace the old Suggest with the passed Suggest and close it. + public void replaceSuggest(final Suggest newSuggest) { + final Suggest oldSuggest = mSuggest; + mSuggest = newSuggest; + if (oldSuggest != null) { + oldSuggest.close(); + } + } + /** * Initializes the input logic for input in an editor. * |