From 399c6c4f38e16b24dd50dbbf9da80a4ad192dc40 Mon Sep 17 00:00:00 2001 From: fsbugreporter Date: Mon, 8 Jul 2019 11:48:28 +0200 Subject: [PATCH] introduction of option to igore coordinates in updateMapMarker and removeMapMarker AIDL functions; added new AIDL function removeAllMarkers --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 17 ++++++- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 51 +++++++++++++------ .../net/osmand/aidl/OsmandAidlService.java | 15 +++++- .../aidl/mapmarker/RemoveMapMarkerParams.java | 13 +++++ .../aidl/mapmarker/UpdateMapMarkerParams.java | 14 +++++ 5 files changed, 90 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index e884cb434f..7cacb137dd 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -105,16 +105,23 @@ interface IOsmAndAidlInterface { boolean addMapMarker(in AddMapMarkerParams params); /** - * Add map marker at given location. + * Remove map marker. + * + * If ignoreCoordinates is false the marker is only removed if lat/lon match the currently set values of the marker. + * If ignoreCoordinates is true the marker is removed if the name matches, the values of lat/lon are ignored. * * @param lat (double) - latitude. * @param lon (double) - longitude. * @param name (String)- name of marker. + * @param ignoreCoordinates (boolean) - flag to determine whether lat/lon shall be ignored */ boolean removeMapMarker(in RemoveMapMarkerParams params); /** - * Update map marker at given location with name. + * Update map marker. + * + * If ignoreCoordinates is false the marker gets updated only if latPrev/lonPrev match the currently set values of the marker. + * If ignoreCoordinates is true the marker gets updated if the name matches, the values of latPrev/lonPrev are ignored. * * @param latPrev (double) - latitude (current marker). * @param lonPrev (double) - longitude (current marker). @@ -122,6 +129,7 @@ interface IOsmAndAidlInterface { * @param latNew (double) - latitude (new marker). * @param lonNew (double) - longitude (new marker). * @param nameNew (String) - name (new marker). + * @param ignoreCoordinates (boolean) - flag to determine whether latPrev/lonPrev shall be ignored */ boolean updateMapMarker(in UpdateMapMarkerParams params); @@ -816,4 +824,9 @@ interface IOsmAndAidlInterface { * @params callback (IOsmAndAidlCallback) - callback to notify user on voice message */ long registerForVoiceRouterMessages(in ANavigationVoiceRouterMessageParams params, IOsmAndAidlCallback callback); + + /** + * Remove all map markers. + */ + boolean removeAllMapMarkers(); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 20e694c179..331566f132 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1037,16 +1037,18 @@ public class OsmandAidlApi { } } - boolean removeMapMarker(AMapMarker marker) { + boolean removeMapMarker(AMapMarker marker, boolean ignoreCoordinates) { if (marker != null) { LatLon latLon = new LatLon(marker.getLatLon().getLatitude(), marker.getLatLon().getLongitude()); MapMarkersHelper markersHelper = app.getMapMarkersHelper(); List mapMarkers = markersHelper.getMapMarkers(); for (MapMarker m : mapMarkers) { - if (m.getOnlyName().equals(marker.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { - markersHelper.moveMapMarkerToHistory(m); - refreshMap(); - return true; + if (m.getOnlyName().equals(marker.getName())) { + if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { + markersHelper.moveMapMarkerToHistory(m); + refreshMap(); + return true; + } } } return false; @@ -1055,23 +1057,40 @@ public class OsmandAidlApi { } } - boolean updateMapMarker(AMapMarker markerPrev, AMapMarker markerNew) { + boolean removeAllMapMarkers() { + boolean refreshNeeded = false; + MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + List mapMarkers = markersHelper.getMapMarkers(); + for (MapMarker m : mapMarkers) { + markersHelper.moveMapMarkerToHistory(m); + refreshNeeded = true; + } + if (refreshNeeded) { + refreshMap(); + } + return true; + } + + + boolean updateMapMarker(AMapMarker markerPrev, AMapMarker markerNew, boolean ignoreCoordinates) { if (markerPrev != null && markerNew != null) { LatLon latLon = new LatLon(markerPrev.getLatLon().getLatitude(), markerPrev.getLatLon().getLongitude()); LatLon latLonNew = new LatLon(markerNew.getLatLon().getLatitude(), markerNew.getLatLon().getLongitude()); MapMarkersHelper markersHelper = app.getMapMarkersHelper(); List mapMarkers = markersHelper.getMapMarkers(); for (MapMarker m : mapMarkers) { - if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { - PointDescription pd = new PointDescription( - PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); - MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); - marker.id = m.id; - marker.creationDate = m.creationDate; - marker.visitedDate = m.visitedDate; - markersHelper.moveMapMarker(marker, latLonNew); - refreshMap(); - return true; + if (m.getOnlyName().equals(markerPrev.getName())) { + if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { + PointDescription pd = new PointDescription( + PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); + MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index); + marker.id = m.id; + marker.creationDate = m.creationDate; + marker.visitedDate = m.visitedDate; + markersHelper.moveMapMarker(marker, latLonNew); + refreshMap(); + return true; + } } } return false; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 262a064a22..4cccbbbbca 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -282,7 +282,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean removeMapMarker(RemoveMapMarkerParams params) { try { OsmandAidlApi api = getApi("removeMapMarker"); - return params != null && api != null && api.removeMapMarker(params.getMarker()); + return params != null && api != null && api.removeMapMarker(params.getMarker(), params.getIgnoreCoordinates()); } catch (Exception e) { handleException(e); return false; @@ -293,7 +293,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean updateMapMarker(UpdateMapMarkerParams params) { try { OsmandAidlApi api = getApi("updateMapMarker"); - return params != null && api != null && api.updateMapMarker(params.getMarkerPrev(), params.getMarkerNew()); + return params != null && api != null && api.updateMapMarker(params.getMarkerPrev(), params.getMarkerNew(), params.getIgnoreCoordinates()); } catch (Exception e) { handleException(e); return false; @@ -1163,6 +1163,17 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { return UNKNOWN_API_ERROR; } } + + @Override + public boolean removeAllMapMarkers() { + try { + OsmandAidlApi api = getApi("removeAllMapMarkers"); + return api != null && api.removeAllMapMarkers(); + } catch (Exception e) { + handleException(e); + return false; + } + } }; public static class AidlCallbackParams { diff --git a/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkerParams.java b/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkerParams.java index 08f489922c..6d1fb3d2aa 100644 --- a/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkerParams.java +++ b/OsmAnd/src/net/osmand/aidl/mapmarker/RemoveMapMarkerParams.java @@ -6,9 +6,16 @@ import android.os.Parcelable; public class RemoveMapMarkerParams implements Parcelable { private AMapMarker marker; + private boolean ignoreCoordinates; public RemoveMapMarkerParams(AMapMarker marker) { this.marker = marker; + this.ignoreCoordinates = false; + } + + public RemoveMapMarkerParams(AMapMarker marker, boolean ignoreCoordinates) { + this.marker = marker; + this.ignoreCoordinates = ignoreCoordinates; } public RemoveMapMarkerParams(Parcel in) { @@ -30,12 +37,18 @@ public class RemoveMapMarkerParams implements Parcelable { return marker; } + public boolean getIgnoreCoordinates() { + return ignoreCoordinates; + } + public void writeToParcel(Parcel out, int flags) { out.writeParcelable(marker, flags); + out.writeInt(ignoreCoordinates ? 1 : 0); } private void readFromParcel(Parcel in) { marker = in.readParcelable(AMapMarker.class.getClassLoader()); + ignoreCoordinates = in.readInt() != 0; } public int describeContents() { diff --git a/OsmAnd/src/net/osmand/aidl/mapmarker/UpdateMapMarkerParams.java b/OsmAnd/src/net/osmand/aidl/mapmarker/UpdateMapMarkerParams.java index d03bc0d7f6..26116f3830 100644 --- a/OsmAnd/src/net/osmand/aidl/mapmarker/UpdateMapMarkerParams.java +++ b/OsmAnd/src/net/osmand/aidl/mapmarker/UpdateMapMarkerParams.java @@ -7,10 +7,18 @@ public class UpdateMapMarkerParams implements Parcelable { private AMapMarker markerPrev; private AMapMarker markerNew; + private boolean ignoreCoordinates; public UpdateMapMarkerParams(AMapMarker markerPrev, AMapMarker markerNew) { this.markerPrev = markerPrev; this.markerNew = markerNew; + this.ignoreCoordinates = false; + } + + public UpdateMapMarkerParams(AMapMarker markerPrev, AMapMarker markerNew, boolean ignoreCoordinates) { + this.markerPrev = markerPrev; + this.markerNew = markerNew; + this.ignoreCoordinates = ignoreCoordinates; } public UpdateMapMarkerParams(Parcel in) { @@ -36,14 +44,20 @@ public class UpdateMapMarkerParams implements Parcelable { return markerNew; } + public boolean getIgnoreCoordinates() { + return ignoreCoordinates; + } + public void writeToParcel(Parcel out, int flags) { out.writeParcelable(markerPrev, flags); out.writeParcelable(markerNew, flags); + out.writeInt(ignoreCoordinates ? 1 : 0); } private void readFromParcel(Parcel in) { markerPrev = in.readParcelable(AMapMarker.class.getClassLoader()); markerNew = in.readParcelable(AMapMarker.class.getClassLoader()); + ignoreCoordinates = in.readInt() != 0; } public int describeContents() {