use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class GPXAction method getGpxFile.
private void getGpxFile(@NonNull String gpxFilePath, @NonNull MapActivity mapActivity, @NonNull CallbackWithObject<GPXFile> onGpxFileAvailable) {
OsmandApplication app = mapActivity.getMyApplication();
if (gpxFilePath.isEmpty()) {
onGpxFileAvailable.processResult(app.getSavingTrackHelper().getCurrentGpx());
} else {
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
if (selectedGpxFile != null) {
onGpxFileAvailable.processResult(selectedGpxFile.getGpxFile());
} else {
CallbackWithObject<GPXFile[]> onGpxFileLoaded = gpxFiles -> {
onGpxFileAvailable.processResult(gpxFiles[0]);
return true;
};
String gpxFileName = Algorithms.getFileWithoutDirs(gpxFilePath);
File gpxFileDir = new File(gpxFilePath.replace("/" + gpxFileName, ""));
GpxUiHelper.loadGPXFileInDifferentThread(mapActivity, onGpxFileLoaded, gpxFileDir, null, gpxFileName);
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class OsmandAidlApi method finishGpxImport.
@SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
final int col = GpxAppearanceAdapter.parseTrackColor(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
if (!destinationExists) {
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
gpxDataItem.setApiImported(true);
app.getGpxDbHelper().add(gpxDataItem);
} else {
GpxDataItem item = app.getGpxDbHelper().getItem(destination);
if (item != null) {
app.getGpxDbHelper().updateColor(item, col);
}
}
final GpxSelectionHelper helper = app.getSelectedGpxHelper();
final SelectedGpxFile selectedGpx = helper.getSelectedFileByName(destination.getName());
if (selectedGpx != null) {
if (show) {
new AsyncTask<File, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(File... files) {
return GPXUtilities.loadGPXFile(files[0]);
}
@Override
protected void onPostExecute(GPXFile gpx) {
if (gpx.error == null) {
if (col != -1) {
gpx.setColor(col);
}
selectedGpx.setGpxFile(gpx, app);
refreshMap();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
} else {
helper.selectGpxFile(selectedGpx.getGpxFile(), false, false);
refreshMap();
}
} else if (show) {
new AsyncTask<File, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(File... files) {
return GPXUtilities.loadGPXFile(files[0]);
}
@Override
protected void onPostExecute(GPXFile gpx) {
if (gpx.error == null) {
helper.selectGpxFile(gpx, true, false);
refreshMap();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class MapContextMenu method addWptPt.
public void addWptPt() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
PointDescription pointDescription = getPointDescription();
String title = getTitleStr();
if (pointDescription.isWpt() || !hasValidTitle()) {
title = "";
}
String preselectedIconName = null;
Object object = getObject();
if (object instanceof Amenity && pointDescription.isPoi()) {
int preselectedIconId = getPreselectedIconId(((Amenity) object));
preselectedIconName = RenderingIcons.getBigIconName(preselectedIconId);
}
List<SelectedGpxFile> list = app.getSelectedGpxHelper().getSelectedGPXFiles();
boolean forceAddToCurrentTrack = OsmandPlugin.isActive(OsmandMonitoringPlugin.class) && (list.isEmpty() || (list.size() == 1 && list.get(0).getGpxFile().showCurrentTrack));
if (forceAddToCurrentTrack) {
GPXFile gpxFile = app.getSavingTrackHelper().getCurrentGpx();
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
if (wptPtPointEditor != null) {
wptPtPointEditor.add(gpxFile, getLatLon(), title, preselectedIconName);
}
} else {
addNewWptToGPXFile(title, preselectedIconName);
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class MeasurementToolFragment method showGpxOnMap.
protected static void showGpxOnMap(OsmandApplication app, GPXFile gpx, boolean isNewGpx) {
GPXUtilities.createArtificialPrimeMeridianPoints(gpx);
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
if (sf != null && !isNewGpx) {
sf.processPoints(app);
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class GPXLayer method showMenuAction.
@Override
public boolean showMenuAction(@Nullable Object object) {
OsmandApplication app = view.getApplication();
MapActivity mapActivity = view.getMapActivity();
if (mapActivity != null) {
if (object instanceof Pair && ((Pair<?, ?>) object).first instanceof TravelGpx && ((Pair<?, ?>) object).second instanceof SelectedGpxPoint) {
Pair<TravelGpx, SelectedGpxPoint> pair = (Pair) object;
LatLon latLon = new LatLon(pair.second.getSelectedPoint().lat, pair.second.getSelectedPoint().lon);
TravelHelper travelHelper = app.getTravelHelper();
travelHelper.openTrackMenu(pair.first, mapActivity, pair.first.getRouteId(), latLon);
return true;
} else if (object instanceof SelectedGpxPoint) {
SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) object;
if (selectedGpxPoint.shouldShowTrackPointMenu()) {
WptPt selectedWptPt = selectedGpxPoint.getSelectedPoint();
LatLon latLon = new LatLon(selectedWptPt.lat, selectedWptPt.lon);
contextMenuLayer.showContextMenu(latLon, getObjectName(selectedGpxPoint), selectedGpxPoint, null);
} else {
SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile();
TrackMenuFragment.showInstance(mapActivity, selectedGpxFile, selectedGpxPoint);
}
return true;
}
}
return false;
}
Aggregations