Search in sources :

Example 11 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class OsmandAidlApi method finishGpxImport.

@SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
    final int col = GpxAppearanceAdapter.parseTrackColor(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
    if (!destinationExists) {
        GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
        gpxDataItem.setApiImported(true);
        app.getGpxDbHelper().add(gpxDataItem);
    } else {
        GpxDataItem item = app.getGpxDbHelper().getItem(destination);
        if (item != null) {
            app.getGpxDbHelper().updateColor(item, col);
        }
    }
    final GpxSelectionHelper helper = app.getSelectedGpxHelper();
    final SelectedGpxFile selectedGpx = helper.getSelectedFileByName(destination.getName());
    if (selectedGpx != null) {
        if (show) {
            new AsyncTask<File, Void, GPXFile>() {

                @Override
                protected GPXFile doInBackground(File... files) {
                    return GPXUtilities.loadGPXFile(files[0]);
                }

                @Override
                protected void onPostExecute(GPXFile gpx) {
                    if (gpx.error == null) {
                        if (col != -1) {
                            gpx.setColor(col);
                        }
                        selectedGpx.setGpxFile(gpx, app);
                        refreshMap();
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
        } else {
            helper.selectGpxFile(selectedGpx.getGpxFile(), false, false);
            refreshMap();
        }
    } else if (show) {
        new AsyncTask<File, Void, GPXFile>() {

            @Override
            protected GPXFile doInBackground(File... files) {
                return GPXUtilities.loadGPXFile(files[0]);
            }

            @Override
            protected void onPostExecute(GPXFile gpx) {
                if (gpx.error == null) {
                    helper.selectGpxFile(gpx, true, false);
                    refreshMap();
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) AsyncTask(android.os.AsyncTask) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASqliteDbFile(net.osmand.aidl.tiles.ASqliteDbFile) File(java.io.File) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) AGpxFile(net.osmand.aidl.gpx.AGpxFile) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 12 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class OsmandAidlApi method getImportedGpx.

boolean getImportedGpx(List<AGpxFile> files) {
    List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
    for (GpxDataItem dataItem : gpxDataItems) {
        File file = dataItem.getFile();
        if (file.exists()) {
            String fileName = file.getName();
            boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
            long modifiedTime = dataItem.getFileLastModifiedTime();
            long fileSize = file.length();
            AGpxFileDetails details = null;
            GPXTrackAnalysis analysis = dataItem.getAnalysis();
            if (analysis != null) {
                details = createGpxFileDetails(analysis);
            }
            files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
        }
    }
    return true;
}
Also used : GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) AGpxFileDetails(net.osmand.aidl.gpx.AGpxFileDetails) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) AGpxFile(net.osmand.aidl.gpx.AGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASqliteDbFile(net.osmand.aidl.tiles.ASqliteDbFile) File(java.io.File) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) AGpxFile(net.osmand.aidl.gpx.AGpxFile)

Example 13 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class OsmandAidlApi method getImportedGpxV2.

boolean getImportedGpxV2(List<net.osmand.aidlapi.gpx.AGpxFile> files) {
    List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
    for (GpxDataItem dataItem : gpxDataItems) {
        File file = dataItem.getFile();
        if (file.exists()) {
            String fileName = file.getName();
            boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
            long modifiedTime = dataItem.getFileLastModifiedTime();
            long fileSize = file.length();
            int color = dataItem.getColor();
            String colorName = "";
            if (color != 0) {
                colorName = GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
            }
            net.osmand.aidlapi.gpx.AGpxFileDetails details = null;
            GPXTrackAnalysis analysis = dataItem.getAnalysis();
            if (analysis != null) {
                details = createGpxFileDetailsV2(analysis);
            }
            files.add(new net.osmand.aidlapi.gpx.AGpxFile(fileName, modifiedTime, fileSize, active, colorName, details));
        }
    }
    return true;
}
Also used : GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASqliteDbFile(net.osmand.aidl.tiles.ASqliteDbFile) File(java.io.File) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) AGpxFile(net.osmand.aidl.gpx.AGpxFile) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint)

Example 14 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class SaveGpxAsyncTask method saveImport.

private String saveImport(GPXFile gpxFile, String fileName, boolean useImportDir) {
    final String warning;
    if (gpxFile.isEmpty() || fileName == null) {
        warning = app.getString(R.string.error_reading_gpx);
    } else {
        final File importDir;
        if (useImportDir) {
            importDir = app.getAppPath(GPX_IMPORT_DIR);
        } else {
            importDir = app.getAppPath(GPX_INDEX_DIR);
        }
        // noinspection ResultOfMethodCallIgnored
        importDir.mkdirs();
        if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) {
            final WptPt pt = gpxFile.findPointToShow();
            final File toWrite = getFileToSave(fileName, importDir, pt);
            boolean destinationExists = toWrite.exists();
            Exception e = GPXUtilities.writeGpxFile(toWrite, gpxFile);
            if (e == null) {
                gpxFile.path = toWrite.getAbsolutePath();
                File file = new File(gpxFile.path);
                if (!destinationExists) {
                    GpxDataItem item = new GpxDataItem(file, gpxFile);
                    app.getGpxDbHelper().add(item);
                } else {
                    GpxDataItem item = app.getGpxDbHelper().getItem(file);
                    if (item != null) {
                        app.getGpxDbHelper().clearAnalysis(item);
                    }
                }
                warning = null;
            } else {
                warning = app.getString(R.string.error_reading_gpx);
            }
        } else {
            warning = app.getString(R.string.sd_dir_not_accessible);
        }
    }
    return warning;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 15 with GpxDataItem

use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TrackBitmapDrawer method drawTrack.

private void drawTrack(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile selectedGpxFile) {
    GpxDataItem gpxDataItem = null;
    if (!selectedGpxFile.isShowCurrentTrack()) {
        gpxDataItem = getGpxDataItem();
    }
    List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
    for (TrkSegment segment : segments) {
        int color = getTrackColor(selectedGpxFile, segment, gpxDataItem);
        if (segment.renderer == null && !segment.points.isEmpty()) {
            if (selectedGpxFile.isShowCurrentTrack()) {
                segment.renderer = new CurrentTrack(segment.points);
            } else {
                segment.renderer = new StandardTrack(segment.points, 17.2);
            }
        }
        paint.setColor(color);
        if (segment.renderer instanceof RenderableSegment) {
            ((RenderableSegment) segment.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox);
        }
    }
}
Also used : StandardTrack(net.osmand.plus.views.Renderable.StandardTrack) RenderableSegment(net.osmand.plus.views.Renderable.RenderableSegment) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) TrkSegment(net.osmand.GPXUtilities.TrkSegment) Paint(android.graphics.Paint) CurrentTrack(net.osmand.plus.views.Renderable.CurrentTrack)

Aggregations

GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)28 File (java.io.File)18 GPXFile (net.osmand.GPXUtilities.GPXFile)18 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)16 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)8 GpxDataItemCallback (net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback)6 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 View (android.view.View)4 AGpxFile (net.osmand.aidl.gpx.AGpxFile)4 ASelectedGpxFile (net.osmand.aidl.gpx.ASelectedGpxFile)4 ASqliteDbFile (net.osmand.aidl.tiles.ASqliteDbFile)4 SuppressLint (android.annotation.SuppressLint)3 ArrayList (java.util.ArrayList)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 LinearLayout (android.widget.LinearLayout)2 Nullable (androidx.annotation.Nullable)2 List (java.util.List)2