Merge pull request #4036 from osmandapp/osmo_api_improvements

Osmo api improvements
This commit is contained in:
Alexey 2017-07-06 10:03:00 +03:00 committed by GitHub
commit 2e5d809fd6
12 changed files with 343 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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<FavouritesDbHelper.FavoriteGroup> 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<FavouritesDbHelper.FavoriteGroup> 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<FavouritesDbHelper.FavoriteGroup> 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();

View file

@ -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 {

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.favorite.group;
parcelable AFavoriteGroup;

View file

@ -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;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.favorite.group;
parcelable AddFavoriteGroupParams;

View file

@ -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;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.favorite.group;
parcelable RemoveFavoriteGroupParams;

View file

@ -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<RemoveFavoriteGroupParams> CREATOR = new Creator<RemoveFavoriteGroupParams>() {
@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;
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.favorite.group;
parcelable UpdateFavoriteGroupParams;

View file

@ -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<UpdateFavoriteGroupParams> CREATOR = new Creator<UpdateFavoriteGroupParams>() {
@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;
}
}

View file

@ -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);
}