am 3a7ed5fd
: Merge "Fix IllegalStateException raied by monkey"
* commit '3a7ed5fdfe5e2ceaabe80532a75380e2c6c1e012': Fix IllegalStateException raied by monkey
This commit is contained in:
commit
a58431003c
4 changed files with 36 additions and 33 deletions
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handles key detection.
|
* This class handles key detection.
|
||||||
*/
|
*/
|
||||||
|
@ -41,13 +39,15 @@ public class KeyDetector {
|
||||||
* @param keyHysteresisDistanceForSlidingModifier the same parameter for sliding input that
|
* @param keyHysteresisDistanceForSlidingModifier the same parameter for sliding input that
|
||||||
* starts from a modifier key such as shift and symbols key.
|
* starts from a modifier key such as shift and symbols key.
|
||||||
*/
|
*/
|
||||||
public KeyDetector(float keyHysteresisDistance, float keyHysteresisDistanceForSlidingModifier) {
|
public KeyDetector(final float keyHysteresisDistance,
|
||||||
|
final float keyHysteresisDistanceForSlidingModifier) {
|
||||||
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
||||||
mKeyHysteresisDistanceForSlidingModifierSquared = (int)(
|
mKeyHysteresisDistanceForSlidingModifierSquared = (int)(
|
||||||
keyHysteresisDistanceForSlidingModifier * keyHysteresisDistanceForSlidingModifier);
|
keyHysteresisDistanceForSlidingModifier * keyHysteresisDistanceForSlidingModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyboard(Keyboard keyboard, float correctionX, float correctionY) {
|
public void setKeyboard(final Keyboard keyboard, final float correctionX,
|
||||||
|
final float correctionY) {
|
||||||
if (keyboard == null) {
|
if (keyboard == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
@ -56,24 +56,21 @@ public class KeyDetector {
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getKeyHysteresisDistanceSquared(boolean isSlidingFromModifier) {
|
public int getKeyHysteresisDistanceSquared(final boolean isSlidingFromModifier) {
|
||||||
return isSlidingFromModifier
|
return isSlidingFromModifier
|
||||||
? mKeyHysteresisDistanceForSlidingModifierSquared : mKeyHysteresisDistanceSquared;
|
? mKeyHysteresisDistanceForSlidingModifierSquared : mKeyHysteresisDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTouchX(int x) {
|
public int getTouchX(final int x) {
|
||||||
return x + mCorrectionX;
|
return x + mCorrectionX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove vertical correction.
|
// TODO: Remove vertical correction.
|
||||||
public int getTouchY(int y) {
|
public int getTouchY(final int y) {
|
||||||
return y + mCorrectionY;
|
return y + mCorrectionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Keyboard getKeyboard() {
|
public Keyboard getKeyboard() {
|
||||||
if (mKeyboard == null) {
|
|
||||||
throw new IllegalStateException("keyboard isn't set");
|
|
||||||
}
|
|
||||||
return mKeyboard;
|
return mKeyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +85,7 @@ public class KeyDetector {
|
||||||
* @param y The y-coordinate of a touch point
|
* @param y The y-coordinate of a touch point
|
||||||
* @return the key that the touch point hits.
|
* @return the key that the touch point hits.
|
||||||
*/
|
*/
|
||||||
public Key detectHitKey(int x, int y) {
|
public Key detectHitKey(final int x, final int y) {
|
||||||
final int touchX = getTouchX(x);
|
final int touchX = getTouchX(x);
|
||||||
final int touchY = getTouchY(y);
|
final int touchY = getTouchY(y);
|
||||||
|
|
||||||
|
@ -113,20 +110,4 @@ public class KeyDetector {
|
||||||
}
|
}
|
||||||
return primaryKey;
|
return primaryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String printableCode(Key key) {
|
|
||||||
return key != null ? Constants.printableCode(key.getCode()) : "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String printableCodes(int[] codes) {
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
boolean addDelimiter = false;
|
|
||||||
for (final int code : codes) {
|
|
||||||
if (code == Constants.NOT_A_CODE) break;
|
|
||||||
if (addDelimiter) sb.append(", ");
|
|
||||||
sb.append(Constants.printableCode(code));
|
|
||||||
addDelimiter = true;
|
|
||||||
}
|
|
||||||
return "[" + sb + "]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,13 +33,17 @@ public final class MoreKeysDetector extends KeyDetector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Key detectHitKey(int x, int y) {
|
public Key detectHitKey(final int x, final int y) {
|
||||||
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
if (keyboard == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final int touchX = getTouchX(x);
|
final int touchX = getTouchX(x);
|
||||||
final int touchY = getTouchY(y);
|
final int touchY = getTouchY(y);
|
||||||
|
|
||||||
Key nearestKey = null;
|
Key nearestKey = null;
|
||||||
int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
|
int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
|
||||||
for (final Key key : getKeyboard().getKeys()) {
|
for (final Key key : keyboard.getKeys()) {
|
||||||
final int dist = key.squaredDistanceToEdge(touchX, touchY);
|
final int dist = key.squaredDistanceToEdge(touchX, touchY);
|
||||||
if (dist < nearestDist) {
|
if (dist < nearestDist) {
|
||||||
nearestKey = key;
|
nearestKey = key;
|
||||||
|
|
|
@ -257,12 +257,15 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setKeyDetector(final KeyDetector keyDetector) {
|
public static void setKeyDetector(final KeyDetector keyDetector) {
|
||||||
|
final Keyboard keyboard = keyDetector.getKeyboard();
|
||||||
|
if (keyboard == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final int trackersSize = sTrackers.size();
|
final int trackersSize = sTrackers.size();
|
||||||
for (int i = 0; i < trackersSize; ++i) {
|
for (int i = 0; i < trackersSize; ++i) {
|
||||||
final PointerTracker tracker = sTrackers.get(i);
|
final PointerTracker tracker = sTrackers.get(i);
|
||||||
tracker.setKeyDetectorInner(keyDetector);
|
tracker.setKeyDetectorInner(keyDetector);
|
||||||
}
|
}
|
||||||
final Keyboard keyboard = keyDetector.getKeyboard();
|
|
||||||
sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
|
sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +304,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
|
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
|
||||||
if (DEBUG_LISTENER) {
|
if (DEBUG_LISTENER) {
|
||||||
Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
|
Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
|
||||||
KeyDetector.printableCode(key),
|
(key == null ? "none" : Constants.printableCode(key.getCode())),
|
||||||
ignoreModifierKey ? " ignoreModifier" : "",
|
ignoreModifierKey ? " ignoreModifier" : "",
|
||||||
key.isEnabled() ? "" : " disabled",
|
key.isEnabled() ? "" : " disabled",
|
||||||
repeatCount > 0 ? " repeatCount=" + repeatCount : ""));
|
repeatCount > 0 ? " repeatCount=" + repeatCount : ""));
|
||||||
|
@ -402,11 +405,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
|
|
||||||
private void setKeyDetectorInner(final KeyDetector keyDetector) {
|
private void setKeyDetectorInner(final KeyDetector keyDetector) {
|
||||||
final Keyboard keyboard = keyDetector.getKeyboard();
|
final Keyboard keyboard = keyDetector.getKeyboard();
|
||||||
|
if (keyboard == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (keyDetector == mKeyDetector && keyboard == mKeyboard) {
|
if (keyDetector == mKeyDetector && keyboard == mKeyboard) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mKeyDetector = keyDetector;
|
mKeyDetector = keyDetector;
|
||||||
mKeyboard = keyDetector.getKeyboard();
|
mKeyboard = keyboard;
|
||||||
// Mark that keyboard layout has been changed.
|
// Mark that keyboard layout has been changed.
|
||||||
mKeyboardLayoutHasBeenChanged = true;
|
mKeyboardLayoutHasBeenChanged = true;
|
||||||
final int keyWidth = mKeyboard.mMostCommonKeyWidth;
|
final int keyWidth = mKeyboard.mMostCommonKeyWidth;
|
||||||
|
@ -1235,7 +1241,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
private void printTouchEvent(final String title, final int x, final int y,
|
private void printTouchEvent(final String title, final int x, final int y,
|
||||||
final long eventTime) {
|
final long eventTime) {
|
||||||
final Key key = mKeyDetector.detectHitKey(x, y);
|
final Key key = mKeyDetector.detectHitKey(x, y);
|
||||||
final String code = KeyDetector.printableCode(key);
|
final String code = (key == null ? "none" : Constants.printableCode(key.getCode()));
|
||||||
Log.d(TAG, String.format("[%d]%s%s %4d %4d %5d %s", mPointerId,
|
Log.d(TAG, String.format("[%d]%s%s %4d %4d %5d %s", mPointerId,
|
||||||
(mIsTrackingForActionDisabled ? "-" : " "), title, x, y, eventTime, code));
|
(mIsTrackingForActionDisabled ? "-" : " "), title, x, y, eventTime, code));
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,6 +252,18 @@ public final class Constants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String printableCodes(final int[] codes) {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
boolean addDelimiter = false;
|
||||||
|
for (final int code : codes) {
|
||||||
|
if (code == NOT_A_CODE) break;
|
||||||
|
if (addDelimiter) sb.append(", ");
|
||||||
|
sb.append(printableCode(code));
|
||||||
|
addDelimiter = true;
|
||||||
|
}
|
||||||
|
return "[" + sb + "]";
|
||||||
|
}
|
||||||
|
|
||||||
public static final int MAX_INT_BIT_COUNT = 32;
|
public static final int MAX_INT_BIT_COUNT = 32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue