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

Change-Id: Ic0ed243f8c1fbf62793565ee37175270b47f0801
main
Tadashi G. Takaoka 2012-10-31 18:39:33 +09:00
parent 8b449c6dda
commit 3c6d3a4df8
1 changed files with 77 additions and 61 deletions

View File

@ -908,34 +908,22 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
setPressedKeyGraphics(key, eventTime);
}
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);
mTimerProxy.cancelKeyTimers();
startRepeatKey(key);
if (mIsAllowedSlidingKeyInput) {
private void processSlidingKeyInput(final Key newKey, final int x, final int y,
final long eventTime) {
// 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 {
// HACK: On some devices, quick successive touches may be reported as a sudden
// move by touch panel firmware. This hack detects such cases and translates the
// move event to successive up and down events.
// TODO: Should find a way to balance gesture detection and this hack.
if (sNeedsPhantomSuddenMoveEventHack
&& getDistance(x, y, lastX, lastY) >= mPhantonSuddenMoveThreshold) {
}
private void processPhantomSuddenMoveHack(final Key key, final int x, final int y,
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
if (DEBUG_MODE) {
Log.w(TAG, String.format("[%d] onMoveEvent:"
+ " phantom sudden move event (distance=%d) is translated to "
@ -951,12 +939,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
onUpEventInternal(eventTime);
onDownEventInternal(x, y, eventTime);
}
// HACK: On some devices, quick successive proximate touches may be reported as
// a bogus down-move-up event by touch panel firmware. This hack detects such
// cases and breaks these events into separate up and down events.
else if (sNeedsProximateBogusDownMoveUpEventHack
&& sTimeRecorder.isInFastTyping(eventTime)
&& mBogusMoveEventDetector.isCloseToActualDownEvent(x, y)) {
private void processProximateBogusDownMoveUpEventHack(final Key key, final int x, final int y,
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
if (DEBUG_MODE) {
final float keyDiagonal = (float)Math.hypot(
mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
@ -972,22 +957,52 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
onUpEventInternal(eventTime);
onDownEventInternal(x, y, eventTime);
}
private void slideFromOldKeyToNewKey(final Key key, 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.
setReleasedKeyGraphics(oldKey);
callListenerOnRelease(oldKey, oldKey.mCode, true);
startSlidingKeyInput(oldKey);
mTimerProxy.cancelKeyTimers();
startRepeatKey(key);
if (mIsAllowedSlidingKeyInput) {
processSlidingKeyInput(key, x, y, eventTime);
} else {
// HACK: If there are currently multiple touches, register the key even if
// the finger slides off the key. This defends against noise from some
// touch panels when there are close multiple touches.
// Caveat: When in chording input mode with a modifier key, we don't use
// this hack.
// HACK: On some devices, quick successive touches may be reported as a sudden move by
// touch panel firmware. This hack detects such cases and translates the move event to
// successive up and down events.
// TODO: Should find a way to balance gesture detection and this hack.
if (sNeedsPhantomSuddenMoveEventHack
&& getDistance(x, y, lastX, lastY) >= mPhantonSuddenMoveThreshold) {
processPhantomSuddenMoveHack(key, x, y, eventTime, oldKey, lastX, lastY);
}
// HACK: On some devices, quick successive proximate touches may be reported as a bogus
// down-move-up event by touch panel firmware. This hack detects such cases and breaks
// these events into separate up and down events.
else if (sNeedsProximateBogusDownMoveUpEventHack
&& sTimeRecorder.isInFastTyping(eventTime)
&& mBogusMoveEventDetector.isCloseToActualDownEvent(x, y)) {
processProximateBogusDownMoveUpEventHack(key, x, y, eventTime, oldKey, lastX, lastY);
}
else {
// HACK: If there are currently multiple touches, register the key even if the
// finger slides off the key. This defends against noise from some touch panels
// when there are close multiple touches.
// Caveat: When in chording input mode with a modifier key, we don't use this hack.
if (getActivePointerTrackerCount() > 1 && sPointerTrackerQueue != null
&& !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) {
if (DEBUG_MODE) {
Log.w(TAG, String.format("[%d] onMoveEvent:"
+ " detected sliding finger while multi touching",
mPointerId));
+ " detected sliding finger while multi touching", mPointerId));
}
onUpEvent(x, y, eventTime);
mKeyAlreadyProcessed = true;
}
setReleasedKeyGraphics(oldKey);
} else {
if (!mIsDetectingGesture) {
mKeyAlreadyProcessed = true;
}
@ -995,6 +1010,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
}
}
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
@ -1029,10 +1045,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
if (newKey != null) {
if (oldKey == null) {
slideInToNewKey(newKey, x, y, eventTime);
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
slideFromOldKeyToNewKey(newKey, x, y, eventTime, oldKey, lastX, lastY);
} else if (oldKey == null) {
slideInToNewKey(newKey, x, y, eventTime);
}
} else {
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {