From fb886aabe939359a18e8cf013824e58b8747dfee Mon Sep 17 00:00:00 2001 From: tim Date: Mon, 14 Apr 2014 00:10:15 +0200 Subject: [PATCH] - Simplify the audio, since we don't trigger the alarm if in a call. --- .../org/treehouse/hypoalarm/AlarmKlaxon.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmKlaxon.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmKlaxon.java index 99cb422..e4a8cb5 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmKlaxon.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmKlaxon.java @@ -27,7 +27,6 @@ public class AlarmKlaxon { /** * * TODO allow user to select alarm tone - * TODO prevent alarm from being ignored or snoozing if a call comes in? * */ @@ -37,7 +36,6 @@ public class AlarmKlaxon { telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); initialCallState = telephonyManager.getCallState(); - boolean inTelephoneCall = initialCallState != TelephonyManager.CALL_STATE_IDLE; phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String ignored) { @@ -46,7 +44,11 @@ public class AlarmKlaxon { // which kills the alarm. Check against the initial call state so // we don't kill the alarm during a call. if (state != TelephonyManager.CALL_STATE_IDLE && state != initialCallState) { - stopAudio(context); + if (mediaPlayer != null) { + mediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME); + } + // or just stop the audio entirely... + //stopAudio(context); } } }; @@ -68,14 +70,8 @@ public class AlarmKlaxon { }); try { - if (inTelephoneCall) { - Log.d("AlarmKlaxon", "Using the in-call alarm"); - mediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME); - setDataSourceFromResource(context, mediaPlayer, R.raw.in_call_alarm); - } else { - mediaPlayer.setDataSource(context, alarmNoise); - startAudio(context); - } + mediaPlayer.setDataSource(context, alarmNoise); + startAudio(context); } catch (Exception ex) { // The alarmNoise may be on the sd card which could be busy right // now. Use the fallback ringtone.