Remove KeyEventHandler
Change-Id: Iddde1f85139cb21bde6e4fc275c32f3d62f4862f
This commit is contained in:
parent
5d311f2c13
commit
770b00874b
4 changed files with 126 additions and 188 deletions
|
@ -24,7 +24,6 @@ import android.animation.ObjectAnimator;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
|
@ -49,8 +48,6 @@ import android.widget.TextView;
|
|||
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
||||
import com.android.inputmethod.annotations.ExternallyReferenced;
|
||||
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
||||
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
||||
import com.android.inputmethod.keyboard.internal.DrawingHandler;
|
||||
import com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText;
|
||||
import com.android.inputmethod.keyboard.internal.GestureTrailsPreview;
|
||||
|
@ -120,9 +117,8 @@ import java.util.WeakHashMap;
|
|||
* @attr ref R.styleable#MainKeyboardView_gestureRecognitionSpeedThreshold
|
||||
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
|
||||
*/
|
||||
public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
|
||||
PointerTracker.DrawingProxy, MoreKeysPanel.Controller, DrawingHandler.Callbacks,
|
||||
TimerHandler.Callbacks {
|
||||
public final class MainKeyboardView extends KeyboardView implements PointerTracker.DrawingProxy,
|
||||
MoreKeysPanel.Controller, DrawingHandler.Callbacks, TimerHandler.Callbacks {
|
||||
private static final String TAG = MainKeyboardView.class.getSimpleName();
|
||||
|
||||
/** Listener for {@link KeyboardActionListener}. */
|
||||
|
@ -214,8 +210,27 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
final Resources res = getResources();
|
||||
PointerTracker.init(res);
|
||||
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
|
||||
|
||||
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||
final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
|
||||
final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
|
||||
mKeyTimerHandler = new TimerHandler(
|
||||
this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);
|
||||
|
||||
final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
|
||||
final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
|
||||
mKeyDetector = new KeyDetector(
|
||||
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
|
||||
|
||||
PointerTracker.init(mainKeyboardViewAttr, mKeyTimerHandler, this /* DrawingProxy */,
|
||||
mKeyDetector);
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final boolean forceNonDistinctMultitouch = prefs.getBoolean(
|
||||
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false);
|
||||
|
@ -223,12 +238,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)
|
||||
&& !forceNonDistinctMultitouch;
|
||||
mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
|
||||
: new NonDistinctMultitouchHelper();
|
||||
: new NonDistinctMultitouchHelper(PointerTracker.getPointerTracker(0));
|
||||
|
||||
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
|
||||
|
||||
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||
final int backgroundDimAlpha = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
|
||||
mBackgroundDimAlphaPaint.setColor(Color.BLACK);
|
||||
|
@ -253,18 +264,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
||||
|
||||
final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
|
||||
final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
|
||||
mKeyDetector = new KeyDetector(
|
||||
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
|
||||
final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
|
||||
final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
|
||||
mKeyTimerHandler = new TimerHandler(
|
||||
this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);
|
||||
mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
|
||||
R.styleable.MainKeyboardView_keyPreviewOffset, 0);
|
||||
mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
|
||||
|
@ -287,7 +286,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
|
||||
mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
|
||||
PointerTracker.setParameters(mainKeyboardViewAttr);
|
||||
|
||||
mGestureFloatingPreviewText = new GestureFloatingPreviewText(
|
||||
mPreviewPlacerView, mainKeyboardViewAttr);
|
||||
|
@ -313,7 +311,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
|
||||
mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
|
||||
|
||||
mLanguageOnSpacebarHorizontalMargin = (int)res.getDimension(
|
||||
mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
|
||||
R.dimen.config_language_on_spacebar_horizontal_margin);
|
||||
}
|
||||
|
||||
|
@ -402,28 +400,16 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
PointerTracker.setKeyboardActionListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link KeyboardActionListener} object.
|
||||
* @return the listener attached to this keyboard
|
||||
*/
|
||||
@Override
|
||||
public KeyboardActionListener getKeyboardActionListener() {
|
||||
return mKeyboardActionListener;
|
||||
// TODO: We should reconsider which coordinate system should be used to represent keyboard
|
||||
// event.
|
||||
public int getKeyX(final int x) {
|
||||
return Constants.isValidCoordinate(x) ? mKeyDetector.getTouchX(x) : x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyDetector getKeyDetector() {
|
||||
return mKeyDetector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawingProxy getDrawingProxy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimerProxy getTimerProxy() {
|
||||
return mKeyTimerHandler;
|
||||
// TODO: We should reconsider which coordinate system should be used to represent keyboard
|
||||
// event.
|
||||
public int getKeyY(final int y) {
|
||||
return Constants.isValidCoordinate(y) ? mKeyDetector.getTouchY(y) : y;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -441,6 +427,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
mKeyDetector.setKeyboard(
|
||||
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
|
||||
PointerTracker.setKeyDetector(mKeyDetector);
|
||||
PointerTracker.setKeyboardActionListener(mKeyboardActionListener);
|
||||
mMoreKeysKeyboardCache.clear();
|
||||
|
||||
mSpaceKey = keyboard.getKey(Constants.CODE_SPACE);
|
||||
|
@ -999,7 +986,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
mKeyTimerHandler.cancelKeyRepeatTimer();
|
||||
}
|
||||
// Non distinct multitouch screen support
|
||||
mNonDistinctMultitouchHelper.processMotionEvent(me, this);
|
||||
mNonDistinctMultitouchHelper.processMotionEvent(me, mKeyDetector);
|
||||
return true;
|
||||
}
|
||||
return processMotionEvent(me);
|
||||
|
@ -1016,8 +1003,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
|
||||
final int index = me.getActionIndex();
|
||||
final int id = me.getPointerId(index);
|
||||
final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
|
||||
tracker.processMotionEvent(me, this);
|
||||
final PointerTracker tracker = PointerTracker.getPointerTracker(id);
|
||||
tracker.processMotionEvent(me, mKeyDetector);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1033,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
@Override
|
||||
public boolean dispatchHoverEvent(final MotionEvent event) {
|
||||
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
|
||||
final PointerTracker tracker = PointerTracker.getPointerTracker(0, this);
|
||||
final PointerTracker tracker = PointerTracker.getPointerTracker(0);
|
||||
return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(event, tracker);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,33 +55,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
private static boolean sGestureHandlingEnabledByInputField = false;
|
||||
private static boolean sGestureHandlingEnabledByUser = false;
|
||||
|
||||
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 PointerTracke
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
public interface DrawingProxy {
|
||||
public void invalidateKey(Key key);
|
||||
public void showKeyPreview(Key key);
|
||||
|
@ -142,18 +115,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
public final int mKeyRepeatInterval;
|
||||
public final int mLongPressShiftLockTimeout;
|
||||
|
||||
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
|
||||
|
||||
private PointerTrackerParams() {
|
||||
mKeySelectionByDraggingFinger = false;
|
||||
mTouchNoiseThresholdTime = 0;
|
||||
mTouchNoiseThresholdDistance = 0;
|
||||
mSuppressKeyPreviewAfterBatchInputDuration = 0;
|
||||
mKeyRepeatStartTimeout = 0;
|
||||
mKeyRepeatInterval = 0;
|
||||
mLongPressShiftLockTimeout = 0;
|
||||
}
|
||||
|
||||
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
|
||||
mKeySelectionByDraggingFinger = mainKeyboardViewAttr.getBoolean(
|
||||
R.styleable.MainKeyboardView_keySelectionByDraggingFinger, false);
|
||||
|
@ -189,10 +150,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
|
||||
public final int mPointerId;
|
||||
|
||||
private DrawingProxy mDrawingProxy;
|
||||
private TimerProxy mTimerProxy;
|
||||
private static DrawingProxy sDrawingProxy;
|
||||
private static TimerProxy sTimerProxy;
|
||||
private static KeyDetector sDefaultKeyDetector;
|
||||
private KeyDetector mKeyDetector;
|
||||
private KeyboardActionListener mListener = KeyboardActionListener.EMPTY_LISTENER;
|
||||
private static KeyboardActionListener sListener = KeyboardActionListener.EMPTY_LISTENER;
|
||||
|
||||
private Keyboard mKeyboard;
|
||||
private int mPhantomSuddenMoveThreshold;
|
||||
|
@ -377,22 +339,26 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
return needsTheHack;
|
||||
}
|
||||
|
||||
public static void init(final Resources res) {
|
||||
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
|
||||
ResourceUtils.getDeviceOverrideValue(
|
||||
res, R.array.phantom_sudden_move_event_device_list));
|
||||
sNeedsProximateBogusDownMoveUpEventHack = needsProximateBogusDownMoveUpEventHack(res);
|
||||
sParams = PointerTrackerParams.DEFAULT;
|
||||
sGestureStrokeParams = GestureStrokeParams.DEFAULT;
|
||||
sGesturePreviewParams = GestureStrokePreviewParams.DEFAULT;
|
||||
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
|
||||
}
|
||||
|
||||
public static void setParameters(final TypedArray mainKeyboardViewAttr) {
|
||||
// TODO: Add PointerTrackerFactory singleton and move some class static methods into it.
|
||||
public static void init(final TypedArray mainKeyboardViewAttr, final TimerProxy timerProxy,
|
||||
final DrawingProxy drawingProxy, final KeyDetector defaultKeyDetector) {
|
||||
sParams = new PointerTrackerParams(mainKeyboardViewAttr);
|
||||
sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
|
||||
sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
|
||||
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
|
||||
|
||||
final Resources res = mainKeyboardViewAttr.getResources();
|
||||
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
|
||||
ResourceUtils.getDeviceOverrideValue(
|
||||
res, R.array.phantom_sudden_move_event_device_list));
|
||||
sNeedsProximateBogusDownMoveUpEventHack = needsProximateBogusDownMoveUpEventHack(res);
|
||||
sGestureStrokeParams = GestureStrokeParams.DEFAULT;
|
||||
sGesturePreviewParams = GestureStrokePreviewParams.DEFAULT;
|
||||
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
|
||||
|
||||
sTimerProxy = timerProxy;
|
||||
sDrawingProxy = drawingProxy;
|
||||
sDefaultKeyDetector = defaultKeyDetector;
|
||||
}
|
||||
|
||||
private static void updateGestureHandlingMode() {
|
||||
|
@ -413,12 +379,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
updateGestureHandlingMode();
|
||||
}
|
||||
|
||||
public static PointerTracker getPointerTracker(final int id, final KeyEventHandler handler) {
|
||||
public static PointerTracker getPointerTracker(final int id) {
|
||||
final ArrayList<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);
|
||||
final PointerTracker tracker = new PointerTracker(i);
|
||||
trackers.add(tracker);
|
||||
}
|
||||
|
||||
|
@ -434,11 +400,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
public static void setKeyboardActionListener(final KeyboardActionListener listener) {
|
||||
final int trackersSize = sTrackers.size();
|
||||
for (int i = 0; i < trackersSize; ++i) {
|
||||
final PointerTracker tracker = sTrackers.get(i);
|
||||
tracker.mListener = listener;
|
||||
}
|
||||
sListener = listener;
|
||||
}
|
||||
|
||||
public static void setKeyDetector(final KeyDetector keyDetector) {
|
||||
|
@ -468,21 +430,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
}
|
||||
|
||||
private PointerTracker(final int id, final KeyEventHandler handler) {
|
||||
if (handler == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
private PointerTracker(final int id) {
|
||||
mPointerId = id;
|
||||
mGestureStrokeWithPreviewPoints = new GestureStrokeWithPreviewPoints(
|
||||
id, sGestureStrokeParams, sGesturePreviewParams);
|
||||
setKeyEventHandler(handler);
|
||||
}
|
||||
|
||||
private void setKeyEventHandler(final KeyEventHandler handler) {
|
||||
setKeyDetectorInner(handler.getKeyDetector());
|
||||
mListener = handler.getKeyboardActionListener();
|
||||
mDrawingProxy = handler.getDrawingProxy();
|
||||
mTimerProxy = handler.getTimerProxy();
|
||||
setKeyDetectorInner(sDefaultKeyDetector);
|
||||
}
|
||||
|
||||
// Returns true if keyboard has been changed by this callback.
|
||||
|
@ -507,10 +459,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
return false;
|
||||
}
|
||||
if (key.isEnabled()) {
|
||||
mListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
|
||||
sListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
|
||||
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
|
||||
mKeyboardLayoutHasBeenChanged = false;
|
||||
mTimerProxy.startTypingStateTimer(key);
|
||||
sTimerProxy.startTypingStateTimer(key);
|
||||
return keyboardLayoutHasBeenChanged;
|
||||
}
|
||||
return false;
|
||||
|
@ -521,7 +473,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
|
||||
final int y, final long eventTime) {
|
||||
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
|
||||
final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
|
||||
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final int code = altersCode ? key.getAltCode() : primaryCode;
|
||||
if (DEBUG_LISTENER) {
|
||||
final String output = code == Constants.CODE_OUTPUT_TEXT
|
||||
|
@ -541,9 +493,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (key.isEnabled() || altersCode) {
|
||||
sTimeRecorder.onCodeInput(code, eventTime);
|
||||
if (code == Constants.CODE_OUTPUT_TEXT) {
|
||||
mListener.onTextInput(key.getOutputText());
|
||||
sListener.onTextInput(key.getOutputText());
|
||||
} else if (code != Constants.CODE_UNSPECIFIED) {
|
||||
mListener.onCodeInput(code, x, y);
|
||||
sListener.onCodeInput(code, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -571,7 +523,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
return;
|
||||
}
|
||||
if (key.isEnabled()) {
|
||||
mListener.onReleaseKey(primaryCode, withSliding);
|
||||
sListener.onReleaseKey(primaryCode, withSliding);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -579,7 +531,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (DEBUG_LISTENER) {
|
||||
Log.d(TAG, String.format("[%d] onFinishSlidingInput", mPointerId));
|
||||
}
|
||||
mListener.onFinishSlidingInput();
|
||||
sListener.onFinishSlidingInput();
|
||||
}
|
||||
|
||||
private void callListenerOnCancelInput() {
|
||||
|
@ -589,7 +541,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
||||
ResearchLogger.pointerTracker_callListenerOnCancelInput();
|
||||
}
|
||||
mListener.onCancelInput();
|
||||
sListener.onCancelInput();
|
||||
}
|
||||
|
||||
private void setKeyDetectorInner(final KeyDetector keyDetector) {
|
||||
|
@ -606,7 +558,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
mGestureStrokeWithPreviewPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
|
||||
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
|
||||
if (newKey != mCurrentKey) {
|
||||
if (mDrawingProxy != null) {
|
||||
if (sDrawingProxy != null) {
|
||||
setReleasedKeyGraphics(mCurrentKey);
|
||||
}
|
||||
// Keep {@link #mCurrentKey} that comes from previous keyboard.
|
||||
|
@ -634,7 +586,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
private void setReleasedKeyGraphics(final Key key) {
|
||||
mDrawingProxy.dismissKeyPreview(key);
|
||||
sDrawingProxy.dismissKeyPreview(key);
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -675,14 +627,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
|
||||
final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
|
||||
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final boolean needsToUpdateGraphics = key.isEnabled() || altersCode;
|
||||
if (!needsToUpdateGraphics) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!key.noKeyPreview() && !sInGesture && !needsToSuppressKeyPreviewPopup(eventTime)) {
|
||||
mDrawingProxy.showKeyPreview(key);
|
||||
sDrawingProxy.showKeyPreview(key);
|
||||
}
|
||||
updatePressKeyGraphics(key);
|
||||
|
||||
|
@ -694,7 +646,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
}
|
||||
|
||||
if (key.altCodeWhileTyping() && mTimerProxy.isTypingState()) {
|
||||
if (key.altCodeWhileTyping() && sTimerProxy.isTypingState()) {
|
||||
final int altCode = key.getAltCode();
|
||||
final Key altKey = mKeyboard.getKey(altCode);
|
||||
if (altKey != null) {
|
||||
|
@ -708,14 +660,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateReleaseKeyGraphics(final Key key) {
|
||||
private static void updateReleaseKeyGraphics(final Key key) {
|
||||
key.onReleased();
|
||||
mDrawingProxy.invalidateKey(key);
|
||||
sDrawingProxy.invalidateKey(key);
|
||||
}
|
||||
|
||||
private void updatePressKeyGraphics(final Key key) {
|
||||
private static void updatePressKeyGraphics(final Key key) {
|
||||
key.onPressed();
|
||||
mDrawingProxy.invalidateKey(key);
|
||||
sDrawingProxy.invalidateKey(key);
|
||||
}
|
||||
|
||||
public GestureStrokeWithPreviewPoints getGestureStrokeWithPreviewPoints() {
|
||||
|
@ -786,12 +738,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
sAggregratedPointers.reset();
|
||||
sLastRecognitionPointSize = 0;
|
||||
sLastRecognitionTime = 0;
|
||||
mListener.onStartBatchInput();
|
||||
sListener.onStartBatchInput();
|
||||
dismissAllMoreKeysPanels();
|
||||
}
|
||||
mTimerProxy.cancelLongPressTimer();
|
||||
sTimerProxy.cancelLongPressTimer();
|
||||
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
||||
mDrawingProxy.showGestureTrail(
|
||||
sDrawingProxy.showGestureTrail(
|
||||
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
||||
}
|
||||
|
||||
|
@ -809,7 +761,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
return;
|
||||
}
|
||||
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
||||
mDrawingProxy.showGestureTrail(
|
||||
sDrawingProxy.showGestureTrail(
|
||||
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
||||
}
|
||||
|
||||
|
@ -824,8 +776,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
|
||||
size));
|
||||
}
|
||||
mTimerProxy.startUpdateBatchInputTimer(this);
|
||||
mListener.onUpdateBatchInput(sAggregratedPointers);
|
||||
sTimerProxy.startUpdateBatchInputTimer(this);
|
||||
sListener.onUpdateBatchInput(sAggregratedPointers);
|
||||
// The listener may change the size of the pointers (when auto-committing
|
||||
// for example), so we need to get the size from the pointers again.
|
||||
sLastRecognitionPointSize = sAggregratedPointers.getPointerSize();
|
||||
|
@ -840,13 +792,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (getActivePointerTrackerCount() == 1) {
|
||||
sInGesture = false;
|
||||
sTimeRecorder.onEndBatchInput(eventTime);
|
||||
mTimerProxy.cancelAllUpdateBatchInputTimers();
|
||||
sTimerProxy.cancelAllUpdateBatchInputTimers();
|
||||
if (!mIsTrackingForActionDisabled) {
|
||||
if (DEBUG_LISTENER) {
|
||||
Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d",
|
||||
mPointerId, sAggregratedPointers.getPointerSize()));
|
||||
}
|
||||
mListener.onEndBatchInput(sAggregratedPointers);
|
||||
sListener.onEndBatchInput(sAggregratedPointers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -854,7 +806,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
return;
|
||||
}
|
||||
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
|
||||
mDrawingProxy.showGestureTrail(
|
||||
sDrawingProxy.showGestureTrail(
|
||||
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
|
||||
}
|
||||
|
||||
|
@ -868,17 +820,17 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (DEBUG_LISTENER) {
|
||||
Log.d(TAG, String.format("[%d] onCancelBatchInput", mPointerId));
|
||||
}
|
||||
mListener.onCancelBatchInput();
|
||||
sListener.onCancelBatchInput();
|
||||
}
|
||||
|
||||
public void processMotionEvent(final MotionEvent me, final KeyEventHandler handler) {
|
||||
public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) {
|
||||
final int action = me.getActionMasked();
|
||||
final long eventTime = me.getEventTime();
|
||||
if (action == MotionEvent.ACTION_MOVE) {
|
||||
final int pointerCount = me.getPointerCount();
|
||||
for (int index = 0; index < pointerCount; index++) {
|
||||
final int id = me.getPointerId(index);
|
||||
final PointerTracker tracker = getPointerTracker(id, handler);
|
||||
final PointerTracker tracker = getPointerTracker(id);
|
||||
final int x = (int)me.getX(index);
|
||||
final int y = (int)me.getY(index);
|
||||
tracker.onMoveEvent(x, y, eventTime, me);
|
||||
|
@ -891,7 +843,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
onDownEvent(x, y, eventTime, handler);
|
||||
onDownEvent(x, y, eventTime, keyDetector);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
|
@ -904,11 +856,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
private void onDownEvent(final int x, final int y, final long eventTime,
|
||||
final KeyEventHandler handler) {
|
||||
final KeyDetector keyDetector) {
|
||||
if (DEBUG_EVENT) {
|
||||
printTouchEvent("onDownEvent:", x, y, eventTime);
|
||||
}
|
||||
setKeyEventHandler(handler);
|
||||
setKeyDetectorInner(keyDetector);
|
||||
// Naive up-to-down noise filter.
|
||||
final long deltaT = eventTime - mUpTime;
|
||||
if (deltaT < sParams.mTouchNoiseThresholdTime) {
|
||||
|
@ -998,7 +950,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
private void resetKeySelectionByDraggingFinger() {
|
||||
mIsInDraggingFinger = false;
|
||||
mIsInSlidingKeyInput = false;
|
||||
mDrawingProxy.dismissSlidingKeyInputPreview();
|
||||
sDrawingProxy.dismissSlidingKeyInputPreview();
|
||||
}
|
||||
|
||||
private void onGestureMoveEvent(final int x, final int y, final long eventTime,
|
||||
|
@ -1009,7 +961,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard(
|
||||
x, y, gestureTime, isMajorEvent);
|
||||
if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) {
|
||||
mTimerProxy.startUpdateBatchInputTimer(this);
|
||||
sTimerProxy.startUpdateBatchInputTimer(this);
|
||||
}
|
||||
// If the move event goes out from valid batch input area, cancel batch input.
|
||||
if (!onValidArea) {
|
||||
|
@ -1055,7 +1007,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
|
||||
onMoveKey(x, y);
|
||||
if (mIsInSlidingKeyInput) {
|
||||
mDrawingProxy.showSlidingKeyInputPreview(this);
|
||||
sDrawingProxy.showSlidingKeyInputPreview(this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1120,7 +1072,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
setReleasedKeyGraphics(oldKey);
|
||||
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
|
||||
startKeySelectionByDraggingFinger(oldKey);
|
||||
mTimerProxy.cancelKeyTimers();
|
||||
sTimerProxy.cancelKeyTimers();
|
||||
}
|
||||
|
||||
private void dragFingerFromOldKeyToNewKey(final Key key, final int x, final int y,
|
||||
|
@ -1212,7 +1164,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
}
|
||||
if (mIsInSlidingKeyInput) {
|
||||
mDrawingProxy.showSlidingKeyInputPreview(this);
|
||||
sDrawingProxy.showSlidingKeyInputPreview(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1173,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
printTouchEvent("onUpEvent :", x, y, eventTime);
|
||||
}
|
||||
|
||||
mTimerProxy.cancelUpdateBatchInputTimer(this);
|
||||
sTimerProxy.cancelUpdateBatchInputTimer(this);
|
||||
if (!sInGesture) {
|
||||
if (mCurrentKey != null && mCurrentKey.isModifier()) {
|
||||
// Before processing an up event of modifier key, all pointers already being
|
||||
|
@ -1251,7 +1203,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
private void onUpEventInternal(final int x, final int y, final long eventTime) {
|
||||
mTimerProxy.cancelKeyTimers();
|
||||
sTimerProxy.cancelKeyTimers();
|
||||
final boolean isInDraggingFinger = mIsInDraggingFinger;
|
||||
final boolean isInSlidingKeyInput = mIsInSlidingKeyInput;
|
||||
resetKeySelectionByDraggingFinger();
|
||||
|
@ -1330,7 +1282,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
}
|
||||
|
||||
private void onCancelEventInternal() {
|
||||
mTimerProxy.cancelKeyTimers();
|
||||
sTimerProxy.cancelKeyTimers();
|
||||
setReleasedKeyGraphics(mCurrentKey);
|
||||
resetKeySelectionByDraggingFinger();
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
|
@ -1393,7 +1345,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
if (mIsInDraggingFinger && key.getMoreKeys() == null) return;
|
||||
|
||||
final int delay = getLongPressTimeout(key.getCode());
|
||||
mTimerProxy.startLongPressTimer(this, delay);
|
||||
sTimerProxy.startLongPressTimer(this, delay);
|
||||
}
|
||||
|
||||
private int getLongPressTimeout(final int code) {
|
||||
|
@ -1446,7 +1398,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
|||
private void startKeyRepeatTimer(final int repeatCount) {
|
||||
final int delay =
|
||||
(repeatCount == 1) ? sParams.mKeyRepeatStartTimeout : sParams.mKeyRepeatInterval;
|
||||
mTimerProxy.startKeyRepeatTimer(this, repeatCount, delay);
|
||||
sTimerProxy.startKeyRepeatTimer(this, repeatCount, delay);
|
||||
}
|
||||
|
||||
private void printTouchEvent(final String title, final int x, final int y,
|
||||
|
|
|
@ -20,18 +20,24 @@ import android.util.Log;
|
|||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.inputmethod.keyboard.Key;
|
||||
import com.android.inputmethod.keyboard.KeyDetector;
|
||||
import com.android.inputmethod.keyboard.PointerTracker;
|
||||
import com.android.inputmethod.keyboard.PointerTracker.KeyEventHandler;
|
||||
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||
|
||||
public final class NonDistinctMultitouchHelper {
|
||||
private static final String TAG = NonDistinctMultitouchHelper.class.getSimpleName();
|
||||
|
||||
// Use only main (id=0) pointer tracker.
|
||||
private final PointerTracker mMainTracker;
|
||||
private int mOldPointerCount = 1;
|
||||
private Key mOldKey;
|
||||
private int[] mLastCoords = CoordinateUtils.newInstance();
|
||||
|
||||
public void processMotionEvent(final MotionEvent me, final KeyEventHandler keyEventHandler) {
|
||||
public NonDistinctMultitouchHelper(final PointerTracker mainTracker) {
|
||||
mMainTracker = mainTracker;
|
||||
}
|
||||
|
||||
public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) {
|
||||
final int pointerCount = me.getPointerCount();
|
||||
final int oldPointerCount = mOldPointerCount;
|
||||
mOldPointerCount = pointerCount;
|
||||
|
@ -41,8 +47,7 @@ public final class NonDistinctMultitouchHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
// Use only main (id=0) pointer tracker.
|
||||
final PointerTracker mainTracker = PointerTracker.getPointerTracker(0, keyEventHandler);
|
||||
final PointerTracker mainTracker = mMainTracker;
|
||||
final int action = me.getActionMasked();
|
||||
final int index = me.getActionIndex();
|
||||
final long eventTime = me.getEventTime();
|
||||
|
@ -51,12 +56,12 @@ public final class NonDistinctMultitouchHelper {
|
|||
// In single-touch.
|
||||
if (oldPointerCount == 1 && pointerCount == 1) {
|
||||
if (me.getPointerId(index) == mainTracker.mPointerId) {
|
||||
mainTracker.processMotionEvent(me, keyEventHandler);
|
||||
mainTracker.processMotionEvent(me, keyDetector);
|
||||
return;
|
||||
}
|
||||
// Inject a copied event.
|
||||
injectMotionEvent(action, me.getX(index), me.getY(index), downTime, eventTime,
|
||||
mainTracker, keyEventHandler);
|
||||
mainTracker, keyDetector);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -70,7 +75,7 @@ public final class NonDistinctMultitouchHelper {
|
|||
mOldKey = mainTracker.getKeyOn(x, y);
|
||||
// Inject an artifact up event for the old key.
|
||||
injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime,
|
||||
mainTracker, keyEventHandler);
|
||||
mainTracker, keyDetector);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -85,11 +90,11 @@ public final class NonDistinctMultitouchHelper {
|
|||
// Inject an artifact down event for the new key.
|
||||
// An artifact up event for the new key will usually be injected as a single-touch.
|
||||
injectMotionEvent(MotionEvent.ACTION_DOWN, x, y, downTime, eventTime,
|
||||
mainTracker, keyEventHandler);
|
||||
mainTracker, keyDetector);
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
// Inject an artifact up event for the new key also.
|
||||
injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime,
|
||||
mainTracker, keyEventHandler);
|
||||
mainTracker, keyDetector);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -101,11 +106,11 @@ public final class NonDistinctMultitouchHelper {
|
|||
|
||||
private static void injectMotionEvent(final int action, final float x, final float y,
|
||||
final long downTime, final long eventTime, final PointerTracker tracker,
|
||||
final KeyEventHandler handler) {
|
||||
final KeyDetector keyDetector) {
|
||||
final MotionEvent me = MotionEvent.obtain(
|
||||
downTime, eventTime, action, x, y, 0 /* metaState */);
|
||||
try {
|
||||
tracker.processMotionEvent(me, handler);
|
||||
tracker.processMotionEvent(me, keyDetector);
|
||||
} finally {
|
||||
me.recycle();
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
|||
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
||||
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
|
||||
import com.android.inputmethod.event.EventInterpreter;
|
||||
import com.android.inputmethod.keyboard.KeyDetector;
|
||||
import com.android.inputmethod.keyboard.Keyboard;
|
||||
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
|
@ -2284,16 +2283,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
resetComposingState(false /* alsoResetLastComposedWord */);
|
||||
}
|
||||
if (isComposingWord) {
|
||||
final int keyX, keyY;
|
||||
if (Constants.isValidCoordinate(x) && Constants.isValidCoordinate(y)) {
|
||||
final KeyDetector keyDetector =
|
||||
mKeyboardSwitcher.getMainKeyboardView().getKeyDetector();
|
||||
keyX = keyDetector.getTouchX(x);
|
||||
keyY = keyDetector.getTouchY(y);
|
||||
} else {
|
||||
keyX = x;
|
||||
keyY = y;
|
||||
}
|
||||
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||
// TODO: We should reconsider which coordinate system should be used to represent
|
||||
// keyboard event.
|
||||
final int keyX = mainKeyboardView.getKeyX(x);
|
||||
final int keyY = mainKeyboardView.getKeyY(y);
|
||||
mWordComposer.add(primaryCode, keyX, keyY);
|
||||
// If it's the first letter, make note of auto-caps state
|
||||
if (mWordComposer.size() == 1) {
|
||||
|
|
Loading…
Reference in a new issue