早上好,我正在Android Nexus 7上开发一个应用程序。我使用方法event.getEventTime(),我注意到时间戳不是有规律的间隔。存在大的不规则性,并且在一些情况下,两个时间戳之间的差异是0.我将需要例如规则的间隔,例如10或100毫秒用于后续处理。有办法克服这个问题吗?提前感谢您的建议。
我在下面报告了捕获与移动相关的参数的代码段。 我想知道为什么在移动的情况下,设备不会以规则的采样间隔收集数据
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
lastTouchX = eventX;
lastTouchY = eventY;
//----------------------------------
datiPunto[0] = String.valueOf(eventX);
datiPunto[1] = String.valueOf(eventY);
datiPunto[2] = String.valueOf(time);
datiPunto[3] = String.valueOf(event.getAction());
datiPunto[4] = "0";
datiPunto[5] = "0";
datiPunto[6] = String.valueOf(pressure);
CSVFileWriter.mem(datiPunto,tempDir, nome);
Log.i("worning","file csv memorizzato");
//----------------------------------
return true;
case MotionEvent.ACTION_MOVE:
resetDirtyRect(eventX, eventY);
int historySize = event.getHistorySize();
//float action = event.getAction();
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);
float historicalPressure = event.getHistoricalPressure(i);
long historicalTime = event.getHistoricalEventTime(i);
//----------------------------------
datiPunto[0] = String.valueOf(historicalX);
datiPunto[1] = String.valueOf(historicalY);
datiPunto[2] = String.valueOf(historicalTime);
datiPunto[3] = String.valueOf(event.getAction());
datiPunto[4] ="0";
datiPunto[5] = "0";
//datiPunto[4] = String.valueOf(action);
datiPunto[6] = String.valueOf(historicalPressure);
CSVFileWriter.mem(datiPunto,tempDir, nome);
Log.i("worning","file csv memorizzato");
//----------------------------------
expandDirtyRect(historicalX, historicalY);
path.lineTo(historicalX, historicalY);
} // close loop historical data
//----------------------------------
datiPunto[0] = String.valueOf(eventX);
datiPunto[1] = String.valueOf(eventY);
datiPunto[2] = String.valueOf(time);
datiPunto[3] = String.valueOf(event.getAction());
datiPunto[4] = "0";
datiPunto[5] = "0";
datiPunto[6] = String.valueOf(pressure);
CSVFileWriter.mem(datiPunto,tempDir, nome);
Log.i("worning","file csv memorizzato");
//----------------------------------
path.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
datiPunto[0] = String.valueOf(eventX);
datiPunto[1] = String.valueOf(eventY);
datiPunto[2] = String.valueOf(time);
datiPunto[3] = String.valueOf(event.getAction());
datiPunto[4] = "0";
datiPunto[5] = "0";
datiPunto[6] = String.valueOf(pressure);
CSVFileWriter.mem(datiPunto,tempDir, nome);
Log.i("worning","file csv memorizzato");
countPenUp++;
break;