From 2013bab89ca2f82589f99d98d9cf3b41ea5aac65 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 30 Nov 2011 17:54:58 +0900 Subject: [PATCH] Add Key.altCode attribute * Registering alternate code and while key is typing. * Showing press/release graphics of the key that has the above altenate code. * Showing press/release graphics of all shift keys. * Renaming Key.ignoreWhileTyping to Key.altCodeWhileTyping. Bug: 5639503 Change-Id: I67fb45bae76284a1f0deb6fd12ae5fb781d06cc3 --- java/res/values/attrs.xml | 4 +- java/res/xml-sw600dp/kbd_key_styles.xml | 6 +- java/res/xml-sw768dp/kbd_key_styles.xml | 6 +- java/res/xml/kbd_key_styles.xml | 6 +- .../com/android/inputmethod/keyboard/Key.java | 10 +- .../inputmethod/keyboard/Keyboard.java | 19 ++- .../inputmethod/keyboard/PointerTracker.java | 117 +++++++++++------- .../keyboard/internal/KeyStyles.java | 1 + 8 files changed, 110 insertions(+), 59 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index b11e25bc3..15e006593 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -185,6 +185,8 @@ + + @@ -201,7 +203,7 @@ - + diff --git a/java/res/xml-sw600dp/kbd_key_styles.xml b/java/res/xml-sw600dp/kbd_key_styles.xml index 5e9a88dd7..aba1a8029 100644 --- a/java/res/xml-sw600dp/kbd_key_styles.xml +++ b/java/res/xml-sw600dp/kbd_key_styles.xml @@ -77,13 +77,15 @@ latin:styleName="shortcutKeyStyle" latin:code="@integer/key_shortcut" latin:keyIcon="iconShortcutKey" - latin:keyActionFlags="noKeyPreview|ignoreWhileTyping" + latin:keyActionFlags="noKeyPreview|altCodeWhileTyping" + latin:altCode="@integer/key_space" latin:parentStyle="f2PopupStyle" /> mUnshiftedIcons; public final KeyboardIconsSet mIconsSet; + private final Map mKeyCache = new HashMap(); private final KeyboardShiftState mShiftState = new KeyboardShiftState(); private final ProximityInfo mProximityInfo; @@ -145,6 +146,22 @@ public class Keyboard { return mProximityInfo; } + public Key getKey(int code) { + final Integer keyCode = code; + if (mKeyCache.containsKey(keyCode)) { + return mKeyCache.get(keyCode); + } + + for (final Key key : mKeys) { + if (key.mCode == code) { + mKeyCache.put(keyCode, key); + return key; + } + } + mKeyCache.put(keyCode, null); + return null; + } + public boolean hasShiftLockKey() { return !mShiftLockKeys.isEmpty(); } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index da60af3be..4e8765dcc 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -258,23 +258,27 @@ public class PointerTracker { // primaryCode is different from {@link Key#mCode}. private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); - if (DEBUG_LISTENER) - Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode) + final boolean alterCode = key.altCodeWhileTyping() && mTimerProxy.isTyping(); + final int code = alterCode ? key.mAltCode : primaryCode; + // If code is CODE_DUMMY here, this key will be ignored or generate text. + final CharSequence text = (code != Keyboard.CODE_DUMMY) ? null : key.mOutputText; + if (DEBUG_LISTENER) { + Log.d(TAG, "onCodeInput: " + keyCodePrintable(code) + " text=" + text + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y - + " ignoreModifier=" + ignoreModifierKey); + + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode); + } if (ignoreModifierKey) { return; } if (key.isEnabled()) { - mListener.onCodeInput(primaryCode, keyCodes, x, y); - } - } - - private void callListenerOnTextInput(Key key) { - if (DEBUG_LISTENER) - Log.d(TAG, "onTextInput: text=" + key.mOutputText); - if (key.isEnabled()) { - mListener.onTextInput(key.mOutputText); + if (code != Keyboard.CODE_DUMMY) { + mListener.onCodeInput(code, keyCodes, x, y); + } else if (text != null) { + mListener.onTextInput(text); + } + if (!key.altCodeWhileTyping() && !key.isModifier()) { + mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); + } } } @@ -328,6 +332,23 @@ public class PointerTracker { if (key != null && key.isEnabled()) { key.onReleased(); mDrawingProxy.invalidateKey(key); + + if (key.isShift()) { + for (final Key shiftKey : mKeyboard.mShiftKeys) { + if (shiftKey != key) { + shiftKey.onReleased(); + mDrawingProxy.invalidateKey(shiftKey); + } + } + } + + if (key.altCodeWhileTyping()) { + final Key altKey = mKeyboard.getKey(key.mAltCode); + if (altKey != null) { + altKey.onReleased(); + mDrawingProxy.invalidateKey(altKey); + } + } } } @@ -338,6 +359,24 @@ public class PointerTracker { } key.onPressed(); mDrawingProxy.invalidateKey(key); + + if (key.isShift()) { + for (final Key shiftKey : mKeyboard.mShiftKeys) { + if (shiftKey != key) { + shiftKey.onPressed(); + mDrawingProxy.invalidateKey(shiftKey); + } + } + } + + if (key.altCodeWhileTyping() && mTimerProxy.isTyping()) { + final Key altKey = mKeyboard.getKey(key.mAltCode); + if (altKey != null) { + // TODO: Show altKey's preview. + altKey.onPressed(); + mDrawingProxy.invalidateKey(altKey); + } + } } } @@ -696,45 +735,27 @@ public class PointerTracker { callListenerOnCancelInput(); return; } - if (key.mOutputText != null) { - final boolean ignoreText = key.ignoreWhileTyping() && mTimerProxy.isTyping(); - if (!ignoreText) { - callListenerOnTextInput(key); - } - callListenerOnRelease(key, key.mCode, false); - if (!ignoreText) { - mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); - } - } else { - int code = key.mCode; - final int[] codes = mKeyDetector.newCodeArray(); - mKeyDetector.getKeyAndNearbyCodes(x, y, codes); - // If keyboard is in manual temporary upper case state and key has manual temporary - // uppercase letter as key hint letter, alternate character code should be sent. - if (mKeyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()) { - code = key.mHintLabel.charAt(0); - codes[0] = code; - } + int code = key.mCode; + final int[] codes = mKeyDetector.newCodeArray(); + mKeyDetector.getKeyAndNearbyCodes(x, y, codes); - // Swap the first and second values in the codes array if the primary code is not the - // first value but the second value in the array. This happens when key debouncing is - // in effect. - if (codes.length >= 2 && codes[0] != code && codes[1] == code) { - codes[1] = codes[0]; - codes[0] = code; - } - final boolean ignoreCode = key.ignoreWhileTyping() && mTimerProxy.isTyping(); - if (!ignoreCode) { - // TODO: It might be useful to register the nearest key code in codes[] instead of - // just ignoring. - callListenerOnCodeInput(key, code, codes, x, y); - } - callListenerOnRelease(key, code, false); - if (!key.ignoreWhileTyping() && !key.isModifier()) { - mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout); - } + // If keyboard is in manual temporary upper case state and key has manual temporary + // uppercase letter as key hint letter, alternate character code should be sent. + if (mKeyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()) { + code = key.mHintLabel.charAt(0); + codes[0] = code; } + + // Swap the first and second values in the codes array if the primary code is not the + // first value but the second value in the array. This happens when key debouncing is + // in effect. + if (codes.length >= 2 && codes[0] != code && codes[1] == code) { + codes[1] = codes[0]; + codes[0] = code; + } + callListenerOnCodeInput(key, code, codes, x, y); + callListenerOnRelease(key, code, false); } private long mPreviousEventTime; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 565edb901..218793500 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -152,6 +152,7 @@ public class KeyStyles { private void parseKeyStyleAttributes(TypedArray keyAttr) { // TODO: Currently not all Key attributes can be declared as style. readInt(keyAttr, R.styleable.Keyboard_Key_code); + readInt(keyAttr, R.styleable.Keyboard_Key_altCode); readText(keyAttr, R.styleable.Keyboard_Key_keyLabel); readText(keyAttr, R.styleable.Keyboard_Key_keyOutputText); readText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);