Search in sources :

Example 46 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class TrackActivity method addNewGpxData.

public void addNewGpxData(NewGpxData.ActionType actionType, TrkSegment segment) {
    GPXFile gpxFile = getGpx();
    QuadRect rect = getRect();
    NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
    WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null;
    if (pointToShow != null) {
        LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
        final OsmandSettings settings = app.getSettings();
        settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_line)), false, newGpxData);
        MapActivity.launchMapActivityMoveToTop(this);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) NewGpxData(net.osmand.plus.measurementtool.NewGpxData) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 47 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class MapActivityLayers method showGPXFileLayer.

public AlertDialog showGPXFileLayer(List<String> files, final OsmandMapTileView mapView) {
    final OsmandSettings settings = getApplication().getSettings();
    CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            WptPt locToShow = null;
            for (GPXFile g : result) {
                if (g.showCurrentTrack) {
                    if (!settings.SAVE_TRACK_TO_GPX.get() && !settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
                        Toast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_LONG).show();
                    }
                    break;
                } else {
                    locToShow = g.findPointToShow();
                }
            }
            getApplication().getSelectedGpxHelper().setGpxFileToDisplay(result);
            if (locToShow != null) {
                mapView.getAnimatedDraggingThread().startMoving(locToShow.lat, locToShow.lon, mapView.getZoom(), true);
            }
            mapView.refreshMap();
            activity.getDashboard().refreshContent(true);
            return true;
        }
    };
    return GpxUiHelper.selectGPXFiles(files, activity, callbackWithObject);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) CallbackWithObject(net.osmand.CallbackWithObject) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 48 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class SavingTrackHelper method saveDataToGpx.

/**
 * @return warnings
 */
public synchronized List<String> saveDataToGpx(File dir) {
    List<String> warnings = new ArrayList<String>();
    dir.mkdirs();
    if (dir.getParentFile().canWrite()) {
        if (dir.exists()) {
            Map<String, GPXFile> data = collectRecordedData();
            // save file
            for (final String f : data.keySet()) {
                // $NON-NLS-1$
                File fout = new File(dir, f + ".gpx");
                if (!data.get(f).isEmpty()) {
                    WptPt pt = data.get(f).findPointToShow();
                    File targetDir = dir;
                    if (ctx.getSettings().STORE_TRACKS_IN_MONTHLY_DIRECTORIES.get()) {
                        SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM");
                        String dateDirName = dateDirFormat.format(new Date(pt.time));
                        File dateDir = new File(dir, dateDirName);
                        dateDir.mkdirs();
                        if (dateDir.exists()) {
                            targetDir = dateDir;
                        }
                    }
                    // $NON-NLS-1$
                    String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
                    // $NON-NLS-1$
                    fout = new File(targetDir, fileName + ".gpx");
                    int ind = 1;
                    while (fout.exists()) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        fout = new File(targetDir, fileName + "_" + (++ind) + ".gpx");
                    }
                }
                String warn = GPXUtilities.writeGpxFile(fout, data.get(f), ctx);
                if (warn != null) {
                    warnings.add(warn);
                    return warnings;
                }
                GPXFile gpx = data.get(f);
                GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
                GpxDataItem item = new GpxDataItem(fout, analysis);
                ctx.getGpxDatabase().add(item);
            }
        }
    }
    SQLiteDatabase db = getWritableDatabase();
    if (db != null && warnings.isEmpty() && db.isOpen()) {
        try {
            // remove all from db
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
        // delete all
        // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
        // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
        } finally {
            db.close();
        }
    }
    distance = 0;
    points = 0;
    duration = 0;
    ctx.getSelectedGpxHelper().clearPoints(currentTrack.getModifiableGpxFile());
    currentTrack.getModifiableGpxFile().tracks.clear();
    currentTrack.getModifiablePointsToDisplay().clear();
    currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
    prepareCurrentTrackForRecording();
    return warnings;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) ArrayList(java.util.ArrayList) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) Date(java.util.Date) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 49 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class GpxSelectionHelper method processSplit.

public void processSplit() {
    List<GpxDataItem> items = app.getGpxDatabase().getItems();
    for (GpxDataItem dataItem : items) {
        if (dataItem.getSplitType() != 0) {
            SelectedGpxFile selectedGpxFile = getSelectedFileByPath(dataItem.getFile().getAbsolutePath());
            if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
                GPXFile gpxFile = selectedGpxFile.getGpxFile();
                List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
                if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) {
                    for (GpxDisplayGroup model : groups) {
                        model.noSplit(app);
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
                    for (GpxDisplayGroup model : groups) {
                        model.splitByDistance(app, dataItem.getSplitInterval());
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
                    for (GpxDisplayGroup model : groups) {
                        model.splitByTime(app, (int) dataItem.getSplitInterval());
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                }
            }
        }
    }
}
Also used : GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 50 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class GpxSelectionHelper method syncGpx.

private void syncGpx(GPXFile gpxFile) {
    File gpx = new File(gpxFile.path);
    if (gpx.exists()) {
        MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
        mapMarkersHelper.runSynchronization(mapMarkersHelper.getOrCreateGroup(gpx));
    }
}
Also used : GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

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