- Simplify the audio, since we don't trigger the alarm if in a call.

This commit is contained in:
Timothy Allen 2014-04-14 00:10:15 +02:00
parent 36b796fd13
commit fb886aabe9
1 changed files with 7 additions and 11 deletions

View File

@ -27,7 +27,6 @@ public class AlarmKlaxon {
/** /**
* *
* TODO allow user to select alarm tone * 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); telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
initialCallState = telephonyManager.getCallState(); initialCallState = telephonyManager.getCallState();
boolean inTelephoneCall = initialCallState != TelephonyManager.CALL_STATE_IDLE;
phoneStateListener = new PhoneStateListener() { phoneStateListener = new PhoneStateListener() {
@Override @Override
public void onCallStateChanged(int state, String ignored) { 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 // which kills the alarm. Check against the initial call state so
// we don't kill the alarm during a call. // we don't kill the alarm during a call.
if (state != TelephonyManager.CALL_STATE_IDLE && state != initialCallState) { 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 { try {
if (inTelephoneCall) { mediaPlayer.setDataSource(context, alarmNoise);
Log.d("AlarmKlaxon", "Using the in-call alarm"); startAudio(context);
mediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
setDataSourceFromResource(context, mediaPlayer, R.raw.in_call_alarm);
} else {
mediaPlayer.setDataSource(context, alarmNoise);
startAudio(context);
}
} catch (Exception ex) { } catch (Exception ex) {
// The alarmNoise may be on the sd card which could be busy right // The alarmNoise may be on the sd card which could be busy right
// now. Use the fallback ringtone. // now. Use the fallback ringtone.