consolidate DecimalFormatters

This commit is contained in:
Milos Kozak 2016-07-11 18:07:54 +02:00
parent f7715a3409
commit 4dff8bc6af
14 changed files with 79 additions and 109 deletions

View file

@ -2,24 +2,20 @@ package info.nightscout.androidaps.db;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.DataPointInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.client.data.NSCal;
import info.nightscout.client.data.NSSgv;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = "BgReadings")
public class BgReading implements DataPointInterface {
private static Logger log = LoggerFactory.getLogger(BgReading.class);
public static final DecimalFormat mmolFormat = new DecimalFormat("0.0");
public static final DecimalFormat mgdlFormat = new DecimalFormat("0");
public long getTimeIndex() {
return timeIndex;
@ -62,8 +58,8 @@ public class BgReading implements DataPointInterface {
}
public String valueToUnitsToString(String units) {
if (units.equals(Constants.MGDL)) return mgdlFormat.format(value);
else return mmolFormat.format(value * Constants.MGDL_TO_MMOLL);
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(value);
else return DecimalFormatter.to0Decimal(value * Constants.MGDL_TO_MMOLL);
}
@Override

View file

@ -1,11 +1,5 @@
package info.nightscout.androidaps.db;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import android.content.Context;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
@ -26,7 +20,11 @@ import com.j256.ormlite.table.TableUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;

View file

@ -7,17 +7,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = "TempBasals")
public class TempBasal {
@ -187,10 +184,9 @@ public class TempBasal {
public String toString() {
DateFormat formatDateToJustTime = new SimpleDateFormat("HH:mm");
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
if (isAbsolute) {
return formatNumber2decimalplaces.format(absolute) + "U/h @" +
return DecimalFormatter.to2Decimal(absolute) + "U/h @" +
formatDateToJustTime.format(timeStart) +
" " + getRealDuration() + "/" + duration + "min";
} else { // percent

View file

@ -24,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.Date;
import info.nightscout.androidaps.Config;
@ -46,6 +45,7 @@ import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatu
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
import info.nightscout.utils.SetWarnColor;
@ -709,9 +709,6 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
}
private void updateGUI() {
final DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
final DecimalFormat formatNumber1decimalplaces = new DecimalFormat("0.0");
final DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
final DateFormat formatTime = DateFormat.getTimeInstance(DateFormat.SHORT);
Activity activity = getActivity();
@ -730,13 +727,13 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
Long agoMsec = new Date().getTime() - getDanaRPump().lastBolusTime.getTime();
int agoHours = (int) (agoMsec / 60d / 60d / 1000d);
if (agoHours < 6) // max 6h back
lastBolusView.setText(formatTime.format(getDanaRPump().lastBolusTime) + " (" + formatNumber1decimalplaces.format(agoHours) + " " + getString(R.string.hoursago) + ") " + formatNumber2decimalplaces.format(getDanaRPump().lastBolusAmount) + " U");
lastBolusView.setText(formatTime.format(getDanaRPump().lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + " U");
else lastBolusView.setText("");
}
dailyUnitsView.setText(formatNumber0decimalplaces.format(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U");
dailyUnitsView.setText(DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, getDanaRPump().dailyTotalUnits, getDanaRPump().maxDailyTotalUnits * 0.75d, getDanaRPump().maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (getDanaRPump().activeProfile + 1) + " ) " + formatNumber2decimalplaces.format(getBaseBasalRate()) + " U/h");
basaBasalRateView.setText("( " + (getDanaRPump().activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getBaseBasalRate()) + " U/h");
if (isRealTempBasalInProgress()) {
tempBasalView.setText(getRealTempBasal().toString());
} else {
@ -747,7 +744,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
} else {
extendedBolusView.setText("");
}
reservoirView.setText(formatNumber0decimalplaces.format(getDanaRPump().reservoirRemainingUnits) + " / 300 U");
reservoirView.setText(DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + " / 300 U");
SetWarnColor.setColorInverse(reservoirView, getDanaRPump().reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (getDanaRPump().batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(reservoirView, getDanaRPump().batteryRemaining, 51d, 26d);

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.DanaR.Dialogs;
import android.support.v4.app.DialogFragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,13 +13,13 @@ import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.Date;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
/**
* Created by mike on 10.07.2016.
@ -38,8 +38,6 @@ public class ProfileViewDialog extends DialogFragment {
private static Button refreshButton;
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
Handler mHandler;
static HandlerThread mHandlerThread;
@ -96,7 +94,7 @@ public class ProfileViewDialog extends DialogFragment {
noProfile.setVisibility(View.GONE);
}
units.setText(profile.getUnits());
dia.setText(formatNumber2decimalplaces.format(profile.getDia()) + " h");
dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h");
activeProfile.setText(profile.getActiveProfile());
ic.setText(profile.getIcList());
isf.setText(profile.getIsfList());

View file

@ -5,15 +5,13 @@ import com.squareup.otto.Bus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
import info.nightscout.utils.DecimalFormatter;
public class MsgBolusProgress extends DanaRMessage {
private static Logger log = LoggerFactory.getLogger(MsgBolusProgress.class);
public static final DecimalFormat bolusNumberFormat = new DecimalFormat("0.0");
private static Bus bus = null;
private static Treatment t;
@ -38,7 +36,7 @@ public class MsgBolusProgress extends DanaRMessage {
Double done = (amount * 100 - progress) / 100d;
t.insulin = done;
EventDanaRBolusProgress bolusingEvent = EventDanaRBolusProgress.getInstance();
bolusingEvent.sStatus = "Delivering " + bolusNumberFormat.format(done) + "U";
bolusingEvent.sStatus = "Delivering " + DecimalFormatter.to1Decimal(done) + "U";
bolusingEvent.t = t;
if (Config.logDanaMessageDetail) {

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.Loop;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Html;
@ -9,8 +8,6 @@ import android.text.Spanned;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.utils.DecimalFormatter;

View file

@ -17,18 +17,17 @@ import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;

View file

@ -19,8 +19,6 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -29,6 +27,7 @@ import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
public class NSProfileViewerFragment extends Fragment implements PluginBase, ProfileInterface {
private static Logger log = LoggerFactory.getLogger(NSProfileViewerFragment.class);
@ -42,8 +41,6 @@ public class NSProfileViewerFragment extends Fragment implements PluginBase, Pro
private static TextView basal;
private static TextView target;
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
@ -126,7 +123,7 @@ public class NSProfileViewerFragment extends Fragment implements PluginBase, Pro
noProfile.setVisibility(View.GONE);
}
units.setText(profile.getUnits());
dia.setText(formatNumber2decimalplaces.format(profile.getDia()) + " h");
dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h");
activeProfile.setText(profile.getActiveProfile());
ic.setText(profile.getIcList());
isf.setText(profile.getIsfList());

View file

@ -8,8 +8,12 @@ import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.*;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -27,7 +31,11 @@ import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.*;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
// TODO: wizard upload top NS calculation
// TODO: add carbtime
@ -52,9 +60,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
PlusMinusEditText editCarbs;
PlusMinusEditText editCorr;
public static final DecimalFormat numberFormat = new DecimalFormat("0.00");
public static final DecimalFormat intFormat = new DecimalFormat("0");
Integer calculatedCarbs = 0;
Double calculatedTotalInsulin = 0d;
@ -222,8 +227,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
bgDiff = lastBgValue - targetBGHigh;
}
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + intFormat.format(sens));
bgInsulin.setText(numberFormat.format(bgDiff / sens) + "U");
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to0Decimal(sens));
bgInsulin.setText(DecimalFormatter.to2Decimal(bgDiff / sens) + "U");
bgInput.removeTextChangedListener(textWatcher);
//bgInput.setText(lastBg.valueToUnitsToString(units));
editBg.setValue(lastBg.valueToUnits(units));
@ -245,8 +250,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
bolusIobInsulin.setText("-" + numberFormat.format(bolusIob.iob) + "U");
basalIobInsulin.setText("-" + numberFormat.format(basalIob.basaliob) + "U");
bolusIobInsulin.setText("-" + DecimalFormatter.to2Decimal(bolusIob.iob) + "U");
basalIobInsulin.setText("-" + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U");
totalInsulin.setText("");
wizardDialogDeliverButton.setVisibility(Button.INVISIBLE);
@ -291,14 +296,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
bgDiff = c_bg - targetBGHigh;
}
Double insulinFromBG = (bgCheckbox.isChecked() && c_bg != 0d) ? bgDiff / sens : 0d;
bg.setText(c_bg + " ISF: " + intFormat.format(sens));
bgInsulin.setText(numberFormat.format(insulinFromBG) + "U");
bg.setText(c_bg + " ISF: " + DecimalFormatter.to0Decimal(sens));
bgInsulin.setText(DecimalFormatter.to2Decimal(insulinFromBG) + "U");
// Insuling from carbs
Double ic = profile.getIc(NSProfile.secondsFromMidnight());
Double insulinFromCarbs = c_carbs / ic;
carbs.setText(intFormat.format(c_carbs) + "g IC: " + intFormat.format(ic));
carbsInsulin.setText(numberFormat.format(insulinFromCarbs) + "U");
carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to0Decimal(ic));
carbsInsulin.setText(DecimalFormatter.to2Decimal(insulinFromCarbs) + "U");
// Insulin from IOB
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
@ -310,32 +315,32 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
Double insulingFromBolusIOB = bolusIobCheckbox.isChecked() ? -bolusIob.iob : 0d;
Double insulingFromBasalsIOB = basalIobCheckbox.isChecked() ? -basalIob.basaliob : 0d;
bolusIobInsulin.setText(numberFormat.format(insulingFromBolusIOB) + "U");
basalIobInsulin.setText(numberFormat.format(insulingFromBasalsIOB) + "U");
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(insulingFromBolusIOB) + "U");
basalIobInsulin.setText(DecimalFormatter.to2Decimal(insulingFromBasalsIOB) + "U");
// Insulin from correction
Double insulinFromCorrection = corrAfterConstraint;
correctionInsulin.setText(numberFormat.format(insulinFromCorrection) + "U");
correctionInsulin.setText(DecimalFormatter.to2Decimal(insulinFromCorrection) + "U");
// Total
calculatedTotalInsulin = insulinFromBG + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection;
if (calculatedTotalInsulin < 0) {
Double carbsEquivalent = -calculatedTotalInsulin * ic;
total.setText(getString(R.string.missing) + " " + intFormat.format(carbsEquivalent) + "g");
total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(carbsEquivalent) + "g");
calculatedTotalInsulin = 0d;
totalInsulin.setText("");
} else {
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, 0.05d);
total.setText("");
totalInsulin.setText(numberFormat.format(calculatedTotalInsulin) + "U");
totalInsulin.setText(DecimalFormatter.to2Decimal(calculatedTotalInsulin) + "U");
}
calculatedCarbs = c_carbs;
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
String insulinText = calculatedTotalInsulin > 0d ? (numberFormat.format(calculatedTotalInsulin) + "U") : "";
String carbsText = calculatedCarbs > 0d ? (intFormat.format(calculatedCarbs) + "g") : "";
String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.to2Decimal(calculatedTotalInsulin) + "U") : "";
String carbsText = calculatedCarbs > 0d ? (DecimalFormatter.to0Decimal(calculatedCarbs) + "g") : "";
wizardDialogDeliverButton.setText(getString(R.string.send) + " " + insulinText + " " + carbsText);
wizardDialogDeliverButton.setVisibility(Button.VISIBLE);
} else {

View file

@ -29,7 +29,6 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@ -61,6 +60,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
@ -389,7 +389,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
}
public void updateGUI() {
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
BgReading actualBG = MainApp.getDbHelper().actualBg();
BgReading lastBG = MainApp.getDbHelper().lastBg();
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
@ -437,7 +436,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
cancelTempLayout.setVisibility(View.GONE);
setTempLayout.setVisibility(View.VISIBLE);
Double currentBasal = pump.getBaseBasalRate();
runningTempView.setText(formatNumber2decimalplaces.format(currentBasal) + " U/h");
runningTempView.setText(DecimalFormatter.to2Decimal(currentBasal) + " U/h");
}
if (profile == null) {
@ -486,9 +485,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
if (basalIob == null) basalIob = new IobTotal();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
String iobtext = getString(R.string.treatments_iob_label_string) + " " + formatNumber2decimalplaces.format(iobTotal.iob) + "U ("
+ getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(bolusIob.iob) + "U "
+ getString(R.string.basal) + ": " + formatNumber2decimalplaces.format(basalIob.basaliob) + "U)";
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(iobTotal.iob) + "U ("
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
iobView.setText(iobtext);
// ****** GRAPH *******

View file

@ -6,7 +6,9 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.*;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -24,7 +26,6 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -37,9 +38,10 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.utils.DecimalFormatter;
public class TempBasalsFragment extends Fragment implements PluginBase, TempBasalsInterface {
@ -53,10 +55,6 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
public long lastCalculationTimestamp = 0;
public IobTotal lastCalculation;
private static DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
private static DecimalFormat formatNumber3decimalplaces = new DecimalFormat("0.000");
private List<TempBasal> tempBasals;
private List<TempBasal> extendedBoluses;
@ -269,19 +267,19 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
} else {
holder.date.setText(df.format(tempBasal.timeStart));
}
holder.duration.setText(formatNumber0decimalplaces.format(tempBasal.duration) + " min");
holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.duration) + " min");
if (tempBasal.isAbsolute) {
holder.absolute.setText(formatNumber0decimalplaces.format(tempBasal.absolute) + " U/h");
holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.absolute) + " U/h");
holder.percent.setText("");
} else {
holder.absolute.setText("");
holder.percent.setText(formatNumber0decimalplaces.format(tempBasal.percent) + "%");
holder.percent.setText(DecimalFormatter.to0Decimal(tempBasal.percent) + "%");
}
holder.realDuration.setText(formatNumber0decimalplaces.format(tempBasal.getRealDuration()) + " min");
holder.realDuration.setText(DecimalFormatter.to0Decimal(tempBasal.getRealDuration()) + " min");
IobTotal iob = tempBasal.iobCalc(new Date());
holder.iob.setText(formatNumber2decimalplaces.format(iob.basaliob) + " U");
holder.netInsulin.setText(formatNumber2decimalplaces.format(iob.netInsulin) + " U");
holder.netRatio.setText(formatNumber2decimalplaces.format(iob.netRatio) + " U/h");
holder.iob.setText(DecimalFormatter.to2Decimal(iob.basaliob) + " U");
holder.netInsulin.setText(DecimalFormatter.to2Decimal(iob.netInsulin) + " U");
holder.netRatio.setText(DecimalFormatter.to2Decimal(iob.netRatio) + " U/h");
holder.extendedFlag.setVisibility(tempBasal.isExtended ? View.VISIBLE : View.GONE);
if (tempBasal.isInProgress())
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress));
@ -417,7 +415,7 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(getMergedList()), false);
if (lastCalculation != null) {
String totalText = formatNumber2decimalplaces.format(lastCalculation.basaliob) + " U";
String totalText = DecimalFormatter.to2Decimal(lastCalculation.basaliob) + " U";
tempBasalTotalView.setText(totalText);
}
}

View file

@ -26,24 +26,21 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
public class TreatmentsFragment extends Fragment implements View.OnClickListener, PluginBase, TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
@ -58,10 +55,6 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
private long lastCalculationTimestamp = 0;
private IobTotal lastCalculation;
private static DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
private static DecimalFormat formatNumber3decimalplaces = new DecimalFormat("0.000");
private List<Treatment> treatments;
boolean fragmentEnabled = true;
@ -211,11 +204,11 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
return;
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
holder.date.setText(df.format(treatments.get(position).created_at));
holder.insulin.setText(formatNumber2decimalplaces.format(treatments.get(position).insulin) + " U");
holder.carbs.setText(formatNumber0decimalplaces.format(treatments.get(position).carbs) + " g");
holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U");
holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g");
Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia());
holder.iob.setText(formatNumber2decimalplaces.format(iob.iobContrib) + " U");
holder.activity.setText(formatNumber3decimalplaces.format(iob.activityContrib) + " U");
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
if (iob.iobContrib != 0)
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB));
else
@ -340,9 +333,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(treatments), false);
if (lastCalculation != null)
iobTotal.setText(formatNumber2decimalplaces.format(lastCalculation.iob) + " U");
iobTotal.setText(DecimalFormatter.to2Decimal(lastCalculation.iob) + " U");
if (lastCalculation != null)
activityTotal.setText(formatNumber3decimalplaces.format(lastCalculation.activity) + " U");
activityTotal.setText(DecimalFormatter.to3Decimal(lastCalculation.activity) + " U");
}
});
}

View file

@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.TimeZone;
import info.nightscout.androidaps.Constants;
import info.nightscout.utils.DecimalFormatter;
public class NSProfile {
private JSONObject json = null;
@ -333,9 +334,7 @@ public class NSProfile {
}
public static String toUnitsString(Double valueInMgdl, Double valueInMmol, String units) {
DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
DecimalFormat formatNumber1decimalplaces = new DecimalFormat("0.0");
if (units.equals(Constants.MGDL)) return formatNumber0decimalplaces.format(valueInMgdl);
else return formatNumber1decimalplaces.format(valueInMmol);
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(valueInMgdl);
else return DecimalFormatter.to1Decimal(valueInMmol);
}
}