Merge "Separate GestureStrokeDrawingPoints from GestureStrokeRecognitionPoints"

This commit is contained in:
Tadashi G. Takaoka 2013-12-25 06:58:08 +00:00 committed by Android (Google) Code Review
commit d99d225f10
3 changed files with 37 additions and 39 deletions

View file

@ -203,6 +203,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// true if dragging finger is allowed. // true if dragging finger is allowed.
private boolean mIsAllowedDraggingFinger; private boolean mIsAllowedDraggingFinger;
private final GestureStrokeRecognitionPoints mGestureStrokeRecognitionPoints;
private final GestureStrokeDrawingPoints mGestureStrokeDrawingPoints; private final GestureStrokeDrawingPoints mGestureStrokeDrawingPoints;
// TODO: Add PointerTrackerFactory singleton and move some class static methods into it. // TODO: Add PointerTrackerFactory singleton and move some class static methods into it.
@ -286,8 +287,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private PointerTracker(final int id) { private PointerTracker(final int id) {
mPointerId = id; mPointerId = id;
mGestureStrokeDrawingPoints = new GestureStrokeDrawingPoints( mGestureStrokeRecognitionPoints = new GestureStrokeRecognitionPoints(
id, sGestureStrokeRecognitionParams, sGestureStrokeDrawingParams); id, sGestureStrokeRecognitionParams);
mGestureStrokeDrawingPoints = new GestureStrokeDrawingPoints(sGestureStrokeDrawingParams);
} }
// Returns true if keyboard has been changed by this callback. // Returns true if keyboard has been changed by this callback.
@ -408,7 +410,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mKeyboardLayoutHasBeenChanged = true; mKeyboardLayoutHasBeenChanged = true;
final int keyWidth = mKeyboard.mMostCommonKeyWidth; final int keyWidth = mKeyboard.mMostCommonKeyWidth;
final int keyHeight = mKeyboard.mMostCommonKeyHeight; final int keyHeight = mKeyboard.mMostCommonKeyHeight;
mGestureStrokeDrawingPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight); mGestureStrokeRecognitionPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY); final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
if (newKey != mCurrentKey) { if (newKey != mCurrentKey) {
if (sDrawingProxy != null) { if (sDrawingProxy != null) {
@ -581,7 +583,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
* @return true if the batch input has started successfully. * @return true if the batch input has started successfully.
*/ */
private boolean mayStartBatchInput() { private boolean mayStartBatchInput() {
if (!mGestureStrokeDrawingPoints.isStartOfAGesture()) { if (!mGestureStrokeRecognitionPoints.isStartOfAGesture()) {
return false; return false;
} }
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
@ -609,13 +611,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public void updateBatchInputByTimer(final long syntheticMoveEventTime) { public void updateBatchInputByTimer(final long syntheticMoveEventTime) {
final int gestureTime = (int)(syntheticMoveEventTime - sGestureFirstDownTime); final int gestureTime = (int)(syntheticMoveEventTime - sGestureFirstDownTime);
mGestureStrokeDrawingPoints.duplicateLastPointWith(gestureTime); mGestureStrokeRecognitionPoints.duplicateLastPointWith(gestureTime);
updateBatchInput(syntheticMoveEventTime); updateBatchInput(syntheticMoveEventTime);
} }
private void updateBatchInput(final long moveEventTime) { private void updateBatchInput(final long moveEventTime) {
synchronized (sAggregatedPointers) { synchronized (sAggregatedPointers) {
final GestureStrokeRecognitionPoints stroke = mGestureStrokeDrawingPoints; final GestureStrokeRecognitionPoints stroke = mGestureStrokeRecognitionPoints;
stroke.appendIncrementalBatchPoints(sAggregatedPointers); stroke.appendIncrementalBatchPoints(sAggregatedPointers);
final int size = sAggregatedPointers.getPointerSize(); final int size = sAggregatedPointers.getPointerSize();
if (size > sLastRecognitionPointSize if (size > sLastRecognitionPointSize
@ -642,7 +644,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private boolean mayEndBatchInput(final long upEventTime) { private boolean mayEndBatchInput(final long upEventTime) {
boolean hasEndBatchInputSuccessfully = false; boolean hasEndBatchInputSuccessfully = false;
synchronized (sAggregatedPointers) { synchronized (sAggregatedPointers) {
mGestureStrokeDrawingPoints.appendAllBatchPoints(sAggregatedPointers); mGestureStrokeRecognitionPoints.appendAllBatchPoints(sAggregatedPointers);
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
hasEndBatchInputSuccessfully = true; hasEndBatchInputSuccessfully = true;
sTypingTimeRecorder.onEndBatchInput(upEventTime); sTypingTimeRecorder.onEndBatchInput(upEventTime);
@ -754,8 +756,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
sGestureFirstDownTime = eventTime; sGestureFirstDownTime = eventTime;
} }
mGestureStrokeDrawingPoints.onDownEvent(x, y, eventTime, sGestureFirstDownTime, final int elapsedTimeSinceFirstDown = (int)(eventTime - sGestureFirstDownTime);
sTypingTimeRecorder.getLastLetterTypingTime()); final int elapsedTimeSinceLastTyping = (int)(
eventTime - sTypingTimeRecorder.getLastLetterTypingTime());
mGestureStrokeRecognitionPoints.onDownEvent(x, y, elapsedTimeSinceFirstDown,
elapsedTimeSinceLastTyping);
mGestureStrokeDrawingPoints.onDownEvent(x, y, elapsedTimeSinceFirstDown);
} }
} }
@ -814,11 +820,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (!mIsDetectingGesture) { if (!mIsDetectingGesture) {
return; return;
} }
final int beforeLength = mGestureStrokeDrawingPoints.getLength(); final int beforeLength = mGestureStrokeRecognitionPoints.getLength();
final int gestureTime = (int)(eventTime - sGestureFirstDownTime); final int elapsedTimeSinceFirstDown = (int)(eventTime - sGestureFirstDownTime);
final boolean onValidArea = mGestureStrokeDrawingPoints.addPointOnKeyboard( final boolean onValidArea = mGestureStrokeRecognitionPoints.addPointOnKeyboard(
x, y, gestureTime, isMajorEvent); x, y, elapsedTimeSinceFirstDown, isMajorEvent);
if (mGestureStrokeDrawingPoints.getLength() > beforeLength) { if (mGestureStrokeRecognitionPoints.getLength() > beforeLength) {
sTimerProxy.startUpdateBatchInputTimer(this); sTimerProxy.startUpdateBatchInputTimer(this);
} }
// If the move event goes out from valid batch input area, cancel batch input. // If the move event goes out from valid batch input area, cancel batch input.
@ -826,6 +832,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
cancelBatchInput(); cancelBatchInput();
return; return;
} }
mGestureStrokeDrawingPoints.onMoveEvent(x, y, elapsedTimeSinceFirstDown);
// If the MoreKeysPanel is showing then do not attempt to enter gesture mode. However, // If the MoreKeysPanel is showing then do not attempt to enter gesture mode. However,
// the gestured touch points are still being recorded in case the panel is dismissed. // the gestured touch points are still being recorded in case the panel is dismissed.
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {

View file

@ -20,11 +20,8 @@ import com.android.inputmethod.latin.utils.ResizableIntArray;
/** /**
* This class holds drawing points to represent a gesture stroke on the screen. * This class holds drawing points to represent a gesture stroke on the screen.
* TODO: Currently this class extends {@link GestureStrokeRecognitionPoints} that holds recognition
* points of a gesture stroke. This class should be independent from
* {@link GestureStrokeRecognitionPoints}.
*/ */
public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPoints { public final class GestureStrokeDrawingPoints {
public static final int PREVIEW_CAPACITY = 256; public static final int PREVIEW_CAPACITY = 256;
private final ResizableIntArray mPreviewEventTimes = new ResizableIntArray(PREVIEW_CAPACITY); private final ResizableIntArray mPreviewEventTimes = new ResizableIntArray(PREVIEW_CAPACITY);
@ -42,16 +39,11 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
private int mLastY; private int mLastY;
private double mDistanceFromLastSample; private double mDistanceFromLastSample;
public GestureStrokeDrawingPoints(final int pointerId, public GestureStrokeDrawingPoints(final GestureStrokeDrawingParams drawingParams) {
final GestureStrokeRecognitionParams recognitionParams,
final GestureStrokeDrawingParams drawingParams) {
super(pointerId, recognitionParams);
mDrawingParams = drawingParams; mDrawingParams = drawingParams;
} }
@Override private void reset() {
protected void reset() {
super.reset();
mStrokeId++; mStrokeId++;
mLastPreviewSize = 0; mLastPreviewSize = 0;
mLastInterpolatedPreviewIndex = 0; mLastInterpolatedPreviewIndex = 0;
@ -64,6 +56,11 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
return mStrokeId; return mStrokeId;
} }
public void onDownEvent(final int x, final int y, final int elapsedTimeSinceFirstDown) {
reset();
onMoveEvent(x, y, elapsedTimeSinceFirstDown);
}
private boolean needsSampling(final int x, final int y) { private boolean needsSampling(final int x, final int y) {
mDistanceFromLastSample += Math.hypot(x - mLastX, y - mLastY); mDistanceFromLastSample += Math.hypot(x - mLastX, y - mLastY);
mLastX = x; mLastX = x;
@ -76,16 +73,12 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
return false; return false;
} }
@Override public void onMoveEvent(final int x, final int y, final int elapsedTimeSinceFirstDown) {
public boolean addPointOnKeyboard(final int x, final int y, final int time,
final boolean isMajorEvent) {
if (needsSampling(x, y)) { if (needsSampling(x, y)) {
mPreviewEventTimes.add(time); mPreviewEventTimes.add(elapsedTimeSinceFirstDown);
mPreviewXCoordinates.add(x); mPreviewXCoordinates.add(x);
mPreviewYCoordinates.add(y); mPreviewYCoordinates.add(y);
} }
return super.addPointOnKeyboard(x, y, time, isMajorEvent);
} }
/** /**

View file

@ -103,19 +103,17 @@ public class GestureStrokeRecognitionPoints {
return mEventTimes.getLength(); return mEventTimes.getLength();
} }
public void onDownEvent(final int x, final int y, final long downTime, public void onDownEvent(final int x, final int y, final int elapsedTimeSinceFirstDown,
final long gestureFirstDownTime, final long lastTypingTime) { final int elapsedTimeSinceLastTyping) {
reset(); reset();
final long elapsedTimeAfterTyping = downTime - lastTypingTime; if (elapsedTimeSinceLastTyping < mRecognitionParams.mStaticTimeThresholdAfterFastTyping) {
if (elapsedTimeAfterTyping < mRecognitionParams.mStaticTimeThresholdAfterFastTyping) {
mAfterFastTyping = true; mAfterFastTyping = true;
} }
if (DEBUG) { if (DEBUG) {
Log.d(TAG, String.format("[%d] onDownEvent: dT=%3d%s", mPointerId, Log.d(TAG, String.format("[%d] onDownEvent: dT=%3d%s", mPointerId,
elapsedTimeAfterTyping, mAfterFastTyping ? " afterFastTyping" : "")); elapsedTimeSinceLastTyping, mAfterFastTyping ? " afterFastTyping" : ""));
} }
final int elapsedTimeFromFirstDown = (int)(downTime - gestureFirstDownTime); addPointOnKeyboard(x, y, elapsedTimeSinceFirstDown, true /* isMajorEvent */);
addPointOnKeyboard(x, y, elapsedTimeFromFirstDown, true /* isMajorEvent */);
} }
private int getGestureDynamicDistanceThreshold(final int deltaTime) { private int getGestureDynamicDistanceThreshold(final int deltaTime) {
@ -184,7 +182,7 @@ public class GestureStrokeRecognitionPoints {
} }
} }
protected void reset() { private void reset() {
mIncrementalRecognitionSize = 0; mIncrementalRecognitionSize = 0;
mLastIncrementalBatchSize = 0; mLastIncrementalBatchSize = 0;
mEventTimes.setLength(0); mEventTimes.setLength(0);