use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class Notifications method calcuatleArmTimeBg.
// This is the absolute time, not time from now.
private long calcuatleArmTimeBg(long now) {
Long wakeTimeBg = Long.MAX_VALUE;
ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
if (activeBgAlert != null) {
AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid);
if (alert != null) {
wakeTimeBg = activeBgAlert.next_alert_at;
Log.d(TAG, "ArmTimer BG alert -waking at: " + new Date(wakeTimeBg) + " in " + (wakeTimeBg - now) / 60000d + " minutes");
if (wakeTimeBg < now) {
// next alert should be at least one minute from now.
wakeTimeBg = now + 60000;
Log.w(TAG, "setting next alert to 1 minute from now (no problem right now, but needs a fix someplace else)");
}
}
}
Log.d("Notifications", "calcuatleArmTimeBg returning: " + new Date(wakeTimeBg) + " in " + (wakeTimeBg - now) / 60000d + " minutes");
return wakeTimeBg;
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class AlertList method createAlertsMap.
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;
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip by NightscoutFoundation.
the class EditAlertActivity method verifyThreshold.
private boolean verifyThreshold(double threshold, boolean allDay, int startTime, int endTime) {
List<AlertType> lowAlerts = AlertType.getAll(false);
List<AlertType> highAlerts = AlertType.getAll(true);
if (threshold < MIN_ALERT || threshold > MAX_ALERT) {
Toast.makeText(getApplicationContext(), "threshold has to be between " + unitsConvert2Disp(doMgdl, MIN_ALERT) + " and " + unitsConvert2Disp(doMgdl, MAX_ALERT), Toast.LENGTH_LONG).show();
return false;
}
// We want to make sure that for each threashold there is only one alert. Otherwise, which file should we play.
for (AlertType lowAlert : lowAlerts) {
if (lowAlert.threshold == threshold && overlapping(lowAlert, allDay, startTime, endTime) && lowAlert.active) {
if (uuid == null || !uuid.equals(lowAlert.uuid)) {
// new alert or not myself
Toast.makeText(getApplicationContext(), "Each alert should have it's own threshold. Please choose another threshold.", Toast.LENGTH_LONG).show();
return false;
}
}
}
for (AlertType highAlert : highAlerts) {
if (highAlert.threshold == threshold && overlapping(highAlert, allDay, startTime, endTime) && highAlert.active) {
if (uuid == null || !uuid.equals(highAlert.uuid)) {
// new alert or not myself
Toast.makeText(getApplicationContext(), "Each alert should have it's own threshold. Please choose another threshold.", Toast.LENGTH_LONG).show();
return false;
}
}
}
// high alerts have to be higher than all low alerts...
if (above) {
for (AlertType lowAlert : lowAlerts) {
if (threshold < lowAlert.threshold && overlapping(lowAlert, allDay, startTime, endTime) && lowAlert.active) {
Toast.makeText(getApplicationContext(), "High alert threshold has to be higher than all low alerts. Please choose another threshold.", Toast.LENGTH_LONG).show();
return false;
}
}
} else {
// low alert has to be lower than all high alerts
for (AlertType highAlert : highAlerts) {
if (threshold > highAlert.threshold && overlapping(highAlert, allDay, startTime, endTime) && highAlert.active) {
Toast.makeText(getApplicationContext(), "Low alert threshold has to be lower than all high alerts. Please choose another threshold.", Toast.LENGTH_LONG).show();
return false;
}
}
}
return true;
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip-plus by jamorham.
the class AlertList method createAlertsMap.
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;
}
use of com.eveningoutpost.dexdrip.Models.AlertType in project xDrip-plus by jamorham.
the class AlertPlayer method ClockTick.
// 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()) {
// also don't cancel notification
stopAlert(ctx, false, false, false);
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);
}
}
Aggregations