com.eveningoutpost.dexdrip.UtilityModels.Constants Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Constants. 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: DBSearchUtil.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static int noReadingsAboveRange(Context context) {
    Bounds bounds = new Bounds().invoke();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));

    double high = Double.parseDouble(settings.getString("highValue", "170"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
    }

    int count = new Select()
            .from(BgReading.class)
            .where("timestamp >= " + bounds.start)
            .where("timestamp <= " + bounds.stop)
            .where("calculated_value > " + CUTOFF)
            .where("calculated_value > " + high)
            .where("snyced == 0").count();
    Log.d("DrawStats", "High count: " + count);
    return count;
}
 
Example #2
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void injectDisplayGlucose(BestGlucose.DisplayGlucose displayGlucose) {
    //displayGlucose can be null. E.g. when out of order values come in
    if (displayGlucose != null) {
        if (Math.abs(displayGlucose.timestamp - timestamp) < Constants.MINUTE_IN_MS * 10) {
            dg_mgdl = displayGlucose.mgdl;
            dg_slope = displayGlucose.slope;
            dg_delta_name = displayGlucose.delta_name;
            // TODO we probably should reflect the display glucose delta here as well for completeness
            this.save();
        } else {
            if (JoH.ratelimit("cannotinjectdg", 30)) {
                UserError.Log.e(TAG, "Cannot inject display glucose value as time difference too great: " + JoH.dateTimeText(displayGlucose.timestamp) + " vs " + JoH.dateTimeText(timestamp));
            }
        }
    }
}
 
Example #3
Source File: GcmActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
static void pushCalibration2(double bgValue, String uuid, long offset) {
    Log.i(TAG, "pushCalibration2 called: " + JoH.qs(bgValue, 1) + " " + uuid + " " + offset);
    if (Home.get_master_or_follower()) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
        final String unit = prefs.getString("units", "mgdl");

        if (unit.compareTo("mgdl") != 0) {
            bgValue = bgValue * Constants.MMOLL_TO_MGDL;
        }

        if ((bgValue < 40) || (bgValue > 400)) {
            Log.wtf(TAG, "Invalid out of range calibration glucose mg/dl value of: " + bgValue);
            JoH.static_toast_long("Calibration out of range: " + bgValue + " mg/dl");
            return;
        }
        final String json = newCalibrationToJson(bgValue, uuid, offset);
        GcmActivity.sendMessage(myIdentity(), "cal2", json);
    }
}
 
Example #4
Source File: Accuracy.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static Accuracy create(BloodTest bloodTest, BgReading bgReading, String plugin) {
    if ((bloodTest == null) || (bgReading == null)) return null;
    patched = fixUpTable(schema, patched);
    if (getForPreciseTimestamp(bgReading.timestamp, Constants.MINUTE_IN_MS, plugin) != null) {
        UserError.Log.d(TAG, "Duplicate accuracy timestamp for: " + JoH.dateTimeText(bgReading.timestamp));
        return null;
    }
    final Accuracy ac = new Accuracy();
    ac.timestamp = bgReading.timestamp;
    ac.bg = bloodTest.mgdl;
    ac.bgtimestamp = bloodTest.timestamp;
    ac.bgsource = bloodTest.source;
    ac.plugin = plugin;
    ac.calculated = bgReading.calculated_value;
    //ac.lag = bgReading.timestamp-bloodTest.timestamp;
    ac.difference = bgReading.calculated_value - bloodTest.mgdl;
    ac.save();
    return ac;
}
 
Example #5
Source File: RecordRx.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public RecordRx fromBytes(final byte[] bytes) {

    if (bytes.length != 16) return null;
    this.bytes = bytes;
    buffer = ByteBuffer.wrap(this.bytes);
    index = unsignedShortToInt(buffer.getShort());
    flags = unsignedByteToInt(buffer.get());
    final int timeStampSeconds = buffer.getInt();
    units = ((float) buffer.getShort()) / 2; // negative implies rewind
    temperature = buffer.get();
    battery = buffer.get();
    final int timestampTwentieths = unsignedByteToInt(buffer.get());
    this.timestamp = timeStampSeconds * Constants.SECOND_IN_MS + timestampTwentieths * 50;
    duration = unsignedShortToInt(buffer.getShort()) * 50;
    checkSum = unsignedShortToInt(buffer.getShort());
    this.checksumValid = checksum(bytes) == checkSum;

    return this;
}
 
Example #6
Source File: MedtrumCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void setRetryTimerReal() {
    if (shouldServiceRun()) {
        final long retry_in = whenToRetryNext();
        UserError.Log.d(TAG, "setRetryTimer: Restarting in: " + (retry_in / Constants.SECOND_IN_MS) + " seconds");
        // serviceIntent = PendingIntent.getService(this, MEDTRUM_SERVICE_RETRY_ID,
        //         new Intent(this, this.getClass()), 0);
        serviceIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), MEDTRUM_SERVICE_RETRY_ID);
        retry_time = JoH.wakeUpIntent(this, retry_in, serviceIntent);
        wakeup_time = JoH.tsl() + retry_in;
    } else {
        UserError.Log.d(TAG, "Not setting retry timer as service should not be running");
    }
}
 
Example #7
Source File: NightscoutBackfillActivity.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    xdrip.checkForcedEnglish(this);
    setTitle("Nightscout Backfill");
    super.onResume();
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), "Nightscout Backfill", this);

    if (JoH.msSince(locked) < Constants.HOUR_IN_MS) {
        JoH.static_toast_long(gs(R.string.still_processing_previous_backfill_request));
        finish();
    }
}
 
Example #8
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static long getTimeShift(List<GlucoseData> gds) {
    long nearest = -1;
    for (GlucoseData gd : gds) {
        if (gd.realDate > nearest) nearest = gd.realDate;
    }
    timeShiftNearest = nearest;
    if (nearest > 0) {
        final long since = JoH.msSince(nearest);
        if ((since > 0) && (since < Constants.MINUTE_IN_MS * 5)) {
            return since;
        }
    }
    return 0;
}
 
Example #9
Source File: BgToSpeech.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static String calculateText(double value, String delta_name) {

        final boolean doMgdl = (Pref.getString("units", "mgdl").equals("mgdl"));
        final boolean bg_to_speech_repeat_twice = (Pref.getBooleanDefaultFalse("bg_to_speech_repeat_twice"));
        String text = "";

        // TODO does some of this need unifying from best glucose etc?
        final DecimalFormat df = new DecimalFormat("#");
        if (value >= 400) {
            text = xdrip.getAppContext().getString(R.string.high);
        } else if (value >= 40) {
            if (doMgdl) {
                df.setMaximumFractionDigits(0);
                text = df.format(value);
            } else {
                df.setMaximumFractionDigits(1);
                df.setMinimumFractionDigits(1);
                text = df.format(value * Constants.MGDL_TO_MMOLL);
                try {
                    // we check the locale but it may not actually be available if the instance isn't created yet
                    if (SpeechUtil.getLocale().getLanguage().startsWith("en")) {
                        // in case the text has a comma in current locale but TTS defaults to English
                        text = text.replace(",", ".");
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Null pointer for TTS in calculateText");
                }
            }
            if (delta_name != null) text += " " + mungeDeltaName(delta_name);
            if (bg_to_speech_repeat_twice) text = text + TWICE_DELIMITER + text;
        } else if (value > 12) {
            text = xdrip.getAppContext().getString(R.string.low);
        } else {
            text = xdrip.getAppContext().getString(R.string.error);
        }
        Log.d(TAG, "calculated text: " + text);
        return text;
    }
 
Example #10
Source File: BlueJayService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setRetryTimerReal() {
    if (shouldServiceRun()) {
        final long retry_in = whenToRetryNext();
        UserError.Log.d(TAG, "setRetryTimer: Restarting in: " + (retry_in / Constants.SECOND_IN_MS) + " seconds");
        I.serviceIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), Constants.BLUEJAY_SERVICE_RETRY_ID, "wakeup");
        I.retry_time = JoH.wakeUpIntent(xdrip.getAppContext(), retry_in, I.serviceIntent);
        I.wakeup_time = JoH.tsl() + retry_in;
    } else {
        UserError.Log.d(TAG, "Not setting retry timer as service should not be running");
    }
}
 
Example #11
Source File: ShareFollowDownload.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void handleLoginFailure() {
    UserError.Log.d(TAG, "Login failure: " + session.getErrorString() + " code: " + session.getLastResponseCode());
    if (session.getLastResponseCode() == 0) {
        msg(xdrip.gs(R.string.connectivity_problem_reaching_share_servers));
    } else {
        msg("Share login error: " + session.getErrorString() + " code: " + session.getLastResponseCode());
        loginBackoff += Constants.MINUTE_IN_MS;
        loginBlockedTill = JoH.tsl() + loginBackoff;
    }
    releaseWakeLock();
}
 
Example #12
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 #13
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private long whenToRetryNext() {
    final long poll_time = Math.max((Constants.SECOND_IN_MS * 10) + retry_backoff, RETRY_PERIOD - JoH.msSince(lastPacketTime));
    if (retry_backoff < (Constants.MINUTE_IN_MS)) {
        retry_backoff += Constants.SECOND_IN_MS;
    }
    Log.d(TAG, "Scheduling next retry in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (RETRY_PERIOD - JoH.msSince(lastPacketTime)));
    return poll_time;
}
 
Example #14
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void scan() {
    extendWakeLock((scanSeconds + 1) * Constants.SECOND_IN_MS);
    stopScan("Scan start");
    UserError.Log.d(TAG, "startScan called: hunting: " + address + " " + name);

    ScanFilter filter = this.customFilter;
    if (filter == null) {
        final ScanFilter.Builder builder = new ScanFilter.Builder();
        if (address != null) {
            try {
                builder.setDeviceAddress(address);
            } catch (IllegalArgumentException e) {
                UserError.Log.wtf(TAG, "Invalid bluetooth address: " + address);
            }
        }
        // TODO scanning by name doesn't build a filter
        filter = builder.build();
    } else {
        UserError.Log.d(TAG,"Overriding with custom filter");
    }

    scanSubscription = new Subscription(rxBleClient.scanBleDevices(
            new ScanSettings.Builder()
                    .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
                    .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                    .build(), legacyNoFilterWorkaround ? ScanFilter.empty() : filter)
            .timeout(scanSeconds, TimeUnit.SECONDS) // is unreliable
            .subscribeOn(Schedulers.io())
            .subscribe(this::onScanResult, this::onScanFailure));

    Inevitable.task(STOP_SCAN_TASK_ID, scanSeconds * Constants.SECOND_IN_MS, this::stopScanWithTimeoutCallback);
}
 
Example #15
Source File: DailyJob.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void schedule() {
    if (JoH.pratelimit("daily-job-schedule", 60000)) {
        UserError.Log.uel(TAG, JoH.dateTimeText(JoH.tsl()) + " Job Scheduled"); // Debug only
        new JobRequest.Builder(TAG)
                .setPeriodic(Constants.DAY_IN_MS, Constants.HOUR_IN_MS * 12)
                .setRequiresDeviceIdle(true)
                .setRequiresCharging(true)
                .setRequiredNetworkType(JobRequest.NetworkType.UNMETERED)
                .setUpdateCurrent(true)
                .build()
                .schedule();
    }
}
 
Example #16
Source File: TransmitterData.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized TransmitterData create(int raw_data ,int sensor_battery_level, long timestamp) {
    TransmitterData lastTransmitterData = TransmitterData.last();
    if (lastTransmitterData != null && lastTransmitterData.raw_data == raw_data && Math.abs(lastTransmitterData.timestamp - new Date().getTime()) < (Constants.MINUTE_IN_MS * 2)) { //Stop allowing duplicate data, its bad!
        return null;
    }

    TransmitterData transmitterData = new TransmitterData();
    transmitterData.sensor_battery_level = sensor_battery_level;
    transmitterData.raw_data = raw_data ;
    transmitterData.timestamp = timestamp;
    transmitterData.uuid = UUID.randomUUID().toString();
    transmitterData.save();
    return transmitterData;
}
 
Example #17
Source File: DesertSync.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static String getMyRollCall(final String topic) {
    if (topic != null && topic.equals(getTopic())) {
        if (myRollCall == null || JoH.msSince(myRollCall.created) > Constants.MINUTE_IN_MS * 15) {
            myRollCall = new RollCall();
        }
        return myRollCall.populate().toS();
    } else {
        return "Invalid topic";
    }
}
 
Example #18
Source File: LeFunService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setRetryTimerReal() {
    if (shouldServiceRun()) {
        final long retry_in = whenToRetryNext();
        UserError.Log.d(TAG, "setRetryTimer: Restarting in: " + (retry_in / Constants.SECOND_IN_MS) + " seconds");
        I.serviceIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), Constants.LEFUN_SERVICE_RETRY_ID);
        //PendingIntent.getService(xdrip.getAppContext(), Constants.LEFUN_SERVICE_RETRY_ID,
        //        new Intent(xdrip.getAppContext(), this.getClass()), 0);
        I.retry_time = JoH.wakeUpIntent(xdrip.getAppContext(), retry_in, I.serviceIntent);
        I.wakeup_time = JoH.tsl() + retry_in;
    } else {
        UserError.Log.d(TAG, "Not setting retry timer as service should not be running");
    }
}
 
Example #19
Source File: NightscoutBackfillActivity.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nightscout_backfill);
    JoH.fixActionBar(this);
    dateButton = (Button) findViewById(R.id.backfillDateButton);
    doitButton = (Button) findViewById(R.id.startbackfill);
    calendar = Calendar.getInstance();
    calendar.setTimeInMillis(JoH.tsl() - Constants.DAY_IN_MS);
    updateDateButton();
}
 
Example #20
Source File: BlueJayService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setRetryTimerReal() {
    if (shouldServiceRun()) {
        final long retry_in = whenToRetryNext();
        UserError.Log.d(TAG, "setRetryTimer: Restarting in: " + (retry_in / Constants.SECOND_IN_MS) + " seconds");
        I.serviceIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), Constants.BLUEJAY_SERVICE_RETRY_ID, "wakeup");
        I.retry_time = JoH.wakeUpIntent(xdrip.getAppContext(), retry_in, I.serviceIntent);
        I.wakeup_time = JoH.tsl() + retry_in;
    } else {
        UserError.Log.d(TAG, "Not setting retry timer as service should not be running");
    }
}
 
Example #21
Source File: UploadChunk.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static long getWindowSizePreference() {
    try {
        long value = (long) getLatencySliderValue(Pref.getInt("tidepool_window_latency", 0));
        return Math.max(value * Constants.MINUTE_IN_MS, DEFAULT_WINDOW_OFFSET);
    } catch (Exception e) {
        UserError.Log.e(TAG, "Reverting to default of 15 minutes due to Window Size exception: " + e);
        return DEFAULT_WINDOW_OFFSET; // default
    }
}
 
Example #22
Source File: LibreAlarmReceiver.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static long getTimeShift(List<GlucoseData> gds) {
    long nearest = -1;
    for (GlucoseData gd : gds) {
        if (gd.realDate > nearest) nearest = gd.realDate;
    }
    timeShiftNearest = nearest;
    if (nearest > 0) {
        final long since = JoH.msSince(nearest);
        if ((since > 0) && (since < Constants.MINUTE_IN_MS * 5)) {
            return since;
        }
    }
    return 0;
}
 
Example #23
Source File: VersionFixer.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static String getPeerVersion() {
    final long updated = PersistentStore.getLong(PEER_VERSION_UPDATED);
    if (JoH.msSince(updated) < Constants.MONTH_IN_MS) {
        return PersistentStore.getString(PEER_VERSION);
    }
    return null;
}
 
Example #24
Source File: Medtrum.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized Pair<Long, Integer> getCalibration() {
    final long timestamp = PersistentStore.getLong(PENDING_CALIBRATION_TIMESTAMP);
    final long glucose = PersistentStore.getLong(PENDING_CALIBRATION_GLUCOSE);
    if (glucose == 0 || timestamp == 0 || msSince(timestamp) > Constants.HOUR_IN_MS * 8) {
        return null;
    } else {
        return new Pair<>(timestamp, (int) glucose);
    }

}
 
Example #25
Source File: SensorDays.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static SensorDays get(final DexCollectionType type, final String tx_id) {

        // get cached result
        val result = cache.get(type.toString() + tx_id);
        if (result != null && result.cacheValid()) return result;

        val ths = new SensorDays();

        if (hasLibre(type)) {
            ths.period = Constants.DAY_IN_MS * 14; // TODO 10 day sensors?
            ths.strategy = USE_LIBRE_STRATEGY;

        } else if (hasDexcomRaw(type)) {
            ths.strategy = USE_DEXCOM_STRATEGY;
            val vr2 = (VersionRequest2RxMessage)
                    getFirmwareXDetails(tx_id, 2);
            if (vr2 != null) {
                ths.period = Constants.DAY_IN_MS * vr2.typicalSensorDays;
            } else {
                if (usingG6()) {
                    ths.period = Constants.DAY_IN_MS * 10; // G6 default
                } else {
                    ths.period = Constants.DAY_IN_MS * 7; // G5
                }
            }

        } else {
            // unknown type
        }
        ths.created = tsl();
        cache.put(type.toString() + tx_id, ths);
        return ths;
    }
 
Example #26
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static BloodTest createFromCal(double bg, double timeoffset, String source, String suggested_uuid) {
    final String unit = Pref.getString("units", "mgdl");

    if (unit.compareTo("mgdl") != 0) {
        bg = bg * Constants.MMOLL_TO_MGDL;
    }

    if ((bg < 40) || (bg > 400)) {
        Log.wtf(TAG, "Invalid out of range bloodtest glucose mg/dl value of: " + bg);
        JoH.static_toast_long("Bloodtest out of range: " + bg + " mg/dl");
        return null;
    }

    return create((long) (new Date().getTime() - timeoffset), bg, source, suggested_uuid);
}
 
Example #27
Source File: BgToSpeech.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static String calculateText(double value, String delta_name) {

        final boolean doMgdl = (Pref.getString("units", "mgdl").equals("mgdl"));
        final boolean bg_to_speech_repeat_twice = (Pref.getBooleanDefaultFalse("bg_to_speech_repeat_twice"));
        String text = "";

        // TODO does some of this need unifying from best glucose etc?
        final DecimalFormat df = new DecimalFormat("#");
        if (value >= 400) {
            text = xdrip.getAppContext().getString(R.string.high);
        } else if (value >= 40) {
            if (doMgdl) {
                df.setMaximumFractionDigits(0);
                text = df.format(value);
            } else {
                df.setMaximumFractionDigits(1);
                df.setMinimumFractionDigits(1);
                text = df.format(value * Constants.MGDL_TO_MMOLL);
                try {
                    // we check the locale but it may not actually be available if the instance isn't created yet
                    if (SpeechUtil.getLocale().getLanguage().startsWith("en")) {
                        // in case the text has a comma in current locale but TTS defaults to English
                        text = text.replace(",", ".");
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Null pointer for TTS in calculateText");
                }
            }
            if (delta_name != null) text += " " + mungeDeltaName(delta_name);
            if (bg_to_speech_repeat_twice) text = text + TWICE_DELIMITER + text;
        } else if (value > 12) {
            text = xdrip.getAppContext().getString(R.string.low);
        } else {
            text = xdrip.getAppContext().getString(R.string.error);
        }
        Log.d(TAG, "calculated text: " + text);
        return text;
    }
 
Example #28
Source File: DesertSync.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static String getMyRollCall(final String topic) {
    if (topic != null && topic.equals(getTopic())) {
        if (myRollCall == null || JoH.msSince(myRollCall.created) > Constants.MINUTE_IN_MS * 15) {
            myRollCall = new RollCall();
        }
        return myRollCall.populate().toS();
    } else {
        return "Invalid topic";
    }
}
 
Example #29
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void evaluateG6Settings() {
    if (defaultTransmitter == null) {
        getTransmitterDetails();
    }
    if (haveFirmwareDetails()) {
        if (FirmwareCapability.isTransmitterG6(defaultTransmitter.transmitterId)) {
            if (!usingG6()) {
                setG6bareBones();
                JoH.showNotification("Enabled G6", "G6 Features for old collector automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            }
        }
    }
}
 
Example #30
Source File: APStatus.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static List<APStatus> latestForGraph(int number, long startTime, long endTime) {
    try {
        final List<APStatus> results = new Select()
                .from(APStatus.class)
                .where("timestamp >= " + Math.max(startTime, 0))
                .where("timestamp <= " + endTime)
                .orderBy("timestamp asc") // warn asc!
                .limit(number)
                .execute();
        // extend line to now if we have current data but it is continuation of last record
        // so not generating a new efficient record.
        if (results != null && (results.size() > 0)) {
            final APStatus last = results.get(results.size() - 1);
            final long last_raw_record_timestamp = ExternalStatusService.getLastStatusLineTime();
            // check are not already using the latest.
            if (last_raw_record_timestamp > last.timestamp) {
                final Integer last_recorded_tbr = ExternalStatusService.getTBRInt();
                if (last_recorded_tbr != null) {
                    if ((last.basal_percent == last_recorded_tbr)
                            && (JoH.msSince(last.timestamp) < Constants.HOUR_IN_MS * 3)
                            && (JoH.msSince(ExternalStatusService.getLastStatusLineTime()) < Constants.MINUTE_IN_MS * 20)) {
                        results.add(new APStatus(JoH.tsl(), last_recorded_tbr));
                        UserError.Log.d(TAG, "Adding extension record");
                    }
                }
            }
        }
        return results;
    } catch (android.database.sqlite.SQLiteException e) {
        updateDB();
        return new ArrayList<>();
    }
}