历史 MotionEvent 是否有限制(时间或数量)?
Is there a limit (time or number) for the historical MotionEvent's?
我已经覆盖了 activity 的方法 dispatchTouchEvent 以获取 MotionEvents(只是添加了一些日志记录)。
我观察到 getHistorySize() 方法的大小不是 1-2。
通常,运动的 "historical" 事件不会保存超过 1-2 个事件吗?
当我一段时间不松开手指时,我预计会出现大量历史事件。
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
for(int i=0;i<ev.getPointerCount();i++){
Log.i("HumanRawMotion",(
"Action: "+ev.getAction()
+ " DownTime: "+ev.getDownTime()
+ " eventtime: "+ev.getEventTime()
+ " pressure: "+ev.getPressure()
+ " finger x "+i+": getAxisValue(0) " + ev.getAxisValue(0, i)
+ " finger y "+i+": getAxisValue(1) " + ev.getAxisValue(1, i)
+ " flag: "+ev.getEdgeFlags())
+ " historicalSize: "+ev.getHistorySize()
);
//dont touch this ! (original implementation of the methode
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
这是日志的输出,当我在显示屏上触摸并移动一根手指时:
01-28 13:19:37.984 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 0 DownTime: 158340135 eventtime: 158340135 pressure: 0.675 finger x 0: getAxisValue(0) 630.0 finger y 0: getAxisValue(1) 674.0 flag: 0 historicalSize: 0
01-28 13:19:37.999 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158340135 eventtime: 158340146 pressure: 0.675 finger x 0: getAxisValue(0) 627.38184 finger y 0: getAxisValue(1) 671.90546 flag: 0 historicalSize: 1
01-28 13:19:38.065 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158340135 eventtime: 158340212 pressure: 0.58750004 finger x 0: getAxisValue(0) 626.25 finger y 0: getAxisValue(1) 670.75 flag: 0 historicalSize: 2
01-28 13:19:38.069 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 1 DownTime: 158340135 eventtime: 158340218 pressure: 0.58750004 finger x 0: getAxisValue(0) 626.25 finger y 0: getAxisValue(1) 670.75 flag: 0 historicalSize: 0
01-28 13:19:58.122 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 0 DownTime: 158360275 eventtime: 158360275 pressure: 0.71250004 finger x 0: getAxisValue(0) 547.5 finger y 0: getAxisValue(1) 1023.0 flag: 0 historicalSize: 0
01-28 13:19:58.147 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360290 pressure: 0.725 finger x 0: getAxisValue(0) 545.25 finger y 0: getAxisValue(1) 1023.0 flag: 0 historicalSize: 1
01-28 13:19:58.180 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360328 pressure: 0.75 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1023.5117 flag: 0 historicalSize: 1
01-28 13:19:58.197 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360344 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1024.3497 flag: 0 historicalSize: 1
01-28 13:19:58.214 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360361 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1025.151 flag: 0 historicalSize: 2
01-28 13:19:58.230 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360378 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1025.9537 flag: 0 historicalSize: 1
01-28 13:19:58.247 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360394 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1026.7559 flag: 0 historicalSize: 2
01-28 13:19:58.264 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360411 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1027.5531 flag: 0 historicalSize: 2
01-28 13:19:58.280 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360428 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1028.3606 flag: 0 historicalSize: 1
01-28 13:19:58.300 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360444 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1029.1615 flag: 0 historicalSize: 2
01-28 13:19:58.314 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360461 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1029.966 flag: 0 historicalSize: 1
01-28 13:19:58.330 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360478 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1030.7684 flag: 0 historicalSize: 2
01-28 13:19:58.347 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360494 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1031.5704 flag: 0 historicalSize: 2
01-28 13:19:58.364 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360509 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1032.25 flag: 0 historicalSize: 1
01-28 13:19:58.414 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360561 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1032.7789 flag: 0 historicalSize: 1
01-28 13:19:58.431 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360578 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1033.5829 flag: 0 historicalSize: 2
01-28 13:19:58.449 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360592 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1034.25 flag: 0 historicalSize: 1
01-28 13:19:58.464 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360611 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1034.5911 flag: 0 historicalSize: 1
01-28 13:19:58.497 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360636 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1035.1934 flag: 0 historicalSize: 1
01-28 13:19:58.631 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360778 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1035.5144 flag: 0 historicalSize: 1
01-28 13:19:58.648 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360789 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.25 flag: 0 historicalSize: 1
01-28 13:20:00.638 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158362784 pressure: 0.8125 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1037.25 flag: 0 historicalSize: 2
01-28 13:20:00.927 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158363070 pressure: 0.7 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.5 flag: 0 historicalSize: 0
01-28 13:20:00.928 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 1 DownTime: 158360275 eventtime: 158363080 pressure: 0.7 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.5 flag: 0 historicalSize: 0
保存的历史实际上并不是历史,因为它保存了从最后一个向下指针开始的所有事件,而是 Android 在需要保持性能时将几个 MotionEvent
批处理在一起。那些存储在历史记录中。
您可以参考 MotionEvent docs 的 批处理 部分了解更多信息。
我已经覆盖了 activity 的方法 dispatchTouchEvent 以获取 MotionEvents(只是添加了一些日志记录)。 我观察到 getHistorySize() 方法的大小不是 1-2。 通常,运动的 "historical" 事件不会保存超过 1-2 个事件吗? 当我一段时间不松开手指时,我预计会出现大量历史事件。
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
for(int i=0;i<ev.getPointerCount();i++){
Log.i("HumanRawMotion",(
"Action: "+ev.getAction()
+ " DownTime: "+ev.getDownTime()
+ " eventtime: "+ev.getEventTime()
+ " pressure: "+ev.getPressure()
+ " finger x "+i+": getAxisValue(0) " + ev.getAxisValue(0, i)
+ " finger y "+i+": getAxisValue(1) " + ev.getAxisValue(1, i)
+ " flag: "+ev.getEdgeFlags())
+ " historicalSize: "+ev.getHistorySize()
);
//dont touch this ! (original implementation of the methode
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
这是日志的输出,当我在显示屏上触摸并移动一根手指时:
01-28 13:19:37.984 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 0 DownTime: 158340135 eventtime: 158340135 pressure: 0.675 finger x 0: getAxisValue(0) 630.0 finger y 0: getAxisValue(1) 674.0 flag: 0 historicalSize: 0
01-28 13:19:37.999 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158340135 eventtime: 158340146 pressure: 0.675 finger x 0: getAxisValue(0) 627.38184 finger y 0: getAxisValue(1) 671.90546 flag: 0 historicalSize: 1
01-28 13:19:38.065 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158340135 eventtime: 158340212 pressure: 0.58750004 finger x 0: getAxisValue(0) 626.25 finger y 0: getAxisValue(1) 670.75 flag: 0 historicalSize: 2
01-28 13:19:38.069 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 1 DownTime: 158340135 eventtime: 158340218 pressure: 0.58750004 finger x 0: getAxisValue(0) 626.25 finger y 0: getAxisValue(1) 670.75 flag: 0 historicalSize: 0
01-28 13:19:58.122 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 0 DownTime: 158360275 eventtime: 158360275 pressure: 0.71250004 finger x 0: getAxisValue(0) 547.5 finger y 0: getAxisValue(1) 1023.0 flag: 0 historicalSize: 0
01-28 13:19:58.147 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360290 pressure: 0.725 finger x 0: getAxisValue(0) 545.25 finger y 0: getAxisValue(1) 1023.0 flag: 0 historicalSize: 1
01-28 13:19:58.180 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360328 pressure: 0.75 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1023.5117 flag: 0 historicalSize: 1
01-28 13:19:58.197 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360344 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1024.3497 flag: 0 historicalSize: 1
01-28 13:19:58.214 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360361 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1025.151 flag: 0 historicalSize: 2
01-28 13:19:58.230 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360378 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1025.9537 flag: 0 historicalSize: 1
01-28 13:19:58.247 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360394 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1026.7559 flag: 0 historicalSize: 2
01-28 13:19:58.264 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360411 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1027.5531 flag: 0 historicalSize: 2
01-28 13:19:58.280 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360428 pressure: 0.7625 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1028.3606 flag: 0 historicalSize: 1
01-28 13:19:58.300 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360444 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1029.1615 flag: 0 historicalSize: 2
01-28 13:19:58.314 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360461 pressure: 0.77500004 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1029.966 flag: 0 historicalSize: 1
01-28 13:19:58.330 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360478 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1030.7684 flag: 0 historicalSize: 2
01-28 13:19:58.347 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360494 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1031.5704 flag: 0 historicalSize: 2
01-28 13:19:58.364 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360509 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1032.25 flag: 0 historicalSize: 1
01-28 13:19:58.414 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360561 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1032.7789 flag: 0 historicalSize: 1
01-28 13:19:58.431 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360578 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1033.5829 flag: 0 historicalSize: 2
01-28 13:19:58.449 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360592 pressure: 0.7875 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1034.25 flag: 0 historicalSize: 1
01-28 13:19:58.464 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360611 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1034.5911 flag: 0 historicalSize: 1
01-28 13:19:58.497 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360636 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1035.1934 flag: 0 historicalSize: 1
01-28 13:19:58.631 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360778 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1035.5144 flag: 0 historicalSize: 1
01-28 13:19:58.648 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158360789 pressure: 0.8 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.25 flag: 0 historicalSize: 1
01-28 13:20:00.638 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158362784 pressure: 0.8125 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1037.25 flag: 0 historicalSize: 2
01-28 13:20:00.927 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 2 DownTime: 158360275 eventtime: 158363070 pressure: 0.7 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.5 flag: 0 historicalSize: 0
01-28 13:20:00.928 31404-31404/com.myapp.myapp I/HumanRawMotion﹕ Action: 1 DownTime: 158360275 eventtime: 158363080 pressure: 0.7 finger x 0: getAxisValue(0) 546.0 finger y 0: getAxisValue(1) 1036.5 flag: 0 historicalSize: 0
保存的历史实际上并不是历史,因为它保存了从最后一个向下指针开始的所有事件,而是 Android 在需要保持性能时将几个 MotionEvent
批处理在一起。那些存储在历史记录中。
您可以参考 MotionEvent docs 的 批处理 部分了解更多信息。