Restore original SoundManager
Some checks failed
Build Android APK / build (push) Failing after 3m1s

This commit is contained in:
2026-04-17 13:52:10 +02:00
parent d4b079bc75
commit e69a617a96

View File

@@ -17,44 +17,38 @@ public class SoundManager {
private ToneGenerator toneGenerator; private ToneGenerator toneGenerator;
private Handler handler; private Handler handler;
private boolean enabled = true; private boolean enabled = true;
private boolean isPlaying = false;
private Runnable stopToneRunnable;
public SoundManager(Context context) { public SoundManager(Context context) {
// ToneGenerator.STREAM_MUSIC para compatibilidad API 18+ // ToneGenerator.STREAM_MUSIC para compatibilidad API 18+
toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, VOLUME); toneGenerator = new ToneGenerator(AudioManager.STREAM_MUSIC, VOLUME);
handler = new Handler(Looper.getMainLooper()); handler = new Handler(Looper.getMainLooper());
stopToneRunnable = () -> isPlaying = false;
} }
/** /**
* Sonido de click de boton - tono corto y agudo * Sonido de click de boton - tono corto y agudo
*/ */
public void playButtonClick() { public void playButtonClick() {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true; // Tono DTMF 6 - sonido tipo boton tactil
toneGenerator.startTone(ToneGenerator.TONE_DTMF_6, 80); toneGenerator.startTone(ToneGenerator.TONE_DTMF_6, 80);
handler.postDelayed(stopToneRunnable, 80);
} }
/** /**
* Sonido de exito - secuencia ascendente * Sonido de exito - secuencia ascendente
*/ */
public void playSuccess() { public void playSuccess() {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true; // Tono de confirmacion propositivo
toneGenerator.startTone(ToneGenerator.TONE_PROP_ACK, 150); toneGenerator.startTone(ToneGenerator.TONE_PROP_ACK, 150);
handler.postDelayed(stopToneRunnable, 150);
} }
/** /**
* Sonido de fallo - tono bajo grave * Sonido de fallo - tono bajo grave
*/ */
public void playFailure() { public void playFailure() {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true; // Tono de error
toneGenerator.startTone(ToneGenerator.TONE_PROP_NACK, 200); toneGenerator.startTone(ToneGenerator.TONE_PROP_NACK, 200);
handler.postDelayed(stopToneRunnable, 200);
} }
/** /**
@@ -62,8 +56,7 @@ public class SoundManager {
* Usa diferentes tonos DTMF para cada direccion * Usa diferentes tonos DTMF para cada direccion
*/ */
public void playTone(int direction) { public void playTone(int direction) {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true;
int tone; int tone;
switch (direction) { switch (direction) {
@@ -83,27 +76,22 @@ public class SoundManager {
tone = ToneGenerator.TONE_DTMF_0; tone = ToneGenerator.TONE_DTMF_0;
} }
toneGenerator.startTone(tone, 100); toneGenerator.startTone(tone, 100);
handler.postDelayed(stopToneRunnable, 100);
} }
/** /**
* Tono de inicio de secuencia * Tono de inicio de secuencia
*/ */
public void playSequenceStart() { public void playSequenceStart() {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true;
toneGenerator.startTone(ToneGenerator.TONE_SUP_DIAL, 100); toneGenerator.startTone(ToneGenerator.TONE_SUP_DIAL, 100);
handler.postDelayed(stopToneRunnable, 100);
} }
/** /**
* Tono de alerta/peligro * Tono de alerta/peligro
*/ */
public void playAlert() { public void playAlert() {
if (!enabled || toneGenerator == null || isPlaying) return; if (!enabled || toneGenerator == null) return;
isPlaying = true;
toneGenerator.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 150); toneGenerator.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 150);
handler.postDelayed(stopToneRunnable, 150);
} }
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {