am 681b102a: Track all pointers events

Merge commit '681b102a492b7d5301c1ca87985b4c391eb5eb14' into gingerbread-plus-aosp

* commit '681b102a492b7d5301c1ca87985b4c391eb5eb14':
  Track all pointers events
main
Tadashi G. Takaoka 2010-09-01 06:40:26 -07:00 committed by Android Git Automerger
commit f3231f4531
3 changed files with 33 additions and 68 deletions

View File

@ -965,6 +965,7 @@ public class LatinIME extends InputMethodService
private void postUpdateShiftKeyState() { private void postUpdateShiftKeyState() {
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE); mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
// TODO: Should remove this 300ms delay?
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SHIFT_STATE), 300); mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SHIFT_STATE), 300);
} }
@ -1090,7 +1091,7 @@ public class LatinIME extends InputMethodService
LatinImeLogger.logOnDelete(); LatinImeLogger.logOnDelete();
break; break;
case Keyboard.KEYCODE_SHIFT: case Keyboard.KEYCODE_SHIFT:
handleShift(); // Shift key is handled in onPress().
break; break;
case Keyboard.KEYCODE_CANCEL: case Keyboard.KEYCODE_CANCEL:
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) { if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
@ -1107,6 +1108,7 @@ public class LatinIME extends InputMethodService
toggleLanguage(false, false); toggleLanguage(false, false);
break; break;
case Keyboard.KEYCODE_MODE_CHANGE: case Keyboard.KEYCODE_MODE_CHANGE:
// TODO: Mode change (symbol key) should be handled in onPress().
changeKeyboardMode(); changeKeyboardMode();
break; break;
case LatinKeyboardView.KEYCODE_VOICE: case LatinKeyboardView.KEYCODE_VOICE:
@ -1248,19 +1250,6 @@ public class LatinIME extends InputMethodService
} }
} }
private void handleCapsLock() {
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isAlphabetMode()) {
mCapsLock = !mCapsLock;
if (mCapsLock) {
switcher.setShiftLocked(true);
} else {
switcher.setShifted(false);
}
}
}
private void abortCorrection(boolean force) { private void abortCorrection(boolean force) {
if (force || TextEntryState.isCorrecting()) { if (force || TextEntryState.isCorrecting()) {
getCurrentInputConnection().finishComposingText(); getCurrentInputConnection().finishComposingText();
@ -2157,6 +2146,10 @@ public class LatinIME extends InputMethodService
public void onPress(int primaryCode) { public void onPress(int primaryCode) {
vibrate(); vibrate();
playKeyClick(primaryCode); playKeyClick(primaryCode);
if (primaryCode == Keyboard.KEYCODE_SHIFT) {
handleShift();
}
// TODO: We should handle KEYCODE_MODE_CHANGE (symbol) here as well.
} }
public void onRelease(int primaryCode) { public void onRelease(int primaryCode) {

View File

@ -204,11 +204,6 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
private final ProximityKeyDetector mProximityKeyDetector = new ProximityKeyDetector(); private final ProximityKeyDetector mProximityKeyDetector = new ProximityKeyDetector();
// Variables for dealing with multiple pointers
private int mOldPointerCount = 1;
private int mOldPointerX;
private int mOldPointerY;
// Swipe gesture detector // Swipe gesture detector
private final GestureDetector mGestureDetector; private final GestureDetector mGestureDetector;
private final SwipeTracker mSwipeTracker = new SwipeTracker(); private final SwipeTracker mSwipeTracker = new SwipeTracker();
@ -1070,17 +1065,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
@Override @Override
public boolean onTouchEvent(MotionEvent me) { public boolean onTouchEvent(MotionEvent me) {
// Convert multi-pointer up/down events to single up/down events to
// deal with the typical multi-pointer behavior of two-thumb typing
final int pointerCount = me.getPointerCount(); final int pointerCount = me.getPointerCount();
final int action = me.getAction(); final int action = me.getActionMasked();
final long eventTime = me.getEventTime(); final long eventTime = me.getEventTime();
if (pointerCount > 1 && mOldPointerCount > 1) {
// Don't do anything when 2 or more pointers are down and moving.
return true;
}
// Track the last few movements to look for spurious swipes. // Track the last few movements to look for spurious swipes.
mSwipeTracker.addMovement(me); mSwipeTracker.addMovement(me);
@ -1108,34 +1096,36 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
// Up event will pass through. // Up event will pass through.
} }
// TODO: Should remove this implicit reference to id=0 pointer tracker in the future. if (action == MotionEvent.ACTION_MOVE) {
PointerTracker tracker = getPointerTracker(0); for (int index = 0; index < pointerCount; index++) {
int touchX = getTouchX(me.getX()); int touchX = getTouchX(me.getX(index));
int touchY = getTouchY(me.getY()); int touchY = getTouchY(me.getY(index));
if (pointerCount != mOldPointerCount) { int id = me.getPointerId(index);
if (pointerCount == 1) { PointerTracker tracker = getPointerTracker(id);
// Send a down event for the latest pointer tracker.onMoveEvent(touchX, touchY, eventTime);
}
} else {
int index = me.getActionIndex();
int touchX = getTouchX(me.getX(index));
int touchY = getTouchY(me.getY(index));
int id = me.getPointerId(index);
PointerTracker tracker = getPointerTracker(id);
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
tracker.onDownEvent(touchX, touchY, eventTime); tracker.onDownEvent(touchX, touchY, eventTime);
// If it's an up action, then deliver the up as well. break;
if (action == MotionEvent.ACTION_UP) { case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
tracker.onUpEvent(touchX, touchY, eventTime); tracker.onUpEvent(touchX, touchY, eventTime);
} break;
} else { case MotionEvent.ACTION_CANCEL:
// Send an up event for the last pointer tracker.onCancelEvent(touchX, touchY, eventTime);
tracker.onUpEvent(mOldPointerX, mOldPointerY, eventTime); break;
}
mOldPointerCount = pointerCount;
return true;
} else {
if (pointerCount == 1) {
tracker.onModifiedTouchEvent(action, touchX, touchY, eventTime);
mOldPointerX = touchX;
mOldPointerY = touchY;
return true;
} }
} }
return false; return true;
} }
protected void swipeRight() { protected void swipeRight() {

View File

@ -21,7 +21,6 @@ import com.android.inputmethod.latin.LatinKeyboardBaseView.UIHandler;
import android.inputmethodservice.Keyboard; import android.inputmethodservice.Keyboard;
import android.inputmethodservice.Keyboard.Key; import android.inputmethodservice.Keyboard.Key;
import android.view.MotionEvent;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
public class PointerTracker { public class PointerTracker {
@ -119,23 +118,6 @@ public class PointerTracker {
} }
} }
public void onModifiedTouchEvent(int action, int touchX, int touchY, long eventTime) {
switch (action) {
case MotionEvent.ACTION_DOWN:
onDownEvent(touchX, touchY, eventTime);
break;
case MotionEvent.ACTION_MOVE:
onMoveEvent(touchX, touchY, eventTime);
break;
case MotionEvent.ACTION_UP:
onUpEvent(touchX, touchY, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
onCancelEvent(touchX, touchY, eventTime);
break;
}
}
public void onDownEvent(int touchX, int touchY, long eventTime) { public void onDownEvent(int touchX, int touchY, long eventTime) {
int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null); int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
mCurrentKey = keyIndex; mCurrentKey = keyIndex;