cpp-watch working2
This commit is contained in:
parent
7f0e611783
commit
7fa8ea7224
5 changed files with 129 additions and 67 deletions
|
@ -33,6 +33,8 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||
|
@ -75,6 +77,50 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
static Boolean percentageViewHint = true;
|
||||
static Boolean timeshiftViewHint = true;
|
||||
|
||||
TextWatcher textWatch = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start,
|
||||
int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start,
|
||||
int before, int count) {
|
||||
|
||||
if (percentageView.testValidity()) {
|
||||
if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) {
|
||||
circadianPercentageProfilePlugin.percentage = 100;
|
||||
} else {
|
||||
circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString());
|
||||
}
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (timeshiftView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (diaView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (targethighView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (targetlowView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
circadianPercentageProfilePlugin.storeSettings();
|
||||
updateProfileInfo();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@ -106,16 +152,6 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
||||
diaView.setText(circadianPercentageProfilePlugin.dia.toString());
|
||||
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
|
||||
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
|
||||
percentageView.setText("" + circadianPercentageProfilePlugin.percentage);
|
||||
timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift);
|
||||
updateProfileInfo();
|
||||
|
||||
mgdlView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -266,49 +302,6 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
TextWatcher textWatch = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start,
|
||||
int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start,
|
||||
int before, int count) {
|
||||
|
||||
if (percentageView.testValidity()) {
|
||||
if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) {
|
||||
circadianPercentageProfilePlugin.percentage = 100;
|
||||
} else {
|
||||
circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString());
|
||||
}
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (timeshiftView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (diaView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (targethighView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
if (targetlowView.testValidity()) {
|
||||
circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
|
||||
updateProfileInfo();
|
||||
}
|
||||
circadianPercentageProfilePlugin.storeSettings();
|
||||
updateProfileInfo();
|
||||
}
|
||||
};
|
||||
|
||||
diaView.addTextChangedListener(textWatch);
|
||||
targetlowView.addTextChangedListener(textWatch);
|
||||
|
@ -316,11 +309,41 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
percentageView.addTextChangedListener(textWatch);
|
||||
timeshiftView.addTextChangedListener(textWatch);
|
||||
|
||||
onStatusEvent(null);
|
||||
updateGui();
|
||||
|
||||
onStatusEvent(new EventInitializationChanged());
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
public void updateGui() {
|
||||
|
||||
|
||||
updateProfileInfo();
|
||||
|
||||
diaView.removeTextChangedListener(textWatch);
|
||||
targetlowView.removeTextChangedListener(textWatch);
|
||||
targethighView.removeTextChangedListener(textWatch);
|
||||
percentageView.removeTextChangedListener(textWatch);
|
||||
timeshiftView.removeTextChangedListener(textWatch);
|
||||
|
||||
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
||||
diaView.setText(circadianPercentageProfilePlugin.dia.toString());
|
||||
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
|
||||
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
|
||||
percentageView.setText("" + circadianPercentageProfilePlugin.percentage);
|
||||
timeshiftView.setText("" + circadianPercentageProfilePlugin.timeshift);
|
||||
|
||||
|
||||
diaView.addTextChangedListener(textWatch);
|
||||
targetlowView.addTextChangedListener(textWatch);
|
||||
targethighView.addTextChangedListener(textWatch);
|
||||
percentageView.addTextChangedListener(textWatch);
|
||||
timeshiftView.addTextChangedListener(textWatch);
|
||||
|
||||
}
|
||||
|
||||
private void customSnackbar(View view, final String Msg, Object snackbarCaller) {
|
||||
if(mSnackBar!= null) mSnackBar.dismiss();
|
||||
|
||||
|
@ -470,7 +493,7 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
onStatusEvent(null);
|
||||
onStatusEvent(new EventInitializationChanged());
|
||||
fl.requestFocusFromTouch();
|
||||
}
|
||||
|
||||
|
@ -489,4 +512,17 @@ public class CircadianPercentageProfileFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventProfileSwitchChange e) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGui();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -250,8 +250,8 @@ public class ActionStringHandler {
|
|||
} else {
|
||||
// read CPP values
|
||||
rMessage = "CPP:" + "\n\n"+
|
||||
"Percentage: " + act[1] + "%\n" +
|
||||
"Timeshift: " + act[2];
|
||||
"Timeshift: " + act[1] + "\n" +
|
||||
"Percentage: " + act[2] + "%";
|
||||
rAction = actionstring;
|
||||
}
|
||||
|
||||
|
@ -428,7 +428,13 @@ public class ActionStringHandler {
|
|||
return;
|
||||
}
|
||||
String msg = cpp.externallySetParameters(timeshift, percentage);
|
||||
ToastUtils.showToastInUiThread(MainApp.instance(), msg);
|
||||
if(msg != null && !"".equals(msg)){
|
||||
String rTitle = "STATUS";
|
||||
String rAction = "statusmessage";
|
||||
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, msg, rAction);
|
||||
lastSentTimestamp = System.currentTimeMillis();
|
||||
lastConfirmActionString = rAction;
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateTempTarget(int duration, double low, double high) {
|
||||
|
|
|
@ -19,6 +19,9 @@ import com.google.android.gms.wearable.PutDataRequest;
|
|||
import com.google.android.gms.wearable.Wearable;
|
||||
import com.google.android.gms.wearable.WearableListenerService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -37,6 +40,7 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
|||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
@ -72,6 +76,9 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
SharedPreferences mPrefs;
|
||||
private static boolean lastLoopStatus;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfilePlugin.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
@ -169,13 +176,13 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
if (event != null && event.getPath().equals(WEARABLE_INITIATE_ACTIONSTRING_PATH)) {
|
||||
String actionstring = new String(event.getData());
|
||||
ToastUtils.showToastInUiThread(this, "Wear: " + actionstring);
|
||||
log.debug("Wear: " + actionstring);
|
||||
ActionStringHandler.handleInitiate(actionstring);
|
||||
}
|
||||
|
||||
if (event != null && event.getPath().equals(WEARABLE_CONFIRM_ACTIONSTRING_PATH)) {
|
||||
String actionstring = new String(event.getData());
|
||||
ToastUtils.showToastInUiThread(this, "Wear Confirm: " + actionstring);
|
||||
log.debug("Wear Confirm: " + actionstring);
|
||||
ActionStringHandler.handleConfirmation(actionstring);
|
||||
}
|
||||
}
|
||||
|
@ -497,7 +504,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
dataMapRequest.getDataMap().putString("message", message);
|
||||
dataMapRequest.getDataMap().putString("actionstring", actionstring);
|
||||
|
||||
ToastUtils.showToastInUiThread(this, "Requesting confirmation from wear: " + actionstring);
|
||||
log.debug("Requesting confirmation from wear: " + actionstring);
|
||||
|
||||
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
||||
|
|
|
@ -80,7 +80,7 @@ public class CPPActivity extends ViewSelectorActivity {
|
|||
if (editTimeshift != null){
|
||||
def = SafeParse.stringToDouble(editTimeshift.editText.getText().toString());
|
||||
}
|
||||
editTimeshift = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 24d, 1d, new DecimalFormat("0"), false);
|
||||
editTimeshift = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 23d, 1d, new DecimalFormat("0"), true, true);
|
||||
setLabelToPlusMinusView(view, "timeshift");
|
||||
container.addView(view);
|
||||
return view;
|
||||
|
|
|
@ -31,6 +31,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
Double step = 1d;
|
||||
NumberFormat formater;
|
||||
boolean allowZero = false;
|
||||
boolean roundRobin;
|
||||
|
||||
private Handler mHandler;
|
||||
private ScheduledExecutorService mUpdater;
|
||||
|
@ -65,6 +66,10 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
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) {
|
||||
this( view, editTextID, plusID, minusID, initValue, minValue, maxValue, step, formater, allowZero, false);
|
||||
}
|
||||
|
||||
public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero, boolean roundRobin) {
|
||||
editText = (TextView) view.findViewById(editTextID);
|
||||
minusImage = (ImageView) view.findViewById(minusID);
|
||||
plusImage = (ImageView) view.findViewById(plusID);
|
||||
|
@ -75,6 +80,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
this.step = step;
|
||||
this.formater = formater;
|
||||
this.allowZero = allowZero;
|
||||
this.roundRobin = roundRobin;
|
||||
|
||||
mHandler = new Handler() {
|
||||
@Override
|
||||
|
@ -112,12 +118,15 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
public void setStep(Double step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
private void inc(int multiplier) {
|
||||
value += step * multiplier;
|
||||
if (value > maxValue) {
|
||||
value = maxValue;
|
||||
stopUpdating();
|
||||
if(roundRobin){
|
||||
value = minValue;
|
||||
} else {
|
||||
value = maxValue;
|
||||
stopUpdating();
|
||||
}
|
||||
}
|
||||
updateEditText();
|
||||
}
|
||||
|
@ -125,8 +134,12 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
private void dec( int multiplier) {
|
||||
value -= step * multiplier;
|
||||
if (value < minValue) {
|
||||
value = minValue;
|
||||
stopUpdating();
|
||||
if(roundRobin){
|
||||
value = maxValue;
|
||||
} else {
|
||||
value = minValue;
|
||||
stopUpdating();
|
||||
}
|
||||
}
|
||||
updateEditText();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue