aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/KeyDetector.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/KeyDetector.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java15
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) {