Merge "Separate GestureStrokeDrawingPoints from GestureStrokeRecognitionPoints"
This commit is contained in:
commit
d99d225f10
3 changed files with 37 additions and 39 deletions
|
@ -203,6 +203,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
// true if dragging finger is allowed.
|
||||
private boolean mIsAllowedDraggingFinger;
|
||||
|
||||
private final GestureStrokeRecognitionPoints mGestureStrokeRecognitionPoints;
|
||||
private final GestureStrokeDrawingPoints mGestureStrokeDrawingPoints;
|
||||
|
||||
// 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) {
|
||||
mPointerId = id;
|
||||
mGestureStrokeDrawingPoints = new GestureStrokeDrawingPoints(
|
||||
id, sGestureStrokeRecognitionParams, sGestureStrokeDrawingParams);
|
||||
mGestureStrokeRecognitionPoints = new GestureStrokeRecognitionPoints(
|
||||
id, sGestureStrokeRecognitionParams);
|
||||
mGestureStrokeDrawingPoints = new GestureStrokeDrawingPoints(sGestureStrokeDrawingParams);
|
||||
}
|
||||
|
||||
// Returns true if keyboard has been changed by this callback.
|
||||
|
@ -408,7 +410,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
mKeyboardLayoutHasBeenChanged = true;
|
||||
final int keyWidth = mKeyboard.mMostCommonKeyWidth;
|
||||
final int keyHeight = mKeyboard.mMostCommonKeyHeight;
|
||||
mGestureStrokeDrawingPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
|
||||
mGestureStrokeRecognitionPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
|
||||
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
|
||||
if (newKey != mCurrentKey) {
|
||||
if (sDrawingProxy != null) {
|
||||
|
@ -581,7 +583,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
* @return true if the batch input has started successfully.
|
||||
*/
|
||||
private boolean mayStartBatchInput() {
|
||||
if (!mGestureStrokeDrawingPoints.isStartOfAGesture()) {
|
||||
if (!mGestureStrokeRecognitionPoints.isStartOfAGesture()) {
|
||||
return false;
|
||||
}
|
||||
if (DEBUG_LISTENER) {
|
||||
|
@ -609,13 +611,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
|
||||
public void updateBatchInputByTimer(final long syntheticMoveEventTime) {
|
||||
final int gestureTime = (int)(syntheticMoveEventTime - sGestureFirstDownTime);
|
||||
mGestureStrokeDrawingPoints.duplicateLastPointWith(gestureTime);
|
||||
mGestureStrokeRecognitionPoints.duplicateLastPointWith(gestureTime);
|
||||
updateBatchInput(syntheticMoveEventTime);
|
||||
}
|
||||
|
||||
private void updateBatchInput(final long moveEventTime) {
|
||||
synchronized (sAggregatedPointers) {
|
||||
final GestureStrokeRecognitionPoints stroke = mGestureStrokeDrawingPoints;
|
||||
final GestureStrokeRecognitionPoints stroke = mGestureStrokeRecognitionPoints;
|
||||
stroke.appendIncrementalBatchPoints(sAggregatedPointers);
|
||||
final int size = sAggregatedPointers.getPointerSize();
|
||||
if (size > sLastRecognitionPointSize
|
||||
|
@ -642,7 +644,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
private boolean mayEndBatchInput(final long upEventTime) {
|
||||
boolean hasEndBatchInputSuccessfully = false;
|
||||
synchronized (sAggregatedPointers) {
|
||||
mGestureStrokeDrawingPoints.appendAllBatchPoints(sAggregatedPointers);
|
||||
mGestureStrokeRecognitionPoints.appendAllBatchPoints(sAggregatedPointers);
|
||||
if (getActivePointerTrackerCount() == 1) {
|
||||
hasEndBatchInputSuccessfully = true;
|
||||
sTypingTimeRecorder.onEndBatchInput(upEventTime);
|
||||
|
@ -754,8 +756,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (getActivePointerTrackerCount() == 1) {
|
||||
sGestureFirstDownTime = eventTime;
|
||||
}
|
||||
mGestureStrokeDrawingPoints.onDownEvent(x, y, eventTime, sGestureFirstDownTime,
|
||||
sTypingTimeRecorder.getLastLetterTypingTime());
|
||||
final int elapsedTimeSinceFirstDown = (int)(eventTime - sGestureFirstDownTime);
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
final int beforeLength = mGestureStrokeDrawingPoints.getLength();
|
||||
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
|
||||
final boolean onValidArea = mGestureStrokeDrawingPoints.addPointOnKeyboard(
|
||||
x, y, gestureTime, isMajorEvent);
|
||||
if (mGestureStrokeDrawingPoints.getLength() > beforeLength) {
|
||||
final int beforeLength = mGestureStrokeRecognitionPoints.getLength();
|
||||
final int elapsedTimeSinceFirstDown = (int)(eventTime - sGestureFirstDownTime);
|
||||
final boolean onValidArea = mGestureStrokeRecognitionPoints.addPointOnKeyboard(
|
||||
x, y, elapsedTimeSinceFirstDown, isMajorEvent);
|
||||
if (mGestureStrokeRecognitionPoints.getLength() > beforeLength) {
|
||||
sTimerProxy.startUpdateBatchInputTimer(this);
|
||||
}
|
||||
// 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();
|
||||
return;
|
||||
}
|
||||
mGestureStrokeDrawingPoints.onMoveEvent(x, y, elapsedTimeSinceFirstDown);
|
||||
// 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.
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
|
|
|
@ -20,11 +20,8 @@ import com.android.inputmethod.latin.utils.ResizableIntArray;
|
|||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
private final ResizableIntArray mPreviewEventTimes = new ResizableIntArray(PREVIEW_CAPACITY);
|
||||
|
@ -42,16 +39,11 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
|
|||
private int mLastY;
|
||||
private double mDistanceFromLastSample;
|
||||
|
||||
public GestureStrokeDrawingPoints(final int pointerId,
|
||||
final GestureStrokeRecognitionParams recognitionParams,
|
||||
final GestureStrokeDrawingParams drawingParams) {
|
||||
super(pointerId, recognitionParams);
|
||||
public GestureStrokeDrawingPoints(final GestureStrokeDrawingParams drawingParams) {
|
||||
mDrawingParams = drawingParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
private void reset() {
|
||||
mStrokeId++;
|
||||
mLastPreviewSize = 0;
|
||||
mLastInterpolatedPreviewIndex = 0;
|
||||
|
@ -64,6 +56,11 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
|
|||
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) {
|
||||
mDistanceFromLastSample += Math.hypot(x - mLastX, y - mLastY);
|
||||
mLastX = x;
|
||||
|
@ -76,16 +73,12 @@ public final class GestureStrokeDrawingPoints extends GestureStrokeRecognitionPo
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPointOnKeyboard(final int x, final int y, final int time,
|
||||
final boolean isMajorEvent) {
|
||||
public void onMoveEvent(final int x, final int y, final int elapsedTimeSinceFirstDown) {
|
||||
if (needsSampling(x, y)) {
|
||||
mPreviewEventTimes.add(time);
|
||||
mPreviewEventTimes.add(elapsedTimeSinceFirstDown);
|
||||
mPreviewXCoordinates.add(x);
|
||||
mPreviewYCoordinates.add(y);
|
||||
}
|
||||
return super.addPointOnKeyboard(x, y, time, isMajorEvent);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,19 +103,17 @@ public class GestureStrokeRecognitionPoints {
|
|||
return mEventTimes.getLength();
|
||||
}
|
||||
|
||||
public void onDownEvent(final int x, final int y, final long downTime,
|
||||
final long gestureFirstDownTime, final long lastTypingTime) {
|
||||
public void onDownEvent(final int x, final int y, final int elapsedTimeSinceFirstDown,
|
||||
final int elapsedTimeSinceLastTyping) {
|
||||
reset();
|
||||
final long elapsedTimeAfterTyping = downTime - lastTypingTime;
|
||||
if (elapsedTimeAfterTyping < mRecognitionParams.mStaticTimeThresholdAfterFastTyping) {
|
||||
if (elapsedTimeSinceLastTyping < mRecognitionParams.mStaticTimeThresholdAfterFastTyping) {
|
||||
mAfterFastTyping = true;
|
||||
}
|
||||
if (DEBUG) {
|
||||
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, elapsedTimeFromFirstDown, true /* isMajorEvent */);
|
||||
addPointOnKeyboard(x, y, elapsedTimeSinceFirstDown, true /* isMajorEvent */);
|
||||
}
|
||||
|
||||
private int getGestureDynamicDistanceThreshold(final int deltaTime) {
|
||||
|
@ -184,7 +182,7 @@ public class GestureStrokeRecognitionPoints {
|
|||
}
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
private void reset() {
|
||||
mIncrementalRecognitionSize = 0;
|
||||
mLastIncrementalBatchSize = 0;
|
||||
mEventTimes.setLength(0);
|
||||
|
|
Loading…
Reference in a new issue