0

早上好,我正在 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;
4

0 回答 0