Search in sources :

Example 1 with Insulin

use of com.eveningoutpost.dexdrip.insulin.Insulin 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());
    }
}
Also used : InsulinInjection(com.eveningoutpost.dexdrip.Models.InsulinInjection) GsonBuilder(com.google.gson.GsonBuilder) ViewGroup(android.view.ViewGroup) DecimalFormat(java.text.DecimalFormat) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Insulin(com.eveningoutpost.dexdrip.insulin.Insulin) Date(java.util.Date) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat)

Example 2 with Insulin

use of com.eveningoutpost.dexdrip.insulin.Insulin in project xDrip by NightscoutFoundation.

the class Treatments method convertLegacyDoseToInjectionListByName.

// take a simple insulin value and produce a list by name of insulin - for general quick conversion
public static List<InsulinInjection> convertLegacyDoseToInjectionListByName(final String insulinName, final double insulinSum) {
    Log.d(TAG, "convertingLegacyDoseByName: " + insulinName + " " + insulinSum);
    final Insulin insulin = InsulinManager.getProfile(insulinName);
    // TODO should we actually throw an exception here as this should never happen and the result would be invalid
    if (insulin == null)
        return null;
    final ArrayList<InsulinInjection> injections = new ArrayList<>();
    injections.add(new InsulinInjection(insulin, insulinSum));
    return injections;
}
Also used : ArrayList(java.util.ArrayList) Insulin(com.eveningoutpost.dexdrip.insulin.Insulin)

Example 3 with Insulin

use of com.eveningoutpost.dexdrip.insulin.Insulin 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());
    }
}
Also used : InsulinInjection(com.eveningoutpost.dexdrip.Models.InsulinInjection) GsonBuilder(com.google.gson.GsonBuilder) ViewGroup(android.view.ViewGroup) DecimalFormat(java.text.DecimalFormat) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Insulin(com.eveningoutpost.dexdrip.insulin.Insulin) Date(java.util.Date) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat)

Example 4 with Insulin

use of com.eveningoutpost.dexdrip.insulin.Insulin in project xDrip-plus by jamorham.

the class Treatments method convertLegacyDoseToInjectionListByName.

// take a simple insulin value and produce a list by name of insulin - for general quick conversion
public static List<InsulinInjection> convertLegacyDoseToInjectionListByName(final String insulinName, final double insulinSum) {
    Log.d(TAG, "convertingLegacyDoseByName: " + insulinName + " " + insulinSum);
    final Insulin insulin = InsulinManager.getProfile(insulinName);
    // TODO should we actually throw an exception here as this should never happen and the result would be invalid
    if (insulin == null)
        return null;
    final ArrayList<InsulinInjection> injections = new ArrayList<>();
    injections.add(new InsulinInjection(insulin, insulinSum));
    return injections;
}
Also used : ArrayList(java.util.ArrayList) Insulin(com.eveningoutpost.dexdrip.insulin.Insulin)

Aggregations

Insulin (com.eveningoutpost.dexdrip.insulin.Insulin)4 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 ViewGroup (android.view.ViewGroup)2 InsulinInjection (com.eveningoutpost.dexdrip.Models.InsulinInjection)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 DecimalFormat (java.text.DecimalFormat)2 NumberFormat (java.text.NumberFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2