From 976a42b873215a669fe22709960aa1259292d75c Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 17 Jan 2013 19:27:39 +0900 Subject: [PATCH] Track handled events to consistently return handled status (C1) Bug: 5037589 Change-Id: I92d5be669420f0b2fdeb8fcf85aefd3961bf84b4 --- .../src/com/android/inputmethod/latin/LatinIME.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 4f8852b87..95295300a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -82,6 +82,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Locale; +import java.util.TreeSet; /** * Input method implementation for Qwerty'ish keyboard. @@ -167,6 +168,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private int mDeleteCount; private long mLastKeyTime; private int mActionId; + private TreeSet mCurrentlyPressedHardwareKeys = CollectionUtils.newTreeSet(); // Member variables for remembering the current device orientation. private int mDisplayOrientation; @@ -721,6 +723,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction resetComposingState(true /* alsoResetLastComposedWord */); mDeleteCount = 0; mSpaceState = SPACE_STATE_NONE; + mCurrentlyPressedHardwareKeys.clear(); if (mSuggestionStripView != null) { // This will set the punctuation suggestions if next word suggestion is off; @@ -2420,12 +2423,20 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // 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 (mEventInterpreter.onHardwareKeyEvent(event)) return true; + if (mEventInterpreter.onHardwareKeyEvent(event)) { + final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); + mCurrentlyPressedHardwareKeys.add(keyIdentifier); + return true; + } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(final int keyCode, final KeyEvent event) { + final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode(); + if (mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) { + return true; + } return super.onKeyUp(keyCode, event); }