Android多点触摸的实现
2010-09-10 00:51:00 来源:WEB开发网int mLastNumPointers = 0;
final int[] mLastData = new int[MotionEvent.NUM_SAMPLE_DATA * MAX_POINTERS];
/* mNextNumPointers 为下一个动作在触屏上按键的个数 */
/* 通过对这 2 个值大小的判断,可以确认新的动作方式 */
int mNextNumPointers = 0;
final int[] mNextData = new int[(MotionEvent.NUM_SAMPLE_DATA * MAX_POINTERS)
+ MotionEvent.NUM_SAMPLE_DATA];
………………………………… .
int[] generateAveragedData(int upOrDownPointer, int lastNumPointers,
int nextNumPointers) { //平滑处理
…………………………………… .
}
private boolean assignPointer(int nextIndex, boolean allowOverlap) { //指派按键
……………………………………
}
private int updatePointerIdentifiers() { //更新按键 ID
………………………………… .
}
void removeOldPointer(int index) {
……………………………………
}
MotionEvent generateAbsMotion(InputDevice device, long curTime,
long curTimeNano, Display display, int orientation,
int metaState) {
……………………………………
int upOrDownPointer = updatePointerIdentifiers();
final int numPointers = mLastNumPointers;
………………………………………
/* 对行为的判断 */
if (nextNumPointers != lastNumPointers) { //前后在触屏上点个数不同,说明有手指 up 或 down
if (nextNumPointers > lastNumPointers) {
if (lastNumPointers == 0) { //上次触屏上没有按键,新值又大,说明有按键按下
action = MotionEvent.ACTION_DOWN;
mDownTime = curTime;
} else { //有新点按下,分配给新点 ID 号
action = MotionEvent.ACTION_POINTER_DOWN
| (upOrDownPointer << MotionEvent.ACTION_POINTER_ID_SHIFT);
}
} else { //新动作比原来 pointer 数量少
更多精彩
赞助商链接