Add notes to aidl

This commit is contained in:
PavelRatushny 2017-08-31 17:37:04 +03:00
parent 4e715387df
commit f14dfc70c8
11 changed files with 410 additions and 0 deletions

View file

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

View file

@ -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<String, AMapWidget> widgets = new ConcurrentHashMap<>();
private Map<String, TextInfoWidget> 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;
}
}

View file

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

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StartAudioRecordingParams;

View file

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

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StartVideoRecordingParams;

View file

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

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable StopRecordingParams;

View file

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

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.note;
parcelable TakePhotoNoteParams;

View file

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