From b2508cb189131d8fd26cb66df70e9e1c0e85d342 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 15 Jan 2020 18:41:52 +0200 Subject: [PATCH 1/3] voice commands on exits --- .../net/osmand/plus/routing/VoiceRouter.java | 22 +++++++++---------- .../net/osmand/plus/voice/CommandBuilder.java | 8 +++---- .../osmand/plus/voice/JSCommandBuilder.java | 14 ++++++++---- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 4f03920350..35839f0d7f 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -709,12 +709,11 @@ public class VoiceRouter { boolean isPlay = true; ExitInfo exitInfo = next.getExitInfo(); if (tParam != null) { - p.turn(tParam, dist, getSpeakableStreetName(currentSegment, next, true)); -// if (exitInfo != null) { -// p.takeExit(tParam, dist, getSpeakableExitName(next, exitInfo, true)); -// } else { -// p.turn(tParam, dist, getSpeakableStreetName(currentSegment, next, true)); -// } + if (exitInfo != null) { + p.takeExit(tParam, dist, Integer.parseInt(exitInfo.getRef()), getSpeakableExitName(next, exitInfo, true)); + } else { + p.turn(tParam, dist, getSpeakableStreetName(currentSegment, next, true)); + } suppressDest = true; } else if (next.getTurnType().isRoundAbout()) { p.roundAbout(dist, next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next, true)); @@ -783,12 +782,11 @@ public class VoiceRouter { ExitInfo exitInfo = next.getExitInfo(); boolean isplay = true; if (tParam != null) { - p.turn(tParam, getSpeakableStreetName(currentSegment, next, !suppressDest)); -// if (exitInfo != null) { -// p.takeExit(tParam, getSpeakableExitName(next, exitInfo, !suppressDest)); -// } else { -// p.turn(tParam, getSpeakableStreetName(currentSegment, next, !suppressDest)); -// } + if (exitInfo != null) { + p.takeExit(tParam, Integer.parseInt(exitInfo.getRef()), getSpeakableExitName(next, exitInfo, !suppressDest)); + } else { + p.turn(tParam, getSpeakableStreetName(currentSegment, next, !suppressDest)); + } } else if (next.getTurnType().isRoundAbout()) { p.roundAbout(next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next, !suppressDest)); } else if (next.getTurnType().getValue() == TurnType.TU || next.getTurnType().getValue() == TurnType.TRU) { diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index 65a28b70e6..98ea123a30 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -179,12 +179,12 @@ public class CommandBuilder { return alt(prepareStruct(C_TURN, param, dist, streetName), prepareStruct(C_TURN, param, dist)); } - public CommandBuilder takeExit(String turnType, StreetName streetName) { - return alt(prepareStruct(C_TAKE_EXIT, turnType, streetName), prepareStruct(C_TAKE_EXIT, turnType)); + public CommandBuilder takeExit(String turnType, int exit, StreetName streetName) { + return alt(prepareStruct(C_TAKE_EXIT, turnType, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType,exit)); } - public CommandBuilder takeExit(String turnType, double dist, StreetName streetName) { - return alt(prepareStruct(C_TAKE_EXIT, turnType, dist, streetName), prepareStruct(C_TAKE_EXIT, turnType, dist)); + public CommandBuilder takeExit(String turnType, double dist, int exit, StreetName streetName) { + return alt(prepareStruct(C_TAKE_EXIT, turnType, dist, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType, dist, exit)); } /** diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index dfdfcea29a..bbc705943a 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -65,6 +65,10 @@ public class JSCommandBuilder extends CommandBuilder { return this; } + private boolean isCommandExist(String name) { + return jsScope.get(name) instanceof Function; + } + public JSCommandBuilder goAhead(){ return goAhead(-1, new StreetName()); } @@ -115,12 +119,14 @@ public class JSCommandBuilder extends CommandBuilder { return addCommand(C_TURN, param, dist, convertStreetName(streetName)); } - public JSCommandBuilder takeExit(String turnType, StreetName streetName) { - return takeExit(turnType, -1, streetName); + public JSCommandBuilder takeExit(String turnType, int exit, StreetName streetName) { + return takeExit(turnType, -1, exit, streetName); } - public JSCommandBuilder takeExit(String turnType, double dist, StreetName streetName) { - return addCommand(C_TAKE_EXIT, turnType, dist, convertStreetName(streetName)); + public JSCommandBuilder takeExit(String turnType, double dist, int exit, StreetName streetName) { + return isCommandExist(C_TAKE_EXIT) ? + addCommand(C_TAKE_EXIT, turnType, dist, exit, convertStreetName(streetName)) : + addCommand(C_TURN, turnType, dist, convertStreetName(streetName)); } /** From be31b2b2fd6db222131d99783bee68a6b5a6f081 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 16 Jan 2020 10:16:24 +0200 Subject: [PATCH 2/3] reformat --- OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index 98ea123a30..481b263d9a 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -180,7 +180,7 @@ public class CommandBuilder { } public CommandBuilder takeExit(String turnType, int exit, StreetName streetName) { - return alt(prepareStruct(C_TAKE_EXIT, turnType, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType,exit)); + return alt(prepareStruct(C_TAKE_EXIT, turnType, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType, exit)); } public CommandBuilder takeExit(String turnType, double dist, int exit, StreetName streetName) { From 86844c64a1c3b3c51f4b5d54334c757947b527d9 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 16 Jan 2020 10:32:56 +0200 Subject: [PATCH 3/3] refactor --- OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index bbc705943a..057ba29a32 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -65,7 +65,7 @@ public class JSCommandBuilder extends CommandBuilder { return this; } - private boolean isCommandExist(String name) { + private boolean isJSCommandExists(String name) { return jsScope.get(name) instanceof Function; } @@ -124,7 +124,7 @@ public class JSCommandBuilder extends CommandBuilder { } public JSCommandBuilder takeExit(String turnType, double dist, int exit, StreetName streetName) { - return isCommandExist(C_TAKE_EXIT) ? + return isJSCommandExists(C_TAKE_EXIT) ? addCommand(C_TAKE_EXIT, turnType, dist, exit, convertStreetName(streetName)) : addCommand(C_TURN, turnType, dist, convertStreetName(streetName)); }