aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/ProximityKeyDetector.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2010-11-05 18:41:12 +0900
committerTadashi G. Takaoka <takaoka@google.com>2010-11-06 01:10:55 +0900
commit59b7bd07301196ac333dabafb5dd80750fcd2987 (patch)
treee8fe26f8e99a57a29c7124719a6146ef86b428f2 /java/src/com/android/inputmethod/latin/ProximityKeyDetector.java
parent68864723cf8d8e48385bfcaf30237fba25a8895a (diff)
downloadlatinime-59b7bd07301196ac333dabafb5dd80750fcd2987.tar.gz
latinime-59b7bd07301196ac333dabafb5dd80750fcd2987.tar.xz
latinime-59b7bd07301196ac333dabafb5dd80750fcd2987.zip
Using distance to the edge of key as proximity detection
Because there may be very long key, such as space bar on tablet, we should not use the distance between the touch point and the center of key as proximity detection. Instead of that, this change uses the distance between the point and the nearest edge of key as proximity detection. Also this change fixes the bug that space key (code 32) was not counted in proximity detection. Bug: 3164020 Bug: 3168138 Change-Id: I687f1ce94a8e944c3f6eea0fe00e18ed6e68e278
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ProximityKeyDetector.java')
-rw-r--r--java/src/com/android/inputmethod/latin/ProximityKeyDetector.java43
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;
}
}