diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java
index 112ead21fa..c70a66850f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfileFragment.java
@@ -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();
@@ -469,8 +492,9 @@ public class CircadianPercentageProfileFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
+ updateGui();
MainApp.bus().register(this);
- onStatusEvent(null);
+ onStatusEvent(new EventInitializationChanged());
fl.requestFocusFromTouch();
}
@@ -489,4 +513,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();
+ }
+ });
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java
index 4137b0263b..768cdf90e7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java
@@ -15,9 +15,12 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.data.ProfileStore;
+import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
@@ -159,6 +162,55 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
createConvertedProfile();
}
+ public String externallySetParameters(int timeshift, int percentage) {
+
+ String msg = "";
+
+ if (!fragmentEnabled){
+ msg+= "NO CPP!" + "\n";
+ }
+
+ //check for validity
+ if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
+ msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
+ }
+ if (timeshift < 0 || timeshift > 23) {
+ msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
+ }
+ if(!SP.getBoolean("syncprofiletopump", false)){
+ msg+= MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
+ }
+ final PumpInterface pump = MainApp.getConfigBuilder();
+ final Profile profile = MainApp.getConfigBuilder().getProfile();
+
+ if (pump == null || profile == null || profile.getBasal() == null){
+ msg+= MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
+ }
+ if(!"".equals(msg)) {
+ msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored);
+ return msg;
+ }
+
+ //store profile
+ this.timeshift= timeshift;
+ this.percentage = percentage;
+ storeSettings();
+
+
+ //send profile to pumpe
+ new NewNSTreatmentDialog(); //init
+ NewNSTreatmentDialog.doProfileSwitch(this.getProfile(), this.getProfileName(), 0);
+
+ //return formatted string
+ /*msg += "%: " + this.percentage + " h: +" + this.timeshift;
+ msg += "\n";
+ msg += "\nBasal:\n" + basalString() + "\n";
+ msg += "\nISF:\n" + isfString() + "\n";
+ msg += "\nIC:\n" + isfString() + "\n";*/
+
+ return msg;
+ }
+
private void createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();
@@ -304,4 +356,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
return sb.toString();
}
+ public int getPercentage() {
+ return percentage;
+ }
+
+ public int getTimeshift() {
+ return timeshift;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
index 858bd653f5..096b5b5cda 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java
@@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@@ -225,7 +226,38 @@ public class ActionStringHandler {
lastBolusWizard = bolusWizard;
- } else return;
+ } else if("opencpp".equals(act[0])){
+ Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
+ CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
+
+ if(cpp == null || activeProfile==null || cpp != activeProfile){
+ sendError("CPP not activated!");
+ return;
+ } else {
+ // read CPP values
+ rTitle = "opencpp";
+ rMessage = "opencpp";
+ rAction = "opencpp" + " " + cpp.getPercentage() + " " + cpp.getTimeshift();
+ }
+
+ } else if("cppset".equals(act[0])){
+ Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
+ CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
+
+ if(cpp == null || activeProfile==null || cpp != activeProfile){
+ sendError("CPP not activated!");
+ return;
+ } else {
+ // read CPP values
+ rMessage = "CPP:" + "\n\n"+
+ "Timeshift: " + act[1] + "\n" +
+ "Percentage: " + act[2] + "%";
+ rAction = actionstring;
+ }
+
+ }
+ else return;
+
// send result
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, rMessage, rAction);
@@ -379,10 +411,32 @@ public class ActionStringHandler {
double insulin = SafeParse.stringToDouble(act[1]);
int carbs = SafeParse.stringToInt(act[2]);
doBolus(insulin, carbs);
+ } else if ("cppset".equals(act[0])) {
+ int timeshift = SafeParse.stringToInt(act[1]);
+ int percentage = SafeParse.stringToInt(act[2]);
+ setCPP(percentage, timeshift);
}
lastBolusWizard = null;
}
+ private static void setCPP(int percentage, int timeshift) {
+ Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
+ CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
+
+ if(cpp == null || activeProfile==null || cpp != activeProfile){
+ sendError("CPP not activated!");
+ return;
+ }
+ String msg = cpp.externallySetParameters(timeshift, percentage);
+ 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) {
TempTarget tempTarget = new TempTarget();
tempTarget.date = System.currentTimeMillis();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
index 3f86a78a02..93a85686b3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
@@ -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);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d7f22e9ac3..f266668671 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -680,4 +680,7 @@
Sensitivity WeightedAverage
OK
Cancel
+ needs to be activated to send values to the pump!
+ Not all profiles loaded!
+ Values not stored!
diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml
index fc40e930cd..4db69169dd 100644
--- a/wear/src/main/AndroidManifest.xml
+++ b/wear/src/main/AndroidManifest.xml
@@ -140,6 +140,10 @@
android:name=".interaction.actions.BolusActivity"
android:label="Bolus">
+
+
diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java
index 3d66508fa7..711e6a76f4 100644
--- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java
+++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java
@@ -26,6 +26,8 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.interaction.AAPSPreferences;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interaction.actions.CPPActivity;
+import info.nightscout.androidaps.interaction.utils.SafeParse;
/**
* Created by emmablack on 12/26/14.
@@ -252,7 +254,21 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
- showConfirmationDialog(title, message, actionstring);
+
+ if("opencpp".equals(title) && actionstring.startsWith("opencpp")){
+ String[] act = actionstring.split("\\s+");
+ Intent intent = new Intent(this, CPPActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ //TODO adrian: parse actionstring and add parameters
+ Bundle params = new Bundle();
+ params.putInt("percentage", SafeParse.stringToInt(act[1]));
+ params.putInt("timeshift", SafeParse.stringToInt(act[2]));
+ intent.putExtras(params);
+ startActivity(intent);
+ } else {
+ showConfirmationDialog(title, message, actionstring);
+ }
+
}else if (path.equals(NEW_STATUS_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();
diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java
new file mode 100644
index 0000000000..f3ffb06bc0
--- /dev/null
+++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java
@@ -0,0 +1,133 @@
+package info.nightscout.androidaps.interaction.actions;
+
+
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.support.wearable.view.DotsPageIndicator;
+import android.support.wearable.view.GridPagerAdapter;
+import android.support.wearable.view.GridViewPager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import java.text.DecimalFormat;
+
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.data.ListenerService;
+import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
+import info.nightscout.androidaps.interaction.utils.SafeParse;
+
+/**
+ * Created by adrian on 09/02/17.
+ */
+
+
+public class CPPActivity extends ViewSelectorActivity {
+
+ PlusMinusEditText editPercentage;
+ PlusMinusEditText editTimeshift;
+
+ int percentage = -1;
+ int timeshift = -1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Bundle extras = getIntent().getExtras();
+ percentage = extras.getInt("percentage", -1);
+ timeshift = extras.getInt("timeshift", -1);
+
+ if (percentage ==-1 || timeshift ==-1){
+ finish(); return;
+ }
+
+ setContentView(R.layout.grid_layout);
+ final Resources res = getResources();
+ final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
+
+ pager.setAdapter(new MyGridViewPagerAdapter());
+ DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
+ dotsPageIndicator.setPager(pager);
+ }
+
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ finish();
+ }
+
+
+ private class MyGridViewPagerAdapter extends GridPagerAdapter {
+ @Override
+ public int getColumnCount(int arg0) {
+ return 3;
+ }
+
+ @Override
+ public int getRowCount() {
+ return 1;
+ }
+
+ @Override
+ public Object instantiateItem(ViewGroup container, int row, int col) {
+
+ if(col == 0){
+ final View view = getInflatedPlusMinusView(container);
+ double def = timeshift;
+ 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, 23d, 1d, new DecimalFormat("0"), true, true);
+ setLabelToPlusMinusView(view, "timeshift");
+ container.addView(view);
+ return view;
+ } else if(col == 1){
+ final View view = getInflatedPlusMinusView(container);
+ double def = percentage;
+ if (editPercentage != null){
+ def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
+ }
+ editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
+ setLabelToPlusMinusView(view, "percentage");
+ container.addView(view);
+ return view;
+ } else {
+
+ final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
+ final ImageView confirmbutton = (ImageView) view.findViewById(R.id.confirmbutton);
+ confirmbutton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ //check if it can happen that the fagment is never created that hold data?
+ // (you have to swipe past them anyways - but still)
+
+ String actionstring = "cppset " +SafeParse.stringToInt(editTimeshift.editText.getText().toString())
+ + " " + SafeParse.stringToInt(editPercentage.editText.getText().toString());
+ ListenerService.initiateAction(CPPActivity.this, actionstring);
+ finish();
+ }
+ });
+ container.addView(view);
+ return view;
+ }
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int row, int col, Object view) {
+ // Handle this to get the data before the view is destroyed?
+ // Object should still be kept by this, just setup for reinit?
+ container.removeView((View)view);
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return view==object;
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java
index 5e4c221e9d..a57bd17c8f 100644
--- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java
+++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java
@@ -15,6 +15,7 @@ public class StatusMenuActivity extends MenuListActivity {
"Pump",
"Loop",
"Targets",
+ "CPP",
"OAPS Result"};
}
@@ -33,6 +34,9 @@ public class StatusMenuActivity extends MenuListActivity {
ListenerService.initiateAction(this, "status targets");
break;
case 3:
+ ListenerService.initiateAction(this, "opencpp");
+ break;
+ case 4:
ListenerService.initiateAction(this, "status oapsresult");
break;
}
diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java
index 0cbae9fecf..5af013c042 100644
--- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java
+++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java
@@ -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();
}