diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java
index f6e043d3b6..f6c9d4c3d6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java
@@ -2,11 +2,9 @@ package info.nightscout.androidaps.plugins.Actions.dialogs;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
-import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
@@ -16,7 +14,6 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
-import android.widget.TextView;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
@@ -32,12 +29,11 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.utils.DecimalFormatter;
-import info.nightscout.utils.PlusMinusEditText;
+import info.nightscout.utils.NumberPicker;
import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
@@ -45,13 +41,12 @@ public class FillDialog extends DialogFragment implements OnClickListener {
private static Logger log = LoggerFactory.getLogger(FillDialog.class);
Button deliverButton;
- TextView insulin;
double amount1 = 0d;
double amount2 = 0d;
double amount3 = 0d;
- PlusMinusEditText editInsulin;
+ NumberPicker editInsulin;
Handler mHandler;
public static HandlerThread mHandlerThread;
@@ -73,10 +68,10 @@ public class FillDialog extends DialogFragment implements OnClickListener {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
- insulin = (TextView) view.findViewById(R.id.treatments_newtreatment_insulinamount);
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
- editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
+ editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
+ editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
//setup preset buttons
Button button1 = (Button) view.findViewById(R.id.fill_preset_button1);
@@ -88,21 +83,21 @@ public class FillDialog extends DialogFragment implements OnClickListener {
amount2 = SP.getDouble("fill_button2", 0d);
amount3 = SP.getDouble("fill_button3", 0d);
- if(amount1 >0) {
+ if (amount1 > 0) {
button1.setVisibility(View.VISIBLE);
button1.setText(DecimalFormatter.to2Decimal(amount1) + "U");
button1.setOnClickListener(this);
} else {
button1.setVisibility(View.GONE);
}
- if(amount2 >0) {
+ if (amount2 > 0) {
button2.setVisibility(View.VISIBLE);
button2.setText(DecimalFormatter.to2Decimal(amount2) + "U");
button2.setOnClickListener(this);
} else {
button2.setVisibility(View.GONE);
}
- if(amount3 >0) {
+ if (amount3 > 0) {
button3.setVisibility(View.VISIBLE);
button3.setText(DecimalFormatter.to2Decimal(amount3) + "U");
button3.setOnClickListener(this);
@@ -110,7 +105,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
button3.setVisibility(View.GONE);
}
- if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE ) {
+ if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE) {
divider.setVisibility(View.GONE);
}
return view;
@@ -127,7 +122,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
public void onClick(View view) {
switch (view.getId()) {
case R.id.treatments_newtreatment_deliverbutton:
- Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
+ Double insulin = SafeParse.stringToDouble(editInsulin.getText().toString());
confirmAndDeliver(insulin);
break;
case R.id.fill_preset_button1:
diff --git a/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java b/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java
deleted file mode 100644
index c9949252af..0000000000
--- a/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java
+++ /dev/null
@@ -1,210 +0,0 @@
-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;
-
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-
-/**
- * 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;
- boolean allowZero = false;
-
- private Handler mHandler;
- private ScheduledExecutorService mUpdater;
-
- private class UpdateCounterTask implements Runnable {
- private boolean mInc;
- private int repeated = 0;
- private int multiplier = 1;
-
- private final int doubleLimit = 5;
-
- public UpdateCounterTask(boolean inc) {
- mInc = inc;
- }
-
- public void run() {
- Message msg = new Message();
- if (repeated % doubleLimit == 0) multiplier *= 2;
- repeated++;
- msg.arg1 = multiplier;
- msg.arg2 = repeated;
- if (mInc) {
- msg.what = MSG_INC;
- } else {
- msg.what = MSG_DEC;
- }
- mHandler.sendMessage(msg);
- }
- }
-
- 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, boolean allowZero) {
- 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;
- this.allowZero = allowZero;
-
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_INC:
- inc(msg.arg1);
- return;
- case MSG_DEC:
- dec(msg.arg1);
- return;
- }
- super.handleMessage(msg);
- }
- };
-
- minusImage.setOnTouchListener(this);
- minusImage.setOnKeyListener(this);
- minusImage.setOnClickListener(this);
- plusImage.setOnTouchListener(this);
- plusImage.setOnKeyListener(this);
- plusImage.setOnClickListener(this);
- updateEditText();
- }
-
- public void setValue(Double value) {
- this.value = value;
- updateEditText();
- }
-
- public Double getValue() {
- return value;
- }
-
- public String getText() {
- return editText.getText().toString();
- }
-
- public void setStep(Double step) {
- this.step = step;
- }
-
- private void inc(int multiplier) {
- value += step * multiplier;
- if (value > maxValue) {
- value = maxValue;
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.youareonallowedlimit));
- stopUpdating();
- }
- updateEditText();
- }
-
- private void dec( int multiplier) {
- value -= step * multiplier;
- if (value < minValue) {
- value = minValue;
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.youareonallowedlimit));
- stopUpdating();
- }
- updateEditText();
- }
-
- private void updateEditText() {
- if (value == 0d && !allowZero)
- editText.setText("");
- else
- editText.setText(formater.format(value));
- }
-
- private void startUpdating(boolean inc) {
- if (mUpdater != null) {
- log.debug("Another executor is still active");
- return;
- }
- mUpdater = Executors.newSingleThreadScheduledExecutor();
- mUpdater.scheduleAtFixedRate(new UpdateCounterTask(inc), 200, 200,
- TimeUnit.MILLISECONDS);
- }
-
- private void stopUpdating() {
- if (mUpdater != null) {
- mUpdater.shutdownNow();
- mUpdater = null;
- }
- }
-
- @Override
- public void onClick(View v) {
- if (mUpdater == null) {
- if (v == plusImage) {
- inc(1);
- } else {
- dec(1);
- }
- }
- }
-
- @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/layout/actions_fill_dialog.xml b/app/src/main/res/layout/actions_fill_dialog.xml
index e6fb0b05ee..55e44f4bc7 100644
--- a/app/src/main/res/layout/actions_fill_dialog.xml
+++ b/app/src/main/res/layout/actions_fill_dialog.xml
@@ -6,51 +6,37 @@
android:orientation="vertical"
android:padding="10dp">
-
-
-
-
-
-
+ android:text="@string/treatments_newtreatment_insulinamount_label"
+ android:textAppearance="@android:style/TextAppearance.Material.Small"
+ android:textStyle="bold" />
-
+
+
+ android:layout_gravity="center_vertical"
+ android:gravity="left"
+ android:minWidth="45dp"
+ android:paddingLeft="5dp"
+ android:text="U"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+