Search in sources :

Example 1 with GpxDataItemCallback

use of net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback in project Osmand by osmandapp.

the class GpxUiHelper method updateSelectedTracksAppearance.

private static void updateSelectedTracksAppearance(final OsmandApplication app, List<String> fileNames, final Map<String, String> params) {
    GpxDataItemCallback callback = new GpxDataItemCallback() {

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

        @Override
        public void onGpxDataItemReady(GpxDataItem item) {
            updateTrackAppearance(app, item, params);
        }
    };
    GpxDbHelper gpxDbHelper = app.getGpxDbHelper();
    for (String name : fileNames) {
        GpxDataItem item = gpxDbHelper.getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), name), callback);
        if (item != null) {
            updateTrackAppearance(app, item, params);
        }
    }
}
Also used : GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) SpannableString(android.text.SpannableString) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GpxDbHelper(net.osmand.plus.track.helpers.GpxDbHelper)

Example 2 with GpxDataItemCallback

use of net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback in project Osmand by osmandapp.

the class AvailableGPXFragment method getGpxTrackAnalysis.

@Nullable
public static GPXTrackAnalysis getGpxTrackAnalysis(@NonNull GpxInfo gpxInfo, @NonNull OsmandApplication app, @Nullable final GpxInfoViewCallback callback) {
    SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app);
    GPXTrackAnalysis analysis = null;
    if (sgpx != null && sgpx.isLoaded()) {
        analysis = sgpx.getTrackAnalysis(app);
    } else if (gpxInfo.currentlyRecordingTrack) {
        analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis(app);
    } else if (gpxInfo.file != null) {
        GpxDataItemCallback analyserCallback = null;
        if (callback != null) {
            analyserCallback = new GpxDataItemCallback() {

                @Override
                public boolean isCancelled() {
                    return callback.isCancelled();
                }

                @Override
                public void onGpxDataItemReady(GpxDataItem item) {
                    callback.onGpxDataItemChanged(item);
                }
            };
        }
        GpxDataItem dataItem = app.getGpxDbHelper().getItem(gpxInfo.file, analyserCallback);
        if (dataItem != null) {
            analysis = dataItem.getAnalysis();
        }
    }
    return analysis;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) Nullable(androidx.annotation.Nullable)

Example 3 with GpxDataItemCallback

use of net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback in project Osmand by osmandapp.

the class GPXAction method setupGpxTrackInfo.

private void setupGpxTrackInfo(@NonNull final View container, @NonNull final OsmandApplication app) {
    String gpxFilePath = getSelectedGpxFilePath(false);
    if (gpxFilePath == null) {
        return;
    }
    View trackInfoContainer = container.findViewById(R.id.selected_track_file_container);
    boolean currentTrack = gpxFilePath.isEmpty();
    File file = new File(gpxFilePath);
    String gpxName = currentTrack ? app.getString(R.string.current_track) : GpxUiHelper.getGpxTitle(file.getName());
    SelectedGpxFile selectedGpxFile = currentTrack ? app.getSavingTrackHelper().getCurrentTrack() : app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
    if (selectedGpxFile != null) {
        setupGpxTrackInfo(trackInfoContainer, gpxName, selectedGpxFile.getTrackAnalysis(app), app);
    } else {
        GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(file, new GpxDataItemCallback() {

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

            @Override
            public void onGpxDataItemReady(GpxDataItem item) {
                if (item != null && item.getAnalysis() != null) {
                    setupGpxTrackInfo(trackInfoContainer, gpxName, item.getAnalysis(), app);
                }
            }
        });
        if (gpxDataItem != null && gpxDataItem.getAnalysis() != null) {
            setupGpxTrackInfo(trackInfoContainer, gpxName, gpxDataItem.getAnalysis(), app);
        }
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 4 with GpxDataItemCallback

use of net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback in project Osmand by osmandapp.

the class GpsFiltersCard method fetchGpxDataItem.

@Nullable
private GpxDataItem fetchGpxDataItem() {
    File file = new File(filteredSelectedGpxFile.getGpxFile().path);
    GpxDataItemCallback callback = new GpxDataItemCallback() {

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

        @Override
        public void onGpxDataItemReady(GpxDataItem item) {
            if (item != null) {
                gpxDataItem = item;
            }
        }
    };
    return gpxDbHelper.getItem(file, callback);
}
Also used : GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) FilteredSelectedGpxFile(net.osmand.plus.track.helpers.FilteredSelectedGpxFile) File(java.io.File) Nullable(androidx.annotation.Nullable)

Example 5 with GpxDataItemCallback

use of net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback 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)

Aggregations

GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)6 GpxDataItemCallback (net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback)6 File (java.io.File)5 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)5 GPXFile (net.osmand.GPXUtilities.GPXFile)4 Nullable (androidx.annotation.Nullable)2 SpannableString (android.text.SpannableString)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 OnBackPressedCallback (androidx.activity.OnBackPressedCallback)1 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)1 TrackDrawInfo (net.osmand.plus.track.TrackDrawInfo)1 FilteredSelectedGpxFile (net.osmand.plus.track.helpers.FilteredSelectedGpxFile)1 GpxDbHelper (net.osmand.plus.track.helpers.GpxDbHelper)1