diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ProximityKeyDetector.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ProximityKeyDetector.java | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java b/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java index 01122ebb7..35bdc6728 100644 --- a/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java +++ b/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java @@ -36,41 +36,34 @@ class ProximityKeyDetector extends KeyDetector { final Key[] keys = getKeys(); final int touchX = getTouchX(x); final int touchY = getTouchY(y); + int primaryIndex = BaseKeyboardView.NOT_A_KEY; - int closestKey = BaseKeyboardView.NOT_A_KEY; + int closestKeyIndex = BaseKeyboardView.NOT_A_KEY; int closestKeyDist = mProximityThresholdSquare + 1; - int[] distances = mDistances; + final int[] distances = mDistances; Arrays.fill(distances, Integer.MAX_VALUE); - int [] nearestKeyIndices = mKeyboard.getNearestKeys(touchX, touchY); - final int keyCount = nearestKeyIndices.length; - for (int i = 0; i < keyCount; i++) { - final Key key = keys[nearestKeyIndices[i]]; - int dist = 0; - boolean isInside = key.isInside(touchX, touchY); - if (isInside) { - primaryIndex = nearestKeyIndices[i]; - } - - if (((mProximityCorrectOn - && (dist = key.squaredDistanceFrom(touchX, touchY)) < mProximityThresholdSquare) - || isInside) - && key.codes[0] > 32) { - // Find insertion point - final int nCodes = key.codes.length; + for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) { + final Key key = keys[index]; + final boolean isInside = key.isInside(touchX, touchY); + if (isInside) + primaryIndex = index; + final int dist = key.squaredDistanceToEdge(touchX, touchY); + if (isInside || (mProximityCorrectOn && dist < mProximityThresholdSquare)) { if (dist < closestKeyDist) { closestKeyDist = dist; - closestKey = nearestKeyIndices[i]; + closestKeyIndex = index; } if (allKeys == null) continue; - + final int nCodes = key.codes.length; + // Find insertion point for (int j = 0; j < distances.length; j++) { if (distances[j] > dist) { // Make space for nCodes codes System.arraycopy(distances, j, distances, j + nCodes, - distances.length - j - nCodes); + distances.length - (j + nCodes)); System.arraycopy(allKeys, j, allKeys, j + nCodes, - allKeys.length - j - nCodes); + allKeys.length - (j + nCodes)); System.arraycopy(key.codes, 0, allKeys, j, nCodes); Arrays.fill(distances, j, j + nCodes, dist); break; @@ -78,9 +71,7 @@ class ProximityKeyDetector extends KeyDetector { } } } - if (primaryIndex == BaseKeyboardView.NOT_A_KEY) { - primaryIndex = closestKey; - } - return primaryIndex; + + return primaryIndex == BaseKeyboardView.NOT_A_KEY ? closestKeyIndex : primaryIndex; } } |