diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 089f96c04c..04105f7ba0 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -41,6 +41,11 @@ import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; import net.osmand.aidl.maplayer.UpdateMapLayerParams; +import net.osmand.aidl.note.TakePhotoNoteParams; +import net.osmand.aidl.note.StartVideoRecordingParams; +import net.osmand.aidl.note.StartAudioRecordingParams; +import net.osmand.aidl.note.StopRecordingParams; + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -82,4 +87,9 @@ interface IOsmAndAidlInterface { boolean startGpxRecording(in StartGpxRecordingParams params); boolean stopGpxRecording(in StopGpxRecordingParams params); + boolean takePhotoNote(in TakePhotoNoteParams params); + boolean startVideoRecording(in StartVideoRecordingParams params); + boolean startAudioRecording(in StartAudioRecordingParams params); + boolean stopRecording(in StopRecordingParams 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 7aaeff5eac..a9cfa2013e 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -33,6 +33,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; @@ -73,6 +74,11 @@ public class OsmandAidlApi { private static final String AIDL_ADD_MAP_LAYER = "aidl_add_map_layer"; private static final String AIDL_REMOVE_MAP_LAYER = "aidl_remove_map_layer"; + private static final String AIDL_TAKE_PHOTO_NOTE = "aidl_take_photo_note"; + private static final String AIDL_START_VIDEO_RECORDING = "aidl_start_video_recording"; + private static final String AIDL_START_AUDIO_RECORDING = "aidl_start_audio_recording"; + private static final String AIDL_STOP_RECORDING = "aidl_stop_recording"; + private OsmandApplication app; private Map widgets = new ConcurrentHashMap<>(); private Map widgetControls = new ConcurrentHashMap<>(); @@ -85,6 +91,10 @@ public class OsmandAidlApi { private BroadcastReceiver removeMapWidgetReceiver; private BroadcastReceiver addMapLayerReceiver; private BroadcastReceiver removeMapLayerReceiver; + private BroadcastReceiver takePhotoNoteReceiver; + private BroadcastReceiver startVideoRecordingReceiver; + private BroadcastReceiver startAudioRecordingReceiver; + private BroadcastReceiver stopRecordingReceiver; public OsmandAidlApi(OsmandApplication app) { this.app = app; @@ -97,6 +107,10 @@ public class OsmandAidlApi { registerRemoveMapWidgetReceiver(mapActivity); registerAddMapLayerReceiver(mapActivity); registerRemoveMapLayerReceiver(mapActivity); + registerTakePhotoNoteReceiver(mapActivity); + registerStartVideoRecordingReceiver(mapActivity); + registerStartAudioRecordingReceiver(mapActivity); + registerStopRecordingReceiver(mapActivity); } public void onDestroyMapActivity(final MapActivity mapActivity) { @@ -151,6 +165,38 @@ public class OsmandAidlApi { } removeMapLayerReceiver = null; } + if (takePhotoNoteReceiver != null) { + try { + mapActivity.unregisterReceiver(takePhotoNoteReceiver); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + takePhotoNoteReceiver = null; + } + if (startVideoRecordingReceiver != null) { + try { + mapActivity.unregisterReceiver(startVideoRecordingReceiver); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + startVideoRecordingReceiver = null; + } + if (startAudioRecordingReceiver != null) { + try { + mapActivity.unregisterReceiver(startAudioRecordingReceiver); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + startAudioRecordingReceiver = null; + } + if (stopRecordingReceiver != null) { + try { + mapActivity.unregisterReceiver(stopRecordingReceiver); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + stopRecordingReceiver = null; + } } private void registerRefreshMapReceiver(final MapActivity mapActivity) { @@ -303,6 +349,64 @@ public class OsmandAidlApi { mapActivity.registerReceiver(removeMapLayerReceiver, new IntentFilter(AIDL_REMOVE_MAP_LAYER)); } + private void registerTakePhotoNoteReceiver(final MapActivity mapActivity) { + takePhotoNoteReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); + double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + plugin.takePhoto(lat, lon, mapActivity, false); + } + } + }; + mapActivity.registerReceiver(takePhotoNoteReceiver, new IntentFilter(AIDL_TAKE_PHOTO_NOTE)); + } + + private void registerStartVideoRecordingReceiver(final MapActivity mapActivity) { + startVideoRecordingReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); + double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + plugin.recordVideo(lat, lon, mapActivity); + } + } + }; + mapActivity.registerReceiver(startVideoRecordingReceiver, new IntentFilter(AIDL_START_VIDEO_RECORDING)); + } + + private void registerStartAudioRecordingReceiver(final MapActivity mapActivity) { + startVideoRecordingReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN); + double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN); + plugin.recordAudio(lat, lon, mapActivity); + } + } + }; + mapActivity.registerReceiver(startVideoRecordingReceiver, new IntentFilter(AIDL_START_AUDIO_RECORDING)); + } + + private void registerStopRecordingReceiver(final MapActivity mapActivity) { + stopRecordingReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + plugin.stopRecording(mapActivity, false); + } + } + }; + mapActivity.registerReceiver(stopRecordingReceiver, new IntentFilter(AIDL_STOP_RECORDING)); + } + public void registerMapLayers(MapActivity mapActivity) { for (AMapLayer layer : layers.values()) { OsmandMapLayer mapLayer = mapLayers.get(layer.getId()); @@ -865,4 +969,38 @@ public class OsmandAidlApi { } return false; } + + boolean takePhotoNote(double latitude, double longitude) { + Intent intent = new Intent(); + intent.setAction(AIDL_TAKE_PHOTO_NOTE); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + app.sendBroadcast(intent); + return true; + } + + boolean startVideoRecording(double latitude, double longitude) { + Intent intent = new Intent(); + intent.setAction(AIDL_START_VIDEO_RECORDING); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + app.sendBroadcast(intent); + return true; + } + + boolean startAudioRecording(double latitude, double longitude) { + Intent intent = new Intent(); + intent.setAction(AIDL_START_AUDIO_RECORDING); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + app.sendBroadcast(intent); + return true; + } + + boolean stopRecording() { + Intent intent = new Intent(); + intent.setAction(AIDL_STOP_RECORDING); + app.sendBroadcast(intent); + return true; + } } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index e1da642f59..42307f2625 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -31,6 +31,10 @@ import net.osmand.aidl.mapmarker.UpdateMapMarkerParams; import net.osmand.aidl.mapwidget.AddMapWidgetParams; import net.osmand.aidl.mapwidget.RemoveMapWidgetParams; import net.osmand.aidl.mapwidget.UpdateMapWidgetParams; +import net.osmand.aidl.note.StartAudioRecordingParams; +import net.osmand.aidl.note.StopRecordingParams; +import net.osmand.aidl.note.TakePhotoNoteParams; +import net.osmand.aidl.note.StartVideoRecordingParams; import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; @@ -340,5 +344,41 @@ public class OsmandAidlService extends Service { return false; } } + + @Override + public boolean takePhotoNote(TakePhotoNoteParams params) throws RemoteException { + try { + return params != null && getApi().takePhotoNote(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean startVideoRecording(StartVideoRecordingParams params) throws RemoteException { + try { + return params != null && getApi().startVideoRecording(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean startAudioRecording(StartAudioRecordingParams params) throws RemoteException { + try { + return params != null && getApi().startAudioRecording(params.getLatitude(), params.getLongitude()); + } catch (Exception e) { + return false; + } + } + + @Override + public boolean stopRecording(StopRecordingParams params) throws RemoteException { + try { + return getApi().stopRecording(); + } catch (Exception e) { + return false; + } + } }; } diff --git a/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.aidl b/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.aidl new file mode 100644 index 0000000000..bb16dea140 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.note; + +parcelable StartAudioRecordingParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.java b/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.java new file mode 100644 index 0000000000..c2800feb9c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StartAudioRecordingParams.java @@ -0,0 +1,56 @@ +package net.osmand.aidl.note; + +import android.os.Parcel; +import android.os.Parcelable; + +public class StartAudioRecordingParams implements Parcelable { + + private double latitude; + private double longitude; + + public StartAudioRecordingParams(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public StartAudioRecordingParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public StartAudioRecordingParams createFromParcel(Parcel in) { + return new StartAudioRecordingParams(in); + } + + @Override + public StartAudioRecordingParams[] newArray(int size) { + return new StartAudioRecordingParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(latitude); + out.writeDouble(longitude); + } + + private void readFromParcel(Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + } + + @Override + public int describeContents() { + return 0; + } + +} diff --git a/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.aidl b/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.aidl new file mode 100644 index 0000000000..082b68e09c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.note; + +parcelable StartVideoRecordingParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.java b/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.java new file mode 100644 index 0000000000..aee86ea9de --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StartVideoRecordingParams.java @@ -0,0 +1,56 @@ +package net.osmand.aidl.note; + +import android.os.Parcel; +import android.os.Parcelable; + +public class StartVideoRecordingParams implements Parcelable { + + private double latitude; + private double longitude; + + public StartVideoRecordingParams(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public StartVideoRecordingParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public StartVideoRecordingParams createFromParcel(Parcel in) { + return new StartVideoRecordingParams(in); + } + + @Override + public StartVideoRecordingParams[] newArray(int size) { + return new StartVideoRecordingParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(latitude); + out.writeDouble(longitude); + } + + private void readFromParcel(Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + } + + @Override + public int describeContents() { + return 0; + } + +} diff --git a/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.aidl b/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.aidl new file mode 100644 index 0000000000..4111efbcb6 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.note; + +parcelable StopRecordingParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.java b/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.java new file mode 100644 index 0000000000..b56a42504b --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/StopRecordingParams.java @@ -0,0 +1,42 @@ +package net.osmand.aidl.note; + +import android.os.Parcel; +import android.os.Parcelable; + +public class StopRecordingParams implements Parcelable { + + public StopRecordingParams() { + + } + + public StopRecordingParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public StopRecordingParams createFromParcel(Parcel in) { + return new StopRecordingParams(in); + } + + @Override + public StopRecordingParams[] newArray(int size) { + return new StopRecordingParams[size]; + } + }; + + @Override + public void writeToParcel(Parcel out, int flags) { + + } + + private void readFromParcel(Parcel in) { + + } + + @Override + public int describeContents() { + return 0; + } + +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.aidl b/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.aidl new file mode 100644 index 0000000000..3c09d62c41 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.note; + +parcelable TakePhotoNoteParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.java b/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.java new file mode 100644 index 0000000000..254516e080 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/note/TakePhotoNoteParams.java @@ -0,0 +1,56 @@ +package net.osmand.aidl.note; + +import android.os.Parcel; +import android.os.Parcelable; + +public class TakePhotoNoteParams implements Parcelable { + + private double latitude; + private double longitude; + + public TakePhotoNoteParams(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public TakePhotoNoteParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public TakePhotoNoteParams createFromParcel(Parcel in) { + return new TakePhotoNoteParams(in); + } + + @Override + public TakePhotoNoteParams[] newArray(int size) { + return new TakePhotoNoteParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(latitude); + out.writeDouble(longitude); + } + + private void readFromParcel(Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + } + + @Override + public int describeContents() { + return 0; + } + +}