Search in sources :

Example 21 with SelectedGpxFile

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

the class GPXLayer method removeCachedUnselectedTracks.

private void removeCachedUnselectedTracks(List<SelectedGpxFile> selectedGpxFiles) {
    Set<String> cachedTracksPaths = segmentsCache.keySet();
    List<String> selectedTracksPaths = new ArrayList<>();
    for (SelectedGpxFile gpx : selectedGpxFiles) {
        selectedTracksPaths.add(gpx.getGpxFile().path);
    }
    for (Iterator<String> iterator = cachedTracksPaths.iterator(); iterator.hasNext(); ) {
        String cachedTrackPath = iterator.next();
        boolean trackHidden = !selectedTracksPaths.contains(cachedTrackPath);
        if (trackHidden) {
            iterator.remove();
        }
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ArrayList(java.util.ArrayList)

Example 22 with SelectedGpxFile

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

the class GPXLayer method applyNewObjectPosition.

@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable final ContextMenuLayer.ApplyMovedObjectCallback callback) {
    if (o instanceof WptPt) {
        final WptPt objectInMotion = (WptPt) o;
        SelectedGpxFile selectedGpxFile = pointFileMap.get(objectInMotion);
        if (selectedGpxFile != null) {
            GPXFile gpxFile = selectedGpxFile.getGpxFile();
            gpxFile.updateWptPt(objectInMotion, position.getLatitude(), position.getLongitude(), System.currentTimeMillis(), objectInMotion.desc, objectInMotion.name, objectInMotion.category, objectInMotion.getColor(), objectInMotion.getIconName(), objectInMotion.getBackgroundType());
            syncGpx(gpxFile);
            if (gpxFile.showCurrentTrack) {
                if (callback != null) {
                    callback.onApplyMovedObject(true, objectInMotion);
                }
            } else {
                new SaveGpxAsyncTask(new File(gpxFile.path), gpxFile, new SaveGpxAsyncTask.SaveGpxListener() {

                    @Override
                    public void gpxSavingStarted() {
                    }

                    @Override
                    public void gpxSavingFinished(Exception errorMessage) {
                        if (callback != null) {
                            callback.onApplyMovedObject(errorMessage == null, objectInMotion);
                        }
                    }
                }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    } else if (callback != null) {
        callback.onApplyMovedObject(false, o);
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SaveGpxAsyncTask(net.osmand.plus.track.SaveGpxAsyncTask) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 23 with SelectedGpxFile

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

the class GPXLayer method drawSelectedFilesSplits.

private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
    if (tileBox.getZoom() >= START_ZOOM) {
        // request to load
        OsmandApplication app = view.getApplication();
        for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
            List<GpxDisplayGroup> groups = selectedGpxFile.getDisplayGroups(app);
            if (!Algorithms.isEmpty(groups)) {
                int color = getTrackColor(selectedGpxFile.getGpxFile(), cachedColor);
                paintInnerRect.setColor(color);
                paintInnerRect.setAlpha(179);
                int contrastColor = ColorUtilities.getContrastColor(app, color, false);
                paintTextIcon.setColor(contrastColor);
                paintOuterRect.setColor(contrastColor);
                List<GpxDisplayItem> items = groups.get(0).getModifiableList();
                drawSplitItems(canvas, tileBox, items, settings);
            }
        }
    }
}
Also used : GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) Paint(android.graphics.Paint) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)

Example 24 with SelectedGpxFile

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

the class WptPtEditorFragmentNew method isCategoryVisible.

@Override
protected boolean isCategoryVisible(String categoryName) {
    WptPtEditor editor = getWptPtEditor();
    if (selectedGpxHelper == null || editor == null || editor.getGpxFile() == null) {
        return true;
    }
    SelectedGpxFile selectedGpxFile;
    if (editor.getGpxFile().showCurrentTrack) {
        selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
    } else {
        selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(editor.getGpxFile().path);
    }
    if (selectedGpxFile != null) {
        return !selectedGpxFile.isGroupHidden(categoryName);
    }
    return true;
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)

Example 25 with SelectedGpxFile

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

the class MapMarkersHelper method syncTrackGroup.

private void syncTrackGroup(@NonNull MapMarkersGroup group, @NonNull List<MapMarker> existingMarkers) {
    GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
    File file = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + group.getId());
    if (!file.exists() || !file.isFile()) {
        removeFromGroupsList(group);
        return;
    }
    SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(file.getAbsolutePath());
    GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
    group.setVisible(gpx != null || group.isVisibleUntilRestart());
    if (gpx == null || group.isDisabled()) {
        removeGroupActiveMarkers(group, true);
        return;
    }
    int colorIndex = -1;
    boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty();
    List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
    for (WptPt wptPt : gpxPoints) {
        if (addAll || group.getWptCategories().contains(wptPt.category) || (wptPt.category == null && group.getWptCategories().contains(""))) {
            if (colorIndex == -1) {
                colorIndex = mapMarkers.isEmpty() ? 0 : (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
            } else {
                colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
            }
            MapMarker mapMarker = ItineraryDataHelper.fromWpt(ctx, wptPt, group);
            mapMarker.colorIndex = colorIndex;
            existingMarkers.add(mapMarker);
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ArrayList(java.util.ArrayList) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) FavouritePoint(net.osmand.data.FavouritePoint)

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