use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class TrackSegmentFragment method drawTrack.
private void drawTrack(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile g) {
GpxDataItem gpxDataItem = null;
if (!g.isShowCurrentTrack()) {
gpxDataItem = getGpxDataItem();
}
List<TrkSegment> segments = g.getPointsToDisplay();
for (TrkSegment ts : segments) {
int color = gpxDataItem != null ? gpxDataItem.getColor() : 0;
if (g.isShowCurrentTrack()) {
color = currentTrackColor;
}
if (color == 0) {
color = ts.getColor(trackColor);
}
if (// only do once (CODE HERE NEEDS TO BE UI INSTEAD)
ts.renders.isEmpty() && !ts.points.isEmpty()) {
// hmmm. 0-point tracks happen, but.... how?
if (g.isShowCurrentTrack()) {
ts.renders.add(new Renderable.CurrentTrack(ts.points));
} else {
ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2));
}
}
paint.setColor(color == 0 ? trackColor : color);
ts.drawRenderers(tileBox.getZoom(), paint, canvas, tileBox);
}
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class MeasurementToolFragment method displaySegmentPoints.
private void displaySegmentPoints() {
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
TrkSegment segment = editingCtx.getNewGpxData().getTrkSegment();
List<WptPt> points = segment.points;
if (measurementLayer != null) {
editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
}
use of net.osmand.plus.GPXUtilities.TrkSegment 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.TrkSegment in project Osmand by osmandapp.
the class PlanRouteFragment method updateText.
private void updateText() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TextView distanceTv = (TextView) mainView.findViewById(R.id.markers_distance_text_view);
TextView timeTv = (TextView) mainView.findViewById(R.id.markers_time_text_view);
TextView countTv = (TextView) mainView.findViewById(R.id.markers_count_text_view);
ApplicationMode appMode = planRouteContext.getSnappedMode();
TrkSegment snapTrkSegment = planRouteContext.getSnapTrkSegment();
boolean defaultMode = appMode == ApplicationMode.DEFAULT;
float dist = 0;
for (int i = 1; i < snapTrkSegment.points.size(); i++) {
WptPt pt1 = snapTrkSegment.points.get(i - 1);
WptPt pt2 = snapTrkSegment.points.get(i);
dist += MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
}
distanceTv.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()) + (defaultMode ? "" : ","));
if (defaultMode) {
timeTv.setText("");
} else {
int seconds = (int) (dist / appMode.getDefaultSpeed());
timeTv.setText("~ " + OsmAndFormatter.getFormattedDuration(seconds, mapActivity.getMyApplication()));
}
countTv.setText(mapActivity.getString(R.string.shared_string_markers) + ": " + selectedCount);
}
}
use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.
the class MeasurementToolLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (inMeasurementMode) {
lineAttrs.updatePaints(view, settings, tb);
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
before.renders.clear();
before.renders.add(new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2));
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
after.renders.clear();
after.renders.add(new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2));
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
}
}
Aggregations