diff options
| author | satok <satok@google.com> | 2012-03-14 23:17:12 +0900 |
|---|---|---|
| committer | satok <satok@google.com> | 2012-03-16 17:26:36 +0900 |
| commit | 1caff47ecdfcf413df709371a919cf9377e26bf7 (patch) | |
| tree | 666f5889c0b4ad267dfa292f07cf9fb0622273ad /java/src/com/android/inputmethod/keyboard/KeyDetector.java | |
| parent | 9945f364061dc0b297da0e13a7e864ac6890bb4c (diff) | |
Calculate proximity characters in the native code
Bug: 4343280
Change-Id: I6adaf560f7a4f1f96dcb6ec2f61f20ee3001167e
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/KeyDetector.java')
| -rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyDetector.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index ea3f6236a..d342c6df0 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -260,12 +260,19 @@ public class KeyDetector { final int touchX = getTouchX(x); final int touchY = getTouchY(y); - for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) { - if (key.isOnKey(touchX, touchY)) { - return key; + int minDistance = Integer.MAX_VALUE; + Key primaryKey = null; + for (final Key key: mKeyboard.getNearestKeys(touchX, touchY)) { + final boolean isOnKey = key.isOnKey(touchX, touchY); + final int distance = key.squaredDistanceToEdge(touchX, touchY); + // TODO: need to take care of hitbox overlaps + if (primaryKey == null || distance < minDistance + || (distance == minDistance && isOnKey)) { + minDistance = distance; + primaryKey = key; } } - return null; + return primaryKey; } public static String printableCode(Key key) { |
