/**
   * email a flight
   *
   * @param flightid
   * @param filetype kml or igc
   */
  private void emailFlight(final long flightid, final String filetype) {

    final String filetypeUpper = filetype.toUpperCase();

    AsyncProgressDialog progress =
        new AsyncFileWriter(flightid, filetype) {

          /*
           * (non-Javadoc)
           *
           * @see
           * com.geeksville.view.AsyncProgressDialog#onPostExecute
           * (java.lang .Void)
           */
          @Override
          protected void onPostExecute(Void unused) {
            super.onPostExecute(unused);

            if (fileLoc != null) {
              Uri fileuri = Uri.fromFile(fileLoc);

              // Intent sendIntent = new
              // Intent(Intent.ACTION_SEND_MULTIPLE);
              Intent sendIntent = new Intent(Intent.ACTION_SEND);
              // Mime type of the attachment (or) u can use
              // sendIntent.setType("*/*")
              if (filetype.equals("igc")) sendIntent.setType("application/x-igc");
              else
                // FIXME, support kmz
                sendIntent.setType("application/vnd.google-earth.kml+xml");

              // sendIntent.setType("*/*");
              // Subject for the message or Email
              sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Flight");

              // Full Path to the attachment
              // ArrayList<Uri> files = new ArrayList<Uri>();
              // files.add(fileuri);
              // sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
              // files);
              sendIntent.putExtra(Intent.EXTRA_STREAM, fileuri);

              // Use a chooser to decide whether email or mms
              startActivity(Intent.createChooser(sendIntent, "Send flight"));

              // Keep stats on # of emails sent
              Map<String, String> map = new HashMap<String, String>();
              map.put("Time", (new Date()).toGMTString());
              FlurryAgent.onEvent("EmailFlight", map);
            }
          }
        };

    progress.execute();
  }
  /**
   * view a flight in google earth - FIXME, doesn't yet work - need to check their manifest
   *
   * @param flightid
   * @param filetype kml or igc
   */
  private void externalViewFlight(final long flightid, final String filetype) {

    final String filetypeUpper = filetype.toUpperCase();

    AsyncProgressDialog progress =
        new AsyncFileWriter(flightid, filetype) {

          /*
           * (non-Javadoc)
           *
           * @see
           * com.geeksville.view.AsyncProgressDialog#onPostExecute
           * (java.lang .Void)
           */
          @Override
          protected void onPostExecute(Void unused) {
            super.onPostExecute(unused);

            if (fileLoc != null) {
              Uri fileuri = Uri.fromFile(fileLoc);

              // Intent sendIntent = new
              // Intent(Intent.ACTION_SEND_MULTIPLE);
              Intent sendIntent = new Intent(Intent.ACTION_VIEW, fileuri);
              // Mime type of the attachment (or) u can use
              // sendIntent.setType("*/*")
              if (filetype.equals("igc")) sendIntent.setType("application/x-igc");
              else
                // FIXME, support kmz
                sendIntent.setType("application/vnd.google-earth.kml+xml");

              startActivity(Intent.createChooser(sendIntent, getString(R.string.view_flight)));

              // Keep stats on # of emails sent
              Map<String, String> map = new HashMap<String, String>();
              map.put("Time", (new Date()).toGMTString());
              FlurryAgent.onEvent("GEarthView", map);
            }
          }
        };

    progress.execute();
  }
  private void leonardoUpload(final long flightid) {

    final Account acct = new Account(this, "delayed");

    if (acct.isValid()) {
      AsyncProgressDialog progress =
          new AsyncProgressDialog(
              this, getString(R.string.uploading), getString(R.string.please_wait)) {
            @Override
            protected void doInBackground() {

              String fileLoc;

              try {
                fileLoc = flightToIGC(flightid);
              } catch (IOException ex) {
                showCompletionDialog(
                    getString(R.string.igc_stream_write_failed), ex.getLocalizedMessage());
                return;
              }

              try {
                String basename = getString(R.string.flight_) + flightid;

                showCompletionToast(
                    LeonardoUpload.upload(
                        acct.username, acct.password, acct.serverURL, basename, fileLoc));

              } catch (IOException ex) {
                showCompletionDialog(getString(R.string.upload_failed), ex.getLocalizedMessage());
              }
            }
          };

      progress.execute();
    } else {
      Toast.makeText(this, R.string.please_set_your_leonardo_account_information, Toast.LENGTH_LONG)
          .show();
      startActivity(new Intent(this, MyPreferences.class));
    }
  }
Beispiel #4
0
  private void startLogging() {

    final Account acct = new Account(this, "live2");

    // We always log to the DB
    final PositionWriter dbwriter =
        new LocationDBWriter(this, prefs.isDelayedUpload(), prefs.getPilotName(), null);

    // Also always keep the the current live track
    // FIXME - skanky way we pass live tracks to the map
    LocationList loclist = new LocationList();
    FlyMapActivity.liveList = loclist;

    final PositionWriter ramwriter = new LocationListWriter(loclist);

    loggingButton.setEnabled(false); // Turn off the button until our
    // background thread finishes

    AsyncProgressDialog progress =
        new AsyncProgressDialog(
            this, getString(R.string.starting_logging), getString(R.string.please_wait)) {

          @Override
          protected void doInBackground() {
            PositionWriter[] selected = null;

            // Possibly also leonardo live
            if (prefs.isLiveUpload()) {
              try {
                if (!acct.isValid())
                  throw new Exception(getString(R.string.username_or_password_is_unset));

                // FIXME - do this in an async dialog helper
                PositionWriter liveWriter =
                    new LeonardoLiveWriter(
                        LoggingControl.this,
                        acct.serverURL,
                        acct.username,
                        acct.password,
                        prefs.getWingModel(),
                        prefs.getLogInterval());

                selected = new PositionWriter[] {dbwriter, ramwriter, liveWriter};
              } catch (Exception ex) {
                // Bad password or connection problems
                showCompletionDialog(
                    LoggingControl.this.getString(R.string.leonardolive_problem), ex.getMessage());
              }
            }

            // If we haven't already connected to the live server
            if (selected == null) selected = new PositionWriter[] {dbwriter, ramwriter};

            PositionWriter writer = new PositionWriterSet(selected);

            // Start up our logger service
            GPSToPositionWriter gpsToPos = ((GaggleApplication) getApplication()).getGpsLogger();

            gpsToPos.startLogging(
                getApplication(),
                writer,
                prefs.getLogInterval(),
                prefs.getLaunchDistX(),
                prefs.getLaunchDistY());
          }

          /** @see com.geeksville.view.AsyncProgressDialog#onPostExecute (java.lang.Void) */
          @Override
          protected void onPostExecute(Void unused) {
            loggingButton.setEnabled(true);

            super.onPostExecute(unused);
          }
        };

    progress.execute();
  }