Add navigate gpx to aidl
This commit is contained in:
parent
656c50be1d
commit
fc3a6b9be4
5 changed files with 161 additions and 0 deletions
|
@ -42,6 +42,7 @@ import net.osmand.aidl.maplayer.RemoveMapLayerParams;
|
|||
import net.osmand.aidl.maplayer.UpdateMapLayerParams;
|
||||
|
||||
import net.osmand.aidl.navigation.NavigateParams;
|
||||
import net.osmand.aidl.navigation.NavigateGpxParams;
|
||||
|
||||
import net.osmand.aidl.note.TakePhotoNoteParams;
|
||||
import net.osmand.aidl.note.StartVideoRecordingParams;
|
||||
|
@ -95,5 +96,6 @@ interface IOsmAndAidlInterface {
|
|||
boolean stopRecording(in StopRecordingParams params);
|
||||
|
||||
boolean navigate(in NavigateParams params);
|
||||
boolean navigateGpx(in NavigateGpxParams params);
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
|
@ -55,6 +56,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -78,6 +80,8 @@ public class OsmandAidlApi {
|
|||
private static final String AIDL_DEST_LAT = "aidl_dest_lat";
|
||||
private static final String AIDL_DEST_LON = "aidl_dest_lon";
|
||||
private static final String AIDL_PROFILE = "aidl_profile";
|
||||
private static final String AIDL_DATA = "aidl_data";
|
||||
private static final String AIDL_URI = "aidl_uri";
|
||||
private static final String AIDL_FORCE = "aidl_force";
|
||||
|
||||
private static final String AIDL_OBJECT_ID = "aidl_object_id";
|
||||
|
@ -94,6 +98,7 @@ public class OsmandAidlApi {
|
|||
private static final String AIDL_STOP_RECORDING = "aidl_stop_recording";
|
||||
|
||||
private static final String AIDL_NAVIGATE = "aidl_navigate";
|
||||
private static final String AIDL_NAVIGATE_GPX = "aidl_navigate_gpx";
|
||||
|
||||
private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
|
||||
|
||||
|
@ -120,6 +125,7 @@ public class OsmandAidlApi {
|
|||
private BroadcastReceiver startAudioRecordingReceiver;
|
||||
private BroadcastReceiver stopRecordingReceiver;
|
||||
private BroadcastReceiver navigateReceiver;
|
||||
private BroadcastReceiver navigateGpxReceiver;
|
||||
|
||||
public OsmandAidlApi(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -137,6 +143,7 @@ public class OsmandAidlApi {
|
|||
registerStartAudioRecordingReceiver(mapActivity);
|
||||
registerStopRecordingReceiver(mapActivity);
|
||||
registerNavigateReceiver(mapActivity);
|
||||
registerNavigateGpxReceiver(mapActivity);
|
||||
}
|
||||
|
||||
public void onDestroyMapActivity(final MapActivity mapActivity) {
|
||||
|
@ -231,6 +238,14 @@ public class OsmandAidlApi {
|
|||
}
|
||||
navigateReceiver = null;
|
||||
}
|
||||
if (navigateGpxReceiver != null) {
|
||||
try {
|
||||
mapActivity.unregisterReceiver(navigateGpxReceiver);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
navigateGpxReceiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerRefreshMapReceiver(final MapActivity mapActivity) {
|
||||
|
@ -503,6 +518,58 @@ public class OsmandAidlApi {
|
|||
mapActivity.registerReceiver(navigateReceiver, new IntentFilter(AIDL_NAVIGATE));
|
||||
}
|
||||
|
||||
private void registerNavigateGpxReceiver(final MapActivity mapActivity) {
|
||||
navigateGpxReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
|
||||
|
||||
GPXFile gpx = null;
|
||||
if (intent.getStringExtra(AIDL_DATA) != null) {
|
||||
String gpxStr = intent.getStringExtra(AIDL_DATA);
|
||||
if (!Algorithms.isEmpty(gpxStr)) {
|
||||
gpx = GPXUtilities.loadGPXFile(mapActivity, new ByteArrayInputStream(gpxStr.getBytes()));
|
||||
}
|
||||
} else if (intent.getParcelableExtra(AIDL_URI) != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
|
||||
|
||||
ParcelFileDescriptor gpxParcelDescriptor = null;
|
||||
try {
|
||||
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (gpxParcelDescriptor != null) {
|
||||
FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
|
||||
gpx = GPXUtilities.loadGPXFile(mapActivity, new FileInputStream(fileDescriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gpx != null) {
|
||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
final GPXFile gpxFile = gpx;
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (!routingHelper.isFollowingMode()) {
|
||||
startNavigation(mapActivity, gpxFile, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
startNavigation(mapActivity, gpx, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
mapActivity.registerReceiver(navigateGpxReceiver, new IntentFilter(AIDL_NAVIGATE_GPX));
|
||||
}
|
||||
|
||||
private void startNavigation(MapActivity mapActivity,
|
||||
GPXFile gpx,
|
||||
LatLon from, PointDescription fromDesc,
|
||||
|
@ -1144,4 +1211,14 @@ public class OsmandAidlApi {
|
|||
app.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean navigateGpx(String data, Uri uri, boolean force) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(AIDL_NAVIGATE_GPX);
|
||||
intent.putExtra(AIDL_DATA, data);
|
||||
intent.putExtra(AIDL_URI, uri);
|
||||
intent.putExtra(AIDL_FORCE, force);
|
||||
app.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ 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.navigation.NavigateGpxParams;
|
||||
import net.osmand.aidl.navigation.NavigateParams;
|
||||
import net.osmand.aidl.note.StartAudioRecordingParams;
|
||||
import net.osmand.aidl.note.StopRecordingParams;
|
||||
|
@ -390,5 +391,14 @@ public class OsmandAidlService extends Service {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean navigateGpx(NavigateGpxParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi().navigateGpx(params.getData(), params.getUri(), params.isForce());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.navigation;
|
||||
|
||||
parcelable NavigateGpxParams;
|
69
OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java
Normal file
69
OsmAnd/src/net/osmand/aidl/navigation/NavigateGpxParams.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package net.osmand.aidl.navigation;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class NavigateGpxParams implements Parcelable {
|
||||
|
||||
private String data;
|
||||
private Uri uri;
|
||||
private boolean force;
|
||||
|
||||
public NavigateGpxParams(String data, boolean force) {
|
||||
this.data = data;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public NavigateGpxParams(Uri uri, boolean force) {
|
||||
this.uri = uri;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public NavigateGpxParams(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<NavigateGpxParams> CREATOR = new Creator<NavigateGpxParams>() {
|
||||
@Override
|
||||
public NavigateGpxParams createFromParcel(Parcel in) {
|
||||
return new NavigateGpxParams(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigateGpxParams[] newArray(int size) {
|
||||
return new NavigateGpxParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public boolean isForce() {
|
||||
return force;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(data);
|
||||
out.writeParcelable(uri, flags);
|
||||
out.writeByte((byte) (force ? 1 : 0));
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel in) {
|
||||
data = in.readString();
|
||||
uri = in.readParcelable(Uri.class.getClassLoader());
|
||||
force = in.readByte() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue