Clean up PointerTracker a bit
Change-Id: If4ff87348fbc40f271c68dad255dbc42f9b26eb6main
parent
323a7aae6c
commit
212165b0b8
|
@ -62,7 +62,6 @@ import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SuggestedWords;
|
import com.android.inputmethod.latin.SuggestedWords;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||||
import com.android.inputmethod.latin.settings.DebugSettings;
|
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.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||||
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper;
|
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 mKeyRepeatStartTimeout;
|
||||||
private final int mKeyRepeatInterval;
|
private final int mKeyRepeatInterval;
|
||||||
private final int mLongPressShiftLockTimeout;
|
|
||||||
private final int mIgnoreAltCodeKeyTimeout;
|
private final int mIgnoreAltCodeKeyTimeout;
|
||||||
private final int mGestureRecognitionUpdateTime;
|
private final int mGestureRecognitionUpdateTime;
|
||||||
|
|
||||||
|
@ -215,8 +213,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
|
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
|
||||||
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
|
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
|
||||||
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
|
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
|
||||||
mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
|
|
||||||
R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
|
|
||||||
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
|
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
|
||||||
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
|
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
|
||||||
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
|
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
|
||||||
|
@ -280,32 +276,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startLongPressTimer(final PointerTracker tracker) {
|
public void startLongPressTimer(final PointerTracker tracker, final int delay) {
|
||||||
cancelLongPressTimer();
|
cancelLongPressTimer();
|
||||||
if (tracker == null) {
|
if (delay <= 0) return;
|
||||||
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);
|
sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelLongPressTimer() {
|
public void cancelLongPressTimer() {
|
||||||
|
@ -901,9 +876,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showGestureTrail(final PointerTracker tracker) {
|
public void showGestureTrail(final PointerTracker tracker,
|
||||||
|
final boolean showsFloatingPreviewText) {
|
||||||
locatePreviewPlacerView();
|
locatePreviewPlacerView();
|
||||||
|
if (showsFloatingPreviewText) {
|
||||||
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
||||||
|
}
|
||||||
mGestureTrailsPreview.setPreviewPosition(tracker);
|
mGestureTrailsPreview.setPreviewPosition(tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.android.inputmethod.latin.InputPointers;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
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.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||||
import com.android.inputmethod.latin.utils.ResourceUtils;
|
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 dismissKeyPreview(PointerTracker tracker);
|
||||||
public void showSlidingKeyInputPreview(PointerTracker tracker);
|
public void showSlidingKeyInputPreview(PointerTracker tracker);
|
||||||
public void dismissSlidingKeyInputPreview();
|
public void dismissSlidingKeyInputPreview();
|
||||||
public void showGestureTrail(PointerTracker tracker);
|
public void showGestureTrail(PointerTracker tracker, boolean showsFloatingPreviewText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TimerProxy {
|
public interface TimerProxy {
|
||||||
public void startTypingStateTimer(Key typedKey);
|
public void startTypingStateTimer(Key typedKey);
|
||||||
public boolean isTypingState();
|
public boolean isTypingState();
|
||||||
public void startKeyRepeatTimer(PointerTracker tracker);
|
public void startKeyRepeatTimer(PointerTracker tracker);
|
||||||
public void startLongPressTimer(PointerTracker tracker);
|
public void startLongPressTimer(PointerTracker tracker, int delay);
|
||||||
public void cancelLongPressTimer();
|
public void cancelLongPressTimer();
|
||||||
public void startDoubleTapShiftKeyTimer();
|
public void startDoubleTapShiftKeyTimer();
|
||||||
public void cancelDoubleTapShiftKeyTimer();
|
public void cancelDoubleTapShiftKeyTimer();
|
||||||
|
@ -112,7 +113,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
@Override
|
@Override
|
||||||
public void startKeyRepeatTimer(PointerTracker tracker) {}
|
public void startKeyRepeatTimer(PointerTracker tracker) {}
|
||||||
@Override
|
@Override
|
||||||
public void startLongPressTimer(PointerTracker tracker) {}
|
public void startLongPressTimer(PointerTracker tracker, int delay) {}
|
||||||
@Override
|
@Override
|
||||||
public void cancelLongPressTimer() {}
|
public void cancelLongPressTimer() {}
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,6 +138,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
public final int mTouchNoiseThresholdTime;
|
public final int mTouchNoiseThresholdTime;
|
||||||
public final int mTouchNoiseThresholdDistance;
|
public final int mTouchNoiseThresholdDistance;
|
||||||
public final int mSuppressKeyPreviewAfterBatchInputDuration;
|
public final int mSuppressKeyPreviewAfterBatchInputDuration;
|
||||||
|
public final int mLongPressShiftLockTimeout;
|
||||||
|
|
||||||
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
|
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
|
||||||
|
|
||||||
|
@ -145,6 +147,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
mTouchNoiseThresholdTime = 0;
|
mTouchNoiseThresholdTime = 0;
|
||||||
mTouchNoiseThresholdDistance = 0;
|
mTouchNoiseThresholdDistance = 0;
|
||||||
mSuppressKeyPreviewAfterBatchInputDuration = 0;
|
mSuppressKeyPreviewAfterBatchInputDuration = 0;
|
||||||
|
mLongPressShiftLockTimeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
|
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
|
||||||
|
@ -156,6 +159,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
|
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
|
||||||
mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt(
|
mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt(
|
||||||
R.styleable.MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration, 0);
|
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.
|
// the more keys panel currently being shown. equals null if no panel is active.
|
||||||
private MoreKeysPanel mMoreKeysPanel;
|
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.
|
// true if this pointer is in a sliding key input.
|
||||||
boolean mIsInSlidingKeyInput;
|
boolean mIsInSlidingKeyInput;
|
||||||
// true if this pointer is in a sliding key input from a modifier key,
|
// 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;
|
return mIsInSlidingKeyInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSlidingKeyInputFromModifier() {
|
|
||||||
return mIsInSlidingKeyInputFromModifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Key getKey() {
|
public Key getKey() {
|
||||||
return mCurrentKey;
|
return mCurrentKey;
|
||||||
}
|
}
|
||||||
|
@ -753,7 +755,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
return sPointerTrackerQueue.size();
|
return sPointerTrackerQueue.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOldestTrackerInQueue() {
|
private boolean isOldestTrackerInQueue() {
|
||||||
return sPointerTrackerQueue.getOldestElement() == this;
|
return sPointerTrackerQueue.getOldestElement() == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +778,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
dismissAllMoreKeysPanels();
|
dismissAllMoreKeysPanels();
|
||||||
}
|
}
|
||||||
mTimerProxy.cancelLongPressTimer();
|
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) {
|
public void updateBatchInputByTimer(final long eventTime) {
|
||||||
|
@ -792,7 +796,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
if (mIsTrackingForActionDisabled) {
|
if (mIsTrackingForActionDisabled) {
|
||||||
return;
|
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) {
|
private void updateBatchInput(final long eventTime) {
|
||||||
|
@ -833,7 +839,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
if (mIsTrackingForActionDisabled) {
|
if (mIsTrackingForActionDisabled) {
|
||||||
return;
|
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() {
|
private void cancelBatchInput() {
|
||||||
|
@ -1013,7 +1021,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
final int translatedY = mMoreKeysPanel.translateY(y);
|
final int translatedY = mMoreKeysPanel.translateY(y);
|
||||||
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
|
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
|
||||||
onMoveKey(x, y);
|
onMoveKey(x, y);
|
||||||
|
if (mIsInSlidingKeyInputFromModifier) {
|
||||||
mDrawingProxy.showSlidingKeyInputPreview(this);
|
mDrawingProxy.showSlidingKeyInputPreview(this);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onMoveEventInternal(x, y, eventTime);
|
onMoveEventInternal(x, y, eventTime);
|
||||||
|
@ -1168,8 +1178,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
slideOutFromOldKey(oldKey, x, y);
|
slideOutFromOldKey(oldKey, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mIsInSlidingKeyInputFromModifier) {
|
||||||
mDrawingProxy.showSlidingKeyInputPreview(this);
|
mDrawingProxy.showSlidingKeyInputPreview(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onUpEvent(final int x, final int y, final long eventTime) {
|
public void onUpEvent(final int x, final int y, final long eventTime) {
|
||||||
if (DEBUG_EVENT) {
|
if (DEBUG_EVENT) {
|
||||||
|
@ -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
|
// 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.
|
// whether or not we are in the sliding input mode.
|
||||||
if (mIsInSlidingKeyInput && key.mMoreKeys == null) return;
|
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) {
|
private void detectAndSendKey(final Key key, final int x, final int y, final long eventTime) {
|
||||||
|
|
|
@ -115,9 +115,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPreviewPosition(final PointerTracker tracker) {
|
public void setPreviewPosition(final PointerTracker tracker) {
|
||||||
final boolean needsToUpdateLastPointer =
|
if (!isPreviewEnabled()) {
|
||||||
tracker.isOldestTrackerInQueue() && isPreviewEnabled();
|
|
||||||
if (!needsToUpdateLastPointer) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tracker.getLastCoordinates(mLastPointerCoords);
|
tracker.getLastCoordinates(mLastPointerCoords);
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||||
public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
|
public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
|
||||||
private final float mPreviewBodyRadius;
|
private final float mPreviewBodyRadius;
|
||||||
|
|
||||||
private boolean mShowSlidingKeyInputPreview;
|
private boolean mShowsSlidingKeyInputPreview;
|
||||||
private final int[] mPreviewFrom = CoordinateUtils.newInstance();
|
private final int[] mPreviewFrom = CoordinateUtils.newInstance();
|
||||||
private final int[] mPreviewTo = CoordinateUtils.newInstance();
|
private final int[] mPreviewTo = CoordinateUtils.newInstance();
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dismissSlidingKeyInputPreview() {
|
public void dismissSlidingKeyInputPreview() {
|
||||||
mShowSlidingKeyInputPreview = false;
|
mShowsSlidingKeyInputPreview = false;
|
||||||
getDrawingView().invalidate();
|
getDrawingView().invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void drawPreview(final Canvas canvas) {
|
public void drawPreview(final Canvas canvas) {
|
||||||
if (!isPreviewEnabled() || !mShowSlidingKeyInputPreview) {
|
if (!isPreviewEnabled() || !mShowsSlidingKeyInputPreview) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,13 +90,9 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setPreviewPosition(final PointerTracker tracker) {
|
public void setPreviewPosition(final PointerTracker tracker) {
|
||||||
if (!tracker.isInSlidingKeyInputFromModifier()) {
|
|
||||||
mShowSlidingKeyInputPreview = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tracker.getDownCoordinates(mPreviewFrom);
|
tracker.getDownCoordinates(mPreviewFrom);
|
||||||
tracker.getLastCoordinates(mPreviewTo);
|
tracker.getLastCoordinates(mPreviewTo);
|
||||||
mShowSlidingKeyInputPreview = true;
|
mShowsSlidingKeyInputPreview = true;
|
||||||
getDrawingView().invalidate();
|
getDrawingView().invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue