com.eveningoutpost.dexdrip.UtilityModels.Notifications Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Notifications. 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: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void restartSensorWithTimeTravel(long when) {
    if (acceptCommands()) {
        enqueueUniqueCommand(
                new SessionStopTxMessage(
                        DexTimeKeeper.getDexTime(getTransmitterID(), when)),
                "Auto Stop Sensor");
        final long when_started = when + SECOND_IN_MS;
        enqueueUniqueCommand(new SessionStartTxMessage(when,
                        DexTimeKeeper.getDexTime(getTransmitterID(), when_started)),
                "Auto Start Sensor");
        if (Pref.getBoolean("ob1_g5_preemptive_restart_alert", true)) {
            Notifications.ob1SessionRestartRequested();
        }
        Treatments.create_note(xdrip.getAppContext().getString(R.string.ob1_session_restarted_note), JoH.tsl());
    }
}
 
Example #2
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void restartSensorWithTimeTravel(long when) {
    if (acceptCommands()) {
        enqueueUniqueCommand(
                new SessionStopTxMessage(
                        DexTimeKeeper.getDexTime(getTransmitterID(), when)),
                "Auto Stop Sensor");
        final long when_started = when + SECOND_IN_MS;
        enqueueUniqueCommand(new SessionStartTxMessage(when,
                        DexTimeKeeper.getDexTime(getTransmitterID(), when_started)),
                "Auto Start Sensor");
        if (Pref.getBoolean("ob1_g5_preemptive_restart_alert", true)) {
            Notifications.ob1SessionRestartRequested();
        }
        Treatments.create_note(xdrip.getAppContext().getString(R.string.ob1_session_restarted_note), JoH.tsl());
    }
}
 
Example #3
Source File: NewDataObserver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void newBgReading(BgReading bgReading, boolean is_follower) {

        sendToPebble();
        sendToWear();
        sendToAmazfit();
        sendToLeFun();
        sendToMiBand();
        sendToBlueJay();
        sendToRemoteBlueJay();
        Notifications.start();
        uploadToShare(bgReading, is_follower);
        textToSpeech(bgReading, null);
        LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
        LockScreenWallPaper.setIfEnabled();
        TidepoolEntry.newData();

    }
 
Example #4
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void restartSensorWithTimeTravel(long when) {
    if (acceptCommands()) {
        enqueueUniqueCommand(
                new SessionStopTxMessage(
                        DexTimeKeeper.getDexTime(getTransmitterID(), when)),
                "Auto Stop Sensor");
        final long when_started = when + SECOND_IN_MS;
        enqueueUniqueCommand(new SessionStartTxMessage(when,
                        DexTimeKeeper.getDexTime(getTransmitterID(), when_started)),
                "Auto Start Sensor");
        if (Pref.getBoolean("ob1_g5_preemptive_restart_alert", true)) {
            Notifications.ob1SessionRestartRequested();
        }
        Treatments.create_note(xdrip.getAppContext().getString(R.string.ob1_session_restarted_note), JoH.tsl());
    }
}
 
Example #5
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void restartSensorWithTimeTravel(long when) {
    if (acceptCommands()) {
        enqueueUniqueCommand(
                new SessionStopTxMessage(
                        DexTimeKeeper.getDexTime(getTransmitterID(), when)),
                "Auto Stop Sensor");
        final long when_started = when + SECOND_IN_MS;
        enqueueUniqueCommand(new SessionStartTxMessage(when,
                        DexTimeKeeper.getDexTime(getTransmitterID(), when_started)),
                "Auto Start Sensor");
        if (Pref.getBoolean("ob1_g5_preemptive_restart_alert", true)) {
            Notifications.ob1SessionRestartRequested();
        }
        Treatments.create_note(xdrip.getAppContext().getString(R.string.ob1_session_restarted_note), JoH.tsl());
    }
}
 
Example #6
Source File: NewDataObserver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void newBgReading(BgReading bgReading, boolean is_follower) {

        sendToPebble();
        sendToWear();
        sendToAmazfit();
        sendToLeFun();
        sendToMiBand();
        sendToBlueJay();
        sendToRemoteBlueJay();
        Notifications.start();
        uploadToShare(bgReading, is_follower);
        textToSpeech(bgReading, null);
        LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
        LockScreenWallPaper.setIfEnabled();
        TidepoolEntry.newData();

    }
 
Example #7
Source File: BgReading.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public static void create(EGVRecord egvRecord, long addativeOffset, Context context) {
    BgReading bgReading = BgReading.getForTimestamp(egvRecord.getSystemTime().getTime() + addativeOffset);
    Log.i(TAG, "create: Looking for BG reading to tag this thing to: " + egvRecord.getBGValue());
    if(bgReading != null) {
        bgReading.calculated_value = egvRecord.getBGValue();
        if (egvRecord.getBGValue() <= 13) {
            Calibration calibration = bgReading.calibration;
            double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp)/(1000 * 60 * 10)));
            double calSlope = (calibration.first_scale / firstAdjSlope)*1000;
            double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope)*-1;
            bgReading.raw_calculated = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
        }
        Log.i(TAG, "create: NEW VALUE CALCULATED AT: " + bgReading.calculated_value);
        Pair<Double, Boolean> slopePair = BgReading.slopefromName(egvRecord.getTrend().friendlyTrendName());
        bgReading.calculated_value_slope = slopePair.first;
        bgReading.hide_slope = slopePair.second;
        bgReading.noise = egvRecord.noiseValue();
        bgReading.save();
        bgReading.find_new_curve();
        bgReading.find_new_raw_curve();
        context.startService(new Intent(context, Notifications.class));
        BgSendQueue.handleNewBgReading(bgReading, "create", context);
    }
}
 
Example #8
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void create(EGVRecord egvRecord, long addativeOffset, Context context) {
    BgReading bgReading = BgReading.getForTimestamp(egvRecord.getSystemTime().getTime() + addativeOffset);
    Log.w(TAG, "Looking for BG reading to tag this thing to: " + egvRecord.getBGValue());
    if(bgReading != null) {
        bgReading.calculated_value = egvRecord.getBGValue();
        if (egvRecord.getBGValue() <= 13) {
            Calibration calibration = bgReading.calibration;
            double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp)/(1000 * 60 * 10)));
            double calSlope = (calibration.first_scale / firstAdjSlope)*1000;
            double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope)*-1;
            bgReading.raw_calculated = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
            bgReading.noise = egvRecord.noiseValue();
        }
        Log.w(TAG, "NEW VALUE CALCULATED AT: " + bgReading.calculated_value);
        bgReading.calculated_value_slope = bgReading.slopefromName(egvRecord.getTrend().friendlyTrendName());
        if(egvRecord.getTrend().friendlyTrendName().compareTo("NOT_COMPUTABLE") == 0 || egvRecord.getTrend().friendlyTrendName().compareTo("OUT_OF_RANGE") == 0) {
            bgReading.hide_slope = true;
        }
        bgReading.save();
        bgReading.find_new_curve();
        bgReading.find_new_raw_curve();
        Notifications.notificationSetter(context);
        BgSendQueue.addToQueue(bgReading, "create", context);
    }
}
 
Example #9
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #10
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForDropAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean falling_alert = prefs.getBoolean("falling_alert", false);
    if(!falling_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "checkForDropAllert: Notifications are currently disabled!!");
        return;
    }

    String dropRate = prefs.getString("falling_bg_val", "2");
    float fdropRate = 2;

    try
    {
        fdropRate = Float.parseFloat(dropRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.i(TAG_ALERT, "checkForDropAllert will check for rate of " + fdropRate);

    boolean dropAlert = checkForDropRiseAllert(fdropRate, true);
    Notifications.DropAlert(context, dropAlert);
}
 
Example #11
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void notifyAndSync(final BgReading bgr) {
    final boolean recent = bgr.isCurrent();
    if (recent) {
        Notifications.start(); // may not be needed as this is duplicated in handleNewBgReading
        // probably not wanted for G5 internal values?
        //bgr.injectNoise(true); // Add noise parameter for nightscout
        //bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
    }
    BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), Home.get_follower(), !recent); // pebble and widget and follower
}
 
Example #12
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #13
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void notifyAndSync(final BgReading bgr) {
    final boolean recent = bgr.isCurrent();
    if (recent) {
        Notifications.start(); // may not be needed as this is duplicated in handleNewBgReading
        // probably not wanted for G5 internal values?
        //bgr.injectNoise(true); // Add noise parameter for nightscout
        //bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
    }
    BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), Home.get_follower(), !recent); // pebble and widget and follower
}
 
Example #14
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void create(EGVRecord egvRecord, long addativeOffset, Context context) {
    BgReading bgReading = BgReading.getForTimestamp(egvRecord.getSystemTime().getTime() + addativeOffset);
    Log.i(TAG, "create: Looking for BG reading to tag this thing to: " + egvRecord.getBGValue());
    if (bgReading != null) {
        bgReading.calculated_value = egvRecord.getBGValue();
        if (egvRecord.getBGValue() <= 13) {
            Calibration calibration = bgReading.calibration;
            double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp) / (1000 * 60 * 10)));
            double calSlope = (calibration.first_scale / firstAdjSlope) * 1000;
            double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope) * -1;
            bgReading.raw_calculated = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
        }
        Log.i(TAG, "create: NEW VALUE CALCULATED AT: " + bgReading.calculated_value);
        bgReading.calculated_value_slope = bgReading.slopefromName(egvRecord.getTrend().friendlyTrendName());
        bgReading.noise = egvRecord.noiseValue();
        String friendlyName = egvRecord.getTrend().friendlyTrendName();
        if (friendlyName.compareTo("NONE") == 0 ||
                friendlyName.compareTo("NOT_COMPUTABLE") == 0 ||
                friendlyName.compareTo("NOT COMPUTABLE") == 0 ||
                friendlyName.compareTo("OUT OF RANGE") == 0 ||
                friendlyName.compareTo("OUT_OF_RANGE") == 0) {
            bgReading.hide_slope = true;
        }
        bgReading.save();
        bgReading.find_new_curve();
        bgReading.find_new_raw_curve();
        //context.startService(new Intent(context, Notifications.class));
        Notifications.start(); // this may not be needed as it is duplicated in handleNewBgReading
        BgSendQueue.handleNewBgReading(bgReading, "create", context);
    }
}
 
Example #15
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void notifyAndSync(final BgReading bgr) {
    final boolean recent = bgr.isCurrent();
    if (recent) {
        Notifications.start(); // may not be needed as this is duplicated in handleNewBgReading
        // probably not wanted for G5 internal values?
        //bgr.injectNoise(true); // Add noise parameter for nightscout
        //bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
    }
    BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), Home.get_follower(), !recent); // pebble and widget and follower
}
 
Example #16
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #17
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean getAndRaiseUnclearReading(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "getAndRaiseUnclearReading Notifications are currently disabled!!");
        UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");
        return false;
    }

    Boolean bg_unclear_readings_alerts = prefs.getBoolean("bg_unclear_readings_alerts", false);
    if (!bg_unclear_readings_alerts
            || !DexCollectionType.hasFiltered()
            || Ob1G5CollectionService.usingG6()
            || Ob1G5CollectionService.usingNativeMode()) {
        Log.d(TAG_ALERT, "getUnclearReading returned false since feature is disabled");
        UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");
        return false;
    }
    Long UnclearTimeSetting = Long.parseLong(prefs.getString("bg_unclear_readings_minutes", "90")) * 60000;

    Long UnclearTime = BgReading.getUnclearTime(UnclearTimeSetting);

    if (UnclearTime >= UnclearTimeSetting ) {
        Log.d("NOTIFICATIONS", "Readings have been unclear for too long!!");
        Notifications.bgUnclearAlert(context);
        return true;
    }

    UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");

    if (UnclearTime > 0 ) {
        Log.d(TAG_ALERT, "We are in an clear state, but not for too long. Alerts are disabled");
        return true;
    }

    return false;
}
 
Example #18
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForDropAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean falling_alert = prefs.getBoolean("falling_alert", false);
    if(!falling_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "checkForDropAllert: Notifications are currently disabled!!");
        return;
    }

    String dropRate = prefs.getString("falling_bg_val", "2");
    float fdropRate = 2;

    try
    {
        fdropRate = Float.parseFloat(dropRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.i(TAG_ALERT, "checkForDropAllert will check for rate of " + fdropRate);

    boolean dropAlert = checkForDropRiseAllert(fdropRate, true);
    Notifications.DropAlert(context, dropAlert);
}
 
Example #19
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void stopBtService() {
    Log.d(TAG, "stopService call stopService");
    CollectionServiceStarter.stopBtService(getApplicationContext());
    Log.d(TAG, "stopBtService should have called onDestroy");
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    PendingIntent wakeIntent = PendingIntent.getService(this, 0, new Intent(this, Notifications.class), PendingIntent.FLAG_UPDATE_CURRENT);
    wakeIntent.cancel();
    alarmManager.cancel(wakeIntent);
    Log.d(TAG, "stopBtService cancel Notifications wakeIntent");
}
 
Example #20
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void create(EGVRecord egvRecord, long addativeOffset, Context context) {
    BgReading bgReading = BgReading.getForTimestamp(egvRecord.getSystemTime().getTime() + addativeOffset);
    Log.i(TAG, "create: Looking for BG reading to tag this thing to: " + egvRecord.getBGValue());
    if (bgReading != null) {
        bgReading.calculated_value = egvRecord.getBGValue();
        if (egvRecord.getBGValue() <= 13) {
            Calibration calibration = bgReading.calibration;
            double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp) / (1000 * 60 * 10)));
            double calSlope = (calibration.first_scale / firstAdjSlope) * 1000;
            double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope) * -1;
            bgReading.raw_calculated = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
        }
        Log.i(TAG, "create: NEW VALUE CALCULATED AT: " + bgReading.calculated_value);
        bgReading.calculated_value_slope = bgReading.slopefromName(egvRecord.getTrend().friendlyTrendName());
        bgReading.noise = egvRecord.noiseValue();
        String friendlyName = egvRecord.getTrend().friendlyTrendName();
        if (friendlyName.compareTo("NONE") == 0 ||
                friendlyName.compareTo("NOT_COMPUTABLE") == 0 ||
                friendlyName.compareTo("NOT COMPUTABLE") == 0 ||
                friendlyName.compareTo("OUT OF RANGE") == 0 ||
                friendlyName.compareTo("OUT_OF_RANGE") == 0) {
            bgReading.hide_slope = true;
        }
        bgReading.save();
        bgReading.find_new_curve();
        bgReading.find_new_raw_curve();
        //context.startService(new Intent(context, Notifications.class));
        Notifications.start(); // this may not be needed as it is duplicated in handleNewBgReading
        BgSendQueue.handleNewBgReading(bgReading, "create", context);
    }
}
 
Example #21
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForDropAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean falling_alert = prefs.getBoolean("falling_alert", false);
    if(!falling_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "checkForDropAllert: Notifications are currently disabled!!");
        return;
    }

    String dropRate = prefs.getString("falling_bg_val", "2");
    float fdropRate = 2;

    try
    {
        fdropRate = Float.parseFloat(dropRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.i(TAG_ALERT, "checkForDropAllert will check for rate of " + fdropRate);

    boolean dropAlert = checkForDropRiseAllert(fdropRate, true);
    Notifications.DropAlert(context, dropAlert);
}
 
Example #22
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #23
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForDropAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean falling_alert = prefs.getBoolean("falling_alert", false);
    if(!falling_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "checkForDropAllert: Notifications are currently disabled!!");
        return;
    }

    String dropRate = prefs.getString("falling_bg_val", "2");
    float fdropRate = 2;

    try
    {
        fdropRate = Float.parseFloat(dropRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.i(TAG_ALERT, "checkForDropAllert will check for rate of " + fdropRate);

    boolean dropAlert = checkForDropRiseAllert(fdropRate, true);
    Notifications.DropAlert(context, dropAlert);
}
 
Example #24
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean getAndRaiseUnclearReading(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "getAndRaiseUnclearReading Notifications are currently disabled!!");
        UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");
        return false;
    }

    Boolean bg_unclear_readings_alerts = prefs.getBoolean("bg_unclear_readings_alerts", false);
    if (!bg_unclear_readings_alerts
            || !DexCollectionType.hasFiltered()
            || Ob1G5CollectionService.usingG6()
            || Ob1G5CollectionService.usingNativeMode()) {
        Log.d(TAG_ALERT, "getUnclearReading returned false since feature is disabled");
        UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");
        return false;
    }
    Long UnclearTimeSetting = Long.parseLong(prefs.getString("bg_unclear_readings_minutes", "90")) * 60000;

    Long UnclearTime = BgReading.getUnclearTime(UnclearTimeSetting);

    if (UnclearTime >= UnclearTimeSetting ) {
        Log.d("NOTIFICATIONS", "Readings have been unclear for too long!!");
        Notifications.bgUnclearAlert(context);
        return true;
    }

    UserNotification.DeleteNotificationByType("bg_unclear_readings_alert");

    if (UnclearTime > 0 ) {
        Log.d(TAG_ALERT, "We are in an clear state, but not for too long. Alerts are disabled");
        return true;
    }

    return false;
}
 
Example #25
Source File: ParakeetHelper.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void sendNotification(String body, String title) {
    if (Pref.getBooleanDefaultFalse("parakeet_status_alerts")) {
        Intent intent = new Intent(xdrip.getAppContext(), Home.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(xdrip.getAppContext(), 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =  new NotificationCompat.Builder(xdrip.getAppContext(), NotificationChannels.PARAKEET_STATUS_CHANNEL)
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(xdrip.getAppContext().getResources(), R.drawable.jamorham_parakeet_marker))
                .setContentTitle(title)
                .setContentText(body)
                .setAutoCancel(true)
             //   .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        if (!((PowerStateReceiver.is_power_connected()) && (Pref.getBooleanDefaultFalse("parakeet_charge_silent"))))
        {
            notificationBuilder.setSound(defaultSoundUri);
        }

        NotificationManager notificationManager =
                (NotificationManager) xdrip.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.cancel(Notifications.parakeetMissingId);
        notificationManager.notify(Notifications.parakeetMissingId, XdripNotificationCompat.build(notificationBuilder));
    } else {
        Log.d(TAG, "Not sending parakeet notification as they are disabled: " + body);
    }
}
 
Example #26
Source File: AlertType.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static AlertType get_highest_active_alert(Context context, double bg, AtomicBoolean unclearReading) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "Notifications are currently disabled!!");
        return null;
    }

    if (bg <= 14) { // Special dexcom codes should not set off low alarms
        return null;
    }

    Boolean bg_unclear_readings_alerts = prefs.getBoolean("bg_unclear_readings_alerts", false);
    Long UnclearTimeSetting = Long.parseLong(prefs.getString("bg_unclear_readings_minutes", "90")) * 60000;

    Long UnclearTime = BgReading.getUnclearTime(UnclearTimeSetting);

    AlertType at;
    if (UnclearTime >= UnclearTimeSetting && bg_unclear_readings_alerts ) {
        Log.d("NOTIFICATIONS", "Readings have been unclear for too long!!");
        unclearReading.set(true);
        Notifications.bgUnclearAlert(context);
    }
    if ((UnclearTime > 0 ) && bg_unclear_readings_alerts) {
        Log.d(TAG_ALERT, "We are in an clear state, but not for too long. Alerts are disabled");
        return null;
    }
    at = get_highest_active_alert_helper(bg, prefs);
    if (at != null) {
        Log.d(TAG_ALERT, "get_highest_active_alert_helper returned alert uuid = " + at.uuid + " alert name = " + at.name);
    } else {
        Log.d(TAG_ALERT, "get_highest_active_alert_helper returned NULL");
    }
    return at;
}
 
Example #27
Source File: BgReading.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    if(IsUnclearTime(context)) {
        Log.d(TAG_ALERT, "checkForRisingAllert we are in an clear time, returning without doing anything");
        return ;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #28
Source File: BgReading.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForDropAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean falling_alert = prefs.getBoolean("falling_alert", false);
    if(!falling_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.d("NOTIFICATIONS", "checkForDropAllert: Notifications are currently disabled!!");
        return;
    }

    if(IsUnclearTime(context)) {
        Log.d(TAG_ALERT, "checkForDropAllert we are in an clear time, returning without doing anything");
        return ;
    }

    String dropRate = prefs.getString("falling_bg_val", "2");
    float fdropRate = 2;

    try
    {
        fdropRate = Float.parseFloat(dropRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.i(TAG_ALERT, "checkForDropAllert will check for rate of " + fdropRate);

    boolean dropAlert = checkForDropRiseAllert(fdropRate, true);
    Notifications.DropAlert(context, dropAlert);
}
 
Example #29
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 #30
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_export_database) {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... params) {
                return DatabaseUtil.saveSql(getBaseContext());
            }

            @Override
            protected void onPostExecute(String filename) {
                super.onPostExecute(filename);

                final Context ctx = getApplicationContext();

                Toast.makeText(ctx, "Export stored at " + filename, Toast.LENGTH_SHORT).show();

                final NotificationCompat.Builder n = new NotificationCompat.Builder(ctx);
                n.setContentTitle("Export complete");
                n.setContentText("Ready to be sent.");
                n.setAutoCancel(true);
                n.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on);
                ShareNotification.viewOrShare("application/octet-stream", Uri.fromFile(new File(filename)), n, ctx);

                final NotificationManager manager = (NotificationManager) ctx.getSystemService(Service.NOTIFICATION_SERVICE);
                manager.notify(Notifications.exportCompleteNotificationId, n.build());
            }
        }.execute();

        return true;
    }
    return super.onOptionsItemSelected(item);
}