From 1caff47ecdfcf413df709371a919cf9377e26bf7 Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 14 Mar 2012 23:17:12 +0900 Subject: Calculate proximity characters in the native code Bug: 4343280 Change-Id: I6adaf560f7a4f1f96dcb6ec2f61f20ee3001167e --- .../src/com/android/inputmethod/keyboard/KeyDetector.java | 15 +++++++++++---- java/src/com/android/inputmethod/latin/WordComposer.java | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'java/src') 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) { diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index a9609310c..251063ec4 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -140,8 +140,8 @@ public class WordComposer { keyX = x; keyY = y; } else { - codes = keyDetector.newCodeArray(); - keyDetector.getNearbyCodes(x, y, codes); + final Key key = keyDetector.detectHitKey(x, y); + codes = new int[] { key != null ? key.mCode : NOT_A_CODE }; keyX = keyDetector.getTouchX(x); keyY = keyDetector.getTouchY(y); } -- cgit v1.2.3-83-g751a