コード例 #1
0
        @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;
        }
コード例 #2
0
        @Override
        public void handleMessage(final Message msg) {
          try {
            if (waypoint == null) {
              Log.d("No waypoint loaded to edit. id= " + waypointId);
              waypointId = -1;
            } else {
              geocode = waypoint.getGeocode();
              prefix = waypoint.getPrefix();
              lookup = waypoint.getLookup();
              own = waypoint.isUserDefined();

              if (initViews) {
                visitedCheckBox.setChecked(waypoint.isVisited());
                if (waypoint.getCoords() != null) {
                  buttonLat.setText(
                      waypoint.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
                  buttonLon.setText(
                      waypoint.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
                }
                waypointName.setText(
                    Html.fromHtml(StringUtils.trimToEmpty(waypoint.getName())).toString());
                Dialogs.moveCursorToEnd(waypointName);
                if (TextUtils.containsHtml(waypoint.getNote())) {
                  note.setText(
                      Html.fromHtml(StringUtils.trimToEmpty(waypoint.getNote())).toString());
                } else {
                  note.setText(StringUtils.trimToEmpty(waypoint.getNote()));
                }
                Dialogs.moveCursorToEnd(note);
              }
              new AsyncTask<Void, Void, Geocache>() {
                @Override
                protected Geocache doInBackground(final Void... params) {
                  return DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_ONLY);
                }

                @Override
                protected void onPostExecute(final Geocache cache) {
                  setCoordsModificationVisibility(ConnectorFactory.getConnector(geocode), cache);
                }
              }.execute();
            }

            if (own) {
              initializeWaypointTypeSelector();
            }
          } catch (final RuntimeException e) {
            Log.e("EditWaypointActivity.loadWaypointHandler", e);
          } finally {
            if (waitDialog != null) {
              waitDialog.dismiss();
              waitDialog = null;
            }
          }
        }
コード例 #3
0
ファイル: GeocacheTest.java プロジェクト: schwabe/cgeo
  private void assertWaypointsParsed(final String note, final int expectedWaypoints) {
    recordMapStoreFlags();

    try {
      setMapStoreFlags(false, false);

      final Geocache cache = new Geocache();
      final String geocode = "Test" + System.nanoTime();
      cache.setGeocode(geocode);
      cache.setWaypoints(new ArrayList<Waypoint>(), false);
      for (int i = 0; i < 2; i++) {
        cache.setPersonalNote(note);
        cache.parseWaypointsFromNote();
        final List<Waypoint> waypoints = cache.getWaypoints();
        assertThat(waypoints).isNotNull();
        assertThat(waypoints).hasSize(expectedWaypoints);
        final Waypoint waypoint = waypoints.get(0);
        assertThat(waypoint.getCoords()).isEqualTo(new Geopoint("N51 13.888 E007 03.444"));
        //            assertThat(waypoint.getNote()).isEqualTo("Test");
        assertThat(waypoint.getName())
            .isEqualTo(
                CgeoApplication.getInstance().getString(R.string.cache_personal_note) + " 1");
        cache.store(StoredList.TEMPORARY_LIST.id, null);
      }
      removeCacheCompletely(geocode);
    } finally {
      restoreMapStoreFlags();
    }
  }