Refactor gesture detector logic

GestureDetector listener's onFling method will not call detectAndSendKey
anymore.

Make gesture detector be ignoring multitouch.  Refactoring
GestureDetector out of LatinKeyboardBaseView class change will follow.

Bug: 2910379
Change-Id: I0b2a9c4cf7d432f89f9085f3c2bdf3a3757a8903
main
Tadashi G. Takaoka 2010-08-26 15:22:18 +09:00
parent 0d098c514e
commit 0c54809891
1 changed files with 9 additions and 23 deletions

View File

@ -204,7 +204,6 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
private boolean mAbortKey; private boolean mAbortKey;
private Key mInvalidatedKey; private Key mInvalidatedKey;
private Rect mClipRegion = new Rect(0, 0, 0, 0); private Rect mClipRegion = new Rect(0, 0, 0, 0);
private boolean mCancelGestureDetector;
private SwipeTracker mSwipeTracker = new SwipeTracker(); private SwipeTracker mSwipeTracker = new SwipeTracker();
private int mSwipeThreshold; private int mSwipeThreshold;
private boolean mDisambiguateSwipe; private boolean mDisambiguateSwipe;
@ -544,12 +543,11 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
} }
private void initGestureDetector() { private void initGestureDetector() {
mGestureDetector = new GestureDetector( GestureDetector.SimpleOnGestureListener listener =
getContext(), new GestureDetector.SimpleOnGestureListener() { new GestureDetector.SimpleOnGestureListener() {
@Override @Override
public boolean onFling(MotionEvent me1, MotionEvent me2, public boolean onFling(MotionEvent me1, MotionEvent me2,
float velocityX, float velocityY) { float velocityX, float velocityY) {
if (mCancelGestureDetector) return false;
final float absX = Math.abs(velocityX); final float absX = Math.abs(velocityX);
final float absY = Math.abs(velocityY); final float absY = Math.abs(velocityY);
float deltaX = me2.getX() - me1.getX(); float deltaX = me2.getX() - me1.getX();
@ -559,44 +557,33 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
mSwipeTracker.computeCurrentVelocity(1000); mSwipeTracker.computeCurrentVelocity(1000);
final float endingVelocityX = mSwipeTracker.getXVelocity(); final float endingVelocityX = mSwipeTracker.getXVelocity();
final float endingVelocityY = mSwipeTracker.getYVelocity(); final float endingVelocityY = mSwipeTracker.getYVelocity();
boolean sendDownKey = false;
if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) { if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) { if (mDisambiguateSwipe && endingVelocityX >= velocityX / 4) {
sendDownKey = true;
} else {
swipeRight(); swipeRight();
return true; return true;
} }
} else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) { } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) { if (mDisambiguateSwipe && endingVelocityX <= velocityX / 4) {
sendDownKey = true;
} else {
swipeLeft(); swipeLeft();
return true; return true;
} }
} else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) { } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) { if (mDisambiguateSwipe && endingVelocityY <= velocityY / 4) {
sendDownKey = true;
} else {
swipeUp(); swipeUp();
return true; return true;
} }
} else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) { } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) { if (mDisambiguateSwipe && endingVelocityY >= velocityY / 4) {
sendDownKey = true;
} else {
swipeDown(); swipeDown();
return true; return true;
} }
} }
if (sendDownKey) {
detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
}
return false; return false;
} }
}); };
final boolean ignoreMultitouch = true;
mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch);
mGestureDetector.setIsLongpressEnabled(false); mGestureDetector.setIsLongpressEnabled(false);
} }
@ -1299,7 +1286,6 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
return true; return true;
} }
mCancelGestureDetector = (pointerCount > 1);
if (mGestureDetector.onTouchEvent(me)) { if (mGestureDetector.onTouchEvent(me)) {
showPreview(NOT_A_KEY); showPreview(NOT_A_KEY);
mHandler.cancelKeyTimers(); mHandler.cancelKeyTimers();