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

Change-Id: I87ef8b174295fb12a91fec35acd3b0cc152ad8f0
This commit is contained in:
Tadashi G. Takaoka 2012-10-31 18:31:48 +09:00
parent 33aa6e3cf0
commit 8b449c6dda

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);
}
}
}