plus minus controls

This commit is contained in:
Milos Kozak 2016-06-28 11:19:27 +02:00
parent caa4f3402e
commit f3c15aca75
18 changed files with 379 additions and 51 deletions

View file

@ -1,6 +1,7 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintLabelFor" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintRtlHardcoded" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -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;

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

View file

@ -1,69 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:focusableInTouchMode="true"
android:orientation="vertical"
>
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="@string/treatments_newtreatment_insulinamount_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal"/>
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/treatments_newtreatment_insulinamount"
android:padding="10dp"
android:minWidth="200dp"
android:layout_gravity="center_horizontal"
android:inputType="numberDecimal"/>
android:orientation="horizontal">
<ImageView
android:id="@+id/treatments_newtreatment_insulinamount_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:src="@drawable/ic_action_add"
android:tint="#ffffff" />
<EditText
android:id="@+id/treatments_newtreatment_insulinamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="200dp"
android:padding="10dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal" />
<ImageView
android:id="@+id/treatments_newtreatment_insulinamount_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:src="@drawable/ic_action_minus"
android:tint="#ffffff" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="@string/treatments_newtreatment_carbsamount_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/treatments_newtreatment_carbsamount"
android:padding="10dp"
android:minWidth="200dp"
android:layout_gravity="center_horizontal"
android:inputType="numberDecimal"/>
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<Button
android:id="@+id/treatments_newtreatment_deliverbutton"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:textSize="20sp"
android:padding="10dp"
android:layout_weight="1"
/>
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/treatments_newtreatment_carbsamount_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:src="@drawable/ic_action_add"
android:tint="#ffffff" />
<EditText
android:id="@+id/treatments_newtreatment_carbsamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="200dp"
android:padding="10dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal" />
<ImageView
android:id="@+id/treatments_newtreatment_carbsamount_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:src="@drawable/ic_action_minus"
android:tint="#ffffff" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:id="@+id/treatments_newtreatment_deliverbutton"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="OK"
android:textSize="20sp" />
</LinearLayout>

View file

@ -5,7 +5,8 @@
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical"
>
android:minWidth="300dp"
android:focusableInTouchMode="true">
<LinearLayout
android:orientation="horizontal"
@ -21,6 +22,16 @@
android:layout_gravity="center_horizontal"
android:width="80dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_bginput_plus"
android:src="@drawable/ic_action_add"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -32,6 +43,16 @@
android:gravity="center_horizontal"
android:layout_weight="0.5" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_bginput_minus"
android:layout_gravity="center"
android:src="@drawable/ic_action_minus"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<TextView
android:id="@+id/treatments_wizard_bgunits"
android:layout_width="wrap_content"
@ -59,6 +80,16 @@
android:layout_gravity="center_horizontal"
android:width="80dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_carbsinput_plus"
android:src="@drawable/ic_action_add"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -72,6 +103,16 @@
android:gravity="center_horizontal"
android:layout_weight="0.5" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_carbsinput_minus"
android:layout_gravity="center"
android:src="@drawable/ic_action_minus"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -98,6 +139,16 @@
android:layout_gravity="center_horizontal"
android:width="80dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_correctioninput_plus"
android:src="@drawable/ic_action_add"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -111,6 +162,16 @@
android:gravity="center_horizontal"
android:layout_weight="0.5" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/treatments_wizard_correctioninput_minus"
android:layout_gravity="center"
android:src="@drawable/ic_action_minus"
android:background="@drawable/circle"
android:backgroundTint="#ffffff"
android:tint="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"