Search in sources :

Example 11 with SelectedGpxFile

use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.

the class MapLayerMenuListener method getAlreadySelectedGpx.

@NonNull
private List<String> getAlreadySelectedGpx() {
    GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
    List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
    List<String> files = GpxUiHelper.getSelectedTrackPaths(mapActivity.getMyApplication());
    if (selectedGpxFiles.isEmpty()) {
        Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
        for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {
            if (!Algorithms.isEmpty(f.getKey().path)) {
                File file = new File(f.getKey().path);
                if (file.exists() && !file.isDirectory()) {
                    files.add(f.getKey().path);
                }
            }
        }
    }
    return files;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) Map(java.util.Map) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) NonNull(androidx.annotation.NonNull)

Example 12 with SelectedGpxFile

use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.

the class WptPtMenuController method getTypeStr.

@NonNull
@Override
public String getTypeStr() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        GpxSelectionHelper helper = mapActivity.getMyApplication().getSelectedGpxHelper();
        SelectedGpxFile selectedGpxFile = helper.getSelectedGPXFile(wpt);
        StringBuilder sb = new StringBuilder();
        sb.append(mapActivity.getString(R.string.shared_string_waypoint));
        sb.append(", ");
        if (selectedGpxFile != null) {
            File file = new File(selectedGpxFile.getGpxFile().path);
            String gpxName = file.getName().replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
            sb.append(gpxName);
        }
        return sb.toString();
    } else {
        return "";
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(androidx.annotation.NonNull)

Example 13 with SelectedGpxFile

use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile 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 14 with SelectedGpxFile

use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.

the class SplitSegmentDialogFragment method updateHeader.

private void updateHeader() {
    final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
    if (getGpx() != null && !getGpx().showCurrentTrack && adapter.getCount() > 0) {
        setupSplitIntervalView(splitIntervalView);
        if (options.size() == 0) {
            prepareSplitIntervalAdapterData();
        }
        updateSplitIntervalView(splitIntervalView);
        splitIntervalView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final ListPopupWindow popup = new ListPopupWindow(v.getContext());
                popup.setAnchorView(splitIntervalView);
                popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
                popup.setModal(true);
                popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
                popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
                popup.setAdapter(new ArrayAdapter<>(v.getContext(), R.layout.popup_list_text_item, options));
                popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        selectedSplitInterval = position;
                        SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), true, false);
                        final List<GpxDisplayGroup> groups = getDisplayGroups();
                        if (groups.size() > 0) {
                            updateSplit(groups, sf);
                        }
                        popup.dismiss();
                        updateSplitIntervalView(splitIntervalView);
                    }
                });
                popup.show();
            }
        });
        splitIntervalView.setVisibility(View.VISIBLE);
    } else {
        splitIntervalView.setVisibility(View.GONE);
    }
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ArrayAdapter(android.widget.ArrayAdapter)

Example 15 with SelectedGpxFile

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

Aggregations

SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)66 GPXFile (net.osmand.GPXUtilities.GPXFile)36 File (java.io.File)26 MapActivity (net.osmand.plus.activities.MapActivity)18 OsmandApplication (net.osmand.plus.OsmandApplication)17 ArrayList (java.util.ArrayList)13 WptPt (net.osmand.GPXUtilities.WptPt)12 GpxSelectionHelper (net.osmand.plus.track.helpers.GpxSelectionHelper)12 GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)9 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)8 LatLon (net.osmand.data.LatLon)8 SelectedGpxPoint (net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)6 NonNull (androidx.annotation.NonNull)5 Paint (android.graphics.Paint)4 CallbackWithObject (net.osmand.CallbackWithObject)4 MapMarker (net.osmand.plus.mapmarkers.MapMarker)4 GpxDisplayGroup (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup)4 DialogInterface (android.content.DialogInterface)3