private void getCarsFromCache() {
    File directory;
    try {
      directory = Util.resolveExternalStorageBaseFolder();

      File f = new File(directory, CarManager.CAR_CACHE_FILE_NAME);

      if (f.isFile()) {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(f));

        String content = "";
        String line = "";

        while ((line = bufferedReader.readLine()) != null) {
          content = content.concat(line);
        }

        bufferedReader.close();

        JSONArray cars = new JSONArray(content);

        addSensorsToList(cars);
      }
    } catch (IOException e) {
      logger.warn(e.getMessage(), e);
    } catch (JSONException e) {
      logger.warn(e.getMessage(), e);
    }
  }
Exemple #2
0
  /**
   * Returns the length of a track in kilometers
   *
   * @return
   */
  public double getLengthOfTrack() {
    List<Measurement> measurements = this.getMeasurements();

    double distance = 0.0;

    if (measurements.size() > 1) {
      for (int i = 0; i < measurements.size() - 1; i++) {
        distance =
            distance
                + Util.getDistance(
                    measurements.get(i).getLatitude(),
                    measurements.get(i).getLongitude(),
                    measurements.get(i + 1).getLatitude(),
                    measurements.get(i + 1).getLongitude());
      }
    }
    return distance;
  }