Search in sources :

Example 11 with GpxSelectionHelper

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

the class MapLayerMenuListener method onContextMenuClick.

@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
    final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
    final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters();
    final ContextMenuItem item = menuAdapter.getItem(pos);
    if (item.getSelected() != null) {
        item.setColor(mapActivity, isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
    }
    if (itemId == R.string.layer_poi) {
        PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
        poiFiltersHelper.clearSelectedPoiFilters(wiki);
        if (isChecked) {
            showPoiFilterDialog(adapter, adapter.getItem(pos));
        } else {
            adapter.getItem(pos).setDescription(poiFiltersHelper.getSelectedPoiFiltersName(wiki));
        }
    } else if (itemId == R.string.layer_amenity_label) {
        settings.SHOW_POI_LABEL.set(isChecked);
    } else if (itemId == R.string.shared_string_favorites) {
        settings.SHOW_FAVORITES.set(isChecked);
    } else if (itemId == R.string.layer_gpx_layer) {
        final GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
        if (selectedGpxHelper.isShowingAnyGpxFiles()) {
            selectedGpxHelper.clearAllGpxFilesToShow(true);
            adapter.getItem(pos).setDescription(selectedGpxHelper.getGpxDescription());
        } else {
            showGpxSelectionDialog(adapter, adapter.getItem(pos));
        }
    } else if (itemId == R.string.rendering_category_transport) {
        boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication());
        TransportLinesMenu.toggleTransportLines(mapActivity, !selected, result -> {
            item.setSelected(result);
            item.setColor(mapActivity, result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
            adapter.notifyDataSetChanged();
            return true;
        });
    } else if (itemId == R.string.map_markers) {
        settings.SHOW_MAP_MARKERS.set(isChecked);
    } else if (itemId == R.string.layer_map) {
        if (!OsmandPlugin.isActive(OsmandRasterMapsPlugin.class)) {
            PluginsFragment.showInstance(mapActivity.getSupportFragmentManager());
        } else {
            ContextMenuItem it = adapter.getItem(pos);
            mapActivity.getMapLayers().selectMapLayer(mapActivity, it, adapter);
        }
        return false;
    }
    adapter.notifyDataSetChanged();
    mapActivity.updateLayers();
    mapActivity.refreshMap();
    return false;
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 12 with GpxSelectionHelper

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

the class WptPtEditorFragmentNew method doAddWpt.

private void doAddWpt(String name, String category, String description) {
    WptPt wpt = getWpt();
    WptPtEditor editor = getWptPtEditor();
    if (wpt != null && editor != null) {
        wpt.name = name;
        wpt.category = category;
        wpt.desc = description;
        if (color != 0) {
            wpt.setColor(color);
        } else {
            wpt.removeColor();
        }
        wpt.setBackgroundType(backgroundTypeName);
        wpt.setIconName(iconName);
        GPXFile gpx = editor.getGpxFile();
        SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
        GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
        if (gpx != null && savingTrackHelper != null && selectedGpxHelper != null) {
            if (gpx.showCurrentTrack) {
                this.wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color, iconName, backgroundTypeName);
                if (!editor.isGpxSelected()) {
                    selectedGpxHelper.setGpxFileToDisplay(gpx);
                }
            } else {
                addWpt(gpx, description, name, category, color, iconName, backgroundTypeName);
                saveGpx(getMyApplication(), gpx, editor.isGpxSelected());
            }
            syncGpx(gpx);
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 13 with GpxSelectionHelper

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

the class WptPtMenuBuilder method buildWaypointsView.

private void buildWaypointsView(View view) {
    GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
    SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedGPXFile(wpt);
    if (selectedGpxFile != null) {
        List<WptPt> points = selectedGpxFile.getGpxFile().getPoints();
        GPXUtilities.GPXFile gpx = selectedGpxFile.getGpxFile();
        if (points.size() > 0) {
            String title = view.getContext().getString(R.string.context_menu_points_of_group);
            File file = new File(gpx.path);
            String gpxName = file.getName().replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
            int color = getPointColor(wpt, getFileColor(selectedGpxFile));
            buildRow(view, app.getUIUtilities().getPaintedIcon(R.drawable.ic_type_waypoints_group, color), null, title, 0, gpxName, true, getCollapsableWaypointsView(view.getContext(), true, gpx, wpt), false, 0, false, null, false);
        }
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) 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) GPXUtilities(net.osmand.GPXUtilities)

Example 14 with GpxSelectionHelper

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

the class MapMarkersGroupsAdapter method switchGpxVisibility.

private void switchGpxVisibility(@NonNull GPXFile gpxFile, @Nullable SelectedGpxFile selectedGpxFile, boolean visible) {
    GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
    if (!visible && selectedGpxFile != null && selectedGpxFile.selectedByUser) {
        return;
    }
    gpxHelper.selectGpxFile(gpxFile, visible, false, false, false, false);
}
Also used : GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper)

Example 15 with GpxSelectionHelper

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

the class MapMarkersHelper method syncGpxPassedPoints.

private void syncGpxPassedPoints(MapMarker marker, Set<GPXFile> gpxFiles) {
    GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
    File file = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + marker.groupKey);
    if (file.exists()) {
        SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(file.getAbsolutePath());
        if (selectedGpxFile != null) {
            boolean passedPoint = marker.wptPt.getExtensionsToWrite().containsKey(VISITED_DATE);
            if (marker.history && !passedPoint) {
                marker.wptPt.getExtensionsToWrite().put(VISITED_DATE, GPXUtilities.formatTime(System.currentTimeMillis()));
                gpxFiles.add(selectedGpxFile.getGpxFile());
            } else if (!marker.history && passedPoint) {
                marker.wptPt.getExtensionsToWrite().remove(VISITED_DATE);
                gpxFiles.add(selectedGpxFile.getGpxFile());
            }
        }
    }
}
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) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Aggregations

GpxSelectionHelper (net.osmand.plus.track.helpers.GpxSelectionHelper)20 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)12 File (java.io.File)9 GPXFile (net.osmand.GPXUtilities.GPXFile)8 WptPt (net.osmand.GPXUtilities.WptPt)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)3 SavingTrackHelper (net.osmand.plus.track.helpers.SavingTrackHelper)3 Bundle (android.os.Bundle)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 FavouritePoint (net.osmand.data.FavouritePoint)2 GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AsyncTask (android.os.AsyncTask)1 Editable (android.text.Editable)1