2010-08-31 15:27:04 +00:00
|
|
|
/*
|
2011-05-20 03:09:57 +00:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2010-08-31 15:27:04 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2010-08-31 15:27:04 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-08-31 15:27:04 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2010-08-31 15:27:04 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
package com.android.inputmethod.keyboard;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2013-07-17 07:58:11 +00:00
|
|
|
import android.content.res.Resources;
|
2012-08-23 05:28:15 +00:00
|
|
|
import android.content.res.TypedArray;
|
2011-10-26 11:54:35 +00:00
|
|
|
import android.os.SystemClock;
|
2013-07-17 07:58:11 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2011-06-21 14:38:42 +00:00
|
|
|
import android.util.Log;
|
2011-09-06 06:25:58 +00:00
|
|
|
import android.view.MotionEvent;
|
2011-06-21 14:38:42 +00:00
|
|
|
|
2012-07-19 03:33:51 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2012-07-18 05:27:51 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStroke;
|
2012-10-05 03:12:54 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStroke.GestureStrokeParams;
|
2012-09-14 09:10:39 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints;
|
2013-05-07 08:40:47 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints.GestureStrokePreviewParams;
|
2011-06-22 02:53:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
|
2012-10-29 05:46:34 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2012-07-18 05:27:51 +00:00
|
|
|
import com.android.inputmethod.latin.InputPointers;
|
2011-01-28 03:40:27 +00:00
|
|
|
import com.android.inputmethod.latin.LatinImeLogger;
|
2012-08-23 05:28:15 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
2012-03-30 20:15:46 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2013-07-30 09:42:48 +00:00
|
|
|
import com.android.inputmethod.latin.settings.Settings;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2013-07-17 07:58:11 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
2012-07-20 18:02:39 +00:00
|
|
|
import com.android.inputmethod.research.ResearchLogger;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
import java.util.ArrayList;
|
2010-12-18 11:04:44 +00:00
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class PointerTracker implements PointerTrackerQueue.Element {
|
2010-12-18 11:04:44 +00:00
|
|
|
private static final String TAG = PointerTracker.class.getSimpleName();
|
|
|
|
private static final boolean DEBUG_EVENT = false;
|
|
|
|
private static final boolean DEBUG_MOVE_EVENT = false;
|
|
|
|
private static final boolean DEBUG_LISTENER = false;
|
2012-10-10 09:37:46 +00:00
|
|
|
private static boolean DEBUG_MODE = LatinImeLogger.sDBG || DEBUG_EVENT;
|
2010-09-01 16:35:24 +00:00
|
|
|
|
2012-07-23 05:59:19 +00:00
|
|
|
/** True if {@link PointerTracker}s should handle gesture events. */
|
|
|
|
private static boolean sShouldHandleGesture = false;
|
2012-08-08 02:41:58 +00:00
|
|
|
private static boolean sMainDictionaryAvailable = false;
|
|
|
|
private static boolean sGestureHandlingEnabledByInputField = false;
|
|
|
|
private static boolean sGestureHandlingEnabledByUser = false;
|
2012-07-19 03:33:51 +00:00
|
|
|
|
2011-07-11 02:31:02 +00:00
|
|
|
public interface KeyEventHandler {
|
|
|
|
/**
|
|
|
|
* Get KeyDetector object that is used for this PointerTracker.
|
|
|
|
* @return the KeyDetector object that is used for this PointerTracker
|
|
|
|
*/
|
|
|
|
public KeyDetector getKeyDetector();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get KeyboardActionListener object that is used to register key code and so on.
|
2013-08-13 03:10:26 +00:00
|
|
|
* @return the KeyboardActionListner for this PointerTracke
|
2011-07-11 02:31:02 +00:00
|
|
|
*/
|
|
|
|
public KeyboardActionListener getKeyboardActionListener();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get DrawingProxy object that is used for this PointerTracker.
|
|
|
|
* @return the DrawingProxy object that is used for this PointerTracker
|
|
|
|
*/
|
|
|
|
public DrawingProxy getDrawingProxy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get TimerProxy object that handles key repeat and long press timer event for this
|
|
|
|
* PointerTracker.
|
|
|
|
* @return the TimerProxy object that handles key repeat and long press timer event.
|
|
|
|
*/
|
|
|
|
public TimerProxy getTimerProxy();
|
|
|
|
}
|
|
|
|
|
2012-12-03 06:49:10 +00:00
|
|
|
public interface DrawingProxy {
|
2010-08-31 15:27:04 +00:00
|
|
|
public void invalidateKey(Key key);
|
2011-11-29 07:56:27 +00:00
|
|
|
public void showKeyPreview(PointerTracker tracker);
|
2011-04-19 06:18:20 +00:00
|
|
|
public void dismissKeyPreview(PointerTracker tracker);
|
2012-11-28 06:24:13 +00:00
|
|
|
public void showSlidingKeyInputPreview(PointerTracker tracker);
|
2012-12-04 07:04:21 +00:00
|
|
|
public void dismissSlidingKeyInputPreview();
|
2013-07-30 09:42:48 +00:00
|
|
|
public void showGestureTrail(PointerTracker tracker, boolean showsFloatingPreviewText);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 01:35:58 +00:00
|
|
|
public interface TimerProxy {
|
2012-07-31 09:51:58 +00:00
|
|
|
public void startTypingStateTimer(Key typedKey);
|
2012-03-14 05:46:22 +00:00
|
|
|
public boolean isTypingState();
|
2013-08-13 03:10:26 +00:00
|
|
|
public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay);
|
2013-07-30 09:42:48 +00:00
|
|
|
public void startLongPressTimer(PointerTracker tracker, int delay);
|
2011-07-17 21:37:30 +00:00
|
|
|
public void cancelLongPressTimer();
|
2013-06-03 08:50:48 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer();
|
|
|
|
public void cancelDoubleTapShiftKeyTimer();
|
|
|
|
public boolean isInDoubleTapShiftKeyTimeout();
|
2011-07-09 01:35:58 +00:00
|
|
|
public void cancelKeyTimers();
|
2012-11-22 02:04:41 +00:00
|
|
|
public void startUpdateBatchInputTimer(PointerTracker tracker);
|
2013-01-09 03:56:55 +00:00
|
|
|
public void cancelUpdateBatchInputTimer(PointerTracker tracker);
|
2012-11-28 05:34:48 +00:00
|
|
|
public void cancelAllUpdateBatchInputTimers();
|
2011-08-24 05:44:46 +00:00
|
|
|
|
|
|
|
public static class Adapter implements TimerProxy {
|
2011-11-22 00:41:01 +00:00
|
|
|
@Override
|
2012-07-31 09:51:58 +00:00
|
|
|
public void startTypingStateTimer(Key typedKey) {}
|
2011-11-22 00:41:01 +00:00
|
|
|
@Override
|
2012-03-14 05:46:22 +00:00
|
|
|
public boolean isTypingState() { return false; }
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2013-08-13 03:10:26 +00:00
|
|
|
public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay) {}
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2013-07-30 09:42:48 +00:00
|
|
|
public void startLongPressTimer(PointerTracker tracker, int delay) {}
|
2012-02-01 06:07:25 +00:00
|
|
|
@Override
|
2011-08-24 05:44:46 +00:00
|
|
|
public void cancelLongPressTimer() {}
|
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer() {}
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void cancelDoubleTapShiftKeyTimer() {}
|
2012-02-16 19:45:35 +00:00
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public boolean isInDoubleTapShiftKeyTimeout() { return false; }
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
2011-08-24 05:44:46 +00:00
|
|
|
public void cancelKeyTimers() {}
|
2012-11-22 02:04:41 +00:00
|
|
|
@Override
|
|
|
|
public void startUpdateBatchInputTimer(PointerTracker tracker) {}
|
|
|
|
@Override
|
2013-01-09 03:56:55 +00:00
|
|
|
public void cancelUpdateBatchInputTimer(PointerTracker tracker) {}
|
|
|
|
@Override
|
2012-11-28 05:34:48 +00:00
|
|
|
public void cancelAllUpdateBatchInputTimers() {}
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
2011-07-09 01:35:58 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
static final class PointerTrackerParams {
|
2012-08-23 05:28:15 +00:00
|
|
|
public final boolean mSlidingKeyInputEnabled;
|
|
|
|
public final int mTouchNoiseThresholdTime;
|
2012-10-10 09:37:46 +00:00
|
|
|
public final int mTouchNoiseThresholdDistance;
|
2012-10-05 05:37:22 +00:00
|
|
|
public final int mSuppressKeyPreviewAfterBatchInputDuration;
|
2013-08-01 06:17:54 +00:00
|
|
|
public final int mKeyRepeatStartTimeout;
|
|
|
|
public final int mKeyRepeatInterval;
|
2013-07-30 09:42:48 +00:00
|
|
|
public final int mLongPressShiftLockTimeout;
|
2012-08-23 05:28:15 +00:00
|
|
|
|
|
|
|
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
|
|
|
|
|
|
|
|
private PointerTrackerParams() {
|
|
|
|
mSlidingKeyInputEnabled = false;
|
|
|
|
mTouchNoiseThresholdTime = 0;
|
2012-10-10 09:37:46 +00:00
|
|
|
mTouchNoiseThresholdDistance = 0;
|
2012-10-05 05:37:22 +00:00
|
|
|
mSuppressKeyPreviewAfterBatchInputDuration = 0;
|
2013-08-01 06:17:54 +00:00
|
|
|
mKeyRepeatStartTimeout = 0;
|
|
|
|
mKeyRepeatInterval = 0;
|
2013-07-30 09:42:48 +00:00
|
|
|
mLongPressShiftLockTimeout = 0;
|
2012-08-23 05:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 03:12:54 +00:00
|
|
|
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
|
2012-08-23 05:28:15 +00:00
|
|
|
mSlidingKeyInputEnabled = mainKeyboardViewAttr.getBoolean(
|
|
|
|
R.styleable.MainKeyboardView_slidingKeyInputEnable, false);
|
|
|
|
mTouchNoiseThresholdTime = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_touchNoiseThresholdTime, 0);
|
2012-10-10 09:37:46 +00:00
|
|
|
mTouchNoiseThresholdDistance = mainKeyboardViewAttr.getDimensionPixelSize(
|
2012-08-23 05:28:15 +00:00
|
|
|
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
|
2012-10-05 05:37:22 +00:00
|
|
|
mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration, 0);
|
2013-08-01 06:17:54 +00:00
|
|
|
mKeyRepeatStartTimeout = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
|
|
|
|
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
|
2013-07-30 09:42:48 +00:00
|
|
|
mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
|
2012-08-23 05:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-25 11:14:39 +00:00
|
|
|
// Parameters for pointer handling.
|
2012-08-23 05:28:15 +00:00
|
|
|
private static PointerTrackerParams sParams;
|
2012-10-05 03:12:54 +00:00
|
|
|
private static GestureStrokeParams sGestureStrokeParams;
|
2013-05-07 08:40:47 +00:00
|
|
|
private static GestureStrokePreviewParams sGesturePreviewParams;
|
2012-05-30 10:29:57 +00:00
|
|
|
private static boolean sNeedsPhantomSuddenMoveEventHack;
|
2012-10-10 09:37:46 +00:00
|
|
|
// Move this threshold to resource.
|
|
|
|
// TODO: Device specific parameter would be better for device specific hack?
|
|
|
|
private static final float PHANTOM_SUDDEN_MOVE_THRESHOLD = 0.25f; // in keyWidth
|
2013-07-17 07:58:11 +00:00
|
|
|
// This hack is applied to certain classes of tablets.
|
|
|
|
// See {@link #needsProximateBogusDownMoveUpEventHack(Resources)}.
|
|
|
|
private static boolean sNeedsProximateBogusDownMoveUpEventHack;
|
2011-07-11 22:24:01 +00:00
|
|
|
|
2012-08-21 07:34:55 +00:00
|
|
|
private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList();
|
2012-11-01 04:24:18 +00:00
|
|
|
private static final PointerTrackerQueue sPointerTrackerQueue = new PointerTrackerQueue();
|
2011-07-11 22:24:01 +00:00
|
|
|
|
|
|
|
public final int mPointerId;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2011-07-09 04:26:29 +00:00
|
|
|
private DrawingProxy mDrawingProxy;
|
|
|
|
private TimerProxy mTimerProxy;
|
2011-07-04 10:59:57 +00:00
|
|
|
private KeyDetector mKeyDetector;
|
2013-07-02 09:07:35 +00:00
|
|
|
private KeyboardActionListener mListener = KeyboardActionListener.EMPTY_LISTENER;
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
private Keyboard mKeyboard;
|
2012-10-10 09:37:46 +00:00
|
|
|
private int mPhantonSuddenMoveThreshold;
|
|
|
|
private final BogusMoveEventDetector mBogusMoveEventDetector = new BogusMoveEventDetector();
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private boolean mIsDetectingGesture = false; // per PointerTracker.
|
|
|
|
private static boolean sInGesture = false;
|
|
|
|
private static long sGestureFirstDownTime;
|
2012-10-05 05:37:22 +00:00
|
|
|
private static TimeRecorder sTimeRecorder;
|
2012-08-23 06:01:46 +00:00
|
|
|
private static final InputPointers sAggregratedPointers = new InputPointers(
|
|
|
|
GestureStroke.DEFAULT_CAPACITY);
|
2012-09-27 10:01:17 +00:00
|
|
|
private static int sLastRecognitionPointSize = 0; // synchronized using sAggregratedPointers
|
|
|
|
private static long sLastRecognitionTime = 0; // synchronized using sAggregratedPointers
|
2012-07-18 08:56:30 +00:00
|
|
|
|
2012-10-10 09:37:46 +00:00
|
|
|
static final class BogusMoveEventDetector {
|
|
|
|
// Move these thresholds to resource.
|
2012-10-16 00:16:39 +00:00
|
|
|
// These thresholds' unit is a diagonal length of a key.
|
|
|
|
private static final float BOGUS_MOVE_ACCUMULATED_DISTANCE_THRESHOLD = 0.53f;
|
|
|
|
private static final float BOGUS_MOVE_RADIUS_THRESHOLD = 1.14f;
|
2012-10-10 09:37:46 +00:00
|
|
|
|
|
|
|
private int mAccumulatedDistanceThreshold;
|
|
|
|
private int mRadiusThreshold;
|
|
|
|
|
|
|
|
// Accumulated distance from actual and artificial down keys.
|
|
|
|
/* package */ int mAccumulatedDistanceFromDownKey;
|
|
|
|
private int mActualDownX;
|
|
|
|
private int mActualDownY;
|
|
|
|
|
2012-10-16 00:16:39 +00:00
|
|
|
public void setKeyboardGeometry(final int keyWidth, final int keyHeight) {
|
|
|
|
final float keyDiagonal = (float)Math.hypot(keyWidth, keyHeight);
|
2012-10-10 09:37:46 +00:00
|
|
|
mAccumulatedDistanceThreshold = (int)(
|
2012-10-16 00:16:39 +00:00
|
|
|
keyDiagonal * BOGUS_MOVE_ACCUMULATED_DISTANCE_THRESHOLD);
|
|
|
|
mRadiusThreshold = (int)(keyDiagonal * BOGUS_MOVE_RADIUS_THRESHOLD);
|
2012-10-10 09:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onActualDownEvent(final int x, final int y) {
|
|
|
|
mActualDownX = x;
|
|
|
|
mActualDownY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onDownKey() {
|
|
|
|
mAccumulatedDistanceFromDownKey = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onMoveKey(final int distance) {
|
|
|
|
mAccumulatedDistanceFromDownKey += distance;
|
|
|
|
}
|
|
|
|
|
2012-10-16 00:16:39 +00:00
|
|
|
public boolean hasTraveledLongDistance(final int x, final int y) {
|
|
|
|
final int dx = Math.abs(x - mActualDownX);
|
|
|
|
final int dy = Math.abs(y - mActualDownY);
|
|
|
|
// A bogus move event should be a horizontal movement. A vertical movement might be
|
|
|
|
// a sloppy typing and should be ignored.
|
|
|
|
return dx >= dy && mAccumulatedDistanceFromDownKey >= mAccumulatedDistanceThreshold;
|
2012-10-10 09:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* package */ int getDistanceFromDownEvent(final int x, final int y) {
|
|
|
|
return getDistance(x, y, mActualDownX, mActualDownY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCloseToActualDownEvent(final int x, final int y) {
|
|
|
|
return getDistanceFromDownEvent(x, y) < mRadiusThreshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 05:37:22 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-10 09:37:46 +00:00
|
|
|
public boolean isInFastTyping(final long eventTime) {
|
|
|
|
final long elapsedTimeSinceLastLetterTyping = eventTime - mLastLetterTypingTime;
|
|
|
|
return elapsedTimeSinceLastLetterTyping < mStaticTimeThresholdAfterFastTyping;
|
|
|
|
}
|
|
|
|
|
2012-10-09 05:31:13 +00:00
|
|
|
private boolean wasLastInputTyping() {
|
|
|
|
return mLastTypingTime >= mLastBatchInputTime;
|
2012-10-05 05:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onCodeInput(final int code, final long eventTime) {
|
2012-10-09 05:31:13 +00:00
|
|
|
// 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;
|
2012-10-05 05:37:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (eventTime - mLastLetterTypingTime < mStaticTimeThresholdAfterFastTyping) {
|
|
|
|
// This non-letter typing should be treated as a part of fast typing.
|
2012-10-09 05:31:13 +00:00
|
|
|
mLastLetterTypingTime = eventTime;
|
2012-10-05 05:37:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-09 05:31:13 +00:00
|
|
|
mLastTypingTime = eventTime;
|
2012-10-05 05:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onEndBatchInput(final long eventTime) {
|
2012-10-09 05:31:13 +00:00
|
|
|
mLastBatchInputTime = eventTime;
|
2012-10-05 05:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getLastLetterTypingTime() {
|
|
|
|
return mLastLetterTypingTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
|
2012-10-09 05:31:13 +00:00
|
|
|
return !wasLastInputTyping()
|
2012-10-05 05:37:22 +00:00
|
|
|
&& eventTime - mLastBatchInputTime < mSuppressKeyPreviewAfterBatchInputDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 23:19:19 +00:00
|
|
|
// The position and time at which first down event occurred.
|
|
|
|
private long mDownTime;
|
2012-11-28 06:24:13 +00:00
|
|
|
private int[] mDownCoordinates = CoordinateUtils.newInstance();
|
2011-07-08 23:19:19 +00:00
|
|
|
private long mUpTime;
|
|
|
|
|
2011-11-29 07:56:27 +00:00
|
|
|
// The current key where this pointer is.
|
|
|
|
private Key mCurrentKey = null;
|
|
|
|
// The position where the current key was recognized for the first time.
|
2011-07-08 23:19:19 +00:00
|
|
|
private int mKeyX;
|
|
|
|
private int mKeyY;
|
|
|
|
|
|
|
|
// Last pointer position.
|
|
|
|
private int mLastX;
|
|
|
|
private int mLastY;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2010-12-30 07:51:36 +00:00
|
|
|
// true if keyboard layout has been changed.
|
|
|
|
private boolean mKeyboardLayoutHasBeenChanged;
|
|
|
|
|
2013-04-22 08:57:05 +00:00
|
|
|
// true if this pointer is no longer triggering any action because it has been canceled.
|
|
|
|
private boolean mIsTrackingForActionDisabled;
|
2010-09-03 03:51:03 +00:00
|
|
|
|
2012-12-03 02:47:52 +00:00
|
|
|
// the more keys panel currently being shown. equals null if no panel is active.
|
|
|
|
private MoreKeysPanel mMoreKeysPanel;
|
2011-07-23 08:16:56 +00:00
|
|
|
|
2013-07-30 09:42:48 +00:00
|
|
|
private static final int MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT = 3;
|
2012-10-06 14:22:36 +00:00
|
|
|
// true if this pointer is in a sliding key input.
|
2011-07-11 22:24:01 +00:00
|
|
|
boolean mIsInSlidingKeyInput;
|
2012-10-06 14:22:36 +00:00
|
|
|
// true if this pointer is in a sliding key input from a modifier key,
|
|
|
|
// so that further modifier keys should be ignored.
|
|
|
|
boolean mIsInSlidingKeyInputFromModifier;
|
2010-12-20 07:21:54 +00:00
|
|
|
|
2012-10-06 14:22:36 +00:00
|
|
|
// true if a sliding key input is allowed.
|
2010-12-18 09:48:32 +00:00
|
|
|
private boolean mIsAllowedSlidingKeyInput;
|
|
|
|
|
2012-09-14 09:10:39 +00:00
|
|
|
private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints;
|
2012-07-18 05:27:51 +00:00
|
|
|
|
2013-07-17 07:58:11 +00:00
|
|
|
private static final int SMALL_TABLET_SMALLEST_WIDTH = 600; // dp
|
|
|
|
private static final int LARGE_TABLET_SMALLEST_WIDTH = 768; // dp
|
|
|
|
|
|
|
|
private static boolean needsProximateBogusDownMoveUpEventHack(final Resources res) {
|
|
|
|
// The proximate bogus down move up event hack is needed for a device such like,
|
|
|
|
// 1) is large tablet, or 2) is small tablet and the screen density is less than hdpi.
|
|
|
|
// Though it seems odd to use screen density as criteria of the quality of the touch
|
|
|
|
// screen, the small table that has a less density screen than hdpi most likely has been
|
|
|
|
// made with the touch screen that needs the hack.
|
|
|
|
final int sw = res.getConfiguration().smallestScreenWidthDp;
|
|
|
|
final boolean isLargeTablet = (sw >= LARGE_TABLET_SMALLEST_WIDTH);
|
|
|
|
final boolean isSmallTablet =
|
|
|
|
(sw >= SMALL_TABLET_SMALLEST_WIDTH && sw < LARGE_TABLET_SMALLEST_WIDTH);
|
|
|
|
final int densityDpi = res.getDisplayMetrics().densityDpi;
|
|
|
|
final boolean hasLowDensityScreen = (densityDpi < DisplayMetrics.DENSITY_HIGH);
|
|
|
|
final boolean needsTheHack = isLargeTablet || (isSmallTablet && hasLowDensityScreen);
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
Log.d(TAG, "needsProximateBogusDownMoveUpEventHack=" + needsTheHack
|
|
|
|
+ " smallestScreenWidthDp=" + sw + " densityDpi=" + densityDpi);
|
|
|
|
}
|
|
|
|
return needsTheHack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void init(final Resources res) {
|
|
|
|
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
|
|
|
|
ResourceUtils.getDeviceOverrideValue(
|
|
|
|
res, R.array.phantom_sudden_move_event_device_list));
|
|
|
|
sNeedsProximateBogusDownMoveUpEventHack = needsProximateBogusDownMoveUpEventHack(res);
|
2012-08-23 05:28:15 +00:00
|
|
|
sParams = PointerTrackerParams.DEFAULT;
|
2012-10-05 03:12:54 +00:00
|
|
|
sGestureStrokeParams = GestureStrokeParams.DEFAULT;
|
2013-05-07 08:40:47 +00:00
|
|
|
sGesturePreviewParams = GestureStrokePreviewParams.DEFAULT;
|
2012-10-05 05:37:22 +00:00
|
|
|
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
|
2012-01-25 11:14:39 +00:00
|
|
|
}
|
2011-11-22 00:41:01 +00:00
|
|
|
|
2012-08-23 05:28:15 +00:00
|
|
|
public static void setParameters(final TypedArray mainKeyboardViewAttr) {
|
|
|
|
sParams = new PointerTrackerParams(mainKeyboardViewAttr);
|
2012-10-05 03:12:54 +00:00
|
|
|
sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
|
2013-05-07 08:40:47 +00:00
|
|
|
sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
|
2012-10-05 05:37:22 +00:00
|
|
|
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 02:41:58 +00:00
|
|
|
private static void updateGestureHandlingMode() {
|
|
|
|
sShouldHandleGesture = sMainDictionaryAvailable
|
|
|
|
&& sGestureHandlingEnabledByInputField
|
|
|
|
&& sGestureHandlingEnabledByUser
|
|
|
|
&& !AccessibilityUtils.getInstance().isTouchExplorationEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that this method is called from a non-UI thread.
|
2012-08-23 06:14:46 +00:00
|
|
|
public static void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
|
2012-08-08 02:41:58 +00:00
|
|
|
sMainDictionaryAvailable = mainDictionaryAvailable;
|
|
|
|
updateGestureHandlingMode();
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
|
2012-08-08 02:41:58 +00:00
|
|
|
sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
|
|
|
|
updateGestureHandlingMode();
|
2012-07-19 03:33:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public static PointerTracker getPointerTracker(final int id, final KeyEventHandler handler) {
|
2012-03-13 11:53:15 +00:00
|
|
|
final ArrayList<PointerTracker> trackers = sTrackers;
|
2011-07-11 22:24:01 +00:00
|
|
|
|
|
|
|
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
|
|
|
|
for (int i = trackers.size(); i <= id; i++) {
|
|
|
|
final PointerTracker tracker = new PointerTracker(i, handler);
|
|
|
|
trackers.add(tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
return trackers.get(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isAnyInSlidingKeyInput() {
|
2012-11-01 04:24:18 +00:00
|
|
|
return sPointerTrackerQueue.isAnyInSlidingKeyInput();
|
2011-07-11 22:24:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 10:00:45 +00:00
|
|
|
public static void cancelAllPointerTrackers() {
|
|
|
|
sPointerTrackerQueue.cancelAllPointerTrackers();
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public static void setKeyboardActionListener(final KeyboardActionListener listener) {
|
2012-07-20 08:51:52 +00:00
|
|
|
final int trackersSize = sTrackers.size();
|
|
|
|
for (int i = 0; i < trackersSize; ++i) {
|
|
|
|
final PointerTracker tracker = sTrackers.get(i);
|
2011-07-11 22:24:01 +00:00
|
|
|
tracker.mListener = listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public static void setKeyDetector(final KeyDetector keyDetector) {
|
2012-07-20 08:51:52 +00:00
|
|
|
final int trackersSize = sTrackers.size();
|
|
|
|
for (int i = 0; i < trackersSize; ++i) {
|
|
|
|
final PointerTracker tracker = sTrackers.get(i);
|
2011-07-11 22:24:01 +00:00
|
|
|
tracker.setKeyDetectorInner(keyDetector);
|
|
|
|
// Mark that keyboard layout has been changed.
|
|
|
|
tracker.mKeyboardLayoutHasBeenChanged = true;
|
|
|
|
}
|
2012-07-19 03:33:51 +00:00
|
|
|
final Keyboard keyboard = keyDetector.getKeyboard();
|
2012-08-08 02:41:58 +00:00
|
|
|
sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput();
|
|
|
|
updateGestureHandlingMode();
|
2011-07-11 22:24:01 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 05:15:56 +00:00
|
|
|
public static void setReleasedKeyGraphicsToAllKeys() {
|
2012-07-20 08:51:52 +00:00
|
|
|
final int trackersSize = sTrackers.size();
|
|
|
|
for (int i = 0; i < trackersSize; ++i) {
|
|
|
|
final PointerTracker tracker = sTrackers.get(i);
|
2011-11-29 07:56:27 +00:00
|
|
|
tracker.setReleasedKeyGraphics(tracker.mCurrentKey);
|
2011-07-11 22:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 20:38:29 +00:00
|
|
|
public static void dismissAllMoreKeysPanels() {
|
|
|
|
final int trackersSize = sTrackers.size();
|
|
|
|
for (int i = 0; i < trackersSize; ++i) {
|
|
|
|
final PointerTracker tracker = sTrackers.get(i);
|
|
|
|
if (tracker.isShowingMoreKeysPanel()) {
|
|
|
|
tracker.mMoreKeysPanel.dismissMoreKeysPanel();
|
|
|
|
tracker.mMoreKeysPanel = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private PointerTracker(final int id, final KeyEventHandler handler) {
|
|
|
|
if (handler == null) {
|
2011-07-11 22:24:01 +00:00
|
|
|
throw new NullPointerException();
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2011-07-11 22:24:01 +00:00
|
|
|
mPointerId = id;
|
2012-10-05 03:12:54 +00:00
|
|
|
mGestureStrokeWithPreviewPoints = new GestureStrokeWithPreviewPoints(
|
2013-05-07 08:40:47 +00:00
|
|
|
id, sGestureStrokeParams, sGesturePreviewParams);
|
2013-07-31 09:13:42 +00:00
|
|
|
setKeyEventHandler(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setKeyEventHandler(final KeyEventHandler handler) {
|
2011-07-11 22:24:01 +00:00
|
|
|
setKeyDetectorInner(handler.getKeyDetector());
|
|
|
|
mListener = handler.getKeyboardActionListener();
|
|
|
|
mDrawingProxy = handler.getDrawingProxy();
|
|
|
|
mTimerProxy = handler.getTimerProxy();
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 07:51:36 +00:00
|
|
|
// Returns true if keyboard has been changed by this callback.
|
2013-08-01 06:17:54 +00:00
|
|
|
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key,
|
2013-08-13 03:10:26 +00:00
|
|
|
final int repeatCount) {
|
2013-04-22 08:57:05 +00:00
|
|
|
// While gesture input is going on, this method should be a no-operation. But when gesture
|
|
|
|
// input has been canceled, <code>sInGesture</code> and <code>mIsDetectingGesture</code>
|
|
|
|
// are set to false. To keep this method is a no-operation,
|
|
|
|
// <code>mIsTrackingForActionDisabled</code> should also be taken account of.
|
|
|
|
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
|
2012-06-12 10:40:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-15 05:39:02 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
|
2011-12-01 07:34:23 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2013-08-01 06:17:54 +00:00
|
|
|
Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
|
2012-09-27 10:01:17 +00:00
|
|
|
KeyDetector.printableCode(key),
|
|
|
|
ignoreModifierKey ? " ignoreModifier" : "",
|
2013-08-01 06:17:54 +00:00
|
|
|
key.isEnabled() ? "" : " disabled",
|
2013-08-13 03:10:26 +00:00
|
|
|
repeatCount > 0 ? " repeatCount=" + repeatCount : ""));
|
2011-12-01 07:34:23 +00:00
|
|
|
}
|
2011-11-22 00:41:01 +00:00
|
|
|
if (ignoreModifierKey) {
|
2011-04-07 08:16:30 +00:00
|
|
|
return false;
|
2011-11-22 00:41:01 +00:00
|
|
|
}
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled()) {
|
2013-08-12 09:05:11 +00:00
|
|
|
mListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
|
2011-02-20 07:50:46 +00:00
|
|
|
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
2012-07-31 09:51:58 +00:00
|
|
|
mTimerProxy.startTypingStateTimer(key);
|
2011-02-20 07:50:46 +00:00
|
|
|
return keyboardLayoutHasBeenChanged;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 07:50:46 +00:00
|
|
|
// Note that we need primaryCode argument because the keyboard may in shifted state and the
|
|
|
|
// primaryCode is different from {@link Key#mCode}.
|
2012-08-23 06:14:46 +00:00
|
|
|
private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
|
2012-10-05 05:37:22 +00:00
|
|
|
final int y, final long eventTime) {
|
2013-04-15 05:39:02 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
|
2012-03-14 10:49:13 +00:00
|
|
|
final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
|
2012-08-28 08:19:49 +00:00
|
|
|
final int code = altersCode ? key.getAltCode() : primaryCode;
|
2011-11-30 08:54:58 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2012-10-29 05:46:34 +00:00
|
|
|
final String output = code == Constants.CODE_OUTPUT_TEXT
|
|
|
|
? key.getOutputText() : Constants.printableCode(code);
|
2012-09-27 10:01:17 +00:00
|
|
|
Log.d(TAG, String.format("[%d] onCodeInput: %4d %4d %s%s%s", mPointerId, x, y,
|
|
|
|
output, ignoreModifierKey ? " ignoreModifier" : "",
|
|
|
|
altersCode ? " altersCode" : "", key.isEnabled() ? "" : " disabled"));
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-03-30 20:15:46 +00:00
|
|
|
ResearchLogger.pointerTracker_callListenerOnCodeInput(key, x, y, ignoreModifierKey,
|
|
|
|
altersCode, code);
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
if (ignoreModifierKey) {
|
2011-04-07 08:16:30 +00:00
|
|
|
return;
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|
2012-03-14 10:49:13 +00:00
|
|
|
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
|
|
|
|
if (key.isEnabled() || altersCode) {
|
2012-10-05 05:37:22 +00:00
|
|
|
sTimeRecorder.onCodeInput(code, eventTime);
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_OUTPUT_TEXT) {
|
2012-08-28 08:19:49 +00:00
|
|
|
mListener.onTextInput(key.getOutputText());
|
2012-10-29 05:46:34 +00:00
|
|
|
} else if (code != Constants.CODE_UNSPECIFIED) {
|
2012-03-06 05:56:46 +00:00
|
|
|
mListener.onCodeInput(code, x, y);
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
2011-11-22 00:41:01 +00:00
|
|
|
}
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 14:22:36 +00:00
|
|
|
// Note that we need primaryCode argument because the keyboard may be in shifted state and the
|
2011-02-20 07:50:46 +00:00
|
|
|
// primaryCode is different from {@link Key#mCode}.
|
2012-08-23 06:14:46 +00:00
|
|
|
private void callListenerOnRelease(final Key key, final int primaryCode,
|
|
|
|
final boolean withSliding) {
|
2013-04-22 08:57:05 +00:00
|
|
|
// See the comment at {@link #callListenerOnPressAndCheckKeyboardLayoutChange(Key}}.
|
|
|
|
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
|
2012-06-12 10:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-04-15 05:39:02 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
|
2011-12-01 07:34:23 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2012-09-27 10:01:17 +00:00
|
|
|
Log.d(TAG, String.format("[%d] onRelease : %s%s%s%s", mPointerId,
|
2012-10-29 05:46:34 +00:00
|
|
|
Constants.printableCode(primaryCode),
|
2012-09-27 10:01:17 +00:00
|
|
|
withSliding ? " sliding" : "", ignoreModifierKey ? " ignoreModifier" : "",
|
|
|
|
key.isEnabled() ? "": " disabled"));
|
2011-12-01 07:34:23 +00:00
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-03-30 20:15:46 +00:00
|
|
|
ResearchLogger.pointerTracker_callListenerOnRelease(key, primaryCode, withSliding,
|
|
|
|
ignoreModifierKey);
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
if (ignoreModifierKey) {
|
2011-04-07 08:16:30 +00:00
|
|
|
return;
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|
2011-11-22 00:41:01 +00:00
|
|
|
if (key.isEnabled()) {
|
2012-01-17 08:08:26 +00:00
|
|
|
mListener.onReleaseKey(primaryCode, withSliding);
|
2011-11-22 00:41:01 +00:00
|
|
|
}
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
private void callListenerOnFinishSlidingInput() {
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, String.format("[%d] onFinishSlidingInput", mPointerId));
|
|
|
|
}
|
|
|
|
mListener.onFinishSlidingInput();
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:13:57 +00:00
|
|
|
private void callListenerOnCancelInput() {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2012-09-27 10:01:17 +00:00
|
|
|
Log.d(TAG, String.format("[%d] onCancelInput", mPointerId));
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-03-30 20:15:46 +00:00
|
|
|
ResearchLogger.pointerTracker_callListenerOnCancelInput();
|
|
|
|
}
|
2010-12-20 07:13:57 +00:00
|
|
|
mListener.onCancelInput();
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void setKeyDetectorInner(final KeyDetector keyDetector) {
|
2012-09-27 10:01:17 +00:00
|
|
|
final Keyboard keyboard = keyDetector.getKeyboard();
|
|
|
|
if (keyDetector == mKeyDetector && keyboard == mKeyboard) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-04 10:59:57 +00:00
|
|
|
mKeyDetector = keyDetector;
|
2011-07-08 05:31:29 +00:00
|
|
|
mKeyboard = keyDetector.getKeyboard();
|
2012-10-16 00:16:39 +00:00
|
|
|
final int keyWidth = mKeyboard.mMostCommonKeyWidth;
|
|
|
|
final int keyHeight = mKeyboard.mMostCommonKeyHeight;
|
2012-11-22 06:39:28 +00:00
|
|
|
mGestureStrokeWithPreviewPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
|
2012-06-25 07:33:06 +00:00
|
|
|
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
|
|
|
|
if (newKey != mCurrentKey) {
|
|
|
|
if (mDrawingProxy != null) {
|
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
|
|
|
}
|
2012-08-01 09:55:02 +00:00
|
|
|
// Keep {@link #mCurrentKey} that comes from previous keyboard.
|
2012-06-25 07:33:06 +00:00
|
|
|
}
|
2012-10-10 09:37:46 +00:00
|
|
|
mPhantonSuddenMoveThreshold = (int)(keyWidth * PHANTOM_SUDDEN_MOVE_THRESHOLD);
|
2012-10-16 00:16:39 +00:00
|
|
|
mBogusMoveEventDetector.setKeyboardGeometry(keyWidth, keyHeight);
|
2011-07-08 05:31:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 05:45:06 +00:00
|
|
|
@Override
|
2010-12-20 07:21:54 +00:00
|
|
|
public boolean isInSlidingKeyInput() {
|
|
|
|
return mIsInSlidingKeyInput;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:56:27 +00:00
|
|
|
public Key getKey() {
|
|
|
|
return mCurrentKey;
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 05:45:06 +00:00
|
|
|
@Override
|
2010-09-15 06:02:29 +00:00
|
|
|
public boolean isModifier() {
|
2011-11-29 07:56:27 +00:00
|
|
|
return mCurrentKey != null && mCurrentKey.isModifier();
|
2010-09-15 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public Key getKeyOn(final int x, final int y) {
|
2012-03-15 10:44:43 +00:00
|
|
|
return mKeyDetector.detectHitKey(x, y);
|
2010-09-15 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void setReleasedKeyGraphics(final Key key) {
|
2011-07-23 08:27:49 +00:00
|
|
|
mDrawingProxy.dismissKeyPreview(this);
|
2012-03-14 10:49:13 +00:00
|
|
|
if (key == null) {
|
2012-03-13 08:15:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-14 10:49:13 +00:00
|
|
|
// Even if the key is disabled, update the key release graphics just in case.
|
2012-03-13 08:15:05 +00:00
|
|
|
updateReleaseKeyGraphics(key);
|
|
|
|
|
|
|
|
if (key.isShift()) {
|
|
|
|
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
|
|
|
if (shiftKey != key) {
|
|
|
|
updateReleaseKeyGraphics(shiftKey);
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-13 08:15:05 +00:00
|
|
|
}
|
2011-11-30 08:54:58 +00:00
|
|
|
|
2012-03-13 08:15:05 +00:00
|
|
|
if (key.altCodeWhileTyping()) {
|
2012-08-28 08:19:49 +00:00
|
|
|
final int altCode = key.getAltCode();
|
2012-03-13 08:15:05 +00:00
|
|
|
final Key altKey = mKeyboard.getKey(altCode);
|
|
|
|
if (altKey != null) {
|
|
|
|
updateReleaseKeyGraphics(altKey);
|
|
|
|
}
|
|
|
|
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
2012-08-28 08:19:49 +00:00
|
|
|
if (k != key && k.getAltCode() == altCode) {
|
2012-03-13 08:15:05 +00:00
|
|
|
updateReleaseKeyGraphics(k);
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 06:59:59 +00:00
|
|
|
private static boolean needsToSuppressKeyPreviewPopup(final long eventTime) {
|
|
|
|
if (!sShouldHandleGesture) return false;
|
2012-10-05 05:37:22 +00:00
|
|
|
return sTimeRecorder.needsToSuppressKeyPreviewPopup(eventTime);
|
2012-09-28 06:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setPressedKeyGraphics(final Key key, final long eventTime) {
|
2012-03-14 10:49:13 +00:00
|
|
|
if (key == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
|
|
|
|
final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
|
|
|
|
final boolean needsToUpdateGraphics = key.isEnabled() || altersCode;
|
|
|
|
if (!needsToUpdateGraphics) {
|
2012-03-13 08:15:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-28 06:59:59 +00:00
|
|
|
if (!key.noKeyPreview() && !sInGesture && !needsToSuppressKeyPreviewPopup(eventTime)) {
|
2012-03-13 08:15:05 +00:00
|
|
|
mDrawingProxy.showKeyPreview(this);
|
|
|
|
}
|
|
|
|
updatePressKeyGraphics(key);
|
|
|
|
|
|
|
|
if (key.isShift()) {
|
|
|
|
for (final Key shiftKey : mKeyboard.mShiftKeys) {
|
|
|
|
if (shiftKey != key) {
|
|
|
|
updatePressKeyGraphics(shiftKey);
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-13 08:15:05 +00:00
|
|
|
}
|
2011-11-30 08:54:58 +00:00
|
|
|
|
2012-03-14 05:46:22 +00:00
|
|
|
if (key.altCodeWhileTyping() && mTimerProxy.isTypingState()) {
|
2012-08-28 08:19:49 +00:00
|
|
|
final int altCode = key.getAltCode();
|
2012-03-13 08:15:05 +00:00
|
|
|
final Key altKey = mKeyboard.getKey(altCode);
|
|
|
|
if (altKey != null) {
|
|
|
|
updatePressKeyGraphics(altKey);
|
|
|
|
}
|
|
|
|
for (final Key k : mKeyboard.mAltCodeKeysWhileTyping) {
|
2012-08-28 08:19:49 +00:00
|
|
|
if (k != key && k.getAltCode() == altCode) {
|
2012-03-13 08:15:05 +00:00
|
|
|
updatePressKeyGraphics(k);
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
}
|
2010-09-03 03:51:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void updateReleaseKeyGraphics(final Key key) {
|
2012-03-13 08:15:05 +00:00
|
|
|
key.onReleased();
|
|
|
|
mDrawingProxy.invalidateKey(key);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void updatePressKeyGraphics(final Key key) {
|
2012-03-13 08:15:05 +00:00
|
|
|
key.onPressed();
|
|
|
|
mDrawingProxy.invalidateKey(key);
|
|
|
|
}
|
|
|
|
|
2012-09-14 09:10:39 +00:00
|
|
|
public GestureStrokeWithPreviewPoints getGestureStrokeWithPreviewPoints() {
|
|
|
|
return mGestureStrokeWithPreviewPoints;
|
2012-07-20 12:01:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:24:13 +00:00
|
|
|
public void getLastCoordinates(final int[] outCoords) {
|
|
|
|
CoordinateUtils.set(outCoords, mLastX, mLastY);
|
2011-07-08 23:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getDownTime() {
|
|
|
|
return mDownTime;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:24:13 +00:00
|
|
|
public void getDownCoordinates(final int[] outCoords) {
|
|
|
|
CoordinateUtils.copy(outCoords, mDownCoordinates);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private Key onDownKey(final int x, final int y, final long eventTime) {
|
2011-07-08 23:19:19 +00:00
|
|
|
mDownTime = eventTime;
|
2012-11-28 06:24:13 +00:00
|
|
|
CoordinateUtils.set(mDownCoordinates, x, y);
|
2012-10-10 09:37:46 +00:00
|
|
|
mBogusMoveEventDetector.onDownKey();
|
2011-07-08 23:19:19 +00:00
|
|
|
return onMoveToNewKey(onMoveKeyInternal(x, y), x, y);
|
|
|
|
}
|
|
|
|
|
2012-10-10 09:37:46 +00:00
|
|
|
static int getDistance(final int x1, final int y1, final int x2, final int y2) {
|
|
|
|
return (int)Math.hypot(x1 - x2, y1 - y2);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private Key onMoveKeyInternal(final int x, final int y) {
|
2012-10-10 09:37:46 +00:00
|
|
|
mBogusMoveEventDetector.onMoveKey(getDistance(x, y, mLastX, mLastY));
|
2011-07-08 23:19:19 +00:00
|
|
|
mLastX = x;
|
|
|
|
mLastY = y;
|
2012-03-15 10:44:43 +00:00
|
|
|
return mKeyDetector.detectHitKey(x, y);
|
2011-07-08 23:19:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private Key onMoveKey(final int x, final int y) {
|
2011-07-08 23:19:19 +00:00
|
|
|
return onMoveKeyInternal(x, y);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private Key onMoveToNewKey(final Key newKey, final int x, final int y) {
|
2011-11-29 07:56:27 +00:00
|
|
|
mCurrentKey = newKey;
|
2011-07-08 23:19:19 +00:00
|
|
|
mKeyX = x;
|
|
|
|
mKeyY = y;
|
2011-11-29 07:56:27 +00:00
|
|
|
return newKey;
|
2011-07-08 23:19:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private static int getActivePointerTrackerCount() {
|
2012-11-01 04:24:18 +00:00
|
|
|
return sPointerTrackerQueue.size();
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 09:42:48 +00:00
|
|
|
private boolean isOldestTrackerInQueue() {
|
2013-01-21 09:02:09 +00:00
|
|
|
return sPointerTrackerQueue.getOldestElement() == this;
|
2012-11-01 04:04:49 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 03:46:55 +00:00
|
|
|
private void mayStartBatchInput(final Key key) {
|
2012-09-14 09:10:39 +00:00
|
|
|
if (sInGesture || !mGestureStrokeWithPreviewPoints.isStartOfAGesture()) {
|
2012-09-14 01:23:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-12 09:05:11 +00:00
|
|
|
if (key == null || !Character.isLetter(key.getCode())) {
|
2012-09-26 03:46:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-14 01:23:59 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2012-09-27 10:01:17 +00:00
|
|
|
Log.d(TAG, String.format("[%d] onStartBatchInput", mPointerId));
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-09-14 01:23:59 +00:00
|
|
|
sInGesture = true;
|
2012-09-27 10:01:17 +00:00
|
|
|
synchronized (sAggregratedPointers) {
|
|
|
|
sAggregratedPointers.reset();
|
|
|
|
sLastRecognitionPointSize = 0;
|
|
|
|
sLastRecognitionTime = 0;
|
|
|
|
mListener.onStartBatchInput();
|
2012-12-10 20:38:29 +00:00
|
|
|
dismissAllMoreKeysPanels();
|
2012-09-27 10:01:17 +00:00
|
|
|
}
|
2012-10-11 08:51:45 +00:00
|
|
|
mTimerProxy.cancelLongPressTimer();
|
2013-07-30 09:42:48 +00:00
|
|
|
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
|
|
|
mDrawingProxy.showGestureTrail(
|
|
|
|
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 02:04:41 +00:00
|
|
|
public void updateBatchInputByTimer(final long eventTime) {
|
|
|
|
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
|
|
|
|
mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime);
|
|
|
|
updateBatchInput(eventTime);
|
|
|
|
}
|
|
|
|
|
2012-09-26 06:49:23 +00:00
|
|
|
private void mayUpdateBatchInput(final long eventTime, final Key key) {
|
|
|
|
if (key != null) {
|
2012-11-22 02:04:41 +00:00
|
|
|
updateBatchInput(eventTime);
|
|
|
|
}
|
2013-04-22 08:57:05 +00:00
|
|
|
if (mIsTrackingForActionDisabled) {
|
2012-12-03 05:42:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-30 09:42:48 +00:00
|
|
|
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
|
|
|
mDrawingProxy.showGestureTrail(
|
|
|
|
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
2012-11-22 02:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBatchInput(final long eventTime) {
|
|
|
|
synchronized (sAggregratedPointers) {
|
|
|
|
final GestureStroke stroke = mGestureStrokeWithPreviewPoints;
|
|
|
|
stroke.appendIncrementalBatchPoints(sAggregratedPointers);
|
|
|
|
final int size = sAggregratedPointers.getPointerSize();
|
|
|
|
if (size > sLastRecognitionPointSize
|
|
|
|
&& stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) {
|
|
|
|
sLastRecognitionPointSize = size;
|
|
|
|
sLastRecognitionTime = eventTime;
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
|
|
|
|
size));
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2012-11-22 02:04:41 +00:00
|
|
|
mTimerProxy.startUpdateBatchInputTimer(this);
|
|
|
|
mListener.onUpdateBatchInput(sAggregratedPointers);
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 06:59:59 +00:00
|
|
|
private void mayEndBatchInput(final long eventTime) {
|
2012-08-23 06:01:46 +00:00
|
|
|
synchronized (sAggregratedPointers) {
|
2012-09-14 09:10:39 +00:00
|
|
|
mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregratedPointers);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (getActivePointerTrackerCount() == 1) {
|
|
|
|
sInGesture = false;
|
2012-10-05 05:37:22 +00:00
|
|
|
sTimeRecorder.onEndBatchInput(eventTime);
|
2012-11-30 05:53:38 +00:00
|
|
|
mTimerProxy.cancelAllUpdateBatchInputTimers();
|
2013-04-22 08:57:05 +00:00
|
|
|
if (!mIsTrackingForActionDisabled) {
|
2012-11-22 06:39:28 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d",
|
|
|
|
mPointerId, sAggregratedPointers.getPointerSize()));
|
|
|
|
}
|
|
|
|
mListener.onEndBatchInput(sAggregratedPointers);
|
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2013-04-22 08:57:05 +00:00
|
|
|
if (mIsTrackingForActionDisabled) {
|
2012-12-03 05:42:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-30 09:42:48 +00:00
|
|
|
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
|
|
|
mDrawingProxy.showGestureTrail(
|
|
|
|
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 01:49:35 +00:00
|
|
|
private void cancelBatchInput() {
|
2013-07-25 10:00:45 +00:00
|
|
|
cancelAllPointerTrackers();
|
2013-01-09 06:26:03 +00:00
|
|
|
mIsDetectingGesture = false;
|
2012-12-21 05:14:09 +00:00
|
|
|
if (!sInGesture) {
|
|
|
|
return;
|
|
|
|
}
|
2012-12-06 01:49:35 +00:00
|
|
|
sInGesture = false;
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, String.format("[%d] onCancelBatchInput", mPointerId));
|
|
|
|
}
|
|
|
|
mListener.onCancelBatchInput();
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:48:04 +00:00
|
|
|
public void processMotionEvent(final MotionEvent me, final KeyEventHandler handler) {
|
|
|
|
final int action = me.getActionMasked();
|
|
|
|
final long eventTime = me.getEventTime();
|
|
|
|
if (action == MotionEvent.ACTION_MOVE) {
|
|
|
|
final int pointerCount = me.getPointerCount();
|
|
|
|
for (int index = 0; index < pointerCount; index++) {
|
|
|
|
final int id = me.getPointerId(index);
|
|
|
|
final PointerTracker tracker = getPointerTracker(id, handler);
|
|
|
|
final int x = (int)me.getX(index);
|
|
|
|
final int y = (int)me.getY(index);
|
|
|
|
tracker.onMoveEvent(x, y, eventTime, me);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final int index = me.getActionIndex();
|
|
|
|
final int x = (int)me.getX(index);
|
|
|
|
final int y = (int)me.getY(index);
|
2011-09-06 06:25:58 +00:00
|
|
|
switch (action) {
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
case MotionEvent.ACTION_POINTER_DOWN:
|
|
|
|
onDownEvent(x, y, eventTime, handler);
|
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
case MotionEvent.ACTION_POINTER_UP:
|
|
|
|
onUpEvent(x, y, eventTime);
|
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
|
|
|
onCancelEvent(x, y, eventTime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:48:04 +00:00
|
|
|
private void onDownEvent(final int x, final int y, final long eventTime,
|
2012-08-23 06:14:46 +00:00
|
|
|
final KeyEventHandler handler) {
|
|
|
|
if (DEBUG_EVENT) {
|
2010-12-18 11:04:44 +00:00
|
|
|
printTouchEvent("onDownEvent:", x, y, eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2013-07-31 09:13:42 +00:00
|
|
|
setKeyEventHandler(handler);
|
2010-12-17 05:13:01 +00:00
|
|
|
// Naive up-to-down noise filter.
|
2011-07-08 23:19:19 +00:00
|
|
|
final long deltaT = eventTime - mUpTime;
|
2012-01-25 11:14:39 +00:00
|
|
|
if (deltaT < sParams.mTouchNoiseThresholdTime) {
|
2012-10-10 09:37:46 +00:00
|
|
|
final int distance = getDistance(x, y, mLastX, mLastY);
|
|
|
|
if (distance < sParams.mTouchNoiseThresholdDistance) {
|
2011-01-28 03:40:27 +00:00
|
|
|
if (DEBUG_MODE)
|
2012-10-10 09:37:46 +00:00
|
|
|
Log.w(TAG, String.format("[%d] onDownEvent:"
|
|
|
|
+ " ignore potential noise: time=%d distance=%d",
|
|
|
|
mPointerId, deltaT, distance));
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-10-10 09:37:46 +00:00
|
|
|
ResearchLogger.pointerTracker_onDownEvent(deltaT, distance * distance);
|
2012-03-30 20:15:46 +00:00
|
|
|
}
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2010-12-17 05:13:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 10:40:37 +00:00
|
|
|
final Key key = getKeyOn(x, y);
|
2012-10-10 09:37:46 +00:00
|
|
|
mBogusMoveEventDetector.onActualDownEvent(x, y);
|
2012-11-01 04:24:18 +00:00
|
|
|
if (key != null && key.isModifier()) {
|
|
|
|
// Before processing a down event of modifier key, all pointers already being
|
|
|
|
// tracked should be released.
|
|
|
|
sPointerTrackerQueue.releaseAllPointers(eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
2012-11-01 04:24:18 +00:00
|
|
|
sPointerTrackerQueue.add(this);
|
2010-12-21 05:01:13 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!sShouldHandleGesture) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-09 08:20:07 +00:00
|
|
|
// A gesture should start only from a non-modifier key.
|
2012-09-14 05:00:51 +00:00
|
|
|
mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard()
|
2013-08-01 06:17:54 +00:00
|
|
|
&& key != null && !key.isModifier() && !key.isRepeatable();
|
2012-09-14 05:00:51 +00:00
|
|
|
if (mIsDetectingGesture) {
|
|
|
|
if (getActivePointerTrackerCount() == 1) {
|
2012-08-23 06:01:46 +00:00
|
|
|
sGestureFirstDownTime = eventTime;
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-09-27 10:01:17 +00:00
|
|
|
mGestureStrokeWithPreviewPoints.onDownEvent(x, y, eventTime, sGestureFirstDownTime,
|
2012-10-05 05:37:22 +00:00
|
|
|
sTimeRecorder.getLastLetterTypingTime());
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 02:47:52 +00:00
|
|
|
private boolean isShowingMoreKeysPanel() {
|
|
|
|
return (mMoreKeysPanel != null);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void onDownEventInternal(final int x, final int y, final long eventTime) {
|
2011-11-29 07:56:27 +00:00
|
|
|
Key key = onDownKey(x, y, eventTime);
|
2010-12-18 09:48:32 +00:00
|
|
|
// Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding
|
2011-08-23 03:08:36 +00:00
|
|
|
// from modifier key, or 3) this pointer's KeyDetector always allows sliding input.
|
2012-01-25 11:14:39 +00:00
|
|
|
mIsAllowedSlidingKeyInput = sParams.mSlidingKeyInputEnabled
|
2011-12-01 07:26:09 +00:00
|
|
|
|| (key != null && key.isModifier())
|
2011-08-23 03:08:36 +00:00
|
|
|
|| mKeyDetector.alwaysAllowsSlidingInput();
|
2010-12-30 07:51:36 +00:00
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
2013-04-22 08:57:05 +00:00
|
|
|
mIsTrackingForActionDisabled = false;
|
2012-10-06 14:22:36 +00:00
|
|
|
resetSlidingKeyInput();
|
2011-11-29 07:56:27 +00:00
|
|
|
if (key != null) {
|
2010-12-30 07:51:36 +00:00
|
|
|
// This onPress call may have changed keyboard layout. Those cases are detected at
|
2011-11-29 07:56:27 +00:00
|
|
|
// {@link #setKeyboard}. In those cases, we should update key according to the new
|
2010-12-30 07:51:36 +00:00
|
|
|
// keyboard layout.
|
2013-08-13 03:10:26 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, 0 /* repeatCount */)) {
|
2011-11-29 07:56:27 +00:00
|
|
|
key = onDownKey(x, y, eventTime);
|
|
|
|
}
|
2011-04-07 08:16:30 +00:00
|
|
|
|
2011-11-29 07:56:27 +00:00
|
|
|
startRepeatKey(key);
|
|
|
|
startLongPressTimer(key);
|
2012-09-28 06:59:59 +00:00
|
|
|
setPressedKeyGraphics(key, eventTime);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void startSlidingKeyInput(final Key key) {
|
2011-11-29 07:56:27 +00:00
|
|
|
if (!mIsInSlidingKeyInput) {
|
2012-10-06 14:22:36 +00:00
|
|
|
mIsInSlidingKeyInputFromModifier = key.isModifier();
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|
2011-04-07 08:16:30 +00:00
|
|
|
mIsInSlidingKeyInput = true;
|
|
|
|
}
|
|
|
|
|
2012-10-06 14:22:36 +00:00
|
|
|
private void resetSlidingKeyInput() {
|
|
|
|
mIsInSlidingKeyInput = false;
|
|
|
|
mIsInSlidingKeyInputFromModifier = false;
|
2012-12-04 07:04:21 +00:00
|
|
|
mDrawingProxy.dismissSlidingKeyInputPreview();
|
2012-10-06 14:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private void onGestureMoveEvent(final int x, final int y, final long eventTime,
|
2012-09-21 03:15:02 +00:00
|
|
|
final boolean isMajorEvent, final Key key) {
|
2012-08-23 06:01:46 +00:00
|
|
|
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
|
|
|
|
if (mIsDetectingGesture) {
|
2013-01-10 01:34:20 +00:00
|
|
|
final int beforeLength = mGestureStrokeWithPreviewPoints.getLength();
|
2012-11-22 06:39:28 +00:00
|
|
|
final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard(
|
|
|
|
x, y, gestureTime, isMajorEvent);
|
2013-01-10 01:34:20 +00:00
|
|
|
if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) {
|
|
|
|
mTimerProxy.startUpdateBatchInputTimer(this);
|
|
|
|
}
|
2013-01-09 06:26:03 +00:00
|
|
|
// If the move event goes out from valid batch input area, cancel batch input.
|
2012-11-22 06:39:28 +00:00
|
|
|
if (!onValidArea) {
|
2012-12-06 01:49:35 +00:00
|
|
|
cancelBatchInput();
|
2012-11-22 06:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-12-10 20:38:29 +00:00
|
|
|
// 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()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-26 03:46:55 +00:00
|
|
|
mayStartBatchInput(key);
|
2012-09-26 06:49:23 +00:00
|
|
|
if (sInGesture) {
|
|
|
|
mayUpdateBatchInput(eventTime, key);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:48:04 +00:00
|
|
|
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (DEBUG_MOVE_EVENT) {
|
2010-12-18 11:04:44 +00:00
|
|
|
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2013-04-22 08:57:05 +00:00
|
|
|
if (mIsTrackingForActionDisabled) {
|
2010-09-03 08:54:37 +00:00
|
|
|
return;
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sShouldHandleGesture && me != null) {
|
2012-06-12 10:40:37 +00:00
|
|
|
// Add historical points to gesture path.
|
|
|
|
final int pointerIndex = me.findPointerIndex(mPointerId);
|
|
|
|
final int historicalSize = me.getHistorySize();
|
|
|
|
for (int h = 0; h < historicalSize; h++) {
|
|
|
|
final int historicalX = (int)me.getHistoricalX(pointerIndex, h);
|
|
|
|
final int historicalY = (int)me.getHistoricalY(pointerIndex, h);
|
|
|
|
final long historicalTime = me.getHistoricalEventTime(h);
|
2012-08-23 06:01:46 +00:00
|
|
|
onGestureMoveEvent(historicalX, historicalY, historicalTime,
|
2012-09-21 03:15:02 +00:00
|
|
|
false /* isMajorEvent */, null);
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-10 20:38:29 +00:00
|
|
|
|
|
|
|
if (isShowingMoreKeysPanel()) {
|
2013-01-24 07:08:33 +00:00
|
|
|
final int translatedX = mMoreKeysPanel.translateX(x);
|
|
|
|
final int translatedY = mMoreKeysPanel.translateY(y);
|
|
|
|
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
|
|
|
|
onMoveKey(x, y);
|
2013-07-30 09:42:48 +00:00
|
|
|
if (mIsInSlidingKeyInputFromModifier) {
|
|
|
|
mDrawingProxy.showSlidingKeyInputPreview(this);
|
|
|
|
}
|
2012-12-10 20:38:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
onMoveEventInternal(x, y, eventTime);
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:39:33 +00:00
|
|
|
private void processSlidingKeyInput(final Key newKey, final int x, final int y,
|
|
|
|
final long eventTime) {
|
|
|
|
// This onPress call may have changed keyboard layout. Those cases are detected
|
|
|
|
// at {@link #setKeyboard}. In those cases, we should update key according
|
|
|
|
// to the new keyboard layout.
|
|
|
|
Key key = newKey;
|
2013-08-13 03:10:26 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, 0 /* repeatCount */)) {
|
2012-10-31 09:39:33 +00:00
|
|
|
key = onMoveKey(x, y);
|
|
|
|
}
|
|
|
|
onMoveToNewKey(key, x, y);
|
2013-04-22 08:57:05 +00:00
|
|
|
if (mIsTrackingForActionDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-31 09:39:33 +00:00
|
|
|
startLongPressTimer(key);
|
|
|
|
setPressedKeyGraphics(key, eventTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processPhantomSuddenMoveHack(final Key key, final int x, final int y,
|
|
|
|
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
Log.w(TAG, String.format("[%d] onMoveEvent:"
|
|
|
|
+ " phantom sudden move event (distance=%d) is translated to "
|
|
|
|
+ "up[%d,%d,%s]/down[%d,%d,%s] events", mPointerId,
|
|
|
|
getDistance(x, y, lastX, lastY),
|
2013-08-12 09:05:11 +00:00
|
|
|
lastX, lastY, Constants.printableCode(oldKey.getCode()),
|
|
|
|
x, y, Constants.printableCode(key.getCode())));
|
2012-10-31 09:39:33 +00:00
|
|
|
}
|
|
|
|
// TODO: This should be moved to outside of this nested if-clause?
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-10-31 09:39:33 +00:00
|
|
|
ResearchLogger.pointerTracker_onMoveEvent(x, y, lastX, lastY);
|
|
|
|
}
|
2012-12-03 02:47:52 +00:00
|
|
|
onUpEventInternal(x, y, eventTime);
|
2012-10-31 09:39:33 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processProximateBogusDownMoveUpEventHack(final Key key, final int x, final int y,
|
|
|
|
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
final float keyDiagonal = (float)Math.hypot(
|
|
|
|
mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
|
|
|
|
final float radiusRatio =
|
|
|
|
mBogusMoveEventDetector.getDistanceFromDownEvent(x, y)
|
|
|
|
/ keyDiagonal;
|
|
|
|
Log.w(TAG, String.format("[%d] onMoveEvent:"
|
|
|
|
+ " bogus down-move-up event (raidus=%.2f key diagonal) is "
|
|
|
|
+ " translated to up[%d,%d,%s]/down[%d,%d,%s] events",
|
|
|
|
mPointerId, radiusRatio,
|
2013-08-12 09:05:11 +00:00
|
|
|
lastX, lastY, Constants.printableCode(oldKey.getCode()),
|
|
|
|
x, y, Constants.printableCode(key.getCode())));
|
2012-10-31 09:39:33 +00:00
|
|
|
}
|
2012-12-03 02:47:52 +00:00
|
|
|
onUpEventInternal(x, y, eventTime);
|
2012-10-31 09:39:33 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
|
|
|
}
|
|
|
|
|
2012-10-31 10:02:51 +00:00
|
|
|
private void processSildeOutFromOldKey(final Key oldKey) {
|
|
|
|
setReleasedKeyGraphics(oldKey);
|
2013-08-12 09:05:11 +00:00
|
|
|
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
|
2012-10-31 10:02:51 +00:00
|
|
|
startSlidingKeyInput(oldKey);
|
|
|
|
mTimerProxy.cancelKeyTimers();
|
|
|
|
}
|
|
|
|
|
2012-10-31 09:39:33 +00:00
|
|
|
private void slideFromOldKeyToNewKey(final Key key, final int x, final int y,
|
2012-10-31 09:31:48 +00:00
|
|
|
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
|
|
|
|
// The pointer has been slid in to the new key from the previous key, we must call
|
|
|
|
// onRelease() first to notify that the previous key has been released, then call
|
|
|
|
// onPress() to notify that the new key is being pressed.
|
2012-10-31 10:02:51 +00:00
|
|
|
processSildeOutFromOldKey(oldKey);
|
2012-10-31 09:31:48 +00:00
|
|
|
startRepeatKey(key);
|
|
|
|
if (mIsAllowedSlidingKeyInput) {
|
2012-10-31 09:39:33 +00:00
|
|
|
processSlidingKeyInput(key, x, y, eventTime);
|
2012-10-31 10:37:35 +00:00
|
|
|
}
|
|
|
|
// HACK: On some devices, quick successive touches may be reported as a sudden move by
|
|
|
|
// touch panel firmware. This hack detects such cases and translates the move event to
|
|
|
|
// successive up and down events.
|
|
|
|
// TODO: Should find a way to balance gesture detection and this hack.
|
|
|
|
else if (sNeedsPhantomSuddenMoveEventHack
|
|
|
|
&& getDistance(x, y, lastX, lastY) >= mPhantonSuddenMoveThreshold) {
|
|
|
|
processPhantomSuddenMoveHack(key, x, y, eventTime, oldKey, lastX, lastY);
|
|
|
|
}
|
|
|
|
// 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)
|
|
|
|
&& mBogusMoveEventDetector.isCloseToActualDownEvent(x, y)) {
|
|
|
|
processProximateBogusDownMoveUpEventHack(key, x, y, eventTime, oldKey, lastX, lastY);
|
|
|
|
}
|
|
|
|
// HACK: If there are currently multiple touches, register the key even if the finger
|
|
|
|
// slides off the key. This defends against noise from some touch panels when there are
|
|
|
|
// close multiple touches.
|
|
|
|
// Caveat: When in chording input mode with a modifier key, we don't use this hack.
|
2012-11-01 04:24:18 +00:00
|
|
|
else if (getActivePointerTrackerCount() > 1
|
2012-10-31 10:37:35 +00:00
|
|
|
&& !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
Log.w(TAG, String.format("[%d] onMoveEvent:"
|
|
|
|
+ " detected sliding finger while multi touching", mPointerId));
|
2012-10-31 09:39:33 +00:00
|
|
|
}
|
2012-10-31 10:37:35 +00:00
|
|
|
onUpEvent(x, y, eventTime);
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2012-10-31 10:37:35 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
|
|
|
} else {
|
|
|
|
if (!mIsDetectingGesture) {
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2012-10-31 09:31:48 +00:00
|
|
|
}
|
2012-10-31 10:37:35 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
2012-10-31 09:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void slideOutFromOldKey(final Key oldKey, final int x, final int y) {
|
|
|
|
// The pointer has been slid out from the previous key, we must call onRelease() to
|
|
|
|
// notify that the previous key has been released.
|
2012-10-31 10:02:51 +00:00
|
|
|
processSildeOutFromOldKey(oldKey);
|
2012-10-31 09:31:48 +00:00
|
|
|
if (mIsAllowedSlidingKeyInput) {
|
|
|
|
onMoveToNewKey(null, x, y);
|
|
|
|
} else {
|
|
|
|
if (!mIsDetectingGesture) {
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2012-10-31 09:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private void onMoveEventInternal(final int x, final int y, final long eventTime) {
|
2011-07-08 23:19:19 +00:00
|
|
|
final int lastX = mLastX;
|
|
|
|
final int lastY = mLastY;
|
2011-11-29 07:56:27 +00:00
|
|
|
final Key oldKey = mCurrentKey;
|
2012-10-31 09:31:48 +00:00
|
|
|
final Key newKey = onMoveKey(x, y);
|
2012-06-12 10:40:37 +00:00
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sShouldHandleGesture) {
|
|
|
|
// Register move event on gesture tracker.
|
2012-10-31 09:31:48 +00:00
|
|
|
onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, newKey);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sInGesture) {
|
|
|
|
mCurrentKey = null;
|
|
|
|
setReleasedKeyGraphics(oldKey);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 09:31:48 +00:00
|
|
|
if (newKey != null) {
|
2012-10-31 09:39:33 +00:00
|
|
|
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
|
2012-10-31 09:31:48 +00:00
|
|
|
slideFromOldKeyToNewKey(newKey, x, y, eventTime, oldKey, lastX, lastY);
|
2012-10-31 09:39:33 +00:00
|
|
|
} else if (oldKey == null) {
|
2012-10-31 10:02:51 +00:00
|
|
|
// The pointer has been slid in to the new key, but the finger was not on any keys.
|
|
|
|
// In this case, we must call onPress() to notify that the new key is being pressed.
|
|
|
|
processSlidingKeyInput(newKey, x, y, eventTime);
|
2011-04-22 02:09:48 +00:00
|
|
|
}
|
2012-10-31 10:02:51 +00:00
|
|
|
} else { // newKey == null
|
2012-10-31 09:31:48 +00:00
|
|
|
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
|
|
|
|
slideOutFromOldKey(oldKey, x, y);
|
2010-09-02 15:48:16 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2013-07-30 09:42:48 +00:00
|
|
|
if (mIsInSlidingKeyInputFromModifier) {
|
|
|
|
mDrawingProxy.showSlidingKeyInputPreview(this);
|
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 08:48:04 +00:00
|
|
|
private void onUpEvent(final int x, final int y, final long eventTime) {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2010-12-18 11:04:44 +00:00
|
|
|
printTouchEvent("onUpEvent :", x, y, eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
|
2013-01-09 03:56:55 +00:00
|
|
|
mTimerProxy.cancelUpdateBatchInputTimer(this);
|
2012-11-01 04:24:18 +00:00
|
|
|
if (!sInGesture) {
|
|
|
|
if (mCurrentKey != null && mCurrentKey.isModifier()) {
|
|
|
|
// Before processing an up event of modifier key, all pointers already being
|
|
|
|
// tracked should be released.
|
|
|
|
sPointerTrackerQueue.releaseAllPointersExcept(this, eventTime);
|
|
|
|
} else {
|
|
|
|
sPointerTrackerQueue.releaseAllPointersOlderThan(this, eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-03 02:47:52 +00:00
|
|
|
onUpEventInternal(x, y, eventTime);
|
2012-11-01 04:24:18 +00:00
|
|
|
sPointerTrackerQueue.remove(this);
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 06:18:20 +00:00
|
|
|
// Let this pointer tracker know that one of newer-than-this pointer trackers got an up event.
|
|
|
|
// This pointer tracker needs to keep the key top graphics "pressed", but needs to get a
|
|
|
|
// "virtual" up event.
|
2012-08-07 05:45:06 +00:00
|
|
|
@Override
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onPhantomUpEvent(final long eventTime) {
|
|
|
|
if (DEBUG_EVENT) {
|
2012-11-28 06:24:13 +00:00
|
|
|
printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2012-12-03 02:47:52 +00:00
|
|
|
if (isShowingMoreKeysPanel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onUpEventInternal(mLastX, mLastY, eventTime);
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 02:47:52 +00:00
|
|
|
private void onUpEventInternal(final int x, final int y, final long eventTime) {
|
2011-07-09 01:35:58 +00:00
|
|
|
mTimerProxy.cancelKeyTimers();
|
2013-05-13 08:19:21 +00:00
|
|
|
final boolean isInSlidingKeyInput = mIsInSlidingKeyInput;
|
2013-05-14 03:25:21 +00:00
|
|
|
final boolean isInSlidingKeyInputFromModifier = mIsInSlidingKeyInputFromModifier;
|
2012-10-06 14:22:36 +00:00
|
|
|
resetSlidingKeyInput();
|
2012-08-23 06:01:46 +00:00
|
|
|
mIsDetectingGesture = false;
|
|
|
|
final Key currentKey = mCurrentKey;
|
|
|
|
mCurrentKey = null;
|
2012-05-09 09:49:03 +00:00
|
|
|
// Release the last pressed key.
|
2012-08-23 06:01:46 +00:00
|
|
|
setReleasedKeyGraphics(currentKey);
|
2012-12-03 02:47:52 +00:00
|
|
|
|
|
|
|
if (isShowingMoreKeysPanel()) {
|
2013-04-22 08:57:05 +00:00
|
|
|
if (!mIsTrackingForActionDisabled) {
|
2012-12-03 02:47:52 +00:00
|
|
|
final int translatedX = mMoreKeysPanel.translateX(x);
|
|
|
|
final int translatedY = mMoreKeysPanel.translateY(y);
|
|
|
|
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
|
|
|
|
}
|
|
|
|
mMoreKeysPanel.dismissMoreKeysPanel();
|
|
|
|
mMoreKeysPanel = null;
|
|
|
|
return;
|
2011-07-23 08:16:56 +00:00
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sInGesture) {
|
|
|
|
if (currentKey != null) {
|
2013-08-12 09:05:11 +00:00
|
|
|
callListenerOnRelease(currentKey, currentKey.getCode(), true /* withSliding */);
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
2012-09-28 06:59:59 +00:00
|
|
|
mayEndBatchInput(eventTime);
|
2012-06-12 10:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-27 10:01:17 +00:00
|
|
|
|
2013-04-22 08:57:05 +00:00
|
|
|
if (mIsTrackingForActionDisabled) {
|
2011-04-18 10:07:20 +00:00
|
|
|
return;
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2013-05-13 08:19:21 +00:00
|
|
|
if (currentKey != null && currentKey.isRepeatable() && !isInSlidingKeyInput) {
|
|
|
|
// Repeatable key has been registered in {@link #onDownEventInternal(int,int,long)}.
|
|
|
|
return;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2013-05-13 08:19:21 +00:00
|
|
|
detectAndSendKey(currentKey, mKeyX, mKeyY, eventTime);
|
2013-05-14 03:25:21 +00:00
|
|
|
if (isInSlidingKeyInputFromModifier) {
|
|
|
|
callListenerOnFinishSlidingInput();
|
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 07:55:55 +00:00
|
|
|
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
2012-12-03 02:47:52 +00:00
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
2013-08-01 07:55:55 +00:00
|
|
|
final int translatedX = panel.translateX(mLastX);
|
|
|
|
final int translatedY = panel.translateY(mLastY);
|
|
|
|
panel.onDownEvent(translatedX, translatedY, mPointerId, SystemClock.uptimeMillis());
|
2012-12-03 02:47:52 +00:00
|
|
|
mMoreKeysPanel = panel;
|
2011-07-23 08:16:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 06:39:28 +00:00
|
|
|
@Override
|
2013-04-22 08:57:05 +00:00
|
|
|
public void cancelTrackingForAction() {
|
2013-01-09 06:26:03 +00:00
|
|
|
if (isShowingMoreKeysPanel()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-22 08:57:05 +00:00
|
|
|
mIsTrackingForActionDisabled = true;
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onLongPressed() {
|
2012-11-28 06:24:13 +00:00
|
|
|
resetSlidingKeyInput();
|
2013-04-22 08:57:05 +00:00
|
|
|
cancelTrackingForAction();
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
2012-11-01 04:24:18 +00:00
|
|
|
sPointerTrackerQueue.remove(this);
|
2011-04-18 10:07:20 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 08:48:04 +00:00
|
|
|
private void onCancelEvent(final int x, final int y, final long eventTime) {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2010-12-18 11:04:44 +00:00
|
|
|
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
|
2012-12-21 05:14:09 +00:00
|
|
|
cancelBatchInput();
|
2013-07-25 10:00:45 +00:00
|
|
|
cancelAllPointerTrackers();
|
2012-12-06 01:49:35 +00:00
|
|
|
sPointerTrackerQueue.releaseAllPointers(eventTime);
|
2010-12-17 05:13:01 +00:00
|
|
|
onCancelEventInternal();
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 05:13:01 +00:00
|
|
|
private void onCancelEventInternal() {
|
2011-07-09 01:35:58 +00:00
|
|
|
mTimerProxy.cancelKeyTimers();
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
2012-10-06 14:22:36 +00:00
|
|
|
resetSlidingKeyInput();
|
2012-12-10 20:38:29 +00:00
|
|
|
if (isShowingMoreKeysPanel()) {
|
|
|
|
mMoreKeysPanel.dismissMoreKeysPanel();
|
|
|
|
mMoreKeysPanel = null;
|
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 09:37:46 +00:00
|
|
|
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,
|
|
|
|
final Key newKey) {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (mKeyDetector == null) {
|
2011-07-04 10:59:57 +00:00
|
|
|
throw new NullPointerException("keyboard and/or key detector not set");
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
|
|
|
final Key curKey = mCurrentKey;
|
2010-08-31 15:27:04 +00:00
|
|
|
if (newKey == curKey) {
|
2011-04-21 03:22:00 +00:00
|
|
|
return false;
|
2012-10-31 09:57:10 +00:00
|
|
|
}
|
|
|
|
if (curKey == null /* && newKey != null */) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Here curKey points to the different key from newKey.
|
|
|
|
final int keyHysteresisDistanceSquared = mKeyDetector.getKeyHysteresisDistanceSquared(
|
|
|
|
mIsInSlidingKeyInputFromModifier);
|
|
|
|
final int distanceFromKeyEdgeSquared = curKey.squaredDistanceToEdge(x, y);
|
|
|
|
if (distanceFromKeyEdgeSquared >= keyHysteresisDistanceSquared) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
final float distanceToEdgeRatio = (float)Math.sqrt(distanceFromKeyEdgeSquared)
|
|
|
|
/ mKeyboard.mMostCommonKeyWidth;
|
|
|
|
Log.d(TAG, String.format("[%d] isMajorEnoughMoveToBeOnNewKey:"
|
|
|
|
+" %.2f key width from key edge", mPointerId, distanceToEdgeRatio));
|
2012-10-10 09:37:46 +00:00
|
|
|
}
|
2012-10-31 09:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sNeedsProximateBogusDownMoveUpEventHack && !mIsAllowedSlidingKeyInput
|
|
|
|
&& sTimeRecorder.isInFastTyping(eventTime)
|
|
|
|
&& mBogusMoveEventDetector.hasTraveledLongDistance(x, y)) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
final float keyDiagonal = (float)Math.hypot(
|
|
|
|
mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
|
|
|
|
final float lengthFromDownRatio =
|
|
|
|
mBogusMoveEventDetector.mAccumulatedDistanceFromDownKey / keyDiagonal;
|
|
|
|
Log.d(TAG, String.format("[%d] isMajorEnoughMoveToBeOnNewKey:"
|
|
|
|
+ " %.2f key diagonal from virtual down point",
|
|
|
|
mPointerId, lengthFromDownRatio));
|
2012-10-10 09:37:46 +00:00
|
|
|
}
|
2011-04-21 03:22:00 +00:00
|
|
|
return true;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2012-10-31 09:57:10 +00:00
|
|
|
return false;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void startLongPressTimer(final Key key) {
|
2013-05-13 06:05:37 +00:00
|
|
|
if (sInGesture) return;
|
|
|
|
if (key == null) return;
|
|
|
|
if (!key.isLongPressEnabled()) return;
|
|
|
|
// Caveat: Please note that isLongPressEnabled() can be true even if the current key
|
|
|
|
// doesn't have its more keys. (e.g. spacebar, globe key)
|
|
|
|
// 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.
|
2013-08-12 09:05:11 +00:00
|
|
|
if (mIsInSlidingKeyInput && key.getMoreKeys() == null) return;
|
2013-07-30 09:42:48 +00:00
|
|
|
final int delay;
|
2013-08-12 09:05:11 +00:00
|
|
|
switch (key.getCode()) {
|
2013-07-30 09:42:48 +00:00
|
|
|
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);
|
2010-10-02 06:17:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 05:37:22 +00:00
|
|
|
private void detectAndSendKey(final Key key, final int x, final int y, final long eventTime) {
|
2010-09-07 06:37:59 +00:00
|
|
|
if (key == null) {
|
2010-12-20 07:13:57 +00:00
|
|
|
callListenerOnCancelInput();
|
2010-12-18 11:04:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-02 06:17:27 +00:00
|
|
|
|
2013-08-12 09:05:11 +00:00
|
|
|
final int code = key.getCode();
|
2012-10-05 05:37:22 +00:00
|
|
|
callListenerOnCodeInput(key, code, x, y, eventTime);
|
2013-05-14 03:25:21 +00:00
|
|
|
callListenerOnRelease(key, code, false /* withSliding */);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 06:17:54 +00:00
|
|
|
private void startRepeatKey(final Key key) {
|
|
|
|
if (sInGesture) return;
|
|
|
|
if (key == null) return;
|
|
|
|
if (!key.isRepeatable()) return;
|
|
|
|
// Don't start key repeat when we are in sliding input mode.
|
|
|
|
if (mIsInSlidingKeyInput) return;
|
2013-08-12 09:05:11 +00:00
|
|
|
detectAndSendKey(key, key.getX(), key.getY(), SystemClock.uptimeMillis());
|
2013-08-13 03:10:26 +00:00
|
|
|
final int startRepeatCount = 1;
|
|
|
|
mTimerProxy.startKeyRepeatTimer(this, startRepeatCount, sParams.mKeyRepeatStartTimeout);
|
2013-08-01 06:17:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 03:10:26 +00:00
|
|
|
public void onKeyRepeat(final int code, final int repeatCount) {
|
2013-08-01 06:17:54 +00:00
|
|
|
final Key key = getKey();
|
2013-08-12 09:05:11 +00:00
|
|
|
if (key == null || key.getCode() != code) {
|
2013-08-01 06:17:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-13 03:10:26 +00:00
|
|
|
final int nextRepeatCount = repeatCount + 1;
|
|
|
|
mTimerProxy.startKeyRepeatTimer(this, nextRepeatCount, sParams.mKeyRepeatInterval);
|
|
|
|
callListenerOnPressAndCheckKeyboardLayoutChange(key, repeatCount);
|
2013-08-01 06:17:54 +00:00
|
|
|
callListenerOnCodeInput(key, code, mKeyX, mKeyY, SystemClock.uptimeMillis());
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void printTouchEvent(final String title, final int x, final int y,
|
|
|
|
final long eventTime) {
|
2012-03-15 10:44:43 +00:00
|
|
|
final Key key = mKeyDetector.detectHitKey(x, y);
|
2011-12-01 07:34:23 +00:00
|
|
|
final String code = KeyDetector.printableCode(key);
|
2012-09-27 10:01:17 +00:00
|
|
|
Log.d(TAG, String.format("[%d]%s%s %4d %4d %5d %s", mPointerId,
|
2013-04-22 08:57:05 +00:00
|
|
|
(mIsTrackingForActionDisabled ? "-" : " "), title, x, y, eventTime, code));
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
2010-09-24 11:45:24 +00:00
|
|
|
}
|