am 3a7ed5fd: Merge "Fix IllegalStateException raied by monkey"

* commit '3a7ed5fdfe5e2ceaabe80532a75380e2c6c1e012':
  Fix IllegalStateException raied by monkey
main
Tadashi G. Takaoka 2014-02-19 00:30:19 -08:00 committed by Android Git Automerger
commit a58431003c
4 changed files with 36 additions and 33 deletions

View File

@ -16,8 +16,6 @@
package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.Constants;
/**
* This class handles key detection.
*/
@ -41,13 +39,15 @@ public class KeyDetector {
* @param keyHysteresisDistanceForSlidingModifier the same parameter for sliding input that
* 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);
mKeyHysteresisDistanceForSlidingModifierSquared = (int)(
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) {
throw new NullPointerException();
}
@ -56,24 +56,21 @@ public class KeyDetector {
mKeyboard = keyboard;
}
public int getKeyHysteresisDistanceSquared(boolean isSlidingFromModifier) {
public int getKeyHysteresisDistanceSquared(final boolean isSlidingFromModifier) {
return isSlidingFromModifier
? mKeyHysteresisDistanceForSlidingModifierSquared : mKeyHysteresisDistanceSquared;
}
public int getTouchX(int x) {
public int getTouchX(final int x) {
return x + mCorrectionX;
}
// TODO: Remove vertical correction.
public int getTouchY(int y) {
public int getTouchY(final int y) {
return y + mCorrectionY;
}
public Keyboard getKeyboard() {
if (mKeyboard == null) {
throw new IllegalStateException("keyboard isn't set");
}
return mKeyboard;
}
@ -88,7 +85,7 @@ public class KeyDetector {
* @param y The y-coordinate of a touch point
* @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 touchY = getTouchY(y);
@ -113,20 +110,4 @@ public class KeyDetector {
}
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 + "]";
}
}

View File

@ -33,13 +33,17 @@ public final class MoreKeysDetector extends KeyDetector {
}
@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 touchY = getTouchY(y);
Key nearestKey = null;
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);
if (dist < nearestDist) {
nearestKey = key;

View File

@ -257,12 +257,15 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
}
public static void setKeyDetector(final KeyDetector keyDetector) {
final Keyboard keyboard = keyDetector.getKeyboard();
if (keyboard == null) {
return;
}
final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.setKeyDetectorInner(keyDetector);
}
final Keyboard keyboard = keyDetector.getKeyboard();
sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
}
@ -301,7 +304,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
KeyDetector.printableCode(key),
(key == null ? "none" : Constants.printableCode(key.getCode())),
ignoreModifierKey ? " ignoreModifier" : "",
key.isEnabled() ? "" : " disabled",
repeatCount > 0 ? " repeatCount=" + repeatCount : ""));
@ -402,11 +405,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
private void setKeyDetectorInner(final KeyDetector keyDetector) {
final Keyboard keyboard = keyDetector.getKeyboard();
if (keyboard == null) {
return;
}
if (keyDetector == mKeyDetector && keyboard == mKeyboard) {
return;
}
mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard();
mKeyboard = keyboard;
// Mark that keyboard layout has been changed.
mKeyboardLayoutHasBeenChanged = true;
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,
final long eventTime) {
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,
(mIsTrackingForActionDisabled ? "-" : " "), title, x, y, eventTime, code));
}

View File

@ -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;
/**