Separate TypingTimeRecorder class

Change-Id: Ic56d3e3a1be935854dcace36d8a05a9d2619dab9
main
Tadashi G. Takaoka 2013-12-20 15:54:37 +09:00
parent 921a32f0a9
commit 5045103d61
2 changed files with 84 additions and 66 deletions

View File

@ -29,6 +29,7 @@ import com.android.inputmethod.keyboard.internal.GestureStroke.GestureStrokePara
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints;
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints.GestureStrokePreviewParams;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.keyboard.internal.TypingTimeRecorder;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger;
@ -167,7 +168,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private boolean mIsDetectingGesture = false; // per PointerTracker.
private static boolean sInGesture = false;
private static long sGestureFirstDownTime;
private static TimeRecorder sTimeRecorder;
private static TypingTimeRecorder sTypingTimeRecorder;
private static final InputPointers sAggregatedPointers = new InputPointers(
GestureStroke.DEFAULT_CAPACITY);
private static int sLastRecognitionPointSize = 0; // synchronized using sAggregatedPointers
@ -224,64 +225,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
static final class TimeRecorder {
private final int mSuppressKeyPreviewAfterBatchInputDuration;
private final int mStaticTimeThresholdAfterFastTyping; // msec
private long mLastTypingTime;
private long mLastLetterTypingTime;
private long mLastBatchInputTime;
public TimeRecorder(final PointerTrackerParams pointerTrackerParams,
final GestureStrokeParams gestureStrokeParams) {
mSuppressKeyPreviewAfterBatchInputDuration =
pointerTrackerParams.mSuppressKeyPreviewAfterBatchInputDuration;
mStaticTimeThresholdAfterFastTyping =
gestureStrokeParams.mStaticTimeThresholdAfterFastTyping;
}
public boolean isInFastTyping(final long eventTime) {
final long elapsedTimeSinceLastLetterTyping = eventTime - mLastLetterTypingTime;
return elapsedTimeSinceLastLetterTyping < mStaticTimeThresholdAfterFastTyping;
}
private boolean wasLastInputTyping() {
return mLastTypingTime >= mLastBatchInputTime;
}
public void onCodeInput(final int code, final long eventTime) {
// Record the letter typing time when
// 1. Letter keys are typed successively without any batch input in between.
// 2. A letter key is typed within the threshold time since the last any key typing.
// 3. A non-letter key is typed within the threshold time since the last letter key
// typing.
if (Character.isLetter(code)) {
if (wasLastInputTyping()
|| eventTime - mLastTypingTime < mStaticTimeThresholdAfterFastTyping) {
mLastLetterTypingTime = eventTime;
}
} else {
if (eventTime - mLastLetterTypingTime < mStaticTimeThresholdAfterFastTyping) {
// This non-letter typing should be treated as a part of fast typing.
mLastLetterTypingTime = eventTime;
}
}
mLastTypingTime = eventTime;
}
public void onEndBatchInput(final long eventTime) {
mLastBatchInputTime = eventTime;
}
public long getLastLetterTypingTime() {
return mLastLetterTypingTime;
}
public boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
return !wasLastInputTyping()
&& eventTime - mLastBatchInputTime < mSuppressKeyPreviewAfterBatchInputDuration;
}
}
// The position and time at which first down event occurred.
private long mDownTime;
private int[] mDownCoordinates = CoordinateUtils.newInstance();
@ -349,7 +292,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sParams = new PointerTrackerParams(mainKeyboardViewAttr);
sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
sTypingTimeRecorder = new TypingTimeRecorder(
sGestureStrokeParams.mStaticTimeThresholdAfterFastTyping,
sParams.mSuppressKeyPreviewAfterBatchInputDuration);
final Resources res = mainKeyboardViewAttr.getResources();
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
@ -490,7 +435,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
if (key.isEnabled() || altersCode) {
sTimeRecorder.onCodeInput(code, eventTime);
sTypingTimeRecorder.onCodeInput(code, eventTime);
if (code == Constants.CODE_OUTPUT_TEXT) {
sListener.onTextInput(key.getOutputText());
} else if (code != Constants.CODE_UNSPECIFIED) {
@ -617,7 +562,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private static boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
if (!sShouldHandleGesture) return false;
return sTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
return sTypingTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
}
private void setPressedKeyGraphics(final Key key, final long eventTime) {
@ -790,7 +735,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregatedPointers);
if (getActivePointerTrackerCount() == 1) {
sInGesture = false;
sTimeRecorder.onEndBatchInput(eventTime);
sTypingTimeRecorder.onEndBatchInput(eventTime);
sTimerProxy.cancelAllUpdateBatchInputTimers();
if (!mIsTrackingForActionDisabled) {
if (DEBUG_LISTENER) {
@ -905,7 +850,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sGestureFirstDownTime = eventTime;
}
mGestureStrokeWithPreviewPoints.onDownEvent(x, y, eventTime, sGestureFirstDownTime,
sTimeRecorder.getLastLetterTypingTime());
sTypingTimeRecorder.getLastLetterTypingTime());
}
}
@ -1102,7 +1047,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// 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)
else if (sNeedsProximateBogusDownMoveUpEventHack
&& sTypingTimeRecorder.isInFastTyping(eventTime)
&& mBogusMoveEventDetector.isCloseToActualDownEvent(x, y)) {
processProximateBogusDownMoveUpEventHack(key, x, y, eventTime, oldKey, lastX, lastY);
}
@ -1320,7 +1266,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return true;
}
if (sNeedsProximateBogusDownMoveUpEventHack && !mIsAllowedDraggingFinger
&& sTimeRecorder.isInFastTyping(eventTime)
&& sTypingTimeRecorder.isInFastTyping(eventTime)
&& mBogusMoveEventDetector.hasTraveledLongDistance(x, y)) {
if (DEBUG_MODE) {
final float keyDiagonal = (float)Math.hypot(

View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.keyboard.internal;
public final class TypingTimeRecorder {
private final int mStaticTimeThresholdAfterFastTyping; // msec
private final int mSuppressKeyPreviewAfterBatchInputDuration;
private long mLastTypingTime;
private long mLastLetterTypingTime;
private long mLastBatchInputTime;
public TypingTimeRecorder(final int staticTimeThresholdAfterFastTyping,
final int suppressKeyPreviewAfterBatchInputDuration) {
mStaticTimeThresholdAfterFastTyping = staticTimeThresholdAfterFastTyping;
mSuppressKeyPreviewAfterBatchInputDuration = suppressKeyPreviewAfterBatchInputDuration;
}
public boolean isInFastTyping(final long eventTime) {
final long elapsedTimeSinceLastLetterTyping = eventTime - mLastLetterTypingTime;
return elapsedTimeSinceLastLetterTyping < mStaticTimeThresholdAfterFastTyping;
}
private boolean wasLastInputTyping() {
return mLastTypingTime >= mLastBatchInputTime;
}
public void onCodeInput(final int code, final long eventTime) {
// Record the letter typing time when
// 1. Letter keys are typed successively without any batch input in between.
// 2. A letter key is typed within the threshold time since the last any key typing.
// 3. A non-letter key is typed within the threshold time since the last letter key typing.
if (Character.isLetter(code)) {
if (wasLastInputTyping()
|| eventTime - mLastTypingTime < mStaticTimeThresholdAfterFastTyping) {
mLastLetterTypingTime = eventTime;
}
} else {
if (eventTime - mLastLetterTypingTime < mStaticTimeThresholdAfterFastTyping) {
// This non-letter typing should be treated as a part of fast typing.
mLastLetterTypingTime = eventTime;
}
}
mLastTypingTime = eventTime;
}
public void onEndBatchInput(final long eventTime) {
mLastBatchInputTime = eventTime;
}
public long getLastLetterTypingTime() {
return mLastLetterTypingTime;
}
public boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
return !wasLastInputTyping()
&& eventTime - mLastBatchInputTime < mSuppressKeyPreviewAfterBatchInputDuration;
}
}