Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.Notifications#bgMissedAlert()

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Notifications#bgMissedAlert() . 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: MissedReadingService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences prefs;
    boolean bg_missed_alerts;
    Context context;
    int bg_missed_minutes;
    
    
    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    bg_missed_alerts =  prefs.getBoolean("bg_missed_alerts", false);
    bg_missed_minutes =  readPerfsInt(prefs, "bg_missed_minutes", 30);
    long now = new Date().getTime();
    Log.d(TAG, "MissedReadingService onHandleIntent");
    if (!bg_missed_alerts) {
    	// we should not do anything in this case. if the ui, changes will be called again
    	return;
    }

    if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
            prefs.getLong("alerts_disabled_until", 0) <= now &&
            inTimeFrame(prefs)) {
        Notifications.bgMissedAlert(context);
        checkBackAfterSnoozeTime( context, now);
    } else  {
        
        long disabletime = prefs.getLong("alerts_disabled_until", 0) - now;
        
        long missedTime = bg_missed_minutes* 1000 * 60 - BgReading.getTimeSinceLastReading();
        long alarmIn = Math.max(disabletime, missedTime);
        checkBackAfterMissedTime(alarmIn);
    }
}
 
Example 2
Source File: MissedReadingService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs;
    final boolean bg_missed_alerts;
    final Context context;
    final int bg_missed_minutes;


    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.d(TAG, "MissedReadingService onHandleIntent");

    final long stale_millis = Home.stale_data_millis();

    // send to pebble
    /*if (prefs.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType(prefs) != 1) && !BgReading.last_within_millis(stale_millis)) {
        if (JoH.ratelimit("peb-miss",120)) context.startService(new Intent(context, PebbleWatchSync.class));
        // update pebble even when we don't have data to ensure missed readings show
    }*/

    /*if ((Home.get_forced_wear()) && prefs.getBoolean("disable_wearG5_on_missedreadings", false)) {
        int bg_wear_missed_minutes = readPerfsInt(prefs, "disable_wearG5_on_missedreadings_level", 30);
        if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
            Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
            startWatchUpdaterService(context, WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
        }
    }*/

    if ((prefs.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
        if (!BgReading.last_within_millis(stale_millis) && Sensor.isActive() && (!getLocalServiceCollectingState())) {
            if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: "+aggressive_backoff_timer);
                if (aggressive_backoff_timer < 1200) aggressive_backoff_timer+=60;
                CollectionServiceStarter.startBtService(context);
            } else {
                aggressive_backoff_timer = 120; // reset
            }
        }
    }
    //Reminder.processAnyDueReminders();
    //BluetoothGlucoseMeter.immortality();

    bg_missed_alerts =  prefs.getBoolean("bg_missed_alerts", false);//KS TODO bg_missed_alerts pref not supported
    if (!bg_missed_alerts || !Pref.getBoolean("bg_notifications", false)) {
        // we should not do anything in this case. if the ui, changes will be called again
        return;
    }

    bg_missed_minutes =  readPerfsInt(prefs, "bg_missed_minutes", 30);
    final long now = new Date().getTime();

    if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
            prefs.getLong("alerts_disabled_until", 0) <= now &&
            inTimeFrame(prefs)) {
        Notifications.bgMissedAlert(context);
        checkBackAfterSnoozeTime(context, now);
    } else  {

        long disabletime = prefs.getLong("alerts_disabled_until", 0) - now;

        long missedTime = bg_missed_minutes* 1000 * 60 - BgReading.getTimeSinceLastReading();
        long alarmIn = Math.max(disabletime, missedTime);
        checkBackAfterMissedTime(alarmIn);
    }
}
 
Example 3
Source File: MissedReadingService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final boolean bg_missed_alerts;

    final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000);
    try {

        final boolean sensorActive = Sensor.isActive();

        Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log

        final long stale_millis = Home.stale_data_millis();


        // send to pebble
        if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) {
            if (JoH.ratelimit("peb-miss", 120)) {
                // TODO replace ratelimit with Inevitable.task?
                JoH.startService(PebbleWatchSync.class);
            }
            // update pebble even when we don't have data to ensure missed readings show
        }

        if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) {
            LeFun.showLatestBG();
        }


        if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
            if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) {
                if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                    Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer);
                    if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60;
                    CollectionServiceStarter.restartCollectionServiceBackground();
                } else {
                    aggressive_backoff_timer = 120; // reset
                }
            }
        }


        Reminder.processAnyDueReminders();
        BluetoothGlucoseMeter.immortality();
        XdripWebService.immortality(); //
        InPenEntry.immortality();
        DesertSync.pullAsEnabled();
        NanoStatus.keepFollowerUpdated();
        LockScreenWallPaper.timerPoll();

        // TODO functionalize the actual checking
        bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false);
        if (!bg_missed_alerts) {
            // we should not do anything in this case. if the ui, changes will be called again
            return;
        }
        if (!sensorActive) {
            // sensor not running we should return
            return;
        }

        if (!JoH.upForAtLeastMins(15)) {
            Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading");
            return;
        }


        if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) {
            int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30);
            if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
                Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
                startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
            }
        }

        final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30);
        final long now = JoH.tsl();

        // check if readings have been missed
        if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
                Pref.getLong("alerts_disabled_until", 0) <= now &&
                (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) &&
                inTimeFrame()) {
            Notifications.bgMissedAlert(xdrip.getAppContext());
            checkBackAfterSnoozeTime(xdrip.getAppContext(), now);
        } else {

            long disabletime = Pref.getLong("alerts_disabled_until", 0) - now;

            long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading();
            long alarmIn = Math.max(disabletime, missedTime);
            checkBackAfterMissedTime(alarmIn);
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
 
Example 4
Source File: MissedReadingService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs;
    final boolean bg_missed_alerts;
    final Context context;
    final int bg_missed_minutes;


    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.d(TAG, "MissedReadingService onHandleIntent");

    final long stale_millis = Home.stale_data_millis();

    // send to pebble
    /*if (prefs.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType(prefs) != 1) && !BgReading.last_within_millis(stale_millis)) {
        if (JoH.ratelimit("peb-miss",120)) context.startService(new Intent(context, PebbleWatchSync.class));
        // update pebble even when we don't have data to ensure missed readings show
    }*/

    /*if ((Home.get_forced_wear()) && prefs.getBoolean("disable_wearG5_on_missedreadings", false)) {
        int bg_wear_missed_minutes = readPerfsInt(prefs, "disable_wearG5_on_missedreadings_level", 30);
        if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
            Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
            startWatchUpdaterService(context, WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
        }
    }*/

    if ((prefs.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
        if (!BgReading.last_within_millis(stale_millis) && Sensor.isActive() && (!getLocalServiceCollectingState())) {
            if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: "+aggressive_backoff_timer);
                if (aggressive_backoff_timer < 1200) aggressive_backoff_timer+=60;
                CollectionServiceStarter.startBtService(context);
            } else {
                aggressive_backoff_timer = 120; // reset
            }
        }
    }
    //Reminder.processAnyDueReminders();
    //BluetoothGlucoseMeter.immortality();

    bg_missed_alerts =  prefs.getBoolean("bg_missed_alerts", false);//KS TODO bg_missed_alerts pref not supported
    if (!bg_missed_alerts || !Pref.getBoolean("bg_notifications", false)) {
        // we should not do anything in this case. if the ui, changes will be called again
        return;
    }

    bg_missed_minutes =  readPerfsInt(prefs, "bg_missed_minutes", 30);
    final long now = new Date().getTime();

    if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
            prefs.getLong("alerts_disabled_until", 0) <= now &&
            inTimeFrame(prefs)) {
        Notifications.bgMissedAlert(context);
        checkBackAfterSnoozeTime(context, now);
    } else  {

        long disabletime = prefs.getLong("alerts_disabled_until", 0) - now;

        long missedTime = bg_missed_minutes* 1000 * 60 - BgReading.getTimeSinceLastReading();
        long alarmIn = Math.max(disabletime, missedTime);
        checkBackAfterMissedTime(alarmIn);
    }
}
 
Example 5
Source File: MissedReadingService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final boolean bg_missed_alerts;

    final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000);
    try {

        final boolean sensorActive = Sensor.isActive();

        Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log

        final long stale_millis = Home.stale_data_millis();


        // send to pebble
        if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) {
            if (JoH.ratelimit("peb-miss", 120)) {
                // TODO replace ratelimit with Inevitable.task?
                JoH.startService(PebbleWatchSync.class);
            }
            // update pebble even when we don't have data to ensure missed readings show
        }

        if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) {
            LeFun.showLatestBG();
        }


        if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
            if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) {
                if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                    Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer);
                    if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60;
                    CollectionServiceStarter.restartCollectionServiceBackground();
                } else {
                    aggressive_backoff_timer = 120; // reset
                }
            }
        }


        Reminder.processAnyDueReminders();
        BluetoothGlucoseMeter.immortality();
        XdripWebService.immortality(); //
        InPenEntry.immortality();
        DesertSync.pullAsEnabled();
        NanoStatus.keepFollowerUpdated();
        LockScreenWallPaper.timerPoll();

        // TODO functionalize the actual checking
        bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false);
        if (!bg_missed_alerts) {
            // we should not do anything in this case. if the ui, changes will be called again
            return;
        }
        if (!sensorActive) {
            // sensor not running we should return
            return;
        }

        if (!JoH.upForAtLeastMins(15)) {
            Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading");
            return;
        }


        if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) {
            int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30);
            if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
                Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
                startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
            }
        }

        final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30);
        final long now = JoH.tsl();

        // check if readings have been missed
        if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
                Pref.getLong("alerts_disabled_until", 0) <= now &&
                (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) &&
                inTimeFrame()) {
            Notifications.bgMissedAlert(xdrip.getAppContext());
            checkBackAfterSnoozeTime(xdrip.getAppContext(), now);
        } else {

            long disabletime = Pref.getLong("alerts_disabled_until", 0) - now;

            long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading();
            long alarmIn = Math.max(disabletime, missedTime);
            checkBackAfterMissedTime(alarmIn);
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}