com.eveningoutpost.dexdrip.Models.AlertType Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.Models.AlertType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditAlertActivity.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private boolean overlapping(AlertType at, boolean allday, int startTime, int endTime){
    //shortcut: if one is all day, they must overlap
    if(at.all_day || allday) {
        return true;
    }
    int st1 = at.start_time_minutes;
    int st2 = startTime;
    int et1 = at.end_time_minutes;
    int et2 = endTime;

    return  st1 <= st2 && et1 > st2 ||
            st1 <= st2 && (et2 < st2) && et2 > st1 || //2nd timeframe passes midnight
            st2 <= st1 && et2 > st1 ||
            st2 <= st1 && (et1 < st1) && et1 > st2 ||
            (et1 < st1 && et2 < st2); //both timeframes pass midnight -> overlap at least at midnight
}
 
Example #2
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #4
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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.");
        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);
    if (from_interactive) GcmActivity.sendSnoozeToRemote();
}
 
Example #5
Source File: IdempotentMigrations.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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, false, 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, false, bg_low_snooze, true, true);
        prefs.edit().putBoolean("bg_notifications", false).apply();
    }
}
 
Example #6
Source File: IdempotentMigrations.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void performAll() {
        migrateBGAlerts();
        migrateToNewStyleRestUris();
        BgReading.updateDB();
        LibreBlock.updateDB();
        LibreData.updateDB();
        APStatus.updateDB();
        Prediction.updateDB();
        DesertSync.updateDB();
        PenData.updateDB();
        Libre2RawValue.updateDB();
        Libre2Sensor.updateDB();
//        BgReadingArchive.updateDB();
        AlertType.fixUpTable();
        JoH.clearCache();

        IncompatibleApps.notifyAboutIncompatibleApps();
        CompatibleApps.notifyAboutCompatibleApps();

    }
 
Example #7
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: EditAlertActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private boolean overlapping(AlertType at, boolean allday, int startTime, int endTime){
    //shortcut: if one is all day, they must overlap
    if(at.all_day || allday) {
        return true;
    }
    int st1 = at.start_time_minutes;
    int st2 = startTime;
    int et1 = at.end_time_minutes;
    int et2 = endTime;

    return  st1 <= st2 && et1 > st2 ||
            st1 <= st2 && (et2 < st2) && et2 > st1 || //2nd timeframe passes midnight
            st2 <= st1 && et2 > st1 ||
            st2 <= st1 && (et1 < st1) && et1 > st2 ||
            (et1 < st1 && et2 < st2); //both timeframes pass midnight -> overlap at least at midnight
}
 
Example #9
Source File: MissedReadingActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    Context context = getApplicationContext();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().putInt("missed_readings_start", AlertType.toTime(startHour, startMinute)).apply();
    prefs.edit().putInt("missed_readings_end", AlertType.toTime(endHour, endMinute)).apply();
    prefs.edit().putString("bg_missed_minutes", bgMissedMinutes.getText().toString()).apply();
    prefs.edit().putString("bg_missed_alerts_snooze", bgMissedSnoozeMin.getText().toString()).apply();
    prefs.edit().putString("bg_missed_alerts_reraise_sec", bgMissedReraiseSec.getText().toString()).apply();

    prefs.edit().putBoolean("bg_missed_alerts", checkboxEnableAlert.isChecked()).apply();
    prefs.edit().putBoolean("missed_readings_all_day", checkboxAllDay.isChecked()).apply();
    prefs.edit().putBoolean("bg_missed_alerts_enable_alerts_reraise", checkboxEnableReraise.isChecked()).apply();

    MissedReadingService.delayedLaunch();
  //  context.startService(new Intent(context, MissedReadingService.class));
}
 
Example #10
Source File: AlertList.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
HashMap<String, String> createAlertMap(AlertType alert) {
    HashMap<String, String> map = new HashMap<String, String>();
    String overrideSilentMode = "Override Silent Mode";
    if (alert.override_silent_mode == false) {
        overrideSilentMode = "No Alert in Silent Mode";
    }
    // We use a - sign to tell that this text should be stiked through
    String extra = "-";
    if (alert.active) {
        extra = "+";
    }


    map.put("alertName", extra + alert.name);
    map.put("alertThreshold", extra + EditAlertActivity.unitsConvert2Disp(doMgdl, alert.threshold));
    map.put("alertTime", extra + stringTimeFromAlert(alert));
    map.put("alertMp3File", extra + shortPath(alert.mp3_file));
    map.put("alertOverrideSilenceMode", extra + overrideSilentMode);
    map.put("uuid", alert.uuid);

    return map;
}
 
Example #11
Source File: AlertList.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult called request code  = " + requestCode + " result code " + resultCode);
    if (!AlertType.activeLowAlertExists()) {
        displayWarning();
    }
    if (requestCode == ADD_ALERT || requestCode == EDIT_ALERT) {
        if (resultCode == RESULT_OK) {
            Log.d(TAG, "onActivityResult called invalidating...");
            FillLists();
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}
 
Example #12
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: AlertList.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult called request code  = " + requestCode + " result code " + resultCode);
    if(!AlertType.activeLowAlertExists()) {
        displayWarning();
    }
    if (requestCode == ADD_ALERT || requestCode == EDIT_ALERT) {
        if(resultCode == RESULT_OK) {
            Log.d(TAG, "onActivityResult called invalidating...");
            FillLists();
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}
 
Example #14
Source File: AlertList.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
HashMap<String, String> createAlertMap(AlertType alert) {
    HashMap<String, String> map = new HashMap<String, String>();
    String overrideSilentMode = "Override Silent Mode";
    if(alert.override_silent_mode == false) {
        overrideSilentMode = "No Alert in Silent Mode";
    }
    // We use a - sign to tell that this text should be stiked through
    String extra = "-";
    if(alert.active) {
      extra = "+";
    }
    

    map.put("alertName", extra+alert.name);
    map.put("alertThreshold", extra + EditAlertActivity.unitsConvert2Disp(doMgdl, alert.threshold));
    map.put("alertTime", extra + stringTimeFromAlert(alert));
    map.put("alertMp3File", extra + shortPath(alert.mp3_file));
    map.put("alertOverrideSilenceMode", extra + overrideSilentMode);
    map.put("uuid", alert.uuid);

    return map;
}
 
Example #15
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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.");
        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);
    if (from_interactive) GcmActivity.sendSnoozeToRemote();
}
 
Example #16
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #17
Source File: EditAlertActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private boolean overlapping(AlertType at, boolean allday, int startTime, int endTime){
    //shortcut: if one is all day, they must overlap
    if(at.all_day || allday) {
        return true;
    }
    int st1 = at.start_time_minutes;
    int st2 = startTime;
    int et1 = at.end_time_minutes;
    int et2 = endTime;

    return  st1 <= st2 && et1 > st2 ||
            st1 <= st2 && (et2 < st2) && et2 > st1 || //2nd timeframe passes midnight
            st2 <= st1 && et2 > st1 ||
            st2 <= st1 && (et1 < st1) && et1 > st2 ||
            (et1 < st1 && et2 < st2); //both timeframes pass midnight -> overlap at least at midnight
}
 
Example #18
Source File: MissedReadingActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    Context context = getApplicationContext();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().putInt("missed_readings_start", AlertType.toTime(startHour, startMinute)).apply();
    prefs.edit().putInt("missed_readings_end", AlertType.toTime(endHour, endMinute)).apply();
    prefs.edit().putString("bg_missed_minutes", bgMissedMinutes.getText().toString()).apply();
    prefs.edit().putString("bg_missed_alerts_snooze", bgMissedSnoozeMin.getText().toString()).apply();
    prefs.edit().putString("bg_missed_alerts_reraise_sec", bgMissedReraiseSec.getText().toString()).apply();

    prefs.edit().putBoolean("bg_missed_alerts", checkboxEnableAlert.isChecked()).apply();
    prefs.edit().putBoolean("missed_readings_all_day", checkboxAllDay.isChecked()).apply();
    prefs.edit().putBoolean("bg_missed_alerts_enable_alerts_reraise", checkboxEnableReraise.isChecked()).apply();

    MissedReadingService.delayedLaunch();
  //  context.startService(new Intent(context, MissedReadingService.class));
}
 
Example #19
Source File: AlertList.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
HashMap<String, String> createAlertMap(AlertType alert) {
    HashMap<String, String> map = new HashMap<String, String>();
    String overrideSilentMode = "Override Silent Mode";
    if (alert.override_silent_mode == false) {
        overrideSilentMode = "No Alert in Silent Mode";
    }
    // We use a - sign to tell that this text should be stiked through
    String extra = "-";
    if (alert.active) {
        extra = "+";
    }


    map.put("alertName", extra + alert.name);
    map.put("alertThreshold", extra + EditAlertActivity.unitsConvert2Disp(doMgdl, alert.threshold));
    map.put("alertTime", extra + stringTimeFromAlert(alert));
    map.put("alertMp3File", extra + shortPath(alert.mp3_file));
    map.put("alertOverrideSilenceMode", extra + overrideSilentMode);
    map.put("uuid", alert.uuid);

    return map;
}
 
Example #20
Source File: IdempotentMigrations.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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, false, 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, false, bg_low_snooze, true, true);
        prefs.edit().putBoolean("bg_notifications", false).apply();
    }
}
 
Example #21
Source File: AlertList.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult called request code  = " + requestCode + " result code " + resultCode);
    if (!AlertType.activeLowAlertExists()) {
        displayWarning();
    }
    if (requestCode == ADD_ALERT || requestCode == EDIT_ALERT) {
        if (resultCode == RESULT_OK) {
            Log.d(TAG, "onActivityResult called invalidating...");
            FillLists();
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}
 
Example #22
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #23
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendAlertTypeData() {//KS
    try {
        forceGoogleApiConnect();
        List<AlertType> alerts = AlertType.getAllActive();
        if (alerts != null) {
            if (wear_integration) {
                Log.d(TAG, "sendAlertTypeData latest count = " + alerts.size());
                final DataMap entries = new DataMap();
                final ArrayList<DataMap> dataMaps = new ArrayList<>(alerts.size());
                for (AlertType alert : alerts) {
                    if (alert != null) {
                        dataMaps.add(dataMap(alert, "alert"));
                    }
                }
                entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_ALERTTYPE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendAlertTypeData latest count = 0");
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendAlertTypeData: " + e);
    }
}
 
Example #24
Source File: IdempotentMigrations.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void migrateBGAlerts() {
    // Migrate away from old style notifications to Tzachis new Alert system
    AlertType.CreateStaticAlerts();
    if(prefs.getBoolean("bg_notifications", true)){
        double highMark = Double.parseDouble(prefs.getString("highValue", "170"));
        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, "High Alert", true, highMark, true, 1, bg_notification_sound, 0, 0, bg_sound_in_silent, bg_high_snooze, true, true);
        AlertType.add_alert(null, "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();
    }
}
 
Example #25
Source File: Notifications.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #26
Source File: MissedReadingService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private boolean inTimeFrame() {

        int startMinutes = Pref.getInt("missed_readings_start", 0);
        int endMinutes = Pref.getInt("missed_readings_end", 0);
        boolean allDay = Pref.getBoolean("missed_readings_all_day", true);

        return AlertType.s_in_time_frame(allDay, startMinutes, endMinutes);
    }
 
Example #27
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
boolean trendingToAlertEnd(Context context, Boolean newAlert, AlertType Alert) {
    if (newAlert && !smart_alerting) {
        //  User does not want smart alerting at all.
        return false;
    }
    if ((!newAlert) && (!smart_snoozing)) {
        //  User does not want smart snoozing at all.
        return false;
    }
    return BgReading.trendingToAlertEnd(context, Alert.above);
}
 
Example #28
Source File: AlertTracker.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void evaluate() {

        final ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();

        if (activeBgAlert != null) {
            if (!activeBgAlert.is_snoozed) {
                if (JoH.ratelimit("alert-tracker-eval", 10)) {
                    final AlertType type = ActiveBgAlert.alertTypegetOnly(activeBgAlert);
                    if (type != null) {
                        final long since = JoH.msSince(activeBgAlert.alert_started_at);
                        String summary = "";
                        try {
                            summary = "(glucose " + BestGlucose.getDisplayGlucose().humanSummary() + ")";
                        } catch (Exception e) {
                            //
                        }
                        if (!type.above) {
                            EmergencyAssist.checkAndActivate(EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_LOW_ALERT,
                                    since, summary);
                        } else {
                            EmergencyAssist.checkAndActivate(EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_HIGH_ALERT,
                                    since, summary);
                        }
                    }
                }
            }
        }
    }
 
Example #29
Source File: AlertList.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #30
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void Vibrate(Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) {
    //KS Watch currently only supports Vibration, no audio; Use VibrateAudio to support audio
    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && Pref.getBooleanDefaultFalse("bg_notifications"));//KS
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder  builder = new NotificationCompat.Builder(ctx)//KS Notification
            .setSmallIcon(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(notificationIntent(ctx, intent))
            .setLocalOnly(localOnly)//KS
            .setDeleteIntent(snoozeIntent(ctx));
    builder.setVibrate(Notifications.vibratePattern);
    Log.ueh("Alerting",content);
    NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());
    if (Pref.getBooleanDefaultFalse("alert_use_sounds")) {
        try {
            if (JoH.ratelimit("wear-alert-sound", 10)) {
                JoH.playResourceAudio(R.raw.warning);
            }
        } catch (Exception e) {
            //
        }
    }
}