Search in sources :

Example 26 with GPXFile

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();
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 27 with GPXFile

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);
}
Also used : CallbackWithObject(net.osmand.CallbackWithObject) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 28 with GPXFile

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
    }
}
Also used : Intent(android.content.Intent) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 29 with GPXFile

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);
}
Also used : TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) ProgressDialog(android.app.ProgressDialog) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) List(java.util.List) ArrayList(java.util.ArrayList) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) Track(net.osmand.plus.GPXUtilities.Track) Route(net.osmand.plus.GPXUtilities.Route) MapActivity(net.osmand.plus.activities.MapActivity)

Example 30 with GPXFile

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);
}
Also used : ActionType(net.osmand.plus.measurementtool.NewGpxData.ActionType) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Aggregations

GPXFile (net.osmand.plus.GPXUtilities.GPXFile)56 File (java.io.File)26 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)21 WptPt (net.osmand.plus.GPXUtilities.WptPt)16 OsmandApplication (net.osmand.plus.OsmandApplication)11 View (android.view.View)8 TextView (android.widget.TextView)8 Intent (android.content.Intent)7 ImageView (android.widget.ImageView)7 FavouritePoint (net.osmand.data.FavouritePoint)7 LatLon (net.osmand.data.LatLon)7 DialogInterface (android.content.DialogInterface)6 AlertDialog (android.support.v7.app.AlertDialog)6 ArrayList (java.util.ArrayList)6 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)5 Track (net.osmand.plus.GPXUtilities.Track)5 TrkSegment (net.osmand.plus.GPXUtilities.TrkSegment)5 AdapterView (android.widget.AdapterView)4