Java Code Examples for com.eveningoutpost.dexdrip.Home#startHomeWithExtra()

The following examples show how to use com.eveningoutpost.dexdrip.Home#startHomeWithExtra() . 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: ActivityRecognizedService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void interpretRatio(Context context) {
    final long requested = getInternalPrefsLong(REQUESTED);
    final long received = getInternalPrefsLong(RECEIVED);

    if (requested > 0) {
        Log.d(TAG, "Requested: " + requested + " Received: " + received);
        if (requested == 10) {
            if (received < 4) {
                UserError.Log.ueh(TAG, "Issuing full screen wakeup as req: " + getInternalPrefsLong(REQUESTED) + " rec: " + getInternalPrefsLong(RECEIVED));
                Home.startHomeWithExtra(context, Home.HOME_FULL_WAKEUP, "1");
            }
        } else if (requested == 15) {
            if ((received < 4) && (!PowerStateReceiver.is_power_connected())) {
           disableMotionTrackingDueToErrors(context);
            }
        }

        if (requested > 20) {
            evaluateRequestReceivedCounters(false,context);
            resetRequestedReceivedCounters();
        }
    }
}
 
Example 2
Source File: ActivityRecognizedService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void interpretRatio(Context context) {
    final long requested = getInternalPrefsLong(REQUESTED);
    final long received = getInternalPrefsLong(RECEIVED);

    if (requested > 0) {
        Log.d(TAG, "Requested: " + requested + " Received: " + received);
        if (requested == 10) {
            if (received < 4) {
                UserError.Log.ueh(TAG, "Issuing full screen wakeup as req: " + getInternalPrefsLong(REQUESTED) + " rec: " + getInternalPrefsLong(RECEIVED));
                Home.startHomeWithExtra(context, Home.HOME_FULL_WAKEUP, "1");
            }
        } else if (requested == 15) {
            if ((received < 4) && (!PowerStateReceiver.is_power_connected())) {
           disableMotionTrackingDueToErrors(context);
            }
        }

        if (requested > 20) {
            evaluateRequestReceivedCounters(false,context);
            resetRequestedReceivedCounters();
        }
    }
}
 
Example 3
Source File: SnoozeOnNotificationDismissService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    String alertType = (intent != null) ? intent.getStringExtra("alertType") : "null intent"; // Replace by constant
    if (alertType == null) alertType = "null";
    final long time_showing = (intent != null) ? JoH.msSince(intent.getLongExtra("raisedTimeStamp", JoH.tsl() - 10 * Constants.MINUTE_IN_MS)) : 10 * Constants.MINUTE_IN_MS;
    if (time_showing <= MINIMUM_CANCEL_DELAY) {
        UserError.Log.wtf(TAG, "Attempt to cancel alert (" + alertType + ") within minimum limit of: " + JoH.niceTimeScalar(MINIMUM_CANCEL_DELAY));
        Home.startHomeWithExtra(xdrip.getAppContext(),"confirmsnooze","simpleconfirm");
    }
    Log.e(TAG, "SnoozeOnNotificationDismissService called source = " + alertType + " shown for: " + JoH.niceTimeScalar(time_showing));
    if (alertType.equals("bg_alerts") && (time_showing > MINIMUM_CANCEL_DELAY)) {
        snoozeBgAlert();
        return;
    }
    if (alertType.equals("bg_unclear_readings_alert") ||
            alertType.equals("bg_missed_alerts")) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        boolean enableAlertsReraise = prefs.getBoolean(alertType + "_enable_alerts_reraise", false);
        if (enableAlertsReraise && (time_showing > MINIMUM_CANCEL_DELAY)) {
            // Only snooze these alert if it the reraise function is enabled. 
            snoozeOtherAlert(alertType);
        }
        return;
    }

    if (alertType.equals("bg_predict_alert") ||
            alertType.equals("persistent_high_alert")) {
        Log.wtf(TAG, "SnoozeOnNotificationDismissService called for unsupported type!!! source = " + alertType);

    }

    Log.e(TAG, "SnoozeOnNotificationDismissService called for unknown source = " + alertType);
}
 
Example 4
Source File: SnoozeOnNotificationDismissService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    String alertType = (intent != null) ? intent.getStringExtra("alertType") : "null intent"; // Replace by constant
    if (alertType == null) alertType = "null";
    final long time_showing = (intent != null) ? JoH.msSince(intent.getLongExtra("raisedTimeStamp", JoH.tsl() - 10 * Constants.MINUTE_IN_MS)) : 10 * Constants.MINUTE_IN_MS;
    if (time_showing <= MINIMUM_CANCEL_DELAY) {
        UserError.Log.wtf(TAG, "Attempt to cancel alert (" + alertType + ") within minimum limit of: " + JoH.niceTimeScalar(MINIMUM_CANCEL_DELAY));
        Home.startHomeWithExtra(xdrip.getAppContext(),"confirmsnooze","simpleconfirm");
    }
    Log.e(TAG, "SnoozeOnNotificationDismissService called source = " + alertType + " shown for: " + JoH.niceTimeScalar(time_showing));
    if (alertType.equals("bg_alerts") && (time_showing > MINIMUM_CANCEL_DELAY)) {
        snoozeBgAlert();
        return;
    }
    if (alertType.equals("bg_unclear_readings_alert") ||
            alertType.equals("bg_missed_alerts")) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        boolean enableAlertsReraise = prefs.getBoolean(alertType + "_enable_alerts_reraise", false);
        if (enableAlertsReraise && (time_showing > MINIMUM_CANCEL_DELAY)) {
            // Only snooze these alert if it the reraise function is enabled. 
            snoozeOtherAlert(alertType);
        }
        return;
    }

    if (alertType.equals("bg_predict_alert") ||
            alertType.equals("persistent_high_alert")) {
        Log.wtf(TAG, "SnoozeOnNotificationDismissService called for unsupported type!!! source = " + alertType);

    }

    Log.e(TAG, "SnoozeOnNotificationDismissService called for unknown source = " + alertType);
}
 
Example 5
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
synchronized static void opportunisticCalibration() {
    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
        final BloodTest bt = lastValid();
        if (bt == null) {
            Log.d(TAG, "opportunistic: No blood tests");
            return;
        }
        if (JoH.msSince(bt.timestamp) > (Constants.HOUR_IN_MS * 8)) {
            Log.d(TAG, "opportunistic: Blood test older than 8 hours ago");
            return;
        }

        if ((bt.uuid == null) || (bt.uuid.length() < 8)) {
            Log.d(TAG, "opportunisitic: invalid uuid");
            return;
        }

        if ((bt.uuid != null) && (bt.uuid.length() > 1) && PersistentStore.getString(LAST_BT_AUTO_CALIB_UUID).equals(bt.uuid)) {
            Log.d(TAG, "opportunistic: Already processed uuid: " + bt.uuid);
            return;
        }

        final Calibration calibration = Calibration.lastValid();
        if (calibration == null) {
            Log.d(TAG, "opportunistic: No calibrations");
            // TODO do we try to initial calibrate using this?
            return;
        }

        if (JoH.msSince(calibration.timestamp) < Constants.HOUR_IN_MS) {
            Log.d(TAG, "opportunistic: Last calibration less than 1 hour ago");
            return;
        }

        if (bt.timestamp <= calibration.timestamp) {
            Log.d(TAG, "opportunistic: Blood test isn't more recent than last calibration");
            return;
        }

        // get closest bgreading - must be within dexcom period and locked to sensor
        final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
        if (bgReading == null) {
            Log.d(TAG, "opportunistic: No matching bg reading");
            return;
        }

        if (bt.timestamp > highest_timestamp) {
            Accuracy.create(bt, bgReading, "xDrip Original");
            final CalibrationAbstract plugin = PluggableCalibration.getCalibrationPluginFromPreferences();
            final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
            if (plugin != null) {
                BgReading pluginBgReading = plugin.getBgReadingFromBgReading(bgReading, cd);
                Accuracy.create(bt, pluginBgReading, plugin.getAlgorithmName());
            }
            highest_timestamp = bt.timestamp;
        }

        if (!CalibrationRequest.isSlopeFlatEnough(bgReading)) {
            Log.d(TAG, "opportunistic: Slope is not flat enough at: " + JoH.dateTimeText(bgReading.timestamp));
            return;
        }

        // TODO store evaluation failure for this record in cache for future optimization

        // TODO Check we have prior reading as well perhaps
        JoH.clearCache();
        UserError.Log.ueh(TAG, "Opportunistic calibration for Blood Test at " + JoH.dateTimeText(bt.timestamp) + " of " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " matching sensor slope at: " + JoH.dateTimeText(bgReading.timestamp) + " from source " + bt.source);
        final long time_since = JoH.msSince(bt.timestamp);


        Log.d(TAG, "opportunistic: attempting auto calibration");
        PersistentStore.setString(LAST_BT_AUTO_CALIB_UUID, bt.uuid);
        Home.startHomeWithExtra(xdrip.getAppContext(),
                Home.BLUETOOTH_METER_CALIBRATION,
                BgGraphBuilder.unitized_string_static(bt.mgdl),
                Long.toString(time_since),
                "auto");
    }
}
 
Example 6
Source File: ActivityRecognizedService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static void startupInfo() {
    if (ShotStateStore.hasShot(Home.SHOWCASE_MOTION_DETECTION)) return;
    Home.startHomeWithExtra(xdrip.getAppContext(), Home.ACTIVITY_SHOWCASE_INFO, "");
}
 
Example 7
Source File: BluetoothGlucoseMeter.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void evaluateLastRecords() {
    if (lastBloodTest != null) {
        GcmActivity.syncBloodTests();

        final boolean delay_calibration = true;
        final GlucoseReadingRx lastGlucoseRecord = lastBloodTest.glucoseReadingRx;
        if ((lastGlucoseRecord != null) && (lastGlucoseRecord.device != null) && (ct != null)) {
            final String sequence_id = "last-btm-sequence-" + lastGlucoseRecord.device;
            final String timestamp_id = "last-btm-timestamp" + lastGlucoseRecord.device;
            // sequence numbers start from 0 so we add 1
            if ((lastGlucoseRecord.sequence + 1) > PersistentStore.getLong(sequence_id)) {
                PersistentStore.setLong(sequence_id, lastGlucoseRecord.sequence + 1);
                // get adjusted timestamp
                if (lastBloodTest.timestamp > PersistentStore.getLong(timestamp_id)) {
                    PersistentStore.setLong(timestamp_id, lastBloodTest.timestamp);
                    Log.d(TAG, "evaluateLastRecords: appears to be a new record: sequence:" + lastGlucoseRecord.sequence);
                    JoH.runOnUiThreadDelayed(Home::staticRefreshBGCharts, 300);
                    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")
                            || Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                        final long time_since = JoH.msSince(lastBloodTest.timestamp);
                        if (time_since >= 0) {
                            if (time_since < (12 * Constants.HOUR_IN_MS)) {
                                final Calibration calibration = Calibration.lastValid();
                                // check must also be younger than most recent calibration
                                if ((calibration == null) || (lastBloodTest.timestamp > calibration.timestamp)) {
                                    UserError.Log.ueh(TAG, "Prompting for calibration for: " + BgGraphBuilder.unitized_string_with_units_static(lastBloodTest.mgdl) + " from: " + JoH.dateTimeText(lastBloodTest.timestamp));
                                    JoH.clearCache();
                                    Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1");
                                    JoH.runOnUiThreadDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Home.staticRefreshBGCharts();
                                            // requires offset in past

                                            if ((Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto") && isSlopeFlatEnough())) {
                                                Log.d(TAG, "Slope flat enough for auto calibration");
                                                if (!delay_calibration) {
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "auto");
                                                } else {
                                                    Log.d(TAG, "Delaying calibration for later");
                                                    JoH.static_toast_long("Waiting for 15 minutes more sensor data for calibration");
                                                }
                                            } else {
                                                if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")) {
                                                    // manual calibration
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "manual");
                                                } else {
                                                    Log.d(TAG, "Not flat enough slope for auto calibration and manual calibration not enabled");
                                                }
                                            }
                                        }
                                    }, 500);
                                } else {
                                    UserError.Log.e(TAG, "evaluateLastRecords: meter reading is at least as old as last calibration - ignoring");
                                }
                            } else {
                                UserError.Log.e(TAG, "evaluateLastRecords: meter reading is too far in the past: " + JoH.dateTimeText(lastBloodTest.timestamp));
                            }
                        } else {
                            UserError.Log.e(TAG, "evaluateLastRecords: time is in the future - ignoring");
                        }
                    }
                }
            } else {
                UserError.Log.d(TAG, "evaluateLastRecords: sequence isn't newer");
            }
        } else {
            UserError.Log.e(TAG, "evaluateLastRecords: Data missing for evaluation");
        }
    } else {
        UserError.Log.e(TAG, "evaluateLastRecords: lastBloodTest is Null!!");
    }
}
 
Example 8
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
synchronized static void opportunisticCalibration() {
    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
        final BloodTest bt = lastValid();
        if (bt == null) {
            Log.d(TAG, "opportunistic: No blood tests");
            return;
        }
        if (JoH.msSince(bt.timestamp) > (Constants.HOUR_IN_MS * 8)) {
            Log.d(TAG, "opportunistic: Blood test older than 8 hours ago");
            return;
        }

        if ((bt.uuid == null) || (bt.uuid.length() < 8)) {
            Log.d(TAG, "opportunisitic: invalid uuid");
            return;
        }

        if ((bt.uuid != null) && (bt.uuid.length() > 1) && PersistentStore.getString(LAST_BT_AUTO_CALIB_UUID).equals(bt.uuid)) {
            Log.d(TAG, "opportunistic: Already processed uuid: " + bt.uuid);
            return;
        }

        final Calibration calibration = Calibration.lastValid();
        if (calibration == null) {
            Log.d(TAG, "opportunistic: No calibrations");
            // TODO do we try to initial calibrate using this?
            return;
        }

        if (JoH.msSince(calibration.timestamp) < Constants.HOUR_IN_MS) {
            Log.d(TAG, "opportunistic: Last calibration less than 1 hour ago");
            return;
        }

        if (bt.timestamp <= calibration.timestamp) {
            Log.d(TAG, "opportunistic: Blood test isn't more recent than last calibration");
            return;
        }

        // get closest bgreading - must be within dexcom period and locked to sensor
        final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD);
        if (bgReading == null) {
            Log.d(TAG, "opportunistic: No matching bg reading");
            return;
        }

        if (bt.timestamp > highest_timestamp) {
            Accuracy.create(bt, bgReading, "xDrip Original");
            final CalibrationAbstract plugin = PluggableCalibration.getCalibrationPluginFromPreferences();
            final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null;
            if (plugin != null) {
                BgReading pluginBgReading = plugin.getBgReadingFromBgReading(bgReading, cd);
                Accuracy.create(bt, pluginBgReading, plugin.getAlgorithmName());
            }
            highest_timestamp = bt.timestamp;
        }

        if (!CalibrationRequest.isSlopeFlatEnough(bgReading)) {
            Log.d(TAG, "opportunistic: Slope is not flat enough at: " + JoH.dateTimeText(bgReading.timestamp));
            return;
        }

        // TODO store evaluation failure for this record in cache for future optimization

        // TODO Check we have prior reading as well perhaps
        JoH.clearCache();
        UserError.Log.ueh(TAG, "Opportunistic calibration for Blood Test at " + JoH.dateTimeText(bt.timestamp) + " of " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " matching sensor slope at: " + JoH.dateTimeText(bgReading.timestamp) + " from source " + bt.source);
        final long time_since = JoH.msSince(bt.timestamp);


        Log.d(TAG, "opportunistic: attempting auto calibration");
        PersistentStore.setString(LAST_BT_AUTO_CALIB_UUID, bt.uuid);
        Home.startHomeWithExtra(xdrip.getAppContext(),
                Home.BLUETOOTH_METER_CALIBRATION,
                BgGraphBuilder.unitized_string_static(bt.mgdl),
                Long.toString(time_since),
                "auto");
    }
}
 
Example 9
Source File: ActivityRecognizedService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static void startupInfo() {
    if (ShotStateStore.hasShot(Home.SHOWCASE_MOTION_DETECTION)) return;
    Home.startHomeWithExtra(xdrip.getAppContext(), Home.ACTIVITY_SHOWCASE_INFO, "");
}
 
Example 10
Source File: BluetoothGlucoseMeter.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void evaluateLastRecords() {
    if (lastBloodTest != null) {
        GcmActivity.syncBloodTests();

        final boolean delay_calibration = true;
        final GlucoseReadingRx lastGlucoseRecord = lastBloodTest.glucoseReadingRx;
        if ((lastGlucoseRecord != null) && (lastGlucoseRecord.device != null) && (ct != null)) {
            final String sequence_id = "last-btm-sequence-" + lastGlucoseRecord.device;
            final String timestamp_id = "last-btm-timestamp" + lastGlucoseRecord.device;
            // sequence numbers start from 0 so we add 1
            if ((lastGlucoseRecord.sequence + 1) > PersistentStore.getLong(sequence_id)) {
                PersistentStore.setLong(sequence_id, lastGlucoseRecord.sequence + 1);
                // get adjusted timestamp
                if (lastBloodTest.timestamp > PersistentStore.getLong(timestamp_id)) {
                    PersistentStore.setLong(timestamp_id, lastBloodTest.timestamp);
                    Log.d(TAG, "evaluateLastRecords: appears to be a new record: sequence:" + lastGlucoseRecord.sequence);
                    JoH.runOnUiThreadDelayed(Home::staticRefreshBGCharts, 300);
                    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")
                            || Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                        final long time_since = JoH.msSince(lastBloodTest.timestamp);
                        if (time_since >= 0) {
                            if (time_since < (12 * Constants.HOUR_IN_MS)) {
                                final Calibration calibration = Calibration.lastValid();
                                // check must also be younger than most recent calibration
                                if ((calibration == null) || (lastBloodTest.timestamp > calibration.timestamp)) {
                                    UserError.Log.ueh(TAG, "Prompting for calibration for: " + BgGraphBuilder.unitized_string_with_units_static(lastBloodTest.mgdl) + " from: " + JoH.dateTimeText(lastBloodTest.timestamp));
                                    JoH.clearCache();
                                    Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1");
                                    JoH.runOnUiThreadDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Home.staticRefreshBGCharts();
                                            // requires offset in past

                                            if ((Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto") && isSlopeFlatEnough())) {
                                                Log.d(TAG, "Slope flat enough for auto calibration");
                                                if (!delay_calibration) {
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "auto");
                                                } else {
                                                    Log.d(TAG, "Delaying calibration for later");
                                                    JoH.static_toast_long("Waiting for 15 minutes more sensor data for calibration");
                                                }
                                            } else {
                                                if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")) {
                                                    // manual calibration
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "manual");
                                                } else {
                                                    Log.d(TAG, "Not flat enough slope for auto calibration and manual calibration not enabled");
                                                }
                                            }
                                        }
                                    }, 500);
                                } else {
                                    UserError.Log.e(TAG, "evaluateLastRecords: meter reading is at least as old as last calibration - ignoring");
                                }
                            } else {
                                UserError.Log.e(TAG, "evaluateLastRecords: meter reading is too far in the past: " + JoH.dateTimeText(lastBloodTest.timestamp));
                            }
                        } else {
                            UserError.Log.e(TAG, "evaluateLastRecords: time is in the future - ignoring");
                        }
                    }
                }
            } else {
                UserError.Log.d(TAG, "evaluateLastRecords: sequence isn't newer");
            }
        } else {
            UserError.Log.e(TAG, "evaluateLastRecords: Data missing for evaluation");
        }
    } else {
        UserError.Log.e(TAG, "evaluateLastRecords: lastBloodTest is Null!!");
    }
}