public static void Create(String alert_uuid, boolean is_snoozed, Long next_alert_at) { Log.d(TAG, "ActiveBgAlert Create called"); fixUpTable(); ActiveBgAlert aba = getOnly(); if (aba == null) { aba = new ActiveBgAlert(); } aba.alert_uuid = alert_uuid; aba.is_snoozed = is_snoozed; aba.last_alerted_at = 0L; aba.next_alert_at = next_alert_at; aba.alert_started_at = new Date().getTime(); aba.save(); }
public static AlertType alertTypegetOnly() { return alertTypegetOnly(getOnly()); }
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, false); // also don't cancel notification final int minutesFromStartPlaying = activeBgAlert.getAndUpdateAlertingMinutes(); final AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid); if (alert == null) { Log.d(TAG, "ClockTick: The alert was already deleted... will not play"); ActiveBgAlert.ClearData(); return; } Log.d(TAG,"ClockTick: Playing the alert again"); long nextAlertTime = alert.getNextAlertTime(ctx); activeBgAlert.updateNextAlertAt(nextAlertTime); VibrateNotifyMakeNoise(ctx, alert, bgValue, alert.override_silent_mode, minutesFromStartPlaying); AlertTracker.evaluate(); } }
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, false); // also don't cancel notification int timeFromStartPlaying = activeBgAlert.getUpdatePlayTime(); AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid); if (alert == null) { Log.d(TAG, "ClockTick: The alert was already deleted... will not play"); ActiveBgAlert.ClearData(); return; } Log.d(TAG,"ClockTick: Playing the alert again"); long nextAlertTime = alert.getNextAlertTime(ctx); activeBgAlert.updateNextAlertAt(nextAlertTime); Vibrate(ctx, alert, bgValue, alert.override_silent_mode, timeFromStartPlaying); } }
public synchronized void PreSnooze(Context ctx, String uuid, int repeatTime) { Log.i(TAG, "PreSnooze called repeatTime = "+ repeatTime); stopAlert(ctx, true, false); ActiveBgAlert.Create(uuid, true, new Date().getTime() + repeatTime * 60000); ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly(); if (activeBgAlert == null) { Log.wtf(TAG, "Just created the alert, where did it go..."); return; } activeBgAlert.snooze(repeatTime); }
public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) { Log.i(TAG, "Snooze called repeatTime = " + repeatTime); stopAlert(ctx, false, false); ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly(); if (activeBgAlert == null) { Log.e(TAG, "Error, snooze was called but no alert is active."); //KS TODO if (from_interactive) GcmActivity.sendSnoozeToRemote(); return; } if (repeatTime == -1) { // try to work out default AlertType alert = ActiveBgAlert.alertTypegetOnly(); if (alert != null) { repeatTime = alert.default_snooze; Log.d(TAG, "Selecting default snooze time: " + repeatTime); } else { repeatTime = 30; // pick a number if we cannot even find the default Log.e(TAG, "Cannot even find default snooze time so going with: " + repeatTime); } } activeBgAlert.snooze(repeatTime); //KS if (from_interactive) GcmActivity.sendSnoozeToRemote(); }
void displayStatus() { ActiveBgAlert aba = ActiveBgAlert.getOnly(); AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly(); } else { sendRemoteSnooze.setVisibility(View.GONE); if(!aba.ready_to_alarm()) { status = MessageFormat.format("Active alert exists named \"{0}\" {1,choice,0#Alert will rerise at|1#Alert snoozed until} {2,time} ({3} minutes left)", activeBgAlert.name, aba.is_snoozed ? 1 : 0 , new Date(aba.next_alert_at),(aba.next_alert_at - now) / 60000);
public static boolean currentlyAlerting() { final ActiveBgAlert activeBgAlert = getOnly(); return activeBgAlert != null && !activeBgAlert.is_snoozed; }
public static boolean alertSnoozeOver() { ActiveBgAlert activeBgAlert = getOnly(); if (activeBgAlert == null) { // no alert exists, so snoozing is over... (this should not happen) Log.wtf(TAG, "ActiveBgAlert getOnly returning null (we have just checked it)"); return true; } return activeBgAlert.ready_to_alarm(); }
public synchronized void stopAlert(Context ctx, boolean ClearData, boolean clearIfSnoozeFinished, boolean cancelNotification) { Log.d(TAG, "stopAlert: stop called ClearData " + ClearData + " ThreadID " + Thread.currentThread().getId()); if (ClearData) { ActiveBgAlert.ClearData(); } if (clearIfSnoozeFinished) { ActiveBgAlert.ClearIfSnoozeFinished(); } if (cancelNotification) { notificationDismiss(ctx); } if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } revertCurrentVolume(ctx); }
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly(); if (activeBgAlert == null) { Log.d(TAG, "FileBasedNotifications we have a new alert, starting to play it... " + newAlert.name); boolean alertSnoozeOver = ActiveBgAlert.alertSnoozeOver(); if (alertSnoozeOver) { Log.d(TAG, "FileBasedNotifications we had two alerts, the snoozed one is over, we fall down to deleting the snoozed and staring the new");
public static AlertType alertTypegetOnly() { ActiveBgAlert aba = getOnly(); if (aba == null) { Log.v(TAG, "ActiveBgAlert: alertTypegetOnly returning null"); return null; } AlertType alert = AlertType.get_alert(aba.alert_uuid); if(alert == null) { Log.d(TAG, "alertTypegetOnly did not find the active alert as part of existing alerts. returning null"); // removing the alert to be in a better state. ClearData(); return null; } if(!alert.uuid.equals(aba.alert_uuid)) { Log.wtf(TAG, "AlertType.get_alert did not return the correct alert"); } return alert; }
public static ActiveBgAlert getOnly() { try { ActiveBgAlert aba = new Select() .from(ActiveBgAlert.class) .orderBy("_ID asc") .executeSingle(); if (aba != null) { Log.v(TAG, "ActiveBgAlert getOnly aba = " + aba.toString()); } else { Log.v(TAG, "ActiveBgAlert getOnly returning null"); } return aba; } catch (android.database.sqlite.SQLiteException e) { Log.d(TAG,"ActiveBgAlert rebuilding table strcuture"); fixUpTable(); return null; } }
public static AlertType alertTypegetOnly(final ActiveBgAlert aba) { if (aba == null) { Log.v(TAG, "ActiveBgAlert: alertTypegetOnly returning null"); return null; } AlertType alert = AlertType.get_alert(aba.alert_uuid); if(alert == null) { Log.d(TAG, "alertTypegetOnly did not find the active alert as part of existing alerts. returning null"); // removing the alert to be in a better state. ClearData(); return null; } if(!alert.uuid.equals(aba.alert_uuid)) { Log.wtf(TAG, "AlertType.get_alert did not return the correct alert"); } return alert; }
private void snoozeBgAlert() { AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly(); int snooze = 30; if(activeBgAlert != null) { if(activeBgAlert.default_snooze != 0) { snooze = activeBgAlert.default_snooze; } else { snooze = SnoozeActivity.getDefaultSnooze(activeBgAlert.above); } } AlertPlayer.getPlayer().Snooze(getApplicationContext(), snooze); }
public synchronized void startAlert(Context ctx, boolean trendingToAlertEnd, AlertType newAlert, String bgValue , boolean start_snoozed) { 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); long nextAlertTime = newAlert.getNextAlertTime(ctx); ActiveBgAlert.Create(newAlert.uuid, start_snoozed, nextAlertTime); if (!start_snoozed) Vibrate(ctx, newAlert, bgValue, newAlert.override_silent_mode, 0); }
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, false); // also don't cancel notification final int minutesFromStartPlaying = activeBgAlert.getAndUpdateAlertingMinutes(); final AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid); if (alert == null) { Log.d(TAG, "ClockTick: The alert was already deleted... will not play"); ActiveBgAlert.ClearData(); return; } Log.d(TAG,"ClockTick: Playing the alert again"); long nextAlertTime = alert.getNextAlertTime(ctx); activeBgAlert.updateNextAlertAt(nextAlertTime); VibrateNotifyMakeNoise(ctx, alert, bgValue, alert.override_silent_mode, minutesFromStartPlaying); AlertTracker.evaluate(); } }
public synchronized void PreSnooze(Context ctx, String uuid, int repeatTime) { Log.i(TAG, "PreSnooze called repeatTime = "+ repeatTime); stopAlert(ctx, true, false); ActiveBgAlert.Create(uuid, true, new Date().getTime() + repeatTime * 60000); ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly(); if (activeBgAlert == null) { Log.wtf(TAG, "Just created the alert, where did it go..."); return; } activeBgAlert.snooze(repeatTime); }