2016-01-28 42 views
0

我已經覆蓋我的方法dispatchTouchEvent我的活動搶MotionEvents(只是添加了一些日誌記錄)。我觀察到getHistorySize()方法不具有1-2的大小。 典型的是,Motion的「歷史」事件不會保存超過1-2個事件嗎? 當我不提起手指一段時間時,我預計會有大量的歷史事件發生。歷史MotionEvent有沒有限制(時間或數量)?

@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 

回答

1

保存的歷史是沒有實際意義上的歷史,它保存所有從最後一個向下指針開始的事件,而不是Android在需要維護性能時一起批量執行幾個MotionEvent。這些都存儲在歷史中。

欲瞭解更多信息,請參考批次MotionEvent docs部分。