Search in sources :

Example 11 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmNotesMenu method createLayersItems.

private static void createLayersItems(@NonNull final ContextMenuAdapter adapter, @NonNull final MapActivity mapActivity) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null) {
        return;
    }
    final boolean nightMode = isNightMode(app);
    final int themeRes = getThemeRes(app);
    final int selectedModeColor = settings.getApplicationMode().getProfileColor(nightMode);
    final int osmNotesStringId = R.string.layer_osm_bugs;
    final int showZoomLevelStringId = R.string.show_from_zoom_level;
    final int showClosedNotesStringId = R.string.show_closed_notes;
    final String[] zoomStrings = getZoomStrings(mapActivity);
    OnRowItemClick l = new OnRowItemClick() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int position, boolean isChecked, int[] viewCoordinates) {
            if (itemId == osmNotesStringId) {
                plugin.SHOW_OSM_BUGS.set(isChecked);
                plugin.updateLayers(mapActivity, mapActivity);
                mapActivity.refreshMap();
                mapActivity.getDashboard().refreshContent(true);
            } else if (itemId == showZoomLevelStringId) {
                int checked = Arrays.asList(zoomIntValues).indexOf(plugin.SHOW_OSM_BUGS_MIN_ZOOM.get());
                DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(zoomStrings, nightMode, checked, app, selectedModeColor, themeRes, v -> {
                    int which = (int) v.getTag();
                    plugin.SHOW_OSM_BUGS_MIN_ZOOM.set(zoomIntValues[which]);
                    ContextMenuItem item = adapter.getItem(position);
                    if (item != null) {
                        item.setDescription(zoomStrings[which]);
                        adapter.notifyDataSetChanged();
                    }
                    mapActivity.refreshMap();
                });
                AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(mapActivity, themeRes)).setTitle(R.string.show_from_zoom_level).setAdapter(dialogAdapter, null).setNegativeButton(R.string.shared_string_dismiss, null);
                dialogAdapter.setDialog(b.show());
            } else if (itemId == showClosedNotesStringId) {
                plugin.SHOW_CLOSED_OSM_BUGS.set(isChecked);
                mapActivity.refreshMap();
            }
            return false;
        }
    };
    boolean showOsmBugs = plugin.SHOW_OSM_BUGS.get();
    int toggleIconColorId;
    if (showOsmBugs) {
        toggleIconColorId = ColorUtilities.getActiveColorId(nightMode);
    } else {
        toggleIconColorId = ContextMenuItem.INVALID_ID;
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(osmNotesStringId, mapActivity).setDescription(mapActivity.getString(R.string.switch_osm_notes_visibility_desc)).setIcon(R.drawable.ic_action_osm_note).setColor(app, toggleIconColorId).setListener(l).setSelected(showOsmBugs).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(showZoomLevelStringId, mapActivity).setDescription(zoomStrings[Arrays.asList(zoomIntValues).indexOf(plugin.SHOW_OSM_BUGS_MIN_ZOOM.get())]).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener(l).setClickable(showOsmBugs).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(showClosedNotesStringId, mapActivity).setIcon(R.drawable.ic_action_note_dark).setListener(l).setSelected(plugin.SHOW_CLOSED_OSM_BUGS.get()).setClickable(showOsmBugs).hideDivider(true).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setLayout(R.layout.card_bottom_divider).setClickable(false).createItem());
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) AlertDialog(androidx.appcompat.app.AlertDialog) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ColorUtilities(net.osmand.plus.utils.ColorUtilities) NonNull(androidx.annotation.NonNull) R(net.osmand.plus.R) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayAdapter(android.widget.ArrayAdapter) OsmandPlugin(net.osmand.plus.plugins.OsmandPlugin) ContextThemeWrapper(android.view.ContextThemeWrapper) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter) MapActivity(net.osmand.plus.activities.MapActivity) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 12 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class TrackMenuFragment method onCardButtonPressed.

@Override
public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    GPXFile gpxFile = getGpx();
    if (card instanceof OptionsCard || card instanceof OverviewCard || card instanceof SegmentsCard) {
        if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
            if (FileUtils.isTempFile(app, getGpx().path)) {
                File srcFile = displayHelper.getFile();
                File destFIle = new File(app.getAppPath(IndexConstants.GPX_TRAVEL_DIR), srcFile.getName());
                onFileMove(srcFile, destFIle);
                gpxFile = getGpx();
            } else {
                boolean gpxFileSelected = !isGpxFileSelected(app, gpxFile);
                app.getSelectedGpxHelper().selectGpxFile(gpxFile, gpxFileSelected, false);
            }
            updateContent();
            mapActivity.refreshMap();
        } else if (buttonIndex == APPEARANCE_BUTTON_INDEX) {
            TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
        } else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
            GPXFile gpxFileToDisplay = displayHelper.getGpxFileToDisplay();
            if (gpxFileToDisplay != null) {
                if (gpxFileToDisplay.getNonEmptySegmentsCount() > 1) {
                    TrackSelectSegmentBottomSheet.showInstance(fragmentManager, gpxFileToDisplay, this);
                } else {
                    GpxNavigationHelper.startNavigationForGpx(gpxFileToDisplay, mapActivity);
                    dismiss();
                }
            }
        }
        if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
            displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
            mapActivity.refreshMap();
            if (segmentsCard != null) {
                segmentsCard.updateContent();
            }
        } else if (buttonIndex == ANALYZE_ON_MAP_BUTTON_INDEX) {
            new OpenGpxDetailsTask(selectedGpxFile, null, mapActivity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            dismiss();
        } else if (buttonIndex == ANALYZE_BY_INTERVALS_BUTTON_INDEX) {
            TrkSegment segment = gpxFile.getGeneralSegment();
            if (segment == null) {
                List<TrkSegment> segments = gpxFile.getNonEmptyTrkSegments(false);
                if (!Algorithms.isEmpty(segments)) {
                    segment = segments.get(0);
                }
            }
            GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] { GpxDisplayItemType.TRACK_SEGMENT };
            List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
            if (segment != null && !Algorithms.isEmpty(items)) {
                SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
            }
        } else if (buttonIndex == SHARE_BUTTON_INDEX) {
            OsmandApplication app = mapActivity.getMyApplication();
            if (gpxFile.showCurrentTrack) {
                GpxUiHelper.saveAndShareCurrentGpx(app, gpxFile);
            } else if (!Algorithms.isEmpty(gpxFile.path)) {
                GpxUiHelper.saveAndShareGpxWithAppearance(app, gpxFile);
            }
        } else if (buttonIndex == UPLOAD_OSM_BUTTON_INDEX) {
            OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
            if (osmEditingPlugin != null) {
                GpxInfo gpxInfo = new GpxInfo();
                gpxInfo.gpx = gpxFile;
                gpxInfo.file = new File(gpxFile.path);
                osmEditingPlugin.sendGPXFiles(mapActivity, this, gpxInfo);
            }
        } else if (buttonIndex == EDIT_BUTTON_INDEX) {
            app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
            dismiss();
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            MeasurementToolFragment.showInstance(fragmentManager, fileName, false);
        } else if (buttonIndex == RENAME_BUTTON_INDEX) {
            FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
        } else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
            MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true, false);
        } else if (buttonIndex == GPS_FILTER_BUTTON_INDEX) {
            GpsFilterFragment.showInstance(fragmentManager, selectedGpxFile, this);
        } else if (buttonIndex == DELETE_BUTTON_INDEX) {
            String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
            AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(mapActivity, isNightMode()));
            builder.setTitle(getString(R.string.delete_confirmation_msg, fileName));
            builder.setMessage(R.string.are_you_sure);
            final String gpxFilePath = gpxFile.path;
            builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (FileUtils.removeGpxFile(app, new File(gpxFilePath))) {
                        dismiss();
                    }
                }
            });
            builder.show();
        }
    } else if (card instanceof TrackPointsCard) {
        if (buttonIndex == ADD_WAYPOINT_INDEX) {
            PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, app.getString(R.string.add_waypoint));
            QuadRect rect = displayHelper.getRect();
            NewGpxPoint newGpxPoint = new NewGpxPoint(gpxFile, pointDescription, rect);
            mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, (int) rect.width(), (int) rect.height(), 0);
            mapActivity.getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
            hide();
        } else if (buttonIndex == DELETE_WAYPOINTS_INDEX) {
            TrackPointsCard pointsCard = (TrackPointsCard) card;
            if (pointsCard.isSelectionMode()) {
                pointsCard.deleteItemsAction();
            } else {
                pointsCard.setSelectionMode(true);
            }
        } else if (buttonIndex == OPEN_WAYPOINT_INDEX) {
            dismiss();
        }
    } else if (card instanceof PointsGroupsCard) {
        PointsGroupsCard groupsCard = (PointsGroupsCard) card;
        GpxDisplayGroup group = groupsCard.getSelectedGroup();
        if (pointsCard != null) {
            pointsCard.setSelectedGroup(group);
            if (group != null) {
                fitSelectedPointsGroupOnMap(group);
            } else {
                fitTrackOnMap();
            }
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) GpxDisplayGroup(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayGroup) OsmandApplication(net.osmand.plus.OsmandApplication) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) DialogInterface(android.content.DialogInterface) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) OpenGpxDetailsTask(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.OpenGpxDetailsTask) QuadRect(net.osmand.data.QuadRect) PointsGroupsCard(net.osmand.plus.track.cards.PointsGroupsCard) SegmentsCard(net.osmand.plus.track.cards.SegmentsCard) TrackPointsCard(net.osmand.plus.track.cards.TrackPointsCard) MapActivity(net.osmand.plus.activities.MapActivity) OptionsCard(net.osmand.plus.track.cards.OptionsCard) OverviewCard(net.osmand.plus.track.cards.OverviewCard) GpxInfo(net.osmand.plus.myplaces.ui.AvailableGPXFragment.GpxInfo) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GpxDisplayItemType(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItemType) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) FragmentManager(androidx.fragment.app.FragmentManager) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Example 13 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmandPlugin method initPlugins.

public static void initPlugins(@NonNull OsmandApplication app) {
    Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
    allPlugins.clear();
    allPlugins.add(new WikipediaPlugin(app));
    allPlugins.add(new OsmandRasterMapsPlugin(app));
    allPlugins.add(new OsmandMonitoringPlugin(app));
    checkMarketPlugin(app, new SRTMPlugin(app));
    checkMarketPlugin(app, new NauticalMapsPlugin(app));
    checkMarketPlugin(app, new SkiMapsPlugin(app));
    allPlugins.add(new AudioVideoNotesPlugin(app));
    checkMarketPlugin(app, new ParkingPositionPlugin(app));
    allPlugins.add(new OsmEditingPlugin(app));
    allPlugins.add(new OpenPlaceReviewsPlugin(app));
    allPlugins.add(new MapillaryPlugin(app));
    allPlugins.add(new AccessibilityPlugin(app));
    allPlugins.add(new OsmandDevelopmentPlugin(app));
    loadCustomPlugins(app);
    registerAppInitializingDependedProperties(app);
    enablePluginsByDefault(app, enabledPlugins);
    activatePlugins(app, enabledPlugins);
}
Also used : SRTMPlugin(net.osmand.plus.plugins.srtm.SRTMPlugin) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) OpenPlaceReviewsPlugin(net.osmand.plus.plugins.openplacereviews.OpenPlaceReviewsPlugin) OsmandMonitoringPlugin(net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) MapillaryPlugin(net.osmand.plus.plugins.mapillary.MapillaryPlugin) SkiMapsPlugin(net.osmand.plus.plugins.skimaps.SkiMapsPlugin) ParkingPositionPlugin(net.osmand.plus.plugins.parking.ParkingPositionPlugin) OsmandDevelopmentPlugin(net.osmand.plus.plugins.development.OsmandDevelopmentPlugin) NauticalMapsPlugin(net.osmand.plus.plugins.openseamaps.NauticalMapsPlugin) WikipediaPlugin(net.osmand.plus.wikipedia.WikipediaPlugin) AccessibilityPlugin(net.osmand.plus.plugins.accessibility.AccessibilityPlugin) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin)

Example 14 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmNotesSettingsItem method apply.

@Override
public void apply() {
    List<OsmNotesPoint> newItems = getNewItems();
    if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
        appliedItems = new ArrayList<>(newItems);
        OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (osmEditingPlugin != null) {
            OsmBugsDbHelper db = osmEditingPlugin.getDBBug();
            for (OsmNotesPoint duplicate : duplicateItems) {
                int ind = existingItems.indexOf(duplicate);
                if (ind != -1 && ind < existingItems.size()) {
                    OsmNotesPoint original = existingItems.get(ind);
                    if (original != null) {
                        db.deleteAllBugModifications(original);
                    }
                    db.addOsmbugs(duplicate);
                }
            }
            for (OsmNotesPoint point : appliedItems) {
                db.addOsmbugs(point);
            }
        }
    }
}
Also used : OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmBugsDbHelper(net.osmand.plus.plugins.osmedit.helpers.OsmBugsDbHelper) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 15 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmNotesSettingsItem method init.

@Override
protected void init() {
    super.init();
    OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        existingItems = osmEditingPlugin.getDBBug().getOsmbugsPoints();
    }
}
Also used : OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Aggregations

OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)20 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 Entity (net.osmand.osm.edit.Entity)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)4 AlertDialog (androidx.appcompat.app.AlertDialog)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)3 DialogInterface (android.content.DialogInterface)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiType (net.osmand.osm.PoiType)2 Node (net.osmand.osm.edit.Node)2 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)2 UploadOpenstreetmapPointAsyncTask (net.osmand.plus.plugins.osmedit.asynctasks.UploadOpenstreetmapPointAsyncTask)2