From fbfdadfc87a3442067be3dadc3a7521102584eaa Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Tue, 10 Jul 2018 16:52:17 +0300 Subject: [PATCH] Add method for opening OsmAnd at given AMapPoint to the AIDL-API --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 4 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 27 ++++++++-- .../net/osmand/aidl/OsmandAidlService.java | 18 +++++-- .../maplayer/ShowLayerPointOnMapParams.aidl | 3 ++ .../maplayer/ShowLayerPointOnMapParams.java | 51 +++++++++++++++++++ 5 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 64410a3f9f..ea79b255bf 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -51,6 +51,8 @@ import net.osmand.aidl.note.StopRecordingParams; import net.osmand.aidl.gpx.RemoveGpxParams; +import net.osmand.aidl.maplayer.ShowLayerPointOnMapParams; + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -101,4 +103,6 @@ interface IOsmAndAidlInterface { boolean navigateGpx(in NavigateGpxParams params); boolean removeGpx(in RemoveGpxParams params); + + boolean showLayerPointOnMap(in ShowLayerPointOnMapParams params); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 43769d0ac4..3e6fbe81d2 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -9,8 +9,8 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.ParcelFileDescriptor; -import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; +import android.text.TextUtils; import android.view.View; import net.osmand.IndexConstants; @@ -155,10 +155,6 @@ public class OsmandAidlApi { receivers = new TreeMap(); } - public OsmandMapLayer getMapLayer(@NonNull String id) { - return mapLayers.get(id); - } - private void registerRefreshMapReceiver(final MapActivity mapActivity) { BroadcastReceiver refreshMapReceiver = new BroadcastReceiver() { @Override @@ -835,6 +831,27 @@ public class OsmandAidlApi { } } + boolean showLayerPointOnMap(String layerId, String pointId) { + if (!TextUtils.isEmpty(layerId) && !TextUtils.isEmpty(pointId)) { + AMapLayer layer = layers.get(layerId); + if (layer != null) { + AMapPoint point = layer.getPoint(pointId); + if (point != null) { + app.getSettings().setMapLocationToShow( + point.getLocation().getLatitude(), + point.getLocation().getLongitude(), + 15, + new PointDescription(PointDescription.POINT_TYPE_MARKER, point.getFullName()), + false, + point + ); + MapActivity.launchMapActivityMoveToTop(app); + } + } + } + return false; + } + boolean putMapPoint(String layerId, AMapPoint point) { if (point != null) { AMapLayer layer = layers.get(layerId); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index c3ef5baab0..e115275ab6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -4,6 +4,7 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.RemoteException; + import net.osmand.PlatformUtil; import net.osmand.aidl.calculateroute.CalculateRouteParams; import net.osmand.aidl.favorite.AddFavoriteParams; @@ -22,6 +23,7 @@ import net.osmand.aidl.gpx.StopGpxRecordingParams; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; +import net.osmand.aidl.maplayer.ShowLayerPointOnMapParams; import net.osmand.aidl.maplayer.UpdateMapLayerParams; import net.osmand.aidl.maplayer.point.AddMapPointParams; import net.osmand.aidl.maplayer.point.RemoveMapPointParams; @@ -35,16 +37,16 @@ import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; import net.osmand.aidl.navigation.NavigateGpxParams; import net.osmand.aidl.navigation.NavigateParams; import net.osmand.aidl.note.StartAudioRecordingParams; +import net.osmand.aidl.note.StartVideoRecordingParams; import net.osmand.aidl.note.StopRecordingParams; import net.osmand.aidl.note.TakePhotoNoteParams; -import net.osmand.aidl.note.StartVideoRecordingParams; import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; -import java.util.List; - import org.apache.commons.logging.Log; +import java.util.List; + public class OsmandAidlService extends Service { private static final Log LOG = PlatformUtil.getLog(OsmandAidlService.class); @@ -200,6 +202,16 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean showLayerPointOnMap(ShowLayerPointOnMapParams params) throws RemoteException { + try { + return params != null && getApi("showLayerPointOnMap").showLayerPointOnMap(params.getLayerId(), params.getPointId()); + } catch (Exception e) { + handleException(e); + return false; + } + } + @Override public boolean addMapPoint(AddMapPointParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.aidl b/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.aidl new file mode 100644 index 0000000000..7bb973b2ce --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.maplayer; + +parcelable ShowLayerPointOnMapParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.java b/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.java new file mode 100644 index 0000000000..f8be2f55dc --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/maplayer/ShowLayerPointOnMapParams.java @@ -0,0 +1,51 @@ +package net.osmand.aidl.maplayer; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ShowLayerPointOnMapParams implements Parcelable { + + private String layerId; + private String pointId; + + public ShowLayerPointOnMapParams(String layerId, String pointId) { + this.layerId = layerId; + this.pointId = pointId; + } + + public ShowLayerPointOnMapParams(Parcel in) { + layerId = in.readString(); + pointId = in.readString(); + } + + public String getLayerId() { + return layerId; + } + + public String getPointId() { + return pointId; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(layerId); + dest.writeString(pointId); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public ShowLayerPointOnMapParams createFromParcel(Parcel in) { + return new ShowLayerPointOnMapParams(in); + } + + @Override + public ShowLayerPointOnMapParams[] newArray(int size) { + return new ShowLayerPointOnMapParams[size]; + } + }; +}