Search in sources :

Example 16 with SelectedGpxFile

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);
        }
    }
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) LinearLayout(android.widget.LinearLayout) AddressLookupRequest(net.osmand.plus.GeocodingLookupService.AddressLookupRequest) NonNull(androidx.annotation.NonNull) QuickAction(net.osmand.plus.quickaction.QuickAction) ImageView(android.widget.ImageView) R(net.osmand.plus.R) WptPt(net.osmand.GPXUtilities.WptPt) OnDismissListener(net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener) Drawable(android.graphics.drawable.Drawable) ColorInt(androidx.annotation.ColorInt) ColorStateList(android.content.res.ColorStateList) UiUtilities(net.osmand.plus.utils.UiUtilities) CallbackWithObject(net.osmand.CallbackWithObject) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) ColorDialogs(net.osmand.plus.helpers.ColorDialogs) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) Fragment(androidx.fragment.app.Fragment) View(android.view.View) TextRadioItem(net.osmand.plus.widgets.multistatetoggle.TextToggleButton.TextRadioItem) TextToggleButton(net.osmand.plus.widgets.multistatetoggle.TextToggleButton) GPXFile(net.osmand.GPXUtilities.GPXFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) AndroidUiHelper(net.osmand.plus.helpers.AndroidUiHelper) RenderingIcons(net.osmand.plus.render.RenderingIcons) GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) ViewGroup(android.view.ViewGroup) OsmandApplication(net.osmand.plus.OsmandApplication) CreateEditActionDialog(net.osmand.plus.quickaction.CreateEditActionDialog) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) Typeface(android.graphics.Typeface) Context(android.content.Context) ColorUtilities(net.osmand.plus.utils.ColorUtilities) Dialog(android.app.Dialog) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXUtilities(net.osmand.GPXUtilities) GpxUiHelper(net.osmand.plus.helpers.GpxUiHelper) LatLon(net.osmand.data.LatLon) WptPtEditor(net.osmand.plus.mapcontextmenu.editors.WptPtEditor) OsmAndFormatter(net.osmand.plus.utils.OsmAndFormatter) Algorithms(net.osmand.util.Algorithms) SelectTrackFileDialogFragment(net.osmand.plus.quickaction.SelectTrackFileDialogFragment) AndroidUtils(net.osmand.plus.utils.AndroidUtils) LayoutInflater(android.view.LayoutInflater) ProgressDialog(android.app.ProgressDialog) File(java.io.File) BackgroundType(net.osmand.data.FavouritePoint.BackgroundType) QuickActionType(net.osmand.plus.quickaction.QuickActionType) OnRadioItemClickListener(net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener) MapActivity(net.osmand.plus.activities.MapActivity) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 17 with SelectedGpxFile

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);
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) AsyncTask(android.os.AsyncTask) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) ASqliteDbFile(net.osmand.aidl.tiles.ASqliteDbFile) File(java.io.File) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) AGpxFile(net.osmand.aidl.gpx.AGpxFile) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 18 with SelectedGpxFile

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);
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) OsmandMonitoringPlugin(net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin) WptPtEditor(net.osmand.plus.mapcontextmenu.editors.WptPtEditor) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) CallbackWithObject(net.osmand.CallbackWithObject) GPXFile(net.osmand.GPXUtilities.GPXFile) MapActivity(net.osmand.plus.activities.MapActivity)

Example 19 with SelectedGpxFile

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);
    }
}
Also used : SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)

Example 20 with SelectedGpxFile

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;
}
Also used : TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) LatLon(net.osmand.data.LatLon) WptPt(net.osmand.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint) MapActivity(net.osmand.plus.activities.MapActivity) Pair(android.util.Pair) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

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