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
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
package com.android.inputmethod.keyboard;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
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;
|
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-08-20 03:57:34 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewTrail;
|
2011-06-22 02:53:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
|
2012-08-21 07:34:55 +00:00
|
|
|
import com.android.inputmethod.latin.CollectionUtils;
|
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;
|
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-08-07 05:30:28 +00:00
|
|
|
public 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;
|
2011-01-28 03:40:27 +00:00
|
|
|
private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
|
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
|
|
|
|
2012-07-19 05:47:55 +00:00
|
|
|
private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
|
2012-07-18 08:56:30 +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.
|
|
|
|
* @return the KeyboardActionListner for this PointerTracker
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-08-31 06:26:32 +00:00
|
|
|
public interface DrawingProxy extends MoreKeysPanel.Controller {
|
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-08-23 06:01:46 +00:00
|
|
|
public void showGesturePreviewTrail(PointerTracker tracker);
|
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();
|
2012-02-01 06:07:25 +00:00
|
|
|
public void startKeyRepeatTimer(PointerTracker tracker);
|
|
|
|
public void startLongPressTimer(PointerTracker tracker);
|
|
|
|
public void startLongPressTimer(int code);
|
2011-07-17 21:37:30 +00:00
|
|
|
public void cancelLongPressTimer();
|
2012-01-31 06:54:48 +00:00
|
|
|
public void startDoubleTapTimer();
|
2012-02-16 19:45:35 +00:00
|
|
|
public void cancelDoubleTapTimer();
|
2012-01-31 06:54:48 +00:00
|
|
|
public boolean isInDoubleTapTimeout();
|
2011-07-09 01:35:58 +00:00
|
|
|
public void cancelKeyTimers();
|
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
|
2012-02-01 06:07:25 +00:00
|
|
|
public void startKeyRepeatTimer(PointerTracker tracker) {}
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2012-02-01 06:07:25 +00:00
|
|
|
public void startLongPressTimer(PointerTracker tracker) {}
|
|
|
|
@Override
|
|
|
|
public void startLongPressTimer(int code) {}
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
|
|
|
public void cancelLongPressTimer() {}
|
|
|
|
@Override
|
2012-01-31 06:54:48 +00:00
|
|
|
public void startDoubleTapTimer() {}
|
|
|
|
@Override
|
2012-02-16 19:45:35 +00:00
|
|
|
public void cancelDoubleTapTimer() {}
|
|
|
|
@Override
|
2012-01-31 06:54:48 +00:00
|
|
|
public boolean isInDoubleTapTimeout() { return false; }
|
|
|
|
@Override
|
2011-08-24 05:44:46 +00:00
|
|
|
public void cancelKeyTimers() {}
|
|
|
|
}
|
2011-07-09 01:35:58 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 05:28:15 +00:00
|
|
|
static class PointerTrackerParams {
|
|
|
|
public final boolean mSlidingKeyInputEnabled;
|
|
|
|
public final int mTouchNoiseThresholdTime;
|
|
|
|
public final float mTouchNoiseThresholdDistance;
|
|
|
|
public final int mTouchNoiseThresholdDistanceSquared;
|
|
|
|
|
|
|
|
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
|
|
|
|
|
|
|
|
private PointerTrackerParams() {
|
|
|
|
mSlidingKeyInputEnabled = false;
|
|
|
|
mTouchNoiseThresholdTime = 0;
|
|
|
|
mTouchNoiseThresholdDistance = 0.0f;
|
|
|
|
mTouchNoiseThresholdDistanceSquared = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerTrackerParams(TypedArray mainKeyboardViewAttr) {
|
|
|
|
mSlidingKeyInputEnabled = mainKeyboardViewAttr.getBoolean(
|
|
|
|
R.styleable.MainKeyboardView_slidingKeyInputEnable, false);
|
|
|
|
mTouchNoiseThresholdTime = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_touchNoiseThresholdTime, 0);
|
|
|
|
final float touchNouseThresholdDistance = mainKeyboardViewAttr.getDimension(
|
|
|
|
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
|
|
|
|
mTouchNoiseThresholdDistance = touchNouseThresholdDistance;
|
|
|
|
mTouchNoiseThresholdDistanceSquared =
|
|
|
|
(int)(touchNouseThresholdDistance * touchNouseThresholdDistance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-05-30 10:29:57 +00:00
|
|
|
private static boolean sNeedsPhantomSuddenMoveEventHack;
|
2011-07-11 22:24:01 +00:00
|
|
|
|
2012-08-21 07:34:55 +00:00
|
|
|
private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList();
|
2011-07-11 22:24:01 +00:00
|
|
|
private static PointerTrackerQueue sPointerTrackerQueue;
|
|
|
|
|
|
|
|
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;
|
2010-12-18 11:04:44 +00:00
|
|
|
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
private Keyboard mKeyboard;
|
2011-01-28 03:40:27 +00:00
|
|
|
private int mKeyQuarterWidthSquared;
|
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;
|
|
|
|
private static final InputPointers sAggregratedPointers = new InputPointers(
|
|
|
|
GestureStroke.DEFAULT_CAPACITY);
|
|
|
|
private static int sLastRecognitionPointSize = 0;
|
|
|
|
private static long sLastRecognitionTime = 0;
|
2012-07-18 08:56:30 +00:00
|
|
|
|
2011-07-08 23:19:19 +00:00
|
|
|
// The position and time at which first down event occurred.
|
|
|
|
private long mDownTime;
|
|
|
|
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;
|
|
|
|
|
2011-07-23 08:16:56 +00:00
|
|
|
// true if event is already translated to a key action.
|
2010-09-03 03:51:03 +00:00
|
|
|
private boolean mKeyAlreadyProcessed;
|
|
|
|
|
2011-08-31 06:26:32 +00:00
|
|
|
// true if this pointer has been long-pressed and is showing a more keys panel.
|
|
|
|
private boolean mIsShowingMoreKeysPanel;
|
2011-07-23 08:16:56 +00:00
|
|
|
|
2010-12-20 07:21:54 +00:00
|
|
|
// true if this pointer is in sliding key input
|
2011-07-11 22:24:01 +00:00
|
|
|
boolean mIsInSlidingKeyInput;
|
2010-12-20 07:21:54 +00:00
|
|
|
|
2010-12-18 09:48:32 +00:00
|
|
|
// true if sliding key is allowed.
|
|
|
|
private boolean mIsAllowedSlidingKeyInput;
|
|
|
|
|
2011-04-07 08:16:30 +00:00
|
|
|
// ignore modifier key if true
|
|
|
|
private boolean mIgnoreModifierKey;
|
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
// Empty {@link KeyboardActionListener}
|
2011-08-29 10:09:56 +00:00
|
|
|
private static final KeyboardActionListener EMPTY_LISTENER =
|
|
|
|
new KeyboardActionListener.Adapter();
|
2010-09-24 11:45:24 +00:00
|
|
|
|
2012-08-20 03:57:34 +00:00
|
|
|
private final GestureStrokeWithPreviewTrail mGestureStrokeWithPreviewTrail;
|
2012-07-18 05:27:51 +00:00
|
|
|
|
2012-05-30 10:29:57 +00:00
|
|
|
public static void init(boolean hasDistinctMultitouch,
|
2012-07-20 08:49:06 +00:00
|
|
|
boolean needsPhantomSuddenMoveEventHack) {
|
2011-07-11 22:24:01 +00:00
|
|
|
if (hasDistinctMultitouch) {
|
|
|
|
sPointerTrackerQueue = new PointerTrackerQueue();
|
|
|
|
} else {
|
|
|
|
sPointerTrackerQueue = null;
|
|
|
|
}
|
2012-05-30 10:29:57 +00:00
|
|
|
sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack;
|
2012-08-23 05:28:15 +00:00
|
|
|
sParams = PointerTrackerParams.DEFAULT;
|
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);
|
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() {
|
|
|
|
return sPointerTrackerQueue != null ? sPointerTrackerQueue.isAnyInSlidingKeyInput() : false;
|
|
|
|
}
|
|
|
|
|
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-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-08-20 03:57:34 +00:00
|
|
|
mGestureStrokeWithPreviewTrail = new GestureStrokeWithPreviewTrail(id);
|
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.
|
2012-08-23 06:14:46 +00:00
|
|
|
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key) {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sInGesture) {
|
2012-06-12 10:40:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
|
2011-12-01 07:34:23 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2011-12-12 04:08:41 +00:00
|
|
|
Log.d(TAG, "onPress : " + KeyDetector.printableCode(key)
|
2012-01-17 08:08:26 +00:00
|
|
|
+ " ignoreModifier=" + ignoreModifierKey
|
2011-12-01 07:34:23 +00:00
|
|
|
+ " enabled=" + key.isEnabled());
|
|
|
|
}
|
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()) {
|
2012-01-17 08:08:26 +00:00
|
|
|
mListener.onPressKey(key.mCode);
|
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,
|
|
|
|
final int y) {
|
2011-11-29 07:56:27 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && 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-08-28 08:19:49 +00:00
|
|
|
Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code)
|
|
|
|
+ " text=" + key.getOutputText() + " x=" + x + " y=" + y
|
2012-03-14 10:49:13 +00:00
|
|
|
+ " ignoreModifier=" + ignoreModifierKey + " altersCode=" + altersCode
|
2011-12-01 07:34:23 +00:00
|
|
|
+ " enabled=" + key.isEnabled());
|
2011-11-30 08:54:58 +00:00
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
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-01-10 08:24:00 +00:00
|
|
|
if (code == Keyboard.CODE_OUTPUT_TEXT) {
|
2012-08-28 08:19:49 +00:00
|
|
|
mListener.onTextInput(key.getOutputText());
|
2012-01-10 08:24:00 +00:00
|
|
|
} else if (code != Keyboard.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
|
|
|
}
|
|
|
|
|
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 callListenerOnRelease(final Key key, final int primaryCode,
|
|
|
|
final boolean withSliding) {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sInGesture) {
|
2012-06-12 10:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
|
2011-12-01 07:34:23 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2011-12-12 04:08:41 +00:00
|
|
|
Log.d(TAG, "onRelease : " + Keyboard.printableCode(primaryCode)
|
2011-12-01 07:34:23 +00:00
|
|
|
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
|
|
|
|
+ " enabled="+ key.isEnabled());
|
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-12-20 07:13:57 +00:00
|
|
|
private void callListenerOnCancelInput() {
|
2012-08-23 06:14:46 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
2010-12-20 07:13:57 +00:00
|
|
|
Log.d(TAG, "onCancelInput");
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
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) {
|
2011-07-04 10:59:57 +00:00
|
|
|
mKeyDetector = keyDetector;
|
2011-07-08 05:31:29 +00:00
|
|
|
mKeyboard = keyDetector.getKeyboard();
|
2012-08-20 03:57:34 +00:00
|
|
|
mGestureStrokeWithPreviewTrail.setGestureSampleLength(mKeyboard.mMostCommonKeyWidth);
|
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
|
|
|
}
|
2011-07-29 00:05:40 +00:00
|
|
|
final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
|
2011-01-28 03:40:27 +00:00
|
|
|
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
|
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-08-23 06:14:46 +00:00
|
|
|
private void setPressedKeyGraphics(final Key key) {
|
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-08-23 06:01:46 +00:00
|
|
|
if (!key.noKeyPreview() && !sInGesture) {
|
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-08-20 03:57:34 +00:00
|
|
|
public GestureStrokeWithPreviewTrail getGestureStrokeWithPreviewTrail() {
|
|
|
|
return mGestureStrokeWithPreviewTrail;
|
2012-07-20 12:01:44 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 23:19:19 +00:00
|
|
|
public int getLastX() {
|
|
|
|
return mLastX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLastY() {
|
|
|
|
return mLastY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDownTime() {
|
|
|
|
return mDownTime;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
return onMoveToNewKey(onMoveKeyInternal(x, y), x, y);
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private Key onMoveKeyInternal(final int x, final int y) {
|
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() {
|
|
|
|
return (sPointerTrackerQueue == null) ? 1 : sPointerTrackerQueue.size();
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:56:30 +00:00
|
|
|
private void startBatchInput() {
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, "onStartBatchInput");
|
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
sInGesture = true;
|
2012-07-18 08:56:30 +00:00
|
|
|
mListener.onStartBatchInput();
|
2012-08-23 06:01:46 +00:00
|
|
|
mDrawingProxy.showGesturePreviewTrail(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBatchInput(final long eventTime) {
|
|
|
|
synchronized (sAggregratedPointers) {
|
|
|
|
mGestureStrokeWithPreviewTrail.appendIncrementalBatchPoints(sAggregratedPointers);
|
|
|
|
final int size = sAggregratedPointers.getPointerSize();
|
|
|
|
if (size > sLastRecognitionPointSize
|
|
|
|
&& eventTime > sLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) {
|
|
|
|
sLastRecognitionPointSize = size;
|
|
|
|
sLastRecognitionTime = eventTime;
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, "onUpdateBatchInput: batchPoints=" + size);
|
|
|
|
}
|
|
|
|
mListener.onUpdateBatchInput(sAggregratedPointers);
|
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
mDrawingProxy.showGesturePreviewTrail(this);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private void endBatchInput() {
|
|
|
|
synchronized (sAggregratedPointers) {
|
|
|
|
mGestureStrokeWithPreviewTrail.appendAllBatchPoints(sAggregratedPointers);
|
2012-09-07 04:25:34 +00:00
|
|
|
mGestureStrokeWithPreviewTrail.reset();
|
2012-08-23 06:01:46 +00:00
|
|
|
if (getActivePointerTrackerCount() == 1) {
|
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, "onEndBatchInput: batchPoints="
|
|
|
|
+ sAggregratedPointers.getPointerSize());
|
|
|
|
}
|
|
|
|
sInGesture = false;
|
|
|
|
mListener.onEndBatchInput(sAggregratedPointers);
|
|
|
|
clearBatchInputPointsOfAllPointerTrackers();
|
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
mDrawingProxy.showGesturePreviewTrail(this);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private static void abortBatchInput() {
|
2012-07-19 05:47:55 +00:00
|
|
|
clearBatchInputPointsOfAllPointerTrackers();
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private static void clearBatchInputPointsOfAllPointerTrackers() {
|
|
|
|
final int trackersSize = sTrackers.size();
|
|
|
|
for (int i = 0; i < trackersSize; ++i) {
|
|
|
|
final PointerTracker tracker = sTrackers.get(i);
|
|
|
|
tracker.mGestureStrokeWithPreviewTrail.reset();
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
sAggregratedPointers.reset();
|
|
|
|
sLastRecognitionPointSize = 0;
|
|
|
|
sLastRecognitionTime = 0;
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void processMotionEvent(final int action, final int x, final int y, final long eventTime,
|
|
|
|
final KeyEventHandler handler) {
|
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_MOVE:
|
2012-06-26 08:34:04 +00:00
|
|
|
onMoveEvent(x, y, eventTime, null);
|
2011-09-06 06:25:58 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
|
|
|
onCancelEvent(x, y, eventTime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onDownEvent(final int x, final int y, final long eventTime,
|
|
|
|
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
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
|
2011-07-11 02:31:02 +00:00
|
|
|
mDrawingProxy = handler.getDrawingProxy();
|
2011-07-11 01:09:15 +00:00
|
|
|
mTimerProxy = handler.getTimerProxy();
|
2011-07-11 02:31:02 +00:00
|
|
|
setKeyboardActionListener(handler.getKeyboardActionListener());
|
|
|
|
setKeyDetectorInner(handler.getKeyDetector());
|
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) {
|
2011-07-08 23:19:19 +00:00
|
|
|
final int dx = x - mLastX;
|
|
|
|
final int dy = y - mLastY;
|
2010-12-17 05:13:01 +00:00
|
|
|
final int distanceSquared = (dx * dx + dy * dy);
|
2012-08-23 05:28:15 +00:00
|
|
|
if (distanceSquared < sParams.mTouchNoiseThresholdDistanceSquared) {
|
2011-01-28 03:40:27 +00:00
|
|
|
if (DEBUG_MODE)
|
|
|
|
Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
|
|
|
|
+ " distance=" + distanceSquared);
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.pointerTracker_onDownEvent(deltaT, distanceSquared);
|
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2010-12-17 05:13:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 10:40:37 +00:00
|
|
|
final Key key = getKeyOn(x, y);
|
2012-08-23 06:01:46 +00:00
|
|
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
2010-12-21 05:01:13 +00:00
|
|
|
if (queue != null) {
|
2011-11-29 07:56:27 +00:00
|
|
|
if (key != null && key.isModifier()) {
|
2010-12-21 05:01:13 +00:00
|
|
|
// Before processing a down event of modifier key, all pointers already being
|
|
|
|
// tracked should be released.
|
|
|
|
queue.releaseAllPointers(eventTime);
|
|
|
|
}
|
|
|
|
queue.add(this);
|
|
|
|
}
|
|
|
|
onDownEventInternal(x, y, eventTime);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!sShouldHandleGesture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final int activePointerTrackerCount = getActivePointerTrackerCount();
|
|
|
|
if (activePointerTrackerCount == 1) {
|
|
|
|
mIsDetectingGesture = false;
|
2012-07-18 08:56:30 +00:00
|
|
|
// A gesture should start only from the letter key.
|
2012-08-23 06:01:46 +00:00
|
|
|
final boolean isAlphabetKeyboard = (mKeyboard != null)
|
|
|
|
&& mKeyboard.mId.isAlphabetKeyboard();
|
|
|
|
if (isAlphabetKeyboard && !mIsShowingMoreKeysPanel && key != null
|
|
|
|
&& Keyboard.isLetterCode(key.mCode)) {
|
|
|
|
mIsDetectingGesture = true;
|
|
|
|
sGestureFirstDownTime = eventTime;
|
|
|
|
mGestureStrokeWithPreviewTrail.addPoint(x, y, 0, false /* isHistorical */);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
} else if (sInGesture && activePointerTrackerCount > 1) {
|
|
|
|
mIsDetectingGesture = true;
|
|
|
|
final int elapsedTimeFromFirstDown = (int)(eventTime - sGestureFirstDownTime);
|
|
|
|
mGestureStrokeWithPreviewTrail.addPoint(x, y, elapsedTimeFromFirstDown,
|
|
|
|
false /* isHistorical */);
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2010-09-03 03:51:03 +00:00
|
|
|
mKeyAlreadyProcessed = false;
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2011-04-07 08:16:30 +00:00
|
|
|
mIgnoreModifierKey = false;
|
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.
|
2012-01-17 08:08:26 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
|
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);
|
|
|
|
setPressedKeyGraphics(key);
|
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) {
|
|
|
|
mIgnoreModifierKey = key.isModifier();
|
|
|
|
}
|
2011-04-07 08:16:30 +00:00
|
|
|
mIsInSlidingKeyInput = true;
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
private void onGestureMoveEvent(final int x, final int y, final long eventTime,
|
|
|
|
final boolean isHistorical, final Key key) {
|
|
|
|
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
|
|
|
|
if (mIsDetectingGesture) {
|
2012-08-20 03:57:34 +00:00
|
|
|
final GestureStroke stroke = mGestureStrokeWithPreviewTrail;
|
2012-07-18 08:56:30 +00:00
|
|
|
stroke.addPoint(x, y, gestureTime, isHistorical);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!sInGesture && stroke.isStartOfAGesture()) {
|
2012-07-18 08:56:30 +00:00
|
|
|
startBatchInput();
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
if (sInGesture && key != null) {
|
|
|
|
updateBatchInput(eventTime);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
|
|
|
|
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
|
|
|
}
|
|
|
|
if (mKeyAlreadyProcessed) {
|
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-06-12 10:40:37 +00:00
|
|
|
true /* isHistorical */, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:01:46 +00:00
|
|
|
onMoveEventInternal(x, y, eventTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
Key key = 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.
|
|
|
|
onGestureMoveEvent(x, y, eventTime, false /* isHistorical */, key);
|
|
|
|
if (sInGesture) {
|
|
|
|
mIgnoreModifierKey = true;
|
|
|
|
mTimerProxy.cancelLongPressTimer();
|
|
|
|
mIsInSlidingKeyInput = true;
|
|
|
|
mCurrentKey = null;
|
|
|
|
setReleasedKeyGraphics(oldKey);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:56:27 +00:00
|
|
|
if (key != null) {
|
2010-11-09 19:57:41 +00:00
|
|
|
if (oldKey == null) {
|
2010-12-17 07:56:15 +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.
|
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
|
2010-12-30 07:51:36 +00:00
|
|
|
// new keyboard layout.
|
2012-01-17 08:08:26 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
|
2011-11-29 07:56:27 +00:00
|
|
|
key = onMoveKey(x, y);
|
|
|
|
}
|
|
|
|
onMoveToNewKey(key, x, y);
|
|
|
|
startLongPressTimer(key);
|
|
|
|
setPressedKeyGraphics(key);
|
|
|
|
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, key)) {
|
2010-12-17 07:56:15 +00:00
|
|
|
// 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.
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
2011-03-02 19:43:13 +00:00
|
|
|
callListenerOnRelease(oldKey, oldKey.mCode, true);
|
2011-04-07 08:16:30 +00:00
|
|
|
startSlidingKeyInput(oldKey);
|
2011-07-09 01:35:58 +00:00
|
|
|
mTimerProxy.cancelKeyTimers();
|
2011-11-29 07:56:27 +00:00
|
|
|
startRepeatKey(key);
|
2010-12-18 09:48:32 +00:00
|
|
|
if (mIsAllowedSlidingKeyInput) {
|
2010-12-30 07:51:36 +00:00
|
|
|
// This onPress call may have changed keyboard layout. Those cases are detected
|
2011-11-29 07:56:27 +00:00
|
|
|
// at {@link #setKeyboard}. In those cases, we should update key according
|
2010-12-30 07:51:36 +00:00
|
|
|
// to the new keyboard layout.
|
2012-01-17 08:08:26 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
|
2011-11-29 07:56:27 +00:00
|
|
|
key = onMoveKey(x, y);
|
|
|
|
}
|
|
|
|
onMoveToNewKey(key, x, y);
|
|
|
|
startLongPressTimer(key);
|
|
|
|
setPressedKeyGraphics(key);
|
2010-12-18 09:48:32 +00:00
|
|
|
} else {
|
2011-01-28 03:40:27 +00:00
|
|
|
// HACK: On some devices, quick successive touches may be translated to sudden
|
|
|
|
// move by touch panel firmware. This hack detects the case and translates the
|
|
|
|
// move event to successive up and down events.
|
|
|
|
final int dx = x - lastX;
|
|
|
|
final int dy = y - lastY;
|
|
|
|
final int lastMoveSquared = dx * dx + dy * dy;
|
2012-07-26 04:04:31 +00:00
|
|
|
// TODO: Should find a way to balance gesture detection and this hack.
|
2012-05-30 10:29:57 +00:00
|
|
|
if (sNeedsPhantomSuddenMoveEventHack
|
2012-07-26 04:04:31 +00:00
|
|
|
&& lastMoveSquared >= mKeyQuarterWidthSquared
|
2012-08-23 06:01:46 +00:00
|
|
|
&& !mIsDetectingGesture) {
|
2012-05-30 10:29:57 +00:00
|
|
|
if (DEBUG_MODE) {
|
|
|
|
Log.w(TAG, String.format("onMoveEvent:"
|
|
|
|
+ " phantom sudden move event is translated to "
|
2011-01-28 03:40:27 +00:00
|
|
|
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
|
2012-05-30 10:29:57 +00:00
|
|
|
}
|
2012-07-26 04:04:31 +00:00
|
|
|
// TODO: This should be moved to outside of this nested if-clause?
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.pointerTracker_onMoveEvent(x, y, lastX, lastY);
|
|
|
|
}
|
2012-08-07 05:45:06 +00:00
|
|
|
onUpEventInternal();
|
2011-01-28 03:40:27 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
|
|
|
} else {
|
2012-06-27 00:47:59 +00:00
|
|
|
// 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-08-23 06:01:46 +00:00
|
|
|
if (getActivePointerTrackerCount() > 1 && sPointerTrackerQueue != null
|
|
|
|
&& !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) {
|
2012-08-07 05:45:06 +00:00
|
|
|
onUpEventInternal();
|
2012-06-27 00:47:59 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!mIsDetectingGesture) {
|
2012-07-26 04:04:31 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
|
|
|
}
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
2011-01-28 03:40:27 +00:00
|
|
|
}
|
2010-12-18 09:48:32 +00:00
|
|
|
}
|
2011-04-22 02:09:48 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
} else {
|
2011-11-29 07:56:27 +00:00
|
|
|
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, key)) {
|
2010-12-17 07:56:15 +00:00
|
|
|
// The pointer has been slid out from the previous key, we must call onRelease() to
|
|
|
|
// notify that the previous key has been released.
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
2011-03-02 19:43:13 +00:00
|
|
|
callListenerOnRelease(oldKey, oldKey.mCode, true);
|
2011-04-07 08:16:30 +00:00
|
|
|
startSlidingKeyInput(oldKey);
|
2011-07-17 21:37:30 +00:00
|
|
|
mTimerProxy.cancelLongPressTimer();
|
2010-12-18 09:48:32 +00:00
|
|
|
if (mIsAllowedSlidingKeyInput) {
|
2011-11-29 07:56:27 +00:00
|
|
|
onMoveToNewKey(key, x, y);
|
2010-12-18 09:48:32 +00:00
|
|
|
} else {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!mIsDetectingGesture) {
|
2012-07-26 04:04:31 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
|
|
|
}
|
2010-12-18 09:48:32 +00:00
|
|
|
}
|
2010-09-02 15:48:16 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onUpEvent(final int x, final int y, final long eventTime) {
|
|
|
|
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
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
2010-12-21 05:01:13 +00:00
|
|
|
if (queue != null) {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (!sInGesture) {
|
2012-06-12 10:40:37 +00:00
|
|
|
if (mCurrentKey != null && mCurrentKey.isModifier()) {
|
|
|
|
// Before processing an up event of modifier key, all pointers already being
|
|
|
|
// tracked should be released.
|
|
|
|
queue.releaseAllPointersExcept(this, eventTime);
|
|
|
|
} else {
|
|
|
|
queue.releaseAllPointersOlderThan(this, eventTime);
|
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-07 05:45:06 +00:00
|
|
|
onUpEventInternal();
|
2012-08-23 06:01:46 +00:00
|
|
|
if (queue != null) {
|
|
|
|
queue.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-08-07 05:45:06 +00:00
|
|
|
printTouchEvent("onPhntEvent:", getLastX(), getLastY(), eventTime);
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2012-08-07 05:45:06 +00:00
|
|
|
onUpEventInternal();
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 05:45:06 +00:00
|
|
|
private void onUpEventInternal() {
|
2011-07-09 01:35:58 +00:00
|
|
|
mTimerProxy.cancelKeyTimers();
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
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);
|
2011-08-31 06:26:32 +00:00
|
|
|
if (mIsShowingMoreKeysPanel) {
|
|
|
|
mDrawingProxy.dismissMoreKeysPanel();
|
|
|
|
mIsShowingMoreKeysPanel = false;
|
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) {
|
|
|
|
callListenerOnRelease(currentKey, currentKey.mCode, true);
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
endBatchInput();
|
2012-06-12 10:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
// This event will be recognized as a regular code input. Clear unused possible batch points
|
|
|
|
// so they are not mistakenly displayed as preview.
|
2012-07-19 12:53:42 +00:00
|
|
|
clearBatchInputPointsOfAllPointerTrackers();
|
2012-08-23 06:14:46 +00:00
|
|
|
if (mKeyAlreadyProcessed) {
|
2011-04-18 10:07:20 +00:00
|
|
|
return;
|
2012-08-23 06:14:46 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
if (currentKey != null && !currentKey.isRepeatable()) {
|
|
|
|
detectAndSendKey(currentKey, mKeyX, mKeyY);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onShowMoreKeysPanel(final int x, final int y, final KeyEventHandler handler) {
|
2012-07-19 05:47:55 +00:00
|
|
|
abortBatchInput();
|
2011-07-23 08:16:56 +00:00
|
|
|
onLongPressed();
|
2011-08-31 06:26:32 +00:00
|
|
|
mIsShowingMoreKeysPanel = true;
|
2012-07-20 09:40:31 +00:00
|
|
|
onDownEvent(x, y, SystemClock.uptimeMillis(), handler);
|
2011-07-23 08:16:56 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onLongPressed() {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
2011-07-11 22:24:01 +00:00
|
|
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
2011-06-08 07:58:08 +00:00
|
|
|
if (queue != null) {
|
2011-04-22 08:33:24 +00:00
|
|
|
queue.remove(this);
|
2011-06-08 07:58:08 +00:00
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onCancelEvent(final int x, final int y, final long eventTime) {
|
|
|
|
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
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
2011-04-22 02:09:48 +00:00
|
|
|
if (queue != null) {
|
2011-07-23 08:27:49 +00:00
|
|
|
queue.releaseAllPointersExcept(this, eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
queue.remove(this);
|
2011-04-22 02:09:48 +00:00
|
|
|
}
|
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);
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2011-08-31 06:26:32 +00:00
|
|
|
if (mIsShowingMoreKeysPanel) {
|
|
|
|
mDrawingProxy.dismissMoreKeysPanel();
|
|
|
|
mIsShowingMoreKeysPanel = false;
|
2011-07-23 08:16:56 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void startRepeatKey(final Key key) {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (key != null && key.isRepeatable() && !sInGesture) {
|
2012-05-10 18:33:31 +00:00
|
|
|
onRegisterKey(key);
|
2012-02-01 06:07:25 +00:00
|
|
|
mTimerProxy.startKeyRepeatTimer(this);
|
2011-04-22 12:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public void onRegisterKey(final Key key) {
|
2010-09-01 08:50:24 +00:00
|
|
|
if (key != null) {
|
2011-11-29 07:56:27 +00:00
|
|
|
detectAndSendKey(key, key.mX, key.mY);
|
2012-07-31 09:51:58 +00:00
|
|
|
mTimerProxy.startTypingStateTimer(key);
|
2010-09-01 08:50:24 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final Key newKey) {
|
|
|
|
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;
|
2011-11-29 07:56:27 +00:00
|
|
|
} else if (curKey != null) {
|
|
|
|
return curKey.squaredDistanceToEdge(x, y)
|
2011-07-04 10:59:57 +00:00
|
|
|
>= mKeyDetector.getKeyHysteresisDistanceSquared();
|
2010-08-31 15:27:04 +00:00
|
|
|
} else {
|
2011-04-21 03:22:00 +00:00
|
|
|
return true;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void startLongPressTimer(final Key key) {
|
2012-08-23 06:01:46 +00:00
|
|
|
if (key != null && key.isLongPressEnabled() && !sInGesture) {
|
2012-02-01 06:07:25 +00:00
|
|
|
mTimerProxy.startLongPressTimer(this);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2010-10-02 06:17:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
private void detectAndSendKey(final Key key, final int x, final int y) {
|
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
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
final int code = key.mCode;
|
2012-03-06 05:56:46 +00:00
|
|
|
callListenerOnCodeInput(key, code, x, y);
|
2011-11-30 08:54:58 +00:00
|
|
|
callListenerOnRelease(key, code, false);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2011-11-29 07:56:27 +00:00
|
|
|
Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title,
|
2012-06-26 09:36:30 +00:00
|
|
|
(mKeyAlreadyProcessed ? "-" : " "), mPointerId, x, y, eventTime, code));
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
2010-09-24 11:45:24 +00:00
|
|
|
}
|