예제 #1
0
  public void OnLocationUpdate(Location loc) {
    Utilities.LogDebug("GpsMainActivity.OnLocationUpdate");
    DisplayLocationInfo(loc);
    ShowPreferencesSummary();
    SetMainButtonChecked(true);

    if (Session.isSinglePointMode()) {
      loggingService.StopLogging();
      SetMainButtonEnabled(true);
      Session.setSinglePointMode(false);
    }
  }
예제 #2
0
  /** Called when the single point button is clicked */
  public void onClick(View view) {
    Utilities.LogDebug("GpsMainActivity.onClick");

    if (!Session.isStarted()) {
      SetMainButtonEnabled(false);
      loggingService.StartLogging();
      Session.setSinglePointMode(true);
    } else if (Session.isStarted() && Session.isSinglePointMode()) {
      loggingService.StopLogging();
      SetMainButtonEnabled(true);
      Session.setSinglePointMode(false);
    }
  }
예제 #3
0
  /** Stops the service if it isn't logging. Also unbinds. */
  private void StopAndUnbindServiceIfRequired() {
    Utilities.LogDebug("GpsMainActivity.StopAndUnbindServiceIfRequired");
    if (Session.isBoundToService()) {
      unbindService(gpsServiceConnection);
      Session.setBoundToService(false);
    }

    if (!Session.isStarted()) {
      Utilities.LogDebug("StopServiceIfRequired - Stopping the service");
      // serviceIntent = new Intent(this, GpsLoggingService.class);
      stopService(serviceIntent);
    }
  }
예제 #4
0
  private void Annotate(String description) {
    Utilities.LogDebug("GpsMainActivity.Annotate(description)");

    List<IFileLogger> loggers = FileLoggerFactory.GetFileLoggers();

    for (IFileLogger logger : loggers) {
      try {
        logger.Annotate(description, Session.getCurrentLocationInfo());
        SetStatus(getString(R.string.description_added));
        Session.setAllowDescription(false);
      } catch (Exception e) {
        SetStatus(getString(R.string.could_not_write_to_file));
      }
    }
  }
예제 #5
0
  /** Handles the hardware back-button press */
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    Utilities.LogInfo("KeyDown - " + String.valueOf(keyCode));

    if (keyCode == KeyEvent.KEYCODE_BACK && Session.isBoundToService()) {
      StopAndUnbindServiceIfRequired();
    }

    return super.onKeyDown(keyCode, event);
  }
예제 #6
0
 /** Starts the service and binds the activity to it. */
 private void StartAndBindService() {
   Utilities.LogDebug("StartAndBindService - binding now");
   serviceIntent = new Intent(this, GpsLoggingService.class);
   // Start the service in case it isn't already running
   startService(serviceIntent);
   // Now bind to service
   bindService(serviceIntent, gpsServiceConnection, Context.BIND_AUTO_CREATE);
   Session.setBoundToService(true);
 }
예제 #7
0
        public void onServiceConnected(ComponentName name, IBinder service) {
          loggingService = ((GpsLoggingService.GpsLoggingBinder) service).getService();
          GpsLoggingService.SetServiceClient(GpsMainActivity.this);

          Button buttonSinglePoint = (Button) findViewById(R.id.buttonSinglePoint);

          buttonSinglePoint.setOnClickListener(GpsMainActivity.this);

          if (Session.isStarted()) {
            if (Session.isSinglePointMode()) {
              SetMainButtonEnabled(false);
            } else {
              SetMainButtonChecked(true);
              SetSinglePointButtonEnabled(false);
            }

            DisplayLocationInfo(Session.getCurrentLocationInfo());
          }

          // Form setup - toggle button, display existing location info
          ToggleButton buttonOnOff = (ToggleButton) findViewById(R.id.buttonOnOff);
          buttonOnOff.setOnCheckedChangeListener(GpsMainActivity.this);
        }
예제 #8
0
  public static void SendFiles(Context applicationContext, IActionListener callback) {

    final String currentFileName = Session.getCurrentFileName();

    File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");

    if (!gpxFolder.exists()) {
      callback.OnFailure();
      return;
    }

    List<File> files =
        new ArrayList<File>(
            Arrays.asList(
                gpxFolder.listFiles(
                    new FilenameFilter() {
                      @Override
                      public boolean accept(File file, String s) {
                        return s.contains(currentFileName) && !s.contains("zip");
                      }
                    })));

    if (files.size() == 0) {
      callback.OnFailure();
      return;
    }

    if (AppSettings.shouldSendZipFile()) {
      File zipFile = new File(gpxFolder.getPath(), currentFileName + ".zip");
      ArrayList<String> filePaths = new ArrayList<String>();

      for (File f : files) {
        filePaths.add(f.getAbsolutePath());
      }

      Utilities.LogInfo("Zipping file");
      ZipHelper zh =
          new ZipHelper(filePaths.toArray(new String[filePaths.size()]), zipFile.getAbsolutePath());
      zh.Zip();

      // files.clear();
      files.add(zipFile);
    }

    List<IFileSender> senders = GetFileSenders(applicationContext, callback);

    for (IFileSender sender : senders) {
      sender.UploadFile(files);
    }
  }
예제 #9
0
  public void onFileName(String newFileName) {
    if (newFileName == null || newFileName.length() <= 0) {
      return;
    }

    TextView txtFilename = (TextView) findViewById(R.id.txtFileName);

    if (AppSettings.shouldLogToGpx() || AppSettings.shouldLogToKml()) {

      txtFilename.setText(
          getString(R.string.summary_current_filename_format, Session.getCurrentFileName()));
    } else {
      txtFilename.setText("");
    }
  }
예제 #10
0
  /** Prompts user for input, then adds text to log file */
  private void Annotate() {
    Utilities.LogDebug("GpsMainActivity.Annotate");

    if (!AppSettings.shouldLogToGpx() && !AppSettings.shouldLogToKml()) {
      return;
    }

    if (!Session.shoulAllowDescription()) {
      Utilities.MsgBox(
          getString(R.string.not_yet),
          getString(R.string.cant_add_description_until_next_point),
          GetActivity());

      return;
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(GpsMainActivity.this);

    alert.setTitle(R.string.add_description);
    alert.setMessage(R.string.letters_numbers);

    // Set an EditText view to get user input
    final EditText input = new EditText(getApplicationContext());
    alert.setView(input);

    alert.setPositiveButton(
        R.string.ok,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            final String desc = Utilities.CleanDescription(input.getText().toString());
            Annotate(desc);
          }
        });
    alert.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            // Cancelled.
          }
        });

    alert.show();
  }
예제 #11
0
  /**
   * Given a location fix, processes it and displays it in the table on the form.
   *
   * @param loc Location information
   */
  private void DisplayLocationInfo(Location loc) {
    Utilities.LogDebug("GpsMainActivity.DisplayLocationInfo");
    try {

      if (loc == null) {
        return;
      }

      TextView tvLatitude = (TextView) findViewById(R.id.txtLatitude);
      TextView tvLongitude = (TextView) findViewById(R.id.txtLongitude);
      TextView tvDateTime = (TextView) findViewById(R.id.txtDateTimeAndProvider);

      TextView tvAltitude = (TextView) findViewById(R.id.txtAltitude);

      TextView txtSpeed = (TextView) findViewById(R.id.txtSpeed);

      TextView txtSatellites = (TextView) findViewById(R.id.txtSatellites);
      TextView txtDirection = (TextView) findViewById(R.id.txtDirection);
      TextView txtAccuracy = (TextView) findViewById(R.id.txtAccuracy);
      String providerName = loc.getProvider();

      if (providerName.equalsIgnoreCase("gps")) {
        providerName = getString(R.string.providername_gps);
      } else {
        providerName = getString(R.string.providername_celltower);
      }

      tvDateTime.setText(
          new Date(Session.getLatestTimeStamp()).toLocaleString()
              + getString(R.string.providername_using, providerName));
      tvLatitude.setText(String.valueOf(loc.getLatitude()));
      tvLongitude.setText(String.valueOf(loc.getLongitude()));

      if (loc.hasAltitude()) {

        double altitude = loc.getAltitude();

        if (AppSettings.shouldUseImperial()) {
          tvAltitude.setText(
              String.valueOf(Utilities.MetersToFeet(altitude)) + getString(R.string.feet));
        } else {
          tvAltitude.setText(String.valueOf(altitude) + getString(R.string.meters));
        }

      } else {
        tvAltitude.setText(R.string.not_applicable);
      }

      if (loc.hasSpeed()) {

        float speed = loc.getSpeed();
        String unit;
        if (AppSettings.shouldUseImperial()) {
          if (speed > 1.47) {
            speed = speed * 0.6818f;
            unit = getString(R.string.miles_per_hour);

          } else {
            speed = Utilities.MetersToFeet(speed);
            unit = getString(R.string.feet_per_second);
          }
        } else {
          if (speed > 0.277) {
            speed = speed * 3.6f;
            unit = getString(R.string.kilometers_per_hour);
          } else {
            unit = getString(R.string.meters_per_second);
          }
        }

        txtSpeed.setText(String.valueOf(speed) + unit);

      } else {
        txtSpeed.setText(R.string.not_applicable);
      }

      if (loc.hasBearing()) {

        float bearingDegrees = loc.getBearing();
        String direction;

        direction = Utilities.GetBearingDescription(bearingDegrees, getApplicationContext());

        txtDirection.setText(
            direction
                + "("
                + String.valueOf(Math.round(bearingDegrees))
                + getString(R.string.degree_symbol)
                + ")");
      } else {
        txtDirection.setText(R.string.not_applicable);
      }

      if (!Session.isUsingGps()) {
        txtSatellites.setText(R.string.not_applicable);
        Session.setSatelliteCount(0);
      }

      if (loc.hasAccuracy()) {

        float accuracy = loc.getAccuracy();

        if (AppSettings.shouldUseImperial()) {
          txtAccuracy.setText(
              getString(
                  R.string.accuracy_within,
                  String.valueOf(Utilities.MetersToFeet(accuracy)),
                  getString(R.string.feet)));

        } else {
          txtAccuracy.setText(
              getString(
                  R.string.accuracy_within, String.valueOf(accuracy), getString(R.string.meters)));
        }

      } else {
        txtAccuracy.setText(R.string.not_applicable);
      }

    } catch (Exception ex) {
      SetStatus(getString(R.string.error_displaying, ex.getMessage()));
    }
  }
예제 #12
0
 /**
  * Sets the number of satellites in the satellite row in the table.
  *
  * @param number The number of satellites
  */
 private void SetSatelliteInfo(int number) {
   Session.setSatelliteCount(number);
   TextView txtSatellites = (TextView) findViewById(R.id.txtSatellites);
   txtSatellites.setText(String.valueOf(number));
 }
예제 #13
0
  /** Displays a human readable summary of the preferences chosen by the user on the main form */
  private void ShowPreferencesSummary() {
    Utilities.LogDebug("GpsMainActivity.ShowPreferencesSummary");
    try {
      TextView txtLoggingTo = (TextView) findViewById(R.id.txtLoggingTo);
      TextView txtFrequency = (TextView) findViewById(R.id.txtFrequency);
      TextView txtDistance = (TextView) findViewById(R.id.txtDistance);
      TextView txtAutoEmail = (TextView) findViewById(R.id.txtAutoEmail);

      if (!AppSettings.shouldLogToKml() && !AppSettings.shouldLogToGpx()) {
        txtLoggingTo.setText(R.string.summary_loggingto_screen);

      } else if (AppSettings.shouldLogToGpx() && AppSettings.shouldLogToKml()) {
        txtLoggingTo.setText(R.string.summary_loggingto_both);
      } else {
        txtLoggingTo.setText((AppSettings.shouldLogToGpx() ? "GPX" : "KML"));
      }

      if (AppSettings.getMinimumSeconds() > 0) {
        String descriptiveTime =
            Utilities.GetDescriptiveTimeString(
                AppSettings.getMinimumSeconds(), getApplicationContext());

        txtFrequency.setText(descriptiveTime);
      } else {
        txtFrequency.setText(R.string.summary_freq_max);
      }

      if (AppSettings.getMinimumDistanceInMeters() > 0) {
        if (AppSettings.shouldUseImperial()) {
          int minimumDistanceInFeet =
              Utilities.MetersToFeet(AppSettings.getMinimumDistanceInMeters());
          txtDistance.setText(
              ((minimumDistanceInFeet == 1)
                  ? getString(R.string.foot)
                  : String.valueOf(minimumDistanceInFeet) + getString(R.string.feet)));
        } else {
          txtDistance.setText(
              ((AppSettings.getMinimumDistanceInMeters() == 1)
                  ? getString(R.string.meter)
                  : String.valueOf(AppSettings.getMinimumDistanceInMeters())
                      + getString(R.string.meters)));
        }
      } else {
        txtDistance.setText(R.string.summary_dist_regardless);
      }

      if (AppSettings.isAutoEmailEnabled()) {
        String autoEmailResx;

        if (AppSettings.getAutoEmailDelay() == 0) {
          autoEmailResx = "autoemail_frequency_whenistop";
        } else {

          autoEmailResx =
              "autoemail_frequency_"
                  + String.valueOf(AppSettings.getAutoEmailDelay()).replace(".", "");
        }

        String autoEmailDesc =
            getString(getResources().getIdentifier(autoEmailResx, "string", getPackageName()));

        txtAutoEmail.setText(autoEmailDesc);
      } else {
        TableRow trAutoEmail = (TableRow) findViewById(R.id.trAutoEmail);
        trAutoEmail.setVisibility(View.INVISIBLE);
      }

      onFileName(Session.getCurrentFileName());
    } catch (Exception ex) {
      Utilities.LogError("ShowPreferencesSummary", ex);
    }
  }