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;
|
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
|
|
|
|
2013-12-20 06:57:56 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.BogusMoveEventDetector;
|
2013-12-20 06:47:38 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureEnabler;
|
2012-07-18 05:27:51 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.GestureStroke;
|
2013-12-24 06:24:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.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;
|
2013-12-20 06:54:37 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.TypingTimeRecorder;
|
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-12-03 06:49:10 +00:00
|
|
|
public interface DrawingProxy {
|
2010-08-31 15:27:04 +00:00
|
|
|
public void invalidateKey(Key key);
|
2013-12-13 08:09:16 +00:00
|
|
|
public void showKeyPreview(Key key);
|
|
|
|
public void dismissKeyPreview(Key key);
|
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-12-13 08:09:16 +00:00
|
|
|
public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay);
|
|
|
|
public void startLongPressTimerOf(PointerTracker tracker, int delay);
|
|
|
|
public void cancelLongPressTimerOf(PointerTracker tracker);
|
2013-12-16 05:55:05 +00:00
|
|
|
public void cancelLongPressShiftKeyTimers();
|
2013-12-13 08:09:16 +00:00
|
|
|
public void cancelKeyTimersOf(PointerTracker tracker);
|
2013-06-03 08:50:48 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer();
|
|
|
|
public void cancelDoubleTapShiftKeyTimer();
|
|
|
|
public boolean isInDoubleTapShiftKeyTimeout();
|
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-12-13 08:09:16 +00:00
|
|
|
public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay) {}
|
|
|
|
@Override
|
|
|
|
public void startLongPressTimerOf(PointerTracker tracker, int delay) {}
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
public void cancelLongPressTimerOf(PointerTracker tracker) {}
|
2012-02-01 06:07:25 +00:00
|
|
|
@Override
|
2013-12-16 05:55:05 +00:00
|
|
|
public void cancelLongPressShiftKeyTimers() {}
|
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
public void cancelKeyTimersOf(PointerTracker tracker) {}
|
2011-08-24 05:44:46 +00:00
|
|
|
@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
|
2012-11-22 02:04:41 +00:00
|
|
|
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 {
|
2013-12-13 08:09:16 +00:00
|
|
|
public final boolean mKeySelectionByDraggingFinger;
|
2012-08-23 05:28:15 +00:00
|
|
|
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
|
|
|
|
2012-10-05 03:12:54 +00:00
|
|
|
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
|
2013-12-13 08:09:16 +00:00
|
|
|
mKeySelectionByDraggingFinger = mainKeyboardViewAttr.getBoolean(
|
|
|
|
R.styleable.MainKeyboardView_keySelectionByDraggingFinger, false);
|
2012-08-23 05:28:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 06:47:38 +00:00
|
|
|
private static GestureEnabler sGestureEnabler = new GestureEnabler();
|
|
|
|
|
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
|
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
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private static DrawingProxy sDrawingProxy;
|
|
|
|
private static TimerProxy sTimerProxy;
|
|
|
|
private static KeyboardActionListener sListener = KeyboardActionListener.EMPTY_LISTENER;
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2013-12-20 02:56:09 +00:00
|
|
|
// The {@link KeyDetector} is set whenever the down event is processed. Also this is updated
|
|
|
|
// when new {@link Keyboard} is set by {@link #setKeyDetector(KeyDetector)}.
|
|
|
|
private KeyDetector mKeyDetector;
|
2010-12-02 09:46:21 +00:00
|
|
|
private Keyboard mKeyboard;
|
2013-12-13 08:09:16 +00:00
|
|
|
private int mPhantomSuddenMoveThreshold;
|
2012-10-10 09:37:46 +00:00
|
|
|
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;
|
2013-12-20 06:54:37 +00:00
|
|
|
private static TypingTimeRecorder sTypingTimeRecorder;
|
2013-12-17 03:15:02 +00:00
|
|
|
private static final InputPointers sAggregatedPointers = new InputPointers(
|
2012-08-23 06:01:46 +00:00
|
|
|
GestureStroke.DEFAULT_CAPACITY);
|
2013-12-17 03:15:02 +00:00
|
|
|
private static int sLastRecognitionPointSize = 0; // synchronized using sAggregatedPointers
|
|
|
|
private static long sLastRecognitionTime = 0; // synchronized using sAggregatedPointers
|
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;
|
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;
|
2013-12-13 08:09:16 +00:00
|
|
|
// true if this pointer is in the dragging finger mode.
|
|
|
|
boolean mIsInDraggingFinger;
|
|
|
|
// true if this pointer is sliding from a modifier key and in the sliding key input mode,
|
2012-10-06 14:22:36 +00:00
|
|
|
// so that further modifier keys should be ignored.
|
2013-12-13 08:09:16 +00:00
|
|
|
boolean mIsInSlidingKeyInput;
|
2013-09-25 08:39:40 +00:00
|
|
|
// if not a NOT_A_CODE, the key of this code is repeating
|
|
|
|
private int mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
|
2010-12-20 07:21:54 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// true if dragging finger is allowed.
|
|
|
|
private boolean mIsAllowedDraggingFinger;
|
2010-12-18 09:48:32 +00:00
|
|
|
|
2012-09-14 09:10:39 +00:00
|
|
|
private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints;
|
2012-07-18 05:27:51 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// TODO: Add PointerTrackerFactory singleton and move some class static methods into it.
|
|
|
|
public static void init(final TypedArray mainKeyboardViewAttr, final TimerProxy timerProxy,
|
2013-12-20 02:56:09 +00:00
|
|
|
final DrawingProxy drawingProxy) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sParams = new PointerTrackerParams(mainKeyboardViewAttr);
|
|
|
|
sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
|
|
|
|
sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
|
2013-12-20 06:54:37 +00:00
|
|
|
sTypingTimeRecorder = new TypingTimeRecorder(
|
|
|
|
sGestureStrokeParams.mStaticTimeThresholdAfterFastTyping,
|
|
|
|
sParams.mSuppressKeyPreviewAfterBatchInputDuration);
|
2013-12-13 08:09:16 +00:00
|
|
|
|
|
|
|
final Resources res = mainKeyboardViewAttr.getResources();
|
2013-07-17 07:58:11 +00:00
|
|
|
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
|
|
|
|
ResourceUtils.getDeviceOverrideValue(
|
|
|
|
res, R.array.phantom_sudden_move_event_device_list));
|
2013-12-20 06:57:56 +00:00
|
|
|
BogusMoveEventDetector.init(res);
|
2011-11-22 00:41:01 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy = timerProxy;
|
|
|
|
sDrawingProxy = drawingProxy;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 02:41:58 +00:00
|
|
|
// 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) {
|
2013-12-20 06:47:38 +00:00
|
|
|
sGestureEnabler.setMainDictionaryAvailability(mainDictionaryAvailable);
|
2012-08-08 02:41:58 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:14:46 +00:00
|
|
|
public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
|
2013-12-20 06:47:38 +00:00
|
|
|
sGestureEnabler.setGestureHandlingEnabledByUser(gestureHandlingEnabledByUser);
|
2012-07-19 03:33:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public static PointerTracker getPointerTracker(final int id) {
|
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++) {
|
2013-12-13 08:09:16 +00:00
|
|
|
final PointerTracker tracker = new PointerTracker(i);
|
2011-07-11 22:24:01 +00:00
|
|
|
trackers.add(tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
return trackers.get(id);
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public static boolean isAnyInDraggingFinger() {
|
|
|
|
return sPointerTrackerQueue.isAnyInDraggingFinger();
|
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) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener = listener;
|
2011-07-11 22:24:01 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2012-07-19 03:33:51 +00:00
|
|
|
final Keyboard keyboard = keyDetector.getKeyboard();
|
2013-12-20 06:47:38 +00:00
|
|
|
sGestureEnabler.setPasswordMode(keyboard.mId.passwordInput());
|
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);
|
2013-12-13 08:09:16 +00:00
|
|
|
tracker.setReleasedKeyGraphics(tracker.getKey());
|
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);
|
2013-12-13 08:09:16 +00:00
|
|
|
tracker.dismissMoreKeysPanel();
|
2012-12-10 20:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private PointerTracker(final int id) {
|
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);
|
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-12-13 08:09:16 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInDraggingFinger && 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-12-13 08:09:16 +00:00
|
|
|
sListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
|
2011-02-20 07:50:46 +00:00
|
|
|
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.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-12-13 08:09:16 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
|
|
|
|
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.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) {
|
2013-12-20 06:54:37 +00:00
|
|
|
sTypingTimeRecorder.onCodeInput(code, eventTime);
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_OUTPUT_TEXT) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.onTextInput(key.getOutputText());
|
2012-10-29 05:46:34 +00:00
|
|
|
} else if (code != Constants.CODE_UNSPECIFIED) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.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-12-13 08:09:16 +00:00
|
|
|
final boolean ignoreModifierKey = mIsInDraggingFinger && 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()) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.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));
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.onFinishSlidingInput();
|
2013-05-14 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.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();
|
2013-12-13 08:09:16 +00:00
|
|
|
// Mark that keyboard layout has been changed.
|
|
|
|
mKeyboardLayoutHasBeenChanged = true;
|
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) {
|
2013-12-13 08:09:16 +00:00
|
|
|
if (sDrawingProxy != null) {
|
2012-06-25 07:33:06 +00:00
|
|
|
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
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
mPhantomSuddenMoveThreshold = (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
|
2013-12-13 08:09:16 +00:00
|
|
|
public boolean isInDraggingFinger() {
|
|
|
|
return mIsInDraggingFinger;
|
2010-12-20 07:21:54 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.dismissKeyPreview(key);
|
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) {
|
2013-12-20 06:47:38 +00:00
|
|
|
if (!sGestureEnabler.shouldHandleGesture()) return false;
|
2013-12-20 06:54:37 +00:00
|
|
|
return sTypingTimeRecorder.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.
|
2013-12-13 08:09:16 +00:00
|
|
|
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
|
2012-03-14 10:49:13 +00:00
|
|
|
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)) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.showKeyPreview(key);
|
2012-03-13 08:15:05 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2013-12-24 03:39:16 +00:00
|
|
|
if (altersCode) {
|
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
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private static void updateReleaseKeyGraphics(final Key key) {
|
2012-03-13 08:15:05 +00:00
|
|
|
key.onReleased();
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.invalidateKey(key);
|
2012-03-13 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private static void updatePressKeyGraphics(final Key key) {
|
2012-03-13 08:15:05 +00:00
|
|
|
key.onPressed();
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.invalidateKey(key);
|
2012-03-13 08:15:05 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-20 06:57:56 +00:00
|
|
|
private static int getDistance(final int x1, final int y1, final int x2, final int y2) {
|
2012-10-10 09:37:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
/* package */ 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
|
|
|
}
|
|
|
|
|
2013-12-20 08:20:52 +00:00
|
|
|
/**
|
|
|
|
* Determines whether the batch input has started or not.
|
|
|
|
* @return true if the batch input has started successfully.
|
|
|
|
*/
|
|
|
|
private boolean mayStartBatchInput() {
|
|
|
|
if (!mGestureStrokeWithPreviewPoints.isStartOfAGesture()) {
|
|
|
|
return false;
|
2012-09-26 03:46:55 +00:00
|
|
|
}
|
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
|
|
|
}
|
2013-12-17 03:15:02 +00:00
|
|
|
synchronized (sAggregatedPointers) {
|
|
|
|
sAggregatedPointers.reset();
|
2012-09-27 10:01:17 +00:00
|
|
|
sLastRecognitionPointSize = 0;
|
|
|
|
sLastRecognitionTime = 0;
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.onStartBatchInput();
|
2012-12-10 20:38:29 +00:00
|
|
|
dismissAllMoreKeysPanels();
|
2013-12-20 08:20:52 +00:00
|
|
|
sTimerProxy.cancelLongPressTimerOf(this);
|
2012-09-27 10:01:17 +00:00
|
|
|
}
|
2013-12-20 08:20:52 +00:00
|
|
|
return true;
|
2012-11-22 02:04:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 08:20:52 +00:00
|
|
|
private void showGestureTrail() {
|
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.
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.showGestureTrail(
|
2013-07-30 09:42:48 +00:00
|
|
|
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
2012-11-22 02:04:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 08:20:52 +00:00
|
|
|
public void updateBatchInputByTimer(final long syntheticMoveEventTime) {
|
|
|
|
final int gestureTime = (int)(syntheticMoveEventTime - sGestureFirstDownTime);
|
|
|
|
mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime);
|
|
|
|
updateBatchInput(syntheticMoveEventTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBatchInput(final long moveEventTime) {
|
2013-12-17 03:15:02 +00:00
|
|
|
synchronized (sAggregatedPointers) {
|
2012-11-22 02:04:41 +00:00
|
|
|
final GestureStroke stroke = mGestureStrokeWithPreviewPoints;
|
2013-12-17 03:15:02 +00:00
|
|
|
stroke.appendIncrementalBatchPoints(sAggregatedPointers);
|
|
|
|
final int size = sAggregatedPointers.getPointerSize();
|
2012-11-22 02:04:41 +00:00
|
|
|
if (size > sLastRecognitionPointSize
|
2013-12-20 08:20:52 +00:00
|
|
|
&& stroke.hasRecognitionTimePast(moveEventTime, sLastRecognitionTime)) {
|
2012-11-22 02:04:41 +00:00
|
|
|
if (DEBUG_LISTENER) {
|
|
|
|
Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
|
|
|
|
size));
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.startUpdateBatchInputTimer(this);
|
2013-12-17 03:15:02 +00:00
|
|
|
sListener.onUpdateBatchInput(sAggregatedPointers);
|
2013-10-01 10:54:14 +00:00
|
|
|
// The listener may change the size of the pointers (when auto-committing
|
|
|
|
// for example), so we need to get the size from the pointers again.
|
2013-12-17 03:15:02 +00:00
|
|
|
sLastRecognitionPointSize = sAggregatedPointers.getPointerSize();
|
2013-12-20 08:20:52 +00:00
|
|
|
sLastRecognitionTime = moveEventTime;
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 08:20:52 +00:00
|
|
|
/**
|
|
|
|
* Determines whether the batch input has ended successfully or continues.
|
|
|
|
* @param upEventTime the event time of this pointer up.
|
|
|
|
* @return true if the batch input has ended successfully, false if it continues.
|
|
|
|
*/
|
|
|
|
private boolean mayEndBatchInput(final long upEventTime) {
|
|
|
|
boolean hasEndBatchInputSuccessfully = false;
|
2013-12-17 03:15:02 +00:00
|
|
|
synchronized (sAggregatedPointers) {
|
|
|
|
mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregatedPointers);
|
2012-08-23 06:01:46 +00:00
|
|
|
if (getActivePointerTrackerCount() == 1) {
|
2013-12-20 08:20:52 +00:00
|
|
|
hasEndBatchInputSuccessfully = true;
|
|
|
|
sTypingTimeRecorder.onEndBatchInput(upEventTime);
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.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",
|
2013-12-17 03:15:02 +00:00
|
|
|
mPointerId, sAggregatedPointers.getPointerSize()));
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
2013-12-17 03:15:02 +00:00
|
|
|
sListener.onEndBatchInput(sAggregatedPointers);
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
}
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2013-12-20 08:20:52 +00:00
|
|
|
return hasEndBatchInputSuccessfully;
|
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));
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
sListener.onCancelBatchInput();
|
2012-12-06 01:49:35 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) {
|
2013-08-01 08:48:04 +00:00
|
|
|
final int action = me.getActionMasked();
|
|
|
|
final long eventTime = me.getEventTime();
|
|
|
|
if (action == MotionEvent.ACTION_MOVE) {
|
2013-12-13 08:09:16 +00:00
|
|
|
// When this pointer is the only active pointer and is showing a more keys panel,
|
|
|
|
// we should ignore other pointers' motion event.
|
|
|
|
final boolean shouldIgnoreOtherPointers =
|
|
|
|
isShowingMoreKeysPanel() && getActivePointerTrackerCount() == 1;
|
2013-08-01 08:48:04 +00:00
|
|
|
final int pointerCount = me.getPointerCount();
|
|
|
|
for (int index = 0; index < pointerCount; index++) {
|
|
|
|
final int id = me.getPointerId(index);
|
2013-12-13 08:09:16 +00:00
|
|
|
if (shouldIgnoreOtherPointers && id != mPointerId) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-01 08:48:04 +00:00
|
|
|
final int x = (int)me.getX(index);
|
|
|
|
final int y = (int)me.getY(index);
|
2013-12-13 08:09:16 +00:00
|
|
|
final PointerTracker tracker = getPointerTracker(id);
|
2013-08-01 08:48:04 +00:00
|
|
|
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:
|
2013-12-13 08:09:16 +00:00
|
|
|
onDownEvent(x, y, eventTime, keyDetector);
|
2011-09-06 06:25:58 +00:00
|
|
|
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,
|
2013-12-13 08:09:16 +00:00
|
|
|
final KeyDetector keyDetector) {
|
2012-08-23 06:14:46 +00:00
|
|
|
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-12-13 08:09:16 +00:00
|
|
|
setKeyDetectorInner(keyDetector);
|
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);
|
2013-12-20 06:47:38 +00:00
|
|
|
if (!sGestureEnabler.shouldHandleGesture()) {
|
2012-08-23 06:01:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-25 05:14:14 +00:00
|
|
|
// A gesture should start only from a non-modifier key. Note that the gesture detection is
|
|
|
|
// disabled when the key is repeating.
|
2012-09-14 05:00:51 +00:00
|
|
|
mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard()
|
2013-09-25 05:14:14 +00:00
|
|
|
&& key != null && !key.isModifier();
|
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,
|
2013-12-20 06:54:37 +00:00
|
|
|
sTypingTimeRecorder.getLastLetterTypingTime());
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
/* package */ boolean isShowingMoreKeysPanel() {
|
2012-12-03 02:47:52 +00:00
|
|
|
return (mMoreKeysPanel != null);
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void dismissMoreKeysPanel() {
|
|
|
|
if (isShowingMoreKeysPanel()) {
|
|
|
|
mMoreKeysPanel.dismissMoreKeysPanel();
|
|
|
|
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);
|
2013-12-13 08:09:16 +00:00
|
|
|
// Key selection by dragging finger is allowed when 1) key selection by dragging finger is
|
|
|
|
// enabled by configuration, 2) this pointer starts dragging from modifier key, or 3) this
|
|
|
|
// pointer's KeyDetector always allows key selection by dragging finger, such as
|
|
|
|
// {@link MoreKeysKeyboard}.
|
|
|
|
mIsAllowedDraggingFinger = sParams.mKeySelectionByDraggingFinger
|
2011-12-01 07:26:09 +00:00
|
|
|
|| (key != null && key.isModifier())
|
2013-12-13 08:09:16 +00:00
|
|
|
|| mKeyDetector.alwaysAllowsKeySelectionByDraggingFinger();
|
2010-12-30 07:51:36 +00:00
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
2013-04-22 08:57:05 +00:00
|
|
|
mIsTrackingForActionDisabled = false;
|
2013-12-13 08:09:16 +00:00
|
|
|
resetKeySelectionByDraggingFinger();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void startKeySelectionByDraggingFinger(final Key key) {
|
|
|
|
if (!mIsInDraggingFinger) {
|
|
|
|
mIsInSlidingKeyInput = key.isModifier();
|
2011-11-29 07:56:27 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
mIsInDraggingFinger = true;
|
2011-04-07 08:16:30 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void resetKeySelectionByDraggingFinger() {
|
|
|
|
mIsInDraggingFinger = false;
|
2012-10-06 14:22:36 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2013-12-13 08:09:16 +00:00
|
|
|
sDrawingProxy.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) {
|
2013-12-20 08:20:52 +00:00
|
|
|
if (!mIsDetectingGesture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final int beforeLength = mGestureStrokeWithPreviewPoints.getLength();
|
2012-08-23 06:01:46 +00:00
|
|
|
final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
|
2013-12-20 08:20:52 +00:00
|
|
|
final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard(
|
|
|
|
x, y, gestureTime, isMajorEvent);
|
|
|
|
if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) {
|
|
|
|
sTimerProxy.startUpdateBatchInputTimer(this);
|
|
|
|
}
|
|
|
|
// If the move event goes out from valid batch input area, cancel batch input.
|
|
|
|
if (!onValidArea) {
|
|
|
|
cancelBatchInput();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
if (!sInGesture && key != null && Character.isLetter(key.getCode())
|
|
|
|
&& mayStartBatchInput()) {
|
|
|
|
sInGesture = true;
|
|
|
|
}
|
|
|
|
if (sInGesture) {
|
|
|
|
if (key != null) {
|
|
|
|
updateBatchInput(eventTime);
|
2012-07-18 08:56:30 +00:00
|
|
|
}
|
2013-12-20 08:20:52 +00:00
|
|
|
showGestureTrail();
|
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
|
|
|
|
2013-12-20 06:47:38 +00:00
|
|
|
if (sGestureEnabler.shouldHandleGesture() && 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-12-13 08:09:16 +00:00
|
|
|
if (mIsInSlidingKeyInput) {
|
|
|
|
sDrawingProxy.showSlidingKeyInputPreview(this);
|
2013-07-30 09:42:48 +00:00
|
|
|
}
|
2012-12-10 20:38:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-23 06:01:46 +00:00
|
|
|
onMoveEventInternal(x, y, eventTime);
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void processDraggingFingerInToNewKey(final Key newKey, final int x, final int y,
|
2012-10-31 09:39:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void processDraggingFingerOutFromOldKey(final Key oldKey) {
|
2012-10-31 10:02:51 +00:00
|
|
|
setReleasedKeyGraphics(oldKey);
|
2013-08-12 09:05:11 +00:00
|
|
|
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
|
2013-12-13 08:09:16 +00:00
|
|
|
startKeySelectionByDraggingFinger(oldKey);
|
|
|
|
sTimerProxy.cancelKeyTimersOf(this);
|
2012-10-31 10:02:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void dragFingerFromOldKeyToNewKey(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.
|
2013-12-13 08:09:16 +00:00
|
|
|
processDraggingFingerOutFromOldKey(oldKey);
|
2012-10-31 09:31:48 +00:00
|
|
|
startRepeatKey(key);
|
2013-12-13 08:09:16 +00:00
|
|
|
if (mIsAllowedDraggingFinger) {
|
|
|
|
processDraggingFingerInToNewKey(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
|
2013-12-13 08:09:16 +00:00
|
|
|
&& getDistance(x, y, lastX, lastY) >= mPhantomSuddenMoveThreshold) {
|
2012-10-31 10:37:35 +00:00
|
|
|
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.
|
2013-12-20 06:57:56 +00:00
|
|
|
else if (sTypingTimeRecorder.isInFastTyping(eventTime)
|
2012-10-31 10:37:35 +00:00
|
|
|
&& 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y) {
|
2012-10-31 09:31:48 +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.
|
2013-12-13 08:09:16 +00:00
|
|
|
processDraggingFingerOutFromOldKey(oldKey);
|
|
|
|
if (mIsAllowedDraggingFinger) {
|
2012-10-31 09:31:48 +00:00
|
|
|
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
|
|
|
|
2013-12-20 06:47:38 +00:00
|
|
|
if (sGestureEnabler.shouldHandleGesture()) {
|
2012-08-23 06:01:46 +00:00
|
|
|
// 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)) {
|
2013-12-13 08:09:16 +00:00
|
|
|
dragFingerFromOldKeyToNewKey(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.
|
2013-12-13 08:09:16 +00:00
|
|
|
processDraggingFingerInToNewKey(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)) {
|
2013-12-13 08:09:16 +00:00
|
|
|
dragFingerOutFromOldKey(oldKey, x, y);
|
2010-09-02 15:48:16 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
if (mIsInSlidingKeyInput) {
|
|
|
|
sDrawingProxy.showSlidingKeyInputPreview(this);
|
2013-07-30 09:42:48 +00:00
|
|
|
}
|
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-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.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
|
|
|
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) {
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.cancelKeyTimersOf(this);
|
|
|
|
final boolean isInDraggingFinger = mIsInDraggingFinger;
|
2013-05-13 08:19:21 +00:00
|
|
|
final boolean isInSlidingKeyInput = mIsInSlidingKeyInput;
|
2013-12-13 08:09:16 +00:00
|
|
|
resetKeySelectionByDraggingFinger();
|
2012-08-23 06:01:46 +00:00
|
|
|
mIsDetectingGesture = false;
|
|
|
|
final Key currentKey = mCurrentKey;
|
|
|
|
mCurrentKey = null;
|
2013-09-25 08:39:40 +00:00
|
|
|
final int currentRepeatingKeyCode = mCurrentRepeatingKeyCode;
|
|
|
|
mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
|
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
|
|
|
}
|
2013-12-20 08:20:52 +00:00
|
|
|
if (mayEndBatchInput(eventTime)) {
|
|
|
|
sInGesture = false;
|
|
|
|
}
|
|
|
|
showGestureTrail();
|
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-09-25 08:39:40 +00:00
|
|
|
if (currentKey != null && currentKey.isRepeatable()
|
2013-12-13 08:09:16 +00:00
|
|
|
&& (currentKey.getCode() == currentRepeatingKeyCode) && !isInDraggingFinger) {
|
2013-05-13 08:19:21 +00:00
|
|
|
return;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2013-05-13 08:19:21 +00:00
|
|
|
detectAndSendKey(currentKey, mKeyX, mKeyY, eventTime);
|
2013-12-13 08:09:16 +00:00
|
|
|
if (isInSlidingKeyInput) {
|
2013-05-14 03:25:21 +00:00
|
|
|
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() {
|
2013-12-13 08:09:16 +00:00
|
|
|
resetKeySelectionByDraggingFinger();
|
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() {
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.cancelKeyTimersOf(this);
|
2011-11-29 07:56:27 +00:00
|
|
|
setReleasedKeyGraphics(mCurrentKey);
|
2013-12-13 08:09:16 +00:00
|
|
|
resetKeySelectionByDraggingFinger();
|
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(
|
2013-12-13 08:09:16 +00:00
|
|
|
mIsInSlidingKeyInput);
|
2012-10-31 09:57:10 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-12-20 06:57:56 +00:00
|
|
|
if (!mIsAllowedDraggingFinger && sTypingTimeRecorder.isInFastTyping(eventTime)
|
2012-10-31 09:57:10 +00:00
|
|
|
&& mBogusMoveEventDetector.hasTraveledLongDistance(x, y)) {
|
|
|
|
if (DEBUG_MODE) {
|
|
|
|
final float keyDiagonal = (float)Math.hypot(
|
|
|
|
mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
|
|
|
|
final float lengthFromDownRatio =
|
2013-12-20 06:57:56 +00:00
|
|
|
mBogusMoveEventDetector.getAccumulatedDistanceFromDownKey() / keyDiagonal;
|
2012-10-31 09:57:10 +00:00
|
|
|
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-12-16 05:55:05 +00:00
|
|
|
// Note that we need to cancel all active long press shift key timers if any whenever we
|
|
|
|
// start a new long press timer for both non-shift and shift keys.
|
|
|
|
sTimerProxy.cancelLongPressShiftKeyTimers();
|
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
|
2013-12-13 08:09:16 +00:00
|
|
|
// doesn't have its more keys. (e.g. spacebar, globe key) If we are in the dragging finger
|
|
|
|
// mode, we will disable long press timer of such key.
|
2013-05-13 06:05:37 +00:00
|
|
|
// We always need to start the long press timer if the key has its more keys regardless of
|
2013-12-13 08:09:16 +00:00
|
|
|
// whether or not we are in the dragging finger mode.
|
|
|
|
if (mIsInDraggingFinger && key.getMoreKeys() == null) return;
|
|
|
|
|
|
|
|
final int delay = getLongPressTimeout(key.getCode());
|
2013-12-16 05:55:05 +00:00
|
|
|
if (delay <= 0) return;
|
2013-12-13 08:09:16 +00:00
|
|
|
sTimerProxy.startLongPressTimerOf(this, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getLongPressTimeout(final int code) {
|
|
|
|
if (code == Constants.CODE_SHIFT) {
|
|
|
|
return sParams.mLongPressShiftLockTimeout;
|
|
|
|
}
|
|
|
|
final int longpressTimeout = Settings.getInstance().getCurrent().mKeyLongpressTimeout;
|
|
|
|
if (mIsInSlidingKeyInput) {
|
|
|
|
// We use longer timeout for sliding finger input started from the modifier key.
|
|
|
|
return longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
|
2013-07-30 09:42:48 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
return longpressTimeout;
|
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;
|
2013-12-13 08:09:16 +00:00
|
|
|
// Don't start key repeat when we are in the dragging finger mode.
|
|
|
|
if (mIsInDraggingFinger) return;
|
2013-08-13 03:10:26 +00:00
|
|
|
final int startRepeatCount = 1;
|
2013-12-13 08:09:16 +00:00
|
|
|
startKeyRepeatTimer(startRepeatCount);
|
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-09-25 08:39:40 +00:00
|
|
|
mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
|
2013-08-01 06:17:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-25 08:39:40 +00:00
|
|
|
mCurrentRepeatingKeyCode = code;
|
2013-09-25 05:14:14 +00:00
|
|
|
mIsDetectingGesture = false;
|
2013-08-13 03:10:26 +00:00
|
|
|
final int nextRepeatCount = repeatCount + 1;
|
2013-12-13 08:09:16 +00:00
|
|
|
startKeyRepeatTimer(nextRepeatCount);
|
2013-08-13 03:10:26 +00:00
|
|
|
callListenerOnPressAndCheckKeyboardLayoutChange(key, repeatCount);
|
2013-08-01 06:17:54 +00:00
|
|
|
callListenerOnCodeInput(key, code, mKeyX, mKeyY, SystemClock.uptimeMillis());
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private void startKeyRepeatTimer(final int repeatCount) {
|
|
|
|
final int delay =
|
|
|
|
(repeatCount == 1) ? sParams.mKeyRepeatStartTimeout : sParams.mKeyRepeatInterval;
|
|
|
|
sTimerProxy.startKeyRepeatTimerOf(this, repeatCount, delay);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|