diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
9 files changed, 87 insertions, 104 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index be38d9e6d..5816e5680 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -434,9 +434,10 @@ public class Keyboard { case CODE_SHORTCUT: return "shortcut"; case CODE_UNSPECIFIED: return "unspec"; default: - if (code < 0) Log.w(TAG, "Unknow negative key code=" + code); - if (code < 0x100) return String.format("\\u%02x", code); - return String.format("\\u04x", code); + if (code <= 0) Log.w(TAG, "Unknown non-positive key code=" + code); + if (code < CODE_SPACE) return String.format("'\\u%02x'", code); + if (code < 0x100) return String.format("'%c'", code); + return String.format("'\\u%04x'", code); } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java index 6f5420882..dce2c37f2 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java @@ -24,10 +24,8 @@ public interface KeyboardActionListener { * * @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key, * the value will be zero. - * @param withSliding true if pressing has occurred because the user slid finger from other key - * to this key without releasing the finger. */ - public void onPress(int primaryCode, boolean withSliding); + public void onPressKey(int primaryCode); /** * Called when the user releases a key. This is sent after the {@link #onCodeInput} is called. @@ -37,7 +35,7 @@ public interface KeyboardActionListener { * @param withSliding true if releasing has occurred because the user slid finger from the key * to other key without releasing the finger. */ - public void onRelease(int primaryCode, boolean withSliding); + public void onReleaseKey(int primaryCode, boolean withSliding); /** * Send a key code to the listener. @@ -79,9 +77,9 @@ public interface KeyboardActionListener { public static class Adapter implements KeyboardActionListener { @Override - public void onPress(int primaryCode, boolean withSliding) {} + public void onPressKey(int primaryCode) {} @Override - public void onRelease(int primaryCode, boolean withSliding) {} + public void onReleaseKey(int primaryCode, boolean withSliding) {} @Override public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {} @Override diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 9efd65e91..fa87535b4 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -270,24 +270,12 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mState.onUpdateShiftState(mInputMethodService.getCurrentAutoCapsState()); } - public void onPressShift(boolean withSliding) { - mState.onPressShift(withSliding); + public void onPressKey(int code) { + mState.onPressKey(code); } - public void onReleaseShift(boolean withSliding) { - mState.onReleaseShift(withSliding); - } - - public void onPressSymbol() { - mState.onPressSymbol(); - } - - public void onReleaseSymbol() { - mState.onReleaseSymbol(); - } - - public void onOtherKeyPressed() { - mState.onOtherKeyPressed(); + public void onReleaseKey(int code, boolean withSliding) { + mState.onReleaseKey(code, withSliding); } public void onCancelInput() { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 8aa7f883b..aa0f9751d 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -417,9 +417,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // the second tap is treated as this double tap event, so that we need not mark tracker // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. if (ignore) { - mKeyboardActionListener.onCustomRequest(LatinIME.CODE_HAPTIC_AND_AUDIO_FEEDBACK); + invokeCustomRequest(LatinIME.CODE_HAPTIC_AND_AUDIO_FEEDBACK); } else { - mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); + invokeCodeInput(Keyboard.CODE_CAPSLOCK); } } @@ -479,17 +479,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } private boolean invokeCustomRequest(int code) { - return getKeyboardActionListener().onCustomRequest(code); + return mKeyboardActionListener.onCustomRequest(code); } private void invokeCodeInput(int primaryCode) { - getKeyboardActionListener().onCodeInput(primaryCode, null, + mKeyboardActionListener.onCodeInput(primaryCode, null, KeyboardActionListener.NOT_A_TOUCH_COORDINATE, KeyboardActionListener.NOT_A_TOUCH_COORDINATE); } private void invokeReleaseKey(int primaryCode) { - getKeyboardActionListener().onRelease(primaryCode, false); + mKeyboardActionListener.onReleaseKey(primaryCode, false); } private boolean openMoreKeysPanel(Key parentKey, PointerTracker tracker) { @@ -514,7 +514,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke : parentKey.mX + parentKey.mWidth / 2; final int pointY = parentKey.mY - keyboard.mVerticalGap; moreKeysPanel.showMoreKeysPanel( - this, this, pointX, pointY, mMoreKeysWindow, getKeyboardActionListener()); + this, this, pointX, pointY, mMoreKeysWindow, mKeyboardActionListener); final int translatedX = moreKeysPanel.translateX(tracker.getLastX()); final int translatedY = moreKeysPanel.translateY(tracker.getLastY()); tracker.onShowMoreKeysPanel(translatedX, translatedY, moreKeysPanel); diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java index 8e9929681..1f9ed5e91 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardView.java @@ -61,12 +61,13 @@ public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel { } @Override - public void onPress(int primaryCode, boolean withSliding) { - mListener.onPress(primaryCode, withSliding); + public void onPressKey(int primaryCode) { + mListener.onPressKey(primaryCode); } + @Override - public void onRelease(int primaryCode, boolean withSliding) { - mListener.onRelease(primaryCode, withSliding); + public void onReleaseKey(int primaryCode, boolean withSliding) { + mListener.onReleaseKey(primaryCode, withSliding); } }; diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 2183e8ed6..274bd0b31 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -237,18 +237,18 @@ public class PointerTracker { } // Returns true if keyboard has been changed by this callback. - private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) { + private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key) { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); if (DEBUG_LISTENER) { Log.d(TAG, "onPress : " + KeyDetector.printableCode(key) - + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey + + " ignoreModifier=" + ignoreModifierKey + " enabled=" + key.isEnabled()); } if (ignoreModifierKey) { return false; } if (key.isEnabled()) { - mListener.onPress(key.mCode, withSliding); + mListener.onPressKey(key.mCode); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; mKeyboardLayoutHasBeenChanged = false; return keyboardLayoutHasBeenChanged; @@ -296,7 +296,7 @@ public class PointerTracker { return; } if (key.isEnabled()) { - mListener.onRelease(primaryCode, withSliding); + mListener.onReleaseKey(primaryCode, withSliding); } } @@ -495,7 +495,7 @@ public class PointerTracker { // This onPress call may have changed keyboard layout. Those cases are detected at // {@link #setKeyboard}. In those cases, we should update key according to the new // keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false)) { + if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { key = onDownKey(x, y, eventTime); } @@ -529,7 +529,7 @@ public class PointerTracker { // This onPress call may have changed keyboard layout. Those cases are detected at // {@link #setKeyboard}. In those cases, we should update key according to the // new keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(key, true)) { + if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { key = onMoveKey(x, y); } onMoveToNewKey(key, x, y); @@ -548,7 +548,7 @@ public class PointerTracker { // This onPress call may have changed keyboard layout. Those cases are detected // at {@link #setKeyboard}. In those cases, we should update key according // to the new keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(key, true)) { + if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { key = onMoveKey(x, y); } onMoveToNewKey(key, x, y); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index a8e0bd595..fbce937c6 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -21,15 +21,13 @@ import android.util.Log; import com.android.inputmethod.keyboard.Keyboard; -// TODO: Add unit tests /** * Keyboard state machine. * * This class contains all keyboard state transition logic. * * The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()}, - * {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()}, - * {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()}, + * {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)}, * {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)}, * {@link #onUpdateShiftState(boolean)}, and {@link #onToggleCapsLock()}. * @@ -37,7 +35,8 @@ import com.android.inputmethod.keyboard.Keyboard; */ public class KeyboardState { private static final String TAG = KeyboardState.class.getSimpleName(); - private static final boolean DEBUG_STATE = false; + private static final boolean DEBUG_EVENT = false; + private static final boolean DEBUG_ACTION = false; public interface SwitchActions { public void setAlphabetKeyboard(); @@ -97,7 +96,7 @@ public class KeyboardState { } public void onLoadKeyboard(String layoutSwitchBackSymbols, boolean hasDistinctMultitouch) { - if (DEBUG_STATE) { + if (DEBUG_EVENT) { Log.d(TAG, "onLoadKeyboard"); } mLayoutSwitchBackSymbols = layoutSwitchBackSymbols; @@ -122,7 +121,7 @@ public class KeyboardState { state.mIsShifted = mIsSymbolShifted; } state.mIsValid = true; - if (DEBUG_STATE) { + if (DEBUG_EVENT) { Log.d(TAG, "onSaveKeyboardState: alphabet=" + state.mIsAlphabetMode + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted); } @@ -130,7 +129,7 @@ public class KeyboardState { private void onRestoreKeyboardState() { final SavedKeyboardState state = mSavedKeyboardState; - if (DEBUG_STATE) { + if (DEBUG_EVENT) { Log.d(TAG, "onRestoreKeyboardState: valid=" + state.mIsValid + " alphabet=" + state.mIsAlphabetMode + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted); @@ -162,7 +161,7 @@ public class KeyboardState { } private void setShifted(int shiftMode) { - if (DEBUG_STATE) { + if (DEBUG_ACTION) { Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode)); } if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) { @@ -182,7 +181,7 @@ public class KeyboardState { } private void setShiftLocked(boolean shiftLocked) { - if (DEBUG_STATE) { + if (DEBUG_ACTION) { Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked); } mKeyboardShiftState.setShiftLocked(shiftLocked); @@ -206,7 +205,7 @@ public class KeyboardState { } private void setAlphabetKeyboard() { - if (DEBUG_STATE) { + if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetKeyboard"); } mSwitchActions.setAlphabetKeyboard(); @@ -220,7 +219,7 @@ public class KeyboardState { // TODO: Make this method private public void setSymbolsKeyboard() { - if (DEBUG_STATE) { + if (DEBUG_ACTION) { Log.d(TAG, "setSymbolsKeyboard"); } mPrevMainKeyboardWasShiftLocked = mKeyboardShiftState.isShiftLocked(); @@ -231,7 +230,7 @@ public class KeyboardState { } private void setSymbolsShiftedKeyboard() { - if (DEBUG_STATE) { + if (DEBUG_ACTION) { Log.d(TAG, "setSymbolsShiftedKeyboard"); } mSwitchActions.setSymbolsShiftedKeyboard(); @@ -240,19 +239,40 @@ public class KeyboardState { mSwitchState = SWITCH_STATE_SYMBOL_BEGIN; } - public void onPressSymbol() { - if (DEBUG_STATE) { - Log.d(TAG, "onPressSymbol: " + this); + public void onPressKey(int code) { + if (DEBUG_EVENT) { + Log.d(TAG, "onPressKey: code=" + Keyboard.printableCode(code) + " " + this); } + if (code == Keyboard.CODE_SHIFT) { + onPressShift(); + } else if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { + onPressSymbol(); + } else { + mShiftKeyState.onOtherKeyPressed(); + mSymbolKeyState.onOtherKeyPressed(); + } + } + + public void onReleaseKey(int code, boolean withSliding) { + if (DEBUG_EVENT) { + Log.d(TAG, "onReleaseKey: code=" + Keyboard.printableCode(code) + + " sliding=" + withSliding + " " + this); + } + if (code == Keyboard.CODE_SHIFT) { + onReleaseShift(withSliding); + } else if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { + // TODO: Make use of withSliding instead of relying on mSwitchState. + onReleaseSymbol(); + } + } + + private void onPressSymbol() { toggleAlphabetAndSymbols(); mSymbolKeyState.onPress(); mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL; } - public void onReleaseSymbol() { - if (DEBUG_STATE) { - Log.d(TAG, "onReleaseSymbol: " + this); - } + private void onReleaseSymbol() { // Snap back to the previous keyboard mode if the user chords the mode change key and // another key, then releases the mode change key. if (mSwitchState == SWITCH_STATE_CHORDING_ALPHA) { @@ -261,16 +281,8 @@ public class KeyboardState { mSymbolKeyState.onRelease(); } - public void onOtherKeyPressed() { - if (DEBUG_STATE) { - Log.d(TAG, "onOtherKeyPressed: " + this); - } - mShiftKeyState.onOtherKeyPressed(); - mSymbolKeyState.onOtherKeyPressed(); - } - public void onUpdateShiftState(boolean autoCaps) { - if (DEBUG_STATE) { + if (DEBUG_EVENT) { Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this); } onUpdateShiftStateInternal(autoCaps); @@ -294,10 +306,7 @@ public class KeyboardState { } } - public void onPressShift(boolean withSliding) { - if (DEBUG_STATE) { - Log.d(TAG, "onPressShift: sliding=" + withSliding + " " + this); - } + private void onPressShift() { if (mIsAlphabetMode) { if (mKeyboardShiftState.isShiftLocked()) { // Shift key is pressed while caps lock state, we will treat this state as shifted @@ -326,10 +335,7 @@ public class KeyboardState { } } - public void onReleaseShift(boolean withSliding) { - if (DEBUG_STATE) { - Log.d(TAG, "onReleaseShift: sliding=" + withSliding + " " + this); - } + private void onReleaseShift(boolean withSliding) { if (mIsAlphabetMode) { final boolean isShiftLocked = mKeyboardShiftState.isShiftLocked(); if (mShiftKeyState.isMomentary()) { @@ -363,8 +369,8 @@ public class KeyboardState { } public void onCancelInput(boolean isSinglePointer) { - if (DEBUG_STATE) { - Log.d(TAG, "onCancelInput: isSinglePointer=" + isSinglePointer + " " + this); + if (DEBUG_EVENT) { + Log.d(TAG, "onCancelInput: single=" + isSinglePointer + " " + this); } // Snap back to the previous keyboard mode if the user cancels sliding input. if (isSinglePointer) { @@ -392,8 +398,9 @@ public class KeyboardState { } public void onCodeInput(int code, boolean isSinglePointer, boolean autoCaps) { - if (DEBUG_STATE) { - Log.d(TAG, "onCodeInput: code=" + code + " isSinglePointer=" + isSinglePointer + if (DEBUG_EVENT) { + Log.d(TAG, "onCodeInput: code=" + Keyboard.printableCode(code) + + " single=" + isSinglePointer + " autoCaps=" + autoCaps + " " + this); } switch (mSwitchState) { @@ -465,7 +472,7 @@ public class KeyboardState { } public void onToggleCapsLock() { - if (DEBUG_STATE) { + if (DEBUG_EVENT) { Log.d(TAG, "onToggleCapsLock: " + this); } if (mIsAlphabetMode) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b0d0da43b..ee3b2d2e4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1239,7 +1239,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } mLastKeyTime = when; final KeyboardSwitcher switcher = mKeyboardSwitcher; - final boolean distinctMultiTouch = switcher.hasDistinctMultitouch(); // The space state depends only on the last character pressed and its own previous // state. Here, we revert the space state to neutral if the key is actually modifying // the input contents (any non-shift key), which is what we should do for @@ -1262,7 +1261,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar break; case Keyboard.CODE_SHIFT: case Keyboard.CODE_SWITCH_ALPHA_SYMBOL: - // Shift and symbol key is handled in onPress() and onRelease(). + // Shift and symbol key is handled in onPressKey() and onReleaseKey(). break; case Keyboard.CODE_SETTINGS: onSettingsKeyPressed(); @@ -2258,28 +2257,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } @Override - public void onPress(int primaryCode, boolean withSliding) { + public void onPressKey(int primaryCode) { final KeyboardSwitcher switcher = mKeyboardSwitcher; if (switcher.isVibrateAndSoundFeedbackRequired()) { hapticAndAudioFeedback(primaryCode); } - if (primaryCode == Keyboard.CODE_SHIFT) { - switcher.onPressShift(withSliding); - } else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { - switcher.onPressSymbol(); - } else { - switcher.onOtherKeyPressed(); - } + switcher.onPressKey(primaryCode); } @Override - public void onRelease(int primaryCode, boolean withSliding) { - KeyboardSwitcher switcher = mKeyboardSwitcher; - if (primaryCode == Keyboard.CODE_SHIFT) { - switcher.onReleaseShift(withSliding); - } else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { - switcher.onReleaseSymbol(); - } + public void onReleaseKey(int primaryCode, boolean withSliding) { + mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index b5f67ace0..600f14e04 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -56,13 +56,13 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { private final KeyboardActionListener mSuggestionsPaneListener = new KeyboardActionListener.Adapter() { @Override - public void onPress(int primaryCode, boolean withSliding) { - mListener.onPress(primaryCode, withSliding); + public void onPressKey(int primaryCode) { + mListener.onPressKey(primaryCode); } @Override - public void onRelease(int primaryCode, boolean withSliding) { - mListener.onRelease(primaryCode, withSliding); + public void onReleaseKey(int primaryCode, boolean withSliding) { + mListener.onReleaseKey(primaryCode, withSliding); } @Override |