Exemplo n.º 1
0
  private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
Exemplo n.º 2
0
  private final void clearDataCache() {
    java.util.Iterator it = dataCache.values().iterator();

    while (it.hasNext()) {
      File f = (File) it.next();
      f.delete();
    }
  }
  private void saveData(TelemetryData data) {
    PrintWriter out;
    boolean newFile = false;

    if (saveCnt > 25000) {
      File logFile;
      int i;

      logFile = new File(telemetryDir + 99 + ".log");
      logFile.delete();
      newFile = true;

      for (i = 99; i > 0; i--) {
        logFile = new File(telemetryDir + (i - 1) + ".log");
        logFile.renameTo(new File(telemetryDir + i + ".log"));
      }
      saveCnt = 0;
    }

    try {
      String text = "";
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);

      saveCnt++;
      out = new PrintWriter(new FileOutputStream(telemetryDir + "0.log", true));
      if (newFile) {
        text =
            "Time\tLatitude\tLongitude\tSpeed\tAcceleration X\tAcceleration Y\tAcceleration Z\tCoG\tOrientation Y\tOrientation Z\n\n";
        out.print(text);
      }
      text = dateFormat.format(new Date(System.currentTimeMillis())) + "\t";
      if (posValid) text = text + lastLat + "\t" + lastLon + "\t" + m_lastSpeed + "\t";
      else text = text + "-\t-\t-\t";
      text =
          text
              + data.getAccelX()
              + "\t"
              + data.getAccelY()
              + "\t"
              + data.getAccelZ()
              + "\t"
              + data.CoG
              + "\t"
              + data.getOrientY()
              + "\t"
              + data.getOrientZ()
              + "\n\n";
      out.print(text);
      out.close();
    } catch (IOException ioe) {
    }
  }
Exemplo n.º 4
0
 void removeFiles() throws IOException {
   BufferedReader reader = new BufferedReader(new FileReader(new File(sGREDir, "removed-files")));
   try {
     for (String removedFileName = reader.readLine();
         removedFileName != null;
         removedFileName = reader.readLine()) {
       File removedFile = new File(sGREDir, removedFileName);
       if (removedFile.exists()) removedFile.delete();
     }
   } finally {
     reader.close();
   }
 }
Exemplo n.º 5
0
  private final synchronized File getDataCacheFile(byte[] data) {
    try {
      java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
      digest.update(data);

      String key = bytesToHex(digest.digest());

      if (dataCache.containsKey(key)) return (File) dataCache.get(key);

      File f = new File(this.getCacheDir(), "bindata_" + key);
      f.delete();
      FileOutputStream os = new FileOutputStream(f);
      os.write(data, 0, data.length);
      dataCache.put(key, f);
      return f;
    } catch (Throwable e) {
    }

    return null;
  }
Exemplo n.º 6
0
    @Override
    protected String doInBackground(String... sUrl) {

      File folders = new File(Environment.getExternalStorageDirectory() + "/pathofthefile/");
      folders.mkdirs();

      File file;
      file =
          new File(
              Environment.getExternalStorageDirectory()
                  + "/pathofthefile/"
                  + FirstSettings_two.file_video);

      if (!file.exists()) {
        try {
          file.createNewFile();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else {
        file.delete();
        try {
          file.createNewFile();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

      try {
        URL url = new URL(sUrl[0]);
        URLConnection connection = url.openConnection();
        connection.connect();
        // this will be useful so that you can show a typical 0-100%
        // progress bar
        int fileLength = connection.getContentLength();

        // download the file
        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(file);

        byte data[] = new byte[1024];
        long total = 0;
        int count;
        while ((count = input.read(data)) != -1) {
          total += count;
          // publishing the progress....
          publishProgress((int) (total * 100 / fileLength));
          output.write(data, 0, count);
        }

        output.flush();
        output.close();
        input.close();
        return "Downloaded";
      } catch (Exception e) {
        //   Toast.makeText(context,
        //         "exeption",Toast.LENGTH_LONG).show();

        return null;
      }
    }