facilitate adjustable BT_SCO_DELAY

This commit is contained in:
sonora 2016-10-29 20:33:31 +02:00
parent 4c48912e16
commit 83e4eea32e
6 changed files with 24 additions and 7 deletions

View file

@ -1205,6 +1205,9 @@ public class OsmandSettings {
public final OsmandPreference<Integer> AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream",
3/*AudioManager.STREAM_MUSIC*/).makeGlobal();
// For now this can be changed only in TestVoiceActivity
public final OsmandPreference<Integer> 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<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal();

View file

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

View file

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

View file

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

View file

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

View file

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