This commit is contained in:
Victor Shcherb 2019-07-09 14:27:34 +02:00
parent 3c15a7a2ff
commit 60a68a4168
11 changed files with 105 additions and 33 deletions

View file

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

View file

@ -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<String> cmds, List<String> 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);
}

View file

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

View file

@ -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<String> cmds;
private List<String> played;
public OnVoiceNavigationParams() {
cmds = new ArrayList<>();
played = new ArrayList<>();
}
public OnVoiceNavigationParams(List<String> cmds, List<String> played) {
this.cmds = cmds;
this.played = played;
}
public OnVoiceNavigationParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<OnVoiceNavigationParams> CREATOR = new Creator<OnVoiceNavigationParams>() {
@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;
}
}

View file

@ -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<String> listCommands, List<String> played);
}
private List<WeakReference<VoiceMessageListener>> 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<String> 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<WeakReference<VoiceMessageListener>> voiceMessageListeners = new ArrayList<>(this.voiceMessageListeners);
private void notifyOnVoiceMessage(List<String> listCommands, List<String> played) {
List<WeakReference<VoiceMessageListener>> voiceMessageListeners = this.voiceMessageListeners;
for (WeakReference<VoiceMessageListener> weakReference : voiceMessageListeners) {
VoiceMessageListener lnt = weakReference.get();
if (lnt != null) {
lnt.onVoiceMessage();
lnt.onVoiceMessage(listCommands, played);
}
}
}

View file

@ -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<Struct> listStruct = new ArrayList<Struct>();
private List<String> listCommands = new ArrayList<String>();
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<String> 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<String> play(){
return this.commandPlayer.playCommands(this);
}

View file

@ -10,7 +10,7 @@ public interface CommandPlayer {
public CommandBuilder newCommandBuilder();
public void playCommands(CommandBuilder builder);
public List<String> playCommands(CommandBuilder builder);
public void clear();

View file

@ -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<String> play(){
return this.commandPlayer.playCommands(this);
}
@Override

View file

@ -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<String> playCommands(CommandBuilder builder) {
if(vrt.isMute()) {
return;
return Collections.emptyList();
}
filesToPlay.addAll(splitAnnouncements(builder.execute()));
List<String> 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<String> splitAnnouncements(List<String> execute) {

View file

@ -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<String> 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<String> 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() {

View file

@ -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<String> playCommands(CommandBuilder builder) {
final List<String> 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