CPP copy simple profile
This commit is contained in:
parent
d9d7a881a2
commit
be556cf388
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.db.DatabaseHelper;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
||||
|
@ -75,6 +76,7 @@ public class MainApp extends Application {
|
|||
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin());
|
||||
pluginsList.add(NSProfileViewerFragment.getPlugin());
|
||||
pluginsList.add(SimpleProfileFragment.getPlugin());
|
||||
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
||||
pluginsList.add(TreatmentsFragment.getPlugin());
|
||||
pluginsList.add(TempBasalsFragment.getPlugin());
|
||||
pluginsList.add(SafetyFragment.getPlugin());
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package info.nightscout.androidaps.plugins.CircadianPercentageProfile;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
public class CircadianPercentageProfileFragment extends Fragment implements FragmentBase {
|
||||
private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfileFragment.class);
|
||||
|
||||
private static CircadianPercentageProfilePlugin circadianPercentageProfilePlugin = new CircadianPercentageProfilePlugin();
|
||||
|
||||
public static CircadianPercentageProfilePlugin getPlugin() {
|
||||
return circadianPercentageProfilePlugin;
|
||||
}
|
||||
|
||||
EditText diaView;
|
||||
RadioButton mgdlView;
|
||||
RadioButton mmolView;
|
||||
EditText icView;
|
||||
EditText isfView;
|
||||
EditText carView;
|
||||
EditText basalView;
|
||||
EditText targetlowView;
|
||||
EditText targethighView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false);
|
||||
diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia);
|
||||
mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl);
|
||||
mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol);
|
||||
icView = (EditText) layout.findViewById(R.id.simpleprofile_ic);
|
||||
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
|
||||
carView = (EditText) layout.findViewById(R.id.simpleprofile_car);
|
||||
basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate);
|
||||
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
|
||||
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
||||
|
||||
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
||||
diaView.setText(circadianPercentageProfilePlugin.dia.toString());
|
||||
icView.setText(circadianPercentageProfilePlugin.ic.toString());
|
||||
isfView.setText(circadianPercentageProfilePlugin.isf.toString());
|
||||
carView.setText(circadianPercentageProfilePlugin.car.toString());
|
||||
basalView.setText(circadianPercentageProfilePlugin.basal.toString());
|
||||
targetlowView.setText(circadianPercentageProfilePlugin.targetLow.toString());
|
||||
targethighView.setText(circadianPercentageProfilePlugin.targetHigh.toString());
|
||||
|
||||
mgdlView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
circadianPercentageProfilePlugin.mgdl = mgdlView.isChecked();
|
||||
circadianPercentageProfilePlugin.mmol = !circadianPercentageProfilePlugin.mgdl;
|
||||
mmolView.setChecked(circadianPercentageProfilePlugin.mmol);
|
||||
circadianPercentageProfilePlugin.storeSettings();
|
||||
}
|
||||
});
|
||||
mmolView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
circadianPercentageProfilePlugin.mmol = mmolView.isChecked();
|
||||
circadianPercentageProfilePlugin.mgdl = !circadianPercentageProfilePlugin.mmol;
|
||||
mgdlView.setChecked(circadianPercentageProfilePlugin.mgdl);
|
||||
circadianPercentageProfilePlugin.storeSettings();
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
||||
circadianPercentageProfilePlugin.ic = SafeParse.stringToDouble(icView.getText().toString());
|
||||
circadianPercentageProfilePlugin.isf = SafeParse.stringToDouble(isfView.getText().toString());
|
||||
circadianPercentageProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString());
|
||||
circadianPercentageProfilePlugin.basal = SafeParse.stringToDouble(basalView.getText().toString());
|
||||
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
||||
circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
|
||||
circadianPercentageProfilePlugin.storeSettings();
|
||||
}
|
||||
};
|
||||
|
||||
diaView.addTextChangedListener(textWatch);
|
||||
icView.addTextChangedListener(textWatch);
|
||||
isfView.addTextChangedListener(textWatch);
|
||||
carView.addTextChangedListener(textWatch);
|
||||
basalView.addTextChangedListener(textWatch);
|
||||
targetlowView.addTextChangedListener(textWatch);
|
||||
targethighView.addTextChangedListener(textWatch);
|
||||
return layout;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
package info.nightscout.androidaps.plugins.CircadianPercentageProfile;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInterface {
|
||||
public static final String SETTINGS_PREFIX = "CircadianPercentageProfile";
|
||||
private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfilePlugin.class);
|
||||
|
||||
private static boolean fragmentEnabled = true;
|
||||
private static boolean fragmentVisible = true;
|
||||
|
||||
private static NSProfile convertedProfile = null;
|
||||
|
||||
boolean mgdl;
|
||||
boolean mmol;
|
||||
Double dia;
|
||||
Double ic;
|
||||
Double isf;
|
||||
Double car;
|
||||
Double basal;
|
||||
Double targetLow;
|
||||
Double targetHigh;
|
||||
|
||||
public CircadianPercentageProfilePlugin() {
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentClass() {
|
||||
return CircadianPercentageProfileFragment.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return PluginBase.PROFILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Adrian: stringify! (omitted to prevent merge conflicts)
|
||||
return "CPP";
|
||||
//return MainApp.instance().getString(R.string.simpleprofile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int type) {
|
||||
return fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleInTabs(int type) {
|
||||
return fragmentVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHidden(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||
this.fragmentEnabled = fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||
this.fragmentVisible = fragmentVisible;
|
||||
}
|
||||
|
||||
public void storeSettings() {
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Storing settings");
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean(SETTINGS_PREFIX + "mmol", mmol);
|
||||
editor.putBoolean(SETTINGS_PREFIX + "mgdl", mgdl);
|
||||
editor.putString(SETTINGS_PREFIX + "dia", dia.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "ic", ic.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "isf", isf.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "car", car.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "basal", basal.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "targetlow", targetLow.toString());
|
||||
editor.putString(SETTINGS_PREFIX + "targethigh", targetHigh.toString());
|
||||
|
||||
|
||||
editor.commit();
|
||||
createConvertedProfile();
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Loading stored settings");
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
|
||||
if (settings.contains(SETTINGS_PREFIX+ "mgdl"))
|
||||
try {
|
||||
mgdl = settings.getBoolean(SETTINGS_PREFIX + "mgdl", true);
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else mgdl = true;
|
||||
if (settings.contains(SETTINGS_PREFIX + "mmol"))
|
||||
try {
|
||||
mmol = settings.getBoolean(SETTINGS_PREFIX + "mmol", false);
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else mmol = false;
|
||||
if (settings.contains(SETTINGS_PREFIX + "dia"))
|
||||
try {
|
||||
dia = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "dia", "3"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else dia = 3d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "ic"))
|
||||
try {
|
||||
ic = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "ic", "20"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else ic = 20d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "isf"))
|
||||
try {
|
||||
isf = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "isf", "200"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else isf = 200d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "car"))
|
||||
try {
|
||||
car = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "car", "20"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else car = 20d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "basal"))
|
||||
try {
|
||||
basal = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "basal", "1"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else basal = 1d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "targetlow"))
|
||||
try {
|
||||
targetLow = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targetlow", "80"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else targetLow = 80d;
|
||||
if (settings.contains(SETTINGS_PREFIX + "targethigh"))
|
||||
try {
|
||||
targetHigh = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "targethigh", "120"));
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
else targetHigh = 120d;
|
||||
createConvertedProfile();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "576264a12771b7500d7ad184",
|
||||
"startDate": "2016-06-16T08:35:00.000Z",
|
||||
"defaultProfile": "Default",
|
||||
"store": {
|
||||
"Default": {
|
||||
"dia": "3",
|
||||
"carbratio": [{
|
||||
"time": "00:00",
|
||||
"value": "30"
|
||||
}],
|
||||
"carbs_hr": "20",
|
||||
"delay": "20",
|
||||
"sens": [{
|
||||
"time": "00:00",
|
||||
"value": "100"
|
||||
}],
|
||||
"timezone": "UTC",
|
||||
"basal": [{
|
||||
"time": "00:00",
|
||||
"value": "0.1"
|
||||
}],
|
||||
"target_low": [{
|
||||
"time": "00:00",
|
||||
"value": "0"
|
||||
}],
|
||||
"target_high": [{
|
||||
"time": "00:00",
|
||||
"value": "0"
|
||||
}],
|
||||
"startDate": "1970-01-01T00:00:00.000Z",
|
||||
"units": "mmol"
|
||||
}
|
||||
},
|
||||
"created_at": "2016-06-16T08:34:41.256Z"
|
||||
}
|
||||
*/
|
||||
void createConvertedProfile() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject store = new JSONObject();
|
||||
JSONObject profile = new JSONObject();
|
||||
|
||||
try {
|
||||
json.put("defaultProfile", "CircadianPercentage");
|
||||
json.put("store", store);
|
||||
profile.put("dia", dia);
|
||||
profile.put("carbratio", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", ic)));
|
||||
profile.put("carbs_hr", car);
|
||||
profile.put("sens", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", isf)));
|
||||
profile.put("basal", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", basal)));
|
||||
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);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
convertedProfile = new NSProfile(json, "CircadianPercentage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NSProfile getProfile() {
|
||||
return convertedProfile;
|
||||
}
|
||||
|
||||
}
|
155
app/src/main/res/layout/circadianpercentageprofile_fragment.xml
Normal file
155
app/src/main/res/layout/circadianpercentageprofile_fragment.xml
Normal file
|
@ -0,0 +1,155 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".plugins.CircadianPercentageProfile.CircadianPercentageProfileFragment">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left|top">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Units:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/simpleprofile_mgdl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:text="mgdl" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/simpleprofile_mmol"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="3"
|
||||
android:text="mmol" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="DIA:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_dia"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="IC:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_ic"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ISF:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_isf"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Absorption rate:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_car"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Basal rate:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_basalrate"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Target range:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_targetlow"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simpleprofile_targethigh"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue