Search in sources :

Example 1 with OsmEditingPlugin

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

the class ShowHideOSMBugAction method execute.

@Override
public void execute(MapActivity activity) {
    activity.getMyApplication().getSettings().SHOW_OSM_BUGS.set(!activity.getMyApplication().getSettings().SHOW_OSM_BUGS.get());
    OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
    if (plugin != null) {
        plugin.updateLayers(activity.getMapView(), activity);
        activity.getMapView().refreshMap(true);
    }
}
Also used : OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin)

Example 2 with OsmEditingPlugin

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

the class AddPOIAction method execute.

@Override
public void execute(final MapActivity activity) {
    LatLon latLon = activity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null)
        return;
    Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
    node.replaceTags(getTagsFromParams());
    EditPoiData editPoiData = new EditPoiData(node, activity.getMyApplication());
    if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
        Node newNode = editPoiData.getEntity();
        EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newNode, true, getTagsFromParams());
        editPoiDialogFragment.show(activity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
    } else {
        OpenstreetmapUtil mOpenstreetmapUtil;
        if (activity.getMyApplication().getSettings().OFFLINE_EDITION.get() || !activity.getMyApplication().getSettings().isInternetConnectionAvailable(true)) {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
        }
        final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
        Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId());
        OsmPoint.Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
        for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
            if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
                final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
                if (poiType != null) {
                    newNode.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
                    if (poiType.getOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                    }
                } else if (!Algorithms.isEmpty(tag.getValue())) {
                    newNode.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), tag.getValue());
                }
                if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
                    newNode.putTagNoLC(tag.getKey(), tag.getValue());
                }
            } else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
                newNode.putTagNoLC(tag.getKey(), tag.getValue());
            }
        }
        EditPoiDialogFragment.commitNode(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, new CallbackWithObject<Node>() {

            @Override
            public boolean processResult(Node result) {
                if (result != null) {
                    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                    if (plugin != null && offlineEdit) {
                        List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
                        if (activity instanceof MapActivity && points.size() > 0) {
                            OsmPoint point = points.get(points.size() - 1);
                            activity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(activity).getObjectName(point), point);
                        }
                    }
                    if (activity instanceof MapActivity) {
                        activity.getMapView().refreshMap(true);
                    }
                } else {
                // OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                // mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
                // Button saveButton = (Button) view.findViewById(R.id.saveButton);
                // saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
                // ? R.string.shared_string_upload : R.string.shared_string_save);
                }
                return false;
            }
        }, activity, mOpenstreetmapUtil, null);
    }
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.osmedit.EditPoiDialogFragment) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.osmedit.OpenstreetmapLocalUtil) EditPoiData(net.osmand.plus.osmedit.EditPoiData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.osmedit.OpenstreetmapUtil) MapActivity(net.osmand.plus.activities.MapActivity)

Example 3 with OsmEditingPlugin

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

the class AvailableGPXFragment method openPopUpMenu.

private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
    IconsCache iconsCache = getMyApplication().getIconsCache();
    final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
    DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
    MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            showGpxOnMap(gpxInfo);
            return true;
        }
    });
    GPXTrackAnalysis analysis;
    if ((analysis = getGpxTrackAnalysis(gpxInfo, app)) != null) {
        if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
            item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    return true;
                }
            });
        }
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            moveGpx(gpxInfo);
            return true;
        }
    });
    item = optionsMenu.getMenu().add(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            LocalIndexesFragment.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {

                @Override
                public void renamedTo(File file) {
                    app.getGpxDatabase().rename(gpxInfo.file, file);
                    asyncLoader = new LoadGpxTask();
                    asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
                }
            });
            return true;
        }
    });
    item = optionsMenu.getMenu().add(R.string.shared_string_share).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Uri fileUri = Uri.fromFile(gpxInfo.file);
            final Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
            sendIntent.setType("application/gpx+xml");
            startActivity(sendIntent);
            return true;
        }
    });
    final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
        item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
                return true;
            }
        });
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(R.string.recording_delete_confirm);
            builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    operationTask = new DeleteGpxTask();
                    operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
                }
            });
            builder.setNegativeButton(R.string.shared_string_cancel, null);
            builder.show();
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) Intent(android.content.Intent) Uri(android.net.Uri) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) RenameCallback(net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback) IconsCache(net.osmand.plus.IconsCache) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Example 4 with OsmEditingPlugin

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

the class OsmandPlugin method initPlugins.

public static void initPlugins(OsmandApplication app) {
    OsmandSettings settings = app.getSettings();
    Set<String> enabledPlugins = settings.getEnabledPlugins();
    allPlugins.add(new MapillaryPlugin(app));
    enabledPlugins.add(MapillaryPlugin.ID);
    allPlugins.add(new OsmandRasterMapsPlugin(app));
    allPlugins.add(new OsmandMonitoringPlugin(app));
    checkMarketPlugin(app, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
    // ? questionable - definitely not market plugin
    // checkMarketPlugin(app, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
    checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
    checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
    allPlugins.add(new AudioVideoNotesPlugin(app));
    checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
    allPlugins.add(new AccessibilityPlugin(app));
    allPlugins.add(new OsmEditingPlugin(app));
    allPlugins.add(new OsmandDevelopmentPlugin(app));
    activatePlugins(app, enabledPlugins);
}
Also used : SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) AudioVideoNotesPlugin(net.osmand.plus.audionotes.AudioVideoNotesPlugin) OsmandMonitoringPlugin(net.osmand.plus.monitoring.OsmandMonitoringPlugin) MapillaryPlugin(net.osmand.plus.mapillary.MapillaryPlugin) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) SkiMapsPlugin(net.osmand.plus.skimapsplugin.SkiMapsPlugin) ParkingPositionPlugin(net.osmand.plus.parkingpoint.ParkingPositionPlugin) OsmandDevelopmentPlugin(net.osmand.plus.development.OsmandDevelopmentPlugin) NauticalMapsPlugin(net.osmand.plus.openseamapsplugin.NauticalMapsPlugin) AccessibilityPlugin(net.osmand.access.AccessibilityPlugin) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin)

Aggregations

OsmEditingPlugin (net.osmand.plus.osmedit.OsmEditingPlugin)4 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 AccessibilityPlugin (net.osmand.access.AccessibilityPlugin)1 LatLon (net.osmand.data.LatLon)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 PoiType (net.osmand.osm.PoiType)1 Node (net.osmand.osm.edit.Node)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)1