历史MotionEvent是否有限制(时间或数量)?

时间:2016-01-28 12:50:04

标签: android motionevent

我已经覆盖了我的活动的methode dispatchTouchEvent以获取MotionEvents(只是添加了一些日志记录)。 我发现getHistorySize()方法的大小不是1-2。 典型的是,Motion的“历史”事件不会超过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);
    }

这是Log的输出,当我触摸并在显示器周围移动一根手指时:

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

1 个答案:

答案 0 :(得分:1)

保存的历史记录实际上并不是历史记录,因为它保存了从上一个向下指针开始的所有事件,而Android在需要时将几个MotionEvent批处理以保持性能。这些都存储在历史中。

您可以参考MotionEvent docs批处理部分获取更多相关信息。