Clean up batch input related code a bit

Change-Id: I3b6a95fdb82bd15e2b636b1374a96d8987d5d8cf
main
Tadashi G. Takaoka 2013-12-20 17:20:52 +09:00
parent aa7a68a3e0
commit 904866c701
1 changed files with 60 additions and 54 deletions

View File

@ -576,40 +576,29 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return sPointerTrackerQueue.getOldestElement() == this; return sPointerTrackerQueue.getOldestElement() == this;
} }
private void mayStartBatchInput(final Key key) { /**
if (sInGesture || !mGestureStrokeWithPreviewPoints.isStartOfAGesture()) { * Determines whether the batch input has started or not.
return; * @return true if the batch input has started successfully.
} */
if (key == null || !Character.isLetter(key.getCode())) { private boolean mayStartBatchInput() {
return; if (!mGestureStrokeWithPreviewPoints.isStartOfAGesture()) {
return false;
} }
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onStartBatchInput", mPointerId)); Log.d(TAG, String.format("[%d] onStartBatchInput", mPointerId));
} }
sInGesture = true;
synchronized (sAggregatedPointers) { synchronized (sAggregatedPointers) {
sAggregatedPointers.reset(); sAggregatedPointers.reset();
sLastRecognitionPointSize = 0; sLastRecognitionPointSize = 0;
sLastRecognitionTime = 0; sLastRecognitionTime = 0;
sListener.onStartBatchInput(); sListener.onStartBatchInput();
dismissAllMoreKeysPanels(); dismissAllMoreKeysPanels();
}
sTimerProxy.cancelLongPressTimerOf(this); sTimerProxy.cancelLongPressTimerOf(this);
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen. }
sDrawingProxy.showGestureTrail( return true;
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
} }
public void updateBatchInputByTimer(final long eventTime) { private void showGestureTrail() {
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime);
updateBatchInput(eventTime);
}
private void mayUpdateBatchInput(final long eventTime, final Key key) {
if (key != null) {
updateBatchInput(eventTime);
}
if (mIsTrackingForActionDisabled) { if (mIsTrackingForActionDisabled) {
return; return;
} }
@ -618,13 +607,19 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */); this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
} }
private void updateBatchInput(final long eventTime) { public void updateBatchInputByTimer(final long syntheticMoveEventTime) {
final int gestureTime = (int)(syntheticMoveEventTime - sGestureFirstDownTime);
mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime);
updateBatchInput(syntheticMoveEventTime);
}
private void updateBatchInput(final long moveEventTime) {
synchronized (sAggregatedPointers) { synchronized (sAggregatedPointers) {
final GestureStroke stroke = mGestureStrokeWithPreviewPoints; final GestureStroke stroke = mGestureStrokeWithPreviewPoints;
stroke.appendIncrementalBatchPoints(sAggregatedPointers); stroke.appendIncrementalBatchPoints(sAggregatedPointers);
final int size = sAggregatedPointers.getPointerSize(); final int size = sAggregatedPointers.getPointerSize();
if (size > sLastRecognitionPointSize if (size > sLastRecognitionPointSize
&& stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) { && stroke.hasRecognitionTimePast(moveEventTime, sLastRecognitionTime)) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId, Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
size)); size));
@ -634,17 +629,23 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// The listener may change the size of the pointers (when auto-committing // The listener may change the size of the pointers (when auto-committing
// for example), so we need to get the size from the pointers again. // for example), so we need to get the size from the pointers again.
sLastRecognitionPointSize = sAggregatedPointers.getPointerSize(); sLastRecognitionPointSize = sAggregatedPointers.getPointerSize();
sLastRecognitionTime = eventTime; sLastRecognitionTime = moveEventTime;
} }
} }
} }
private void mayEndBatchInput(final long eventTime) { /**
* Determines whether the batch input has ended successfully or continues.
* @param upEventTime the event time of this pointer up.
* @return true if the batch input has ended successfully, false if it continues.
*/
private boolean mayEndBatchInput(final long upEventTime) {
boolean hasEndBatchInputSuccessfully = false;
synchronized (sAggregatedPointers) { synchronized (sAggregatedPointers) {
mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregatedPointers); mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregatedPointers);
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
sInGesture = false; hasEndBatchInputSuccessfully = true;
sTypingTimeRecorder.onEndBatchInput(eventTime); sTypingTimeRecorder.onEndBatchInput(upEventTime);
sTimerProxy.cancelAllUpdateBatchInputTimers(); sTimerProxy.cancelAllUpdateBatchInputTimers();
if (!mIsTrackingForActionDisabled) { if (!mIsTrackingForActionDisabled) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
@ -655,12 +656,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
} }
if (mIsTrackingForActionDisabled) { return hasEndBatchInputSuccessfully;
return;
}
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
sDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
} }
private void cancelBatchInput() { private void cancelBatchInput() {
@ -815,9 +811,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private void onGestureMoveEvent(final int x, final int y, final long eventTime, private void onGestureMoveEvent(final int x, final int y, final long eventTime,
final boolean isMajorEvent, final Key key) { final boolean isMajorEvent, final Key key) {
final int gestureTime = (int)(eventTime - sGestureFirstDownTime); if (!mIsDetectingGesture) {
if (mIsDetectingGesture) { return;
}
final int beforeLength = mGestureStrokeWithPreviewPoints.getLength(); final int beforeLength = mGestureStrokeWithPreviewPoints.getLength();
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard( final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard(
x, y, gestureTime, isMajorEvent); x, y, gestureTime, isMajorEvent);
if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) { if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) {
@ -833,10 +831,15 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return; return;
} }
mayStartBatchInput(key); if (!sInGesture && key != null && Character.isLetter(key.getCode())
if (sInGesture) { && mayStartBatchInput()) {
mayUpdateBatchInput(eventTime, key); sInGesture = true;
} }
if (sInGesture) {
if (key != null) {
updateBatchInput(eventTime);
}
showGestureTrail();
} }
} }
@ -1087,7 +1090,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (currentKey != null) { if (currentKey != null) {
callListenerOnRelease(currentKey, currentKey.getCode(), true /* withSliding */); callListenerOnRelease(currentKey, currentKey.getCode(), true /* withSliding */);
} }
mayEndBatchInput(eventTime); if (mayEndBatchInput(eventTime)) {
sInGesture = false;
}
showGestureTrail();
return; return;
} }