Exemplo n.º 1
0
  private void shareLog() {

    synchronized (this) {

      // if we're logging save the log file
      if (afrAlarmLogging) {
        try {
          final String filename = new SimpleDateFormat("yyyyMMdd_HHmmss'.csv'").format(new Date());

          File sdcard = Environment.getExternalStorageDirectory();
          File dir = new File(sdcard.getAbsolutePath() + "/AdaptiveTuner/");
          dir.mkdirs();

          File file = new File(dir, filename);
          FileOutputStream f = new FileOutputStream(file);

          // write our header
          f.write("timestamp, rpm, map, targetafr, afr, refafr, wat, mat\n".getBytes());

          ArrayList<LogItem> items = afrAlarmLogItems.getItems();
          Iterator<LogItem> iterator = items.iterator();

          while (iterator.hasNext()) {
            final LogItem item = (LogItem) iterator.next();
            f.write(item.getLogBytes());
          }

          afrAlarmLogItems.getItems().clear();

          f.flush();
          f.close();

          menuShareLog.setVisible(false);

          Toast.makeText(
                  getApplicationContext(),
                  String.format(
                      "Log saved as %s%s%s", sdcard.getAbsolutePath(), "/AdaptiveTuner/", filename),
                  Toast.LENGTH_LONG)
              .show();
          if (DEBUG_MODE)
            Log.d(
                TAG,
                String.format(
                    "Log saved as %s%s%s", sdcard.getAbsolutePath(), "/AdaptiveTuner/", filename));

          Intent share = new Intent(Intent.ACTION_SEND);
          share.setType("text/plain");
          share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getPath()));
          startActivity(Intent.createChooser(share, getText(R.string.share_log)));

        } catch (Exception e) {
          Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }
      }
    }
  }