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.os.SystemClock;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
import com.android.inputmethod.keyboard.LatinKeyboardBaseView.KeyTimerHandler;
|
2011-06-22 02:53:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.PointerTrackerKeyState;
|
|
|
|
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;
|
2011-04-22 02:09:48 +00:00
|
|
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
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-04 11:58:58 +00:00
|
|
|
public interface DrawingProxy {
|
2010-08-31 15:27:04 +00:00
|
|
|
public void invalidateKey(Key key);
|
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);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 16:07:11 +00:00
|
|
|
public final int mPointerId;
|
|
|
|
|
2010-08-31 15:27:04 +00:00
|
|
|
// Timing constants
|
2010-10-08 03:51:15 +00:00
|
|
|
private final int mDelayBeforeKeyRepeatStart;
|
|
|
|
private final int mLongPressKeyTimeout;
|
2010-10-22 10:35:23 +00:00
|
|
|
private final int mLongPressShiftKeyTimeout;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
private final DrawingProxy mDrawingProxy;
|
|
|
|
private final KeyTimerHandler mKeyTimerHandler;
|
2011-07-06 23:11:30 +00:00
|
|
|
private final PointerTrackerQueue mPointerTrackerQueue;
|
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 07:56:15 +00:00
|
|
|
private final KeyboardSwitcher mKeyboardSwitcher;
|
2010-12-18 09:48:32 +00:00
|
|
|
private final boolean mConfigSlidingKeyInputEnabled;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2010-12-17 05:13:01 +00:00
|
|
|
private final int mTouchNoiseThresholdMillis;
|
|
|
|
private final int mTouchNoiseThresholdDistanceSquared;
|
|
|
|
|
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;
|
2010-08-31 15:27:04 +00:00
|
|
|
|
2010-12-18 11:04:44 +00:00
|
|
|
private final PointerTrackerKeyState mKeyState;
|
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;
|
|
|
|
|
2010-09-03 03:51:03 +00:00
|
|
|
// true if event is already translated to a key action (long press or mini-keyboard)
|
|
|
|
private boolean mKeyAlreadyProcessed;
|
|
|
|
|
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
|
|
|
|
private boolean mIsInSlidingKeyInput;
|
|
|
|
|
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;
|
|
|
|
|
2011-04-22 02:09:48 +00:00
|
|
|
// TODO: Remove these hacking variables
|
|
|
|
// true if this pointer is in sliding language switch
|
|
|
|
private boolean mIsInSlidingLanguageSwitch;
|
|
|
|
private int mSpaceKeyIndex;
|
|
|
|
private final SubtypeSwitcher mSubtypeSwitcher;
|
|
|
|
|
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-04 11:58:58 +00:00
|
|
|
public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler,
|
2011-07-06 23:11:30 +00:00
|
|
|
KeyDetector keyDetector, DrawingProxy drawingProxy, PointerTrackerQueue queue) {
|
2011-07-04 11:58:58 +00:00
|
|
|
if (drawingProxy == null || keyTimerHandler == null || keyDetector == null)
|
2010-08-31 15:27:04 +00:00
|
|
|
throw new NullPointerException();
|
2010-09-01 16:07:11 +00:00
|
|
|
mPointerId = id;
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy = drawingProxy;
|
|
|
|
mKeyTimerHandler = keyTimerHandler;
|
2011-07-06 23:11:30 +00:00
|
|
|
mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device.
|
2010-12-18 11:04:44 +00:00
|
|
|
mKeyState = new PointerTrackerKeyState(keyDetector);
|
2011-07-08 05:31:29 +00:00
|
|
|
setKeyDetectorInner(keyDetector);
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2011-07-04 11:58:58 +00:00
|
|
|
final Resources res = context.getResources();
|
2010-12-18 09:48:32 +00:00
|
|
|
mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
|
2010-10-08 03:51:15 +00:00
|
|
|
mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
|
|
|
|
mLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout);
|
2010-10-22 10:35:23 +00:00
|
|
|
mLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout);
|
2010-12-17 05:13:01 +00:00
|
|
|
mTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis);
|
|
|
|
final float touchNoiseThresholdDistance = res.getDimension(
|
|
|
|
R.dimen.config_touch_noise_threshold_distance);
|
|
|
|
mTouchNoiseThresholdDistanceSquared = (int)(
|
|
|
|
touchNoiseThresholdDistance * touchNoiseThresholdDistance);
|
2011-04-22 02:09:48 +00:00
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 05:31:29 +00:00
|
|
|
public void setKeyboardActionListener(KeyboardActionListener listener) {
|
2010-08-31 15:27:04 +00:00
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
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();
|
2011-07-04 10:59:57 +00:00
|
|
|
mKeyState.setKeyDetector(keyDetector);
|
2011-07-08 05:31:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void setKeyDetector(KeyDetector keyDetector) {
|
|
|
|
if (keyDetector == null)
|
|
|
|
throw new NullPointerException();
|
|
|
|
setKeyDetectorInner(keyDetector);
|
2010-12-30 07:51:36 +00:00
|
|
|
// Mark that keyboard layout has been changed.
|
|
|
|
mKeyboardLayoutHasBeenChanged = true;
|
2010-08-31 15:27:04 +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() {
|
2010-09-24 11:45:24 +00:00
|
|
|
return isModifierInternal(mKeyState.getKeyIndex());
|
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
|
|
|
public void setReleasedKeyGraphics() {
|
|
|
|
setReleasedKeyGraphics(mKeyState.getKeyIndex());
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 10:07:20 +00:00
|
|
|
private void setReleasedKeyGraphics(int keyIndex) {
|
|
|
|
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) {
|
|
|
|
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-06 23:11:30 +00:00
|
|
|
public void onTouchEvent(int action, int x, int y, long eventTime) {
|
2010-09-06 05:26:46 +00:00
|
|
|
switch (action) {
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
2011-07-06 23:11:30 +00:00
|
|
|
onMoveEvent(x, y, eventTime);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
case MotionEvent.ACTION_POINTER_DOWN:
|
2011-07-06 23:11:30 +00:00
|
|
|
onDownEvent(x, y, eventTime);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
case MotionEvent.ACTION_POINTER_UP:
|
2011-07-06 23:11:30 +00:00
|
|
|
onUpEvent(x, y, eventTime);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
2011-07-06 23:11:30 +00:00
|
|
|
onCancelEvent(x, y, eventTime);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-06 23:11:30 +00:00
|
|
|
public void onDownEvent(int x, int y, long eventTime) {
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onDownEvent:", x, y, eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
|
2010-12-17 05:13:01 +00:00
|
|
|
// Naive up-to-down noise filter.
|
|
|
|
final long deltaT = eventTime - mKeyState.getUpTime();
|
|
|
|
if (deltaT < mTouchNoiseThresholdMillis) {
|
|
|
|
final int dx = x - mKeyState.getLastX();
|
|
|
|
final int dy = y - mKeyState.getLastY();
|
|
|
|
final int distanceSquared = (dx * dx + dy * dy);
|
|
|
|
if (distanceSquared < mTouchNoiseThresholdDistanceSquared) {
|
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-06 23:11:30 +00:00
|
|
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
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) {
|
2010-09-24 11:45:24 +00:00
|
|
|
int keyIndex = mKeyState.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.
|
2010-12-18 09:48:32 +00:00
|
|
|
mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || 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-22 02:09:48 +00:00
|
|
|
mIsInSlidingLanguageSwitch = 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))
|
2010-12-30 07:51:36 +00:00
|
|
|
keyIndex = mKeyState.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
|
|
|
showKeyPreview(keyIndex);
|
|
|
|
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-18 11:04:44 +00:00
|
|
|
final PointerTrackerKeyState keyState = mKeyState;
|
2010-12-17 05:13:01 +00:00
|
|
|
|
2011-04-22 02:09:48 +00:00
|
|
|
// TODO: Remove this hacking code
|
|
|
|
if (mIsInSlidingLanguageSwitch) {
|
|
|
|
((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - keyState.getKeyX());
|
|
|
|
showKeyPreview(mSpaceKeyIndex);
|
|
|
|
return;
|
|
|
|
}
|
2011-01-28 03:40:27 +00:00
|
|
|
final int lastX = keyState.getLastX();
|
|
|
|
final int lastY = keyState.getLastY();
|
2011-04-18 10:07:20 +00:00
|
|
|
final int oldKeyIndex = keyState.getKeyIndex();
|
|
|
|
final Key oldKey = getKey(oldKeyIndex);
|
2010-12-30 07:51:36 +00:00
|
|
|
int keyIndex = keyState.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))
|
2010-12-30 07:51:36 +00:00
|
|
|
keyIndex = keyState.onMoveKey(x, y);
|
2010-09-24 11:45:24 +00:00
|
|
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
2010-10-12 11:24:53 +00:00
|
|
|
startLongPressTimer(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
showKeyPreview(keyIndex);
|
|
|
|
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-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.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))
|
2010-12-30 07:51:36 +00:00
|
|
|
keyIndex = keyState.onMoveKey(x, y);
|
2010-12-18 09:48:32 +00:00
|
|
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
|
|
|
startLongPressTimer(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
setPressedKeyGraphics(keyIndex);
|
|
|
|
showKeyPreview(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-04-19 06:18:20 +00:00
|
|
|
onUpEventInternal(lastX, lastY, eventTime, true);
|
2011-01-28 03:40:27 +00:00
|
|
|
onDownEventInternal(x, y, eventTime);
|
|
|
|
} else {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2011-04-19 06:18:20 +00:00
|
|
|
dismissKeyPreview();
|
2011-04-18 10:07:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
// TODO: Remove this hack code
|
|
|
|
else if (isSpaceKey(keyIndex) && !mIsInSlidingLanguageSwitch
|
|
|
|
&& mKeyboard instanceof LatinKeyboard) {
|
|
|
|
final LatinKeyboard keyboard = ((LatinKeyboard)mKeyboard);
|
|
|
|
if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()
|
|
|
|
&& mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) {
|
|
|
|
final int diff = x - keyState.getKeyX();
|
|
|
|
if (keyboard.shouldTriggerSpacebarSlidingLanguageSwitch(diff)) {
|
|
|
|
// Detect start sliding language switch.
|
|
|
|
mIsInSlidingLanguageSwitch = true;
|
|
|
|
mSpaceKeyIndex = keyIndex;
|
|
|
|
keyboard.updateSpacebarPreviewIcon(diff);
|
|
|
|
// Display spacebar slide language switcher.
|
|
|
|
showKeyPreview(keyIndex);
|
2011-07-06 23:11:30 +00:00
|
|
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
2011-04-22 08:33:24 +00:00
|
|
|
if (queue != null)
|
|
|
|
queue.releaseAllPointersExcept(this, eventTime, true);
|
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-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.cancelLongPressTimers();
|
2010-12-18 09:48:32 +00:00
|
|
|
if (mIsAllowedSlidingKeyInput) {
|
2011-04-18 10:07:20 +00:00
|
|
|
keyState.onMoveToNewKey(keyIndex, x, y);
|
2010-12-18 09:48:32 +00:00
|
|
|
} else {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2011-04-19 06:18:20 +00:00
|
|
|
dismissKeyPreview();
|
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-06 23:11:30 +00:00
|
|
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
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-04-22 02:09:48 +00:00
|
|
|
queue.releaseAllPointersExcept(this, eventTime, true);
|
2010-12-21 05:01:13 +00:00
|
|
|
} else {
|
|
|
|
queue.releaseAllPointersOlderThan(this, eventTime);
|
|
|
|
}
|
|
|
|
queue.remove(this);
|
|
|
|
}
|
2011-04-19 06:18:20 +00:00
|
|
|
onUpEventInternal(x, y, eventTime, true);
|
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-04-22 02:09:48 +00:00
|
|
|
public void onPhantomUpEvent(int x, int y, long eventTime, boolean updateReleasedKeyGraphics) {
|
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onPhntEvent:", x, y, eventTime);
|
|
|
|
onUpEventInternal(x, y, eventTime, updateReleasedKeyGraphics);
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2010-12-21 05:01:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 06:18:20 +00:00
|
|
|
private void onUpEventInternal(int x, int y, long eventTime,
|
|
|
|
boolean updateReleasedKeyGraphics) {
|
2011-07-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.cancelKeyTimers();
|
|
|
|
mDrawingProxy.cancelShowKeyPreview(this);
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = false;
|
2010-12-18 11:04:44 +00:00
|
|
|
final PointerTrackerKeyState keyState = mKeyState;
|
2011-04-18 10:07:20 +00:00
|
|
|
final int keyX, keyY;
|
2011-04-21 03:22:00 +00:00
|
|
|
if (isMajorEnoughMoveToBeOnNewKey(x, y, keyState.onMoveKey(x, y))) {
|
2011-04-18 10:07:20 +00:00
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
|
|
|
} else {
|
|
|
|
// Use previous fixed key coordinates.
|
|
|
|
keyX = keyState.getKeyX();
|
|
|
|
keyY = keyState.getKeyY();
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2011-04-18 10:07:20 +00:00
|
|
|
final int keyIndex = keyState.onUpKey(keyX, keyY, eventTime);
|
2011-04-19 06:18:20 +00:00
|
|
|
dismissKeyPreview();
|
|
|
|
if (updateReleasedKeyGraphics)
|
|
|
|
setReleasedKeyGraphics(keyIndex);
|
2011-04-18 10:07:20 +00:00
|
|
|
if (mKeyAlreadyProcessed)
|
|
|
|
return;
|
2011-04-22 02:09:48 +00:00
|
|
|
// TODO: Remove this hacking code
|
|
|
|
if (mIsInSlidingLanguageSwitch) {
|
|
|
|
setReleasedKeyGraphics(mSpaceKeyIndex);
|
|
|
|
final int languageDir = ((LatinKeyboard)mKeyboard).getLanguageChangeDirection();
|
|
|
|
if (languageDir != 0) {
|
|
|
|
final int code = (languageDir == 1)
|
|
|
|
? LatinKeyboard.CODE_NEXT_LANGUAGE : LatinKeyboard.CODE_PREV_LANGUAGE;
|
|
|
|
// This will change keyboard layout.
|
|
|
|
mListener.onCodeInput(code, new int[] {code}, keyX, keyY);
|
|
|
|
}
|
|
|
|
mIsInSlidingLanguageSwitch = false;
|
2011-04-22 09:49:15 +00:00
|
|
|
((LatinKeyboard)mKeyboard).setSpacebarSlidingLanguageSwitchDiff(0);
|
2011-04-22 02:09:48 +00:00
|
|
|
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-06 23:11:30 +00:00
|
|
|
public void onLongPressed() {
|
2011-04-18 10:07:20 +00:00
|
|
|
mKeyAlreadyProcessed = true;
|
2011-07-06 23:11:30 +00:00
|
|
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
2011-06-08 07:58:08 +00:00
|
|
|
if (queue != null) {
|
|
|
|
// TODO: Support chording + long-press input.
|
|
|
|
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
|
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-06 23:11:30 +00:00
|
|
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
2011-04-22 02:09:48 +00:00
|
|
|
if (queue != null) {
|
|
|
|
queue.releaseAllPointersExcept(this, eventTime, true);
|
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-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.cancelKeyTimers();
|
|
|
|
mDrawingProxy.cancelShowKeyPreview(this);
|
2011-04-19 06:18:20 +00:00
|
|
|
dismissKeyPreview();
|
2011-04-18 10:07:20 +00:00
|
|
|
setReleasedKeyGraphics(mKeyState.getKeyIndex());
|
2010-12-20 07:21:54 +00:00
|
|
|
mIsInSlidingKeyInput = 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
|
|
|
dismissKeyPreview();
|
|
|
|
onRepeatKey(keyIndex);
|
2011-07-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, 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
|
|
|
}
|
|
|
|
|
2010-09-02 12:54:26 +00:00
|
|
|
public int getLastX() {
|
2010-09-24 11:45:24 +00:00
|
|
|
return mKeyState.getLastX();
|
2010-09-02 12:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getLastY() {
|
2010-09-24 11:45:24 +00:00
|
|
|
return mKeyState.getLastY();
|
2010-09-02 12:54:26 +00:00
|
|
|
}
|
|
|
|
|
2010-09-02 15:48:16 +00:00
|
|
|
public long getDownTime() {
|
2010-09-24 11:45:24 +00:00
|
|
|
return mKeyState.getDownTime();
|
2010-09-02 15:48:16 +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");
|
2010-09-24 11:45:24 +00:00
|
|
|
int curKey = mKeyState.getKeyIndex();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-11 11:48:20 +00:00
|
|
|
// The modifier key, such as shift key, should not show its key preview.
|
2011-04-21 09:24:41 +00:00
|
|
|
private boolean isKeyPreviewNotRequired(int keyIndex) {
|
2011-04-08 08:14:12 +00:00
|
|
|
final Key key = getKey(keyIndex);
|
2011-06-23 12:23:44 +00:00
|
|
|
if (key == null || !key.isEnabled())
|
2011-04-21 09:24:41 +00:00
|
|
|
return true;
|
|
|
|
// Such as spacebar sliding language switch.
|
|
|
|
if (mKeyboard.needSpacebarPreview(keyIndex))
|
|
|
|
return false;
|
|
|
|
final int code = key.mCode;
|
|
|
|
return isModifierCode(code) || code == Keyboard.CODE_DELETE
|
|
|
|
|| code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showKeyPreview(int keyIndex) {
|
|
|
|
if (isKeyPreviewNotRequired(keyIndex))
|
2011-04-19 06:18:20 +00:00
|
|
|
return;
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.showKeyPreview(keyIndex, this);
|
2011-04-19 06:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void dismissKeyPreview() {
|
2011-07-04 11:58:58 +00:00
|
|
|
mDrawingProxy.dismissKeyPreview(this);
|
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-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, 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-04-26 05:27:35 +00:00
|
|
|
} else if (mKeyboardSwitcher.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-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
2011-07-04 11:58:58 +00:00
|
|
|
mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout, 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
|
|
|
}
|