diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl index 19d5b75416..2fcd46d2a7 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlCallback.aidl @@ -3,6 +3,7 @@ package net.osmand.aidl; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.gpx.AGpxBitmap; import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.OnVoiceNavigationParams; interface IOsmAndAidlCallback { @@ -49,5 +50,5 @@ interface IOsmAndAidlCallback { /** * Callback for {@link IOsmAndAidlInterface} registerForVoiceRouterMessages() method. */ - void onVoiceRouterNotify(); + void onVoiceRouterNotify(in OnVoiceNavigationParams 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 68e5a9959f..07da3f1642 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -47,6 +47,7 @@ import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.navdrawer.NavDrawerFooterParams; import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.OnVoiceNavigationParams; import net.osmand.aidl.plugins.PluginParams; import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -1923,12 +1924,12 @@ public class OsmandAidlApi { public void registerForVoiceRouterMessages(long id) { VoiceRouter.VoiceMessageListener listener = new VoiceRouter.VoiceMessageListener() { @Override - public void onVoiceMessage() { + public void onVoiceMessage(List cmds, List played) { if (aidlCallbackListener != null) { for (OsmandAidlService.AidlCallbackParams cb : aidlCallbackListener.getAidlCallbacks().values()) { if (!aidlCallbackListener.getAidlCallbacks().isEmpty() && (cb.getKey() & KEY_ON_VOICE_MESSAGE) > 0) { try { - cb.getCallback().onVoiceRouterNotify(); + cb.getCallback().onVoiceRouterNotify(new OnVoiceNavigationParams(cmds, played)); } catch (Exception e) { LOG.error(e.getMessage(), e); } diff --git a/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl new file mode 100644 index 0000000000..53ab4f6a5c --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable OnVoiceNavigationParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java new file mode 100644 index 0000000000..cdffd45110 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/OnVoiceNavigationParams.java @@ -0,0 +1,55 @@ +package net.osmand.aidl.navigation; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.List; + +public class OnVoiceNavigationParams implements Parcelable { + + private List cmds; + private List played; + + public OnVoiceNavigationParams() { + cmds = new ArrayList<>(); + played = new ArrayList<>(); + } + + public OnVoiceNavigationParams(List cmds, List played) { + this.cmds = cmds; + this.played = played; + } + + public OnVoiceNavigationParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public OnVoiceNavigationParams createFromParcel(Parcel in) { + return new OnVoiceNavigationParams(in); + } + + @Override + public OnVoiceNavigationParams[] newArray(int size) { + return new OnVoiceNavigationParams[size]; + } + }; + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeList(cmds); + out.writeList(played); + } + + private void readFromParcel(Parcel in) { + in.readList(cmds, getClass().getClassLoader()); + in.readList(played, getClass().getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 08f9876389..34adfa1afb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import net.osmand.Location; import net.osmand.binary.RouteDataObject; @@ -80,7 +79,7 @@ public class VoiceRouter { private static RouteDirectionInfo nextRouteDirection; public interface VoiceMessageListener { - void onVoiceMessage(); + void onVoiceMessage(List listCommands, List played); } private List> voiceMessageListeners = new ArrayList<>(); @@ -241,8 +240,8 @@ public class VoiceRouter { } public void announceBackOnRoute() { - CommandBuilder p = getNewCommandPlayerToPlay(); if (announceBackOnRoute) { + CommandBuilder p = getNewCommandPlayerToPlay(); if (p != null) { p.backOnRoute(); } @@ -909,9 +908,12 @@ public class VoiceRouter { private void play(CommandBuilder p) { if (p != null) { - p.play(); + List played = p.play(); + notifyOnVoiceMessage(p.getListCommands(), played); + } else { + notifyOnVoiceMessage(Collections.emptyList(), Collections.emptyList()); } - notifyOnVoiceMessage(); + } private void makeSound() { @@ -941,12 +943,12 @@ public class VoiceRouter { voiceMessageListeners = updateVoiceMessageListeners(new ArrayList<>(voiceMessageListeners), voiceMessageListener, false); } - private void notifyOnVoiceMessage() { - List> voiceMessageListeners = new ArrayList<>(this.voiceMessageListeners); + private void notifyOnVoiceMessage(List listCommands, List played) { + List> voiceMessageListeners = this.voiceMessageListeners; for (WeakReference weakReference : voiceMessageListeners) { VoiceMessageListener lnt = weakReference.get(); if (lnt != null) { - lnt.onVoiceMessage(); + lnt.onVoiceMessage(listCommands, played); } } } diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index 779ec2ca62..7abe7d56ff 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -5,15 +5,12 @@ import java.util.Arrays; import java.util.List; import net.osmand.PlatformUtil; -import net.osmand.plus.R; import net.osmand.plus.routing.data.StreetName; import org.apache.commons.logging.Log; import alice.tuprolog.Struct; import alice.tuprolog.Term; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; public class CommandBuilder { @@ -57,6 +54,7 @@ public class CommandBuilder { protected final CommandPlayer commandPlayer; protected boolean alreadyExecuted = false; private List listStruct = new ArrayList(); + private List listCommands = new ArrayList(); public CommandBuilder(CommandPlayer commandPlayer){ this.commandPlayer = commandPlayer; @@ -71,9 +69,21 @@ public class CommandBuilder { private CommandBuilder addCommand(String name, Object... args){ Struct struct = prepareStruct(name, args); listStruct.add(struct); + listCommands.add(name); + for(Object o : args) { + if(o == null) { + listCommands.add(o.toString()); + } else { + listCommands.add(""); + } + } return this; } + public List getListCommands() { + return listCommands; + } + private Struct prepareStruct(String name, Object... args) { checkState(); Term[] list = new Term[args.length]; @@ -254,8 +264,8 @@ public class CommandBuilder { return alt(prepareStruct(C_ROUTE_RECALC, dist, time), prepareStruct(C_ROUTE_RECALC, dist)); } - public void play(){ - this.commandPlayer.playCommands(this); + public List play(){ + return this.commandPlayer.playCommands(this); } diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java index 814b317074..c09356bfac 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java @@ -10,7 +10,7 @@ public interface CommandPlayer { public CommandBuilder newCommandBuilder(); - public void playCommands(CommandBuilder builder); + public List playCommands(CommandBuilder builder); public void clear(); diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index 52a6d6ac6e..24d4865faa 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -12,15 +12,8 @@ import org.mozilla.javascript.NativeJSON; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class JSCommandBuilder extends CommandBuilder { @@ -216,8 +209,8 @@ public class JSCommandBuilder extends CommandBuilder { } @Override - public void play(){ - this.commandPlayer.playCommands(this); + public List play(){ + return this.commandPlayer.playCommands(this); } @Override diff --git a/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java index 8da4098e3b..decb8e2c09 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSMediaCommandPlayerImpl.java @@ -15,6 +15,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { @@ -44,11 +45,12 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { } @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { if(vrt.isMute()) { - return; + return Collections.emptyList(); } - filesToPlay.addAll(splitAnnouncements(builder.execute())); + List lst = splitAnnouncements(builder.execute()); + filesToPlay.addAll(lst); // If we have not already started to play audio, start. if (mediaPlayer == null) { @@ -63,6 +65,7 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl { } } playQueue(); + return lst; } private List splitAnnouncements(List execute) { diff --git a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java index a3366dec37..d32fe76bcb 100644 --- a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java @@ -67,7 +67,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen // Called from the calculating route thread. @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { if(vrt.isMute()) { StringBuilder bld = new StringBuilder(); for (String s : builder.execute()) { @@ -76,9 +76,11 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen if (ctx != null) { // sendAlertToAndroidWear(ctx, bld.toString()); } - return; + return Collections.emptyList(); } - filesToPlay.addAll(builder.execute()); + List lst = builder.execute(); + + filesToPlay.addAll(lst); // If we have not already started to play audio, start. if (mediaPlayer == null) { @@ -93,6 +95,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen } } playQueue(); + return lst; } synchronized void playQueue() { diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index 6eecf61c18..b6821062eb 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -104,7 +104,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { // Called from the calculating route thread. @Override - public synchronized void playCommands(CommandBuilder builder) { + public synchronized List playCommands(CommandBuilder builder) { final List execute = builder.execute(); //list of strings, the speech text, play it StringBuilder bld = new StringBuilder(); for (String s : execute) { @@ -132,6 +132,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { } else if (ctx != null && vrt.isMute()) { // sendAlertToAndroidWear(ctx, bld.toString()); } + return execute; } @Override