Added nav api pause/resume/stop/mute/unmute

This commit is contained in:
crimean 2018-08-25 18:34:23 +03:00
parent 562cc114e0
commit 191a3ef99d
14 changed files with 410 additions and 0 deletions

View file

@ -55,6 +55,12 @@ import net.osmand.aidl.maplayer.point.ShowMapPointParams;
import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams;
import net.osmand.aidl.navigation.PauseNavigationParams;
import net.osmand.aidl.navigation.ResumeNavigationParams;
import net.osmand.aidl.navigation.StopNavigationParams;
import net.osmand.aidl.navigation.MuteNavigationParams;
import net.osmand.aidl.navigation.UnmuteNavigationParams;
// NOTE: Add new methods at the end of file!!!
interface IOsmAndAidlInterface {
@ -109,4 +115,10 @@ interface IOsmAndAidlInterface {
boolean showMapPoint(in ShowMapPointParams params);
boolean setNavDrawerItems(in SetNavDrawerItemsParams params);
boolean pauseNavigation(in PauseNavigationParams params);
boolean resumeNavigation(in ResumeNavigationParams params);
boolean stopNavigation(in StopNavigationParams params);
boolean muteNavigation(in MuteNavigationParams params);
boolean unmuteNavigation(in UnmuteNavigationParams params);
}

View file

@ -117,6 +117,11 @@ public class OsmandAidlApi {
private static final String AIDL_NAVIGATE = "aidl_navigate";
private static final String AIDL_NAVIGATE_GPX = "aidl_navigate_gpx";
private static final String AIDL_PAUSE_NAVIGATION = "pause_navigation";
private static final String AIDL_RESUME_NAVIGATION = "resume_navigation";
private static final String AIDL_STOP_NAVIGATION = "stop_navigation";
private static final String AIDL_MUTE_NAVIGATION = "mute_navigation";
private static final String AIDL_UNMUTE_NAVIGATION = "unmute_navigation";
private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
@ -155,6 +160,11 @@ public class OsmandAidlApi {
registerStopRecordingReceiver(mapActivity);
registerNavigateReceiver(mapActivity);
registerNavigateGpxReceiver(mapActivity);
registerPauseNavigationReceiver(mapActivity);
registerResumeNavigationReceiver(mapActivity);
registerStopNavigationReceiver(mapActivity);
registerMuteNavigationReceiver(mapActivity);
registerUnmuteNavigationReceiver(mapActivity);
}
public void onDestroyMapActivity(final MapActivity mapActivity) {
@ -529,6 +539,70 @@ public class OsmandAidlApi {
}
}
private void registerPauseNavigationReceiver(final MapActivity mapActivity) {
BroadcastReceiver pauseNavigationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isRouteCalculated() && !routingHelper.isRoutePlanningMode()) {
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNavigation(true);
}
}
};
registerReceiver(pauseNavigationReceiver, mapActivity, AIDL_PAUSE_NAVIGATION);
}
private void registerResumeNavigationReceiver(final MapActivity mapActivity) {
BroadcastReceiver resumeNavigationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isRouteCalculated() && routingHelper.isRoutePlanningMode()) {
routingHelper.setRoutePlanningMode(false);
routingHelper.setFollowingMode(true);
}
}
};
registerReceiver(resumeNavigationReceiver, mapActivity, AIDL_RESUME_NAVIGATION);
}
private void registerStopNavigationReceiver(final MapActivity mapActivity) {
BroadcastReceiver stopNavigationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isPauseNavigation() || routingHelper.isFollowingMode()) {
mapActivity.getMapLayers().getMapControlsLayer().stopNavigation();
}
}
};
registerReceiver(stopNavigationReceiver, mapActivity, AIDL_STOP_NAVIGATION);
}
private void registerMuteNavigationReceiver(final MapActivity mapActivity) {
BroadcastReceiver muteNavigationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(true);
mapActivity.getRoutingHelper().getVoiceRouter().setMute(true);
}
};
registerReceiver(muteNavigationReceiver, mapActivity, AIDL_MUTE_NAVIGATION);
}
private void registerUnmuteNavigationReceiver(final MapActivity mapActivity) {
BroadcastReceiver unmuteNavigationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(false);
mapActivity.getRoutingHelper().getVoiceRouter().setMute(false);
}
};
registerReceiver(unmuteNavigationReceiver, mapActivity, AIDL_UNMUTE_NAVIGATION);
}
public void registerMapLayers(MapActivity mapActivity) {
for (AMapLayer layer : layers.values()) {
OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
@ -1191,6 +1265,41 @@ public class OsmandAidlApi {
return true;
}
boolean pauseNavigation() {
Intent intent = new Intent();
intent.setAction(AIDL_PAUSE_NAVIGATION);
app.sendBroadcast(intent);
return true;
}
boolean resumeNavigation() {
Intent intent = new Intent();
intent.setAction(AIDL_RESUME_NAVIGATION);
app.sendBroadcast(intent);
return true;
}
boolean stopNavigation() {
Intent intent = new Intent();
intent.setAction(AIDL_STOP_NAVIGATION);
app.sendBroadcast(intent);
return true;
}
boolean muteNavigation() {
Intent intent = new Intent();
intent.setAction(AIDL_MUTE_NAVIGATION);
app.sendBroadcast(intent);
return true;
}
boolean unmuteNavigation() {
Intent intent = new Intent();
intent.setAction(AIDL_UNMUTE_NAVIGATION);
app.sendBroadcast(intent);
return true;
}
boolean navigateGpx(String data, Uri uri, boolean force) {
Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_GPX);

View file

@ -35,8 +35,13 @@ import net.osmand.aidl.mapwidget.AddMapWidgetParams;
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
import net.osmand.aidl.navdrawer.SetNavDrawerItemsParams;
import net.osmand.aidl.navigation.MuteNavigationParams;
import net.osmand.aidl.navigation.NavigateGpxParams;
import net.osmand.aidl.navigation.NavigateParams;
import net.osmand.aidl.navigation.PauseNavigationParams;
import net.osmand.aidl.navigation.ResumeNavigationParams;
import net.osmand.aidl.navigation.StopNavigationParams;
import net.osmand.aidl.navigation.UnmuteNavigationParams;
import net.osmand.aidl.note.StartAudioRecordingParams;
import net.osmand.aidl.note.StartVideoRecordingParams;
import net.osmand.aidl.note.StopRecordingParams;
@ -459,6 +464,56 @@ public class OsmandAidlService extends Service {
}
}
@Override
public boolean pauseNavigation(PauseNavigationParams params) throws RemoteException {
try {
return getApi("pauseNavigation").pauseNavigation();
} catch (Exception e) {
handleException(e);
return false;
}
}
@Override
public boolean resumeNavigation(ResumeNavigationParams params) throws RemoteException {
try {
return getApi("resumeNavigation").resumeNavigation();
} catch (Exception e) {
handleException(e);
return false;
}
}
@Override
public boolean stopNavigation(StopNavigationParams params) throws RemoteException {
try {
return getApi("stopNavigation").stopNavigation();
} catch (Exception e) {
handleException(e);
return false;
}
}
@Override
public boolean muteNavigation(MuteNavigationParams params) throws RemoteException {
try {
return getApi("muteNavigation").muteNavigation();
} catch (Exception e) {
handleException(e);
return false;
}
}
@Override
public boolean unmuteNavigation(UnmuteNavigationParams params) throws RemoteException {
try {
return getApi("unmuteNavigation").unmuteNavigation();
} catch (Exception e) {
handleException(e);
return false;
}
}
@Override
public boolean setNavDrawerItems(SetNavDrawerItemsParams params) throws RemoteException {
try {

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.navigation;
parcelable MuteNavigationParams;

View file

@ -0,0 +1,38 @@
package net.osmand.aidl.navigation;
import android.os.Parcel;
import android.os.Parcelable;
public class MuteNavigationParams implements Parcelable {
public MuteNavigationParams() {
}
public MuteNavigationParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<MuteNavigationParams> CREATOR = new Creator<MuteNavigationParams>() {
@Override
public MuteNavigationParams createFromParcel(Parcel in) {
return new MuteNavigationParams(in);
}
@Override
public MuteNavigationParams[] newArray(int size) {
return new MuteNavigationParams[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.navigation;
parcelable PauseNavigationParams;

View file

@ -0,0 +1,38 @@
package net.osmand.aidl.navigation;
import android.os.Parcel;
import android.os.Parcelable;
public class PauseNavigationParams implements Parcelable {
public PauseNavigationParams() {
}
public PauseNavigationParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<PauseNavigationParams> CREATOR = new Creator<PauseNavigationParams>() {
@Override
public PauseNavigationParams createFromParcel(Parcel in) {
return new PauseNavigationParams(in);
}
@Override
public PauseNavigationParams[] newArray(int size) {
return new PauseNavigationParams[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.navigation;
parcelable ResumeNavigationParams;

View file

@ -0,0 +1,38 @@
package net.osmand.aidl.navigation;
import android.os.Parcel;
import android.os.Parcelable;
public class ResumeNavigationParams implements Parcelable {
public ResumeNavigationParams() {
}
public ResumeNavigationParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<ResumeNavigationParams> CREATOR = new Creator<ResumeNavigationParams>() {
@Override
public ResumeNavigationParams createFromParcel(Parcel in) {
return new ResumeNavigationParams(in);
}
@Override
public ResumeNavigationParams[] newArray(int size) {
return new ResumeNavigationParams[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.navigation;
parcelable StopNavigationParams;

View file

@ -0,0 +1,38 @@
package net.osmand.aidl.navigation;
import android.os.Parcel;
import android.os.Parcelable;
public class StopNavigationParams implements Parcelable {
public StopNavigationParams() {
}
public StopNavigationParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<StopNavigationParams> CREATOR = new Creator<StopNavigationParams>() {
@Override
public StopNavigationParams createFromParcel(Parcel in) {
return new StopNavigationParams(in);
}
@Override
public StopNavigationParams[] newArray(int size) {
return new StopNavigationParams[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.navigation;
parcelable UnmuteNavigationParams;

View file

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

View file

@ -47,6 +47,11 @@ public class ExternalApiHelper {
public static final String API_CMD_NAVIGATE_GPX = "navigate_gpx";
public static final String API_CMD_NAVIGATE = "navigate";
public static final String API_CMD_PAUSE_NAVIGATION = "pause_navigation";
public static final String API_CMD_RESUME_NAVIGATION = "resume_navigation";
public static final String API_CMD_STOP_NAVIGATION = "stop_navigation";
public static final String API_CMD_MUTE_NAVIGATION = "mute_navigation";
public static final String API_CMD_UNMUTE_NAVIGATION = "unmute_navigation";
public static final String API_CMD_RECORD_AUDIO = "record_audio";
public static final String API_CMD_RECORD_VIDEO = "record_video";
@ -270,6 +275,30 @@ public class ExternalApiHelper {
}
}
} else if (API_CMD_PAUSE_NAVIGATION.equals(cmd)) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isRouteCalculated() && !routingHelper.isRoutePlanningMode()) {
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNavigation(true);
}
} else if (API_CMD_RESUME_NAVIGATION.equals(cmd)) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isRouteCalculated() && routingHelper.isRoutePlanningMode()) {
routingHelper.setRoutePlanningMode(false);
routingHelper.setFollowingMode(true);
}
} else if (API_CMD_STOP_NAVIGATION.equals(cmd)) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (routingHelper.isPauseNavigation() || routingHelper.isFollowingMode()) {
mapActivity.getMapLayers().getMapControlsLayer().stopNavigation();
}
} else if (API_CMD_MUTE_NAVIGATION.equals(cmd)) {
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(true);
mapActivity.getRoutingHelper().getVoiceRouter().setMute(true);
} else if (API_CMD_UNMUTE_NAVIGATION.equals(cmd)) {
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(false);
mapActivity.getRoutingHelper().getVoiceRouter().setMute(false);
} else if (API_CMD_RECORD_AUDIO.equals(cmd)
|| API_CMD_RECORD_VIDEO.equals(cmd)
|| API_CMD_RECORD_PHOTO.equals(cmd)