Search in sources :

Example 6 with GPXFile

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

the class MapActivityActions method enterRoutePlanningMode.

public void enterRoutePlanningMode(final LatLon from, final PointDescription fromName) {
    final boolean useIntermediatePointsByDefault = true;
    List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
    final List<GPXFile> gpxFiles = new ArrayList<>();
    for (SelectedGpxFile gs : selectedGPXFiles) {
        if (!gs.isShowCurrentTrack() && !gs.notShowNavigationDialog) {
            if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkPt()) {
                gpxFiles.add(gs.getGpxFile());
            }
        }
    }
    if (gpxFiles.size() > 0) {
        AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
        if (gpxFiles.size() == 1) {
            bld.setMessage(R.string.use_displayed_track_for_navigation);
            bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    enterRoutePlanningModeGivenGpx(gpxFiles.get(0), from, fromName, useIntermediatePointsByDefault, true);
                }
            });
        } else {
            bld.setTitle(R.string.navigation_over_track);
            ArrayAdapter<GPXFile> adapter = new ArrayAdapter<GPXFile>(mapActivity, R.layout.drawer_list_item, gpxFiles) {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    if (convertView == null) {
                        convertView = mapActivity.getLayoutInflater().inflate(R.layout.drawer_list_item, null);
                    }
                    String path = getItem(position).path;
                    String name = path.substring(path.lastIndexOf("/") + 1, path.length());
                    ((TextView) convertView.findViewById(R.id.title)).setText(name);
                    convertView.findViewById(R.id.icon).setVisibility(View.GONE);
                    convertView.findViewById(R.id.toggle_item).setVisibility(View.GONE);
                    return convertView;
                }
            };
            bld.setAdapter(adapter, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    enterRoutePlanningModeGivenGpx(gpxFiles.get(i), from, fromName, useIntermediatePointsByDefault, true);
                }
            });
        }
        bld.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                enterRoutePlanningModeGivenGpx(null, from, fromName, useIntermediatePointsByDefault, true);
            }
        });
        bld.show();
    } else {
        enterRoutePlanningModeGivenGpx(null, from, fromName, useIntermediatePointsByDefault, true);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with GPXFile

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

the class TrackActivity method addPoint.

public void addPoint(PointDescription pointDescription) {
    Intent currentIntent = getIntent();
    if (currentIntent != null) {
        currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
    }
    final OsmandSettings settings = app.getSettings();
    GPXFile gpx = getGpx();
    LatLon location = settings.getLastKnownMapLocation();
    QuadRect rect = getRect();
    NewGpxPoint newGpxPoint = new NewGpxPoint(gpx, pointDescription, rect);
    if (gpx != null && location != null) {
        settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), pointDescription, false, newGpxPoint);
        MapActivity.launchMapActivityMoveToTop(this);
    }
}
Also used : LatLon(net.osmand.data.LatLon) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Intent(android.content.Intent) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 8 with GPXFile

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

the class SavingTrackHelper method collectRecordedData.

public Map<String, GPXFile> collectRecordedData() {
    Map<String, GPXFile> data = new LinkedHashMap<String, GPXFile>();
    SQLiteDatabase db = getReadableDatabase();
    if (db != null && db.isOpen()) {
        try {
            collectDBPoints(db, data);
            collectDBTracks(db, data);
        } finally {
            db.close();
        }
    }
    return data;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with GPXFile

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

the class SavingTrackHelper method loadGpxFromDatabase.

public void loadGpxFromDatabase() {
    Map<String, GPXFile> files = collectRecordedData();
    currentTrack.getModifiableGpxFile().tracks.clear();
    for (Map.Entry<String, GPXFile> entry : files.entrySet()) {
        ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile());
        currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
    }
    currentTrack.processPoints();
    prepareCurrentTrackForRecording();
    GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
    distance = analysis.totalDistance;
    points = analysis.wptPoints;
    duration = analysis.timeSpan;
}
Also used : GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with GPXFile

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

the class SavingTrackHelper method collectDBTracks.

private void collectDBTracks(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
    Cursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " ASC", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    null);
    long previousTime = 0;
    long previousInterval = 0;
    TrkSegment segment = null;
    Track track = null;
    if (query.moveToFirst()) {
        do {
            WptPt pt = new WptPt();
            pt.lat = query.getDouble(0);
            pt.lon = query.getDouble(1);
            pt.ele = query.getDouble(2);
            pt.speed = query.getDouble(3);
            pt.hdop = query.getDouble(4);
            long time = query.getLong(5);
            pt.time = time;
            long currentInterval = Math.abs(time - previousTime);
            boolean newInterval = pt.lat == 0 && pt.lon == 0;
            if (track != null && !newInterval && (!ctx.getSettings().AUTO_SPLIT_RECORDING.get() || currentInterval < 6 * 60 * 1000 || currentInterval < 10 * previousInterval)) {
                // 6 minute - same segment
                segment.points.add(pt);
            } else if (track != null && (ctx.getSettings().AUTO_SPLIT_RECORDING.get() && currentInterval < 2 * 60 * 60 * 1000)) {
                // 2 hour - same track
                segment = new TrkSegment();
                if (!newInterval) {
                    segment.points.add(pt);
                }
                track.segments.add(segment);
            } else {
                // check if date the same - new track otherwise new file
                track = new Track();
                segment = new TrkSegment();
                track.segments.add(segment);
                if (!newInterval) {
                    segment.points.add(pt);
                }
                // $NON-NLS-1$
                String date = DateFormat.format("yyyy-MM-dd", time).toString();
                if (dataTracks.containsKey(date)) {
                    GPXFile gpx = dataTracks.get(date);
                    gpx.tracks.add(track);
                } else {
                    GPXFile file = new GPXFile();
                    file.tracks.add(track);
                    dataTracks.put(date, file);
                }
            }
            previousInterval = currentInterval;
            previousTime = time;
        } while (query.moveToNext());
    }
    query.close();
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Cursor(android.database.Cursor) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) Track(net.osmand.plus.GPXUtilities.Track)

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