use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MeasurementToolFragment method displayRoutePoints.
private void displayRoutePoints() {
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
List<WptPt> points = gpx.getRoutePoints();
if (measurementLayer != null) {
editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MeasurementToolFragment method showAddToTrackDialog.
private AlertDialog showAddToTrackDialog(final MapActivity mapActivity) {
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
GPXFile gpxFile;
if (result != null && result.length > 0) {
gpxFile = result[0];
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
boolean showOnMap = selectedGpxFile != null;
saveExistingGpx(gpxFile, showOnMap, ActionType.ADD_SEGMENT, false);
}
return true;
}
};
return GpxUiHelper.selectGPXFile(mapActivity, false, false, callbackWithObject);
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MeasurementToolFragment method dismiss.
private void dismiss(MapActivity mapActivity) {
try {
editingCtx.clearSegments();
if (pointsListOpened) {
hidePointsList();
}
if (editingCtx.isInSnapToRoadMode()) {
disableSnapToRoadMode();
}
if (editingCtx.getNewGpxData() != null) {
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
newIntent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newIntent);
}
mapActivity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
} catch (Exception e) {
// ignore
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MeasurementToolFragment method saveGpx.
private void saveGpx(final File dir, final String fileName, final boolean showOnMap, final GPXFile gpx, final boolean openTrackActivity, final NewGpxData.ActionType actionType, final SaveType saveType, final boolean close) {
new AsyncTask<Void, Void, String>() {
private ProgressDialog progressDialog;
private File toSave;
@Override
protected void onPreExecute() {
cancelModes();
MapActivity activity = getMapActivity();
if (activity != null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setMessage(getString(R.string.saving_gpx_tracks));
progressDialog.show();
}
}
@Override
protected String doInBackground(Void... voids) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
MapActivity activity = getMapActivity();
List<WptPt> points = editingCtx.getPoints();
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
if (gpx == null) {
toSave = new File(dir, fileName);
GPXFile gpx = new GPXFile();
if (measurementLayer != null) {
if (saveType == SaveType.LINE) {
TrkSegment segment = new TrkSegment();
if (editingCtx.isInSnapToRoadMode()) {
segment.points.addAll(before.points);
segment.points.addAll(after.points);
} else {
segment.points.addAll(points);
}
Track track = new Track();
track.segments.add(segment);
gpx.tracks.add(track);
} else if (saveType == SaveType.ROUTE_POINT) {
if (editingCtx.isInSnapToRoadMode()) {
TrkSegment segment = new TrkSegment();
segment.points.addAll(before.points);
segment.points.addAll(after.points);
Track track = new Track();
track.segments.add(segment);
gpx.tracks.add(track);
}
Route rt = new Route();
gpx.routes.add(rt);
rt.points.addAll(points);
}
}
if (activity != null) {
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
gpx.path = toSave.getAbsolutePath();
if (showOnMap) {
activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
}
return res;
}
} else {
toSave = new File(gpx.path);
if (measurementLayer != null) {
if (actionType != null) {
switch(actionType) {
case ADD_SEGMENT:
if (editingCtx.isInSnapToRoadMode()) {
List<WptPt> snappedPoints = new ArrayList<>();
snappedPoints.addAll(before.points);
snappedPoints.addAll(after.points);
gpx.addTrkSegment(snappedPoints);
} else {
gpx.addTrkSegment(points);
}
break;
case ADD_ROUTE_POINTS:
gpx.replaceRoutePoints(points);
break;
case EDIT_SEGMENT:
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
break;
}
} else {
gpx.addRoutePoints(points);
}
}
if (activity != null) {
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
if (showOnMap) {
SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
if (sf != null) {
if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
sf.processPoints();
}
}
}
return res;
}
}
return null;
}
@Override
protected void onPostExecute(String warning) {
MapActivity activity = getMapActivity();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (activity != null) {
activity.refreshMap();
if (warning == null) {
saved = true;
if (openTrackActivity) {
dismiss(activity);
} else {
Toast.makeText(activity, MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), Toast.LENGTH_LONG).show();
if (close) {
dismiss(activity);
}
}
} else {
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MeasurementToolFragment method addToGpx.
private void addToGpx(MapActivity mapActivity) {
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
boolean showOnMap = selectedGpxFile != null;
ActionType actionType = editingCtx.getNewGpxData().getActionType();
saveExistingGpx(gpx, showOnMap, actionType, true);
}
Aggregations