From f3c15aca75035b5f13ed15f264808756ef54e008 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 28 Jun 2016 11:19:27 +0200 Subject: [PATCH] plus minus controls --- .idea/inspectionProfiles/Project_Default.xml | 1 + .idea/misc.xml | 2 +- .../info/nightscout/androidaps/Constants.java | 2 + .../Overview/Dialogs/NewTreatmentDialog.java | 17 +- .../Overview/Dialogs/WizardDialog.java | 26 ++- .../nightscout/utils/PlusMinusEditText.java | 180 ++++++++++++++++++ .../main/res/drawable-hdpi/ic_action_add.png | Bin 0 -> 139 bytes .../res/drawable-hdpi/ic_action_minus.png | Bin 0 -> 131 bytes .../main/res/drawable-mdpi/ic_action_add.png | Bin 0 -> 121 bytes .../res/drawable-mdpi/ic_action_minus.png | Bin 0 -> 112 bytes .../main/res/drawable-xhdpi/ic_action_add.png | Bin 0 -> 174 bytes .../res/drawable-xhdpi/ic_action_minus.png | Bin 0 -> 165 bytes .../res/drawable-xxhdpi/ic_action_add.png | Bin 0 -> 246 bytes .../res/drawable-xxhdpi/ic_action_minus.png | Bin 0 -> 217 bytes .../res/drawable-xxxhdpi/ic_action_add.png | Bin 0 -> 477 bytes .../res/drawable-xxxhdpi/ic_action_minus.png | Bin 0 -> 249 bytes .../layout/overview_newtreatment_fragment.xml | 139 ++++++++++---- .../res/layout/overview_wizard_fragment.xml | 63 +++++- 18 files changed, 379 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/info/nightscout/utils/PlusMinusEditText.java create mode 100644 app/src/main/res/drawable-hdpi/ic_action_add.png create mode 100644 app/src/main/res/drawable-hdpi/ic_action_minus.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_add.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_minus.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_add.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_minus.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_add.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_minus.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_action_add.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_action_minus.png diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index f7b3a44868..1943c85e5f 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981032..fbb68289f4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 247ce3caea..12d140c90e 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -14,6 +14,8 @@ public class Constants { public static final double basalAbsoluteOnlyForCheckLimit = 10101010d; public static final Integer basalPercentOnlyForCheckLimit = 10101010; + public static final double bolusOnlyForCheckLimit = 10101010d; + public static final Integer carbsOnlyForCheckLimit = 10101010; public static final Integer notificationID = 556677; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index f6cb977e43..9f4d40bee9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -9,10 +9,14 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; +import java.text.DecimalFormat; + +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { @@ -21,6 +25,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene TextView insulin; TextView carbs; + PlusMinusEditText editCarbs; + PlusMinusEditText editInsulin; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -30,10 +37,16 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene deliverButton.setOnClickListener(this); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); - getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); insulin = (TextView) view.findViewById(R.id.treatments_newtreatment_insulinamount); carbs = (TextView) view.findViewById(R.id.treatments_newtreatment_carbsamount); + Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit); + Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit); + + editCarbs = new PlusMinusEditText(view, R.id.treatments_newtreatment_carbsamount, R.id.treatments_newtreatment_carbsamount_plus, R.id.treatments_newtreatment_carbsamount_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0")); + editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00")); + return view; } @@ -53,7 +66,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (insulinAfterConstraints != insulin || carbsAfterConstraints != carbs) + if (insulinAfterConstraints - insulin != 0 || carbsAfterConstraints != carbs) confirmMessage += "\n" + getString(R.string.constraintapllied); final Double finalInsulinAfterConstraints = insulinAfterConstraints; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index b7595ae719..c687eede0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -15,6 +15,7 @@ import android.widget.TextView; import java.text.DecimalFormat; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; @@ -42,6 +43,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener { TextView correctionInsulin; TextView total, totalInsulin; + PlusMinusEditText editBg; + PlusMinusEditText editCarbs; + PlusMinusEditText editCorr; + public static final DecimalFormat numberFormat = new DecimalFormat("0.00"); public static final DecimalFormat intFormat = new DecimalFormat("0"); @@ -79,7 +84,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener { wizardDialogDeliverButton.setOnClickListener(this); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); - getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + correctionInput = (TextView) view.findViewById(R.id.treatments_wizard_correctioninput); carbsInput = (TextView) view.findViewById(R.id.treatments_wizard_carbsinput); bgInput = (TextView) view.findViewById(R.id.treatments_wizard_bginput); @@ -106,6 +112,12 @@ public class WizardDialog extends DialogFragment implements OnClickListener { basalIobCheckbox.setOnCheckedChangeListener(onCheckedChangeListener); bolusIobCheckbox.setOnCheckedChangeListener(onCheckedChangeListener); + Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit); + Double maxCorrection = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit); + + editBg = new PlusMinusEditText(view, R.id.treatments_wizard_bginput, R.id.treatments_wizard_bginput_plus, R.id.treatments_wizard_bginput_minus, 0d, 0d, 500d, 0.1d, new DecimalFormat("0.0")); + editCarbs = new PlusMinusEditText(view, R.id.treatments_wizard_carbsinput, R.id.treatments_wizard_carbsinput_plus, R.id.treatments_wizard_carbsinput_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0")); + editCorr = new PlusMinusEditText(view, R.id.treatments_wizard_correctioninput, R.id.treatments_wizard_correctioninput_plus, R.id.treatments_wizard_correctioninput_minus, 0d, 0d, maxCorrection, 0.05d, new DecimalFormat("0.00")); initDialog(); return view; } @@ -173,6 +185,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener { String units = profile.getUnits(); bgUnits.setText(units); + if (units.equals(Constants.MGDL)) editBg.setStep(1d); + else editBg.setStep(0.1d); // Set BG if not old BgReading lastBg = MainApp.getDbHelper().lastBg(); @@ -192,13 +206,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener { bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + intFormat.format(sens)); bgInsulin.setText(numberFormat.format(bgDiff / sens) + "U"); bgInput.removeTextChangedListener(textWatcher); - bgInput.setText(lastBg.valueToUnitsToString(units)); + //bgInput.setText(lastBg.valueToUnitsToString(units)); + editBg.setValue(lastBg.valueToUnits(units)); bgInput.addTextChangedListener(textWatcher); } else { bg.setText(""); bgInsulin.setText(""); bgInput.removeTextChangedListener(textWatcher); - bgInput.setText(""); + //bgInput.setText(""); + editBg.setValue(0d); bgInput.addTextChangedListener(textWatcher); } @@ -214,7 +230,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { basalIobInsulin.setText("-" + numberFormat.format(basalIob.basaliob) + "U"); totalInsulin.setText(""); - wizardDialogDeliverButton.setVisibility(Button.GONE); + wizardDialogDeliverButton.setVisibility(Button.INVISIBLE); } @@ -304,7 +320,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { wizardDialogDeliverButton.setText("SEND " + insulinText + " " + carbsText); wizardDialogDeliverButton.setVisibility(Button.VISIBLE); } else { - wizardDialogDeliverButton.setVisibility(Button.GONE); + wizardDialogDeliverButton.setVisibility(Button.INVISIBLE); } } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java b/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java new file mode 100644 index 0000000000..10b213585c --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java @@ -0,0 +1,180 @@ +package info.nightscout.utils; + +import android.os.Handler; +import android.os.Message; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.View; + +import android.widget.ImageView; +import android.widget.TextView; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.NumberFormat; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * Created by mike on 28.06.2016. + */ +public class PlusMinusEditText implements View.OnKeyListener, + View.OnTouchListener, View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(PlusMinusEditText.class); + + Integer editTextID; + TextView editText; + ImageView minusImage; + ImageView plusImage; + + Double value; + Double minValue = 0d; + Double maxValue = 1d; + Double step = 1d; + NumberFormat formater; + + private Handler mHandler; + private ScheduledExecutorService mUpdater; + + private class UpdateCounterTask implements Runnable { + private boolean mInc; + + public UpdateCounterTask(boolean inc) { + mInc = inc; + } + + public void run() { + if (mInc) { + mHandler.sendEmptyMessage(MSG_INC); + } else { + mHandler.sendEmptyMessage(MSG_DEC); + } + } + } + + private static final int MSG_INC = 0; + private static final int MSG_DEC = 1; + + public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater) { + editText = (TextView) view.findViewById(editTextID); + minusImage = (ImageView) view.findViewById(minusID); + plusImage = (ImageView) view.findViewById(plusID); + + this.value = initValue; + this.minValue = minValue; + this.maxValue = maxValue; + this.step = step; + this.formater = formater; + + mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_INC: + inc(); + return; + case MSG_DEC: + dec(); + return; + } + super.handleMessage(msg); + } + }; + + minusImage.setOnTouchListener(this); + minusImage.setOnKeyListener(this); + minusImage.setOnClickListener(this); + plusImage.setOnTouchListener(this); + plusImage.setOnKeyListener(this); + plusImage.setOnClickListener(this); + } + + public void setValue(Double value) { + this.value = value; + updateEditText(); + } + + public Double getValue() { + return value; + } + + public void setStep(Double step) { + this.step = step; + } + + private void inc() { + value += step; + if (value > maxValue) value = maxValue; + updateEditText(); + } + + private void dec() { + value -= step; + if (value < minValue) value = minValue; + updateEditText(); + } + + private void updateEditText() { + if (value == 0d) + editText.setText(""); + else + editText.setText(formater.format(value)); + } + + private void startUpdating(boolean inc) { + if (mUpdater != null) { + log.debug(getClass().getSimpleName(), "Another executor is still active"); + return; + } + mUpdater = Executors.newSingleThreadScheduledExecutor(); + mUpdater.scheduleAtFixedRate(new UpdateCounterTask(inc), 200, 200, + TimeUnit.MILLISECONDS); + } + + private void stopUpdating() { + mUpdater.shutdownNow(); + mUpdater = null; + } + + @Override + public void onClick(View v) { + if (mUpdater == null) { + if (v == plusImage) { + inc(); + } else { + dec(); + } + } + } + + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + boolean isKeyOfInterest = keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER; + boolean isReleased = event.getAction() == KeyEvent.ACTION_UP; + boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN + && event.getAction() != KeyEvent.ACTION_MULTIPLE; + + if (isKeyOfInterest && isReleased) { + stopUpdating(); + } else if (isKeyOfInterest && isPressed) { + startUpdating(v == plusImage); + } + return false; + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL; + boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN; + + if (isReleased) { + stopUpdating(); + } else if (isPressed) { + startUpdating(v == plusImage); + } + return false; + } + +} diff --git a/app/src/main/res/drawable-hdpi/ic_action_add.png b/app/src/main/res/drawable-hdpi/ic_action_add.png new file mode 100644 index 0000000000000000000000000000000000000000..ca13239a7d6102d789ddef86e219ccb44ae56950 GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUtAWs*^kcwMxZ*1gcP~dQN{1*Q! zJNXeqltbT>uQ86!sw>Zl0#yOQ0ha^w=0KPX47-@$wbrp42tDXvgbLY|Ls;{+F)({= UU3IEMqYNbD>FVdQ&MBb@0GInDp#T5? literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_action_minus.png b/app/src/main/res/drawable-hdpi/ic_action_minus.png new file mode 100644 index 0000000000000000000000000000000000000000..e68aed5a2f8985f44411ecbdc5a2fa7074c86f82 GIT binary patch literal 131 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCFHaZ8kcwMxFCXM&P!M1~_~m}d z77jswwGFIilrv|aWCbcg1`l!%#O1SoP(9Geh%C&&(6^1@ytJ!kYjBknNW#{;R literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_action_add.png b/app/src/main/res/drawable-mdpi/ic_action_add.png new file mode 100644 index 0000000000000000000000000000000000000000..06ff3a5c05c9103d79a85b2368b6c394aad5561a GIT binary patch literal 121 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz2TvErkcwMxuNiVNDDW^J`1AjA zC`)`mz!YhtWqTJo2Z!#Q2~@S^)aH4nObiSU!VknL{P!MrG_-=nm zB9q9&_9sVzP1R>@o2dg-0|Lhj&zt`ef4~gk=|`!jta-QdC_^ZS@9FC2vd$@?2>@60 BALsx8 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_action_add.png b/app/src/main/res/drawable-xhdpi/ic_action_add.png new file mode 100644 index 0000000000000000000000000000000000000000..e5dd67bb44d675d18dcf1bf2a94791649b1797b8 GIT binary patch literal 174 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=rJgR1Ar-gY-csaaP~c%X`1}8I z?nx68xH*->%w+?whJ@DX0aYP^1;rm^_JRyR0TuEI@ej&?LIo_0C=x)b@T&*e;3t4r8Bo&3s)J+m<@$NTyFe;EUHx3vIVCg! E09A7xkpKVy literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_add.png b/app/src/main/res/drawable-xxhdpi/ic_action_add.png new file mode 100644 index 0000000000000000000000000000000000000000..ed6a26cd87052f4cf1b1c64039e9088625cf16c7 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGodp%toLn>~)y|$5;L4k+);G6wh z5*aiC9b!J#KFJR9^s1F)WME)qP+(wSVQ64r5MW?nVsKz!-~b60T)+7FO(@V1Vt@tv w2I&`H;VSnmgfsCoP;69SU`SzsIi=yh)J*GZhgk)@&x4HcboFyt=akR{0JTadvj6}9 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_minus.png b/app/src/main/res/drawable-xxhdpi/ic_action_minus.png new file mode 100644 index 0000000000000000000000000000000000000000..c2c7a8895f0d5868c66b9962016f98e243b1e74b GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGo3p`yMLn>~)y~xPPz`()m_y{au485kHD6c`v-7#bKD1Q-~Y7#x7A2n#kmXV@IW12i5C9Ej3`Fdbp- ZgLq!n5|Is@Tl2sMdAj+K!iyruw=hQQf7 z_^k!PE`{zEN?GvR;Nq8=cl>;6Ed)R8E1qP%(nRsoPv&PEZvwR=Kuy#7PQ{J6Gv6E4 z&U}~nt0L!h=BeMO_RBwTo>@F|;~B%Wp8c{(((hS3nO{71h@XGPa+{#TC5BxUTkrFK zdz-lKV}yFc9Yz^#Mj2KG21X7C1||mv4hBXA29^c}0R|=!^6uC;!RTf1)c&1_l%h@&O^JCwF>F<6CwRQ|h;KRi_#^41OoF~#hg@A-TUHx3vIVCg!0J_Do AA^-pY literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_minus.png b/app/src/main/res/drawable-xxxhdpi/ic_action_minus.png new file mode 100644 index 0000000000000000000000000000000000000000..2af4e931e7e316f3ea4566c50e1a668fe041bbce GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRS2RvOILn>~)z2V5!Y#_iIz{>wf zZRh`6vyb$uZ!FQ-ESU9O_Fi*+15dn9+AN@QoS;D}?dQx((@sdeoT#?_%bc@8KTq%H z+u_=GLQeA2$$7>%i`;rYU|g<})PCa!H - + android:padding="10dp"> + android:textAppearance="?android:attr/textAppearanceLarge" /> - + android:orientation="horizontal"> + + + + + + + - - + android:textAppearance="?android:attr/textAppearanceLarge" /> - -