public static String minMaxCarbs(List<ProfileItem> myprofileItemList) { double carbsmin = 9999999; double carbsmax = -1; for (ProfileItem item : myprofileItemList) { if (item.carb_ratio > carbsmax) carbsmax = item.carb_ratio; if (item.carb_ratio < carbsmin) carbsmin = item.carb_ratio; } if (carbsmin == carbsmax) return JoH.qs(carbsmin, -1); return JoH.qs(carbsmin, -1) + " - " + JoH.qs(carbsmax, -1); }
public KeepAliveTxMessage(int time) { this.time = time; data = ByteBuffer.allocate(2); data.put(new byte[]{(byte) opcode, (byte) this.time}); byteSequence = data.order(ByteOrder.LITTLE_ENDIAN).array(); UserError.Log.d(TAG, "New KeepAliveRequestTxMessage: " + JoH.bytesToHex(byteSequence)); } }
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; }
public String bestTime() { final long since = JoH.msSince(timestamp); if (since < Constants.DAY_IN_MS) { return JoH.hourMinuteString(timestamp); } else { return JoH.dateTimeText(timestamp); } }
public static String niceTimeScalarNatural(long t) { if (t > 3000000) t = t + 10000; // round up by 10 seconds if nearly an hour if ((t > Constants.DAY_IN_MS) && (t < Constants.WEEK_IN_MS * 2)) { final SimpleDateFormat df = new SimpleDateFormat("EEEE", Locale.getDefault()); final String day = df.format(new Date(JoH.tsl() + t)); return ((t > Constants.WEEK_IN_MS) ? "next " : "") + day; } else { return niceTimeScalar(t); } }
static void scheduleWakeUp() { final BgReading lastBg = BgReading.lastNoSenssor(); final long last = lastBg != null ? lastBg.timestamp : 0; final long grace = Constants.SECOND_IN_MS * 10; final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace) + grace; UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + " last: " + JoH.dateTimeText(last)); JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(NightscoutFollowService.class, Constants.NSFOLLOW_SERVICE_FAILOVER_ID)); }
final byte[] diag = JoH.hexStringToByteArray(Pref.getStringDefaultBlank("nfc_test_diagnostic")); if ((diag != null) && (diag.length > 0)) { Log.d(TAG, "Diagnostic ->: " + HexDump.dumpHexString(diag, 0, diag.length).trim() + " len: " + diag.length); if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag diagnostic read timeout"); JoH.static_toast_short("NFC diag timeout"); vibrate(context, 3); return null; JoH.benchmark(null); if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag read timeout"); JoH.static_toast_short("NFC read timeout"); vibrate(context, 3); return null; if (replyBlock.length != correct_reply_size) { Log.e(TAG, "Incorrect block size: " + replyBlock.length + " vs " + correct_reply_size); JoH.static_toast_short("NFC invalid data - try again"); if (!addressed) { if (PersistentStore.incrementLong("nfc-address-failures") > 2) { Pref.setBoolean("use_nfc_any_tag", false); JoH.static_toast_short("Turned off any-tag feature"); if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag read timeout"); JoH.static_toast_short("NFC read timeout");
private void scheduleWakeUp(long future, final String info) { if (future <= 0) future = 5000; UserError.Log.d(TAG, "Scheduling wakeup @ " + JoH.dateTimeText(JoH.tsl() + future) + " (" + info + ")"); if (pendingIntent == null) //pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0); pendingIntent = WakeLockTrampoline.getPendingIntent(this.getClass()); wakeup_time = JoH.tsl() + future; JoH.wakeUpIntent(this, future, pendingIntent); }
protected void setAddress(String newAddress) { DisconnectReceiver.addCallBack(this, TAG); if (emptyString(newAddress)) return; newAddress = newAddress.toUpperCase(); if (!JoH.validateMacAddress(newAddress)) { final String msg = "Invalid MAC address: " + newAddress; if (JoH.quietratelimit("jam-invalid-mac", 60)) { UserError.Log.wtf(TAG, msg); JoH.static_toast_long(msg); } return; } if (I.address == null || !I.address.equals(newAddress)) { final String oldAddress = I.address; I.address = newAddress; newAddressEvent(oldAddress, newAddress); } }
public static List<StatusItem> megaStatus() { final KeyStore keyStore = FastStore.getInstance(); final List<StatusItem> l = new ArrayList<>(); l.add(new StatusItem("Tidepool Synced to", niceTimeScalar(msSince(UploadChunk.getLastEnd())) + " ago")); // TODO needs generic message format string final String status = keyStore.getS(TidepoolUploader.STATUS_KEY); if (!JoH.emptyString(status)) { l.add(new StatusItem("Tidepool Status", status)); } return l; } }
public static String prettyTime() { if (isStarted()) { final long elapsed = JoH.msSince(getStart()); if (elapsed < WARMUP_PERIOD) { return JoH.niceTimeScalar((double) WARMUP_PERIOD - elapsed, 1); } else { return JoH.niceTimeScalar((double) elapsed, 1); } } else { return ""; } }
public static void deleteRandomData() { Random rand = new Random(); int minutes_ago_end = rand.nextInt(120); int minutes_ago_start = minutes_ago_end + rand.nextInt(35)+5; long ts_start = JoH.tsl() - minutes_ago_start * Constants.MINUTE_IN_MS; long ts_end = JoH.tsl() - minutes_ago_end * Constants.MINUTE_IN_MS; UserError.Log.d(TAG,"Deleting random bgreadings: "+JoH.dateTimeText(ts_start)+" -> "+JoH.dateTimeText(ts_end)); testDeleteRange(ts_start, ts_end); }
private void setConnectionStatusFollower() { if (GcmListenerSvc.lastMessageReceived == 0) { connection_status.setText(getApplicationContext().getString(R.string.no_data)); } else { connection_status.setText((JoH.qs((JoH.ts() - GcmListenerSvc.lastMessageReceived) / 60000, 0)) + " mins ago"); } } private void setConnectionStatusWifiWixel() {
private void estimateAnticipateFromLinkedData() { final BgReading bg = BgReading.last(); if (bg != null && bg.timestamp > static_last_connected && JoH.msSince(bg.timestamp) < HOUR_IN_MS * 3) { final long ts = bg.timestamp - Constants.SECOND_IN_MS; UserError.Log.d(TAG, "Updating Sync Keeper with network learned timestamp: " + JoH.dateTimeText(ts)); DexSyncKeeper.store(transmitterID, ts); } }
private static void updateStreamedTillTimeForBackfill() { // interact with ListenerService if (JoH.areWeRunningOnAndroidWear()) { final String pref_last_send_previous = "last_send_previous"; final long last_send_previous = PersistentStore.getLong(pref_last_send_previous); PersistentStore.setLong(pref_last_send_previous, Math.min(last_send_previous, JoH.tsl() - MAX_BACKFILL_PERIOD_MS)); } }
public synchronized static boolean setStoredBatteryBytes(String transmitterId, byte[] data) { UserError.Log.e(TAG, "Store: BatteryRX dbg: " + JoH.bytesToHex(data)); if (transmitterId.length() != 6) return false; if (data.length < 10) return false; Log.wtf(TAG, "Saving battery data: " + new BatteryInfoRxMessage(data).toString()); PersistentStore.setBytes(G5_BATTERY_MARKER + transmitterId, data); PersistentStore.setLong(G5_BATTERY_FROM_MARKER + transmitterId, JoH.tsl()); PersistentStore.setBoolean(G5_BATTERY_WEARABLE_SEND, true); return true; }
public static byte[] tolerantHexStringToByteArray(String str) { return hexStringToByteArray(str.toUpperCase().replaceAll("[^A-F0-9]","")); }
public static boolean setStoredFirmwareBytes(String transmitterId, byte[] data, boolean from_bluetooth) { if (from_bluetooth) UserError.Log.e(TAG, "Store: VersionRX dbg: " + JoH.bytesToHex(data)); if (transmitterId.length() != 6) return false; if (data.length < 10) return false; if (JoH.ratelimit("store-firmware-bytes", 60)) { PersistentStore.setBytes("g5-firmware-" + transmitterId, data); } return true; }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { final String insert = isChecked ? xdrip.getAppContext().getString(R.string.sound_once) : xdrip.getAppContext().getString(R.string.alert_until_dismissed); final String second_insert = repeatingCheckbox.isChecked() ? xdrip.getAppContext().getString(R.string.and_then_repeat) + " " + JoH.niceTimeScalar(getPeriod(rbday, rbhour, rbweek)) : xdrip.getAppContext().getString(R.string.will_not_repeat); JoH.static_toast_long(xdrip.getAppContext().getString(R.string.reminder_will) + " " + insert + " " + second_insert); } });