diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 13e909c7e..9abc79d3c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -53,6 +53,7 @@ public class KeyDetector { return x + mCorrectionX; } + // TODO: Remove vertical correction. public int getTouchY(int y) { return y + mCorrectionY; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java index 275aacf36..c41d24529 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java @@ -52,6 +52,7 @@ public interface KeyboardActionListener { */ public void onCodeInput(int primaryCode, int x, int y); + // See {@link Adapter#isInvalidCoordinate(int)}. public static final int NOT_A_TOUCH_COORDINATE = -1; public static final int SUGGESTION_STRIP_COORDINATE = -2; public static final int SPELL_CHECKER_COORDINATE = -3; @@ -89,5 +90,13 @@ public interface KeyboardActionListener { public boolean onCustomRequest(int requestCode) { return false; } + + // TODO: Remove this method when the vertical correction is removed. + public static boolean isInvalidCoordinate(int coordinate) { + // Detect {@link KeyboardActionListener#NOT_A_TOUCH_COORDINATE}, + // {@link KeyboardActionListener#SUGGESTION_STRIP_COORDINATE}, and + // {@link KeyboardActionListener#SPELL_CHECKER_COORDINATE}. + return coordinate < 0; + } } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d4362f79e..722f323a2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -63,6 +63,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.SuggestionSpanUtils; +import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; @@ -1505,8 +1506,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen clearSuggestions(); } if (isComposingWord) { - mWordComposer.add( - primaryCode, x, y, mKeyboardSwitcher.getKeyboardView().getKeyDetector()); + final int keyX, keyY; + if (KeyboardActionListener.Adapter.isInvalidCoordinate(x) + || KeyboardActionListener.Adapter.isInvalidCoordinate(y)) { + keyX = x; + keyY = y; + } else { + final KeyDetector keyDetector = + mKeyboardSwitcher.getKeyboardView().getKeyDetector(); + keyX = keyDetector.getTouchX(x); + keyY = keyDetector.getTouchY(y); + } + mWordComposer.add(primaryCode, keyX, keyY); // If it's the first letter, make note of auto-caps state if (mWordComposer.size() == 1) { mWordComposer.setAutoCapitalized( diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 98282f970..f23dc520a 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardActionListener; import java.util.Arrays; @@ -121,28 +120,10 @@ public class WordComposer { return previous && !Character.isUpperCase(codePoint); } - // TODO: remove input keyDetector - public void add(int primaryCode, int x, int y, KeyDetector keyDetector) { - final int keyX; - final int keyY; - if (null == keyDetector - || x == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE - || y == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE - || x == KeyboardActionListener.NOT_A_TOUCH_COORDINATE - || y == KeyboardActionListener.NOT_A_TOUCH_COORDINATE) { - keyX = x; - keyY = y; - } else { - keyX = keyDetector.getTouchX(x); - keyY = keyDetector.getTouchY(y); - } - add(primaryCode, keyX, keyY); - } - /** * Add a new keystroke, with the pressed key's code point with the touch point coordinates. */ - private void add(int primaryCode, int keyX, int keyY) { + public void add(int primaryCode, int keyX, int keyY) { final int newIndex = size(); mTypedWord.appendCodePoint(primaryCode); refreshSize(); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 5f4d66091..5332c066a 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -768,9 +768,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService codePoint, mScript); if (SpellCheckerProximityInfo.NOT_A_COORDINATE_PAIR == xy) { composer.add(codePoint, WordComposer.NOT_A_COORDINATE, - WordComposer.NOT_A_COORDINATE, null); + WordComposer.NOT_A_COORDINATE); } else { - composer.add(codePoint, xy & 0xFFFF, xy >> 16, null); + composer.add(codePoint, xy & 0xFFFF, xy >> 16); } }