Add favorite group with aidl
This commit is contained in:
parent
327fbadbfb
commit
a32be27bb9
8 changed files with 153 additions and 5 deletions
|
@ -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.group.AFavoriteGroup;
|
||||
import net.osmand.aidl.favorite.group.AddFavoriteGroupParams;
|
||||
|
||||
import net.osmand.aidl.favorite.AFavorite;
|
||||
import net.osmand.aidl.favorite.AddFavoriteParams;
|
||||
import net.osmand.aidl.favorite.RemoveFavoriteParams;
|
||||
|
@ -36,6 +39,8 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams;
|
|||
|
||||
interface IOsmAndAidlInterface {
|
||||
|
||||
boolean addFavoriteGroup(in AddFavoriteGroupParams params);
|
||||
|
||||
boolean addFavorite(in AddFavoriteParams params);
|
||||
boolean removeFavorite(in RemoveFavoriteParams params);
|
||||
boolean updateFavorite(in UpdateFavoriteParams params);
|
||||
|
@ -63,4 +68,4 @@ interface IOsmAndAidlInterface {
|
|||
|
||||
boolean setMapLocation(in SetMapLocationParams params);
|
||||
boolean calculateRoute(in CalculateRouteParams params);
|
||||
}
|
||||
}
|
|
@ -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,20 @@ public class OsmandAidlApi {
|
|||
return control;
|
||||
}
|
||||
|
||||
boolean addFavoriteGroup(AFavoriteGroup favoriteGroup) {
|
||||
if (favoriteGroup != null) {
|
||||
FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||
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 addFavorite(AFavorite favorite) {
|
||||
if (favorite != null) {
|
||||
FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.gpx.ASelectedGpxFile;
|
||||
import net.osmand.aidl.gpx.HideGpxParams;
|
||||
import net.osmand.aidl.gpx.ImportGpxParams;
|
||||
|
@ -49,6 +50,15 @@ public class OsmandAidlService extends Service {
|
|||
|
||||
private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() {
|
||||
|
||||
@Override
|
||||
public boolean addFavoriteGroup(AddFavoriteGroupParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi().addFavoriteGroup(params.getFavoriteGroup());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFavorite(AddFavoriteParams params) throws RemoteException {
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.favorite.group;
|
||||
|
||||
parcelable AFavoriteGroup;
|
|
@ -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<AFavoriteGroup> CREATOR = new Creator<AFavoriteGroup>() {
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.favorite.group;
|
||||
|
||||
parcelable AddFavoriteGroupParams;
|
|
@ -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<AddFavoriteGroupParams> CREATOR = new Creator<AddFavoriteGroupParams>() {
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue