Add the ability to delete gpx file with aidl

This commit is contained in:
Alexander Sytnyk 2018-01-29 18:43:44 +02:00
parent 3c2965c7c1
commit 60354edc72
5 changed files with 81 additions and 0 deletions

View file

@ -49,6 +49,8 @@ import net.osmand.aidl.note.StartVideoRecordingParams;
import net.osmand.aidl.note.StartAudioRecordingParams;
import net.osmand.aidl.note.StopRecordingParams;
import net.osmand.aidl.gpx.RemoveGpxParams;
// NOTE: Add new methods at the end of file!!!
interface IOsmAndAidlInterface {
@ -98,4 +100,5 @@ interface IOsmAndAidlInterface {
boolean navigate(in NavigateParams params);
boolean navigateGpx(in NavigateGpxParams params);
boolean removeGpx(in RemoveGpxParams params);
}

View file

@ -1135,6 +1135,24 @@ public class OsmandAidlApi {
return false;
}
boolean removeGpx(String fileName) {
if (!Algorithms.isEmpty(fileName)) {
final File f = app.getAppPath(IndexConstants.GPX_INDEX_DIR + fileName);
if (f.exists()) {
new AsyncTask<File, Void, Void>() {
@Override
protected Void doInBackground(File... files) {
Algorithms.removeAllFiles(f);
app.getGpxDatabase().remove(f);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, f);
}
}
return false;
}
boolean setMapLocation(double latitude, double longitude, int zoom, boolean animated) {
Intent intent = new Intent();
intent.setAction(AIDL_SET_MAP_LOCATION);

View file

@ -15,6 +15,7 @@ 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;
import net.osmand.aidl.gpx.RemoveGpxParams;
import net.osmand.aidl.gpx.ShowGpxParams;
import net.osmand.aidl.gpx.StartGpxRecordingParams;
import net.osmand.aidl.gpx.StopGpxRecordingParams;
@ -269,6 +270,14 @@ public class OsmandAidlService extends Service {
return getApi().getActiveGpx(files);
}
@Override
public boolean removeGpx(RemoveGpxParams params) throws RemoteException {
if (params != null && params.getFileName() != null) {
return getApi().removeGpx(params.getFileName());
}
return false;
}
@Override
public boolean setMapLocation(SetMapLocationParams params) throws RemoteException {
if (params != null) {

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.gpx;
parcelable RemoveGpxParams;

View file

@ -0,0 +1,48 @@
package net.osmand.aidl.gpx;
import android.os.Parcel;
import android.os.Parcelable;
public class RemoveGpxParams implements Parcelable {
private String fileName;
public RemoveGpxParams(String fileName) {
this.fileName = fileName;
}
public RemoveGpxParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<RemoveGpxParams> CREATOR = new
Creator<RemoveGpxParams>() {
@Override
public RemoveGpxParams createFromParcel(Parcel in) {
return new RemoveGpxParams(in);
}
@Override
public RemoveGpxParams[] newArray(int size) {
return new RemoveGpxParams[size];
}
};
public String getFileName() {
return fileName;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(fileName);
}
private void readFromParcel(Parcel in) {
fileName = in.readString();
}
@Override
public int describeContents() {
return 0;
}
}