From 8b0cb128bec774057934d7b913c4358981b4d4d1 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 24 Aug 2010 22:30:43 +0900 Subject: [PATCH] Refactor onModifiedTouchEvent of LatinKeyboardBaseView This change simplifies onModifierTouchEvent to focus on handling motion event related to a key event. Other refactoring will follow in order to support multi touch. Bug: 2910379 Change-Id: I036be64168d951a535600a7910b36bc109f88490 --- .../latin/LatinKeyboardBaseView.java | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 665c641c2..d22d88f10 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -205,7 +205,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener private boolean mAbortKey; private Key mInvalidatedKey; private Rect mClipRegion = new Rect(0, 0, 0, 0); - private boolean mPossiblePoly; + private boolean mCancelGestureDetector; private SwipeTracker mSwipeTracker = new SwipeTracker(); private int mSwipeThreshold; private boolean mDisambiguateSwipe; @@ -545,7 +545,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener @Override public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) { - if (mPossiblePoly) return false; + if (mCancelGestureDetector) return false; final float absX = Math.abs(velocityX); final float absY = Math.abs(velocityY); float deltaX = me2.getX() - me1.getX(); @@ -1279,46 +1279,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener boolean result = false; final long now = me.getEventTime(); - if (pointerCount != mOldPointerCount) { - if (pointerCount == 1) { - // Send a down event for the latest pointer - MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, - me.getX(), me.getY(), me.getMetaState()); - result = onModifiedTouchEvent(down, false); - down.recycle(); - // If it's an up action, then deliver the up as well. - if (action == MotionEvent.ACTION_UP) { - result = onModifiedTouchEvent(me, true); - } - } else { - // Send an up event for the last pointer - MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, - mOldPointerX, mOldPointerY, me.getMetaState()); - result = onModifiedTouchEvent(up, true); - up.recycle(); - } - } else { - if (pointerCount == 1) { - result = onModifiedTouchEvent(me, false); - mOldPointerX = me.getX(); - mOldPointerY = me.getY(); - } else { - // Don't do anything when 2 pointers are down and moving. - result = true; - } + if (pointerCount > 1 && mOldPointerCount > 1) { + // Don't do anything when 2 or more pointers are down and moving. + return true; } - mOldPointerCount = pointerCount; - - return result; - } - - private boolean onModifiedTouchEvent(MotionEvent me, boolean possiblePoly) { - int touchX = (int) me.getX() - getPaddingLeft(); - int touchY = (int) me.getY() + mVerticalCorrection - getPaddingTop(); - final int action = me.getAction(); - final long eventTime = me.getEventTime(); - int keyIndex = getKeyIndexAndNearbyCodes(touchX, touchY, null); - mPossiblePoly = possiblePoly; // Track the last few movements to look for spurious swipes. if (action == MotionEvent.ACTION_DOWN) mSwipeTracker.clear(); @@ -1330,6 +1294,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener return true; } + mCancelGestureDetector = (pointerCount > 1); if (mGestureDetector.onTouchEvent(me)) { showPreview(NOT_A_KEY); mHandler.cancelKeyTimers(); @@ -1342,6 +1307,43 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener return true; } + if (pointerCount != mOldPointerCount) { + if (pointerCount == 1) { + // Send a down event for the latest pointer + MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, + me.getX(), me.getY(), me.getMetaState()); + result = onModifiedTouchEvent(down); + down.recycle(); + // If it's an up action, then deliver the up as well. + if (action == MotionEvent.ACTION_UP) { + result = onModifiedTouchEvent(me); + } + } else { + // Send an up event for the last pointer + MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, + mOldPointerX, mOldPointerY, me.getMetaState()); + result = onModifiedTouchEvent(up); + up.recycle(); + } + mOldPointerCount = pointerCount; + } else { + if (pointerCount == 1) { + result = onModifiedTouchEvent(me); + mOldPointerX = me.getX(); + mOldPointerY = me.getY(); + } + } + + return result; + } + + private boolean onModifiedTouchEvent(MotionEvent me) { + int touchX = (int) me.getX() - getPaddingLeft(); + int touchY = (int) me.getY() + mVerticalCorrection - getPaddingTop(); + final int action = me.getAction(); + final long eventTime = me.getEventTime(); + int keyIndex = getKeyIndexAndNearbyCodes(touchX, touchY, null); + switch (action) { case MotionEvent.ACTION_DOWN: mAbortKey = false;