From 191a3ef99dd450fed5a7ff262b49eec005870520 Mon Sep 17 00:00:00 2001 From: crimean Date: Sat, 25 Aug 2018 18:34:23 +0300 Subject: [PATCH] Added nav api pause/resume/stop/mute/unmute --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 12 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 109 ++++++++++++++++++ .../net/osmand/aidl/OsmandAidlService.java | 55 +++++++++ .../aidl/navigation/MuteNavigationParams.aidl | 3 + .../aidl/navigation/MuteNavigationParams.java | 38 ++++++ .../navigation/PauseNavigationParams.aidl | 3 + .../navigation/PauseNavigationParams.java | 38 ++++++ .../navigation/ResumeNavigationParams.aidl | 3 + .../navigation/ResumeNavigationParams.java | 38 ++++++ .../aidl/navigation/StopNavigationParams.aidl | 3 + .../aidl/navigation/StopNavigationParams.java | 38 ++++++ .../navigation/UnmuteNavigationParams.aidl | 3 + .../navigation/UnmuteNavigationParams.java | 38 ++++++ .../plus/helpers/ExternalApiHelper.java | 29 +++++ 14 files changed, 410 insertions(+) create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 0987fccfea..d752aa9199 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -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); } \ 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 968162e8c4..f74f77118c 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -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); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index b7c63cc93c..10eb39dcee 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -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 { diff --git a/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.aidl new file mode 100644 index 0000000000..d1205adaf3 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable MuteNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.java new file mode 100644 index 0000000000..8965c415fa --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/MuteNavigationParams.java @@ -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 CREATOR = new Creator() { + @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; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.aidl new file mode 100644 index 0000000000..0a18566304 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable PauseNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.java new file mode 100644 index 0000000000..5a28538039 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/PauseNavigationParams.java @@ -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 CREATOR = new Creator() { + @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; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.aidl new file mode 100644 index 0000000000..4dcf619aaa --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable ResumeNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.java new file mode 100644 index 0000000000..d1032dc914 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/ResumeNavigationParams.java @@ -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 CREATOR = new Creator() { + @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; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.aidl new file mode 100644 index 0000000000..5ba45bdf50 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable StopNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.java new file mode 100644 index 0000000000..e87d6ed2da --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/StopNavigationParams.java @@ -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 CREATOR = new Creator() { + @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; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.aidl new file mode 100644 index 0000000000..7512bbcf34 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable UnmuteNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.java new file mode 100644 index 0000000000..36819db065 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/UnmuteNavigationParams.java @@ -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 CREATOR = new Creator() { + @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; + } +} diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index deaebd3955..b77e369a41 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -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)