From 60354edc7242cd4ec8c05a3bbf7316a25b88c8f9 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 29 Jan 2018 18:43:44 +0200 Subject: [PATCH] Add the ability to delete gpx file with aidl --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 3 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 18 +++++++ .../net/osmand/aidl/OsmandAidlService.java | 9 ++++ .../net/osmand/aidl/gpx/RemoveGpxParams.aidl | 3 ++ .../net/osmand/aidl/gpx/RemoveGpxParams.java | 48 +++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 78beb7ca96..64410a3f9f 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -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); } \ 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 5736d71f13..892c23ef1a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -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() { + + @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); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index d7826cdbd0..0b4edf77bf 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.aidl b/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.aidl new file mode 100644 index 0000000000..e9025f7a19 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.gpx; + +parcelable RemoveGpxParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.java b/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.java new file mode 100644 index 0000000000..2253fa3616 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/gpx/RemoveGpxParams.java @@ -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 CREATOR = new + Creator() { + @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; + } +}