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); onMoveEventInternal(x, y, eventTime);
} }
private void onMoveEventInternal(final int x, final int y, final long eventTime) { private void slideInToNewKey(final Key newKey, 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) {
// The pointer has been slid in to the new key, but the finger was not on any keys. // 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. // 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 // 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 // {@link #setKeyboard}. In those cases, we should update key according to the
// new keyboard layout. // new keyboard layout.
Key key = newKey;
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
key = onMoveKey(x, y); key = onMoveKey(x, y);
} }
onMoveToNewKey(key, x, y); onMoveToNewKey(key, x, y);
startLongPressTimer(key); startLongPressTimer(key);
setPressedKeyGraphics(key, eventTime); 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 // 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 // onRelease() first to notify that the previous key has been released, then call
// onPress() to notify that the new key is being pressed. // onPress() to notify that the new key is being pressed.
Key key = newKey;
setReleasedKeyGraphics(oldKey); setReleasedKeyGraphics(oldKey);
callListenerOnRelease(oldKey, oldKey.mCode, true); callListenerOnRelease(oldKey, oldKey.mCode, true);
startSlidingKeyInput(oldKey); 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 // The pointer has been slid out from the previous key, we must call onRelease() to
// notify that the previous key has been released. // notify that the previous key has been released.
setReleasedKeyGraphics(oldKey); setReleasedKeyGraphics(oldKey);
@ -1016,13 +1004,40 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
startSlidingKeyInput(oldKey); startSlidingKeyInput(oldKey);
mTimerProxy.cancelLongPressTimer(); mTimerProxy.cancelLongPressTimer();
if (mIsAllowedSlidingKeyInput) { if (mIsAllowedSlidingKeyInput) {
onMoveToNewKey(key, x, y); onMoveToNewKey(null, x, y);
} else { } else {
if (!mIsDetectingGesture) { if (!mIsDetectingGesture) {
mKeyAlreadyProcessed = true; 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);
}
} }
} }