Search in sources :

Example 1 with AudioVideoNotesPlugin

use of net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin in project Osmand by osmandapp.

the class ExternalApiHelper method processApiRequest.

public Intent processApiRequest(Intent intent) {
    Intent result = new Intent();
    OsmandApplication app = (OsmandApplication) mapActivity.getApplication();
    try {
        Uri uri = intent.getData();
        String cmd = uri.getHost().toLowerCase();
        if (API_CMD_SHOW_GPX.equals(cmd) || API_CMD_NAVIGATE_GPX.equals(cmd)) {
            boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd);
            String path = uri.getQueryParameter(PARAM_PATH);
            GPXFile gpx = null;
            if (path != null) {
                File f = new File(path);
                if (f.exists()) {
                    gpx = GPXUtilities.loadGPXFile(f);
                }
            } else if (intent.getStringExtra(PARAM_DATA) != null) {
                String gpxStr = intent.getStringExtra(PARAM_DATA);
                if (!Algorithms.isEmpty(gpxStr)) {
                    gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes()));
                }
            } else if (uri.getBooleanQueryParameter(PARAM_URI, false)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    LOG.debug("uriString=" + intent.getClipData().getItemAt(0).getUri());
                    Uri gpxUri = intent.getClipData().getItemAt(0).getUri();
                    ParcelFileDescriptor gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
                    if (gpxParcelDescriptor != null) {
                        FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
                        gpx = GPXUtilities.loadGPXFile(new FileInputStream(fileDescriptor));
                    } else {
                        finish = true;
                        resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
                    }
                } else {
                    finish = true;
                    resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
                }
            } else {
                finish = true;
                resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
            }
            if (gpx != null) {
                if (navigate) {
                    boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
                    boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
                    saveAndNavigateGpx(mapActivity, gpx, force, locationPermission);
                } else {
                    app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
                }
                resultCode = Activity.RESULT_OK;
            } else {
                finish = true;
                resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
            }
        } else if (API_CMD_NAVIGATE.equals(cmd)) {
            String profileStr = uri.getQueryParameter(PARAM_PROFILE);
            final ApplicationMode profile = findNavigationProfile(app, profileStr);
            if (profile == null) {
                resultCode = RESULT_CODE_ERROR_INVALID_PROFILE;
            } else {
                String startName = uri.getQueryParameter(PARAM_START_NAME);
                if (Algorithms.isEmpty(startName)) {
                    startName = "";
                }
                String destName = uri.getQueryParameter(PARAM_DEST_NAME);
                if (Algorithms.isEmpty(destName)) {
                    destName = "";
                }
                final LatLon start;
                final PointDescription startDesc;
                String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
                String startLonStr = uri.getQueryParameter(PARAM_START_LON);
                if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
                    double lat = Double.parseDouble(startLatStr);
                    double lon = Double.parseDouble(startLonStr);
                    start = new LatLon(lat, lon);
                    startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
                } else {
                    start = null;
                    startDesc = null;
                }
                String destLatStr = uri.getQueryParameter(PARAM_DEST_LAT);
                String destLonStr = uri.getQueryParameter(PARAM_DEST_LON);
                final LatLon dest;
                if (!Algorithms.isEmpty(destLatStr) && !Algorithms.isEmpty(destLonStr)) {
                    double destLat = Double.parseDouble(destLatStr);
                    double destLon = Double.parseDouble(destLonStr);
                    dest = new LatLon(destLat, destLon);
                } else {
                    dest = null;
                }
                final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
                boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
                final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
                final RoutingHelper routingHelper = app.getRoutingHelper();
                if (routingHelper.isFollowingMode() && !force) {
                    mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (!routingHelper.isFollowingMode()) {
                                startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
                            }
                        }
                    });
                } else {
                    startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
                }
            }
        } else if (API_CMD_NAVIGATE_SEARCH.equals(cmd)) {
            String profileStr = uri.getQueryParameter(PARAM_PROFILE);
            final ApplicationMode profile = findNavigationProfile(app, profileStr);
            final boolean showSearchResults = uri.getBooleanQueryParameter(PARAM_SHOW_SEARCH_RESULTS, false);
            final String searchQuery = uri.getQueryParameter(PARAM_DEST_SEARCH_QUERY);
            if (Algorithms.isEmpty(searchQuery)) {
                resultCode = RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY;
            } else if (profile == null) {
                resultCode = RESULT_CODE_ERROR_INVALID_PROFILE;
            } else {
                String startName = uri.getQueryParameter(PARAM_START_NAME);
                if (Algorithms.isEmpty(startName)) {
                    startName = "";
                }
                final LatLon start;
                final PointDescription startDesc;
                String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
                String startLonStr = uri.getQueryParameter(PARAM_START_LON);
                if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
                    double lat = Double.parseDouble(startLatStr);
                    double lon = Double.parseDouble(startLonStr);
                    start = new LatLon(lat, lon);
                    startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
                } else {
                    start = null;
                    startDesc = null;
                }
                final LatLon searchLocation;
                String searchLatStr = uri.getQueryParameter(PARAM_SEARCH_LAT);
                String searchLonStr = uri.getQueryParameter(PARAM_SEARCH_LON);
                if (!Algorithms.isEmpty(searchLatStr) && !Algorithms.isEmpty(searchLonStr)) {
                    double lat = Double.parseDouble(searchLatStr);
                    double lon = Double.parseDouble(searchLonStr);
                    searchLocation = new LatLon(lat, lon);
                } else {
                    searchLocation = null;
                }
                if (searchLocation == null) {
                    resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED;
                } else {
                    boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
                    final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
                    final RoutingHelper routingHelper = app.getRoutingHelper();
                    if (routingHelper.isFollowingMode() && !force) {
                        mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                if (!routingHelper.isFollowingMode()) {
                                    searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission);
                                }
                            }
                        });
                    } else {
                        searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission);
                    }
                    resultCode = Activity.RESULT_OK;
                }
            }
        } else if (API_CMD_PAUSE_NAVIGATION.equals(cmd)) {
            RoutingHelper routingHelper = mapActivity.getRoutingHelper();
            if (routingHelper.isRouteCalculated() && !routingHelper.isRoutePlanningMode()) {
                routingHelper.setRoutePlanningMode(true);
                routingHelper.setFollowingMode(false);
                routingHelper.setPauseNavigation(true);
                resultCode = Activity.RESULT_OK;
            }
        } else if (API_CMD_RESUME_NAVIGATION.equals(cmd)) {
            RoutingHelper routingHelper = mapActivity.getRoutingHelper();
            if (routingHelper.isRouteCalculated() && routingHelper.isRoutePlanningMode()) {
                routingHelper.setRoutePlanningMode(false);
                routingHelper.setFollowingMode(true);
                resultCode = Activity.RESULT_OK;
            }
        } else if (API_CMD_STOP_NAVIGATION.equals(cmd)) {
            RoutingHelper routingHelper = mapActivity.getRoutingHelper();
            if (routingHelper.isPauseNavigation() || routingHelper.isFollowingMode()) {
                mapActivity.getMapLayers().getMapControlsLayer().stopNavigationWithoutConfirm();
                resultCode = Activity.RESULT_OK;
            }
        } else if (API_CMD_MUTE_NAVIGATION.equals(cmd)) {
            mapActivity.getRoutingHelper().getVoiceRouter().setMute(true);
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_UNMUTE_NAVIGATION.equals(cmd)) {
            mapActivity.getRoutingHelper().getVoiceRouter().setMute(false);
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_RECORD_AUDIO.equals(cmd) || API_CMD_RECORD_VIDEO.equals(cmd) || API_CMD_RECORD_PHOTO.equals(cmd) || API_CMD_STOP_AV_REC.equals(cmd)) {
            AudioVideoNotesPlugin plugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                if (API_CMD_STOP_AV_REC.equals(cmd)) {
                    plugin.stopRecording(mapActivity, false);
                } else {
                    double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
                    double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
                    if (API_CMD_RECORD_AUDIO.equals(cmd)) {
                        plugin.recordAudio(lat, lon, mapActivity);
                    } else if (API_CMD_RECORD_VIDEO.equals(cmd)) {
                        plugin.recordVideo(lat, lon, mapActivity, false);
                    } else if (API_CMD_RECORD_PHOTO.equals(cmd)) {
                        plugin.takePhoto(lat, lon, mapActivity, true, false);
                    }
                }
                resultCode = Activity.RESULT_OK;
            }
        } else if (API_CMD_GET_INFO.equals(cmd)) {
            Location location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (location != null) {
                result.putExtra(PARAM_LAT, location.getLatitude());
                result.putExtra(PARAM_LON, location.getLongitude());
            }
            LatLon mapLocation = mapActivity.getMapLocation();
            if (location != null) {
                result.putExtra(PARAM_MAP_LAT, mapLocation.getLatitude());
                result.putExtra(PARAM_MAP_LON, mapLocation.getLongitude());
            }
            RoutingHelper routingHelper = app.getRoutingHelper();
            if (routingHelper.isRouteCalculated()) {
                LatLon finalLocation = routingHelper.getFinalLocation();
                result.putExtra(PARAM_DESTINATION_LAT, finalLocation.getLatitude());
                result.putExtra(PARAM_DESTINATION_LON, finalLocation.getLongitude());
                int time = routingHelper.getLeftTime();
                long eta = time + System.currentTimeMillis() / 1000;
                result.putExtra(PARAM_ETA, eta);
                result.putExtra(PARAM_TIME_LEFT, time);
                result.putExtra(PARAM_DISTANCE_LEFT, routingHelper.getLeftDistance());
                result.putExtras(getRouteDirectionsInfo(app));
            }
            result.putExtra(PARAM_VERSION, VERSION_CODE);
            finish = true;
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_ADD_FAVORITE.equals(cmd)) {
            String name = uri.getQueryParameter(PARAM_NAME);
            String desc = uri.getQueryParameter(PARAM_DESC);
            String category = uri.getQueryParameter(PARAM_CATEGORY);
            double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
            double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
            String colorTag = uri.getQueryParameter(PARAM_COLOR);
            boolean visible = uri.getBooleanQueryParameter(PARAM_VISIBLE, true);
            if (name == null) {
                name = "";
            }
            if (desc == null) {
                desc = "";
            }
            if (category == null) {
                category = "";
            }
            int color = 0;
            if (!Algorithms.isEmpty(colorTag)) {
                color = ColorDialogs.getColorByTag(colorTag);
                if (color == 0) {
                    LOG.error("Wrong color tag: " + colorTag);
                }
            }
            FavouritePoint fav = new FavouritePoint(lat, lon, name, category);
            fav.setDescription(desc);
            fav.setColor(color);
            fav.setVisible(visible);
            FavouritesHelper helper = app.getFavoritesHelper();
            helper.addFavourite(fav);
            showOnMap(lat, lon, fav, mapActivity.getMapLayers().getFavouritesLayer().getObjectName(fav));
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_ADD_MAP_MARKER.equals(cmd)) {
            double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
            double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
            String name = uri.getQueryParameter(PARAM_NAME);
            PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name != null ? name : "");
            MapMarkersHelper markersHelper = app.getMapMarkersHelper();
            markersHelper.addMapMarker(new LatLon(lat, lon), pd, null);
            MapMarker marker = markersHelper.getFirstMapMarker();
            if (marker != null) {
                showOnMap(lat, lon, marker, mapActivity.getMapLayers().getMapMarkersLayer().getObjectName(marker));
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_SHOW_LOCATION.equals(cmd)) {
            double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
            double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
            showOnMap(lat, lon, null, null);
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_START_GPX_REC.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                plugin.startGPXMonitoring(null);
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_STOP_GPX_REC.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                plugin.stopRecording();
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_SAVE_GPX.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                plugin.saveCurrentTrack();
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_CLEAR_GPX.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                app.getSavingTrackHelper().clearRecordedData(true);
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_EXECUTE_QUICK_ACTION.equals(cmd)) {
            int actionNumber = Integer.parseInt(uri.getQueryParameter(PARAM_QUICK_ACTION_NUMBER));
            List<QuickAction> actionsList = app.getQuickActionRegistry().getFilteredQuickActions();
            if (actionNumber >= 0 && actionNumber < actionsList.size()) {
                QuickActionRegistry.produceAction(actionsList.get(actionNumber)).execute(mapActivity);
                resultCode = Activity.RESULT_OK;
            } else {
                resultCode = RESULT_CODE_ERROR_QUICK_ACTION_NOT_FOUND;
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
        } else if (API_CMD_GET_QUICK_ACTION_INFO.equals(cmd)) {
            int actionNumber = Integer.parseInt(uri.getQueryParameter(PARAM_QUICK_ACTION_NUMBER));
            List<QuickAction> actionsList = app.getQuickActionRegistry().getFilteredQuickActions();
            if (actionNumber >= 0 && actionNumber < actionsList.size()) {
                QuickAction action = actionsList.get(actionNumber);
                Gson gson = new Gson();
                Type type = new TypeToken<HashMap<String, String>>() {
                }.getType();
                result.putExtra(PARAM_QUICK_ACTION_NAME, action.getName(app));
                result.putExtra(PARAM_QUICK_ACTION_TYPE, action.getActionType().getStringId());
                result.putExtra(PARAM_QUICK_ACTION_PARAMS, gson.toJson(action.getParams(), type));
                result.putExtra(PARAM_VERSION, VERSION_CODE);
                resultCode = Activity.RESULT_OK;
            } else {
                resultCode = RESULT_CODE_ERROR_QUICK_ACTION_NOT_FOUND;
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
        } else if (API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS.equals(cmd)) {
            // not implemented yet
            resultCode = RESULT_CODE_ERROR_NOT_IMPLEMENTED;
        }
    } catch (Exception e) {
        LOG.error("Error processApiRequest:", e);
        resultCode = RESULT_CODE_ERROR_UNKNOWN;
    }
    return result;
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) OsmandApplication(net.osmand.plus.OsmandApplication) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) FavouritePoint(net.osmand.data.FavouritePoint) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) MapMarker(net.osmand.plus.mapmarkers.MapMarker) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) Uri(android.net.Uri) OsmandMonitoringPlugin(net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin) List(java.util.List) ArrayList(java.util.ArrayList) Intent(android.content.Intent) RoutingHelper(net.osmand.plus.routing.RoutingHelper) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) FileInputStream(java.io.FileInputStream) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) Type(java.lang.reflect.Type) ObjectType(net.osmand.search.core.ObjectType) TurnType(net.osmand.router.TurnType) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) PointDescription(net.osmand.data.PointDescription) ParcelFileDescriptor(android.os.ParcelFileDescriptor) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) Location(net.osmand.Location)

Example 2 with AudioVideoNotesPlugin

use of net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin 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 3 with AudioVideoNotesPlugin

use of net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin in project Osmand by osmandapp.

the class OsmandAidlApi method registerTakePhotoNoteReceiver.

private void registerTakePhotoNoteReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver takePhotoNoteReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            final AudioVideoNotesPlugin plugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
            if (mapActivity != null && plugin != null) {
                double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
                double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
                plugin.takePhoto(lat, lon, mapActivity, false, true);
            }
        }
    };
    registerReceiver(takePhotoNoteReceiver, mapActivity, AIDL_TAKE_PHOTO_NOTE);
}
Also used : Context(android.content.Context) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MapActivity(net.osmand.plus.activities.MapActivity)

Example 4 with AudioVideoNotesPlugin

use of net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin in project Osmand by osmandapp.

the class OsmandAidlApi method registerStartAudioRecordingReceiver.

private void registerStartAudioRecordingReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver startAudioRecordingReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            final AudioVideoNotesPlugin plugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
            if (mapActivity != null && plugin != null) {
                double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
                double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
                plugin.recordAudio(lat, lon, mapActivity);
            }
        }
    };
    registerReceiver(startAudioRecordingReceiver, mapActivity, AIDL_START_AUDIO_RECORDING);
}
Also used : Context(android.content.Context) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MapActivity(net.osmand.plus.activities.MapActivity)

Example 5 with AudioVideoNotesPlugin

use of net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin in project Osmand by osmandapp.

the class OsmandAidlApi method registerStopRecordingReceiver.

private void registerStopRecordingReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver stopRecordingReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            final AudioVideoNotesPlugin plugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
            if (mapActivity != null && plugin != null) {
                plugin.stopRecording(mapActivity, false);
            }
        }
    };
    registerReceiver(stopRecordingReceiver, mapActivity, AIDL_STOP_RECORDING);
}
Also used : Context(android.content.Context) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

AudioVideoNotesPlugin (net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin)10 Intent (android.content.Intent)5 List (java.util.List)5 MapActivity (net.osmand.plus.activities.MapActivity)5 BroadcastReceiver (android.content.BroadcastReceiver)4 Context (android.content.Context)4 WeakReference (java.lang.ref.WeakReference)4 ArrayList (java.util.ArrayList)4 NonNull (androidx.annotation.NonNull)3 File (java.io.File)3 FragmentActivity (androidx.fragment.app.FragmentActivity)2 MapMarker (net.osmand.plus.mapmarkers.MapMarker)2 OsmandMonitoringPlugin (net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin)2 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)2 ImportListener (net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 FragmentManager (androidx.fragment.app.FragmentManager)1