Merge "Separate nested if-blocks into helper methods (refactor step 1)"

main
Tadashi G. Takaoka 2012-10-31 03:18:08 -07:00 committed by Android (Google) Code Review
commit dd43dd61eb
1 changed files with 127 additions and 112 deletions

View File

@ -893,39 +893,27 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
onMoveEventInternal(x, y, eventTime);
}
private void onMoveEventInternal(final int x, final int y, final long eventTime) {
final int lastX = mLastX;
final int lastY = mLastY;
final Key oldKey = mCurrentKey;
Key key = onMoveKey(x, y);
if (sShouldHandleGesture) {
// Register move event on gesture tracker.
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, key);
if (sInGesture) {
mCurrentKey = null;
setReleasedKeyGraphics(oldKey);
return;
}
}
if (key != null) {
if (oldKey == null) {
private void slideInToNewKey(final Key newKey, final int x, final int y, final long eventTime) {
// The pointer has been slid in to the new key, but the finger was not on any keys.
// In this case, we must call onPress() to notify that the new key is being pressed.
// This onPress call may have changed keyboard layout. Those cases are detected at
// {@link #setKeyboard}. In those cases, we should update key according to the
// new keyboard layout.
Key key = newKey;
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
key = onMoveKey(x, y);
}
onMoveToNewKey(key, x, y);
startLongPressTimer(key);
setPressedKeyGraphics(key, eventTime);
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, key)) {
}
private void slideFromOldKeyToNewKey(final Key newKey, final int x, final int y,
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
// The pointer has been slid in to the new key from the previous key, we must call
// onRelease() first to notify that the previous key has been released, then call
// onPress() to notify that the new key is being pressed.
Key key = newKey;
setReleasedKeyGraphics(oldKey);
callListenerOnRelease(oldKey, oldKey.mCode, true);
startSlidingKeyInput(oldKey);
@ -1007,8 +995,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
}
} else {
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, key)) {
private void slideOutFromOldKey(final Key oldKey, final int x, final int y) {
// The pointer has been slid out from the previous key, we must call onRelease() to
// notify that the previous key has been released.
setReleasedKeyGraphics(oldKey);
@ -1016,13 +1004,40 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
startSlidingKeyInput(oldKey);
mTimerProxy.cancelLongPressTimer();
if (mIsAllowedSlidingKeyInput) {
onMoveToNewKey(key, x, y);
onMoveToNewKey(null, x, y);
} else {
if (!mIsDetectingGesture) {
mKeyAlreadyProcessed = true;
}
}
}
private void onMoveEventInternal(final int x, final int y, final long eventTime) {
final int lastX = mLastX;
final int lastY = mLastY;
final Key oldKey = mCurrentKey;
final Key newKey = onMoveKey(x, y);
if (sShouldHandleGesture) {
// Register move event on gesture tracker.
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
if (sInGesture) {
mCurrentKey = null;
setReleasedKeyGraphics(oldKey);
return;
}
}
if (newKey != null) {
if (oldKey == null) {
slideInToNewKey(newKey, x, y, eventTime);
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
slideFromOldKeyToNewKey(newKey, x, y, eventTime, oldKey, lastX, lastY);
}
} else {
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
slideOutFromOldKey(oldKey, x, y);
}
}
}