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
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
import android.content.Context;
|
2011-06-21 14:38:42 +00:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.util.Log;
|
2011-07-25 21:05:02 +00:00
|
|
|
import android.widget.TextView;
|
2011-06-21 14:38:42 +00:00
|
|
|
|
2011-06-22 02:53:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
|
2011-01-28 03:40:27 +00:00
|
|
|
import com.android.inputmethod.latin.LatinImeLogger;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
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
|
|
|
import java.util.Arrays;
|
2011-04-15 04:05:58 +00:00
|
|
|
import java.util.List;
|
2010-12-18 11:04:44 +00:00
|
|
|
|
2010-08-31 15:27:04 +00:00
|
|
|
public class PointerTracker {
|
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
|
|
|
|
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-07-04 11:58:58 +00:00
|
|
|
public interface DrawingProxy {
|
2010-08-31 15:27:04 +00:00
|
|
|
public void invalidateKey(Key key);
|
2011-07-25 21:05:02 +00:00
|
|
|
public TextView inflateKeyPreviewText();
|
2011-04-19 06:18:20 +00:00
|
|
|
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
2011-07-01 04:07:59 +00:00
|
|
|
public void cancelShowKeyPreview(PointerTracker tracker);
|
2011-04-19 06:18:20 +00:00
|
|
|
public void dismissKeyPreview(PointerTracker tracker);
|
2011-07-23 08:16:56 +00:00
|
|
|
public boolean dismissPopupPanel();
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 01:35:58 +00:00
|
|
|
public interface TimerProxy {
|
|
|
|
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker);
|
|
|
|
public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker);
|
2011-07-17 21:37:30 +00:00
|
|
|
public void cancelLongPressTimer();
|
2011-07-09 01:35:58 +00:00
|
|
|
public void cancelKeyTimers();
|
|
|
|
}
|
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
private static KeyboardSwitcher sKeyboardSwitcher;
|
|
|
|
private static boolean sConfigSlidingKeyInputEnabled;
|
2010-08-31 15:27:04 +00:00
|
|
|
// Timing constants
|
2011-07-11 22:24:01 +00:00
|
|
|
private static int sDelayBeforeKeyRepeatStart;
|
|
|
|
private static int sLongPressKeyTimeout;
|
|
|
|
private static int sLongPressShiftKeyTimeout;
|
2011-07-17 21:37:30 +00:00
|
|
|
private static int sLongPressSpaceKeyTimeout;
|
2011-07-11 22:24:01 +00:00
|
|
|
private static int sTouchNoiseThresholdMillis;
|
|
|
|
private static int sTouchNoiseThresholdDistanceSquared;
|
|
|
|
|
|
|
|
private static final List<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
|
|
|
|
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-04-15 04:05:58 +00:00
|
|
|
private List<Key> mKeys;
|
2011-01-28 03:40:27 +00:00
|
|
|
private int mKeyQuarterWidthSquared;
|
2011-07-25 21:05:02 +00:00
|
|
|
private final TextView mKeyPreviewText;
|
2010-08-31 15:27:04 +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;
|
|
|
|
|
|
|
|
// The current key index where this pointer is.
|
|
|
|
private int mKeyIndex = KeyDetector.NOT_A_KEY;
|
|
|
|
// The position where mKeyIndex was recognized for the first time.
|
|
|
|
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-07-23 08:16:56 +00:00
|
|
|
// true if this pointer has been long-pressed and is showing a popup panel.
|
|
|
|
private boolean mIsShowingPopupPanel;
|
|
|
|
|
2010-09-07 03:20:03 +00:00
|
|
|
// true if this pointer is repeatable key
|
|
|
|
private boolean mIsRepeatableKey;
|
|
|
|
|
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}
|
|
|
|
private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() {
|
|
|
|
@Override
|
2011-03-02 19:43:13 +00:00
|
|
|
public void onPress(int primaryCode, boolean withSliding) {}
|
2010-12-18 11:04:44 +00:00
|
|
|
@Override
|
2011-03-02 19:43:13 +00:00
|
|
|
public void onRelease(int primaryCode, boolean withSliding) {}
|
2010-12-18 11:04:44 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
|
2010-12-18 11:04:44 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onTextInput(CharSequence text) {}
|
2010-12-18 11:04:44 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCancelInput() {}
|
2010-12-18 11:04:44 +00:00
|
|
|
};
|
2010-09-24 11:45:24 +00:00
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
public static void init(boolean hasDistinctMultitouch, Context context) {
|
|
|
|
if (hasDistinctMultitouch) {
|
|
|
|
sPointerTrackerQueue = new PointerTrackerQueue();
|
|
|
|
} else {
|
|
|
|
sPointerTrackerQueue = null;
|
|
|
|
}
|
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
final Resources res = context.getResources();
|
2011-07-11 22:24:01 +00:00
|
|
|
sConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
|
|
|
|
sDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
|
|
|
|
sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout);
|
|
|
|
sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout);
|
2011-07-17 21:37:30 +00:00
|
|
|
sLongPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout);
|
2011-07-11 22:24:01 +00:00
|
|
|
sTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis);
|
2010-12-17 05:13:01 +00:00
|
|
|
final float touchNoiseThresholdDistance = res.getDimension(
|
|
|
|
R.dimen.config_touch_noise_threshold_distance);
|
2011-07-11 22:24:01 +00:00
|
|
|
sTouchNoiseThresholdDistanceSquared = (int)(
|
2010-12-17 05:13:01 +00:00
|
|
|
touchNoiseThresholdDistance * touchNoiseThresholdDistance);
|
2011-07-11 22:24:01 +00:00
|
|
|
sKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) {
|
|
|
|
final List<PointerTracker> trackers = sTrackers;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setKeyboardActionListener(KeyboardActionListener listener) {
|
|
|
|
for (final PointerTracker tracker : sTrackers) {
|
|
|
|
tracker.mListener = listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setKeyDetector(KeyDetector keyDetector) {
|
|
|
|
for (final PointerTracker tracker : sTrackers) {
|
|
|
|
tracker.setKeyDetectorInner(keyDetector);
|
|
|
|
// Mark that keyboard layout has been changed.
|
|
|
|
tracker.mKeyboardLayoutHasBeenChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void dismissAllKeyPreviews() {
|
|
|
|
for (final PointerTracker tracker : sTrackers) {
|
2011-07-23 08:27:49 +00:00
|
|
|
tracker.setReleasedKeyGraphics(tracker.mKeyIndex);
|
2011-07-11 22:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerTracker(int id, KeyEventHandler handler) {
|
|
|
|
if (handler == null)
|
|
|
|
throw new NullPointerException();
|
|
|
|
mPointerId = id;
|
|
|
|
setKeyDetectorInner(handler.getKeyDetector());
|
|
|
|
mListener = handler.getKeyboardActionListener();
|
|
|
|
mDrawingProxy = handler.getDrawingProxy();
|
|
|
|
mTimerProxy = handler.getTimerProxy();
|
2011-07-25 21:05:02 +00:00
|
|
|
mKeyPreviewText = mDrawingProxy.inflateKeyPreviewText();
|
|
|
|
}
|
|
|
|
|
|
|
|
public TextView getKeyPreviewText() {
|
|
|
|
return mKeyPreviewText;
|
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.
|
2011-03-02 19:43:13 +00:00
|
|
|
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) {
|
2011-04-07 08:16:30 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_LISTENER)
|
2011-04-07 08:16:30 +00:00
|
|
|
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding
|
|
|
|
+ " ignoreModifier=" + ignoreModifierKey);
|
|
|
|
if (ignoreModifierKey)
|
|
|
|
return false;
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled()) {
|
2011-03-02 19:43:13 +00:00
|
|
|
mListener.onPress(key.mCode, withSliding);
|
2011-02-20 07:50:46 +00:00
|
|
|
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
|
|
|
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}.
|
|
|
|
private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) {
|
2011-04-07 08:16:30 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_LISTENER)
|
2010-12-20 07:13:57 +00:00
|
|
|
Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode)
|
2011-04-07 08:16:30 +00:00
|
|
|
+ " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y
|
|
|
|
+ " ignoreModifier=" + ignoreModifierKey);
|
|
|
|
if (ignoreModifierKey)
|
|
|
|
return;
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled())
|
2011-02-20 07:50:46 +00:00
|
|
|
mListener.onCodeInput(primaryCode, keyCodes, x, y);
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 07:50:46 +00:00
|
|
|
private void callListenerOnTextInput(Key key) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_LISTENER)
|
2011-02-20 07:50:46 +00:00
|
|
|
Log.d(TAG, "onTextInput: text=" + key.mOutputText);
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled())
|
2011-02-20 07:50:46 +00:00
|
|
|
mListener.onTextInput(key.mOutputText);
|
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}.
|
2011-03-02 19:43:13 +00:00
|
|
|
private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) {
|
2011-04-07 08:16:30 +00:00
|
|
|
final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_LISTENER)
|
2011-04-07 08:16:30 +00:00
|
|
|
Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding="
|
|
|
|
+ withSliding + " ignoreModifier=" + ignoreModifierKey);
|
|
|
|
if (ignoreModifierKey)
|
|
|
|
return;
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key.isEnabled())
|
2011-03-02 19:43:13 +00:00
|
|
|
mListener.onRelease(primaryCode, withSliding);
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:13:57 +00:00
|
|
|
private void callListenerOnCancelInput() {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_LISTENER)
|
2010-12-20 07:13:57 +00:00
|
|
|
Log.d(TAG, "onCancelInput");
|
|
|
|
mListener.onCancelInput();
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 05:31:29 +00:00
|
|
|
public void setKeyDetectorInner(KeyDetector keyDetector) {
|
2011-07-04 10:59:57 +00:00
|
|
|
mKeyDetector = keyDetector;
|
2011-07-08 05:31:29 +00:00
|
|
|
mKeyboard = keyDetector.getKeyboard();
|
|
|
|
mKeys = mKeyboard.getKeys();
|
|
|
|
final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4;
|
2011-01-28 03:40:27 +00:00
|
|
|
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
|
2011-07-08 05:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:54 +00:00
|
|
|
public boolean isInSlidingKeyInput() {
|
|
|
|
return mIsInSlidingKeyInput;
|
|
|
|
}
|
|
|
|
|
2010-09-01 08:50:24 +00:00
|
|
|
private boolean isValidKeyIndex(int keyIndex) {
|
2011-04-15 04:05:58 +00:00
|
|
|
return keyIndex >= 0 && keyIndex < mKeys.size();
|
2010-09-01 08:50:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 15:27:04 +00:00
|
|
|
public Key getKey(int keyIndex) {
|
2011-04-15 04:05:58 +00:00
|
|
|
return isValidKeyIndex(keyIndex) ? mKeys.get(keyIndex) : null;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
private static boolean isModifierCode(int primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
return primaryCode == Keyboard.CODE_SHIFT
|
2010-12-06 03:12:27 +00:00
|
|
|
|| primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
private boolean isModifierInternal(int keyIndex) {
|
|
|
|
final Key key = getKey(keyIndex);
|
2010-12-20 11:30:26 +00:00
|
|
|
return key == null ? false : isModifierCode(key.mCode);
|
2010-12-18 11:04:44 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 06:02:29 +00:00
|
|
|
public boolean isModifier() {
|
2011-07-08 23:19:19 +00:00
|
|
|
return isModifierInternal(mKeyIndex);
|
2010-09-15 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
private boolean isOnModifierKey(int x, int y) {
|
2010-09-15 06:02:29 +00:00
|
|
|
return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null));
|
|
|
|
}
|
|
|
|
|
2010-12-02 13:59:10 +00:00
|
|
|
public boolean isOnShiftKey(int x, int y) {
|
|
|
|
final Key key = getKey(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null));
|
2010-12-20 11:30:26 +00:00
|
|
|
return key != null && key.mCode == Keyboard.CODE_SHIFT;
|
2010-12-02 13:59:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 12:05:30 +00:00
|
|
|
public int getKeyIndexOn(int x, int y) {
|
|
|
|
return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
|
|
|
|
}
|
|
|
|
|
2010-09-21 07:55:18 +00:00
|
|
|
public boolean isSpaceKey(int keyIndex) {
|
|
|
|
Key key = getKey(keyIndex);
|
2010-12-20 11:30:26 +00:00
|
|
|
return key != null && key.mCode == Keyboard.CODE_SPACE;
|
2010-09-21 07:55:18 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 10:07:20 +00:00
|
|
|
private void setReleasedKeyGraphics(int keyIndex) {
|
2011-07-23 08:27:49 +00:00
|
|
|
mDrawingProxy.dismissKeyPreview(this);
|
2011-04-18 10:07:20 +00:00
|
|
|
final Key key = getKey(keyIndex);
|
|
|
|
if (key != null) {
|
|
|
|
key.onReleased();
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.invalidateKey(key);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 10:07:20 +00:00
|
|
|
private void setPressedKeyGraphics(int keyIndex) {
|
2011-07-23 08:27:49 +00:00
|
|
|
if (isKeyPreviewRequired(keyIndex)) {
|
|
|
|
mDrawingProxy.showKeyPreview(keyIndex, this);
|
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
final Key key = getKey(keyIndex);
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key != null && key.isEnabled()) {
|
2011-04-18 10:07:20 +00:00
|
|
|
key.onPressed();
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.invalidateKey(key);
|
2011-04-18 10:07:20 +00:00
|
|
|
}
|
2010-09-03 03:51:03 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 08:27:49 +00:00
|
|
|
// The modifier key, such as shift key, should not show its key preview.
|
|
|
|
private boolean isKeyPreviewRequired(int keyIndex) {
|
|
|
|
final Key key = getKey(keyIndex);
|
|
|
|
if (key == null || !key.isEnabled())
|
|
|
|
return false;
|
|
|
|
final int code = key.mCode;
|
|
|
|
if (isModifierCode(code) || code == Keyboard.CODE_DELETE
|
|
|
|
|| code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-08 23:19:19 +00:00
|
|
|
public int getLastX() {
|
|
|
|
return mLastX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLastY() {
|
|
|
|
return mLastY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDownTime() {
|
|
|
|
return mDownTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int onDownKey(int x, int y, long eventTime) {
|
|
|
|
mDownTime = eventTime;
|
|
|
|
return onMoveToNewKey(onMoveKeyInternal(x, y), x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int onMoveKeyInternal(int x, int y) {
|
|
|
|
mLastX = x;
|
|
|
|
mLastY = y;
|
|
|
|
return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int onMoveKey(int x, int y) {
|
|
|
|
return onMoveKeyInternal(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int onMoveToNewKey(int keyIndex, int x, int y) {
|
|
|
|
mKeyIndex = keyIndex;
|
|
|
|
mKeyX = x;
|
|
|
|
mKeyY = y;
|
|
|
|
return keyIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int onUpKey(int x, int y, long eventTime) {
|
|
|
|
mUpTime = eventTime;
|
|
|
|
mKeyIndex = KeyDetector.NOT_A_KEY;
|
|
|
|
return onMoveKeyInternal(x, y);
|
|
|
|
}
|
|
|
|
|
2011-07-11 02:31:02 +00:00
|
|
|
public void onDownEvent(int x, int y, long eventTime, KeyEventHandler handler) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onDownEvent:", x, y, eventTime);
|
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;
|
2011-07-11 22:24:01 +00:00
|
|
|
if (deltaT < sTouchNoiseThresholdMillis) {
|
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);
|
2011-07-11 22:24:01 +00:00
|
|
|
if (distanceSquared < sTouchNoiseThresholdDistanceSquared) {
|
2011-01-28 03:40:27 +00:00
|
|
|
if (DEBUG_MODE)
|
|
|
|
Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
|
|
|
|
+ " distance=" + distanceSquared);
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2010-12-17 05:13:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 22:24:01 +00:00
|
|
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
2010-12-21 05:01:13 +00:00
|
|
|
if (queue != null) {
|
|
|
|
if (isOnModifierKey(x, y)) {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2010-12-17 05:13:01 +00:00
|
|
|
private void onDownEventInternal(int x, int y, long eventTime) {
|
2011-07-08 23:19:19 +00:00
|
|
|
int keyIndex = 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-05-11 11:48:20 +00:00
|
|
|
// from modifier key, or 3) this pointer is on mini-keyboard.
|
2011-07-11 22:24:01 +00:00
|
|
|
mIsAllowedSlidingKeyInput = sConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex)
|
2011-05-11 11:48:20 +00:00
|
|
|
|| mKeyDetector instanceof MiniKeyboardKeyDetector;
|
2010-12-30 07:51:36 +00:00
|
|
|
mKeyboardLayoutHasBeenChanged = false;
|
2010-09-03 03:51:03 +00:00
|
|
|
mKeyAlreadyProcessed = false;
|
2010-09-07 03:20:03 +00:00
|
|
|
mIsRepeatableKey = false;
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2011-04-07 08:16:30 +00:00
|
|
|
mIgnoreModifierKey = false;
|
2011-04-18 10:07:20 +00:00
|
|
|
if (isValidKeyIndex(keyIndex)) {
|
2010-12-30 07:51:36 +00:00
|
|
|
// This onPress call may have changed keyboard layout. Those cases are detected at
|
|
|
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the new
|
|
|
|
// keyboard layout.
|
2011-04-18 10:07:20 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), false))
|
2011-07-08 23:19:19 +00:00
|
|
|
keyIndex = onDownKey(x, y, eventTime);
|
2011-04-07 08:16:30 +00:00
|
|
|
|
2011-04-22 12:05:30 +00:00
|
|
|
startRepeatKey(keyIndex);
|
2010-10-12 11:24:53 +00:00
|
|
|
startLongPressTimer(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
setPressedKeyGraphics(keyIndex);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 08:16:30 +00:00
|
|
|
private void startSlidingKeyInput(Key key) {
|
|
|
|
if (!mIsInSlidingKeyInput)
|
|
|
|
mIgnoreModifierKey = isModifierCode(key.mCode);
|
|
|
|
mIsInSlidingKeyInput = true;
|
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onMoveEvent(int x, int y, long eventTime) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_MOVE_EVENT)
|
|
|
|
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
2010-09-03 08:54:37 +00:00
|
|
|
if (mKeyAlreadyProcessed)
|
|
|
|
return;
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2011-07-08 23:19:19 +00:00
|
|
|
final int lastX = mLastX;
|
|
|
|
final int lastY = mLastY;
|
|
|
|
final int oldKeyIndex = mKeyIndex;
|
2011-04-18 10:07:20 +00:00
|
|
|
final Key oldKey = getKey(oldKeyIndex);
|
2011-07-08 23:19:19 +00:00
|
|
|
int keyIndex = onMoveKey(x, y);
|
2010-11-09 19:57:41 +00:00
|
|
|
if (isValidKeyIndex(keyIndex)) {
|
|
|
|
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
|
|
|
|
// {@link #setKeyboard}. In those cases, we should update keyIndex according to the
|
|
|
|
// new keyboard layout.
|
2011-03-02 19:43:13 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true))
|
2011-07-08 23:19:19 +00:00
|
|
|
keyIndex = onMoveKey(x, y);
|
|
|
|
onMoveToNewKey(keyIndex, x, y);
|
2010-10-12 11:24:53 +00:00
|
|
|
startLongPressTimer(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
setPressedKeyGraphics(keyIndex);
|
2011-04-21 03:22:00 +00:00
|
|
|
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
|
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-04-18 10:07:20 +00:00
|
|
|
setReleasedKeyGraphics(oldKeyIndex);
|
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-04-22 12:05:30 +00:00
|
|
|
startRepeatKey(keyIndex);
|
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
|
|
|
|
// at {@link #setKeyboard}. In those cases, we should update keyIndex according
|
|
|
|
// to the new keyboard layout.
|
2011-03-02 19:43:13 +00:00
|
|
|
if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true))
|
2011-07-08 23:19:19 +00:00
|
|
|
keyIndex = onMoveKey(x, y);
|
|
|
|
onMoveToNewKey(keyIndex, x, y);
|
2010-12-18 09:48:32 +00:00
|
|
|
startLongPressTimer(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
setPressedKeyGraphics(keyIndex);
|
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;
|
|
|
|
if (lastMoveSquared >= mKeyQuarterWidthSquared) {
|
|
|
|
if (DEBUG_MODE)
|
|
|
|
Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
|
|
|
|
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
|
2011-07-23 08:27:49 +00:00
|
|
|
onUpEventInternal(lastX, lastY, eventTime);
|
2011-01-28 03:40:27 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
|
|
|
} else {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
|
|
|
setReleasedKeyGraphics(oldKeyIndex);
|
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-04-21 03:22:00 +00:00
|
|
|
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
|
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-04-18 10:07:20 +00:00
|
|
|
setReleasedKeyGraphics(oldKeyIndex);
|
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-07-08 23:19:19 +00:00
|
|
|
onMoveToNewKey(keyIndex, x, y);
|
2010-12-18 09:48:32 +00:00
|
|
|
} else {
|
2011-04-18 10:07:20 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onUpEvent(int x, int y, long eventTime) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onUpEvent :", x, y, eventTime);
|
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) {
|
|
|
|
if (isModifier()) {
|
|
|
|
// Before processing an up event of modifier key, all pointers already being
|
|
|
|
// tracked should be released.
|
2011-07-23 08:27:49 +00:00
|
|
|
queue.releaseAllPointersExcept(this, eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
} else {
|
|
|
|
queue.releaseAllPointersOlderThan(this, eventTime);
|
|
|
|
}
|
|
|
|
queue.remove(this);
|
|
|
|
}
|
2011-07-23 08:27:49 +00:00
|
|
|
onUpEventInternal(x, y, eventTime);
|
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.
|
2011-07-23 08:27:49 +00:00
|
|
|
public void onPhantomUpEvent(int x, int y, long eventTime) {
|
2011-04-22 02:09:48 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onPhntEvent:", x, y, eventTime);
|
2011-07-23 08:27:49 +00:00
|
|
|
onUpEventInternal(x, y, eventTime);
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 08:27:49 +00:00
|
|
|
private void onUpEventInternal(int x, int y, long eventTime) {
|
2011-07-09 01:35:58 +00:00
|
|
|
mTimerProxy.cancelKeyTimers();
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.cancelShowKeyPreview(this);
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2011-04-18 10:07:20 +00:00
|
|
|
final int keyX, keyY;
|
2011-07-08 23:19:19 +00:00
|
|
|
if (isMajorEnoughMoveToBeOnNewKey(x, y, onMoveKey(x, y))) {
|
2011-04-18 10:07:20 +00:00
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
|
|
|
} else {
|
|
|
|
// Use previous fixed key coordinates.
|
2011-07-08 23:19:19 +00:00
|
|
|
keyX = mKeyX;
|
|
|
|
keyY = mKeyY;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2011-07-08 23:19:19 +00:00
|
|
|
final int keyIndex = onUpKey(keyX, keyY, eventTime);
|
2011-07-23 08:27:49 +00:00
|
|
|
setReleasedKeyGraphics(keyIndex);
|
2011-07-23 08:16:56 +00:00
|
|
|
if (mIsShowingPopupPanel) {
|
|
|
|
mDrawingProxy.dismissPopupPanel();
|
|
|
|
mIsShowingPopupPanel = false;
|
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
if (mKeyAlreadyProcessed)
|
|
|
|
return;
|
2010-09-07 03:20:03 +00:00
|
|
|
if (!mIsRepeatableKey) {
|
2011-04-18 10:07:20 +00:00
|
|
|
detectAndSendKey(keyIndex, keyX, keyY);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 08:16:56 +00:00
|
|
|
public void onShowPopupPanel(int x, int y, long eventTime, KeyEventHandler handler) {
|
|
|
|
onLongPressed();
|
|
|
|
onDownEvent(x, y, eventTime, handler);
|
|
|
|
mIsShowingPopupPanel = true;
|
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onLongPressed() {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2011-07-23 08:27:49 +00:00
|
|
|
setReleasedKeyGraphics(mKeyIndex);
|
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
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onCancelEvent(int x, int y, long eventTime) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
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-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.cancelShowKeyPreview(this);
|
2011-07-08 23:19:19 +00:00
|
|
|
setReleasedKeyGraphics(mKeyIndex);
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2011-07-23 08:16:56 +00:00
|
|
|
if (mIsShowingPopupPanel) {
|
|
|
|
mDrawingProxy.dismissPopupPanel();
|
|
|
|
mIsShowingPopupPanel = false;
|
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 12:05:30 +00:00
|
|
|
private void startRepeatKey(int keyIndex) {
|
|
|
|
final Key key = getKey(keyIndex);
|
2011-05-11 11:48:20 +00:00
|
|
|
if (key != null && key.mRepeatable) {
|
2011-04-22 12:05:30 +00:00
|
|
|
onRepeatKey(keyIndex);
|
2011-07-11 22:24:01 +00:00
|
|
|
mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this);
|
2011-04-22 12:05:30 +00:00
|
|
|
mIsRepeatableKey = true;
|
|
|
|
} else {
|
|
|
|
mIsRepeatableKey = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onRepeatKey(int keyIndex) {
|
2010-09-01 08:50:24 +00:00
|
|
|
Key key = getKey(keyIndex);
|
|
|
|
if (key != null) {
|
2010-12-20 11:30:26 +00:00
|
|
|
detectAndSendKey(keyIndex, key.mX, key.mY);
|
2010-09-01 08:50:24 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 03:22:00 +00:00
|
|
|
private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) {
|
2011-07-04 10:59:57 +00:00
|
|
|
if (mKeys == null || mKeyDetector == null)
|
|
|
|
throw new NullPointerException("keyboard and/or key detector not set");
|
2011-07-08 23:19:19 +00:00
|
|
|
int curKey = mKeyIndex;
|
2010-08-31 15:27:04 +00:00
|
|
|
if (newKey == curKey) {
|
2011-04-21 03:22:00 +00:00
|
|
|
return false;
|
2010-09-01 08:50:24 +00:00
|
|
|
} else if (isValidKeyIndex(curKey)) {
|
2011-07-04 10:59:57 +00:00
|
|
|
return mKeys.get(curKey).squaredDistanceToEdge(x, y)
|
|
|
|
>= 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-02 06:17:27 +00:00
|
|
|
private void startLongPressTimer(int keyIndex) {
|
|
|
|
Key key = getKey(keyIndex);
|
2010-12-20 11:30:26 +00:00
|
|
|
if (key.mCode == Keyboard.CODE_SHIFT) {
|
2011-07-17 21:37:30 +00:00
|
|
|
if (sLongPressShiftKeyTimeout > 0) {
|
|
|
|
mTimerProxy.startLongPressTimer(sLongPressShiftKeyTimeout, keyIndex, this);
|
|
|
|
}
|
|
|
|
} else if (key.mCode == Keyboard.CODE_SPACE) {
|
|
|
|
if (sLongPressSpaceKeyTimeout > 0) {
|
|
|
|
mTimerProxy.startLongPressTimer(sLongPressSpaceKeyTimeout, keyIndex, this);
|
|
|
|
}
|
2011-06-15 03:36:53 +00:00
|
|
|
} else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) {
|
2010-12-21 08:13:15 +00:00
|
|
|
// We need not start long press timer on the key which has manual temporary upper case
|
|
|
|
// code defined and the keyboard is in manual temporary upper case mode.
|
|
|
|
return;
|
2011-07-11 22:24:01 +00:00
|
|
|
} else if (sKeyboardSwitcher.isInMomentarySwitchState()) {
|
2010-12-17 07:56:15 +00:00
|
|
|
// We use longer timeout for sliding finger input started from the symbols mode key.
|
2011-07-11 22:24:01 +00:00
|
|
|
mTimerProxy.startLongPressTimer(sLongPressKeyTimeout * 3, keyIndex, this);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
2011-07-11 22:24:01 +00:00
|
|
|
mTimerProxy.startLongPressTimer(sLongPressKeyTimeout, keyIndex, this);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2010-10-02 06:17:27 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 11:30:26 +00:00
|
|
|
private void detectAndSendKey(int index, int x, int y) {
|
2010-09-07 06:37:59 +00:00
|
|
|
final Key key = getKey(index);
|
|
|
|
if (key == null) {
|
2010-12-20 07:13:57 +00:00
|
|
|
callListenerOnCancelInput();
|
2010-12-18 11:04:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (key.mOutputText != null) {
|
2011-02-20 07:50:46 +00:00
|
|
|
callListenerOnTextInput(key);
|
2011-03-02 19:43:13 +00:00
|
|
|
callListenerOnRelease(key, key.mCode, false);
|
2010-09-07 06:37:59 +00:00
|
|
|
} else {
|
2010-12-20 11:30:26 +00:00
|
|
|
int code = key.mCode;
|
2010-12-18 11:04:44 +00:00
|
|
|
final int[] codes = mKeyDetector.newCodeArray();
|
|
|
|
mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes);
|
2010-10-02 06:17:27 +00:00
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
// If keyboard is in manual temporary upper case state and key has manual temporary
|
2011-06-15 03:36:53 +00:00
|
|
|
// uppercase letter as key hint letter, alternate character code should be sent.
|
|
|
|
if (mKeyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()) {
|
2011-06-25 10:38:55 +00:00
|
|
|
code = key.mHintLabel.charAt(0);
|
2010-12-18 11:04:44 +00:00
|
|
|
codes[0] = code;
|
|
|
|
}
|
2010-10-02 06:17:27 +00:00
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
// Swap the first and second values in the codes array if the primary code is not the
|
|
|
|
// first value but the second value in the array. This happens when key debouncing is
|
|
|
|
// in effect.
|
|
|
|
if (codes.length >= 2 && codes[0] != code && codes[1] == code) {
|
|
|
|
codes[1] = codes[0];
|
|
|
|
codes[0] = code;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2011-02-20 07:50:46 +00:00
|
|
|
callListenerOnCodeInput(key, code, codes, x, y);
|
2011-03-02 19:43:13 +00:00
|
|
|
callListenerOnRelease(key, code, false);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
private long mPreviousEventTime;
|
|
|
|
|
|
|
|
private void printTouchEvent(String title, int x, int y, long eventTime) {
|
|
|
|
final int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
|
|
|
|
final Key key = getKey(keyIndex);
|
2010-12-20 11:30:26 +00:00
|
|
|
final String code = (key == null) ? "----" : keyCodePrintable(key.mCode);
|
2010-12-18 11:04:44 +00:00
|
|
|
final long delta = eventTime - mPreviousEventTime;
|
|
|
|
Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %3d(%s)", title,
|
|
|
|
(mKeyAlreadyProcessed ? "-" : " "), mPointerId, x, y, delta, keyIndex, code));
|
|
|
|
mPreviousEventTime = eventTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String keyCodePrintable(int primaryCode) {
|
|
|
|
final String modifier = isModifierCode(primaryCode) ? " modifier" : "";
|
|
|
|
return String.format((primaryCode < 0) ? "%4d" : "0x%02x", primaryCode) + modifier;
|
2010-09-02 11:28:31 +00:00
|
|
|
}
|
2010-09-24 11:45:24 +00:00
|
|
|
}
|