Clean up PointerTracker a bit

Change-Id: If4ff87348fbc40f271c68dad255dbc42f9b26eb6
main
Tadashi G. Takaoka 2013-07-30 18:42:48 +09:00
parent 323a7aae6c
commit 212165b0b8
4 changed files with 54 additions and 55 deletions

View File

@ -62,7 +62,6 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper;
@ -203,7 +202,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private final int mKeyRepeatStartTimeout;
private final int mKeyRepeatInterval;
private final int mLongPressShiftLockTimeout;
private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime;
@ -215,8 +213,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
@ -280,31 +276,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
@Override
public void startLongPressTimer(final PointerTracker tracker) {
public void startLongPressTimer(final PointerTracker tracker, final int delay) {
cancelLongPressTimer();
if (tracker == null) {
return;
}
final Key key = tracker.getKey();
final int delay;
switch (key.mCode) {
case Constants.CODE_SHIFT:
delay = mLongPressShiftLockTimeout;
break;
default:
final int longpressTimeout =
Settings.getInstance().getCurrent().mKeyLongpressTimeout;
if (tracker.isInSlidingKeyInputFromModifier()) {
// We use longer timeout for sliding finger input started from the modifier key.
delay = longpressTimeout * 3;
} else {
delay = longpressTimeout;
}
break;
}
if (delay > 0) {
sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
}
if (delay <= 0) return;
sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
}
@Override
@ -901,9 +876,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
@Override
public void showGestureTrail(final PointerTracker tracker) {
public void showGestureTrail(final PointerTracker tracker,
final boolean showsFloatingPreviewText) {
locatePreviewPlacerView();
mGestureFloatingPreviewText.setPreviewPosition(tracker);
if (showsFloatingPreviewText) {
mGestureFloatingPreviewText.setPreviewPosition(tracker);
}
mGestureTrailsPreview.setPreviewPosition(tracker);
}

View File

@ -34,6 +34,7 @@ import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
@ -87,14 +88,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public void dismissKeyPreview(PointerTracker tracker);
public void showSlidingKeyInputPreview(PointerTracker tracker);
public void dismissSlidingKeyInputPreview();
public void showGestureTrail(PointerTracker tracker);
public void showGestureTrail(PointerTracker tracker, boolean showsFloatingPreviewText);
}
public interface TimerProxy {
public void startTypingStateTimer(Key typedKey);
public boolean isTypingState();
public void startKeyRepeatTimer(PointerTracker tracker);
public void startLongPressTimer(PointerTracker tracker);
public void startLongPressTimer(PointerTracker tracker, int delay);
public void cancelLongPressTimer();
public void startDoubleTapShiftKeyTimer();
public void cancelDoubleTapShiftKeyTimer();
@ -112,7 +113,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override
public void startKeyRepeatTimer(PointerTracker tracker) {}
@Override
public void startLongPressTimer(PointerTracker tracker) {}
public void startLongPressTimer(PointerTracker tracker, int delay) {}
@Override
public void cancelLongPressTimer() {}
@Override
@ -137,6 +138,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public final int mTouchNoiseThresholdTime;
public final int mTouchNoiseThresholdDistance;
public final int mSuppressKeyPreviewAfterBatchInputDuration;
public final int mLongPressShiftLockTimeout;
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
@ -145,6 +147,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mTouchNoiseThresholdTime = 0;
mTouchNoiseThresholdDistance = 0;
mSuppressKeyPreviewAfterBatchInputDuration = 0;
mLongPressShiftLockTimeout = 0;
}
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
@ -156,6 +159,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration, 0);
mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
}
}
@ -327,6 +332,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// the more keys panel currently being shown. equals null if no panel is active.
private MoreKeysPanel mMoreKeysPanel;
private static final int MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT = 3;
// true if this pointer is in a sliding key input.
boolean mIsInSlidingKeyInput;
// true if this pointer is in a sliding key input from a modifier key,
@ -602,10 +608,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return mIsInSlidingKeyInput;
}
public boolean isInSlidingKeyInputFromModifier() {
return mIsInSlidingKeyInputFromModifier;
}
public Key getKey() {
return mCurrentKey;
}
@ -753,7 +755,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return sPointerTrackerQueue.size();
}
public boolean isOldestTrackerInQueue() {
private boolean isOldestTrackerInQueue() {
return sPointerTrackerQueue.getOldestElement() == this;
}
@ -776,7 +778,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
dismissAllMoreKeysPanels();
}
mTimerProxy.cancelLongPressTimer();
mDrawingProxy.showGestureTrail(this);
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
public void updateBatchInputByTimer(final long eventTime) {
@ -792,7 +796,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (mIsTrackingForActionDisabled) {
return;
}
mDrawingProxy.showGestureTrail(this);
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
private void updateBatchInput(final long eventTime) {
@ -833,7 +839,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (mIsTrackingForActionDisabled) {
return;
}
mDrawingProxy.showGestureTrail(this);
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
private void cancelBatchInput() {
@ -1013,7 +1021,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
onMoveKey(x, y);
mDrawingProxy.showSlidingKeyInputPreview(this);
if (mIsInSlidingKeyInputFromModifier) {
mDrawingProxy.showSlidingKeyInputPreview(this);
}
return;
}
onMoveEventInternal(x, y, eventTime);
@ -1168,7 +1178,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
slideOutFromOldKey(oldKey, x, y);
}
}
mDrawingProxy.showSlidingKeyInputPreview(this);
if (mIsInSlidingKeyInputFromModifier) {
mDrawingProxy.showSlidingKeyInputPreview(this);
}
}
public void onUpEvent(final int x, final int y, final long eventTime) {
@ -1353,7 +1365,22 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// We always need to start the long press timer if the key has its more keys regardless of
// whether or not we are in the sliding input mode.
if (mIsInSlidingKeyInput && key.mMoreKeys == null) return;
mTimerProxy.startLongPressTimer(this);
final int delay;
switch (key.mCode) {
case Constants.CODE_SHIFT:
delay = sParams.mLongPressShiftLockTimeout;
break;
default:
final int longpressTimeout = Settings.getInstance().getCurrent().mKeyLongpressTimeout;
if (mIsInSlidingKeyInputFromModifier) {
// We use longer timeout for sliding finger input started from the modifier key.
delay = longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
} else {
delay = longpressTimeout;
}
break;
}
mTimerProxy.startLongPressTimer(this, delay);
}
private void detectAndSendKey(final Key key, final int x, final int y, final long eventTime) {

View File

@ -115,9 +115,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
@Override
public void setPreviewPosition(final PointerTracker tracker) {
final boolean needsToUpdateLastPointer =
tracker.isOldestTrackerInQueue() && isPreviewEnabled();
if (!needsToUpdateLastPointer) {
if (!isPreviewEnabled()) {
return;
}
tracker.getLastCoordinates(mLastPointerCoords);

View File

@ -32,7 +32,7 @@ import com.android.inputmethod.latin.utils.CoordinateUtils;
public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
private final float mPreviewBodyRadius;
private boolean mShowSlidingKeyInputPreview;
private boolean mShowsSlidingKeyInputPreview;
private final int[] mPreviewFrom = CoordinateUtils.newInstance();
private final int[] mPreviewTo = CoordinateUtils.newInstance();
@ -62,7 +62,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
}
public void dismissSlidingKeyInputPreview() {
mShowSlidingKeyInputPreview = false;
mShowsSlidingKeyInputPreview = false;
getDrawingView().invalidate();
}
@ -72,7 +72,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
*/
@Override
public void drawPreview(final Canvas canvas) {
if (!isPreviewEnabled() || !mShowSlidingKeyInputPreview) {
if (!isPreviewEnabled() || !mShowsSlidingKeyInputPreview) {
return;
}
@ -90,13 +90,9 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
*/
@Override
public void setPreviewPosition(final PointerTracker tracker) {
if (!tracker.isInSlidingKeyInputFromModifier()) {
mShowSlidingKeyInputPreview = false;
return;
}
tracker.getDownCoordinates(mPreviewFrom);
tracker.getLastCoordinates(mPreviewTo);
mShowSlidingKeyInputPreview = true;
mShowsSlidingKeyInputPreview = true;
getDrawingView().invalidate();
}
}