Search in sources :

Example 6 with AlertType

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;
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) Date(java.util.Date) ActiveBgAlert(com.eveningoutpost.dexdrip.Models.ActiveBgAlert)

Example 7 with AlertType

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;
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with AlertType

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;
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType)

Example 9 with AlertType

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;
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 10 with AlertType

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);
    }
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) ActiveBgAlert(com.eveningoutpost.dexdrip.Models.ActiveBgAlert)

Aggregations

AlertType (com.eveningoutpost.dexdrip.Models.AlertType)24 ActiveBgAlert (com.eveningoutpost.dexdrip.Models.ActiveBgAlert)10 Date (java.util.Date)10 TextView (android.widget.TextView)4 DataMap (com.google.android.gms.wearable.DataMap)4 ArrayList (java.util.ArrayList)4 Dialog (android.app.Dialog)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Paint (android.graphics.Paint)2 View (android.view.View)2 Button (android.widget.Button)2 NumberPicker (android.widget.NumberPicker)2 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)2 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 HashMap (java.util.HashMap)2