private void Vibrate( Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) { Log.d(TAG, "Vibrate called timeFromStartPlaying = " + timeFromStartPlaying); Log.d("ALARM", "setting vibrate alarm"); int profile = getAlertProfile(ctx); // We use timeFromStartPlaying as a way to force vibrating/ non vibrating... if (profile != ALERT_PROFILE_ASCENDING) { // We start from the non ascending part... timeFromStartPlaying = MAX_ASCENDING; } String title = bgValue + " " + alert.name; String content = "BG LEVEL ALERT: " + bgValue; Intent intent = new Intent(ctx, SnoozeActivity.class); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on) .setContentTitle(title) .setContentText(content) .setContentIntent(notificationIntent(ctx, intent)) .setDeleteIntent(snoozeIntent(ctx)); if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) { if (timeFromStartPlaying >= MAX_VIBRATING) { // Before this, we only vibrate... float volumeFrac = (float) (timeFromStartPlaying - MAX_VIBRATING) / (MAX_ASCENDING - MAX_VIBRATING); volumeFrac = Math.min(volumeFrac, 1); if (profile == ALERT_PROFILE_MEDIUM) { volumeFrac = (float) 0.7; } Log.d(TAG, "Vibrate volumeFrac = " + volumeFrac); boolean isRingTone = EditAlertActivity.isPathRingtone(ctx, alert.mp3_file); if (isRingTone && !overrideSilent) { builder.setSound(Uri.parse(alert.mp3_file)); } else { if (overrideSilent || isLoudPhone(ctx)) { PlayFile(ctx, alert.mp3_file, volumeFrac); } } } } if (profile != ALERT_PROFILE_SILENT && alert.vibrate) { builder.setVibrate(Notifications.vibratePattern); } NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.cancel(Notifications.exportAlertNotificationId); mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build()); }
public synchronized void startAlert( Context ctx, boolean trendingToAlertEnd, AlertType newAlert, String bgValue) { Log.d(TAG, "startAlert called, Threadid " + Thread.currentThread().getId()); if (trendingToAlertEnd) { Log.d(TAG, "startAlert: This alert is trending to it's end will not do anything"); return; } stopAlert(ctx, true, false); int alertIn = newAlert.minutes_between; if (alertIn < 1) { alertIn = 1; } ActiveBgAlert.Create(newAlert.uuid, false, new Date().getTime() + alertIn * 60000); Vibrate(ctx, newAlert, bgValue, newAlert.override_silent_mode, 0); }
// Check the state and alrarm if needed public void ClockTick(Context ctx, boolean trendingToAlertEnd, String bgValue) { if (trendingToAlertEnd) { Log.d(TAG, "ClockTick: This alert is trending to it's end will not do anything"); return; } ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly(); if (activeBgAlert == null) { // Nothing to do ... return; } if (activeBgAlert.ready_to_alarm()) { stopAlert(ctx, false, false); int timeFromStartPlaying = activeBgAlert.getUpdatePlayTime(); AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid); if (alert == null) { Log.w(TAG, "ClockTick: The alert was already deleted... will not play"); ActiveBgAlert.ClearData(); return; } Log.d(TAG, "ClockTick: Playing the alert again"); Vibrate(ctx, alert, bgValue, alert.override_silent_mode, timeFromStartPlaying); } }
public synchronized void stopAlert( Context ctx, boolean ClearData, boolean clearIfSnoozeFinished) { Log.d( TAG, "stopAlert: stop called ClearData " + ClearData + " ThreadID " + Thread.currentThread().getId()); if (ClearData) { ActiveBgAlert.ClearData(); } if (clearIfSnoozeFinished) { ActiveBgAlert.ClearIfSnoozeFinished(); } notificationDismiss(ctx); if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } }