Separate settings for "move sound" and "move speech"

This commit is contained in:
Peter Osterlund 2020-01-26 08:51:46 +01:00
parent d6e7771eab
commit 979b23cf02
17 changed files with 37 additions and 47 deletions

View File

@ -221,6 +221,7 @@ public class DroidFish extends Activity
private boolean leftHanded;
private String moveAnnounceType;
private boolean moveSoundEnabled;
private MediaPlayer moveSound;
private boolean vibrateEnabled;
private boolean animateMoves;
@ -1290,6 +1291,15 @@ public class DroidFish extends Activity
statusFontSize = Math.min(statusFontSize, 16);
status.setTextSize(statusFontSize);
moveAnnounceType = settings.getString("moveAnnounceType", "off");
moveSoundEnabled = settings.getBoolean("moveSoundEnabled", false);
if (moveAnnounceType.equals("sound")) {
moveAnnounceType = "off";
moveSoundEnabled = true;
Editor editor = settings.edit();
editor.putString("moveAnnounceType", moveAnnounceType);
editor.putBoolean("moveSoundEnabled", moveSoundEnabled);
editor.apply();
}
initSpeech();
vibrateEnabled = settings.getBoolean("vibrateEnabled", false);
animateMoves = settings.getBoolean("animateMoves", true);
@ -3690,8 +3700,9 @@ public class DroidFish extends Activity
@Override
public void movePlayed(Position pos, Move move, boolean computerMove) {
if ("sound".equals(moveAnnounceType)) {
if (computerMove) {
if (moveAnnounceType.startsWith("speech_")) {
speech.say(pos, move, moveSoundEnabled && computerMove);
} else if (moveSoundEnabled && computerMove) {
if (moveSound != null)
moveSound.release();
try {
@ -3701,9 +3712,6 @@ public class DroidFish extends Activity
} catch (NotFoundException ignore) {
}
}
} else if (moveAnnounceType.startsWith("speech_")) {
speech.say(pos, move);
}
if (vibrateEnabled && computerMove) {
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);

View File

@ -34,7 +34,8 @@ import android.widget.Toast;
public class Speech {
private TextToSpeech tts;
private boolean initialized = false;
private String toSpeak = null;
private String toSpeak = null; // Pending text to speak after initialization
private boolean toPlaySound = false; // Pending sound to play after initialization
public enum Language {
EN, // English
@ -82,7 +83,7 @@ public class Speech {
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
lang = Language.fromString(langStr);
tts.addEarcon("[move]", "org.petero.droidfish", R.raw.movesound);
say(toSpeak);
say(toSpeak, toPlaySound);
break;
case TextToSpeech.LANG_MISSING_DATA:
toast = R.string.tts_data_missing;
@ -102,16 +103,17 @@ public class Speech {
}
@SuppressWarnings("deprecation")
private void say(String text) {
private void say(String text, boolean playSound) {
if (initialized) {
if (lang != Language.NONE && text != null) {
if (!tts.isSpeaking())
if (playSound && !tts.isSpeaking())
tts.playEarcon("[move]", TextToSpeech.QUEUE_ADD, null);
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
}
toSpeak = null;
} else {
toSpeak = text;
toPlaySound = playSound;
}
}
@ -133,11 +135,11 @@ public class Speech {
}
/** Convert move "move" in position "pos" to a sentence and speak it. */
public void say(Position pos, Move move) {
public void say(Position pos, Move move, boolean playSound) {
String s = moveToText(pos, move, lang);
// System.out.printf("%.3f Speech.say(): %s\n", System.currentTimeMillis() * 1e-3, s);
if (!s.isEmpty())
say(s);
say(s, playSound);
}
/** Convert move "move" in position "pos" to a sentence that can be spoken. */

View File

@ -788,14 +788,12 @@
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Выкл.</item>
<item>Прайграванне гуку</item>
<item>Па-ангельску</item>
<item>Па-нямецку</item>
<item>Па-іспанску</item>

View File

@ -788,14 +788,12 @@ Um gegebenenfalls Strom zu sparen, ist es empfehlenswert, dass Sie diese Paramet
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Keine Benachrichtigung</item>
<item>Benachrichtigungston</item>
<item>Zugansage auf Englisch</item>
<item>Zugansage auf Deutsch</item>
<item>Zugansage auf Spanisch</item>

View File

@ -788,14 +788,12 @@ Si está usted utilizando la batería, se recomienda que cambie los ajustes para
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Anuncio de movimientos desconectado</item>
<item>Aviso de movimiento</item>
<item>Texto hablado en inglés</item>
<item>Texto hablado en alemán</item>
<item>Texto hablado en español</item>

View File

@ -788,14 +788,12 @@ Lorsque que vous êtes sur batterie, il est recommandé de changer les paramètr
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Off</item>
<item>Play sound</item>
<item>English Speech</item>
<item>German Speech</item>
<item>Spanish Speech</item>

View File

@ -788,14 +788,12 @@ Se l\'alimentazione è a batteria, è consigliabile modificare le impostazioni p
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Spento</item>
<item>Riproduci un suono</item>
<item>Annuncio vocale in inglese</item>
<item>Annuncio vocale in tedesco</item>
<item>Annuncio vocale in Spagnolo</item>

View File

@ -792,14 +792,12 @@ DroidFish는 백그라운드에 실행 중인 상태에서 다음과 같이 설
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>끄기</item>
<item>사운드 재생</item>
<item>영어 말하기</item>
<item>독일어 말하기</item>
<item>스페인어 말하기</item>

View File

@ -788,14 +788,12 @@ Als uw telefoon op batterij werkt is het aan te raden om deze instellingen te wi
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Off</item>
<item>Play sound</item>
<item>English Speech</item>
<item>German Speech</item>
<item>Spanish Speech</item>

View File

@ -788,14 +788,12 @@ Jeśli pracujesz na baterii, zalecana jest zmiana ustawień, w celu oszczędzani
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Wyłączone</item>
<item>Odtwórz dźwięk</item>
<item>Wymowa angielska</item>
<item>Mowa niemiecka</item>
<item>Mowa hiszpańska</item>

View File

@ -788,14 +788,12 @@ Se você está usando somente a bateria, recomenda-se que você mude as configur
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Desligado</item>
<item>Tocar som</item>
<item>Voz em inglês</item>
<item>Voz em alemão</item>
<item>Voz em espanhol</item>

View File

@ -788,14 +788,12 @@
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Выкл.</item>
<item>Воспроизведение звука</item>
<item>По-английски</item>
<item>По-немецки</item>
<item>По-испански</item>

View File

@ -788,14 +788,12 @@ Pil gücüyle çalışıyorsanız, pil gücünden tasarruf etmek için ayarları
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Kapalı</item>
<item>Ses çal</item>
<item>İngilizce konuşma</item>
<item>Almanca konuşma</item>
<item>İspanyolca konuşma</item>

View File

@ -788,14 +788,12 @@
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Викл.</item>
<item>Відтворення звуку</item>
<item>Англійська вимова</item>
<item>Німецька вимова</item>
<item>Іспанська вимова</item>

View File

@ -788,14 +788,12 @@
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>关闭</item>
<item>播放声音</item>
<item>英语语音</item>
<item>德语语音</item>
<item>西班牙语音</item>

View File

@ -303,8 +303,10 @@ If you are running on battery power, it is recommended that you change settings
<string name="prefs_autoScrollTitle_summary">Auto scroll titlebar if player names are too long</string>
<string name="prefs_quickMoveInput_title">Quick Move Input</string>
<string name="prefs_quickMoveInput_summary">From and To squares can be touched in any order. Move is played as soon as uniquely defined.</string>
<string name="prefs_moveAnnounceType_title">Move Announcement</string>
<string name="prefs_moveAnnounceType_summary">Announcement sound when computer makes a move</string>
<string name="prefs_moveSoundEnabled_title">Move sound</string>
<string name="prefs_moveSoundEnabled_summary">Play sound when computer makes a move</string>
<string name="prefs_moveAnnounceType_title">Speak moves</string>
<string name="prefs_moveAnnounceType_summary">Speak when computer makes a move</string>
<string name="prefs_vibrateEnabled_title">Enable Vibration</string>
<string name="prefs_vibrateEnabled_summary">Vibrate when computer makes a move</string>
<string name="prefs_fullScreenMode_title">Fullscreen Mode</string>
@ -787,14 +789,12 @@ If you are running on battery power, it is recommended that you change settings
</string-array>
<string-array name="move_announce_type_values">
<item>off</item>
<item>sound</item>
<item>speech_en</item>
<item>speech_de</item>
<item>speech_es</item>
</string-array>
<string-array name="move_announce_type_texts">
<item>Off</item>
<item>Play sound</item>
<item>English Speech</item>
<item>German Speech</item>
<item>Spanish Speech</item>

View File

@ -173,6 +173,12 @@
android:summary="@string/prefs_vibrateEnabled_summary"
android:defaultValue="false">
</CheckBoxPreference>
<CheckBoxPreference
android:key="moveSoundEnabled"
android:title="@string/prefs_moveSoundEnabled_title"
android:summary="@string/prefs_moveSoundEnabled_summary"
android:defaultValue="false">
</CheckBoxPreference>
<ListPreference
android:key="moveAnnounceType"
android:title="@string/prefs_moveAnnounceType_title"