Merge "Remove touch dead zone"
This commit is contained in:
commit
5bee1b00c8
4 changed files with 55 additions and 22 deletions
|
@ -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);
|
||||
|
||||
for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) {
|
||||
if (key.isOnKey(touchX, touchY)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return primaryKey;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String printableCode(Key key) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MoreKeysDetector extends KeyDetector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Key getKeyAndNearbyCodes(int x, int y, final int[] allCodes) {
|
||||
public void getNearbyCodes(int x, int y, final int[] allCodes) {
|
||||
final int touchX = getTouchX(x);
|
||||
final int touchY = getTouchY(y);
|
||||
|
||||
|
@ -53,8 +53,26 @@ public class MoreKeysDetector extends KeyDetector {
|
|||
}
|
||||
}
|
||||
|
||||
if (allCodes != null && nearestKey != null) {
|
||||
if (nearestKey != null) {
|
||||
allCodes[0] = nearestKey.mCode;
|
||||
} else {
|
||||
allCodes[0] = NOT_A_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key detectHitKey(int x, int y) {
|
||||
final int touchX = getTouchX(x);
|
||||
final int touchY = getTouchY(y);
|
||||
|
||||
Key nearestKey = null;
|
||||
int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
|
||||
for (final Key key : getKeyboard().mKeys) {
|
||||
final int dist = key.squaredDistanceToEdge(touchX, touchY);
|
||||
if (dist < nearestDist) {
|
||||
nearestKey = key;
|
||||
nearestDist = dist;
|
||||
}
|
||||
}
|
||||
return nearestKey;
|
||||
}
|
||||
|
|
|
@ -318,7 +318,7 @@ public class PointerTracker {
|
|||
}
|
||||
|
||||
public Key getKeyOn(int x, int y) {
|
||||
return mKeyDetector.getKeyAndNearbyCodes(x, y, null);
|
||||
return mKeyDetector.detectHitKey(x, y);
|
||||
}
|
||||
|
||||
private void setReleasedKeyGraphics(Key key) {
|
||||
|
@ -421,7 +421,7 @@ public class PointerTracker {
|
|||
private Key onMoveKeyInternal(int x, int y) {
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
return mKeyDetector.getKeyAndNearbyCodes(x, y, null);
|
||||
return mKeyDetector.detectHitKey(x, y);
|
||||
}
|
||||
|
||||
private Key onMoveKey(int x, int y) {
|
||||
|
@ -748,7 +748,7 @@ public class PointerTracker {
|
|||
private long mPreviousEventTime;
|
||||
|
||||
private void printTouchEvent(String title, int x, int y, long eventTime) {
|
||||
final Key key = mKeyDetector.getKeyAndNearbyCodes(x, y, null);
|
||||
final Key key = mKeyDetector.detectHitKey(x, y);
|
||||
final String code = KeyDetector.printableCode(key);
|
||||
final long delta = eventTime - mPreviousEventTime;
|
||||
Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title,
|
||||
|
|
|
@ -141,7 +141,7 @@ public class WordComposer {
|
|||
keyY = y;
|
||||
} else {
|
||||
codes = keyDetector.newCodeArray();
|
||||
keyDetector.getKeyAndNearbyCodes(x, y, codes);
|
||||
keyDetector.getNearbyCodes(x, y, codes);
|
||||
keyX = keyDetector.getTouchX(x);
|
||||
keyY = keyDetector.getTouchY(y);
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ public class WordComposer {
|
|||
final int x = key.mX + key.mWidth / 2;
|
||||
final int y = key.mY + key.mHeight / 2;
|
||||
final int[] codes = keyDetector.newCodeArray();
|
||||
keyDetector.getKeyAndNearbyCodes(x, y, codes);
|
||||
keyDetector.getNearbyCodes(x, y, codes);
|
||||
add(codePoint, codes, x, y);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue