Search in sources :

Example 1 with OsmNotesPoint

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

the class ShareOsmPointsAsyncTask method saveGpxFile.

private String saveGpxFile(OsmPoint[] points) {
    GPXFile gpx = new GPXFile(Version.getFullVersion(app));
    for (OsmPoint point : points) {
        if (point.getGroup() == Group.POI) {
            OpenstreetmapPoint p = (OpenstreetmapPoint) point;
            WptPt wpt = new WptPt();
            wpt.name = p.getTagsString();
            wpt.lat = p.getLatitude();
            wpt.lon = p.getLongitude();
            wpt.desc = "id: " + p.getId() + " node" + " " + OsmPoint.stringAction.get(p.getAction());
            gpx.addPoint(wpt);
        } else if (point.getGroup() == Group.BUG) {
            OsmNotesPoint p = (OsmNotesPoint) point;
            WptPt wpt = new WptPt();
            wpt.name = p.getText();
            wpt.lat = p.getLatitude();
            wpt.lon = p.getLongitude();
            wpt.desc = "id: " + p.getId() + " note" + " " + OsmPoint.stringAction.get(p.getAction());
            gpx.addPoint(wpt);
        }
    }
    Exception exception = GPXUtilities.writeGpxFile(srcFile, gpx);
    if (exception != null) {
        return exception.getMessage();
    }
    return null;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) GPXFile(net.osmand.GPXUtilities.GPXFile) IOException(java.io.IOException)

Example 2 with OsmNotesPoint

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

the class OsmNotesSettingsItem method writeItemsToJson.

@NonNull
@Override
JSONObject writeItemsToJson(@NonNull JSONObject json) {
    JSONArray jsonArray = new JSONArray();
    if (!items.isEmpty()) {
        try {
            for (OsmNotesPoint point : items) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(TEXT_KEY, point.getText());
                jsonObject.put(LAT_KEY, point.getLatitude());
                jsonObject.put(LON_KEY, point.getLongitude());
                jsonObject.put(AUTHOR_KEY, point.getAuthor());
                jsonObject.put(ACTION_KEY, OsmPoint.stringAction.get(point.getAction()));
                jsonArray.put(jsonObject);
            }
            json.put("items", jsonArray);
        } catch (JSONException e) {
            warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
            SettingsHelper.LOG.error("Failed write to json", e);
        }
    }
    return json;
}
Also used : JSONObject(org.json.JSONObject) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) NonNull(androidx.annotation.NonNull)

Example 3 with OsmNotesPoint

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

the class OsmNotesSettingsItem method readItemsFromJson.

@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
    try {
        if (!json.has("items")) {
            return;
        }
        OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        long minId = osmEditingPlugin != null ? osmEditingPlugin.getDBBug().getMinID() - 1 : -2;
        int idOffset = 0;
        JSONArray jsonArray = json.getJSONArray("items");
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            String text = object.optString(TEXT_KEY);
            double lat = object.getDouble(LAT_KEY);
            double lon = object.getDouble(LON_KEY);
            String author = object.optString(AUTHOR_KEY);
            author = author.isEmpty() ? null : author;
            String action = object.getString(ACTION_KEY);
            OsmNotesPoint point = new OsmNotesPoint();
            point.setId(Math.min(-2, minId - idOffset));
            point.setText(text);
            point.setLatitude(lat);
            point.setLongitude(lon);
            point.setAuthor(author);
            point.setAction(action);
            items.add(point);
            idOffset++;
        }
    } catch (JSONException e) {
        warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
        throw new IllegalArgumentException("Json parse error", e);
    }
}
Also used : JSONObject(org.json.JSONObject) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 4 with OsmNotesPoint

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

the class SettingsHelper method getMyPlacesItems.

private Map<ExportSettingsType, List<?>> getMyPlacesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
    List<FavoriteGroup> favoriteGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.FAVORITES) ? app.getFavoritesHelper().getFavoriteGroups() : Collections.emptyList();
    if (!favoriteGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.FAVORITES, favoriteGroups);
    }
    List<GpxDataItem> gpxItems = settingsTypes == null || settingsTypes.contains(ExportSettingsType.TRACKS) ? app.getGpxDbHelper().getItems() : Collections.emptyList();
    if (!gpxItems.isEmpty() || addEmptyItems) {
        List<File> files = new ArrayList<>();
        for (GpxDataItem gpxItem : gpxItems) {
            File file = gpxItem.getFile();
            if (file.exists() && !file.isDirectory()) {
                files.add(file);
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.TRACKS, files);
        }
    }
    OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        List<OsmNotesPoint> notesPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_NOTES) ? osmEditingPlugin.getDBBug().getOsmbugsPoints() : Collections.emptyList();
        if (!notesPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_NOTES, notesPointList);
        }
        List<OpenstreetmapPoint> editsPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_EDITS) ? osmEditingPlugin.getDBPOI().getOpenstreetmapPoints() : Collections.emptyList();
        if (!editsPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_EDITS, editsPointList);
        }
    }
    AudioVideoNotesPlugin avNotesPlugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
    if (avNotesPlugin != null) {
        List<File> files = new ArrayList<>();
        if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MULTIMEDIA_NOTES)) {
            for (Recording rec : avNotesPlugin.getAllRecordings()) {
                File file = rec.getFile();
                if (file != null && file.exists()) {
                    files.add(file);
                }
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
        }
    }
    List<MapMarker> mapMarkers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ACTIVE_MARKERS) ? app.getMapMarkersHelper().getMapMarkers() : Collections.emptyList();
    if (!mapMarkers.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.map_markers);
        String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(mapMarkers);
        myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
    }
    List<MapMarker> markersHistory = settingsTypes == null || settingsTypes.contains(ExportSettingsType.HISTORY_MARKERS) ? app.getMapMarkersHelper().getMapMarkersHistory() : Collections.emptyList();
    if (!markersHistory.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.shared_string_history);
        String groupId = ExportSettingsType.HISTORY_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(markersHistory);
        myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
    }
    List<HistoryEntry> historyEntries = settingsTypes == null || settingsTypes.contains(ExportSettingsType.SEARCH_HISTORY) ? SearchHistoryHelper.getInstance(app).getHistoryEntries(false) : Collections.emptyList();
    if (!historyEntries.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
    }
    List<MapMarkersGroup> markersGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ITINERARY_GROUPS) ? app.getMapMarkersHelper().getVisibleMapMarkersGroups() : Collections.emptyList();
    if (!markersGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.ITINERARY_GROUPS, markersGroups);
    }
    return myPlacesItems;
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) MapMarker(net.osmand.plus.mapmarkers.MapMarker) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) List(java.util.List) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Recording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.Recording) File(java.io.File)

Example 5 with OsmNotesPoint

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

the class ExportItemsBottomSheet method setupBottomSheetItem.

private void setupBottomSheetItem(BottomSheetItemWithCompoundButton item, Object object) {
    if (object instanceof ApplicationModeBean) {
        ApplicationModeBean modeBean = (ApplicationModeBean) object;
        String profileName = modeBean.userProfileName;
        if (Algorithms.isEmpty(profileName)) {
            ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
            if (appMode != null) {
                profileName = appMode.toHumanString();
            } else {
                profileName = Algorithms.capitalizeFirstLetter(modeBean.stringKey);
            }
        }
        item.setTitle(profileName);
        String routingProfile = "";
        String routingProfileValue = modeBean.routingProfile;
        if (!routingProfileValue.isEmpty()) {
            try {
                routingProfile = getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
                routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
            } catch (IllegalArgumentException e) {
                routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
                LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
            }
        }
        if (!Algorithms.isEmpty(routingProfile)) {
            item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.nav_type_hint), routingProfile));
        } else {
            item.setDescription(getString(R.string.profile_type_osmand_string));
        }
        int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
        ProfileIconColors iconColor = modeBean.iconColor;
        Integer customIconColor = modeBean.customIconColor;
        int actualIconColor;
        if (selectedItems.contains(object)) {
            actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
        } else {
            actualIconColor = ContextCompat.getColor(app, secondaryColorRes);
        }
        int iconRes = profileIconRes != 0 ? profileIconRes : R.drawable.ic_world_globe_dark;
        item.setIcon(uiUtilities.getPaintedIcon(iconRes, actualIconColor));
    } else if (object instanceof QuickAction) {
        QuickAction quickAction = (QuickAction) object;
        item.setTitle(quickAction.getName(app));
        item.setIcon(uiUtilities.getIcon(quickAction.getIconRes(), getItemIconColor(object)));
    } else if (object instanceof PoiUIFilter) {
        PoiUIFilter poiUIFilter = (PoiUIFilter) object;
        item.setTitle(poiUIFilter.getName());
        int iconRes = RenderingIcons.getBigIconResourceId(poiUIFilter.getIconId());
        item.setIcon(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
    } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
        ITileSource tileSource = (ITileSource) object;
        item.setTitle(tileSource.getName());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_map, getItemIconColor(object)));
    } else if (object instanceof File) {
        setupBottomSheetItemForFile(item, (File) object);
    } else if (object instanceof GpxSettingsItem) {
        GpxSettingsItem settingsItem = (GpxSettingsItem) object;
        setupBottomSheetItemForGpx(item, settingsItem.getFile(), settingsItem.getAppearanceInfo());
    } else if (object instanceof FileSettingsItem) {
        FileSettingsItem settingsItem = (FileSettingsItem) object;
        setupBottomSheetItemForFile(item, settingsItem.getFile());
    } else if (object instanceof AvoidRoadInfo) {
        AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) object;
        item.setTitle(avoidRoadInfo.name);
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_alert, getItemIconColor(object)));
    } else if (object instanceof OsmNotesPoint) {
        OsmNotesPoint osmNotesPoint = (OsmNotesPoint) object;
        item.setTitle(osmNotesPoint.getText());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_osm_note_add, getItemIconColor(object)));
    } else if (object instanceof OpenstreetmapPoint) {
        OpenstreetmapPoint openstreetmapPoint = (OpenstreetmapPoint) object;
        item.setTitle(OsmEditingPlugin.getTitle(openstreetmapPoint, app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_info_dark, getItemIconColor(object)));
    } else if (object instanceof FavoriteGroup) {
        FavoriteGroup group = (FavoriteGroup) object;
        item.setTitle(group.getDisplayName(app));
        int color;
        if (selectedItems.contains(object)) {
            color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
        } else {
            color = ContextCompat.getColor(app, secondaryColorRes);
        }
        item.setIcon(uiUtilities.getPaintedIcon(R.drawable.ic_action_folder, color));
        int points = group.getPoints().size();
        String itemsDescr = getString(R.string.shared_string_gpx_points);
        item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, points));
    } else if (object instanceof GlobalSettingsItem) {
        GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
        item.setTitle(globalSettingsItem.getPublicName(app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
    } else if (object instanceof MapMarkersGroup) {
        MapMarkersGroup markersGroup = (MapMarkersGroup) object;
        if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
            item.setTitle(getString(R.string.map_markers));
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
        } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
            item.setTitle(getString(R.string.markers_history));
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
        } else {
            String groupName = markersGroup.getName();
            if (Algorithms.isEmpty(groupName)) {
                if (markersGroup.getType() == ItineraryType.FAVOURITES) {
                    groupName = app.getString(R.string.shared_string_favorites);
                } else if (markersGroup.getType() == ItineraryType.MARKERS) {
                    groupName = app.getString(R.string.map_markers);
                }
            }
            item.setTitle(groupName);
            item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
        }
        int selectedMarkers = markersGroup.getMarkers().size();
        String itemsDescr = getString(R.string.shared_string_items);
        item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers));
    } else if (object instanceof HistoryEntry) {
        HistoryEntry historyEntry = (HistoryEntry) object;
        item.setTitle(historyEntry.getName().getName());
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
    } else if (object instanceof OnlineRoutingEngine) {
        OnlineRoutingEngine onlineRoutingEngine = (OnlineRoutingEngine) object;
        item.setTitle(onlineRoutingEngine.getName(app));
        item.setIcon(uiUtilities.getIcon(R.drawable.ic_world_globe_dark, getItemIconColor(object)));
    }
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) ProfileIconColors(net.osmand.plus.profiles.ProfileIconColors) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) File(java.io.File)

Aggregations

OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)29 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)16 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)13 ArrayList (java.util.ArrayList)7 View (android.view.View)5 File (java.io.File)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 ITileSource (net.osmand.map.ITileSource)4 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)4 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)4 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)4 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)4 QuickAction (net.osmand.plus.quickaction.QuickAction)4 TextView (android.widget.TextView)3 Entity (net.osmand.osm.edit.Entity)3 LinearLayout (android.widget.LinearLayout)2 NonNull (androidx.annotation.NonNull)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2