summaryrefslogtreecommitdiff
path: root/java/src/com/android/inputmethod/keyboard/KeyDetector.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-03-15 19:44:43 +0900
committerTadashi G. Takaoka <takaoka@google.com>2012-03-15 20:16:43 +0900
commit723aaa2eebcfea0d285f11fc265941057332664d (patch)
tree0add71436e2e852eecad067d4650916f52aa873a /java/src/com/android/inputmethod/keyboard/KeyDetector.java
parent2be7a37acfd498bfc83347597bfb8cb216a310eb (diff)
Remove touch dead zone
KeyDetector should use the distance from the hit box to detect the key. Bug: 6174250 Change-Id: Id1745d90222d1d1a10467f194b45307c12449944
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/KeyDetector.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java45
1 files changed, 30 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 3638eae8d..ea3f6236a 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -97,21 +97,21 @@ public class KeyDetector {
/**
* Computes maximum size of the array that can contain all nearby key codes returned by
- * {@link #getKeyAndNearbyCodes}.
+ * {@link #getNearbyCodes}.
*
* @return Returns maximum size of the array that can contain all nearby key codes returned
- * by {@link #getKeyAndNearbyCodes}.
+ * by {@link #getNearbyCodes}.
*/
protected int getMaxNearbyKeys() {
return MAX_NEARBY_KEYS;
}
/**
- * Allocates array that can hold all key codes returned by {@link #getKeyAndNearbyCodes}
+ * Allocates array that can hold all key codes returned by {@link #getNearbyCodes}
* method. The maximum size of the array should be computed by {@link #getMaxNearbyKeys}.
*
* @return Allocates and returns an array that can hold all key codes returned by
- * {@link #getKeyAndNearbyCodes} method. All elements in the returned array are
+ * {@link #getNearbyCodes} method. All elements in the returned array are
* initialized by {@link #NOT_A_CODE} value.
*/
public int[] newCodeArray() {
@@ -222,15 +222,15 @@ public class KeyDetector {
* @param x The x-coordinate of a touch point
* @param y The y-coordinate of a touch point
* @param allCodes All nearby key codes except functional key are returned in this array
- * @return The nearest key
*/
- public Key getKeyAndNearbyCodes(int x, int y, final int[] allCodes) {
+ // TODO: Move this method to native code.
+ public void getNearbyCodes(int x, int y, final int[] allCodes) {
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
initializeNearbyKeys();
Key primaryKey = null;
- for (final Key key: mKeyboard.getNearestKeys(touchX, touchY)) {
+ for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) {
final boolean isOnKey = key.isOnKey(touchX, touchY);
final int distance = key.squaredDistanceToEdge(touchX, touchY);
if (isOnKey || (mProximityCorrectOn && distance < mProximityThresholdSquare)) {
@@ -241,16 +241,31 @@ public class KeyDetector {
}
}
- if (allCodes != null && allCodes.length > 0) {
- getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes);
- if (DEBUG) {
- Log.d(TAG, "x=" + x + " y=" + y
- + " primary=" + printableCode(primaryKey)
- + " codes=" + printableCodes(allCodes));
- }
+ getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes);
+ if (DEBUG) {
+ Log.d(TAG, "x=" + x + " y=" + y
+ + " primary=" + printableCode(primaryKey)
+ + " codes=" + printableCodes(allCodes));
}
+ }
+
+ /**
+ * Detect the key whose hitbox the touch point is in.
+ *
+ * @param x The x-coordinate of a touch point
+ * @param y The y-coordinate of a touch point
+ * @return the key that the touch point hits.
+ */
+ public Key detectHitKey(int x, int y) {
+ final int touchX = getTouchX(x);
+ final int touchY = getTouchY(y);
- return primaryKey;
+ for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) {
+ if (key.isOnKey(touchX, touchY)) {
+ return key;
+ }
+ }
+ return null;
}
public static String printableCode(Key key) {