private void displayElapsedTime() {
    long calibrationStopTime = System.currentTimeMillis();
    long elapsedTime = calibrationStopTime - calibrationStartTime;

    Toast.makeText(this, "Elapsed time: " + elapsedTime + " ms", Toast.LENGTH_LONG).show();

    calibrationStartTime = System.currentTimeMillis();
  }
  public void startSampling(final SensorEventListener listener) {
    samples.clear();

    Sensor accelerometer = sensor.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    calibrationStartTime = System.currentTimeMillis();
    sensor.registerListener(listener, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
  }