aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java9
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java7
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java190
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java69
-rw-r--r--java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java157
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java6
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java4
14 files changed, 129 insertions, 339 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index a87ff9891..b18cbd3ef 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -200,8 +200,8 @@ public class AccessibleKeyboardViewProxy {
}
private void fireKeyPressEvent(PointerTracker tracker, int x, int y, long eventTime) {
- tracker.onDownEvent(x, y, eventTime, null);
- tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS, null);
+ tracker.onDownEvent(x, y, eventTime);
+ tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS);
}
private class KeyboardFlickGestureDetector extends FlickGestureDetector {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 85418a61d..6d25025c5 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -73,11 +73,10 @@ public class KeyDetector {
return y + mCorrectionY;
}
- protected List<Key> getKeys() {
+ public Keyboard getKeyboard() {
if (mKeyboard == null)
throw new IllegalStateException("keyboard isn't set");
- // mKeyboard is guaranteed not to be null at setKeybaord() method if mKeys is not null
- return mKeyboard.getKeys();
+ return mKeyboard;
}
public void setProximityCorrectionEnabled(boolean enabled) {
@@ -154,7 +153,7 @@ public class KeyDetector {
}
private void getNearbyKeyCodes(final int[] allCodes) {
- final List<Key> keys = getKeys();
+ final List<Key> keys = getKeyboard().getKeys();
final int[] indices = mIndices;
// allCodes[0] should always have the key code even if it is a non-letter key.
@@ -188,7 +187,7 @@ public class KeyDetector {
* @return The nearest key index
*/
public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
- final List<Key> keys = getKeys();
+ final List<Key> keys = getKeyboard().getKeys();
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
index 7e67d6f6b..905f779c0 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
@@ -70,9 +70,4 @@ public interface KeyboardActionListener {
* Called when user released a finger outside any key.
*/
public void onCancelInput();
-
- /**
- * Called when the user quickly moves the finger from up to down.
- */
- public void onSwipeDown();
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 275e9d1fe..7ad947c67 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -763,7 +763,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
- mKeyboardView.setOnKeyboardActionListener(mInputMethodService);
+ mKeyboardView.setKeyboardActionListener(mInputMethodService);
// This always needs to be set since the accessibility state can
// potentially change without the input view being re-created.
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index d1345db9d..e31aa8478 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -331,7 +331,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mPreviewText = null;
mShowKeyPreviewPopup = false;
}
- // TODO: Use Theme (android.R.styleable.Theme_backgroundDimAmount)
mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f);
a.recycle();
@@ -350,12 +349,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- // TODO: Should notify InputMethodService instead?
- KeyboardSwitcher.getInstance().onSizeChanged();
- }
-
/**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard.
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
index c8cfb43e3..60af1ecc2 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
@@ -35,7 +35,6 @@ import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
-import com.android.inputmethod.keyboard.internal.SwipeTracker;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@@ -74,7 +73,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
// TODO: Let the PointerTracker class manage this pointer queue
- private final PointerTrackerQueue mPointerQueue = new PointerTrackerQueue();
+ private final PointerTrackerQueue mPointerQueue;
private final boolean mHasDistinctMultitouch;
private int mOldPointerCount = 1;
@@ -82,11 +81,8 @@ public class LatinKeyboardBaseView extends KeyboardView {
protected KeyDetector mKeyDetector;
- // Swipe gesture detector
+ // To detect double tap.
protected GestureDetector mGestureDetector;
- private final SwipeTracker mSwipeTracker = new SwipeTracker();
- private final int mSwipeThreshold;
- private final boolean mDisambiguateSwipe;
private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this);
@@ -172,6 +168,52 @@ public class LatinKeyboardBaseView extends KeyboardView {
}
}
+ private class DoubleTapListener extends GestureDetector.SimpleOnGestureListener {
+ private boolean mProcessingShiftDoubleTapEvent = false;
+
+ @Override
+ public boolean onDoubleTap(MotionEvent firstDown) {
+ final Keyboard keyboard = getKeyboard();
+ if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
+ && ((LatinKeyboard) keyboard).isAlphaKeyboard()) {
+ final int pointerIndex = firstDown.getActionIndex();
+ final int id = firstDown.getPointerId(pointerIndex);
+ final PointerTracker tracker = getPointerTracker(id);
+ // If the first down event is on shift key.
+ if (tracker.isOnShiftKey((int) firstDown.getX(), (int) firstDown.getY())) {
+ mProcessingShiftDoubleTapEvent = true;
+ return true;
+ }
+ }
+ mProcessingShiftDoubleTapEvent = false;
+ return false;
+ }
+
+ @Override
+ public boolean onDoubleTapEvent(MotionEvent secondTap) {
+ if (mProcessingShiftDoubleTapEvent
+ && secondTap.getAction() == MotionEvent.ACTION_DOWN) {
+ final MotionEvent secondDown = secondTap;
+ final int pointerIndex = secondDown.getActionIndex();
+ final int id = secondDown.getPointerId(pointerIndex);
+ final PointerTracker tracker = getPointerTracker(id);
+ // If the second down event is also on shift key.
+ if (tracker.isOnShiftKey((int) secondDown.getX(), (int) secondDown.getY())) {
+ // Detected a double tap on shift key. If we are in the ignoring double tap
+ // mode, it means we have already turned off caps lock in
+ // {@link KeyboardSwitcher#onReleaseShift} .
+ final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap();
+ if (!ignoringDoubleTap)
+ onDoubleTapShiftKey(tracker);
+ return true;
+ }
+ // Otherwise these events should not be handled as double tap.
+ mProcessingShiftDoubleTapEvent = false;
+ }
+ return mProcessingShiftDoubleTapEvent;
+ }
+ }
+
public LatinKeyboardBaseView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle);
}
@@ -183,91 +225,23 @@ public class LatinKeyboardBaseView extends KeyboardView {
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
mVerticalCorrection = a.getDimensionPixelOffset(
R.styleable.KeyboardView_verticalCorrection, 0);
-
mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0);
- // TODO: Use Theme (android.R.styleable.Theme_backgroundDimAmount)
a.recycle();
final Resources res = getResources();
-
final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance);
mKeyDetector = new KeyDetector(keyHysteresisDistance);
- mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density);
- // TODO: Refer to frameworks/base/core/res/res/values/config.xml
- mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
-
- GestureDetector.SimpleOnGestureListener listener =
- new GestureDetector.SimpleOnGestureListener() {
- private boolean mProcessingShiftDoubleTapEvent = false;
-
- @Override
- public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX,
- float velocityY) {
- final float absX = Math.abs(velocityX);
- final float absY = Math.abs(velocityY);
- float deltaY = me2.getY() - me1.getY();
- int travelY = getHeight() / 2; // Half the keyboard height
- mSwipeTracker.computeCurrentVelocity(1000);
- final float endingVelocityY = mSwipeTracker.getYVelocity();
- if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
- if (mDisambiguateSwipe && endingVelocityY >= velocityY / 4) {
- onSwipeDown();
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean onDoubleTap(MotionEvent firstDown) {
- final Keyboard keyboard = getKeyboard();
- if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
- && ((LatinKeyboard) keyboard).isAlphaKeyboard()) {
- final int pointerIndex = firstDown.getActionIndex();
- final int id = firstDown.getPointerId(pointerIndex);
- final PointerTracker tracker = getPointerTracker(id);
- // If the first down event is on shift key.
- if (tracker.isOnShiftKey((int)firstDown.getX(), (int)firstDown.getY())) {
- mProcessingShiftDoubleTapEvent = true;
- return true;
- }
- }
- mProcessingShiftDoubleTapEvent = false;
- return false;
- }
-
- @Override
- public boolean onDoubleTapEvent(MotionEvent secondTap) {
- if (mProcessingShiftDoubleTapEvent
- && secondTap.getAction() == MotionEvent.ACTION_DOWN) {
- final MotionEvent secondDown = secondTap;
- final int pointerIndex = secondDown.getActionIndex();
- final int id = secondDown.getPointerId(pointerIndex);
- final PointerTracker tracker = getPointerTracker(id);
- // If the second down event is also on shift key.
- if (tracker.isOnShiftKey((int)secondDown.getX(), (int)secondDown.getY())) {
- // Detected a double tap on shift key. If we are in the ignoring double tap
- // mode, it means we have already turned off caps lock in
- // {@link KeyboardSwitcher#onReleaseShift} .
- final boolean ignoringDoubleTap = mKeyTimerHandler.isIgnoringDoubleTap();
- if (!ignoringDoubleTap)
- onDoubleTapShiftKey(tracker);
- return true;
- }
- // Otherwise these events should not be handled as double tap.
- mProcessingShiftDoubleTapEvent = false;
- }
- return mProcessingShiftDoubleTapEvent;
- }
- };
final boolean ignoreMultitouch = true;
- mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch);
+ mGestureDetector = new GestureDetector(
+ getContext(), new DoubleTapListener(), null, ignoreMultitouch);
mGestureDetector.setIsLongpressEnabled(false);
mHasDistinctMultitouch = context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
+
+ mPointerQueue = mHasDistinctMultitouch ? new PointerTrackerQueue() : null;
}
public void startIgnoringDoubleTap() {
@@ -275,10 +249,10 @@ public class LatinKeyboardBaseView extends KeyboardView {
mKeyTimerHandler.startIgnoringDoubleTap();
}
- public void setOnKeyboardActionListener(KeyboardActionListener listener) {
+ public void setKeyboardActionListener(KeyboardActionListener listener) {
mKeyboardActionListener = listener;
for (PointerTracker tracker : mPointerTrackers) {
- tracker.setOnKeyboardActionListener(listener);
+ tracker.setKeyboardActionListener(listener);
}
}
@@ -286,10 +260,16 @@ public class LatinKeyboardBaseView extends KeyboardView {
* Returns the {@link KeyboardActionListener} object.
* @return the listener attached to this keyboard
*/
- protected KeyboardActionListener getOnKeyboardActionListener() {
+ protected KeyboardActionListener getKeyboardActionListener() {
return mKeyboardActionListener;
}
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ // TODO: Should notify InputMethodService instead?
+ KeyboardSwitcher.getInstance().onSizeChanged();
+ }
+
/**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard.
@@ -305,10 +285,10 @@ public class LatinKeyboardBaseView extends KeyboardView {
// Remove any pending messages, except dismissing preview
mKeyTimerHandler.cancelKeyTimers();
super.setKeyboard(keyboard);
- mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
- -getPaddingTop() + mVerticalCorrection);
+ mKeyDetector.setKeyboard(
+ keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection);
for (PointerTracker tracker : mPointerTrackers) {
- tracker.setKeyboard(keyboard, mKeyDetector);
+ tracker.setKeyDetector(mKeyDetector);
}
mKeyDetector.setProximityThreshold(keyboard.getMostCommonKeyWidth());
mPopupPanelCache.clear();
@@ -365,20 +345,20 @@ public class LatinKeyboardBaseView extends KeyboardView {
boolean result = onLongPress(parentKey, tracker);
if (result) {
dismissAllKeyPreviews();
- tracker.onLongPressed(mPointerQueue);
+ tracker.onLongPressed();
}
return result;
}
private void onLongPressShiftKey(PointerTracker tracker) {
- tracker.onLongPressed(mPointerQueue);
+ tracker.onLongPressed();
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
}
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
// the second tap is treated as this double tap event, so that we need not mark tracker
- // calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
+ // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue.
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
}
@@ -394,7 +374,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
final PopupMiniKeyboardView miniKeyboardView =
(PopupMiniKeyboardView)container.findViewById(R.id.mini_keyboard_view);
- miniKeyboardView.setOnKeyboardActionListener(new KeyboardActionListener() {
+ miniKeyboardView.setKeyboardActionListener(new KeyboardActionListener() {
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
mKeyboardActionListener.onCodeInput(primaryCode, keyCodes, x, y);
@@ -414,10 +394,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
}
@Override
- public void onSwipeDown() {
- // Nothing to do.
- }
- @Override
public void onPress(int primaryCode, boolean withSliding) {
mKeyboardActionListener.onPress(primaryCode, withSliding);
}
@@ -482,11 +458,11 @@ public class LatinKeyboardBaseView extends KeyboardView {
for (int i = pointers.size(); i <= id; i++) {
final PointerTracker tracker =
new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this,
- mHasDistinctMultitouch);
+ mPointerQueue);
if (keyboard != null)
- tracker.setKeyboard(keyboard, mKeyDetector);
+ tracker.setKeyDetector(mKeyDetector);
if (listener != null)
- tracker.setOnKeyboardActionListener(listener);
+ tracker.setKeyboardActionListener(listener);
pointers.add(tracker);
}
@@ -520,9 +496,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
- // Track the last few movements to look for spurious swipes.
- mSwipeTracker.addMovement(me);
-
// Gesture detector must be enabled only when mini-keyboard is not on the screen.
if (mPopupMiniKeyboardPanel == null && mGestureDetector != null
&& mGestureDetector.onTouchEvent(me)) {
@@ -565,9 +538,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
// previous key.
final int newKeyIndex = tracker.getKeyIndexOn(x, y);
if (mOldKeyIndex != newKeyIndex) {
- tracker.onDownEvent(x, y, eventTime, null);
+ tracker.onDownEvent(x, y, eventTime);
if (action == MotionEvent.ACTION_UP)
- tracker.onUpEvent(x, y, eventTime, null);
+ tracker.onUpEvent(x, y, eventTime);
}
} else if (pointerCount == 2 && oldPointerCount == 1) {
// Single-touch to multi-touch transition.
@@ -575,9 +548,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
final int lastX = tracker.getLastX();
final int lastY = tracker.getLastY();
mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY);
- tracker.onUpEvent(lastX, lastY, eventTime, null);
+ tracker.onUpEvent(lastX, lastY, eventTime);
} else if (pointerCount == 1 && oldPointerCount == 1) {
- tracker.onTouchEvent(action, x, y, eventTime, null);
+ tracker.onTouchEvent(action, x, y, eventTime);
} else {
Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount
+ " (old " + oldPointerCount + ")");
@@ -585,25 +558,24 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
- final PointerTrackerQueue queue = mPointerQueue;
if (action == MotionEvent.ACTION_MOVE) {
for (int i = 0; i < pointerCount; i++) {
final PointerTracker tracker = getPointerTracker(me.getPointerId(i));
- tracker.onMoveEvent((int)me.getX(i), (int)me.getY(i), eventTime, queue);
+ tracker.onMoveEvent((int)me.getX(i), (int)me.getY(i), eventTime);
}
} else {
final PointerTracker tracker = getPointerTracker(id);
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
- tracker.onDownEvent(x, y, eventTime, queue);
+ tracker.onDownEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
- tracker.onUpEvent(x, y, eventTime, queue);
+ tracker.onUpEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
- tracker.onCancelEvent(x, y, eventTime, queue);
+ tracker.onCancelEvent(x, y, eventTime);
break;
}
}
@@ -611,10 +583,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
- protected void onSwipeDown() {
- mKeyboardActionListener.onSwipeDown();
- }
-
@Override
public void closing() {
super.closing();
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 510bc16b4..39d607d95 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -106,7 +106,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
}
private boolean invokeOnKey(int primaryCode) {
- getOnKeyboardActionListener().onCodeInput(primaryCode, null,
+ getKeyboardActionListener().onCodeInput(primaryCode, null,
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
return true;
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
index 69005db57..1ec0dda15 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
@@ -37,7 +37,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector {
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
- final List<Key> keys = getKeys();
+ final List<Key> keys = getKeyboard().getKeys();
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 4ceabff4c..19cedc41d 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -34,7 +34,6 @@ import java.util.List;
public class PointerTracker {
private static final String TAG = PointerTracker.class.getSimpleName();
- private static final boolean ENABLE_ASSERTION = false;
private static final boolean DEBUG_EVENT = false;
private static final boolean DEBUG_MOVE_EVENT = false;
private static final boolean DEBUG_LISTENER = false;
@@ -56,10 +55,10 @@ public class PointerTracker {
private final DrawingProxy mDrawingProxy;
private final KeyTimerHandler mKeyTimerHandler;
+ private final PointerTrackerQueue mPointerTrackerQueue;
private KeyDetector mKeyDetector;
private KeyboardActionListener mListener = EMPTY_LISTENER;
private final KeyboardSwitcher mKeyboardSwitcher;
- private final boolean mHasDistinctMultitouch;
private final boolean mConfigSlidingKeyInputEnabled;
private final int mTouchNoiseThresholdMillis;
@@ -107,21 +106,19 @@ public class PointerTracker {
public void onTextInput(CharSequence text) {}
@Override
public void onCancelInput() {}
- @Override
- public void onSwipeDown() {}
};
public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler,
- KeyDetector keyDetector, DrawingProxy drawingProxy, boolean hasDistinctMultitouch) {
+ KeyDetector keyDetector, DrawingProxy drawingProxy, PointerTrackerQueue queue) {
if (drawingProxy == null || keyTimerHandler == null || keyDetector == null)
throw new NullPointerException();
mPointerId = id;
mDrawingProxy = drawingProxy;
mKeyTimerHandler = keyTimerHandler;
- mKeyDetector = keyDetector;
- mKeyboardSwitcher = KeyboardSwitcher.getInstance();
+ mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device.
mKeyState = new PointerTrackerKeyState(keyDetector);
- mHasDistinctMultitouch = hasDistinctMultitouch;
+ setKeyDetectorInner(keyDetector);
+ mKeyboardSwitcher = KeyboardSwitcher.getInstance();
final Resources res = context.getResources();
mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
@@ -135,7 +132,7 @@ public class PointerTracker {
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
}
- public void setOnKeyboardActionListener(KeyboardActionListener listener) {
+ public void setKeyboardActionListener(KeyboardActionListener listener) {
mListener = listener;
}
@@ -196,15 +193,19 @@ public class PointerTracker {
mListener.onCancelInput();
}
- public void setKeyboard(Keyboard keyboard, KeyDetector keyDetector) {
- if (keyboard == null || keyDetector == null)
- throw new NullPointerException();
- mKeyboard = keyboard;
- mKeys = keyboard.getKeys();
+ public void setKeyDetectorInner(KeyDetector keyDetector) {
mKeyDetector = keyDetector;
+ mKeyboard = keyDetector.getKeyboard();
+ mKeys = mKeyboard.getKeys();
mKeyState.setKeyDetector(keyDetector);
- final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
+ final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4;
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
+ }
+
+ public void setKeyDetector(KeyDetector keyDetector) {
+ if (keyDetector == null)
+ throw new NullPointerException();
+ setKeyDetectorInner(keyDetector);
// Mark that keyboard layout has been changed.
mKeyboardLayoutHasBeenChanged = true;
}
@@ -273,36 +274,26 @@ public class PointerTracker {
}
}
- 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) {
+ public void onTouchEvent(int action, int x, int y, long eventTime) {
switch (action) {
case MotionEvent.ACTION_MOVE:
- onMoveEvent(x, y, eventTime, queue);
+ onMoveEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
- onDownEvent(x, y, eventTime, queue);
+ onDownEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
- onUpEvent(x, y, eventTime, queue);
+ onUpEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
- onCancelEvent(x, y, eventTime, queue);
+ onCancelEvent(x, y, eventTime);
break;
}
}
- public void onDownEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
- if (ENABLE_ASSERTION) checkAssertion(queue);
+ public void onDownEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onDownEvent:", x, y, eventTime);
@@ -321,6 +312,7 @@ public class PointerTracker {
}
}
+ final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
if (isOnModifierKey(x, y)) {
// Before processing a down event of modifier key, all pointers already being
@@ -364,8 +356,7 @@ public class PointerTracker {
mIsInSlidingKeyInput = true;
}
- public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
- if (ENABLE_ASSERTION) checkAssertion(queue);
+ public void onMoveEvent(int x, int y, long eventTime) {
if (DEBUG_MOVE_EVENT)
printTouchEvent("onMoveEvent:", x, y, eventTime);
if (mKeyAlreadyProcessed)
@@ -449,6 +440,7 @@ public class PointerTracker {
keyboard.updateSpacebarPreviewIcon(diff);
// Display spacebar slide language switcher.
showKeyPreview(keyIndex);
+ final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null)
queue.releaseAllPointersExcept(this, eventTime, true);
}
@@ -472,11 +464,11 @@ public class PointerTracker {
}
}
- public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
- if (ENABLE_ASSERTION) checkAssertion(queue);
+ public void onUpEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onUpEvent :", x, y, eventTime);
+ final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
if (isModifier()) {
// Before processing an up event of modifier key, all pointers already being
@@ -540,8 +532,9 @@ public class PointerTracker {
}
}
- public void onLongPressed(PointerTrackerQueue queue) {
+ public void onLongPressed() {
mKeyAlreadyProcessed = true;
+ final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
// TODO: Support chording + long-press input.
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
@@ -549,11 +542,11 @@ public class PointerTracker {
}
}
- public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
- if (ENABLE_ASSERTION) checkAssertion(queue);
+ public void onCancelEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onCancelEvt:", x, y, eventTime);
+ final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
queue.releaseAllPointersExcept(this, eventTime, true);
queue.remove(this);
diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
index 959427aad..a3d9c0465 100644
--- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
@@ -58,6 +58,11 @@ public class PopupMiniKeyboardView extends LatinKeyboardBaseView implements Popu
}
@Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ // Do nothing for the mini keyboard.
+ }
+
+ @Override
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
// Mini keyboard needs no pop-up key preview displayed, so we pass always false with a
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java
index 6e2b60c30..5a12db248 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java
@@ -39,8 +39,10 @@ public class PointerTrackerKeyState {
private int mLastX;
private int mLastY;
- public PointerTrackerKeyState(KeyDetector keyDetecor) {
- mKeyDetector = keyDetecor;
+ public PointerTrackerKeyState(KeyDetector keyDetector) {
+ if (keyDetector == null)
+ throw new NullPointerException();
+ mKeyDetector = keyDetector;
}
public void setKeyDetector(KeyDetector keyDetector) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java b/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java
deleted file mode 100644
index 8d192c2f0..000000000
--- a/java/src/com/android/inputmethod/keyboard/internal/SwipeTracker.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * 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.
- */
-
-package com.android.inputmethod.keyboard.internal;
-
-import android.view.MotionEvent;
-
-public class SwipeTracker {
- private static final int NUM_PAST = 4;
- private static final int LONGEST_PAST_TIME = 200;
-
- final EventRingBuffer mBuffer = new EventRingBuffer(NUM_PAST);
-
- private float mYVelocity;
- private float mXVelocity;
-
- public void addMovement(MotionEvent ev) {
- if (ev.getAction() == MotionEvent.ACTION_DOWN) {
- mBuffer.clear();
- return;
- }
- long time = ev.getEventTime();
- final int count = ev.getHistorySize();
- for (int i = 0; i < count; i++) {
- addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i), ev.getHistoricalEventTime(i));
- }
- addPoint(ev.getX(), ev.getY(), time);
- }
-
- private void addPoint(float x, float y, long time) {
- final EventRingBuffer buffer = mBuffer;
- while (buffer.size() > 0) {
- long lastT = buffer.getTime(0);
- if (lastT >= time - LONGEST_PAST_TIME)
- break;
- buffer.dropOldest();
- }
- buffer.add(x, y, time);
- }
-
- public void computeCurrentVelocity(int units) {
- computeCurrentVelocity(units, Float.MAX_VALUE);
- }
-
- public void computeCurrentVelocity(int units, float maxVelocity) {
- final EventRingBuffer buffer = mBuffer;
- final float oldestX = buffer.getX(0);
- final float oldestY = buffer.getY(0);
- final long oldestTime = buffer.getTime(0);
-
- float accumX = 0;
- float accumY = 0;
- final int count = buffer.size();
- for (int pos = 1; pos < count; pos++) {
- final int dur = (int)(buffer.getTime(pos) - oldestTime);
- if (dur == 0) continue;
- float dist = buffer.getX(pos) - oldestX;
- float vel = (dist / dur) * units; // pixels/frame.
- if (accumX == 0) accumX = vel;
- else accumX = (accumX + vel) * .5f;
-
- dist = buffer.getY(pos) - oldestY;
- vel = (dist / dur) * units; // pixels/frame.
- if (accumY == 0) accumY = vel;
- else accumY = (accumY + vel) * .5f;
- }
- mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity)
- : Math.min(accumX, maxVelocity);
- mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity)
- : Math.min(accumY, maxVelocity);
- }
-
- public float getXVelocity() {
- return mXVelocity;
- }
-
- public float getYVelocity() {
- return mYVelocity;
- }
-
- public static class EventRingBuffer {
- private final int bufSize;
- private final float xBuf[];
- private final float yBuf[];
- private final long timeBuf[];
- private int top; // points new event
- private int end; // points oldest event
- private int count; // the number of valid data
-
- public EventRingBuffer(int max) {
- this.bufSize = max;
- xBuf = new float[max];
- yBuf = new float[max];
- timeBuf = new long[max];
- clear();
- }
-
- public void clear() {
- top = end = count = 0;
- }
-
- public int size() {
- return count;
- }
-
- // Position 0 points oldest event
- private int index(int pos) {
- return (end + pos) % bufSize;
- }
-
- private int advance(int index) {
- return (index + 1) % bufSize;
- }
-
- public void add(float x, float y, long time) {
- xBuf[top] = x;
- yBuf[top] = y;
- timeBuf[top] = time;
- top = advance(top);
- if (count < bufSize) {
- count++;
- } else {
- end = advance(end);
- }
- }
-
- public float getX(int pos) {
- return xBuf[index(pos)];
- }
-
- public float getY(int pos) {
- return yBuf[index(pos)];
- }
-
- public long getTime(int pos) {
- return timeBuf[index(pos)];
- }
-
- public void dropOldest() {
- count--;
- end = advance(end);
- }
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 12dad534f..30eb83c58 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1892,12 +1892,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// subtype changes.
if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED)
onRefreshKeyboard();
- }
-
- @Override
- public void onSwipeDown() {
- if (mSettingsValues.mSwipeDownDismissKeyboardEnabled)
- handleClose();
}
@Override
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index d6b989073..aba72d320 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -90,7 +90,6 @@ public class Settings extends PreferenceActivity
public static class Values {
// From resources:
- public final boolean mSwipeDownDismissKeyboardEnabled;
public final int mDelayBeforeFadeoutLanguageOnSpacebar;
public final int mDelayUpdateSuggestions;
public final int mDelayUpdateOldSuggestions;
@@ -131,8 +130,6 @@ public class Settings extends PreferenceActivity
}
// Get the resources
- mSwipeDownDismissKeyboardEnabled = res.getBoolean(
- R.bool.config_swipe_down_dismiss_keyboard_enabled);
mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
R.integer.config_delay_before_fadeout_language_on_spacebar);
mDelayUpdateSuggestions =
@@ -539,6 +536,7 @@ public class Settings extends PreferenceActivity
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
}
+ @Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case VOICE_INPUT_CONFIRM_DIALOG: