Пример #1
0
  private void sendLogAndConfirm() {
    if (!sendButtonEnabled) {
      Dialogs.message(this, R.string.log_post_not_possible);
      return;
    }
    if (CalendarUtils.isFuture(date)) {
      Dialogs.message(this, R.string.log_date_future_not_allowed);
      return;
    }
    if (typeSelected.mustConfirmLog()) {
      Dialogs.confirm(
          this,
          R.string.confirm_log_title,
          res.getString(R.string.confirm_log_message, typeSelected.getL10n()),
          new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
              sendLogInternal();
            }
          });
    } else {
      sendLogInternal();
    }
  }
Пример #2
0
 @Override
 public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
   final IntentResult scanResult =
       IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
   if (scanResult != null) {
     final String scan = scanResult.getContents();
     if (StringUtils.isBlank(scan)) {
       return;
     }
     SearchActivity.startActivityScan(scan, this);
   } else if (requestCode == SEARCH_REQUEST_CODE) {
     // SearchActivity activity returned without making a search
     if (resultCode == RESULT_CANCELED) {
       String query = intent.getStringExtra(SearchManager.QUERY);
       if (query == null) {
         query = "";
       }
       Dialogs.message(this, res.getString(R.string.unknown_scan) + "\n\n" + query);
     }
   }
 }
Пример #3
0
    @Override
    public void onClick(final View arg0) {
      final String bearingText = bearing.getText().toString();
      // combine distance from EditText and distanceUnit saved from Spinner
      final String distanceText =
          distanceView.getText().toString()
              + distanceUnits.get(distanceUnitSelector.getSelectedItemPosition());
      final String latText = buttonLat.getText().toString();
      final String lonText = buttonLon.getText().toString();

      if (StringUtils.isBlank(bearingText)
          && StringUtils.isBlank(distanceText)
          && StringUtils.isBlank(latText)
          && StringUtils.isBlank(lonText)) {
        Dialogs.message(
            EditWaypointActivity.this,
            R.string.err_point_no_position_given_title,
            R.string.err_point_no_position_given);
        return;
      }

      Geopoint coords;

      if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
        try {
          coords = new Geopoint(latText, lonText);
        } catch (final Geopoint.ParseException e) {
          showToast(res.getString(e.resource));
          return;
        }
      } else {
        coords = app.currentGeo().getCoords();
      }

      if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
        // bearing & distance
        double bearing;
        try {
          bearing = Double.parseDouble(bearingText);
        } catch (final NumberFormatException ignored) {
          Dialogs.message(
              EditWaypointActivity.this,
              R.string.err_point_bear_and_dist_title,
              R.string.err_point_bear_and_dist);
          return;
        }

        double distance;
        try {
          distance = DistanceParser.parseDistance(distanceText, !Settings.useImperialUnits());
        } catch (final NumberFormatException ignored) {
          showToast(res.getString(R.string.err_parse_dist));
          return;
        }

        coords = coords.project(bearing, distance);
      }

      final String givenName = waypointName.getText().toString().trim();
      final String name =
          StringUtils.defaultIfBlank(givenName, getDefaultWaypointName(getSelectedWaypointType()));
      final String noteText = note.getText().toString().trim();
      final Geopoint coordsToSave = coords;
      final WaypointType type = getSelectedWaypointType();
      final boolean visited = visitedCheckBox.isChecked();
      final ProgressDialog progress =
          ProgressDialog.show(
              EditWaypointActivity.this,
              getString(R.string.waypoint),
              getString(R.string.waypoint_being_saved),
              true);
      final Handler finishHandler =
          new Handler() {

            @Override
            public void handleMessage(final Message msg) {
              switch (msg.what) {
                case UPLOAD_SUCCESS:
                  progress.dismiss();
                  finish();
                  showToast(
                      getString(
                          R.string.waypoint_coordinates_has_been_modified_on_website,
                          coordsToSave));
                  break;
                case SUCCESS:
                  progress.dismiss();
                  finish();
                  break;
                case UPLOAD_START:
                  progress.setMessage(
                      getString(R.string.waypoint_coordinates_uploading_to_website, coordsToSave));
                  break;
                case UPLOAD_ERROR:
                  progress.dismiss();
                  finish();
                  showToast(getString(R.string.waypoint_coordinates_upload_error));
                  break;
                case UPLOAD_NOT_POSSIBLE:
                  progress.dismiss();
                  finish();
                  showToast(
                      getString(R.string.waypoint_coordinates_couldnt_be_modified_on_website));
                  break;
                case SAVE_ERROR:
                  progress.dismiss();
                  finish(); // TODO: should we close activity here ?
                  showToast(res.getString(R.string.err_waypoint_add_failed));
                  break;
                default:
                  throw new UnsupportedOperationException();
              }
            }
          };

      class SaveWptTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(final Void... params) {
          final Waypoint waypoint = new Waypoint(name, type, own);
          waypoint.setGeocode(geocode);
          waypoint.setPrefix(prefix);
          waypoint.setLookup(lookup);
          waypoint.setCoords(coordsToSave);
          waypoint.setNote(noteText);
          waypoint.setVisited(visited);
          waypoint.setId(waypointId);

          final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
          if (cache == null) {
            finishHandler.sendEmptyMessage(SAVE_ERROR);
            return null;
          }
          final Waypoint oldWaypoint = cache.getWaypointById(waypointId);
          if (cache.addOrChangeWaypoint(waypoint, true)) {
            DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
            if (!StaticMapsProvider.hasAllStaticMapsForWaypoint(geocode, waypoint)) {
              StaticMapsProvider.removeWpStaticMaps(oldWaypoint, geocode);
              if (Settings.isStoreOfflineWpMaps()) {
                StaticMapsProvider.storeWaypointStaticMap(cache, waypoint).subscribe();
              }
            }
            if (modifyLocal.isChecked() || modifyBoth.isChecked()) {
              if (!cache.hasUserModifiedCoords()) {
                final Waypoint origWaypoint =
                    new Waypoint(
                        CgeoApplication.getInstance()
                            .getString(R.string.cache_coordinates_original),
                        WaypointType.ORIGINAL,
                        false);
                origWaypoint.setCoords(cache.getCoords());
                cache.addOrChangeWaypoint(origWaypoint, false);
                cache.setUserModifiedCoords(true);
              }
              cache.setCoords(waypoint.getCoords());
              DataStore.saveChangedCache(cache);
            }
            if (modifyBoth.isChecked() && waypoint.getCoords() != null) {
              finishHandler.sendEmptyMessage(UPLOAD_START);

              if (cache.supportsOwnCoordinates()) {
                final boolean result = uploadModifiedCoords(cache, waypoint.getCoords());
                finishHandler.sendEmptyMessage(result ? SUCCESS : UPLOAD_ERROR);
              } else {
                showToast(getString(R.string.waypoint_coordinates_couldnt_be_modified_on_website));
                finishHandler.sendEmptyMessage(UPLOAD_NOT_POSSIBLE);
              }
            } else {
              finishHandler.sendEmptyMessage(SUCCESS);
            }
          } else {
            finishHandler.sendEmptyMessage(SAVE_ERROR);
          }
          return null;
        }
      }
      new SaveWptTask().execute();
    }