From a5ba0bd7936360c162501fa888875ea842ea99c9 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 9 Sep 2015 22:41:28 +0200 Subject: [PATCH] Fix prolog player --- .../voice/AbstractPrologCommandPlayer.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index 56119afd23..5205d05fc6 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -11,6 +12,7 @@ import java.util.List; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; +import net.osmand.StateChangedListener; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -31,7 +33,7 @@ import alice.tuprolog.Term; import alice.tuprolog.Theory; import alice.tuprolog.Var; -public abstract class AbstractPrologCommandPlayer implements CommandPlayer { +public abstract class AbstractPrologCommandPlayer implements CommandPlayer, StateChangedListener { private static final Log log = PlatformUtil.getLog(AbstractPrologCommandPlayer.class); @@ -56,6 +58,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer { protected int streamType; private int currentVersion; + protected AbstractPrologCommandPlayer(OsmandApplication ctx, String voiceProvider, String configFile, int[] sortedVoiceVersions) throws CommandPlayerException { @@ -91,6 +94,15 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer { "alice.tuprolog.lib.ISOLibrary"/*, "alice.tuprolog.lib.IOLibrary"*/}; } + @Override + public void stateChanged(ApplicationMode change) { + prologSystem.getTheoryManager().retract(new Struct("appMode", new Var())); + prologSystem.getTheoryManager() + .assertA( + new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey() + .toLowerCase())), true, "", true); + } + private void init(String voiceProvider, OsmandSettings settings, String configFile) throws CommandPlayerException { prologSystem.clearTheory(); voiceDir = null; @@ -123,7 +135,11 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer { if(m.getParent() != null) { m = m.getParent(); } - prologSystem.addTheory(new Theory("appMode('"+m.getStringKey().toLowerCase()+"').")); + settings.APPLICATION_MODE.addListener(this); + prologSystem.getTheoryManager() + .assertA( + new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey() + .toLowerCase())), true, "", true); prologSystem.addTheory(new Theory("measure('"+mc.toTTSString()+"').")); prologSystem.addTheory(new Theory(config)); config.close(); @@ -149,6 +165,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer { } } + protected Term solveSimplePredicate(String predicate) { Term val = null;