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