2010-08-31 15:27:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardView.UIHandler;
|
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
|
|
|
|
2010-10-08 03:51:15 +00:00
|
|
|
import android.content.res.Resources;
|
2010-09-01 16:35:24 +00:00
|
|
|
import android.util.Log;
|
2010-09-06 05:26:46 +00:00
|
|
|
import android.view.MotionEvent;
|
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();
|
2010-12-21 05:01:13 +00:00
|
|
|
private static final boolean ENABLE_ASSERTION = false;
|
2010-12-18 11:04:44 +00:00
|
|
|
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
|
|
|
|
2010-08-31 15:27:04 +00:00
|
|
|
public interface UIProxy {
|
|
|
|
public void invalidateKey(Key key);
|
2011-04-19 06:18:20 +00:00
|
|
|
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
|
|
|
public void dismissKeyPreview(PointerTracker tracker);
|
2010-10-08 03:51:15 +00:00
|
|
|
public boolean hasDistinctMultitouch();
|
2011-01-14 18:49:21 +00:00
|
|
|
public boolean isAccessibilityEnabled();
|
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-04-19 06:18:20 +00:00
|
|
|
private final KeyboardView mKeyboardView;
|
2010-08-31 15:27:04 +00:00
|
|
|
private final UIProxy mProxy;
|
|
|
|
private final UIHandler mHandler;
|
2010-09-01 14:18:39 +00:00
|
|
|
private final 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-09-06 05:26:46 +00:00
|
|
|
private final boolean mHasDistinctMultitouch;
|
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;
|
2010-09-13 10:26:23 +00:00
|
|
|
private int mKeyHysteresisDistanceSquared = -1;
|
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
|
|
|
|
2011-01-14 18:49:21 +00:00
|
|
|
// true if accessibility is enabled in the parent keyboard
|
|
|
|
private boolean mIsAccessibilityEnabled;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onSwipeDown() {}
|
2010-12-18 11:04:44 +00:00
|
|
|
};
|
2010-09-24 11:45:24 +00:00
|
|
|
|
2011-04-19 06:18:20 +00:00
|
|
|
public PointerTracker(int id, KeyboardView keyboardView, UIHandler handler,
|
|
|
|
KeyDetector keyDetector, UIProxy proxy) {
|
2010-08-31 15:27:04 +00:00
|
|
|
if (proxy == null || handler == null || keyDetector == null)
|
|
|
|
throw new NullPointerException();
|
2010-09-01 16:07:11 +00:00
|
|
|
mPointerId = id;
|
2011-04-19 06:18:20 +00:00
|
|
|
mKeyboardView = keyboardView;
|
2010-08-31 15:27:04 +00:00
|
|
|
mProxy = proxy;
|
|
|
|
mHandler = handler;
|
|
|
|
mKeyDetector = keyDetector;
|
2010-12-17 07:56:15 +00:00
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2010-12-18 11:04:44 +00:00
|
|
|
mKeyState = new PointerTrackerKeyState(keyDetector);
|
2011-01-14 18:49:21 +00:00
|
|
|
mIsAccessibilityEnabled = proxy.isAccessibilityEnabled();
|
2010-10-08 03:51:15 +00:00
|
|
|
mHasDistinctMultitouch = proxy.hasDistinctMultitouch();
|
2011-04-19 06:18:20 +00:00
|
|
|
final Resources res = mKeyboardView.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);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
public void setOnKeyboardActionListener(KeyboardActionListener listener) {
|
2010-08-31 15:27:04 +00:00
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
2011-01-14 18:49:21 +00:00
|
|
|
public void setAccessibilityEnabled(boolean accessibilityEnabled) {
|
|
|
|
mIsAccessibilityEnabled = accessibilityEnabled;
|
|
|
|
}
|
|
|
|
|
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-02-20 07:50:46 +00:00
|
|
|
if (key.mEnabled) {
|
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-02-20 07:50:46 +00:00
|
|
|
if (key.mEnabled)
|
|
|
|
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);
|
|
|
|
if (key.mEnabled)
|
|
|
|
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-02-20 07:50:46 +00:00
|
|
|
if (key.mEnabled)
|
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-04-15 04:05:58 +00:00
|
|
|
public void setKeyboard(Keyboard keyboard, float keyHysteresisDistance) {
|
|
|
|
if (keyboard == null || keyHysteresisDistance < 0)
|
2010-08-31 15:27:04 +00:00
|
|
|
throw new IllegalArgumentException();
|
2010-10-02 06:17:27 +00:00
|
|
|
mKeyboard = keyboard;
|
2011-04-15 04:05:58 +00:00
|
|
|
mKeys = keyboard.getKeys();
|
2010-09-13 10:26:23 +00:00
|
|
|
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
2011-01-28 03:40:27 +00:00
|
|
|
final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
|
|
|
|
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
mProxy.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);
|
|
|
|
if (key != null && key.mEnabled) {
|
|
|
|
key.onPressed();
|
|
|
|
mProxy.invalidateKey(key);
|
|
|
|
}
|
2010-09-03 03:51:03 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
private void checkAssertion(PointerTrackerQueue queue) {
|
|
|
|
if (mHasDistinctMultitouch && queue == null)
|
|
|
|
throw new RuntimeException(
|
|
|
|
"PointerTrackerQueue must be passed on distinct multi touch device");
|
|
|
|
if (!mHasDistinctMultitouch && queue != null)
|
|
|
|
throw new RuntimeException(
|
|
|
|
"PointerTrackerQueue must be null on non-distinct multi touch device");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onTouchEvent(int action, int x, int y, long eventTime, PointerTrackerQueue queue) {
|
2010-09-06 05:26:46 +00:00
|
|
|
switch (action) {
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
2010-12-21 05:01:13 +00:00
|
|
|
onMoveEvent(x, y, eventTime, queue);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
case MotionEvent.ACTION_POINTER_DOWN:
|
2010-12-21 05:01:13 +00:00
|
|
|
onDownEvent(x, y, eventTime, queue);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
case MotionEvent.ACTION_POINTER_UP:
|
2010-12-21 05:01:13 +00:00
|
|
|
onUpEvent(x, y, eventTime, queue);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
2010-12-21 05:01:13 +00:00
|
|
|
onCancelEvent(x, y, eventTime, queue);
|
2010-09-06 05:26:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
public void onDownEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
|
|
|
if (ENABLE_ASSERTION) checkAssertion(queue);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-14 18:49:21 +00:00
|
|
|
// from modifier key, 3) this pointer is on mini-keyboard, or 4) accessibility is enabled.
|
2010-12-18 09:48:32 +00:00
|
|
|
mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex)
|
2011-01-14 18:49:21 +00:00
|
|
|
|| mKeyDetector instanceof MiniKeyboardKeyDetector
|
|
|
|
|| mIsAccessibilityEnabled;
|
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))
|
2010-12-30 07:51:36 +00:00
|
|
|
keyIndex = mKeyState.onDownKey(x, y, eventTime);
|
2011-04-07 08:16:30 +00:00
|
|
|
|
2011-01-14 18:49:21 +00:00
|
|
|
// Accessibility disables key repeat because users may need to pause on a key to hear
|
|
|
|
// its spoken description.
|
2011-04-18 10:07:20 +00:00
|
|
|
final Key key = getKey(keyIndex);
|
|
|
|
if (key != null && key.mRepeatable && !mIsAccessibilityEnabled) {
|
2010-09-01 08:50:24 +00:00
|
|
|
repeatKey(keyIndex);
|
2010-10-08 03:51:15 +00:00
|
|
|
mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this);
|
2010-09-07 03:20:03 +00:00
|
|
|
mIsRepeatableKey = true;
|
2010-09-01 08:50:24 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
|
|
|
if (ENABLE_ASSERTION) checkAssertion(queue);
|
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-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);
|
2010-12-19 11:27:11 +00:00
|
|
|
mHandler.cancelLongPressTimers();
|
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
|
|
|
return;
|
|
|
|
}
|
2011-04-21 03:22:00 +00:00
|
|
|
} else if (mKeyboard.needSpacebarPreview(keyIndex)) {
|
|
|
|
// Display spacebar slide language switcher.
|
|
|
|
showKeyPreview(keyIndex);
|
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);
|
2010-12-19 11:27:11 +00:00
|
|
|
mHandler.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
|
|
|
return;
|
|
|
|
}
|
2010-09-02 15:48:16 +00:00
|
|
|
}
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
|
|
|
if (ENABLE_ASSERTION) checkAssertion(queue);
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onUpEvent :", x, y, eventTime);
|
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.
|
|
|
|
queue.releaseAllPointersExcept(this, eventTime);
|
|
|
|
} 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.
|
|
|
|
public void onPhantomUpEvent(int x, int y, long eventTime) {
|
|
|
|
onUpEventInternal(x, y, eventTime, false);
|
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) {
|
2010-08-31 15:27:04 +00:00
|
|
|
mHandler.cancelKeyTimers();
|
2011-04-19 06:18:20 +00:00
|
|
|
mHandler.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;
|
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-04-18 10:07:20 +00:00
|
|
|
public void onLongPressed(PointerTrackerQueue queue) {
|
|
|
|
mKeyAlreadyProcessed = true;
|
|
|
|
queue.remove(this);
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:01:13 +00:00
|
|
|
public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
|
|
|
if (ENABLE_ASSERTION) checkAssertion(queue);
|
2010-12-18 11:04:44 +00:00
|
|
|
if (DEBUG_EVENT)
|
|
|
|
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
2010-12-21 05:01:13 +00:00
|
|
|
|
|
|
|
if (queue != null)
|
|
|
|
queue.remove(this);
|
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() {
|
2010-08-31 15:27:04 +00:00
|
|
|
mHandler.cancelKeyTimers();
|
2011-04-19 06:18:20 +00:00
|
|
|
mHandler.cancelShowKeyPreview(this);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void repeatKey(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) {
|
2010-09-13 10:26:23 +00:00
|
|
|
if (mKeys == null || mKeyHysteresisDistanceSquared < 0)
|
2010-08-31 15:27:04 +00:00
|
|
|
throw new IllegalStateException("keyboard and/or hysteresis 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-04-21 03:22:00 +00:00
|
|
|
return mKeys.get(curKey).squaredDistanceToEdge(x, y) >= mKeyHysteresisDistanceSquared;
|
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-04-21 09:24:41 +00:00
|
|
|
// The modifier key, such as shift key, should not show its key preview. If accessibility is
|
|
|
|
// turned on, the modifier key should show its key preview.
|
|
|
|
private boolean isKeyPreviewNotRequired(int keyIndex) {
|
2011-04-08 08:14:12 +00:00
|
|
|
final Key key = getKey(keyIndex);
|
2011-04-21 09:24:41 +00:00
|
|
|
if (!key.mEnabled)
|
|
|
|
return true;
|
|
|
|
if (mIsAccessibilityEnabled)
|
|
|
|
return false;
|
|
|
|
// 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;
|
|
|
|
mProxy.showKeyPreview(keyIndex, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dismissKeyPreview() {
|
|
|
|
mProxy.dismissKeyPreview(this);
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 06:17:27 +00:00
|
|
|
private void startLongPressTimer(int keyIndex) {
|
2011-01-14 18:49:21 +00:00
|
|
|
// Accessibility disables long press because users are likely to need to pause on a key
|
|
|
|
// for an unspecified duration in order to hear the key's spoken description.
|
|
|
|
if (mIsAccessibilityEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-02 06:17:27 +00:00
|
|
|
Key key = getKey(keyIndex);
|
2011-04-08 08:14:12 +00:00
|
|
|
if (!key.mEnabled)
|
|
|
|
return;
|
2010-12-20 11:30:26 +00:00
|
|
|
if (key.mCode == Keyboard.CODE_SHIFT) {
|
2010-10-22 10:35:23 +00:00
|
|
|
mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this);
|
2010-12-21 08:13:15 +00:00
|
|
|
} else if (key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY
|
|
|
|
&& mKeyboard.isManualTemporaryUpperCase()) {
|
|
|
|
// 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;
|
2010-12-17 07:56:15 +00:00
|
|
|
} else if (mKeyboardSwitcher.isInMomentaryAutoModeSwitchState()) {
|
|
|
|
// We use longer timeout for sliding finger input started from the symbols mode key.
|
2010-12-30 08:27:47 +00:00
|
|
|
mHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
|
|
|
mHandler.startLongPressTimer(mLongPressKeyTimeout, keyIndex, this);
|
|
|
|
}
|
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
|
|
|
|
// shift code, alternate character code should be sent.
|
2010-12-21 08:13:15 +00:00
|
|
|
if (mKeyboard.isManualTemporaryUpperCase()
|
|
|
|
&& key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY) {
|
2010-12-18 11:04:44 +00:00
|
|
|
code = key.mManualTemporaryUpperCaseCode;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public CharSequence getPreviewText(Key key) {
|
2010-12-20 11:30:26 +00:00
|
|
|
return key.mLabel;
|
2010-08-31 15:27:04 +00:00
|
|
|
}
|
2010-09-02 11:28:31 +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
|
|
|
}
|