use of com.eveningoutpost.dexdrip.Models.InsulinInjection in project xDrip-plus by jamorham.
the class Home method processAndApproveTreatment.
private void processAndApproveTreatment() {
// preserve globals before threading off
final double myglucosenumber = thisglucosenumber;
double mytimeoffset = thistimeoffset;
// TODO Handle BG Tests here also
if (watchkeypad) {
// calculate absolute offset
long treatment_timestamp = watchkeypad_timestamp - (long) mytimeoffset;
mytimeoffset = JoH.tsl() - treatment_timestamp;
Log.d(TAG, "Watch Keypad timestamp is: " + JoH.dateTimeText(treatment_timestamp) + " Original offset: " + JoH.qs(thistimeoffset) + " New: " + JoH.qs(mytimeoffset));
if ((mytimeoffset > (DAY_IN_MS * 3)) || (mytimeoffset < -HOUR_IN_MS * 3)) {
Log.e(TAG, "Treatment timestamp out of range: " + mytimeoffset);
JoH.static_toast_long(gs(R.string.treatment_time_wrong));
WatchUpdaterService.sendWearLocalToast(gs(R.string.treatment_error), Toast.LENGTH_LONG);
} else {
JoH.static_toast_long(gs(R.string.treatment_processed));
WatchUpdaterService.sendWearLocalToast(gs(R.string.treatment_processed), Toast.LENGTH_LONG);
long time = Treatments.getTimeStampWithOffset(mytimeoffset);
// sanity check timestamp
final Treatments exists = Treatments.byTimestamp(time);
if (exists == null) {
ArrayList<InsulinInjection> injections = new ArrayList<InsulinInjection>();
for (int i = 0; i < maxInsulinProfiles; i++) if (insulinset[i] && thisinsulinprofile[i] != null) {
InsulinInjection injection = new InsulinInjection(thisinsulinprofile[i], thisinsulinnumber[i]);
injections.add(injection);
}
Log.d(TAG, "processAndApproveTreatment create watchkeypad Treatment carbs=" + thiscarbsnumber + " insulin=" + thisInsulinSumNumber + " timestamp=" + JoH.dateTimeText(time) + " uuid=" + thisuuid);
Treatments.create(thiscarbsnumber, thisInsulinSumNumber, injections, time, thisuuid);
// gruoner: changed pendiq handling 09/12/19 TODO remove duplicate code with helper function
// in case of multiple injections in a treatment, select the injection with the primary insulin profile defined in the profile editor; if not found, take 0
// in case of a single injection in a treatment, assume thats the #units to send to pendiq
double pendiqInsulin = 0;
if (MultipleInsulins.isEnabled() && injections.size() > 1) {
for (InsulinInjection i : injections) if (i.getProfile() == InsulinManager.getBolusProfile())
pendiqInsulin = i.getUnits();
} else
pendiqInsulin = thisInsulinSumNumber;
Pendiq.handleTreatment(pendiqInsulin);
} else {
Log.d(TAG, "processAndApproveTreatment Treatment already exists carbs=" + thiscarbsnumber + " insulin=" + thisInsulinSumNumber + " timestamp=" + JoH.dateTimeText(time));
}
}
} else {
WatchUpdaterService.sendWearToast(gs(R.string.treatment_processed), Toast.LENGTH_LONG);
ArrayList<InsulinInjection> injections = new ArrayList<InsulinInjection>();
for (int i = 0; i < maxInsulinProfiles; i++) if (insulinset[i] && thisinsulinprofile[i] != null) {
InsulinInjection injection = new InsulinInjection(thisinsulinprofile[i], thisinsulinnumber[i]);
injections.add(injection);
}
Treatments.create(thiscarbsnumber, thisInsulinSumNumber, injections, Treatments.getTimeStampWithOffset(mytimeoffset));
// gruoner: changed pendiq handling 09/12/19 TODO remove duplicate code with helper function
// in case of multiple injections in a treatment, select the injection with the primary insulin profile defined in the profile editor; if not found, take 0
// in case of a single injection in a treatment, assume thats the #units to send to pendiq
double pendiqInsulin = 0;
if (MultipleInsulins.isEnabled() && injections.size() > 1) {
for (InsulinInjection i : injections) if (i.getProfile() == InsulinManager.getBolusProfile())
pendiqInsulin = i.getUnits();
} else
pendiqInsulin = thisInsulinSumNumber;
Pendiq.handleTreatment(pendiqInsulin);
}
hideAllTreatmentButtons();
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("approve button");
}
if (watchkeypad) {
if (myglucosenumber > 0) {
if ((mytimeoffset > (DAY_IN_MS * 3)) || (mytimeoffset < -HOUR_IN_MS * 3)) {
Log.e(TAG, "Treatment bloodtest timestamp out of range: " + mytimeoffset);
} else {
BloodTest.createFromCal(myglucosenumber, mytimeoffset, "Manual Entry", thisuuid);
}
}
watchkeypad = false;
watchkeypadset = false;
watchkeypad_timestamp = -1;
} else
processCalibrationNoUI(myglucosenumber, mytimeoffset);
staticRefreshBGCharts();
}
use of com.eveningoutpost.dexdrip.Models.InsulinInjection in project xDrip-plus by jamorham.
the class Home method onCreate.
@SuppressLint("ObsoleteSdkInt")
@Override
protected void onCreate(Bundle savedInstanceState) {
mActivity = this;
if (!xdrip.checkAppContext(getApplicationContext())) {
toast(gs(R.string.unusual_internal_context_problem__please_report));
Log.wtf(TAG, "xdrip.checkAppContext FAILED!");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// not much to do
}
if (!xdrip.checkAppContext(getApplicationContext())) {
toast(gs(R.string.cannot_start__please_report_context_problem));
finish();
}
}
if (Build.VERSION.SDK_INT < 17) {
JoH.static_toast_long(gs(R.string.xdrip_will_not_work_below_android_version_42));
finish();
}
xdrip.checkForcedEnglish(Home.this);
super.onCreate(savedInstanceState);
// for toolbar mode
setTheme(R.style.AppThemeToolBarLite);
Injectors.getHomeShelfComponent().inject(this);
if (!Experience.gotData()) {
homeShelf.set("source_wizard", true);
homeShelf.set("source_wizard_auto", true);
}
nanoStatus = new NanoStatus("collector", 1000);
expiryStatus = new NanoStatus("sensor-expiry", 15000);
set_is_follower();
setVolumeControlStream(AudioManager.STREAM_MUSIC);
checkedeula = checkEula();
binding = ActivityHomeBinding.inflate(getLayoutInflater());
binding.setVs(homeShelf);
binding.setHome(this);
binding.setUi(ui);
binding.setNano(nanoStatus);
binding.setExpiry(expiryStatus);
setContentView(binding.getRoot());
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(mToolbar);
final Home home = this;
mToolbar.setLongClickable(true);
mToolbar.setOnLongClickListener(v -> {
// show configurator
final ActivityHomeShelfSettingsBinding binding = ActivityHomeShelfSettingsBinding.inflate(getLayoutInflater());
final Dialog dialog = new Dialog(v.getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
binding.setVs(homeShelf);
binding.setHome(home);
homeShelf.set("arrow_configurator", false);
dialog.setContentView(binding.getRoot());
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
return false;
});
// findViewById(R.id.home_layout_holder).setBackgroundColor(getCol(X.color_home_chart_background));
this.dexbridgeBattery = (TextView) findViewById(R.id.textBridgeBattery);
this.parakeetBattery = (TextView) findViewById(R.id.parakeetbattery);
this.sensorAge = (TextView) findViewById(R.id.libstatus);
this.extraStatusLineText = (TextView) findViewById(R.id.extraStatusLine);
this.currentBgValueText = (TextView) findViewById(R.id.currentBgValueRealTime);
this.bpmButton = (Button) findViewById(R.id.bpmButton);
this.stepsButton = (Button) findViewById(R.id.walkButton);
extraStatusLineText.setText("");
dexbridgeBattery.setText("");
parakeetBattery.setText("");
sensorAge.setText("");
if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
this.currentBgValueText.setTextSize(100);
}
this.notificationText = (TextView) findViewById(R.id.notices);
if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
this.notificationText.setTextSize(40);
}
is_newbie = Experience.isNewbie();
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) && checkedeula) {
if (Experience.installedForAtLeast(5 * Constants.MINUTE_IN_MS)) {
checkBatteryOptimization();
}
}
// jamorham voice input et al
this.voiceRecognitionText = (TextView) findViewById(R.id.treatmentTextView);
this.textBloodGlucose = (TextView) findViewById(R.id.textBloodGlucose);
this.textCarbohydrates = (TextView) findViewById(R.id.textCarbohydrate);
this.textInsulinSumDose = (TextView) findViewById(R.id.textInsulinSumUnits);
this.textTime = (TextView) findViewById(R.id.textTimeButton);
this.btnBloodGlucose = (ImageButton) findViewById(R.id.bloodTestButton);
this.btnCarbohydrates = (ImageButton) findViewById(R.id.buttonCarbs);
this.textInsulinDose[0] = (TextView) findViewById(R.id.textInsulin1Units);
this.buttonInsulinSingleDose = (ImageButton) findViewById(R.id.buttonInsulin0);
this.btnInsulinDose[0] = (ImageButton) findViewById(R.id.buttonInsulin1);
this.textInsulinDose[1] = (TextView) findViewById(R.id.textInsulin2Units);
this.btnInsulinDose[1] = (ImageButton) findViewById(R.id.buttonInsulin2);
this.textInsulinDose[2] = (TextView) findViewById(R.id.textInsulin3Units);
this.btnInsulinDose[2] = (ImageButton) findViewById(R.id.buttonInsulin3);
this.btnCancel = (ImageButton) findViewById(R.id.cancelTreatment);
this.btnApprove = (ImageButton) findViewById(R.id.approveTreatment);
this.btnTime = (ImageButton) findViewById(R.id.timeButton);
this.btnUndo = (ImageButton) findViewById(R.id.btnUndo);
this.btnRedo = (ImageButton) findViewById(R.id.btnRedo);
this.btnVehicleMode = (ImageButton) findViewById(R.id.vehicleModeButton);
hideAllTreatmentButtons();
if (searchWords == null) {
initializeSearchWords("");
}
if (// TODO only when using multiples?
insulins == null)
insulins = InsulinManager.getDefaultInstance();
this.btnSpeak = (ImageButton) findViewById(R.id.btnTreatment);
btnSpeak.setOnClickListener(v -> promptTextInput());
btnSpeak.setOnLongClickListener(v -> {
promptSpeechInput();
return true;
});
this.btnNote = (ImageButton) findViewById(R.id.btnNote);
btnNote.setOnLongClickListener(v -> {
if (Pref.getBooleanDefaultFalse("default_to_voice_notes")) {
showNoteTextInputDialog(v, 0);
} else {
promptSpeechNoteInput(v);
}
return false;
});
btnNote.setOnClickListener(v -> {
if (!Pref.getBooleanDefaultFalse("default_to_voice_notes")) {
showNoteTextInputDialog(v, 0);
} else {
promptSpeechNoteInput(v);
}
});
btnCancel.setOnClickListener(v -> cancelTreatment());
// handle single insulin button (non multiples)
buttonInsulinSingleDose.setOnClickListener(v -> {
// proccess and approve treatment
textInsulinSumDose.setVisibility(View.INVISIBLE);
buttonInsulinSingleDose.setVisibility(View.INVISIBLE);
Treatments.create(0, thisInsulinSumNumber, Treatments.getTimeStampWithOffset(thistimeoffset));
Pendiq.handleTreatment(thisInsulinSumNumber);
thisInsulinSumNumber = 0;
reset_viewport = true;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("insulin button");
}
});
for (int i = 0; i < maxInsulinProfiles; i++) {
int finalI = i;
btnInsulinDose[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// proccess and approve treatment
textInsulinDose[finalI].setVisibility(View.INVISIBLE);
btnInsulinDose[finalI].setVisibility(View.INVISIBLE);
// create individual treatment just for this entry
Treatments.create(0, thisinsulinnumber[finalI], Treatments.convertLegacyDoseToInjectionListByName(thisinsulinprofile[finalI].getName(), thisinsulinnumber[finalI]), Treatments.getTimeStampWithOffset(thistimeoffset));
thisinsulinnumber[finalI] = 0;
insulinset[finalI] = false;
textInsulinDose[finalI].setText("");
reset_viewport = true;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("insulin button");
}
}
});
}
btnApprove.setOnClickListener(v -> processAndApproveTreatment());
btnCarbohydrates.setOnClickListener(v -> {
// proccess and approve treatment
textCarbohydrates.setVisibility(View.INVISIBLE);
btnCarbohydrates.setVisibility(View.INVISIBLE);
reset_viewport = true;
Treatments.create(thiscarbsnumber, 0, new ArrayList<InsulinInjection>(), Treatments.getTimeStampWithOffset(thistimeoffset));
thiscarbsnumber = 0;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("carbs button");
}
});
btnBloodGlucose.setOnClickListener(v -> {
reset_viewport = true;
processCalibration();
});
btnTime.setOnClickListener(v -> {
// clears time if clicked
textTime.setVisibility(View.INVISIBLE);
btnTime.setVisibility(View.INVISIBLE);
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("time button");
}
});
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screen_width = dm.widthPixels;
int screen_height = dm.heightPixels;
if (screen_width <= 320) {
small_width = true;
small_screen = true;
}
if (screen_height <= 320) {
small_height = true;
small_screen = true;
}
// final int refdpi = 320;
Log.d(TAG, "Width height: " + screen_width + " " + screen_height + " DPI:" + dm.densityDpi);
JoH.fixActionBar(this);
try {
getSupportActionBar().setTitle(R.string.app_name);
} catch (NullPointerException e) {
Log.e(TAG, "Couldn't set title due to null pointer");
}
activityVisible = true;
statusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String bwp = intent.getStringExtra("bwp");
if (bwp != null) {
statusBWP = bwp;
refreshStatusLine();
} else {
final String iob = intent.getStringExtra("iob");
if (iob != null) {
statusIOB = iob;
refreshStatusLine();
}
}
}
};
// handle incoming extras
final Bundle bundle = getIntent().getExtras();
processIncomingBundle(bundle);
checkBadSettings();
// lower priority
PlusSyncService.startSyncService(getApplicationContext(), "HomeOnCreate");
ParakeetHelper.notifyOnNextCheckin(false);
if (checkedeula && (!getString(R.string.app_name).equals("xDrip+"))) {
showcasemenu(SHOWCASE_VARIANT);
}
// clear any design prototyping default
currentBgValueText.setText("");
}
use of com.eveningoutpost.dexdrip.Models.InsulinInjection in project xDrip-plus by jamorham.
the class Home method handleWordPair.
private void handleWordPair() {
boolean preserve = false;
if ((thisnumber == -1) || (thisword.equals("")))
return;
Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword);
switch(thisword) {
case "watchkeypad":
if (!watchkeypadset && (thisnumber > 1501968469)) {
watchkeypad = true;
watchkeypadset = true;
watchkeypad_timestamp = (long) (thisnumber * 1000);
Log.d(TAG, "Treatment entered on watchkeypad: " + thisnumber);
} else {
Log.d(TAG, "watchkeypad already set");
}
break;
case "rapid":
if (!insulinsumset && (thisnumber > 0)) {
thisInsulinSumNumber = thisnumber;
textInsulinSumDose.setText(Double.toString(thisnumber) + " units");
Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber));
textInsulinSumDose.setVisibility(View.VISIBLE);
if (!MultipleInsulins.isEnabled()) {
// show the button next to the single insulin dose if not using multiples
buttonInsulinSingleDose.setVisibility(View.VISIBLE);
}
insulinsumset = true;
} else {
Log.d(TAG, "Rapid dose already set");
preserve = true;
}
break;
case "carbs":
if (!carbsset && (thisnumber > 0)) {
thiscarbsnumber = thisnumber;
textCarbohydrates.setText((int) thisnumber + " g carbs");
carbsset = true;
Log.d(TAG, "Carbs eaten: " + thisnumber);
btnCarbohydrates.setVisibility(View.VISIBLE);
textCarbohydrates.setVisibility(View.VISIBLE);
} else {
Log.d(TAG, "Carbs already set");
preserve = true;
}
break;
case "blood":
if (!glucoseset && (thisnumber > 0)) {
thisglucosenumber = thisnumber;
if (Pref.getString("units", "mgdl").equals("mgdl")) {
if (textBloodGlucose != null)
textBloodGlucose.setText(thisnumber + " mg/dl");
} else {
if (textBloodGlucose != null)
textBloodGlucose.setText(thisnumber + " mmol/l");
}
Log.d(TAG, "Blood test: " + thisnumber);
glucoseset = true;
if (textBloodGlucose != null) {
btnBloodGlucose.setVisibility(View.VISIBLE);
textBloodGlucose.setVisibility(View.VISIBLE);
}
} else {
Log.d(TAG, "Blood glucose already set");
preserve = true;
}
break;
case "time":
Log.d(TAG, "processing time keyword");
if (!timeset && (thisnumber >= 0)) {
final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
final DecimalFormat df = (DecimalFormat) nf;
// DecimalFormat df = new DecimalFormat("#");
df.setMinimumIntegerDigits(2);
df.setMinimumFractionDigits(2);
df.setMaximumFractionDigits(2);
df.setMaximumIntegerDigits(2);
final Calendar c = Calendar.getInstance();
final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US);
final SimpleDateFormat simpleDateFormat2 = // TODO double check 24 hour 12.00 etc
new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US);
final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber);
Log.d(TAG, "Time Timing data datenew: " + datenew);
final Date datethen;
final Date datenow = new Date();
try {
datethen = simpleDateFormat2.parse(datenew);
double difference = datenow.getTime() - datethen.getTime();
// is it more than 1 hour in the future? If so it must be yesterday
if (difference < -(1000 * 60 * 60)) {
difference = difference + (86400 * 1000);
} else {
// - midnight feast pre-bolus nom nom
if (difference > (60 * 60 * 23 * 1000))
difference = difference - (86400 * 1000);
}
Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: " + JoH.qs(difference));
textTime.setText(df.format(thisnumber));
timeset = true;
thistimeoffset = difference;
btnTime.setVisibility(View.VISIBLE);
textTime.setVisibility(View.VISIBLE);
} catch (ParseException e) {
// toast to explain?
Log.d(TAG, "Got exception parsing date time");
}
} else {
Log.d(TAG, "Time data already set");
preserve = true;
}
break;
default:
if (MultipleInsulins.isEnabled()) {
final Insulin insulin = InsulinManager.getProfile(thisword);
if (insulin != null) {
UserError.Log.d("TREATMENTS", "Processing for: " + insulin.getName());
int number = 0;
for (number = 0; number < maxInsulinProfiles; number++) if ((thisinsulinprofile[number] == null) || (thisinsulinprofile[number] == insulin)) {
thisinsulinprofile[number] = insulin;
break;
}
if (!insulinset[number] && (thisnumber > 0)) {
thisinsulinnumber[number] = thisnumber;
textInsulinDose[number].setText(Double.toString(thisnumber) + " " + insulin.getName());
Log.d(TAG, insulin.getName() + " dose: " + Double.toString(thisnumber));
insulinset[number] = true;
btnInsulinDose[number].setVisibility(View.VISIBLE);
textInsulinDose[number].setVisibility(View.VISIBLE);
} else {
Log.d(TAG, insulin.getName() + " dose already set");
preserve = true;
}
}
}
break;
}
if (preserve == false) {
Log.d(TAG, "Clearing speech values");
thisnumber = -1;
thisword = "";
} else {
Log.d(TAG, "Preserving speech values");
}
// don't show approve if we only have time
if ((insulinsumset || glucoseset || carbsset) && !watchkeypad) {
btnApprove.setVisibility(View.VISIBLE);
if (small_screen) {
final float button_scale_factor = 0.60f;
final int small_text_size = 12;
((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0;
((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0;
((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0);
((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0);
((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0;
((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0;
btnApprove.setScaleX(button_scale_factor);
btnApprove.setScaleY(button_scale_factor);
btnCancel.setScaleX(button_scale_factor);
btnCancel.setScaleY(button_scale_factor);
for (int i = 0; i < maxInsulinProfiles; i++) {
btnInsulinDose[i].setScaleY(button_scale_factor);
btnInsulinDose[i].setScaleX(button_scale_factor);
textInsulinDose[i].setTextSize(small_text_size);
}
btnCarbohydrates.setScaleX(button_scale_factor);
btnCarbohydrates.setScaleY(button_scale_factor);
btnBloodGlucose.setScaleX(button_scale_factor);
btnBloodGlucose.setScaleY(button_scale_factor);
btnTime.setScaleX(button_scale_factor);
btnTime.setScaleY(button_scale_factor);
textCarbohydrates.setTextSize(small_text_size);
textInsulinSumDose.setTextSize(small_text_size);
textBloodGlucose.setTextSize(small_text_size);
textTime.setTextSize(small_text_size);
}
}
if ((insulinsumset || glucoseset || carbsset || timeset) && !watchkeypad) {
btnCancel.setVisibility(View.VISIBLE);
if (chart != null) {
chart.setAlpha((float) 0.10);
}
ArrayList<InsulinInjection> injections = new ArrayList<InsulinInjection>();
for (int i = 0; i < maxInsulinProfiles; i++) if (insulinset[i] && thisinsulinprofile[i] != null) {
InsulinInjection injection = new InsulinInjection(thisinsulinprofile[i], thisinsulinnumber[i]);
injections.add(injection);
}
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
WatchUpdaterService.sendTreatment(thiscarbsnumber, thisInsulinSumNumber, thisglucosenumber, gson.toJson(injections), thistimeoffset, textTime.getText().toString());
}
}
use of com.eveningoutpost.dexdrip.Models.InsulinInjection in project xDrip by NightscoutFoundation.
the class Home method handleWordPair.
private void handleWordPair() {
boolean preserve = false;
if ((thisnumber == -1) || (thisword.equals("")))
return;
Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword);
switch(thisword) {
case "watchkeypad":
if (!watchkeypadset && (thisnumber > 1501968469)) {
watchkeypad = true;
watchkeypadset = true;
watchkeypad_timestamp = (long) (thisnumber * 1000);
Log.d(TAG, "Treatment entered on watchkeypad: " + thisnumber);
} else {
Log.d(TAG, "watchkeypad already set");
}
break;
case "rapid":
if (!insulinsumset && (thisnumber > 0)) {
thisInsulinSumNumber = thisnumber;
textInsulinSumDose.setText(Double.toString(thisnumber) + " units");
Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber));
textInsulinSumDose.setVisibility(View.VISIBLE);
if (!MultipleInsulins.isEnabled()) {
// show the button next to the single insulin dose if not using multiples
buttonInsulinSingleDose.setVisibility(View.VISIBLE);
}
insulinsumset = true;
} else {
Log.d(TAG, "Rapid dose already set");
preserve = true;
}
break;
case "carbs":
if (!carbsset && (thisnumber > 0)) {
thiscarbsnumber = thisnumber;
textCarbohydrates.setText((int) thisnumber + " g carbs");
carbsset = true;
Log.d(TAG, "Carbs eaten: " + thisnumber);
btnCarbohydrates.setVisibility(View.VISIBLE);
textCarbohydrates.setVisibility(View.VISIBLE);
} else {
Log.d(TAG, "Carbs already set");
preserve = true;
}
break;
case "blood":
if (!glucoseset && (thisnumber > 0)) {
thisglucosenumber = thisnumber;
if (Pref.getString("units", "mgdl").equals("mgdl")) {
if (textBloodGlucose != null)
textBloodGlucose.setText(thisnumber + " mg/dl");
} else {
if (textBloodGlucose != null)
textBloodGlucose.setText(thisnumber + " mmol/l");
}
Log.d(TAG, "Blood test: " + thisnumber);
glucoseset = true;
if (textBloodGlucose != null) {
btnBloodGlucose.setVisibility(View.VISIBLE);
textBloodGlucose.setVisibility(View.VISIBLE);
}
} else {
Log.d(TAG, "Blood glucose already set");
preserve = true;
}
break;
case "time":
Log.d(TAG, "processing time keyword");
if (!timeset && (thisnumber >= 0)) {
final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
final DecimalFormat df = (DecimalFormat) nf;
// DecimalFormat df = new DecimalFormat("#");
df.setMinimumIntegerDigits(2);
df.setMinimumFractionDigits(2);
df.setMaximumFractionDigits(2);
df.setMaximumIntegerDigits(2);
final Calendar c = Calendar.getInstance();
final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US);
final SimpleDateFormat simpleDateFormat2 = // TODO double check 24 hour 12.00 etc
new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US);
final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber);
Log.d(TAG, "Time Timing data datenew: " + datenew);
final Date datethen;
final Date datenow = new Date();
try {
datethen = simpleDateFormat2.parse(datenew);
double difference = datenow.getTime() - datethen.getTime();
// is it more than 1 hour in the future? If so it must be yesterday
if (difference < -(1000 * 60 * 60)) {
difference = difference + (86400 * 1000);
} else {
// - midnight feast pre-bolus nom nom
if (difference > (60 * 60 * 23 * 1000))
difference = difference - (86400 * 1000);
}
Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: " + JoH.qs(difference));
textTime.setText(df.format(thisnumber));
timeset = true;
thistimeoffset = difference;
btnTime.setVisibility(View.VISIBLE);
textTime.setVisibility(View.VISIBLE);
} catch (ParseException e) {
// toast to explain?
Log.d(TAG, "Got exception parsing date time");
}
} else {
Log.d(TAG, "Time data already set");
preserve = true;
}
break;
default:
if (MultipleInsulins.isEnabled()) {
final Insulin insulin = InsulinManager.getProfile(thisword);
if (insulin != null) {
UserError.Log.d("TREATMENTS", "Processing for: " + insulin.getName());
int number = 0;
for (number = 0; number < maxInsulinProfiles; number++) if ((thisinsulinprofile[number] == null) || (thisinsulinprofile[number] == insulin)) {
thisinsulinprofile[number] = insulin;
break;
}
if (!insulinset[number] && (thisnumber > 0)) {
thisinsulinnumber[number] = thisnumber;
textInsulinDose[number].setText(Double.toString(thisnumber) + " " + insulin.getName());
Log.d(TAG, insulin.getName() + " dose: " + Double.toString(thisnumber));
insulinset[number] = true;
btnInsulinDose[number].setVisibility(View.VISIBLE);
textInsulinDose[number].setVisibility(View.VISIBLE);
} else {
Log.d(TAG, insulin.getName() + " dose already set");
preserve = true;
}
}
}
break;
}
if (preserve == false) {
Log.d(TAG, "Clearing speech values");
thisnumber = -1;
thisword = "";
} else {
Log.d(TAG, "Preserving speech values");
}
// don't show approve if we only have time
if ((insulinsumset || glucoseset || carbsset) && !watchkeypad) {
btnApprove.setVisibility(View.VISIBLE);
if (small_screen) {
final float button_scale_factor = 0.60f;
final int small_text_size = 12;
((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0;
((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0;
((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0);
((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0);
((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0;
((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0;
btnApprove.setScaleX(button_scale_factor);
btnApprove.setScaleY(button_scale_factor);
btnCancel.setScaleX(button_scale_factor);
btnCancel.setScaleY(button_scale_factor);
for (int i = 0; i < maxInsulinProfiles; i++) {
btnInsulinDose[i].setScaleY(button_scale_factor);
btnInsulinDose[i].setScaleX(button_scale_factor);
textInsulinDose[i].setTextSize(small_text_size);
}
btnCarbohydrates.setScaleX(button_scale_factor);
btnCarbohydrates.setScaleY(button_scale_factor);
btnBloodGlucose.setScaleX(button_scale_factor);
btnBloodGlucose.setScaleY(button_scale_factor);
btnTime.setScaleX(button_scale_factor);
btnTime.setScaleY(button_scale_factor);
textCarbohydrates.setTextSize(small_text_size);
textInsulinSumDose.setTextSize(small_text_size);
textBloodGlucose.setTextSize(small_text_size);
textTime.setTextSize(small_text_size);
}
}
if ((insulinsumset || glucoseset || carbsset || timeset) && !watchkeypad) {
btnCancel.setVisibility(View.VISIBLE);
if (chart != null) {
chart.setAlpha((float) 0.10);
}
ArrayList<InsulinInjection> injections = new ArrayList<InsulinInjection>();
for (int i = 0; i < maxInsulinProfiles; i++) if (insulinset[i] && thisinsulinprofile[i] != null) {
InsulinInjection injection = new InsulinInjection(thisinsulinprofile[i], thisinsulinnumber[i]);
injections.add(injection);
}
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
WatchUpdaterService.sendTreatment(thiscarbsnumber, thisInsulinSumNumber, thisglucosenumber, gson.toJson(injections), thistimeoffset, textTime.getText().toString());
}
}
use of com.eveningoutpost.dexdrip.Models.InsulinInjection in project xDrip by NightscoutFoundation.
the class Home method onCreate.
@SuppressLint("ObsoleteSdkInt")
@Override
protected void onCreate(Bundle savedInstanceState) {
mActivity = this;
if (!xdrip.checkAppContext(getApplicationContext())) {
toast(gs(R.string.unusual_internal_context_problem__please_report));
Log.wtf(TAG, "xdrip.checkAppContext FAILED!");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// not much to do
}
if (!xdrip.checkAppContext(getApplicationContext())) {
toast(gs(R.string.cannot_start__please_report_context_problem));
finish();
}
}
if (Build.VERSION.SDK_INT < 17) {
JoH.static_toast_long(gs(R.string.xdrip_will_not_work_below_android_version_42));
finish();
}
xdrip.checkForcedEnglish(Home.this);
super.onCreate(savedInstanceState);
// for toolbar mode
setTheme(R.style.AppThemeToolBarLite);
Injectors.getHomeShelfComponent().inject(this);
if (!Experience.gotData()) {
homeShelf.set("source_wizard", true);
homeShelf.set("source_wizard_auto", true);
}
nanoStatus = new NanoStatus("collector", 1000);
expiryStatus = new NanoStatus("sensor-expiry", 15000);
set_is_follower();
setVolumeControlStream(AudioManager.STREAM_MUSIC);
checkedeula = checkEula();
binding = ActivityHomeBinding.inflate(getLayoutInflater());
binding.setVs(homeShelf);
binding.setHome(this);
binding.setUi(ui);
binding.setNano(nanoStatus);
binding.setExpiry(expiryStatus);
setContentView(binding.getRoot());
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(mToolbar);
final Home home = this;
mToolbar.setLongClickable(true);
mToolbar.setOnLongClickListener(v -> {
// show configurator
final ActivityHomeShelfSettingsBinding binding = ActivityHomeShelfSettingsBinding.inflate(getLayoutInflater());
final Dialog dialog = new Dialog(v.getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
binding.setVs(homeShelf);
binding.setHome(home);
homeShelf.set("arrow_configurator", false);
dialog.setContentView(binding.getRoot());
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
return false;
});
// findViewById(R.id.home_layout_holder).setBackgroundColor(getCol(X.color_home_chart_background));
this.dexbridgeBattery = (TextView) findViewById(R.id.textBridgeBattery);
this.parakeetBattery = (TextView) findViewById(R.id.parakeetbattery);
this.sensorAge = (TextView) findViewById(R.id.libstatus);
this.extraStatusLineText = (TextView) findViewById(R.id.extraStatusLine);
this.currentBgValueText = (TextView) findViewById(R.id.currentBgValueRealTime);
this.bpmButton = (Button) findViewById(R.id.bpmButton);
this.stepsButton = (Button) findViewById(R.id.walkButton);
extraStatusLineText.setText("");
dexbridgeBattery.setText("");
parakeetBattery.setText("");
sensorAge.setText("");
if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
this.currentBgValueText.setTextSize(100);
}
this.notificationText = (TextView) findViewById(R.id.notices);
if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
this.notificationText.setTextSize(40);
}
is_newbie = Experience.isNewbie();
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) && checkedeula) {
if (Experience.installedForAtLeast(5 * Constants.MINUTE_IN_MS)) {
checkBatteryOptimization();
}
}
// jamorham voice input et al
this.voiceRecognitionText = (TextView) findViewById(R.id.treatmentTextView);
this.textBloodGlucose = (TextView) findViewById(R.id.textBloodGlucose);
this.textCarbohydrates = (TextView) findViewById(R.id.textCarbohydrate);
this.textInsulinSumDose = (TextView) findViewById(R.id.textInsulinSumUnits);
this.textTime = (TextView) findViewById(R.id.textTimeButton);
this.btnBloodGlucose = (ImageButton) findViewById(R.id.bloodTestButton);
this.btnCarbohydrates = (ImageButton) findViewById(R.id.buttonCarbs);
this.textInsulinDose[0] = (TextView) findViewById(R.id.textInsulin1Units);
this.buttonInsulinSingleDose = (ImageButton) findViewById(R.id.buttonInsulin0);
this.btnInsulinDose[0] = (ImageButton) findViewById(R.id.buttonInsulin1);
this.textInsulinDose[1] = (TextView) findViewById(R.id.textInsulin2Units);
this.btnInsulinDose[1] = (ImageButton) findViewById(R.id.buttonInsulin2);
this.textInsulinDose[2] = (TextView) findViewById(R.id.textInsulin3Units);
this.btnInsulinDose[2] = (ImageButton) findViewById(R.id.buttonInsulin3);
this.btnCancel = (ImageButton) findViewById(R.id.cancelTreatment);
this.btnApprove = (ImageButton) findViewById(R.id.approveTreatment);
this.btnTime = (ImageButton) findViewById(R.id.timeButton);
this.btnUndo = (ImageButton) findViewById(R.id.btnUndo);
this.btnRedo = (ImageButton) findViewById(R.id.btnRedo);
this.btnVehicleMode = (ImageButton) findViewById(R.id.vehicleModeButton);
hideAllTreatmentButtons();
if (searchWords == null) {
initializeSearchWords("");
}
if (// TODO only when using multiples?
insulins == null)
insulins = InsulinManager.getDefaultInstance();
this.btnSpeak = (ImageButton) findViewById(R.id.btnTreatment);
btnSpeak.setOnClickListener(v -> promptTextInput());
btnSpeak.setOnLongClickListener(v -> {
promptSpeechInput();
return true;
});
this.btnNote = (ImageButton) findViewById(R.id.btnNote);
btnNote.setOnLongClickListener(v -> {
if (Pref.getBooleanDefaultFalse("default_to_voice_notes")) {
showNoteTextInputDialog(v, 0);
} else {
promptSpeechNoteInput(v);
}
return false;
});
btnNote.setOnClickListener(v -> {
if (!Pref.getBooleanDefaultFalse("default_to_voice_notes")) {
showNoteTextInputDialog(v, 0);
} else {
promptSpeechNoteInput(v);
}
});
btnCancel.setOnClickListener(v -> cancelTreatment());
// handle single insulin button (non multiples)
buttonInsulinSingleDose.setOnClickListener(v -> {
// proccess and approve treatment
textInsulinSumDose.setVisibility(View.INVISIBLE);
buttonInsulinSingleDose.setVisibility(View.INVISIBLE);
Treatments.create(0, thisInsulinSumNumber, Treatments.getTimeStampWithOffset(thistimeoffset));
Pendiq.handleTreatment(thisInsulinSumNumber);
thisInsulinSumNumber = 0;
reset_viewport = true;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("insulin button");
}
});
for (int i = 0; i < maxInsulinProfiles; i++) {
int finalI = i;
btnInsulinDose[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// proccess and approve treatment
textInsulinDose[finalI].setVisibility(View.INVISIBLE);
btnInsulinDose[finalI].setVisibility(View.INVISIBLE);
// create individual treatment just for this entry
Treatments.create(0, thisinsulinnumber[finalI], Treatments.convertLegacyDoseToInjectionListByName(thisinsulinprofile[finalI].getName(), thisinsulinnumber[finalI]), Treatments.getTimeStampWithOffset(thistimeoffset));
thisinsulinnumber[finalI] = 0;
insulinset[finalI] = false;
textInsulinDose[finalI].setText("");
reset_viewport = true;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("insulin button");
}
}
});
}
btnApprove.setOnClickListener(v -> processAndApproveTreatment());
btnCarbohydrates.setOnClickListener(v -> {
// proccess and approve treatment
textCarbohydrates.setVisibility(View.INVISIBLE);
btnCarbohydrates.setVisibility(View.INVISIBLE);
reset_viewport = true;
Treatments.create(thiscarbsnumber, 0, new ArrayList<InsulinInjection>(), Treatments.getTimeStampWithOffset(thistimeoffset));
thiscarbsnumber = 0;
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("carbs button");
}
});
btnBloodGlucose.setOnClickListener(v -> {
reset_viewport = true;
processCalibration();
});
btnTime.setOnClickListener(v -> {
// clears time if clicked
textTime.setVisibility(View.INVISIBLE);
btnTime.setVisibility(View.INVISIBLE);
if (hideTreatmentButtonsIfAllDone()) {
updateCurrentBgInfo("time button");
}
});
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screen_width = dm.widthPixels;
int screen_height = dm.heightPixels;
if (screen_width <= 320) {
small_width = true;
small_screen = true;
}
if (screen_height <= 320) {
small_height = true;
small_screen = true;
}
// final int refdpi = 320;
Log.d(TAG, "Width height: " + screen_width + " " + screen_height + " DPI:" + dm.densityDpi);
JoH.fixActionBar(this);
try {
getSupportActionBar().setTitle(R.string.app_name);
} catch (NullPointerException e) {
Log.e(TAG, "Couldn't set title due to null pointer");
}
activityVisible = true;
statusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String bwp = intent.getStringExtra("bwp");
if (bwp != null) {
statusBWP = bwp;
refreshStatusLine();
} else {
final String iob = intent.getStringExtra("iob");
if (iob != null) {
statusIOB = iob;
refreshStatusLine();
}
}
}
};
// handle incoming extras
final Bundle bundle = getIntent().getExtras();
processIncomingBundle(bundle);
checkBadSettings();
// lower priority
PlusSyncService.startSyncService(getApplicationContext(), "HomeOnCreate");
ParakeetHelper.notifyOnNextCheckin(false);
if (checkedeula && (!getString(R.string.app_name).equals("xDrip+"))) {
showcasemenu(SHOWCASE_VARIANT);
}
// clear any design prototyping default
currentBgValueText.setText("");
}
Aggregations