diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index b03eb12fc3..bc0310ac15 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -3,6 +3,9 @@ package net.osmand.aidl; import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.map.SetMapLocationParams; +import net.osmand.aidl.favorite.AFavorite; +import net.osmand.aidl.favorite.AddFavoriteParams; + import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AddMapMarkerParams; import net.osmand.aidl.mapmarker.RemoveMapMarkerParams; @@ -31,6 +34,8 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams; interface IOsmAndAidlInterface { + boolean addFavorite(in AddFavoriteParams params); + boolean addMapMarker(in AddMapMarkerParams params); boolean removeMapMarker(in RemoveMapMarkerParams params); boolean updateMapMarker(in UpdateMapMarkerParams params); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 5293ff233f..f39a369651 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -9,13 +9,16 @@ import android.os.ParcelFileDescriptor; import android.view.View; import net.osmand.IndexConstants; +import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.maplayer.AMapLayer; import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapwidget.AMapWidget; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; @@ -23,6 +26,7 @@ import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; @@ -345,6 +349,24 @@ public class OsmandAidlApi { return control; } + boolean addFavorite(AFavorite favorite) { + if (favorite != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + FavouritePoint point = new FavouritePoint(favorite.getLat(), favorite.getLon(), favorite.getName(), favorite.getCategory()); + point.setDescription(favorite.getDescription()); + int color = 0; + if (!Algorithms.isEmpty(favorite.getColor())) { + color = ColorDialogs.getColorByTag(favorite.getColor()); + } + point.setColor(color); + point.setVisible(favorite.isVisible()); + favoritesHelper.addFavourite(point); + return true; + } else { + return false; + } + } + boolean addMapMarker(AMapMarker marker) { if (marker != null) { PointDescription pd = new PointDescription( diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 5e7d106be3..8a1547e841 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -2,12 +2,11 @@ package net.osmand.aidl; import android.app.Service; import android.content.Intent; -import android.net.Uri; -import android.os.Build; import android.os.IBinder; import android.os.RemoteException; import net.osmand.aidl.calculateroute.CalculateRouteParams; +import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -48,6 +47,15 @@ public class OsmandAidlService extends Service { private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() { + @Override + public boolean addFavorite(AddFavoriteParams params) throws RemoteException { + try { + return params != null && getApi().addFavorite(params.getFavorite()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.aidl b/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.aidl new file mode 100644 index 0000000000..afd535fbe8 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite; + +parcelable AFavorite; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.java b/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.java new file mode 100644 index 0000000000..b7fc057249 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/AFavorite.java @@ -0,0 +1,96 @@ +package net.osmand.aidl.favorite; + +import android.os.Parcel; +import android.os.Parcelable; + +public class AFavorite implements Parcelable { + + private double lat; + private double lon; + private String name; + private String description; + private String category; + private String color; + private boolean visible; + + public AFavorite(double lat, double lon, String name, String description, + String category, String color, boolean visible) { + this.lat = lat; + this.lon = lon; + this.name = name; + this.description = description; + this.category = category; + this.color = color; + this.visible = visible; + } + + public AFavorite(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AFavorite createFromParcel(Parcel in) { + return new AFavorite(in); + } + + @Override + public AFavorite[] newArray(int size) { + return new AFavorite[size]; + } + }; + + public double getLat() { + return lat; + } + + public double getLon() { + return lon; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getCategory() { + return category; + } + + public String getColor() { + return color; + } + + public boolean isVisible() { + return visible; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(lat); + out.writeDouble(lon); + out.writeString(name); + out.writeString(description); + out.writeString(category); + out.writeString(color); + out.writeByte((byte) (visible ? 1 : 0)); + } + + private void readFromParcel(Parcel in) { + lat = in.readDouble(); + lon = in.readDouble(); + name = in.readString(); + description = in.readString(); + category = in.readString(); + color = in.readString(); + visible = in.readByte() != 0; + } + + @Override + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.aidl new file mode 100644 index 0000000000..c546992b10 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite; + +parcelable AddFavoriteParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.java b/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.java new file mode 100644 index 0000000000..87baeb5a99 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/AddFavoriteParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.favorite; + +import android.os.Parcel; +import android.os.Parcelable; + +public class AddFavoriteParams implements Parcelable { + + private AFavorite favorite; + + public AddFavoriteParams(AFavorite favorite) { + this.favorite = favorite; + } + + public AddFavoriteParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AddFavoriteParams createFromParcel(Parcel in) { + return new AddFavoriteParams(in); + } + + @Override + public AddFavoriteParams[] newArray(int size) { + return new AddFavoriteParams[size]; + } + }; + + public AFavorite getFavorite() { + return favorite; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favorite, flags); + } + + private void readFromParcel(Parcel in) { + favorite = in.readParcelable(AFavorite.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +}