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;
 }
 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);
   }
 }
Example #3
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);
    }
  }
  @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);
    }
  }
Example #5
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();
  }
Example #6
0
 public void OnFatalMessage(String message) {
   Utilities.MsgBox(getString(R.string.sorry), message, this);
 }
Example #7
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);
    }
  }
Example #8
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);
    }
  }
Example #9
0
 /**
  * Displays a message box to the user with an OK button.
  *
  * @param title
  * @param message
  * @param className The calling class, such as GpsMainActivity.this or mainActivity.
  */
 public static void MsgBox(String title, String message, Context className) {
   MsgBox(title, message, className, null);
 }