Search in sources :

Example 16 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingUtils method writeToJson.

public static void writeToJson(@NonNull JSONObject json, @NonNull List<OnlineRoutingEngine> engines) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    Gson gson = new Gson();
    Type type = new TypeToken<HashMap<String, String>>() {
    }.getType();
    for (OnlineRoutingEngine engine : engines) {
        if (Algorithms.isEmpty(engine.getStringKey())) {
            continue;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(TYPE, engine.getTypeName());
        jsonObject.put(PARAMS, gson.toJson(engine.getParams(), type));
        jsonArray.put(jsonObject);
    }
    json.put(ITEMS, jsonArray);
}
Also used : EngineType(net.osmand.plus.onlinerouting.engine.EngineType) Type(java.lang.reflect.Type) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson)

Example 17 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class SettingsHelper method getResourcesItems.

private Map<ExportSettingsType, List<?>> getResourcesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> resourcesItems = new LinkedHashMap<>();
    Map<String, File> externalRenderers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.CUSTOM_RENDER_STYLE) ? app.getRendererRegistry().getExternalRenderers() : Collections.emptyMap();
    if (!externalRenderers.isEmpty() || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.CUSTOM_RENDER_STYLE, new ArrayList<>(externalRenderers.values()));
    }
    List<File> routingProfiles = new ArrayList<>();
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.CUSTOM_ROUTING)) {
        File routingProfilesFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
        if (routingProfilesFolder.exists() && routingProfilesFolder.isDirectory()) {
            File[] fl = routingProfilesFolder.listFiles();
            if (fl != null && fl.length > 0) {
                routingProfiles.addAll(Arrays.asList(fl));
            }
        }
    }
    if (!Algorithms.isEmpty(routingProfiles) || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.CUSTOM_ROUTING, routingProfiles);
    }
    List<OnlineRoutingEngine> onlineRoutingEngines = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ONLINE_ROUTING_ENGINES) ? app.getOnlineRoutingHelper().getOnlyCustomEngines() : Collections.emptyList();
    if (!Algorithms.isEmpty(onlineRoutingEngines) || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines);
    }
    List<ITileSource> iTileSources = new ArrayList<>();
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MAP_SOURCES)) {
        Set<String> tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet();
        for (String name : tileSourceNames) {
            File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + name);
            if (f != null) {
                ITileSource template;
                if (f.getName().endsWith(SQLiteTileSource.EXT)) {
                    template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
                } else {
                    template = TileSourceManager.createTileSourceTemplate(f);
                }
                if (template.getUrlTemplate() != null) {
                    iTileSources.add(template);
                }
            }
        }
    }
    if (!iTileSources.isEmpty() || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.MAP_SOURCES, iTileSources);
    }
    List<LocalIndexInfo> localIndexInfoList;
    List<LocalIndexType> dataTypes = new ArrayList<>();
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.OFFLINE_MAPS)) {
        dataTypes.add(LocalIndexType.MAP_DATA);
        dataTypes.add(LocalIndexType.TILES_DATA);
        dataTypes.add(LocalIndexType.SRTM_DATA);
        dataTypes.add(LocalIndexType.WIKI_DATA);
    }
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.TTS_VOICE)) {
        dataTypes.add(LocalIndexType.TTS_VOICE_DATA);
    }
    if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.VOICE)) {
        dataTypes.add(LocalIndexType.VOICE_DATA);
    }
    localIndexInfoList = !dataTypes.isEmpty() ? getLocalIndexData(dataTypes.toArray(new LocalIndexType[0])) : Collections.emptyList();
    List<File> files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA, LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA);
    if (!files.isEmpty() || addEmptyItems) {
        sortLocalFiles(files);
        resourcesItems.put(ExportSettingsType.OFFLINE_MAPS, files);
    }
    files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
    if (!files.isEmpty() || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.TTS_VOICE, files);
    }
    files = getFilesByType(localIndexInfoList, LocalIndexType.VOICE_DATA);
    if (!files.isEmpty() || addEmptyItems) {
        resourcesItems.put(ExportSettingsType.VOICE, files);
    }
    return resourcesItems;
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) LocalIndexType(net.osmand.plus.download.LocalIndexHelper.LocalIndexType) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ITileSource(net.osmand.map.ITileSource) List(java.util.List) ArrayList(java.util.ArrayList) LocalIndexInfo(net.osmand.plus.download.LocalIndexInfo) File(java.io.File) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Example 18 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class SettingsHelper method prepareSettingsItems.

public List<SettingsItem> prepareSettingsItems(List<?> data, List<SettingsItem> settingsItems, boolean export) {
    List<SettingsItem> result = new ArrayList<>();
    List<QuickAction> quickActions = new ArrayList<>();
    List<PoiUIFilter> poiUIFilters = new ArrayList<>();
    List<ITileSource> tileSourceTemplates = new ArrayList<>();
    List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
    List<ApplicationModeBean> appModeBeans = new ArrayList<>();
    List<FavoriteGroup> favoriteGroups = new ArrayList<>();
    List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
    List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
    List<MapMarkersGroup> markersGroups = new ArrayList<>();
    List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
    List<HistoryEntry> historyEntries = new ArrayList<>();
    List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
    List<MapMarkersGroup> itineraryGroups = new ArrayList<>();
    for (Object object : data) {
        if (object instanceof QuickAction) {
            quickActions.add((QuickAction) object);
        } else if (object instanceof PoiUIFilter) {
            poiUIFilters.add((PoiUIFilter) object);
        } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
            tileSourceTemplates.add((ITileSource) object);
        } else if (object instanceof File) {
            try {
                File file = (File) object;
                if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) {
                    result.add(new GpxSettingsItem(app, file));
                } else {
                    result.add(new FileSettingsItem(app, file));
                }
            } catch (IllegalArgumentException e) {
                LOG.warn("Trying to export unsuported file type", e);
            }
        } else if (object instanceof FileSettingsItem) {
            result.add((FileSettingsItem) object);
        } else if (object instanceof AvoidRoadInfo) {
            avoidRoads.add((AvoidRoadInfo) object);
        } else if (object instanceof ApplicationModeBean) {
            appModeBeans.add((ApplicationModeBean) object);
        } else if (object instanceof OsmNotesPoint) {
            osmNotesPointList.add((OsmNotesPoint) object);
        } else if (object instanceof OpenstreetmapPoint) {
            osmEditsPointList.add((OpenstreetmapPoint) object);
        } else if (object instanceof FavoriteGroup) {
            favoriteGroups.add((FavoriteGroup) object);
        } else if (object instanceof MapMarkersGroup) {
            MapMarkersGroup markersGroup = (MapMarkersGroup) object;
            if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
                markersGroups.add((MapMarkersGroup) object);
            } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
                markersHistoryGroups.add((MapMarkersGroup) object);
            } else {
                itineraryGroups.add((MapMarkersGroup) object);
            }
        } else if (object instanceof HistoryEntry) {
            historyEntries.add((HistoryEntry) object);
        } else if (object instanceof GlobalSettingsItem) {
            result.add((GlobalSettingsItem) object);
        } else if (object instanceof OnlineRoutingEngine) {
            onlineRoutingEngines.add((OnlineRoutingEngine) object);
        }
    }
    if (!quickActions.isEmpty()) {
        QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems);
        result.add(new QuickActionsSettingsItem(app, baseItem, quickActions));
    }
    if (!poiUIFilters.isEmpty()) {
        PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems);
        result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters));
    }
    if (!tileSourceTemplates.isEmpty()) {
        MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems);
        result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates));
    }
    if (!avoidRoads.isEmpty()) {
        AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems);
        result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads));
    }
    if (!appModeBeans.isEmpty()) {
        for (ApplicationModeBean modeBean : appModeBeans) {
            if (export) {
                ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
                if (mode != null) {
                    result.add(new ProfileSettingsItem(app, mode));
                }
            } else {
                result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean));
            }
        }
    }
    if (!osmNotesPointList.isEmpty()) {
        OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems);
        result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList));
    }
    if (!osmEditsPointList.isEmpty()) {
        OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems);
        result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList));
    }
    if (!favoriteGroups.isEmpty()) {
        FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems);
        result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
    }
    if (!markersGroups.isEmpty()) {
        List<MapMarker> mapMarkers = new ArrayList<>();
        for (MapMarkersGroup group : markersGroups) {
            mapMarkers.addAll(group.getMarkers());
        }
        MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
        result.add(new MarkersSettingsItem(app, baseItem, mapMarkers));
    }
    if (!markersHistoryGroups.isEmpty()) {
        List<MapMarker> mapMarkers = new ArrayList<>();
        for (MapMarkersGroup group : markersHistoryGroups) {
            mapMarkers.addAll(group.getMarkers());
        }
        HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
        result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers));
    }
    if (!historyEntries.isEmpty()) {
        SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems);
        result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries));
    }
    if (!onlineRoutingEngines.isEmpty()) {
        OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems);
        result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines));
    }
    if (!itineraryGroups.isEmpty()) {
        ItinerarySettingsItem baseItem = getBaseItem(SettingsItemType.ITINERARY_GROUPS, ItinerarySettingsItem.class, settingsItems);
        result.add(new ItinerarySettingsItem(app, baseItem, itineraryGroups));
    }
    return result;
}
Also used : SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) QuickAction(net.osmand.plus.quickaction.QuickAction) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ArrayList(java.util.ArrayList) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) File(java.io.File) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem)

Example 19 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class SettingsHelper method getSettingsToOperate.

public static Map<ExportSettingsType, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean importComplete, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> settingsToOperate = new EnumMap<>(ExportSettingsType.class);
    List<ApplicationModeBean> profiles = new ArrayList<>();
    List<QuickAction> quickActions = new ArrayList<>();
    List<PoiUIFilter> poiUIFilters = new ArrayList<>();
    List<ITileSource> tileSourceTemplates = new ArrayList<>();
    List<File> routingFilesList = new ArrayList<>();
    List<File> renderFilesList = new ArrayList<>();
    List<File> ttsVoiceFilesList = new ArrayList<>();
    List<File> voiceFilesList = new ArrayList<>();
    List<FileSettingsItem> mapFilesList = new ArrayList<>();
    List<FileSettingsItem> tracksFilesList = new ArrayList<>();
    List<FileSettingsItem> multimediaFilesList = new ArrayList<>();
    List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
    List<GlobalSettingsItem> globalSettingsItems = new ArrayList<>();
    List<OsmNotesPoint> notesPointList = new ArrayList<>();
    List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
    List<FavoriteGroup> favoriteGroups = new ArrayList<>();
    List<MapMarkersGroup> markersGroups = new ArrayList<>();
    List<HistoryEntry> historyEntries = new ArrayList<>();
    List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
    List<MapMarkersGroup> itineraryGroups = new ArrayList<>();
    for (SettingsItem item : settingsItems) {
        switch(item.getType()) {
            case PROFILE:
                profiles.add(((ProfileSettingsItem) item).getModeBean());
                break;
            case FILE:
                FileSettingsItem fileItem = (FileSettingsItem) item;
                if (fileItem.getSubtype() == FileSubtype.RENDERING_STYLE) {
                    renderFilesList.add(fileItem.getFile());
                } else if (fileItem.getSubtype() == FileSubtype.ROUTING_CONFIG) {
                    routingFilesList.add(fileItem.getFile());
                } else if (fileItem.getSubtype() == FileSubtype.MULTIMEDIA_NOTES) {
                    multimediaFilesList.add(fileItem);
                } else if (fileItem.getSubtype() == FileSubtype.GPX) {
                    tracksFilesList.add(fileItem);
                } else if (fileItem.getSubtype().isMap()) {
                    mapFilesList.add(fileItem);
                } else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
                    ttsVoiceFilesList.add(fileItem.getFile());
                } else if (fileItem.getSubtype() == FileSubtype.VOICE) {
                    voiceFilesList.add(fileItem.getFile());
                }
                break;
            case QUICK_ACTIONS:
                QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item;
                if (importComplete) {
                    quickActions.addAll(quickActionsItem.getAppliedItems());
                } else {
                    quickActions.addAll(quickActionsItem.getItems());
                }
                break;
            case POI_UI_FILTERS:
                PoiUiFiltersSettingsItem poiUiFilterItem = (PoiUiFiltersSettingsItem) item;
                if (importComplete) {
                    poiUIFilters.addAll(poiUiFilterItem.getAppliedItems());
                } else {
                    poiUIFilters.addAll(poiUiFilterItem.getItems());
                }
                break;
            case MAP_SOURCES:
                MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item;
                if (importComplete) {
                    tileSourceTemplates.addAll(mapSourcesItem.getAppliedItems());
                } else {
                    tileSourceTemplates.addAll(mapSourcesItem.getItems());
                }
                break;
            case AVOID_ROADS:
                AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item;
                if (importComplete) {
                    avoidRoads.addAll(avoidRoadsItem.getAppliedItems());
                } else {
                    avoidRoads.addAll(avoidRoadsItem.getItems());
                }
                break;
            case GLOBAL:
                globalSettingsItems.add((GlobalSettingsItem) item);
                break;
            case OSM_NOTES:
                OsmNotesSettingsItem osmNotesSettingsItem = (OsmNotesSettingsItem) item;
                if (importComplete) {
                    notesPointList.addAll(osmNotesSettingsItem.getAppliedItems());
                } else {
                    notesPointList.addAll(osmNotesSettingsItem.getItems());
                }
                break;
            case OSM_EDITS:
                OsmEditsSettingsItem osmEditsSettingsItem = (OsmEditsSettingsItem) item;
                if (importComplete) {
                    editsPointList.addAll(osmEditsSettingsItem.getAppliedItems());
                } else {
                    editsPointList.addAll(osmEditsSettingsItem.getItems());
                }
                break;
            case FAVOURITES:
                FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
                favoriteGroups.addAll(favoritesSettingsItem.getItems());
                break;
            case ACTIVE_MARKERS:
                MarkersSettingsItem markersSettingsItem = (MarkersSettingsItem) item;
                markersGroups.add(markersSettingsItem.getMarkersGroup());
                break;
            case HISTORY_MARKERS:
                HistoryMarkersSettingsItem historyMarkersSettingsItem = (HistoryMarkersSettingsItem) item;
                markersGroups.add(historyMarkersSettingsItem.getMarkersGroup());
                break;
            case SEARCH_HISTORY:
                SearchHistorySettingsItem searchHistorySettingsItem = (SearchHistorySettingsItem) item;
                historyEntries.addAll(searchHistorySettingsItem.getItems());
                break;
            case GPX:
                tracksFilesList.add((GpxSettingsItem) item);
                break;
            case ONLINE_ROUTING_ENGINES:
                OnlineRoutingSettingsItem onlineRoutingSettingsItem = (OnlineRoutingSettingsItem) item;
                onlineRoutingEngines.addAll(onlineRoutingSettingsItem.getItems());
                break;
            case ITINERARY_GROUPS:
                ItinerarySettingsItem itinerarySettingsItem = (ItinerarySettingsItem) item;
                itineraryGroups.addAll(itinerarySettingsItem.getItems());
                break;
            default:
                break;
        }
    }
    for (SettingsItem item : settingsItems) {
        switch(item.getType()) {
            case PROFILE:
                if (!profiles.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.PROFILE, profiles);
                }
                break;
            case FILE:
                FileSettingsItem fileItem = (FileSettingsItem) item;
                if (fileItem.getSubtype() == FileSubtype.RENDERING_STYLE) {
                    if (!renderFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.CUSTOM_RENDER_STYLE, renderFilesList);
                    }
                } else if (fileItem.getSubtype() == FileSubtype.ROUTING_CONFIG) {
                    if (!routingFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.CUSTOM_ROUTING, routingFilesList);
                    }
                } else if (fileItem.getSubtype() == FileSubtype.MULTIMEDIA_NOTES) {
                    if (!multimediaFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.MULTIMEDIA_NOTES, multimediaFilesList);
                    }
                } else if (fileItem.getSubtype() == FileSubtype.GPX) {
                    if (!tracksFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.TRACKS, tracksFilesList);
                    }
                } else if (fileItem.getSubtype().isMap()) {
                    if (!mapFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList);
                    }
                } else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
                    if (!ttsVoiceFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.TTS_VOICE, ttsVoiceFilesList);
                    }
                } else if (fileItem.getSubtype() == FileSubtype.VOICE) {
                    if (!voiceFilesList.isEmpty() || addEmptyItems) {
                        settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList);
                    }
                }
                break;
            case QUICK_ACTIONS:
                if (!quickActions.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.QUICK_ACTIONS, quickActions);
                }
                break;
            case POI_UI_FILTERS:
                if (!poiUIFilters.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.POI_TYPES, poiUIFilters);
                }
                break;
            case MAP_SOURCES:
                if (!tileSourceTemplates.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.MAP_SOURCES, tileSourceTemplates);
                }
                break;
            case AVOID_ROADS:
                if (!avoidRoads.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.AVOID_ROADS, avoidRoads);
                }
                break;
            case GLOBAL:
                if (!globalSettingsItems.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.GLOBAL, globalSettingsItems);
                }
                break;
            case OSM_NOTES:
                if (!notesPointList.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.OSM_NOTES, notesPointList);
                }
                break;
            case OSM_EDITS:
                if (!editsPointList.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList);
                }
                break;
            case FAVOURITES:
                if (!favoriteGroups.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.FAVORITES, favoriteGroups);
                }
                break;
            case ACTIVE_MARKERS:
            case HISTORY_MARKERS:
                if (!markersGroups.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.ACTIVE_MARKERS, markersGroups);
                }
                break;
            case SEARCH_HISTORY:
                if (!historyEntries.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
                }
                break;
            case GPX:
                if (!tracksFilesList.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.TRACKS, tracksFilesList);
                }
                break;
            case ONLINE_ROUTING_ENGINES:
                if (!onlineRoutingEngines.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines);
                }
                break;
            case ITINERARY_GROUPS:
                if (!itineraryGroups.isEmpty() || addEmptyItems) {
                    settingsToOperate.put(ExportSettingsType.ITINERARY_GROUPS, itineraryGroups);
                }
                break;
            default:
                break;
        }
    }
    return settingsToOperate;
}
Also used : SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) QuickAction(net.osmand.plus.quickaction.QuickAction) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) List(java.util.List) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) EnumMap(java.util.EnumMap) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) File(java.io.File) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem)

Example 20 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class DuplicatesSettingsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    Object currentItem = items.get(position);
    if (holder instanceof HeaderViewHolder) {
        HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
        headerHolder.title.setText((String) currentItem);
        headerHolder.subTitle.setText(String.format(app.getString(R.string.listed_exist), currentItem));
        headerHolder.divider.setVisibility(View.VISIBLE);
    } else if (holder instanceof ItemViewHolder) {
        ItemViewHolder itemHolder = (ItemViewHolder) holder;
        itemHolder.subTitle.setVisibility(View.GONE);
        if (currentItem instanceof ApplicationModeBean) {
            ApplicationModeBean modeBean = (ApplicationModeBean) currentItem;
            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);
                }
            }
            itemHolder.title.setText(profileName);
            String routingProfile = "";
            String routingProfileValue = modeBean.routingProfile;
            if (!routingProfileValue.isEmpty()) {
                try {
                    routingProfile = app.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)) {
                itemHolder.subTitle.setVisibility(View.GONE);
            } else {
                itemHolder.subTitle.setText(String.format(app.getString(R.string.ltr_or_rtl_combine_via_colon), app.getString(R.string.nav_type_hint), routingProfile));
                itemHolder.subTitle.setVisibility(View.VISIBLE);
            }
            int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
            ProfileIconColors iconColor = modeBean.iconColor;
            Integer customIconColor = modeBean.customIconColor;
            int actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
            itemHolder.icon.setImageDrawable(uiUtilities.getPaintedIcon(profileIconRes, actualIconColor));
        } else if (currentItem instanceof QuickAction) {
            QuickAction action = (QuickAction) currentItem;
            itemHolder.title.setText(action.getName(app));
            itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), activeColorRes));
        } else if (currentItem instanceof PoiUIFilter) {
            PoiUIFilter filter = (PoiUIFilter) currentItem;
            itemHolder.title.setText(filter.getName());
            int iconRes = RenderingIcons.getBigIconResourceId(filter.getIconId());
            itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
        } else if (currentItem instanceof ITileSource) {
            itemHolder.title.setText(((ITileSource) currentItem).getName());
            itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
        } else if (currentItem instanceof File) {
            File file = (File) currentItem;
            FileSubtype fileSubtype = FileSubtype.getSubtypeByPath(app, file.getPath());
            itemHolder.title.setText(file.getName());
            if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
                itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, activeColorRes));
            } else if (file.getAbsolutePath().contains(IndexConstants.ROUTING_PROFILES_DIR)) {
                itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
            } else if (file.getAbsolutePath().contains(IndexConstants.GPX_INDEX_DIR)) {
                itemHolder.title.setText(GpxUiHelper.getGpxTitle(file.getName()));
                itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
            } else if (file.getAbsolutePath().contains(IndexConstants.AV_INDEX_DIR)) {
                int iconId = AudioVideoNotesPlugin.getIconIdForRecordingFile(file);
                if (iconId == -1) {
                    iconId = R.drawable.ic_action_photo_dark;
                }
                itemHolder.title.setText(new Recording(file).getName(app, true));
                itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconId, activeColorRes));
            } else if (fileSubtype.isMap() || fileSubtype == FileSubtype.TTS_VOICE || fileSubtype == FileSubtype.VOICE) {
                itemHolder.title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
                itemHolder.icon.setImageDrawable(uiUtilities.getIcon(fileSubtype.getIconId(), activeColorRes));
            }
        } else if (currentItem instanceof AvoidRoadInfo) {
            itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
            itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, activeColorRes));
        } else if (currentItem instanceof FavoriteGroup) {
            itemHolder.title.setText(((FavoriteGroup) currentItem).getDisplayName(app));
            itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
        } else if (currentItem instanceof MapMarker) {
            MapMarker mapMarker = (MapMarker) currentItem;
            itemHolder.title.setText(mapMarker.getName(app));
            itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
        } else if (currentItem instanceof HistoryEntry) {
            itemHolder.title.setText(((HistoryEntry) currentItem).getName().getName());
        } else if (currentItem instanceof OnlineRoutingEngine) {
            itemHolder.title.setText(((OnlineRoutingEngine) currentItem).getName(app));
            itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_world_globe_dark, activeColorRes));
        } else if (currentItem instanceof MapMarkersGroup) {
            MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
            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);
                }
            }
            itemHolder.title.setText(groupName);
            itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
        }
        itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
    }
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) ProfileIconColors(net.osmand.plus.profiles.ProfileIconColors) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) AvoidRoadInfo(net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ITileSource(net.osmand.map.ITileSource) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) FileSubtype(net.osmand.plus.settings.backend.backup.items.FileSettingsItem.FileSubtype) Recording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.Recording) File(java.io.File)

Aggregations

OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)22 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ITileSource (net.osmand.map.ITileSource)6 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)4 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)4 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)4 NonNull (androidx.annotation.NonNull)3 MapMarker (net.osmand.plus.mapmarkers.MapMarker)3 OnlineRoutingHelper (net.osmand.plus.onlinerouting.OnlineRoutingHelper)3 SQLiteTileSource (net.osmand.plus.resources.SQLiteTileSource)3 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)3 GlobalSettingsItem (net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem)3