public static void add_alert( String uuid, String name, boolean above, double threshold, boolean all_day, int minutes_between, String mp3_file, int start_time_minutes, int end_time_minutes, boolean override_silent_mode, int snooze, boolean vibrate, boolean active) { AlertType at = new AlertType(); at.name = name; at.above = above; at.threshold = threshold; at.all_day = all_day; at.minutes_between = minutes_between; at.uuid = uuid != null? uuid : UUID.randomUUID().toString(); at.active = active; at.mp3_file = mp3_file; at.start_time_minutes = start_time_minutes; at.end_time_minutes = end_time_minutes; at.override_silent_mode = override_silent_mode; at.default_snooze = snooze; at.vibrate = vibrate; at.save(); }
public static void testAll(Context context) { remove_all(); add_alert(null, "high alert 1", true, 180, true, 10, null, 0, 0, true, 20, true, true); add_alert(null, "high alert 2", true, 200, true, 10, null, 0, 0, true, 20, true, true); add_alert(null, "high alert 3", true, 220, true, 10, null, 0, 0, true, 20, true, true); print_all(); AlertType a1 = get_highest_active_alert(context, 190); Log.d(TAG, "a1 = " + a1.toString()); AlertType a2 = get_highest_active_alert(context, 210); Log.d(TAG, "a2 = " + a2.toString()); AlertType a3 = get_alert(a1.uuid); Log.d(TAG, "a1 == a3 ? need to see true " + (a1==a3) + a1 + " " + a3); add_alert(null, "low alert 1", false, 80, true, 10, null, 0, 0, true, 20, true, true); add_alert(null, "low alert 2", false, 60, true, 10, null, 0, 0, true, 20, true, true); AlertType al1 = get_highest_active_alert(context, 90); Log.d(TAG, "al1 should be null " + al1); al1 = get_highest_active_alert(context, 80); Log.d(TAG, "al1 = " + al1.toString()); AlertType al2 = get_highest_active_alert(context, 50); Log.d(TAG, "al2 = " + al2.toString()); Log.d(TAG, "HigherAlert(a1, a2) = a1?" + (HigherAlert(a1,a2) == a2)); Log.d(TAG, "HigherAlert(al1, al2) = al1?" + (HigherAlert(al1,al2) == al2)); Log.d(TAG, "HigherAlert(a1, al1) = al1?" + (HigherAlert(a1,al1) == al1)); Log.d(TAG, "HigherAlert(al1, a2) = al1?" + (HigherAlert(al1,a2) == al1)); // Make sure we do not influance on real data... remove_all(); }
public boolean should_alarm(double bg) { // Log.e(TAG, "should_alarm called active = " + active ); if(in_time_frame() && active && (beyond_threshold(bg) || trending_to_threshold(bg))) { return true; } else { return false; } }
boolean active) { fixUpTable(); final AlertType at = get_alert(uuid); if (at == null) { Log.e(TAG, "Alert Type null during update"); at.default_snooze = snooze; at.vibrate = vibrate; at.save();
AlertType newAlert = AlertType.get_highest_active_alert(context, calculated_value); boolean opositeDirection = AlertType.OpositeDirection(activeBgAlert, newAlert); if(!opositeDirection) { AlertType newHigherAlert = AlertType.HigherAlert(activeBgAlert, newAlert); if ((newHigherAlert == activeBgAlert)) {
int timeStart = AlertType.toTime(startHour, startMinute); int timeEnd = AlertType.toTime(endHour, endMinute); if(timeStart == AlertType.toTime(23, 59)) { timeStart++; if(timeEnd == AlertType.toTime(23, 59)) { timeEnd++; if(timeStart == AlertType.toTime(0, 0) && timeEnd == AlertType.toTime(24, 0)) { allDay = true; AlertType.update_alert(uuid, alertText.getText().toString(), above, threshold, allDay, alertReraise, mp3_file, timeStart, timeEnd, overrideSilentMode, defaultSnooze, vibrate, !disabled); } else { AlertType.add_alert(null, alertText.getText().toString(), above, threshold, allDay, alertReraise, mp3_file, timeStart, timeEnd, overrideSilentMode, defaultSnooze, vibrate, !disabled);
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); } }
if(lowAlert.should_alarm(bg-offset)) { return filter_alert_on_stale(lowAlert,prefs); if(HighAlert.should_alarm(bg)) { return filter_alert_on_stale(HighAlert,prefs);
ArrayList<HashMap<String, String>> createAlertsMap(boolean above) { ArrayList<HashMap<String, String>> feedList = new ArrayList<HashMap<String, String>>(); List<AlertType> alerts = AlertType.getAll(above); for (AlertType alert : alerts) { Log.d(TAG, alert.toString()); feedList.add(createAlertMap(alert)); } return feedList; }
public static void remove_all() { fixUpTable(); List<AlertType> Alerts = new Select() .from(AlertType.class) .execute(); for (AlertType alert : Alerts) { alert.delete(); } ActiveBgAlert.ClearData(); }
public static boolean activeLowAlertExists() { List<AlertType> alerts = getAll(false); if(alerts == null) { return false; } for (AlertType alert : alerts) { if(alert.active) { return true; } } return false; }
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 static void testAlert( String name, boolean above, double threshold, boolean all_day, int minutes_between, String mp3_file, int start_time_minutes, int end_time_minutes, boolean override_silent_mode, int snooze, boolean vibrate, Context context) { AlertType at = new AlertType(); at.name = name; at.above = above; at.threshold = threshold; at.all_day = all_day; at.minutes_between = minutes_between; at.uuid = UUID.randomUUID().toString(); at.active = true; at.mp3_file = mp3_file; at.start_time_minutes = start_time_minutes; at.end_time_minutes = end_time_minutes; at.override_silent_mode = override_silent_mode; at.default_snooze = snooze; at.vibrate = vibrate; AlertPlayer.getPlayer().startAlert(context, false, at, "TEST", false); }
public static void remove_all() { List<AlertType> Alerts = new Select() .from(AlertType.class) .execute(); for (AlertType alert : Alerts) { alert.delete(); } ActiveBgAlert.ClearData(); }
private void migrateBGAlerts() { // Migrate away from old style notifications to Tzachis new Alert system // AlertType.CreateStaticAlerts(); // jamorham weird problem auto-calibrations if(prefs.getBoolean("bg_notifications", true)){ double highMark = Double.parseDouble(prefs.getString("highValue", "170"))+54; // make default alert not too fatiguing double lowMark = Double.parseDouble(prefs.getString("lowValue", "70")); boolean doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0); if(!doMgdl) { highMark = highMark * Constants.MMOLL_TO_MGDL; lowMark = lowMark * Constants.MMOLL_TO_MGDL; } boolean bg_sound_in_silent = prefs.getBoolean("bg_sound_in_silent", false); String bg_notification_sound = prefs.getString("bg_notification_sound", "content://settings/system/notification_sound"); int bg_high_snooze = Integer.parseInt(prefs.getString("bg_snooze", Integer.toString(SnoozeActivity.getDefaultSnooze(true)))); int bg_low_snooze = Integer.parseInt(prefs.getString("bg_snooze", Integer.toString(SnoozeActivity.getDefaultSnooze(false)))); AlertType.add_alert(null, mContext.getString(R.string.high_alert), true, highMark, true, 1, bg_notification_sound, 0, 0, bg_sound_in_silent, bg_high_snooze, true, true); AlertType.add_alert(null, mContext.getString(R.string.low_alert), false, lowMark, true, 1, bg_notification_sound, 0, 0, bg_sound_in_silent, bg_low_snooze, true, true); prefs.edit().putBoolean("bg_notifications", false).apply(); } }
boolean active) { fixUpTable(); final AlertType at = get_alert(uuid); if (at == null) { Log.e(TAG, "Alert Type null during update"); at.default_snooze = snooze; at.vibrate = vibrate; at.save();
AlertType newAlert = AlertType.get_highest_active_alert(context, calculated_value); boolean opositeDirection = AlertType.OpositeDirection(activeBgAlert, newAlert); if(!opositeDirection) { AlertType newHigherAlert = AlertType.HigherAlert(activeBgAlert, newAlert); if ((newHigherAlert == activeBgAlert)) {