Search in sources :

Example 1 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker 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 MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkersActiveAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, final int pos) {
    UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
    MapMarker marker = markers.get(pos);
    ImageView markerImageViewToUpdate;
    int drawableResToUpdate;
    int markerColor = MapMarker.getColorId(marker.colorIndex);
    int actionIconColor = night ? R.color.icon_color_primary_dark : R.color.icon_color_primary_light;
    LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
    final boolean displayedInWidget = pos < mapActivity.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    if (showDirectionEnabled && displayedInWidget) {
        holder.iconDirection.setVisibility(View.GONE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor));
        holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
        holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.text_color_primary_dark : R.color.color_white));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
        holder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, R.drawable.marker_circle_background_on_map_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, R.color.color_white));
        holder.iconReorder.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_item_move, R.color.icon_color_default_light));
        holder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
        drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
        markerImageViewToUpdate = holder.icon;
    } else {
        holder.iconDirection.setVisibility(View.VISIBLE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag, markerColor));
        holder.mainLayout.setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, night));
        holder.title.setTextColor(ColorUtilities.getPrimaryTextColor(mapActivity, night));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.app_bar_color_dark : R.color.divider_color_light));
        holder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, actionIconColor));
        holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_item_move));
        holder.description.setTextColor(ColorUtilities.getDefaultIconColor(mapActivity, night));
        drawableResToUpdate = R.drawable.ic_direction_arrow;
        markerImageViewToUpdate = holder.iconDirection;
    }
    if (pos == getItemCount() - 1) {
        holder.bottomShadow.setVisibility(View.VISIBLE);
        holder.divider.setVisibility(View.GONE);
    } else {
        holder.bottomShadow.setVisibility(View.GONE);
        holder.divider.setVisibility(View.VISIBLE);
    }
    holder.point.setVisibility(View.VISIBLE);
    holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                listener.onDragStarted(holder);
            }
            return false;
        }
    });
    holder.title.setText(marker.getName(mapActivity));
    String descr;
    if ((descr = marker.groupName) != null) {
        if (descr.isEmpty()) {
            descr = mapActivity.getString(R.string.shared_string_favorites);
        }
    } else {
        descr = OsmAndFormatter.getFormattedDate(mapActivity, marker.creationDate);
    }
    if (marker.wptPt != null && !Algorithms.isEmpty(marker.wptPt.category)) {
        descr = marker.wptPt.category + ", " + descr;
    }
    holder.description.setText(descr);
    holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int position = holder.getAdapterPosition();
            if (position < 0) {
                return;
            }
            final MapMarker marker = markers.get(position);
            mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
            changeMarkers();
            notifyDataSetChanged();
            snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
                    changeMarkers();
                    notifyDataSetChanged();
                }
            });
            UiUtilities.setupSnackbar(snackbar, night);
            snackbar.show();
        }
    });
    updateLocationViewCache.arrowResId = drawableResToUpdate;
    updateLocationViewCache.arrowColor = showDirectionEnabled && displayedInWidget ? markerColor : 0;
    uiUtilities.updateLocationView(updateLocationViewCache, markerImageViewToUpdate, holder.distance, markerLatLon);
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MotionEvent(android.view.MotionEvent)

Example 3 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method createDisplayGroups.

private void createDisplayGroups() {
    items = new ArrayList<>();
    MapMarkersHelper helper = app.getMapMarkersHelper();
    helper.updateGroups();
    List<MapMarkersGroup> groups = new ArrayList<>(helper.getVisibleMapMarkersGroups());
    groups.addAll(helper.getGroupsForDisplayedGpx());
    groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
    // evaluate time constants
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    long currentTimeMillis = System.currentTimeMillis();
    Calendar currentDateCalendar = Calendar.getInstance();
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    // evaluate today, yesterday, last 7 days
    String today = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -1);
    String yesterday = dateFormat.format(currentDateCalendar.getTime());
    currentDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
    currentDateCalendar.set(Calendar.MINUTE, 0);
    currentDateCalendar.add(Calendar.DAY_OF_YEAR, -6);
    long last7Days = currentDateCalendar.getTimeInMillis();
    // evaluate this year & last 3 months
    currentDateCalendar.setTimeInMillis(currentTimeMillis);
    String thisYear = dateFormat.format(currentDateCalendar.getTime()).substring(0, 5);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus1 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus2 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    currentDateCalendar.add(Calendar.MONTH, -1);
    String monthMinus3 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
    Calendar markerCalendar = Calendar.getInstance();
    for (int i = 0; i < groups.size(); i++) {
        MapMarkersGroup group = groups.get(i);
        String markerGroupName = group.getName();
        if (markerGroupName == null) {
            int previousGroupDateId = 0;
            List<MapMarker> groupMarkers = group.getActiveMarkers();
            for (int j = 0; j < groupMarkers.size(); j++) {
                MapMarker marker = groupMarkers.get(j);
                String markerDate = dateFormat.format(new Date(marker.creationDate));
                int currentGroupDateId;
                MarkerGroupItem currentGroupItem = null;
                if (marker.creationDate >= currentTimeMillis || (today.equals(markerDate))) {
                    currentGroupDateId = -1;
                    currentGroupItem = MarkerGroupItem.TODAY_HEADER;
                } else if (yesterday.equals(markerDate)) {
                    currentGroupDateId = -2;
                    currentGroupItem = MarkerGroupItem.YESTERDAY_HEADER;
                } else if (marker.creationDate >= last7Days) {
                    currentGroupDateId = -3;
                    currentGroupItem = MarkerGroupItem.LAST_SEVEN_DAYS_HEADER;
                } else if (markerDate.startsWith(monthMinus1)) {
                    currentGroupDateId = -5;
                } else if (markerDate.startsWith(monthMinus2)) {
                    currentGroupDateId = -6;
                } else if (markerDate.startsWith(monthMinus3)) {
                    currentGroupDateId = -7;
                } else if (markerDate.startsWith(thisYear)) {
                    currentGroupItem = MarkerGroupItem.THIS_YEAR_HEADER;
                    currentGroupDateId = -4;
                } else {
                    markerCalendar.setTimeInMillis(marker.creationDate);
                    currentGroupDateId = markerCalendar.get(Calendar.YEAR);
                }
                if (previousGroupDateId != currentGroupDateId) {
                    if (currentGroupItem != null) {
                        items.add(currentGroupItem);
                    } else if (currentGroupDateId < 0) {
                        SimpleDateFormat monthdateFormat = new SimpleDateFormat("LLLL", Locale.getDefault());
                        String monthStr = monthdateFormat.format(new Date(marker.creationDate));
                        if (monthStr.length() > 1) {
                            monthStr = Algorithms.capitalizeFirstLetter(monthStr);
                        }
                        items.add(new MarkerGroupItem(monthStr));
                    } else {
                        items.add(new MarkerGroupItem(currentGroupDateId + ""));
                    }
                    previousGroupDateId = currentGroupDateId;
                }
                items.add(marker);
            }
        } else {
            items.add(new GroupHeader(group));
            if (!group.isDisabled()) {
                if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
                    CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(group);
                    items.add(categoriesSubHeader);
                }
                TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper();
                if (travelHelper.isAnyTravelBookPresent()) {
                    List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
                    for (TravelArticle art : savedArticles) {
                        String gpxName = travelHelper.getGPXName(art);
                        File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
                        if (path.getAbsolutePath().equals(group.getGpxPath(app))) {
                            group.setWikivoyageArticle(art);
                        }
                    }
                }
            }
            if (Algorithms.isEmpty(group.getWptCategories())) {
                helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath(app)).getPointsByCategories().keySet());
            }
            populateAdapterWithGroupMarkers(group, getItemCount());
        }
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) Calendar(java.util.Calendar) GroupHeader(net.osmand.plus.mapmarkers.GroupHeader) ArrayList(java.util.ArrayList) Date(java.util.Date) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) SimpleDateFormat(java.text.SimpleDateFormat) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper)

Example 4 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class AddPointBottomSheetDialog method getAdapterOnClickListener.

private OnClickListener getAdapterOnClickListener(final List<Object> items) {
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) v.getTag();
            int position = viewHolder != null ? viewHolder.getAdapterPosition() : RecyclerView.NO_POSITION;
            if (mapActivity == null || position == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = items.get(position);
            if (item.equals(FAVORITES)) {
                openFavoritesDialog();
            } else if (item.equals(MARKERS)) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker(-1, pointType);
                dismiss();
            } else if (item instanceof MapMarker) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker((MapMarker) item, pointType);
                dismiss();
            } else {
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                Pair<LatLon, PointDescription> pair = getLocationAndDescrFromItem(item);
                LatLon ll = pair.first;
                PointDescription name = pair.second;
                if (ll == null) {
                    if (item instanceof PointType) {
                        AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item);
                    } else {
                        dismiss();
                    }
                } else {
                    FavouritesHelper favorites = requiredMyApplication().getFavoritesHelper();
                    switch(pointType) {
                        case START:
                            targetPointsHelper.setStartPoint(ll, true, name);
                            break;
                        case TARGET:
                            targetPointsHelper.navigateToPoint(ll, true, -1, name);
                            break;
                        case INTERMEDIATE:
                            targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), name);
                            break;
                        case HOME:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null);
                            break;
                        case WORK:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.WORK, null);
                            break;
                        case PARKING:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.PARKING, null);
                            break;
                    }
                    dismiss();
                }
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) PointType(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType) RecyclerView(androidx.recyclerview.widget.RecyclerView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Example 5 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class ItinerarySettingsItem method getReader.

@Nullable
@Override
public SettingsItemReader<ItinerarySettingsItem> getReader() {
    return new SettingsItemReader<ItinerarySettingsItem>(this) {

        @Override
        public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IllegalArgumentException {
            List<ItineraryGroupInfo> groupInfos = new ArrayList<>();
            GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream, dataHelper.getGPXExtensionsReader(groupInfos));
            if (gpxFile.error != null) {
                warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
                SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
            } else {
                Map<String, MapMarker> markers = new LinkedHashMap<>();
                Map<String, MapMarkersGroup> groups = new LinkedHashMap<>();
                dataHelper.collectMarkersGroups(gpxFile, groups, groupInfos, markers);
                items.addAll(groups.values());
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ItineraryGroupInfo(net.osmand.plus.mapmarkers.ItineraryDataHelper.ItineraryGroupInfo) LinkedHashMap(java.util.LinkedHashMap) SettingsItemReader(net.osmand.plus.settings.backend.backup.SettingsItemReader) NonNull(androidx.annotation.NonNull) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) GPXFile(net.osmand.GPXUtilities.GPXFile) Nullable(androidx.annotation.Nullable)

Aggregations

MapMarker (net.osmand.plus.mapmarkers.MapMarker)53 LatLon (net.osmand.data.LatLon)21 ArrayList (java.util.ArrayList)15 OsmandApplication (net.osmand.plus.OsmandApplication)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)12 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)10 GPXFile (net.osmand.GPXUtilities.GPXFile)9 PointDescription (net.osmand.data.PointDescription)9 File (java.io.File)8 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)8 View (android.view.View)7 FavouritePoint (net.osmand.data.FavouritePoint)7 MapActivity (net.osmand.plus.activities.MapActivity)7 Paint (android.graphics.Paint)6 NonNull (androidx.annotation.NonNull)6 Nullable (androidx.annotation.Nullable)6 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 WptPt (net.osmand.GPXUtilities.WptPt)6 Location (net.osmand.Location)6 Amenity (net.osmand.data.Amenity)6