From 74ea6c4011c3d5d0438d764685adca89b9dded1e Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 14 Nov 2016 03:22:11 +0100 Subject: [PATCH] CPP working --- .../CircadianPercentageProfileFragment.java | 27 +++++++++++++++---- .../CircadianPercentageProfilePlugin.java | 24 ++++++++++++----- ...dianpercentageprofile_editbasal_dialog.xml | 4 +-- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index c1a7184f18..2cb22a29fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -1,14 +1,10 @@ package info.nightscout.androidaps.plugins.CircadianPercentageProfile; -import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; -import android.media.Image; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; -import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; @@ -25,7 +21,6 @@ import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Text; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.FragmentBase; @@ -291,6 +286,28 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } getDialog().setCancelable(true); + view.findViewById(R.id.ok_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + for (int i = 0; i < 24; i++) { + if (editTexts[i].getText().length()!= 0){ + values[i]= SafeParse.stringToDouble(editTexts[i].getText().toString()) ; + } + } + updateProfileInfo(); + getPlugin().storeSettings(); + dismiss(); + } + }); + + view.findViewById(R.id.cancel_action).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java index cb5ccce4ff..671d35c3a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.CircadianPercentageProfile; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.util.StringBuilderPrinter; import org.json.JSONArray; import org.json.JSONException; @@ -41,8 +40,8 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte int percentage; int timeshift; double[] basebasal = new double[]{1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d, 1d}; - double[] baseisf = new double[]{35d, 35d, 35d, 35.1d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d}; - double[] baseic = new double[]{4d, 4d, 4d, 4d, 4.1d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d}; + double[] baseisf = new double[]{35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d, 35d}; + double[] baseic = new double[]{4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d, 4d}; public CircadianPercentageProfilePlugin() { loadSettings(); @@ -203,8 +202,21 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte JSONObject store = new JSONObject(); JSONObject profile = new JSONObject(); + StringBuilder stringBuilder = new StringBuilder(); + double sum = 0d; + for (int i = 0; i < 24; i++) { + sum += basebasal[i]; + } + stringBuilder.append(DecimalFormatter.to2Decimal(sum)); + stringBuilder.append("U@"); + stringBuilder.append(percentage); + stringBuilder.append("%>"); + stringBuilder.append(timeshift); + stringBuilder.append("h"); + String profileName = stringBuilder.toString(); + try { - json.put("defaultProfile", "CircadianPercentage"); + json.put("defaultProfile", profileName); json.put("store", store); profile.put("dia", dia); @@ -234,11 +246,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte profile.put("target_low", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetLow))); profile.put("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh))); profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); - store.put("CircadianPercentage", profile); + store.put(profileName, profile); } catch (JSONException e) { e.printStackTrace(); } - convertedProfile = new NSProfile(json, "CircadianPercentage"); + convertedProfile = new NSProfile(json, profileName); } @Override diff --git a/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml b/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml index 48e9f5a52f..90e2000aa8 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml @@ -41,7 +41,7 @@ android:layout_gravity="center_horizontal">