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();
}
}
}
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);
}
}
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);
}
}
}
}
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;
}
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);
}
}
}
Aggregations