示例#1
1
  @Override
  protected void onDestroy() {

    Utilities.LogDebug("GpsMainActivity.onDestroy");
    StopAndUnbindServiceIfRequired();
    super.onDestroy();
  }
示例#2
0
  /** Event raised when the form is created for the first time */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    Utilities.LogDebug("GpsMainActivity.onCreate");

    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String lang = prefs.getString("locale_override", "");

    if (!lang.equalsIgnoreCase("")) {
      Locale locale = new Locale(lang);
      Locale.setDefault(locale);
      Configuration config = new Configuration();
      config.locale = locale;
      getApplicationContext()
          .getResources()
          .updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());
    }

    super.onCreate(savedInstanceState);

    Utilities.LogInfo("GPSLogger started");

    setContentView(R.layout.main);

    GetPreferences();

    StartAndBindService();
  }
示例#3
0
  private void EmailNow() {
    Utilities.LogDebug("GpsMainActivity.EmailNow");

    if (Utilities.IsEmailSetup()) {
      loggingService.ForceEmailLogFile();
    } else {
      Intent emailSetup = new Intent(getApplicationContext(), AutoEmailActivity.class);
      startActivity(emailSetup);
    }
  }
示例#4
0
 /** @return the currentFileName (without extension) */
 public static String getCurrentFileName() {
   if (AppSettings.isCustomFile() && !Utilities.IsNullOrEmpty(currentFileName)) {
     return Utilities.GetFormattedCustomFileName(currentFileName);
   } else {
     if (!Utilities.IsNullOrEmpty(currentFileName)
         && AppSettings.shouldPrefixSerialToFileName()
         && !currentFileName.contains(Utilities.GetBuildSerial())) {
       currentFileName = String.valueOf(Utilities.GetBuildSerial()) + "_" + currentFileName;
     }
   }
   return currentFileName;
 }
示例#5
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);
    }
  }
示例#6
0
  /** Clears the table, removes all values. */
  public void ClearForm() {

    Utilities.LogDebug("GpsMainActivity.ClearForm");

    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);

    tvLatitude.setText("");
    tvLongitude.setText("");
    tvDateTime.setText("");
    tvAltitude.setText("");
    txtSpeed.setText("");
    txtSatellites.setText("");
    txtDirection.setText("");
    txtAccuracy.setText("");
  }
示例#7
0
  /** Called when one of the menu items is selected. */
  public boolean onOptionsItemSelected(MenuItem item) {

    int itemId = item.getItemId();
    Utilities.LogInfo("Option item selected - " + String.valueOf(item.getTitle()));

    switch (itemId) {
      case R.id.mnuSettings:
        Intent settingsActivity = new Intent(getApplicationContext(), GpsSettingsActivity.class);
        startActivity(settingsActivity);
        break;
      case R.id.mnuOSM:
        UploadToOpenStreetMap();
        break;
      case R.id.mnuDropBox:
        UploadToDropBox();
        break;
      case R.id.mnuAnnotate:
        Annotate();
        break;
      case R.id.mnuShare:
        Share();
        break;
      case R.id.mnuEmailnow:
        EmailNow();
        break;
      case R.id.mnuExit:
        loggingService.StopLogging();
        loggingService.stopSelf();
        finish();
        break;
    }
    return false;
  }
示例#8
0
  private void UploadToDropBox() {
    Utilities.LogDebug("GpsMainActivity.UploadToDropBox");

    final DropBoxHelper dropBoxHelper = new DropBoxHelper(getApplicationContext(), this);

    if (!dropBoxHelper.IsLinked()) {
      startActivity(new Intent("com.mendhak.gpslogger.DROPBOX_SETUP"));
      return;
    }

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

    if (gpxFolder.exists()) {

      String[] enumeratedFiles = gpxFolder.list();
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.dropbox_upload);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];
              Utilities.ShowProgress(
                  GpsMainActivity.this,
                  getString(R.string.dropbox_uploading),
                  getString(R.string.please_wait));
              dropBoxHelper.UploadFile(chosenFileName);
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
示例#9
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);
  }
示例#10
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);
 }
示例#11
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();
  }
 public boolean onPreferenceClick(Preference preference) {
   if (!IsFormValid()) {
     Utilities.MsgBox(
         getString(R.string.autoopengts_invalid_form),
         getString(R.string.autoopengts_invalid_form_message),
         OpenGTSActivity.this);
     return false;
   }
   return true;
 }
示例#13
0
  /** Called when the toggle button is clicked */
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    Utilities.LogDebug("GpsMainActivity.onCheckedChanged");

    if (isChecked) {
      GetPreferences();
      SetSinglePointButtonEnabled(false);
      loggingService.StartLogging();
    } else {
      SetSinglePointButtonEnabled(true);
      loggingService.StopLogging();
    }
  }
示例#14
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);
    }
  }
示例#15
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);
    }
  }
示例#16
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);
    }
  }
示例#17
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));
      }
    }
  }
示例#18
0
  public static String GetFormattedCustomFileName(String baseName) {

    Time t = new Time();
    t.setToNow();

    String finalFileName = baseName;
    finalFileName =
        finalFileName.replaceAll("(?i)%ser", String.valueOf(Utilities.GetBuildSerial()));
    finalFileName = finalFileName.replaceAll("(?i)%hour", String.valueOf(t.hour));
    finalFileName = finalFileName.replaceAll("(?i)%min", String.valueOf(t.minute));
    finalFileName = finalFileName.replaceAll("(?i)%year", String.valueOf(t.year));
    finalFileName = finalFileName.replaceAll("(?i)%month", String.valueOf(t.month + 1));
    finalFileName = finalFileName.replaceAll("(?i)%day", String.valueOf(t.monthDay));
    return finalFileName;
  }
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
     if (!IsFormValid()) {
       Utilities.MsgBox(
           getString(R.string.autoopengts_invalid_form),
           getString(R.string.autoopengts_invalid_form_message),
           this);
       return false;
     } else {
       return super.onKeyDown(keyCode, event);
     }
   } else {
     return super.onKeyDown(keyCode, event);
   }
 }
示例#20
0
  @Override
  public void run() {
    if (!kmlFile.exists()) {
      return;
    }

    try {
      synchronized (Kml22FileLogger.lock) {
        StringBuilder descriptionNode = new StringBuilder();
        descriptionNode.append("<Placemark><name>");
        descriptionNode.append(description);
        descriptionNode.append("</name><Point><coordinates>");
        descriptionNode.append(String.valueOf(loc.getLongitude()));
        descriptionNode.append(",");
        descriptionNode.append(String.valueOf(loc.getLatitude()));
        descriptionNode.append(",");
        descriptionNode.append(String.valueOf(loc.getAltitude()));
        descriptionNode.append("</coordinates></Point></Placemark>\n");

        BufferedReader bf = new BufferedReader(new FileReader(kmlFile));

        StringBuilder restOfFile = new StringBuilder();
        String currentLine;
        int lineNumber = 1;

        while ((currentLine = bf.readLine()) != null) {
          if (lineNumber > 1) {
            restOfFile.append(currentLine);
            restOfFile.append("\n");
          }

          lineNumber++;
        }

        bf.close();

        RandomAccessFile raf = new RandomAccessFile(kmlFile, "rw");
        raf.seek(255);
        raf.write(descriptionNode.toString().getBytes());
        raf.write(restOfFile.toString().getBytes());
        raf.close();
      }
    } catch (Exception e) {
      Utilities.LogError("Kml22FileLogger.Annotate", e);
    }
  }
  @Override
  protected void onResume() {
    super.onResume();

    try {
      if (helper.FinishAuthorization()) {
        startActivity(new Intent(getApplicationContext(), GpsMainActivity.class));
        finish();
      }
    } catch (Exception e) {
      Utilities.MsgBox(
          getString(R.string.error),
          getString(R.string.dropbox_couldnotauthorize),
          DropBoxAuthorizationActivity.this);
      tracer.error("DropBoxAuthorizationActivity.onResume", e);
    }
  }
示例#22
0
 @Override
 public void OnFailure() {
   Utilities.HideProgress();
 }
示例#23
0
  @Override
  public void run() {
    try {

      RandomAccessFile raf;

      String dateTimeString = Utilities.GetIsoDateTime(new Date(loc.getTime()));
      String placemarkHead = "<Placemark>\n<gx:Track>\n";
      String placemarkTail = "</gx:Track>\n</Placemark></Document></kml>\n";

      synchronized (Kml22FileLogger.lock) {
        if (!kmlFile.exists()) {
          kmlFile.createNewFile();

          FileOutputStream initialWriter = new FileOutputStream(kmlFile, true);
          BufferedOutputStream initialOutput = new BufferedOutputStream(initialWriter);

          StringBuilder initialXml = new StringBuilder();
          initialXml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
          initialXml.append("<kml xmlns=\"http://www.opengis.net/kml/2.2\" ");
          initialXml.append("xmlns:gx=\"http://www.google.com/kml/ext/2.2\" ");
          initialXml.append("xmlns:kml=\"http://www.opengis.net/kml/2.2\" ");
          initialXml.append("xmlns:atom=\"http://www.w3.org/2005/Atom\">");
          initialXml.append("<Document>");
          initialXml.append("<name>").append(dateTimeString).append("</name>\n");

          initialXml.append("</Document></kml>\n");
          initialOutput.write(initialXml.toString().getBytes());
          initialOutput.flush();
          initialOutput.close();

          // New file, so new track segment
          addNewTrackSegment = true;
        }

        if (addNewTrackSegment) {
          raf = new RandomAccessFile(kmlFile, "rw");
          raf.seek(kmlFile.length() - 18);
          raf.write((placemarkHead + placemarkTail).getBytes());
          raf.close();
        }

        StringBuilder coords = new StringBuilder();
        coords.append("\n<when>");
        coords.append(dateTimeString);
        coords.append("</when>\n<gx:coord>");
        coords.append(String.valueOf(loc.getLongitude()));
        coords.append(" ");
        coords.append(String.valueOf(loc.getLatitude()));
        coords.append(" ");
        coords.append(String.valueOf(loc.getAltitude()));
        coords.append("</gx:coord>\n");
        coords.append(placemarkTail);

        raf = new RandomAccessFile(kmlFile, "rw");
        raf.seek(kmlFile.length() - 42);
        raf.write(coords.toString().getBytes());
        raf.close();
        Utilities.LogDebug("Finished writing to KML22 File");
      }

    } catch (Exception e) {
      Utilities.LogError("Kml22FileLogger.Write", e);
    }
  }
示例#24
0
 public void OnFatalMessage(String message) {
   Utilities.MsgBox(getString(R.string.sorry), message, this);
 }
示例#25
0
 @Override
 public void OnComplete() {
   Utilities.HideProgress();
 }
示例#26
0
  /**
   * Allows user to send a GPX/KML file along with location, or location only using a provider.
   * 'Provider' means any application that can accept such an intent (Facebook, SMS, Twitter, Email,
   * K-9, Bluetooth)
   */
  private void Share() {
    Utilities.LogDebug("GpsMainActivity.Share");
    try {

      final String locationOnly = getString(R.string.sharing_location_only);
      final File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger");
      if (gpxFolder.exists()) {
        String[] enumeratedFiles = gpxFolder.list();
        List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
        Collections.reverse(fileList);
        fileList.add(0, locationOnly);
        final String[] files = fileList.toArray(new String[fileList.size()]);

        final Dialog dialog = new Dialog(this);
        dialog.setTitle(R.string.sharing_pick_file);
        dialog.setContentView(R.layout.filelist);
        ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

        thelist.setAdapter(
            new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

        thelist.setOnItemClickListener(
            new OnItemClickListener() {

              public void onItemClick(AdapterView<?> av, View v, int index, long arg) {
                dialog.dismiss();
                String chosenFileName = files[index];

                final Intent intent = new Intent(Intent.ACTION_SEND);

                // intent.setType("text/plain");
                intent.setType("*/*");

                if (chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.setType("text/plain");
                }

                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                if (Session.hasValidLocation()) {
                  String bodyText =
                      getString(
                          R.string.sharing_latlong_text,
                          String.valueOf(Session.getCurrentLatitude()),
                          String.valueOf(Session.getCurrentLongitude()));
                  intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                  intent.putExtra("sms_body", bodyText);
                }

                if (chosenFileName.length() > 0 && !chosenFileName.equalsIgnoreCase(locationOnly)) {
                  intent.putExtra(
                      Intent.EXTRA_STREAM, Uri.fromFile(new File(gpxFolder, chosenFileName)));
                }

                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
              }
            });
        dialog.show();
      } else {
        Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
      }
    } catch (Exception ex) {
      Utilities.LogError("Share", ex);
    }
  }
示例#27
0
  /** Uploads a GPS Trace to OpenStreetMap.org. */
  private void UploadToOpenStreetMap() {
    Utilities.LogDebug("GpsMainactivity.UploadToOpenStreetMap");

    if (!OSMHelper.IsOsmAuthorized(getApplicationContext())) {
      startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
      return;
    }

    final String goToOsmSettings = getString(R.string.menu_settings);

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

    if (gpxFolder.exists()) {
      FilenameFilter select =
          new FilenameFilter() {

            public boolean accept(File dir, String filename) {
              return filename.toLowerCase().contains(".gpx");
            }
          };

      String[] enumeratedFiles = gpxFolder.list(select);
      List<String> fileList = new ArrayList<String>(Arrays.asList(enumeratedFiles));
      Collections.reverse(fileList);
      fileList.add(0, goToOsmSettings);
      final String[] files = fileList.toArray(new String[fileList.size()]);

      final Dialog dialog = new Dialog(this);
      dialog.setTitle(R.string.osm_pick_file);
      dialog.setContentView(R.layout.filelist);
      ListView thelist = (ListView) dialog.findViewById(R.id.listViewFiles);

      thelist.setAdapter(
          new ArrayAdapter<String>(
              getApplicationContext(), android.R.layout.simple_list_item_single_choice, files));

      thelist.setOnItemClickListener(
          new OnItemClickListener() {

            public void onItemClick(AdapterView<?> av, View v, int index, long arg) {

              dialog.dismiss();
              String chosenFileName = files[index];

              if (chosenFileName.equalsIgnoreCase(goToOsmSettings)) {
                startActivity(OSMHelper.GetOsmSettingsIntent(getApplicationContext()));
              } else {
                OSMHelper osm = new OSMHelper(GpsMainActivity.this, GpsMainActivity.this);
                Utilities.ShowProgress(
                    GpsMainActivity.this,
                    getString(R.string.osm_uploading),
                    getString(R.string.please_wait));
                osm.UploadGpsTrace(chosenFileName);
              }
            }
          });
      dialog.show();
    } else {
      Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this);
    }
  }
示例#28
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()));
    }
  }
示例#29
0
 /**
  * Sets the message in the top status label.
  *
  * @param message The status message
  */
 private void SetStatus(String message) {
   Utilities.LogDebug("GpsMainActivity.SetStatus: " + message);
   TextView tvStatus = (TextView) findViewById(R.id.textStatus);
   tvStatus.setText(message);
   Utilities.LogInfo(message);
 }
示例#30
0
 public void OnStopLogging() {
   Utilities.LogDebug("GpsMainActivity.OnStopLogging");
   SetMainButtonChecked(false);
 }