diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 0a199f58a7..adfccdbdf1 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -3,6 +3,11 @@ package net.osmand.aidl; import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.map.SetMapLocationParams; +import net.osmand.aidl.favorite.group.AFavoriteGroup; +import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; +import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; +import net.osmand.aidl.favorite.group.UpdateFavoriteGroupParams; + import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.RemoveFavoriteParams; @@ -36,6 +41,12 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams; interface IOsmAndAidlInterface { + boolean refreshMap(); + + boolean addFavoriteGroup(in AddFavoriteGroupParams params); + boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); + boolean updateFavoriteGroup(in UpdateFavoriteGroupParams params); + boolean addFavorite(in AddFavoriteParams params); boolean removeFavorite(in RemoveFavoriteParams params); boolean updateFavorite(in UpdateFavoriteParams params); @@ -63,4 +74,4 @@ interface IOsmAndAidlInterface { boolean setMapLocation(in SetMapLocationParams params); boolean calculateRoute(in CalculateRouteParams 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 6d9712f4b9..351e511ea5 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -10,6 +10,7 @@ import android.view.View; import net.osmand.IndexConstants; import net.osmand.aidl.favorite.AFavorite; +import net.osmand.aidl.favorite.group.AFavoriteGroup; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.maplayer.AMapLayer; import net.osmand.aidl.maplayer.point.AMapPoint; @@ -349,6 +350,67 @@ public class OsmandAidlApi { return control; } + boolean reloadMap() { + refreshMap(); + return true; + } + + boolean addFavoriteGroup(AFavoriteGroup favoriteGroup) { + if (favoriteGroup != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(favoriteGroup.getName())) { + return false; + } + } + int color = 0; + if (!Algorithms.isEmpty(favoriteGroup.getColor())) { + color = ColorDialogs.getColorByTag(favoriteGroup.getColor()); + } + favoritesHelper.addEmptyCategory(favoriteGroup.getName(), color, favoriteGroup.isVisible()); + return true; + } else { + return false; + } + } + + boolean removeFavoriteGroup(AFavoriteGroup favoriteGroup) { + if (favoriteGroup != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(favoriteGroup.getName())) { + favoritesHelper.deleteGroup(g); + return true; + } + } + return false; + } else { + return false; + } + } + + boolean updateFavoriteGroup(AFavoriteGroup gPrev, AFavoriteGroup gNew) { + if (gPrev != null && gNew != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(gPrev.getName())) { + int color = 0; + if (!Algorithms.isEmpty(gNew.getColor())) { + color = ColorDialogs.getColorByTag(gNew.getColor()); + } + favoritesHelper.editFavouriteGroup(g, gNew.getName(), color, gNew.isVisible()); + return true; + } + } + return false; + } else { + return false; + } + } + boolean addFavorite(AFavorite favorite) { if (favorite != null) { FavouritesDbHelper favoritesHelper = app.getFavorites(); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 1602c663f3..2a40acb86a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -9,6 +9,9 @@ import net.osmand.aidl.calculateroute.CalculateRouteParams; import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.RemoveFavoriteParams; import net.osmand.aidl.favorite.UpdateFavoriteParams; +import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; +import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; +import net.osmand.aidl.favorite.group.UpdateFavoriteGroupParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -49,6 +52,42 @@ public class OsmandAidlService extends Service { private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() { + @Override + public boolean refreshMap() throws RemoteException { + try { + return getApi().reloadMap(); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean addFavoriteGroup(AddFavoriteGroupParams params) throws RemoteException { + try { + return params != null && getApi().addFavoriteGroup(params.getFavoriteGroup()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean removeFavoriteGroup(RemoveFavoriteGroupParams params) throws RemoteException { + try { + return params != null && getApi().removeFavoriteGroup(params.getFavoriteGroup()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean updateFavoriteGroup(UpdateFavoriteGroupParams params) throws RemoteException { + try { + return params != null && getApi().updateFavoriteGroup(params.getFavoriteGroupPrev(), params.getFavoriteGroupNew()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addFavorite(AddFavoriteParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.aidl new file mode 100644 index 0000000000..baec925474 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable AFavoriteGroup; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.java b/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.java new file mode 100644 index 0000000000..e9b6348468 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/AFavoriteGroup.java @@ -0,0 +1,63 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class AFavoriteGroup implements Parcelable { + + private String name; + private String color; + private boolean visible; + + public AFavoriteGroup(String name, String color, boolean visible) { + this.name = name; + this.color = color; + this.visible = visible; + } + + public AFavoriteGroup(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AFavoriteGroup createFromParcel(Parcel in) { + return new AFavoriteGroup(in); + } + + @Override + public AFavoriteGroup[] newArray(int size) { + return new AFavoriteGroup[size]; + } + }; + + public String getName() { + return name; + } + + public String getColor() { + return color; + } + + public boolean isVisible() { + return visible; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeString(name); + out.writeString(color); + out.writeByte((byte) (visible ? 1 : 0)); + } + + private void readFromParcel(Parcel in) { + name = in.readString(); + color = in.readString(); + visible = in.readByte() != 0; + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.aidl new file mode 100644 index 0000000000..5850b5cd34 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable AddFavoriteGroupParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.java b/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.java new file mode 100644 index 0000000000..7cb3228572 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/AddFavoriteGroupParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class AddFavoriteGroupParams implements Parcelable { + + private AFavoriteGroup favoriteGroup; + + public AddFavoriteGroupParams(AFavoriteGroup favoriteGroup) { + this.favoriteGroup = favoriteGroup; + } + + public AddFavoriteGroupParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public AddFavoriteGroupParams createFromParcel(Parcel in) { + return new AddFavoriteGroupParams(in); + } + + @Override + public AddFavoriteGroupParams[] newArray(int size) { + return new AddFavoriteGroupParams[size]; + } + }; + + public AFavoriteGroup getFavoriteGroup() { + return favoriteGroup; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoriteGroup, flags); + } + + private void readFromParcel(Parcel in) { + favoriteGroup = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl new file mode 100644 index 0000000000..e8b0710a01 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable RemoveFavoriteGroupParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java new file mode 100644 index 0000000000..0b17274440 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class RemoveFavoriteGroupParams implements Parcelable { + + private AFavoriteGroup favoriteGroup; + + public RemoveFavoriteGroupParams(AFavoriteGroup favoriteGroup) { + this.favoriteGroup = favoriteGroup; + } + + public RemoveFavoriteGroupParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RemoveFavoriteGroupParams createFromParcel(Parcel in) { + return new RemoveFavoriteGroupParams(in); + } + + @Override + public RemoveFavoriteGroupParams[] newArray(int size) { + return new RemoveFavoriteGroupParams[size]; + } + }; + + public AFavoriteGroup getFavoriteGroup() { + return favoriteGroup; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoriteGroup, flags); + } + + private void readFromParcel(Parcel in) { + favoriteGroup = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl new file mode 100644 index 0000000000..e9001a8c5e --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable UpdateFavoriteGroupParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java new file mode 100644 index 0000000000..0ea52e1fda --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java @@ -0,0 +1,55 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class UpdateFavoriteGroupParams implements Parcelable { + + private AFavoriteGroup favoriteGroupPrev; + private AFavoriteGroup favoriteGroupNew; + + public UpdateFavoriteGroupParams(AFavoriteGroup favoriteGroup, AFavoriteGroup favoriteGroupNew) { + this.favoriteGroupPrev = favoriteGroup; + this.favoriteGroupNew = favoriteGroupNew; + } + + public UpdateFavoriteGroupParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public UpdateFavoriteGroupParams createFromParcel(Parcel in) { + return new UpdateFavoriteGroupParams(in); + } + + @Override + public UpdateFavoriteGroupParams[] newArray(int size) { + return new UpdateFavoriteGroupParams[size]; + } + }; + + public AFavoriteGroup getFavoriteGroupPrev() { + return favoriteGroupPrev; + } + + public AFavoriteGroup getFavoriteGroupNew() { + return favoriteGroupNew; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoriteGroupPrev, flags); + out.writeParcelable(favoriteGroupNew, flags); + } + + private void readFromParcel(Parcel in) { + favoriteGroupPrev = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + favoriteGroupNew = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 2f66e4e478..cc5fdc0c96 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -415,16 +415,18 @@ public class FavouritesDbHelper { public void addEmptyCategory(String name) { - FavoriteGroup group = new FavoriteGroup(); - group.name = name; - favoriteGroups.add(group); - flatGroups.put(name, group); + addEmptyCategory(name, 0, true); } public void addEmptyCategory(String name, int color) { + addEmptyCategory(name, color, true); + } + + public void addEmptyCategory(String name, int color, boolean visible) { FavoriteGroup group = new FavoriteGroup(); group.name = name; group.color = color; + group.visible = visible; favoriteGroups.add(group); flatGroups.put(name, group); }