From 83e4eea32e8e2d569c9282d22c04693af035ff21 Mon Sep 17 00:00:00 2001 From: sonora Date: Sat, 29 Oct 2016 20:33:31 +0200 Subject: [PATCH] facilitate adjustable BT_SCO_DELAY --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 3 +++ .../plus/development/TestVoiceActivity.java | 15 ++++++++++++++- .../src/net/osmand/plus/routing/VoiceRouter.java | 2 +- .../plus/voice/AbstractPrologCommandPlayer.java | 5 +++-- .../osmand/plus/voice/MediaCommandPlayerImpl.java | 2 +- .../osmand/plus/voice/TTSCommandPlayerImpl.java | 4 ++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 8572a8b68e..0fc121d7f3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1205,6 +1205,9 @@ public class OsmandSettings { public final OsmandPreference AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream", 3/*AudioManager.STREAM_MUSIC*/).makeGlobal(); + // For now this can be changed only in TestVoiceActivity + public final OsmandPreference BT_SCO_DELAY = new IntPreference("bt_sco_delay", 1500).makeGlobal().cache(); + // this value string is synchronized with settings_pref.xml preference name public final CommonPreference MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java index dc06cedc55..851e9c16c3 100644 --- a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java @@ -238,6 +238,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity { addButton(ll, " System checks:", builder(p)); addButton(ll, "(11.1) Display BT SCO availability (Phone call audio only)", builder(p).attention("")); + addButton(ll, "(11.2) Tap to change Phone call audio delay (if car stereo cuts off prompts). Default is 1500 ms.", builder(p).attention("")); ll.forceLayout(); } @@ -259,7 +260,19 @@ public class TestVoiceActivity extends OsmandActionBarActivity { public void onClick(View v) { builder.play(); if (description.startsWith("(11.1)") && (((OsmandApplication) getApplication()).getSettings().AUDIO_STREAM_GUIDANCE.get() == 0)) { - Toast.makeText(TestVoiceActivity.this, AbstractPrologCommandPlayer.btScoInit, Toast.LENGTH_LONG).show(); + Toast.makeText(TestVoiceActivity.this, AbstractPrologCommandPlayer.btScoInit + "\nBT SCO init delay: " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + " ms", Toast.LENGTH_LONG).show(); + } + if (description.startsWith("(11.2)") && (((OsmandApplication) getApplication()).getSettings().AUDIO_STREAM_GUIDANCE.get() == 0)) { + if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1000) { + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1500); + } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1500) { + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2000); + } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2000) { + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2500); + } else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2500) { + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1000); + } + Toast.makeText(TestVoiceActivity.this, "BT SCO init delay changed to " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + " ms", Toast.LENGTH_LONG).show(); } } }); diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 203c10913e..60279cc2f6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -176,7 +176,7 @@ public class VoiceRouter { // Trigger close prompts earlier if delayed for BT SCO connection establishment if ((settings.AUDIO_STREAM_GUIDANCE.get() == 0) && !AbstractPrologCommandPlayer.btScoStatus) { - btScoDelayDistance = currentSpeed * (double) AbstractPrologCommandPlayer.BT_SCO_DELAY / 1000; + btScoDelayDistance = currentSpeed * (double) settings.BT_SCO_DELAY.get() / 1000; } if ((dist < etalon + btScoDelayDistance) || ((dist - btScoDelayDistance) / currentSpeed) < (etalon / defSpeed)) { diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index 2bb98edadf..953031f659 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -307,7 +307,8 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat public static boolean btScoStatus = false; - public static final int BT_SCO_DELAY = 1500; + // BT_SCO_DELAY now in Settings. 1500 ms works for most configurations. + //public static final int BT_SCO_DELAY = 1500; // This only needed for init debugging in TestVoiceActivity: public static String btScoInit = ""; @@ -332,7 +333,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat btScoInit = "BT SCO available: YES\nBT SCO initializes: NO\n(" + e.getMessage() + ")"; return false; } - btScoInit = "BT SCO available: YES\nBT SCO initializes: YES\nBT SCO init delay: " + BT_SCO_DELAY + " ms"; + btScoInit = "BT SCO available: YES\nBT SCO initializes: YES"; return true; } else { AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); diff --git a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java index 457d80d688..1e03df6dce 100644 --- a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java @@ -86,7 +86,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen if (ctx != null && ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) { try { log.debug("Delaying MediaCommandPlayer for BT SCO"); - Thread.sleep(BT_SCO_DELAY); + Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get()); } catch (InterruptedException e) { } } diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index d5202ee1c1..55134479d4 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -114,9 +114,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { ttsRequests++; if (android.os.Build.VERSION.SDK_INT < 21) { params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis()); - mTts.playSilence(BT_SCO_DELAY, TextToSpeech.QUEUE_ADD, params); + mTts.playSilence(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, params); } else { - mTts.playSilentUtterance(BT_SCO_DELAY, TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis()); + mTts.playSilentUtterance(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis()); } } }