Search in sources :

Example 26 with GpxDataItem

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

the class TrackAppearanceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = requireMyApplication();
    settings = app.getSettings();
    gpxDbHelper = app.getGpxDbHelper();
    if (savedInstanceState != null) {
        trackDrawInfo = new TrackDrawInfo(savedInstanceState);
        if (selectedGpxFile == null) {
            restoreSelectedGpxFile(trackDrawInfo.getFilePath(), trackDrawInfo.isCurrentRecording());
        }
        if (!trackDrawInfo.isCurrentRecording()) {
            gpxDataItem = gpxDbHelper.getItem(new File(trackDrawInfo.getFilePath()));
        }
        showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, settings.SHOW_START_FINISH_ICONS.get());
    } else {
        showStartFinishIconsInitialValue = settings.SHOW_START_FINISH_ICONS.get();
        if (selectedGpxFile.isShowCurrentTrack()) {
            trackDrawInfo = new TrackDrawInfo(app, true);
        } else {
            GpxDataItemCallback callback = new GpxDataItemCallback() {

                @Override
                public boolean isCancelled() {
                    return false;
                }

                @Override
                public void onGpxDataItemReady(GpxDataItem item) {
                    if (item != null) {
                        gpxDataItem = item;
                        trackDrawInfo.updateParams(item);
                    }
                    if (view != null) {
                        initContent();
                    }
                }
            };
            String filePath = selectedGpxFile.getGpxFile().path;
            gpxDataItem = gpxDbHelper.getItem(new File(filePath), callback);
            trackDrawInfo = new TrackDrawInfo(filePath, gpxDataItem, false);
        }
    }
    requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {

        public void handleOnBackPressed() {
            dismiss();
        }
    });
}
Also used : TrackDrawInfo(net.osmand.plus.track.TrackDrawInfo) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) 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 27 with GpxDataItem

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

the class GpxUiHelper method getDataItem.

private static GpxDataItem getDataItem(@NonNull final OsmandApplication app, @NonNull final GPXFile gpxFile) {
    GpxDataItemCallback itemCallback = new GpxDataItemCallback() {

        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public void onGpxDataItemReady(GpxDataItem item) {
            addAppearanceToGpx(gpxFile, item);
            saveAndShareGpx(app, gpxFile);
        }
    };
    return app.getGpxDbHelper().getItem(new File(gpxFile.path), itemCallback);
}
Also used : GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) 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 28 with GpxDataItem

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

the class SavingTrackHelper method saveDataToGpx.

/**
 * @return warnings, gpxFilesByName
 */
public synchronized SaveGpxResult saveDataToGpx(@NonNull File dir) {
    List<String> warnings = new ArrayList<>();
    Map<String, GPXFile> gpxFilesByName = new LinkedHashMap<>();
    dir.mkdirs();
    if (dir.getParentFile().canWrite() && dir.exists()) {
        Map<String, GPXFile> data = collectRecordedData();
        for (Map.Entry<String, GPXFile> entry : data.entrySet()) {
            String f = entry.getKey();
            GPXFile gpx = entry.getValue();
            log.debug("Filename: " + f);
            File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
            if (!gpx.isEmpty()) {
                WptPt pt = gpx.findPointToShow();
                // $NON-NLS-1$
                String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
                Integer trackStorageDirectory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get();
                if (!OsmandSettings.REC_DIRECTORY.equals(trackStorageDirectory)) {
                    SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM", Locale.US);
                    // if (trackStorageDirectory == OsmandSettings.DAILY_DIRECTORY) {
                    // dateDirFormat = new SimpleDateFormat("yyyy-MM-dd");
                    // }
                    String dateDirName = dateDirFormat.format(new Date(pt.time));
                    File dateDir = new File(dir, dateDirName);
                    dateDir.mkdirs();
                    if (dateDir.exists()) {
                        fileName = dateDirName + File.separator + fileName;
                    }
                }
                gpxFilesByName.put(fileName, gpx);
                fout = new File(dir, fileName + IndexConstants.GPX_FILE_EXT);
                int ind = 1;
                while (fout.exists()) {
                    // $NON-NLS-1$
                    fout = new File(dir, fileName + "_" + (++ind) + IndexConstants.GPX_FILE_EXT);
                }
            }
            Exception warn = GPXUtilities.writeGpxFile(fout, gpx);
            if (warn != null) {
                warnings.add(warn.getMessage());
                return new SaveGpxResult(warnings, new HashMap<String, GPXFile>());
            }
            GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
            GpxDataItem item = new GpxDataItem(fout, analysis);
            ctx.getGpxDbHelper().add(item);
            lastTimeFileSaved = fout.lastModified();
        }
        clearRecordedData(warnings.isEmpty());
    }
    return new SaveGpxResult(warnings, gpxFilesByName);
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) ArrayList(java.util.ArrayList) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXFile(net.osmand.GPXUtilities.GPXFile) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

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