();
40 | ra.add("one");
41 | ra.add("two");
42 | ra.add("three");
43 | return join(ra, "+");
44 | }
45 |
46 |
47 | /**
48 | * Append To StringBuilder
49 | *
50 | * @param stringBuilder
51 | * @param stringToAdd
52 | * @param delimiter
53 | * @return
54 | */
55 | public static void appendToStringBuilder(StringBuilder stringBuilder, String stringToAdd, String delimiter) {
56 | if (stringBuilder.length() > 0) {
57 | stringBuilder.append(delimiter + stringToAdd);
58 | } else {
59 | stringBuilder.append(stringToAdd);
60 | }
61 | }
62 |
63 |
64 | public static String getFormatedValueUS(Number value, int decimals) {
65 | return DecimalFormaters[decimals].format(value).replace(",", ".");
66 | }
67 |
68 |
69 | public static String getLeadingZero(int number, int places) {
70 | String nn = "" + number;
71 |
72 | while (nn.length() < places) {
73 | nn = "0" + nn;
74 | }
75 |
76 | return nn;
77 | }
78 |
79 |
80 | public static String toDateTimeString(LocalDateTime localDateTime) {
81 | return localDateTime.toString("dd.MM.yyyy HH:mm:ss");
82 | }
83 |
84 |
85 | public static String getStringInLength(String value, int length) {
86 | StringBuilder val = new StringBuilder(value);
87 |
88 | if (val.length() > length) {
89 | return val.substring(0, length);
90 | }
91 |
92 | for (int i = val.length(); i < length; i++) {
93 | val.append(" ");
94 | }
95 |
96 | return val.toString();
97 | }
98 |
99 |
100 | public static void splitString(String s, int characters) {
101 |
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/Constants.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps;
2 |
3 | /**
4 | * Created by mike on 07.06.2016.
5 | */
6 | public class Constants {
7 | public static final String MGDL = "mg/dl"; // This is Nightscout's representation
8 | public static final String MMOL = "mmol";
9 |
10 | public static final double MMOLL_TO_MGDL = 18; // 18.0182;
11 | public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;
12 |
13 | public static final double defaultDIA = 5d;
14 |
15 | public static final Double REALLYHIGHBASALRATE = 1111111d;
16 | public static final Integer REALLYHIGHPERCENTBASALRATE = 1111111;
17 | public static final double REALLYHIGHBOLUS = 1111111d;
18 | public static final Integer REALLYHIGHCARBS = 1111111;
19 | public static final double REALLYHIGHIOB = 1111111d;
20 |
21 | public static final Integer notificationID = 556677;
22 |
23 | public static final int hoursToKeepInDatabase = 72;
24 | public static final int daysToKeepHistoryInDatabase = 30;
25 |
26 | public static final long keepAliveMsecs = 5 * 60 * 1000L;
27 |
28 | // SMS COMMUNICATOR
29 | public static final long remoteBolusMinDistance = 15 * 60 * 1000L;
30 |
31 | // Circadian Percentage Profile
32 | public static final int CPP_MIN_PERCENTAGE = 30;
33 | public static final int CPP_MAX_PERCENTAGE = 200;
34 | public static final int CPP_MIN_TIMESHIFT = -6;
35 | public static final int CPP_MAX_TIMESHIFT = 23;
36 |
37 | public static final double MAX_PROFILE_SWITCH_DURATION = 7 * 24 * 60; // [min] ~ 7 days
38 |
39 | //DanaR
40 | public static final double dailyLimitWarning = 0.95d;
41 |
42 | // Temp targets
43 | public static final int defaultActivityTTDuration = 90; // min
44 | public static final double defaultActivityTTmgdl = 140d;
45 | public static final double defaultActivityTTmmol = 8d;
46 | public static final int defaultEatingSoonTTDuration = 45; // min
47 | public static final double defaultEatingSoonTTmgdl = 90d;
48 | public static final double defaultEatingSoonTTmmol = 5d;
49 | public static final int defaultHypoTTDuration = 30; // min
50 | public static final double defaultHypoTTmgdl = 120d;
51 | public static final double defaultHypoTTmmol = 6.5d;
52 |
53 | public static final double MIN_TT_MGDL = 72d;
54 | public static final double MAX_TT_MGDL = 180d;
55 | public static final double MIN_TT_MMOL = 4d;
56 | public static final double MAX_TT_MMOL = 10d;
57 |
58 | //NSClientInternal
59 | public static final int MAX_LOG_LINES = 100;
60 |
61 | //Screen: Threshold for width/height to go into small width/height layout
62 | public static final int SMALL_WIDTH = 320;
63 | public static final int SMALL_HEIGHT = 480;
64 |
65 | //Autosens
66 | public static final double DEVIATION_TO_BE_EQUAL = 2.0;
67 | public static final double DEFAULT_MAX_ABSORPTION_TIME = 6.0;
68 |
69 | // Pump
70 | public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1;
71 | public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60;
72 |
73 | //SMS Communicator
74 | //public static final long SMS_CONFIRM_TIMEOUT = T.mins(5).msecs();
75 |
76 | //Storage [MB]
77 | public static final long MINIMUM_FREE_SPACE = 200;
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/LocationHelper.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.plugins.pump.common.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.content.Intent;
8 | import android.location.LocationManager;
9 | import android.os.Build;
10 |
11 | import com.androidaps.dashaps.R;
12 |
13 |
14 | /**
15 | * Helper for checking if location services are enabled on the device.
16 | */
17 | public class LocationHelper {
18 |
19 | /**
20 | * Determine if GPS is currently enabled.
21 | *
22 | * On Android 6 (Marshmallow), location needs to be enabled for Bluetooth discovery to work.
23 | *
24 | * @param context The current app context.
25 | * @return true if location is enabled, false otherwise.
26 | */
27 | public static boolean isLocationEnabled(Context context) {
28 | LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
29 |
30 | return (locationManager != null && //
31 | (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || //
32 | locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)));
33 |
34 | // return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
35 | }
36 |
37 |
38 | /**
39 | * Prompt the user to enable GPS location if it isn't already on.
40 | *
41 | * @param parent The currently visible activity.
42 | */
43 | public static void requestLocation(final Activity parent) {
44 | if (LocationHelper.isLocationEnabled(parent)) {
45 | return;
46 | }
47 |
48 | // Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533
49 |
50 | AlertDialog.Builder builder = new AlertDialog.Builder(parent);
51 | builder.setTitle(R.string.location_not_found_title);
52 | builder.setMessage(R.string.location_not_found_message);
53 | builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() {
54 |
55 | public void onClick(DialogInterface dialogInterface, int i) {
56 | parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
57 | }
58 | });
59 | builder.setNegativeButton(R.string.location_no, null);
60 | builder.create().show();
61 | }
62 |
63 |
64 | /**
65 | * Prompt the user to enable GPS location on devices that need it for Bluetooth discovery.
66 | *
67 | * Android 6 (Marshmallow) needs GPS enabled for Bluetooth discovery to work.
68 | *
69 | * @param activity The currently visible activity.
70 | */
71 | public static void requestLocationForBluetooth(Activity activity) {
72 | // Location needs to be enabled for Bluetooth discovery on Marshmallow.
73 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
74 | LocationHelper.requestLocation(activity);
75 | }
76 | }
77 |
78 | // public static Boolean locationPermission(ActivityWithMenu act) {
79 | // return ActivityCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) ==
80 | // PackageManager.PERMISSION_GRANTED;
81 | // }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/utils/OKDialog.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.os.Handler;
8 | import android.os.SystemClock;
9 | import android.text.Spanned;
10 | import android.view.ContextThemeWrapper;
11 |
12 | import com.androidaps.dashaps.MainApp;
13 | import com.androidaps.dashaps.R;
14 |
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 |
19 | /**
20 | * Created by mike on 31.03.2017.
21 | */
22 |
23 | public class OKDialog {
24 | private static Logger log = LoggerFactory.getLogger(OKDialog.class);
25 |
26 | public static void show(final Context context, String title, String message, final Runnable runnable) {
27 | try {
28 | AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AppTheme));
29 | builder.setTitle(title);
30 | builder.setMessage(message);
31 | builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
32 | public void onClick(DialogInterface dialog, int which) {
33 | dialog.dismiss();
34 | if (runnable != null) {
35 | SystemClock.sleep(100);
36 | runOnUiThread(runnable);
37 | }
38 | }
39 | });
40 |
41 | builder.create().show();
42 | } catch (Exception e) {
43 | log.debug("show_dialog exception: ", e);
44 | }
45 | }
46 |
47 | public static boolean runOnUiThread(Runnable theRunnable) {
48 | final Handler mainHandler = new Handler(MainApp.instance().getApplicationContext().getMainLooper());
49 | return mainHandler.post(theRunnable);
50 | }
51 |
52 | public static void show(final Activity activity, String title, Spanned message, final Runnable runnable) {
53 | try {
54 | AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme));
55 | builder.setTitle(title);
56 | builder.setMessage(message);
57 | builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
58 | public void onClick(DialogInterface dialog, int which) {
59 | dialog.dismiss();
60 | if (runnable != null) {
61 | SystemClock.sleep(100);
62 | activity.runOnUiThread(runnable);
63 | }
64 | }
65 | });
66 |
67 | builder.create().show();
68 | } catch (Exception e) {
69 | log.debug("show_dialog exception: " + e);
70 | }
71 | }
72 |
73 | public static void showConfirmation(final Activity activity, String message, final Runnable runnable) {
74 | AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
75 | .setMessage(message)
76 | .setPositiveButton(android.R.string.ok, (dialog, which) -> {
77 | dialog.dismiss();
78 | if (runnable != null) {
79 | SystemClock.sleep(100);
80 | activity.runOnUiThread(runnable);
81 | }
82 | })
83 | .setNegativeButton(android.R.string.cancel, null)
84 | .show();
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/ui/command/SetTBRUiCommand.java:
--------------------------------------------------------------------------------
1 | package com.androidaps.dashaps.ui.command;
2 |
3 | import com.androidaps.dashaps.MainApp;
4 | import com.androidaps.dashaps.data.PodCommandUIType;
5 | import com.androidaps.dashaps.ui.fragments.OverviewFragment;
6 | import com.androidaps.dashaps.ui.fragments.treatment.MainTreatmentFragment;
7 |
8 | import info.nightscout.androidaps.data.PumpEnactResult;
9 | import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
10 | import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
11 |
12 | public class SetTBRUiCommand extends PodCommandQueueUi {
13 |
14 | private double amount;
15 | PumpEnactResult response;
16 | private boolean cancelled;
17 | private long started;
18 |
19 |
20 | public SetTBRUiCommand(double amount) {
21 | this.amount = amount;
22 | }
23 |
24 | @Override
25 | public PodCommandUIType getCommandType() {
26 | return PodCommandUIType.SetTemporaryBasal;
27 | }
28 |
29 | @Override
30 | public void executeCommand() {
31 |
32 | OmnipodPumpStatus pumpStatus = MainApp.getPumpStatus();
33 |
34 | pumpStatus.tempBasalStart = System.currentTimeMillis();
35 | started = pumpStatus.tempBasalStart;
36 |
37 | pumpStatus.tempBasalAmount = amount;
38 | pumpStatus.tempBasalEnd = DateTimeUtil.getTimeInFutureFromMinutes(30);
39 | pumpStatus.tempBasalLength = 30;
40 |
41 | response = MainApp.getOmnipodDashCommunicationManager().setTemporaryBasal(pumpStatus.getTemporaryBasal());
42 |
43 | if (response.success) {
44 | expireAt = pumpStatus.tempBasalEnd;
45 | } else {
46 | expireAt = DateTimeUtil.getTimeInFutureFromSeconds(30);
47 | }
48 |
49 | MainApp.instance().addCommandToQueue(this);
50 |
51 | }
52 |
53 | @Override
54 | public void setCancelled() {
55 | this.cancelled = true;
56 | expireAt = DateTimeUtil.getTimeInFutureFromSeconds(10);
57 | }
58 |
59 |
60 | @Override
61 | public void updateUi(OverviewFragment overviewFragment) {
62 | if (cancelled)
63 | overviewFragment.setTBR("Tbr cancelled");
64 | else if (response.success)
65 | overviewFragment.setTBR(String.format("Rate: %.3f U, Time: %d/30 min", amount, getTimeFromBeginning()));
66 | else
67 | overviewFragment.setTBR("Error setting Bolus: " + response.comment);
68 | }
69 |
70 | @Override
71 | public void updateUi(MainTreatmentFragment treatmentFragment) {
72 | if (cancelled)
73 | treatmentFragment.setTBR(UiStatusType.AllDisabled);
74 | else if (response.success)
75 | treatmentFragment.setTBR(UiStatusType.CancelEnabled);
76 | else
77 | treatmentFragment.setTBR(UiStatusType.AllDisabled);
78 | }
79 |
80 | @Override
81 | public void updateUiOnFinalize(OverviewFragment overviewFragment) {
82 | if (cancelled)
83 | overviewFragment.setTBR("Tbr cancelled");
84 | else if (response.success)
85 | overviewFragment.setTBR(String.format("Rate: %.3f U, Time: 30/30 min", amount));
86 | else
87 | overviewFragment.setTBR("Error setting TBR: " + response.comment);
88 | }
89 |
90 | @Override
91 | public void updateUiOnFinalize(MainTreatmentFragment treatmentFragment) {
92 | treatmentFragment.setTBR(UiStatusType.StartEnabled);
93 | }
94 |
95 | private int getTimeFromBeginning() {
96 | return (int) (System.currentTimeMillis() - started) / (1000 * 60);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/DashAPSUiQueue.java:
--------------------------------------------------------------------------------
1 | package com.androidaps.dashaps;
2 |
3 | import android.util.Log;
4 |
5 | import com.androidaps.dashaps.data.PodCommandUIType;
6 | import com.androidaps.dashaps.ui.command.PodCommandQueueUi;
7 | import com.androidaps.dashaps.ui.fragments.OverviewFragment;
8 | import com.androidaps.dashaps.ui.fragments.treatment.MainTreatmentFragment;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class DashAPSUiQueue {
14 |
15 | private List queue = new ArrayList<>();
16 |
17 | private PodCommandQueueUi bolusCommand = null;
18 | private PodCommandQueueUi tbrCommand = null;
19 |
20 |
21 | public DashAPSUiQueue() {
22 | }
23 |
24 |
25 | public void processQueue() {
26 |
27 | if (workWithQueue(QueueCommand.AnyElementOnQueue, null) != null) {
28 | Log.d("DashAPSUIQueue", "Run Queue (Process)");
29 |
30 | List queueList = (List) workWithQueue(QueueCommand.GetQueue, null);
31 |
32 | List removedList = new ArrayList<>();
33 |
34 | for (PodCommandQueueUi podCommandQueueUi : queueList) {
35 |
36 | if (podCommandQueueUi.isCommandExpired()) {
37 | OverviewFragment.getInstance().processCommandFinished(podCommandQueueUi);
38 | MainTreatmentFragment.getInstance().processCommandFinished(podCommandQueueUi);
39 | removedList.add(podCommandQueueUi);
40 | if (podCommandQueueUi.getCommandType() == PodCommandUIType.SetBolus) {
41 | this.bolusCommand = null;
42 | } else if (podCommandQueueUi.getCommandType() == PodCommandUIType.SetTemporaryBasal) {
43 | this.tbrCommand = null;
44 | }
45 | } else {
46 | OverviewFragment.getInstance().processCommand(podCommandQueueUi);
47 | MainTreatmentFragment.getInstance().processCommand(podCommandQueueUi);
48 | }
49 |
50 | }
51 |
52 | workWithQueue(QueueCommand.RemoveFromList, removedList);
53 |
54 | } else {
55 | Log.d("DashAPSUIQueue", "Run Queue (Empty)");
56 | }
57 |
58 | }
59 |
60 |
61 | public void startChangeCommand(QueueCommand queueCommand) {
62 | workWithQueue(queueCommand, null);
63 | }
64 |
65 |
66 | private synchronized Object workWithQueue(QueueCommand queueCommand, Object parameter) {
67 |
68 | switch (queueCommand) {
69 |
70 | case Add: {
71 | PodCommandQueueUi command = (PodCommandQueueUi) parameter;
72 | this.queue.add(command);
73 | if (command.getCommandType() == PodCommandUIType.SetBolus) {
74 | this.bolusCommand = command;
75 | } else if (command.getCommandType() == PodCommandUIType.SetTemporaryBasal) {
76 | this.tbrCommand = command;
77 | }
78 | return null;
79 | }
80 |
81 | case GetQueue:
82 | return new ArrayList<>(this.queue);
83 |
84 | case RemoveFromList:
85 | this.queue.removeAll((List) parameter);
86 | return null;
87 |
88 | case AnyElementOnQueue: {
89 | return (this.queue.size() == 0) ? null : "";
90 | }
91 |
92 | case CancelBolus:
93 | this.bolusCommand.setCancelled();
94 | break;
95 |
96 | case CancelTBR:
97 | this.tbrCommand.setCancelled();
98 | break;
99 | }
100 |
101 | return null;
102 | }
103 |
104 | public void addToQueue(PodCommandQueueUi command) {
105 | Log.d("DashAPSUIQueue", "Add To Queue");
106 | workWithQueue(QueueCommand.Add, command);
107 | }
108 |
109 |
110 | public enum QueueCommand {
111 | Add,
112 | GetQueue,
113 | RemoveFromList,
114 | AnyElementOnQueue,
115 | CancelBolus,
116 | CancelTBR
117 | }
118 |
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/ui/command/SetBolusUiCommand.java:
--------------------------------------------------------------------------------
1 | package com.androidaps.dashaps.ui.command;
2 |
3 | import com.androidaps.dashaps.MainApp;
4 | import com.androidaps.dashaps.R;
5 | import com.androidaps.dashaps.data.PodCommandUIType;
6 | import com.androidaps.dashaps.ui.fragments.OverviewFragment;
7 | import com.androidaps.dashaps.ui.fragments.treatment.MainTreatmentFragment;
8 | import com.androidaps.dashaps.ui.util.DashUIUtil;
9 |
10 | import org.joda.time.Duration;
11 |
12 | import java.util.Date;
13 | import java.util.GregorianCalendar;
14 |
15 | import info.nightscout.androidaps.data.DetailedBolusInfo;
16 | import info.nightscout.androidaps.data.PumpEnactResult;
17 | import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
18 | import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
19 |
20 | public class SetBolusUiCommand extends PodCommandQueueUi {
21 |
22 | private double amount;
23 | PumpEnactResult response;
24 | private boolean cancelled = false;
25 | double delivered;
26 | long started = 0;
27 |
28 | public SetBolusUiCommand(double amount) {
29 | this.amount = amount;
30 | }
31 |
32 |
33 | @Override
34 | public PodCommandUIType getCommandType() {
35 | return PodCommandUIType.SetBolus;
36 | }
37 |
38 | @Override
39 | public void executeCommand() {
40 |
41 | OmnipodPumpStatus pumpStatus = MainApp.getPumpStatus();
42 |
43 | Duration duration = DashUIUtil.calculateBolusDuration(amount);
44 |
45 | pumpStatus.lastBolusTime = new Date();
46 | pumpStatus.lastBolusAmount = amount;
47 | pumpStatus.lastBolusEstimatedEndTime = DateTimeUtil.getTimeInFutureFromSeconds((int) duration.getStandardSeconds());
48 |
49 | started = System.currentTimeMillis();
50 |
51 | DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
52 | detailedBolusInfo.insulin = amount;
53 | detailedBolusInfo.isSMB = false;
54 | detailedBolusInfo.date = started;
55 |
56 | response = MainApp.getOmnipodDashCommunicationManager().setBolus(detailedBolusInfo);
57 |
58 |
59 | if (response.success) {
60 | expireAt = DateTimeUtil.getTimeInFutureFromSeconds((int) duration.getStandardSeconds());
61 | } else {
62 | expireAt = DateTimeUtil.getTimeInFutureFromSeconds(30);
63 | }
64 |
65 | MainApp.instance().addCommandToQueue(this);
66 | }
67 |
68 |
69 | @Override
70 | public void setCancelled() {
71 | this.cancelled = true;
72 |
73 | long diff = System.currentTimeMillis() - started;
74 |
75 | diff /= 1000;
76 |
77 | this.delivered = DashUIUtil.getAmountFromDeliveryTime((int) diff);
78 | expireAt = DateTimeUtil.getTimeInFutureFromSeconds(10);
79 | }
80 |
81 |
82 | @Override
83 | public void updateUi(OverviewFragment overviewFragment) {
84 | if (cancelled)
85 | overviewFragment.setBolus(MainApp.gs(R.string.bolus_cancelled, String.format("%.1f", delivered)));
86 | else if (response.success)
87 | overviewFragment.setBolus(MainApp.gs(R.string.bolus_delivering, String.format("%.1f", amount)));
88 | else
89 | overviewFragment.setBolus("Error setting Bolus: " + response.comment);
90 | }
91 |
92 | @Override
93 | public void updateUi(MainTreatmentFragment treatmentFragment) {
94 | if (cancelled)
95 | treatmentFragment.setBolus(UiStatusType.AllDisabled);
96 | else if (response.success)
97 | treatmentFragment.setBolus(UiStatusType.CancelEnabled);
98 | else
99 | treatmentFragment.setBolus(UiStatusType.AllDisabled);
100 | }
101 |
102 | @Override
103 | public void updateUiOnFinalize(OverviewFragment overviewFragment) {
104 | if (cancelled)
105 | overviewFragment.setBolus(MainApp.gs(R.string.bolus_cancelled, String.format("%.1f", delivered)));
106 | else if (response.success)
107 | overviewFragment.setBolus(String.format("Delivered %.1f U (at %s)", amount, DateTimeUtil.toString(new GregorianCalendar())));
108 | else
109 | overviewFragment.setBolus("Error setting Bolus: " + response.comment);
110 | }
111 |
112 | @Override
113 | public void updateUiOnFinalize(MainTreatmentFragment treatmentFragment) {
114 | treatmentFragment.setBolus(UiStatusType.StartEnabled);
115 | }
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_treatment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
20 |
21 |
28 |
29 |
36 |
37 |
45 |
46 |
56 |
57 |
66 |
67 |
68 |
69 |
78 |
79 |
86 |
87 |
95 |
96 |
97 |
107 |
108 |
115 |
116 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.plugins.pump.omnipod_dash.comm;
2 |
3 | import android.content.Context;
4 |
5 | import com.androidaps.dashaps.MainApp;
6 |
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import info.nightscout.androidaps.data.DetailedBolusInfo;
11 | import info.nightscout.androidaps.data.Profile;
12 | import info.nightscout.androidaps.data.PumpEnactResult;
13 | import info.nightscout.androidaps.logging.L;
14 | import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
15 | import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
16 | import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
17 | import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
18 | import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
19 | import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
20 | import info.nightscout.androidaps.utils.SP;
21 |
22 | /**
23 | * Created by andy on 4.8.2019
24 | */
25 | public class OmnipodDashCommunicationManager implements OmnipodCommunicationManagerInterface {
26 |
27 | private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
28 |
29 | private static OmnipodDashCommunicationManager omnipodCommunicationManager;
30 | private String errorMessage;
31 | private OmnipodPumpStatus pumpStatus;
32 | private PumpEnactResult OK_RESPONSE = new PumpEnactResult().success(true);
33 | //PodCommManager podCommManager = null;
34 |
35 | public OmnipodDashCommunicationManager(Context context) {
36 | omnipodCommunicationManager = this;
37 | MainApp.getPumpStatus().previousConnection = SP.getLong(
38 | RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
39 |
40 | //AppCommManager appCommManager = AppCommManager.getInstance();
41 |
42 | //this.podCommManager = PodCommManager.getInstance(context);
43 | }
44 |
45 |
46 | // private PodSessionState getPodSessionState() {
47 | // LOG.debug("getPodSessionState not implemented.");
48 | // return null;
49 | // }
50 |
51 |
52 | public static OmnipodDashCommunicationManager getInstance() {
53 | return omnipodCommunicationManager;
54 | }
55 |
56 |
57 | public String getErrorResponse() {
58 | return this.errorMessage;
59 | }
60 |
61 |
62 | private boolean isLogEnabled() {
63 | return L.isEnabled(L.PUMPCOMM);
64 | }
65 |
66 |
67 | @Override
68 | public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) {
69 | LOG.debug("getPodSessionState not implemented.");
70 | return OK_RESPONSE;
71 | }
72 |
73 | public PumpEnactResult getPodStatus() {
74 | LOG.debug("getPodStatus not implemented.");
75 | return OK_RESPONSE;
76 | }
77 |
78 |
79 | public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
80 | LOG.debug("deactivatePod not implemented.");
81 | return OK_RESPONSE;
82 | }
83 |
84 | public PumpEnactResult setBasalProfile(Profile profile) {
85 | LOG.debug("setBasalProfile not implemented.");
86 | return OK_RESPONSE;
87 | }
88 |
89 | public PumpEnactResult resetPodStatus() {
90 | LOG.debug("resetPodStatus not implemented.");
91 | return OK_RESPONSE;
92 | }
93 |
94 | @Override
95 | public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) {
96 | LOG.debug("setBolus not implemented.");
97 | return OK_RESPONSE;
98 | }
99 |
100 | public PumpEnactResult cancelBolus() {
101 | LOG.debug("cancelBolus not implemented.");
102 | return OK_RESPONSE;
103 | }
104 |
105 | public PumpEnactResult setTemporaryBasal(TempBasalPair tbr) {
106 | LOG.debug("setTemporaryBasal not implemented.");
107 | return OK_RESPONSE;
108 | }
109 |
110 | public PumpEnactResult cancelTemporaryBasal() {
111 | LOG.debug("cancelTemporaryBasal not implemented.");
112 | return OK_RESPONSE;
113 | }
114 |
115 | @Override
116 | public PumpEnactResult acknowledgeAlerts() {
117 | LOG.debug("acknowledgeAlerts not implemented.");
118 | return OK_RESPONSE;
119 | }
120 |
121 | @Override
122 | public PumpEnactResult setTime() {
123 | LOG.debug("setTime not implemented.");
124 | return OK_RESPONSE;
125 | }
126 |
127 | @Override
128 | public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
129 | this.pumpStatus = pumpStatus;
130 | }
131 |
132 | // @Override
133 | // public PodInfoRecentPulseLog readPulseLog() {
134 | // return null;
135 | // }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/logging/L.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.logging;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import info.nightscout.androidaps.utils.SP;
7 |
8 | public class L {
9 |
10 | public static class LogElement {
11 | public String name;
12 | boolean defaultValue;
13 | public boolean enabled;
14 | boolean requiresRestart = false;
15 |
16 | LogElement(String name, boolean defaultValue) {
17 | this.name = name;
18 | this.defaultValue = defaultValue;
19 | enabled = SP.getBoolean(getSPName(), defaultValue);
20 | }
21 |
22 | LogElement(String name, boolean defaultValue, boolean requiresRestart) {
23 | this.name = name;
24 | this.defaultValue = defaultValue;
25 | this.requiresRestart = requiresRestart;
26 | enabled = SP.getBoolean(getSPName(), defaultValue);
27 | }
28 |
29 | LogElement(boolean defaultValue) {
30 | this.name = "NONEXISTING";
31 | this.defaultValue = defaultValue;
32 | enabled = defaultValue;
33 | }
34 |
35 | private String getSPName() {
36 | return "log_" + name;
37 | }
38 |
39 | public void setEnabled(boolean enabled) {
40 | this.enabled = enabled;
41 | SP.putBoolean(getSPName(), enabled);
42 | }
43 |
44 | void resetToDefault() {
45 | setEnabled(defaultValue);
46 | }
47 | }
48 |
49 | private static List logElements;
50 |
51 | static {
52 | initialize();
53 | }
54 |
55 | private static LogElement findByName(String name) {
56 | for (LogElement element : logElements) {
57 | if (element.name.equals(name))
58 | return element;
59 | }
60 | return new LogElement(false);
61 | }
62 |
63 | public static boolean isEnabled(String name) {
64 | return findByName(name).enabled;
65 | }
66 |
67 | public static List getLogElements() {
68 | return logElements;
69 | }
70 |
71 | public static void resetToDefaults() {
72 | for (LogElement element : logElements) {
73 | element.resetToDefault();
74 | }
75 | }
76 |
77 |
78 | public static final String CORE = "CORE";
79 | public static final String AUTOSENS = "AUTOSENS";
80 | public static final String EVENTS = "EVENTS";
81 | public static final String GLUCOSE = "GLUCOSE";
82 | public static final String BGSOURCE = "BGSOURCE";
83 | public static final String OVERVIEW = "OVERVIEW";
84 | public static final String NOTIFICATION = "NOTIFICATION";
85 | public static final String DATASERVICE = "DATASERVICE";
86 | public static final String DATABASE = "DATABASE";
87 | public static final String DATAFOOD = "DATAFOOD";
88 | public static final String DATATREATMENTS = "DATATREATMENTS";
89 | public static final String NSCLIENT = "NSCLIENT";
90 | public static final String CONSTRAINTS = "CONSTRAINTS";
91 | public static final String PUMP = "PUMP";
92 | public static final String PUMPQUEUE = "PUMPQUEUE";
93 | public static final String PUMPCOMM = "PUMPCOMM";
94 | public static final String PUMPBTCOMM = "PUMPBTCOMM";
95 | public static final String APS = "APS";
96 | public static final String PROFILE = "PROFILE";
97 | public static final String CONFIGBUILDER = "CONFIGBUILDER";
98 | public static final String UI = "UI";
99 | public static final String SMS = "SMS";
100 |
101 | private static void initialize() {
102 | logElements = new ArrayList<>();
103 | logElements.add(new LogElement(APS, true));
104 | logElements.add(new LogElement(AUTOSENS, false));
105 | logElements.add(new LogElement(BGSOURCE, true));
106 | logElements.add(new LogElement(GLUCOSE, false));
107 | logElements.add(new LogElement(CONFIGBUILDER, false));
108 | logElements.add(new LogElement(CONSTRAINTS, true));
109 | logElements.add(new LogElement(CORE, true));
110 | logElements.add(new LogElement(DATABASE, true));
111 | logElements.add(new LogElement(DATAFOOD, false));
112 | logElements.add(new LogElement(DATASERVICE, true));
113 | logElements.add(new LogElement(DATATREATMENTS, true));
114 | logElements.add(new LogElement(EVENTS, false, true));
115 | logElements.add(new LogElement(NOTIFICATION, true));
116 | logElements.add(new LogElement(NSCLIENT, true));
117 | logElements.add(new LogElement(OVERVIEW, true));
118 | logElements.add(new LogElement(PROFILE, true));
119 | logElements.add(new LogElement(PUMP, true));
120 | logElements.add(new LogElement(PUMPBTCOMM, false));
121 | logElements.add(new LogElement(PUMPCOMM, true));
122 | logElements.add(new LogElement(PUMPQUEUE, true));
123 | logElements.add(new LogElement(SMS, true));
124 | logElements.add(new LogElement(UI, true));
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/data/Pod.java:
--------------------------------------------------------------------------------
1 | //
2 | // Decompiled by Procyon v0.5.34
3 | //
4 |
5 | package com.androidaps.dashaps.data;
6 |
7 |
8 | import com.androidaps.dashaps.enums.PodState;
9 | import com.google.gson.annotations.Expose;
10 |
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
14 | import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
15 |
16 |
17 | public class Pod {
18 |
19 | private static final String TAG = "Pod";
20 |
21 | //private int activationState;
22 | @Expose
23 | private String address;
24 | @Expose
25 | private long lotNumber;
26 | @Expose
27 | private String bleVersion;
28 | @Expose
29 | private String podVersion;
30 | @Expose
31 | private Long activationTime;
32 | @Expose
33 | private int podState;
34 |
35 | private Long podExpire;
36 |
37 | private Long podWarning;
38 |
39 | // FIXME Pod will be used instead of OmnipodPumpStatus for now
40 |
41 | public Pod() {
42 |
43 | }
44 |
45 | public void checkPodExpiry() {
46 | if (getPodStateObject() == PodState.Active) {
47 | //Long activationTime = this.pod.getActivationTime();
48 |
49 | Long expireTime = DateTimeUtil.getTimeInFutureFromMinutes(activationTime, 3 * 24 * 60);
50 |
51 | if (System.currentTimeMillis() > expireTime) {
52 | setPodState(PodState.Deactivated);
53 | } else {
54 | this.podExpire = expireTime;
55 | this.podWarning = expireTime - (8 * 24 * 60 * 60 * 1000);
56 | }
57 | }
58 | }
59 |
60 |
61 | public boolean checkTimeIsWithinPodLifetime(final Long n) {
62 |
63 | return n == null || n <= 0L || this.getActivationTime() == null || (this.getActivationTime() <= n && n <= this.getActivationTime() + TimeUnit.HOURS.toMillis(80L));
64 | }
65 |
66 |
67 | public Long getActivationTime() {
68 |
69 | return this.activationTime;
70 | }
71 |
72 |
73 | public String getAddress() {
74 |
75 | return this.address;
76 | }
77 |
78 |
79 | public long getLotNumber() {
80 |
81 | return this.lotNumber;
82 | }
83 |
84 |
85 | public void setActivationTime(final Long activationTime) {
86 |
87 | this.activationTime = activationTime;
88 | }
89 |
90 |
91 | public void setAddress(final String address) {
92 |
93 | this.address = address;
94 | }
95 |
96 |
97 | public void setLotNumber(final long lotNumber) {
98 |
99 | this.lotNumber = lotNumber;
100 | }
101 |
102 |
103 | public void setPodState(final int podState) {
104 |
105 | this.podState = podState;
106 | }
107 |
108 |
109 | public void setPodState(final PodState podState) {
110 |
111 | this.podState = podState.getValue();
112 | }
113 |
114 |
115 | public void resetAddress() {
116 |
117 | this.setAddress(null);
118 | }
119 |
120 | // public void setActivationState(final PodCommManager.ActivationStatus a) {
121 | //
122 | // this.setActivationState(a.getValue());
123 | // }
124 |
125 | public PodState getPodStateObject() {
126 | return PodState.getByValue(this.podState);
127 | }
128 |
129 |
130 | // public void setPulsesRemaining(final Short n) {
131 | //
132 | // this.setPulsesRemaining(n);
133 | // }
134 |
135 |
136 | // public void setState(final PodStatusType g) {
137 | //
138 | // this.setPodState(g.name());
139 | // }
140 |
141 |
142 | @Override
143 | public String toString() {
144 | final StringBuilder sb = new StringBuilder("Pod{");
145 | sb.append("activationTime=").append(activationTime);
146 | sb.append(", address='").append(address).append('\'');
147 | sb.append(", bleVersion='").append(bleVersion).append('\'');
148 | sb.append(", lotNumber=").append(lotNumber);
149 | sb.append(", podVersion='").append(podVersion).append('\'');
150 | sb.append(", podState=").append(podState);
151 | sb.append('}');
152 | return sb.toString();
153 | }
154 |
155 | public void setBleVersion(String bleVersion) {
156 | this.bleVersion = bleVersion;
157 | }
158 |
159 | public String getBleVersion() {
160 | return this.bleVersion;
161 | }
162 |
163 | public void setPodVersion(String podVersion) {
164 | this.podVersion = podVersion;
165 | }
166 |
167 | public String getPodVersion() {
168 | return this.podVersion;
169 | }
170 |
171 |
172 | public void update(OmnipodPumpStatus pumpStatus, PodUpdateType podUpdateType) {
173 |
174 | }
175 |
176 |
177 | public long getPodExpire() {
178 | return podExpire;
179 | }
180 |
181 | public void setPodExpire(long podExpire) {
182 | this.podExpire = podExpire;
183 | }
184 |
185 | public long getPodWarning() {
186 | return podWarning;
187 | }
188 |
189 | public void setPodWarning(long podWarning) {
190 | this.podWarning = podWarning;
191 | }
192 |
193 | public boolean isExpired() {
194 | if (podExpire != null) {
195 | if (System.currentTimeMillis() > podExpire) {
196 | setPodState(PodState.Deactivated);
197 | podExpire = null;
198 | return true;
199 | } else
200 | return false;
201 | } else
202 | return true;
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.interfaces;
2 |
3 | import info.nightscout.androidaps.plugins.pump.common.defs.PumpCapability;
4 | import info.nightscout.androidaps.plugins.pump.common.defs.PumpTempBasalType;
5 | import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
6 |
7 | /**
8 | * Created by mike on 08.12.2016.
9 | */
10 |
11 | public class PumpDescription {
12 | public PumpType pumpType = PumpType.GenericAAPS;
13 |
14 | public PumpDescription() {
15 | resetSettings();
16 | }
17 |
18 | public static final int NONE = 0;
19 | public static final int PERCENT = 0x01;
20 | public static final int ABSOLUTE = 0x02;
21 |
22 | public boolean isBolusCapable;
23 | public double bolusStep;
24 |
25 | public boolean isExtendedBolusCapable;
26 | public double extendedBolusStep;
27 | public double extendedBolusDurationStep;
28 | public double extendedBolusMaxDuration;
29 |
30 | public boolean isTempBasalCapable;
31 | public int tempBasalStyle;
32 |
33 | public int maxTempPercent;
34 | public int tempPercentStep;
35 |
36 | public double maxTempAbsolute;
37 | public double tempAbsoluteStep;
38 |
39 | public int tempDurationStep;
40 | public boolean tempDurationStep15mAllowed;
41 | public boolean tempDurationStep30mAllowed;
42 | public int tempMaxDuration;
43 |
44 | public boolean isSetBasalProfileCapable;
45 | public double basalStep;
46 | public double basalMinimumRate;
47 | public double basalMaximumRate;
48 |
49 | public boolean isRefillingCapable;
50 |
51 | public boolean storesCarbInfo;
52 |
53 | public boolean is30minBasalRatesCapable;
54 |
55 | public boolean supportsTDDs;
56 | public boolean needsManualTDDLoad;
57 |
58 | public boolean hasFixedUnreachableAlert;
59 |
60 | public void resetSettings() {
61 | isBolusCapable = true;
62 | bolusStep = 0.1d;
63 |
64 | isExtendedBolusCapable = true;
65 | extendedBolusStep = 0.1d;
66 | extendedBolusDurationStep = 30;
67 | extendedBolusMaxDuration = 12 * 60;
68 |
69 | isTempBasalCapable = true;
70 | tempBasalStyle = PERCENT;
71 | maxTempPercent = 200;
72 | tempPercentStep = 10;
73 | maxTempAbsolute = 10;
74 | tempAbsoluteStep = 0.05d;
75 | tempDurationStep = 60;
76 | tempMaxDuration = 12 * 60;
77 | tempDurationStep15mAllowed = false;
78 | tempDurationStep30mAllowed = false;
79 |
80 | isSetBasalProfileCapable = true;
81 | basalStep = 0.01d;
82 | basalMinimumRate = 0.04d;
83 | basalMaximumRate = 25d;
84 | is30minBasalRatesCapable = false;
85 |
86 | isRefillingCapable = false;
87 | storesCarbInfo = true;
88 |
89 | supportsTDDs = false;
90 | needsManualTDDLoad = true;
91 |
92 | hasFixedUnreachableAlert = false;
93 | }
94 |
95 | public void setPumpDescription(PumpType pumpType) {
96 | resetSettings();
97 | this.pumpType = pumpType;
98 |
99 | PumpCapability pumpCapability = pumpType.getPumpCapability();
100 |
101 | isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);
102 | bolusStep = pumpType.getBolusSize();
103 |
104 | isExtendedBolusCapable = pumpCapability.hasCapability(PumpCapability.ExtendedBolus);
105 | extendedBolusStep = pumpType.getExtendedBolusSettings().getStep();
106 | extendedBolusDurationStep = pumpType.getExtendedBolusSettings().getDurationStep();
107 | extendedBolusMaxDuration = pumpType.getExtendedBolusSettings().getMaxDuration();
108 |
109 | isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TempBasal);
110 |
111 | if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
112 | tempBasalStyle = PERCENT;
113 | maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
114 | tempPercentStep = (int) pumpType.getTbrSettings().getStep();
115 | } else {
116 | tempBasalStyle = ABSOLUTE;
117 | maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
118 | tempAbsoluteStep = pumpType.getTbrSettings().getStep();
119 | }
120 |
121 | tempDurationStep = pumpType.getTbrSettings().getDurationStep();
122 | tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
123 |
124 | tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations()
125 | .hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
126 | tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations()
127 | .hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
128 |
129 | isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
130 | basalStep = pumpType.getBaseBasalStep();
131 | basalMinimumRate = pumpType.getBaseBasalMinValue();
132 |
133 | isRefillingCapable = pumpCapability.hasCapability(PumpCapability.Refill);
134 | storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
135 |
136 | supportsTDDs = pumpCapability.hasCapability(PumpCapability.TDD);
137 | needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad);
138 |
139 | is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min);
140 |
141 | hasFixedUnreachableAlert = pumpType.getHasFixedUnreachableAlert();
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/DashAapsService.java:
--------------------------------------------------------------------------------
1 | package com.androidaps.dashaps;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Binder;
6 | import android.os.Handler;
7 | import android.os.IBinder;
8 | import android.os.SystemClock;
9 | import android.util.Log;
10 |
11 | import com.androidaps.dashaps.data.Pod;
12 | import com.androidaps.dashaps.enums.PodState;
13 | import com.androidaps.dashaps.ui.fragments.OverviewFragment;
14 | import com.androidaps.dashaps.ui.fragments.PodFragment;
15 | import com.androidaps.dashaps.ui.fragments.treatment.MainTreatmentFragment;
16 | import com.google.gson.Gson;
17 | import com.google.gson.GsonBuilder;
18 |
19 | import org.joda.time.LocalDateTime;
20 |
21 | import java.util.Arrays;
22 |
23 | import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
24 | import info.nightscout.androidaps.utils.SP;
25 |
26 | public class DashAapsService extends Service {
27 |
28 | Binder mBinder;
29 | boolean serviceRunning;
30 | int[] time = new int[6];
31 | private String TAG = "DashAapsService";
32 | //Gson gson = new Gson();
33 |
34 | public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
35 | .setPrettyPrinting().create();
36 |
37 | public static Pod pod;
38 | //public static PodStateDto podStateDto;
39 |
40 | static DashAapsService instance = new DashAapsService();
41 |
42 | private long nextQueueUpdate = 0L;
43 | private Long podExpire = null;
44 | private Long podWarning = null;
45 |
46 | public DashAapsService() {
47 | }
48 |
49 | public static DashAapsService getInstance() {
50 | return instance;
51 | }
52 |
53 |
54 | private void doProcess() {
55 |
56 | checkTime();
57 |
58 |
59 | }
60 |
61 | private void checkIfPodExpired() {
62 |
63 | if (pod != null && pod.getPodStateObject() == PodState.Active) {
64 |
65 | if (pod.isExpired()) {
66 | OverviewFragment.getInstance().setPod(pod);
67 | PodFragment.getInstance().setPod(pod);
68 | MainTreatmentFragment.getInstance().setPod(pod);
69 | }
70 | }
71 | }
72 |
73 |
74 | private void checkTime() {
75 |
76 | LocalDateTime ldt = new LocalDateTime();
77 |
78 | //Log.d(TAG, "Check Time: Test");
79 |
80 | int[] timeNew = new int[6];
81 | timeNew[0] = ldt.getDayOfMonth();
82 | timeNew[1] = ldt.getMonthOfYear();
83 | timeNew[2] = ldt.getYear();
84 |
85 | timeNew[3] = ldt.getHourOfDay();
86 | timeNew[4] = ldt.getMinuteOfHour();
87 | timeNew[5] = ldt.getSecondOfMinute();
88 |
89 | if (!Arrays.equals(time, timeNew)) {
90 | if (OverviewFragment.getInstance() == null)
91 | return;
92 |
93 | OverviewFragment.getInstance().setTime(timeNew);
94 |
95 | if (time[4] != timeNew[4]) {
96 | // do minute changes actions
97 | OverviewFragment.getInstance().setLocalDateTime(ldt);
98 |
99 | if (PodFragment.getInstance() != null)
100 | PodFragment.getInstance().setLocalDateTime(ldt);
101 | }
102 |
103 | time = timeNew;
104 | }
105 | }
106 |
107 | @Override
108 | public IBinder onBind(Intent intent) {
109 | return null;
110 | }
111 |
112 |
113 | private Handler handler;
114 | private Runnable runnable;
115 | private final int runTime = 5000;
116 |
117 | DashAPSUiQueue queue = null;
118 |
119 | @Override
120 | public void onCreate() {
121 | super.onCreate();
122 | Log.i(TAG, "onCreate");
123 |
124 | this.serviceRunning = true;
125 |
126 | loadData();
127 |
128 | queue = MainApp.getQueue();
129 |
130 | new Thread(() -> {
131 |
132 | do {
133 | SystemClock.sleep(500);
134 | //Log.d(TAG, "Thread");
135 |
136 | doProcess();
137 |
138 | //Log.i(TAG, "processLoop");
139 |
140 | doQueueProcess();
141 |
142 | } while (serviceRunning);
143 |
144 | }).start();
145 |
146 | }
147 |
148 | private boolean locked = false;
149 |
150 | private void doQueueProcess() {
151 | if (System.currentTimeMillis() > nextQueueUpdate && !locked) {
152 | //Log.d(TAG, "Queue Update");
153 | locked = true;
154 | queue.processQueue();
155 | this.nextQueueUpdate = DateTimeUtil.getTimeInFutureFromSeconds(15);
156 | locked = false;
157 |
158 | checkIfPodExpired();
159 | }
160 | }
161 |
162 |
163 | @Override
164 | public void onDestroy() {
165 |
166 | super.onDestroy();
167 | serviceRunning = false;
168 |
169 | //saveData();
170 | }
171 |
172 |
173 | private void loadData() {
174 |
175 | Log.d(TAG, "loadData");
176 |
177 | String data = SP.getString("Pod", null);
178 |
179 | if (data != null) {
180 | Log.d(TAG, "loadData - Pod");
181 | Pod pod = gsonInstancePretty.fromJson(data, Pod.class);
182 | this.pod = pod;
183 |
184 | this.pod.checkPodExpiry();
185 | }
186 |
187 | //if (pod!=null)
188 | // SP.putString("Pod", gsonInstancePretty.toJson(pod));
189 | //
190 | // if (podStateDto!=null)
191 | // SP.putString("PodState", gsonInstancePretty.toJson(podStateDto));
192 |
193 | }
194 |
195 |
196 | public void saveData() {
197 | Log.d(TAG, "saveData");
198 |
199 | if (pod != null) {
200 | SP.putString("Pod", gsonInstancePretty.toJson(pod));
201 | Log.d(TAG, "saveData - Pod");
202 | } else {
203 | SP.remove("Pod");
204 | }
205 |
206 |
207 | //
208 | // if (podStateDto!=null)
209 | // SP.putString("PodState", gsonInstancePretty.toJson(podStateDto));
210 |
211 | }
212 |
213 |
214 | @Override
215 | public int onStartCommand(Intent intent, int flags, int startId) {
216 | return START_STICKY;
217 | }
218 |
219 | @SuppressWarnings("deprecation")
220 | @Override
221 | public void onStart(Intent intent, int startId) {
222 | super.onStart(intent, startId);
223 | Log.i(TAG, "onStart");
224 | }
225 |
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/CRC.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.plugins.pump.common.utils;
2 |
3 | /**
4 | * Created by geoff on 4/27/15.
5 | */
6 | public class CRC {
7 |
8 | static final int[] crc8lookup = new int[] {
9 | 0, 155, 173, 54, 193, 90, 108, 247, 25,
10 | 130,
11 | 180,
12 | 47,
13 | 216,
14 | 67,
15 | 117,
16 | 238,
17 | 50,
18 | 169, //
19 | 159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201,
20 | 82,
21 | 165,
22 | 62,
23 | 8,
24 | 147,
25 | 125,
26 | 230,
27 | 208,
28 | 75, //
29 | 188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21,
30 | 35,
31 | 184,
32 | 200,
33 | 83,
34 | 101,
35 | 254,
36 | 9,
37 | 146, //
38 | 164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227,
39 | 120,
40 | 78,
41 | 213,
42 | 34,
43 | 185,
44 | 143,
45 | 20, //
46 | 172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95,
47 | 196,
48 | 242,
49 | 105,
50 | 135,
51 | 28,
52 | 42, //
53 | 177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229,
54 | 57,
55 | 162,
56 | 148,
57 | 15,
58 | 248, //
59 | 99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64,
60 | 183,
61 | 44,
62 | 26,
63 | 129, //
64 | 93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52,
65 | 218,
66 | 65,
67 | 119, //
68 | 236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10,
69 | 145, 102,
70 | 253, //
71 | 203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214,
72 | 224, 123 };
73 |
74 | static final int[] crc16lookup = new int[] {
75 | 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011, 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d,
76 | 0x8027, 0x0022, 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072, 0x0050, 0x8055, 0x805f, 0x005a,
77 | 0x804b, 0x004e, 0x0044, 0x8041, 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2, 0x00f0, 0x80f5,
78 | 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1, 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
79 | 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082, 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d,
80 | 0x8197, 0x0192, 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1, 0x01e0, 0x81e5, 0x81ef, 0x01ea,
81 | 0x81fb, 0x01fe, 0x01f4, 0x81f1, 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2, 0x0140, 0x8145,
82 | 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151, 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
83 | 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132, 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e,
84 | 0x0104, 0x8101, 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312, 0x0330, 0x8335, 0x833f, 0x033a,
85 | 0x832b, 0x032e, 0x0324, 0x8321, 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371, 0x8353, 0x0356,
86 | 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342, 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
87 | 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2, 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd,
88 | 0x83b7, 0x03b2, 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381, 0x0280, 0x8285, 0x828f, 0x028a,
89 | 0x829b, 0x029e, 0x0294, 0x8291, 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2, 0x82e3, 0x02e6,
90 | 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2, 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
91 | 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252, 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e,
92 | 0x0264, 0x8261, 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231, 0x8213, 0x0216, 0x021c, 0x8219,
93 | 0x0208, 0x820d, 0x8207, 0x0202 };
94 |
95 |
96 | public static byte crc8(byte[] data, int len) {
97 | byte result = 0;
98 | if (data == null) {
99 | return 0;
100 | }
101 | if (len > data.length) {
102 | len = data.length;
103 | }
104 | for (int i = 0; i < len; i++) {
105 | int tmp = result;
106 | int tmp2 = tmp ^ data[i];
107 | int tmp3 = tmp2 & 0xFF;
108 | int idx = tmp3;
109 | result = (byte)crc8lookup[idx];
110 | // log(String.format("iter=%d,tmp=0x%02x, tmp2=0x%02x, tmp3=0x%02x, lookup=0x%02x",i,tmp,tmp2,tmp3,result));
111 | }
112 | // orig python:
113 | // result = klass.lookup[ ( result ^ block[ i ] & 0xFF ) ]
114 | return result;
115 |
116 | }
117 |
118 |
119 | public static byte crc8(byte[] data) {
120 | return crc8(data, data.length);
121 | }
122 |
123 |
124 | public static byte[] calculate16CCITT(byte[] data) {
125 | int crc = 0xFFFF;
126 | int polynomial = 0x1021;
127 | if (data != null) {
128 | if (data.length > 0) {
129 | for (int j = 0; j < data.length; j++) {
130 | byte b = data[j];
131 | for (int i = 0; i < 8; i++) {
132 | boolean bit = ((b >> (7 - i) & 1) == 1);
133 | boolean c15 = ((crc >> 15 & 1) == 1);
134 | crc <<= 1;
135 | if (c15 ^ bit)
136 | crc ^= polynomial;
137 | }
138 | }
139 | }
140 | }
141 | crc &= 0xffff;
142 | return new byte[] { (byte)((crc & 0xFF00) >> 8), (byte)(crc & 0xFF) };
143 | }
144 |
145 |
146 | public static int crc16(byte[] bytes) {
147 | int crc = 0x0000;
148 | for (byte b : bytes) {
149 | crc = (crc >>> 8) ^ crc16lookup[(crc ^ b) & 0xff];
150 | }
151 | return crc;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/utils/SP.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.utils;
2 |
3 | import android.content.SharedPreferences;
4 | import android.preference.PreferenceManager;
5 |
6 | import com.androidaps.dashaps.MainApp;
7 |
8 |
9 | /**
10 | * Created by mike on 17.02.2017.
11 | */
12 |
13 | public class SP {
14 | static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
15 |
16 | static public boolean contains(String key) {
17 | return sharedPreferences.contains(key);
18 | }
19 |
20 | static public boolean contains(int resourceId) {
21 | return sharedPreferences.contains(MainApp.gs(resourceId));
22 | }
23 |
24 | static public String getString(int resourceID, String defaultValue) {
25 | return sharedPreferences.getString(MainApp.gs(resourceID), defaultValue);
26 | }
27 |
28 | static public String getString(String key, String defaultValue) {
29 | return sharedPreferences.getString(key, defaultValue);
30 | }
31 |
32 | static public boolean getBoolean(int resourceID, Boolean defaultValue) {
33 | try {
34 | return sharedPreferences.getBoolean(MainApp.gs(resourceID), defaultValue);
35 | } catch (Exception e) {
36 | return defaultValue;
37 | }
38 | }
39 |
40 | static public boolean getBoolean(String key, Boolean defaultValue) {
41 | try {
42 | return sharedPreferences.getBoolean(key, defaultValue);
43 | } catch (Exception e) {
44 | return defaultValue;
45 | }
46 | }
47 |
48 | static public Double getDouble(int resourceID, Double defaultValue) {
49 | return SafeParse.stringToDouble(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString()));
50 | }
51 |
52 | static public Double getDouble(String key, Double defaultValue) {
53 | return SafeParse.stringToDouble(sharedPreferences.getString(key, defaultValue.toString()));
54 | }
55 |
56 | static public int getInt(int resourceID, Integer defaultValue) {
57 | try {
58 | return sharedPreferences.getInt(MainApp.gs(resourceID), defaultValue);
59 | } catch (Exception e) {
60 | return SafeParse.stringToInt(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString()));
61 | }
62 | }
63 |
64 | static public int getInt(String key, Integer defaultValue) {
65 | try {
66 | return sharedPreferences.getInt(key, defaultValue);
67 | } catch (Exception e) {
68 | return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString()));
69 | }
70 | }
71 |
72 | static public long getLong(int resourceID, Long defaultValue) {
73 | try {
74 | return sharedPreferences.getLong(MainApp.gs(resourceID), defaultValue);
75 | } catch (Exception e) {
76 | return SafeParse.stringToLong(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString()));
77 | }
78 | }
79 |
80 | static public long getLong(String key, Long defaultValue) {
81 | try {
82 | return sharedPreferences.getLong(key, defaultValue);
83 | } catch (Exception e) {
84 | return SafeParse.stringToLong(sharedPreferences.getString(key, defaultValue.toString()));
85 | }
86 | }
87 |
88 | static public void putBoolean(String key, boolean value) {
89 | SharedPreferences.Editor editor = sharedPreferences.edit();
90 | editor.putBoolean(key, value);
91 | editor.apply();
92 | }
93 |
94 | static public void putBoolean(int resourceID, boolean value) {
95 | SharedPreferences.Editor editor = sharedPreferences.edit();
96 | editor.putBoolean(MainApp.gs(resourceID), value);
97 | editor.apply();
98 | }
99 |
100 | static public void putDouble(String key, double value) {
101 | SharedPreferences.Editor editor = sharedPreferences.edit();
102 | editor.putString(key, Double.toString(value));
103 | editor.apply();
104 | }
105 |
106 | static public void putDouble(int resourceID, double value) {
107 | SharedPreferences.Editor editor = sharedPreferences.edit();
108 | editor.putString(MainApp.gs(resourceID), Double.toString(value));
109 | editor.apply();
110 | }
111 |
112 | static public void putLong(String key, long value) {
113 | SharedPreferences.Editor editor = sharedPreferences.edit();
114 | editor.putLong(key, value);
115 | editor.apply();
116 | }
117 |
118 | static public void putLong(int resourceID, long value) {
119 | SharedPreferences.Editor editor = sharedPreferences.edit();
120 | editor.putLong(MainApp.gs(resourceID), value);
121 | editor.apply();
122 | }
123 |
124 | static public void putInt(String key, int value) {
125 | SharedPreferences.Editor editor = sharedPreferences.edit();
126 | editor.putInt(key, value);
127 | editor.apply();
128 | }
129 |
130 | static public void putInt(int resourceID, int value) {
131 | SharedPreferences.Editor editor = sharedPreferences.edit();
132 | editor.putInt(MainApp.gs(resourceID), value);
133 | editor.apply();
134 | }
135 |
136 |
137 | static public void putDouble(int resourceID, Double value) {
138 | SharedPreferences.Editor editor = sharedPreferences.edit();
139 | editor.putString(MainApp.gs(resourceID), value.toString());
140 | editor.apply();
141 | }
142 |
143 | static public void putDouble(String key, Double value) {
144 | SharedPreferences.Editor editor = sharedPreferences.edit();
145 | editor.putString(key, value.toString());
146 | editor.apply();
147 | }
148 |
149 | static public void putString(int resourceID, String value) {
150 | SharedPreferences.Editor editor = sharedPreferences.edit();
151 | editor.putString(MainApp.gs(resourceID), value);
152 | editor.apply();
153 | }
154 |
155 | static public void putString(String key, String value) {
156 | SharedPreferences.Editor editor = sharedPreferences.edit();
157 | editor.putString(key, value);
158 | editor.apply();
159 | }
160 |
161 | static public void remove(int resourceID) {
162 | SharedPreferences.Editor editor = sharedPreferences.edit();
163 | editor.remove(MainApp.gs(resourceID));
164 | editor.apply();
165 | }
166 |
167 | static public void remove(String key) {
168 | SharedPreferences.Editor editor = sharedPreferences.edit();
169 | editor.remove(key);
170 | editor.apply();
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java:
--------------------------------------------------------------------------------
1 | package info.nightscout.androidaps.utils;
2 |
3 | import android.os.Bundle;
4 |
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import info.nightscout.androidaps.logging.L;
9 |
10 | /**
11 | * Created by jamorham on 21/02/2018.
12 | *
13 | * Some users do not wish to be tracked, Fabric Answers and Crashlytics do not provide an easy way
14 | * to disable them and make calls from a potentially invalid singleton reference. This wrapper
15 | * emulates the methods but ignores the request if the instance is null or invalid.
16 | */
17 |
18 | public class FabricPrivacy {
19 | private static Logger log = LoggerFactory.getLogger(L.CORE);
20 |
21 | private static volatile FabricPrivacy instance;
22 |
23 |
24 | public static FabricPrivacy getInstance() {
25 | if (instance == null) {
26 | initSelf();
27 | }
28 | return instance;
29 | }
30 |
31 | private static synchronized void initSelf() {
32 | if (instance == null) {
33 | instance = new FabricPrivacy();
34 | }
35 | }
36 |
37 | // Crashlytics logException
38 | public static void logException(Throwable throwable) {
39 | if (L.isEnabled(L.CORE))
40 | log.debug("Ignoring opted out non-initialized log: " + throwable);
41 | // try {
42 | // final Crashlytics crashlytics = Crashlytics.getInstance();
43 | // crashlytics.core.logException(throwable);
44 | // } catch (NullPointerException | IllegalStateException e) {
45 | // if (L.isEnabled(L.CORE))
46 | // log.debug("Ignoring opted out non-initialized log: " + throwable);
47 | // }
48 | }
49 |
50 | // Crashlytics log
51 | public static void log(String msg) {
52 | if (L.isEnabled(L.CORE))
53 | log.debug("Ignoring opted out non-initialized log: " + msg);
54 | // try {
55 | // final Crashlytics crashlytics = Crashlytics.getInstance();
56 | // crashlytics.core.log(msg);
57 | // } catch (NullPointerException | IllegalStateException e) {
58 | // if (L.isEnabled(L.CORE))
59 | // log.debug("Ignoring opted out non-initialized log: " + msg);
60 | // }
61 | }
62 |
63 | // Crashlytics log
64 | public static void log(int priority, String tag, String msg) {
65 | if (L.isEnabled(L.CORE))
66 | log.debug("Ignoring opted out non-initialized log: " + msg);
67 | // try {
68 | // final Crashlytics crashlytics = Crashlytics.getInstance();
69 | // crashlytics.core.log(priority, tag, msg);
70 | // } catch (NullPointerException | IllegalStateException e) {
71 | // if (L.isEnabled(L.CORE))
72 | // log.debug("Ignoring opted out non-initialized log: " + msg);
73 | // }
74 | }
75 |
76 | public static boolean fabricEnabled() {
77 | return false; //SP.getBoolean("enable_fabric", true);
78 | }
79 |
80 | // Analytics logCustom
81 | public void logCustom(Bundle event) {
82 | try {
83 | if (fabricEnabled()) {
84 | //MainApp.getFirebaseAnalytics().logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, event);
85 | } else {
86 | if (L.isEnabled(L.CORE))
87 | log.debug("Ignoring recently opted-out event: " + event.toString());
88 | }
89 | } catch (NullPointerException | IllegalStateException e) {
90 | if (L.isEnabled(L.CORE))
91 | log.debug("Ignoring opted-out non-initialized event: " + event.toString());
92 | }
93 | }
94 |
95 | // Analytics logCustom
96 | public void logCustom(String event) {
97 | try {
98 | if (fabricEnabled()) {
99 | //MainApp.getFirebaseAnalytics().logEvent(event, new Bundle());
100 | } else {
101 | if (L.isEnabled(L.CORE))
102 | log.debug("Ignoring recently opted-out event: " + event);
103 | }
104 | } catch (NullPointerException | IllegalStateException e) {
105 | if (L.isEnabled(L.CORE))
106 | log.debug("Ignoring opted-out non-initialized event: " + event);
107 | }
108 | }
109 |
110 | public static void setUserStats() {
111 | if (!fabricEnabled()) return;
112 |
113 | // String closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed().value() ? "CLOSED_LOOP_ENABLED" : "CLOSED_LOOP_DISABLED";
114 | // // Size is limited to 36 chars
115 | // String remote = BuildConfig.REMOTE.toLowerCase()
116 | // .replace("https://", "")
117 | // .replace("http://", "")
118 | // .replace(".git", "")
119 | // .replace(".com/", ":")
120 | // .replace(".org/", ":")
121 | // .replace(".net/", ":");
122 | //
123 | // MainApp.getFirebaseAnalytics().setUserProperty("Mode", BuildConfig.APPLICATION_ID + "-" + closedLoopEnabled);
124 | // MainApp.getFirebaseAnalytics().setUserProperty("Language", LocaleHelper.INSTANCE.currentLanguage());
125 | // MainApp.getFirebaseAnalytics().setUserProperty("Version", BuildConfig.VERSION);
126 | // MainApp.getFirebaseAnalytics().setUserProperty("HEAD", BuildConfig.HEAD);
127 | // MainApp.getFirebaseAnalytics().setUserProperty("Remote", remote);
128 | // List hashes = SignatureVerifierPlugin.getPlugin().shortHashes();
129 | // if (hashes.size() >= 1)
130 | // MainApp.getFirebaseAnalytics().setUserProperty("Hash", hashes.get(0));
131 | //
132 | // if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
133 | // MainApp.getFirebaseAnalytics().setUserProperty("Pump", ConfigBuilderPlugin.getPlugin().getActivePump().getClass().getSimpleName());
134 | // if (ConfigBuilderPlugin.getPlugin().getActiveAPS() != null)
135 | // MainApp.getFirebaseAnalytics().setUserProperty("Aps", ConfigBuilderPlugin.getPlugin().getActiveAPS().getClass().getSimpleName());
136 | // if (ConfigBuilderPlugin.getPlugin().getActiveBgSource() != null)
137 | // MainApp.getFirebaseAnalytics().setUserProperty("BgSource", ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().getSimpleName());
138 | // if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null)
139 | // MainApp.getFirebaseAnalytics().setUserProperty("Profile", ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getSimpleName());
140 | // if (ConfigBuilderPlugin.getPlugin().getActiveSensitivity() != null)
141 | // MainApp.getFirebaseAnalytics().setUserProperty("Sensitivity", ConfigBuilderPlugin.getPlugin().getActiveSensitivity().getClass().getSimpleName());
142 | // if (ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null)
143 | // MainApp.getFirebaseAnalytics().setUserProperty("Insulin", ConfigBuilderPlugin.getPlugin().getActiveInsulin().getClass().getSimpleName());
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/HexDump.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package info.nightscout.androidaps.plugins.pump.common.utils;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | * Clone of Android's HexDump class, for use in debugging. Cosmetic changes
23 | * only.
24 | */
25 | public class HexDump {
26 |
27 | private final static char[] HEX_DIGITS = {
28 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
29 |
30 |
31 | public static String dumpHexString(byte[] array) {
32 | return dumpHexString(array, 0, array.length);
33 | }
34 |
35 |
36 | public static String dumpHexString(byte[] array, int offset, int length) {
37 | StringBuilder result = new StringBuilder();
38 |
39 | byte[] line = new byte[16];
40 | int lineIndex = 0;
41 |
42 | result.append("\n0x");
43 | result.append(toHexString(offset));
44 |
45 | for (int i = offset; i < offset + length; i++) {
46 | if (lineIndex == 16) {
47 | result.append(" ");
48 |
49 | for (int j = 0; j < 16; j++) {
50 | if (line[j] > ' ' && line[j] < '~') {
51 | result.append(new String(line, j, 1));
52 | } else {
53 | result.append(".");
54 | }
55 | }
56 |
57 | result.append("\n0x");
58 | result.append(toHexString(i));
59 | lineIndex = 0;
60 | }
61 |
62 | byte b = array[i];
63 | result.append(" ");
64 | result.append(HEX_DIGITS[(b >>> 4) & 0x0F]);
65 | result.append(HEX_DIGITS[b & 0x0F]);
66 |
67 | line[lineIndex++] = b;
68 | }
69 |
70 | if (lineIndex != 16) {
71 | int count = (16 - lineIndex) * 3;
72 | count++;
73 | for (int i = 0; i < count; i++) {
74 | result.append(" ");
75 | }
76 |
77 | for (int i = 0; i < lineIndex; i++) {
78 | if (line[i] > ' ' && line[i] < '~') {
79 | result.append(new String(line, i, 1));
80 | } else {
81 | result.append(".");
82 | }
83 | }
84 | }
85 |
86 | return result.toString();
87 | }
88 |
89 |
90 | public static String toHexString(byte b) {
91 | return toHexString(toByteArray(b));
92 | }
93 |
94 |
95 | public static String toHexString(byte[] array) {
96 | return toHexString(array, 0, array.length);
97 | }
98 |
99 |
100 | public static String toHexString(byte[] array, int offset, int length) {
101 | char[] buf = new char[length * 2];
102 |
103 | int bufIndex = 0;
104 | for (int i = offset; i < offset + length; i++) {
105 | byte b = array[i];
106 | buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
107 | buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
108 | }
109 |
110 | return new String(buf);
111 | }
112 |
113 |
114 | public static String toHexStringDisplayable(byte[] arr) {
115 | StringBuilder sb = new StringBuilder();
116 |
117 | if (arr == null) {
118 | sb.append("Null array");
119 | } else {
120 |
121 | if (arr.length == 0) {
122 | sb.append("Zero-length array");
123 | } else {
124 |
125 | for (byte element : arr) {
126 | sb.append(getCorrectHexValue(element));
127 | sb.append(" ");
128 | }
129 | }
130 | }
131 |
132 | return sb.toString();
133 | }
134 |
135 |
136 | public static String toHexStringDisplayable(List data) {
137 | StringBuilder sb = new StringBuilder();
138 |
139 | for (byte element : data) {
140 | sb.append(getCorrectHexValue(element));
141 | sb.append(" ");
142 | }
143 |
144 | return sb.toString();
145 | }
146 |
147 |
148 | public static String getCorrectHexValue(byte inp) {
149 | String hx = Integer.toHexString((char)inp);
150 | hx = hx.toUpperCase();
151 |
152 | if (hx.length() == 0)
153 | return "00";
154 | else if (hx.length() == 1)
155 | return "0" + hx;
156 | else if (hx.length() == 2)
157 | return hx;
158 | else if (hx.length() == 4)
159 | return hx.substring(2);
160 | else {
161 | System.out.println("HEX ERROR !!!!!!!!!!!!!!!!");
162 | }
163 |
164 | // System.out.print(Integer.toHexString((char)arr[i]) + " ");
165 |
166 | return null;
167 | }
168 |
169 |
170 | public static String toHexString(int i) {
171 | return toHexString(toByteArray(i));
172 | }
173 |
174 |
175 | public static String toHexString(short i) {
176 | return toHexString(toByteArray(i));
177 | }
178 |
179 |
180 | public static byte[] toByteArray(byte b) {
181 | byte[] array = new byte[1];
182 | array[0] = b;
183 | return array;
184 | }
185 |
186 |
187 | public static byte[] toByteArray(int i) {
188 | byte[] array = new byte[4];
189 |
190 | array[3] = (byte)(i & 0xFF);
191 | array[2] = (byte)((i >> 8) & 0xFF);
192 | array[1] = (byte)((i >> 16) & 0xFF);
193 | array[0] = (byte)((i >> 24) & 0xFF);
194 |
195 | return array;
196 | }
197 |
198 |
199 | public static byte[] toByteArray(short i) {
200 | byte[] array = new byte[2];
201 |
202 | array[1] = (byte)(i & 0xFF);
203 | array[0] = (byte)((i >> 8) & 0xFF);
204 |
205 | return array;
206 | }
207 |
208 |
209 | private static int toByte(char c) {
210 | if (c >= '0' && c <= '9')
211 | return (c - '0');
212 | if (c >= 'A' && c <= 'F')
213 | return (c - 'A' + 10);
214 | if (c >= 'a' && c <= 'f')
215 | return (c - 'a' + 10);
216 |
217 | throw new RuntimeException("Invalid hex char '" + c + "'");
218 | }
219 |
220 |
221 | public static byte[] hexStringToByteArray(String hexString) {
222 | int length = hexString.length();
223 | byte[] buffer = new byte[length / 2];
224 |
225 | for (int i = 0; i < length; i += 2) {
226 | buffer[i / 2] = (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i + 1)));
227 | }
228 |
229 | return buffer;
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DashAPS
3 | Overview
4 | Treatments
5 | Pod
6 |
7 |
8 | Location Is Not Enabled
9 | For Bluetooth discovery to work on newer devices, location must be enabled. AAPS does not track your location and it can be disabled after pairing is successful.
10 | Enable
11 | No
12 |
13 |
14 |
15 |
16 | pref_omnipod_beep_bolus_enabled
17 | pref_omnipod_beep_basal_enabled
18 | pref_omnipod_beep_smb_enabled
19 | pref_omnipod_beep_tbr_enabled
20 | pref_omnipod_pod_debugging_options_enabled
21 | Bolus Beep Enabled
22 | Basal Beep Enabled
23 | SMB Beep Enabled
24 | TBR Beep Enabled
25 | Pod Debugging Options Enabled
26 |
27 | g/U
28 | /U
29 | U/h
30 | Medtronic Pump
31 | Omnipod
32 | Bluetooth Initializing…
33 | Bluetooth Error
34 | Bluetooth Ready
35 | Not Started
36 | RileyLink Initialization…
37 | RileyLink Error
38 | Tuning up RileyLink and Pump
39 | Problem connecting to Pump
40 | Connected
41 | Errors
42 | Serial # not set.
43 | Serial # invalid.
44 | Pump Type not set.
45 | Pump Type unsupported.
46 | Pump Frequency not set.
47 | Pump Frequency unsupported.
48 | RileyLink Address invalid.
49 | Pump type detected is not the same as configured type.
50 |
51 | Basal profiles are not enabled on pump.
52 | Basal profile set on pump is incorrect (must be STD).
53 | Wrong TBR type set on pump (must be Absolute).
54 | Wrong Max Bolus set on Pump (must be %1$.2f).
55 | Wrong Max Basal set on Pump (must be %1$.2f).
56 | Operation is not possible.\n\n You need to configure Medtronic Pump first, before you can use this operation.
57 | Over 24h Time change was requested.
58 | Device is not RileyLink
59 | RileyLink unreachable
60 | Bluetooth disabled
61 | No Bluetooth Adapter
62 | TuneUp Failed
63 | Pump unreachable
64 | Pod unreachable
65 | Not set
66 | pref_rileylink_mac_address
67 | Never contacted
68 | Waking up
69 | Error with communication
70 | Timeout on communication
71 | Pump unreachable
72 | Invalid configuration
73 | Active
74 | Sleeping
75 | Pair Pod
76 | Prime Pod
77 | Fill Cannula
78 | Set Basal Profile
79 | Cancel Delivery
80 | Deactivate Pod
81 | Enacted
82 | Comment
83 | Success
84 | Percent
85 | Absolute
86 | Cancel temp basal
87 | SMB
88 | Waiting for result
89 | U
90 | Duration
91 | Insulin
92 | OK
93 | Cancel
94 |
95 |
96 |
97 | Hello blank fragment
98 | Delivery cancelled (%s delivered)
99 | Delivering (%s U)
100 | Delivered %s U (at %s)
101 |
102 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_pod.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
19 |
20 |
21 |
32 |
33 |
34 |
44 |
45 |
54 |
55 |
65 |
66 |
75 |
76 |
77 |
87 |
88 |
97 |
98 |
99 |
109 |
110 |
119 |
120 |
121 |
131 |
132 |
141 |
142 |
143 |
153 |
154 |
163 |
164 |
165 |
175 |
176 |
185 |
186 |
187 |
196 |
197 |
206 |
207 |
216 |
217 |
218 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidaps/dashaps/ui/fragments/treatment/MainTreatmentFragment.java:
--------------------------------------------------------------------------------
1 | package com.androidaps.dashaps.ui.fragments.treatment;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 |
14 | import com.androidaps.dashaps.DashAapsService;
15 | import com.androidaps.dashaps.MainActivity;
16 | import com.androidaps.dashaps.R;
17 | import com.androidaps.dashaps.data.Pod;
18 | import com.androidaps.dashaps.enums.PodState;
19 | import com.androidaps.dashaps.ui.command.CancelBolusUiCommand;
20 | import com.androidaps.dashaps.ui.command.CancelTBRUiCommand;
21 | import com.androidaps.dashaps.ui.command.PodCommandQueueUi;
22 | import com.androidaps.dashaps.ui.command.SetBolusUiCommand;
23 | import com.androidaps.dashaps.ui.command.SetTBRUiCommand;
24 | import com.androidaps.dashaps.ui.command.UiStatusType;
25 |
26 | import info.nightscout.androidaps.utils.OKDialog;
27 |
28 |
29 | /**
30 | * A simple {@link Fragment} subclass.
31 | * Activities that contain this fragment must implement the
32 | * {@link MainTreatmentFragment.OnFragmentInteractionListener} interface
33 | * to handle interaction events.
34 | * Use the {@link MainTreatmentFragment#newInstance} factory method to
35 | * create an instance of this fragment.
36 | */
37 | public class MainTreatmentFragment extends Fragment {
38 |
39 | private static final String TAG = "MainTreatmentFragment";
40 | private OnFragmentInteractionListener mListener;
41 | private static MainTreatmentFragment instance;
42 |
43 | private Button buttonBolusStart;
44 | private Button buttonBolusCancel;
45 | private EditText bolusAmount;
46 | private Button buttonTbrStart;
47 | private EditText tbrAmount;
48 | private Button buttonTbrCancel;
49 |
50 |
51 | public MainTreatmentFragment() {
52 | // Required empty public constructor
53 | }
54 |
55 | public static MainTreatmentFragment getInstance() {
56 | return instance;
57 | }
58 |
59 |
60 | /**
61 | * Use this factory method to create a new instance of
62 | * this fragment using the provided parameters.
63 | *
64 | * @return A new instance of fragment TreatmentFragment.
65 | */
66 | public static MainTreatmentFragment newInstance() {
67 | MainTreatmentFragment fragment = new MainTreatmentFragment();
68 | instance = fragment;
69 | return fragment;
70 | }
71 |
72 | @Override
73 | public void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 |
76 | }
77 |
78 | @Override
79 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
80 | Bundle savedInstanceState) {
81 | // Inflate the layout for this fragment
82 | View rootView = inflater.inflate(R.layout.fragment_treatment, container, false);
83 |
84 | buttonBolusStart = rootView.findViewById(R.id.buttonBolusStart);
85 | buttonBolusStart.setOnClickListener(v -> {
86 | if (bolusAmount.getText().toString().length() == 0) {
87 | Log.e(TAG, "Need to set amount.");
88 | OKDialog.show(MainActivity.getInstance(), "Warning", "You need to set the amount, before you can start bolus.", null);
89 | } else {
90 | buttonBolusStart.setEnabled(false);
91 | new SetBolusUiCommand(Double.valueOf(bolusAmount.getText().toString())).execute();
92 | }
93 | });
94 |
95 | buttonBolusCancel = rootView.findViewById(R.id.buttonBolusCancel);
96 | buttonBolusCancel.setOnClickListener(v -> {
97 | buttonBolusCancel.setEnabled(false);
98 | new CancelBolusUiCommand().execute();
99 | });
100 | buttonBolusCancel.setEnabled(false);
101 |
102 | bolusAmount = rootView.findViewById(R.id.bolusAmount);
103 |
104 |
105 | buttonTbrStart = rootView.findViewById(R.id.buttonTbrStart);
106 | buttonTbrStart.setOnClickListener(v -> {
107 | if (tbrAmount.getText().toString().length() == 0) {
108 | Log.e(TAG, "Need to set amount.");
109 | OKDialog.show(MainActivity.getInstance(), "Warning", "You need to set the amount, before you can start bolus.", null);
110 | } else {
111 | buttonTbrStart.setEnabled(false);
112 | new SetTBRUiCommand(Double.valueOf(tbrAmount.getText().toString())).execute();
113 | }
114 | });
115 |
116 | buttonTbrCancel = rootView.findViewById(R.id.buttonTbrCancel);
117 | buttonTbrCancel.setOnClickListener(v -> {
118 | buttonTbrCancel.setEnabled(false);
119 | new CancelTBRUiCommand().execute();
120 | });
121 | buttonTbrCancel.setEnabled(false);
122 |
123 | tbrAmount = rootView.findViewById(R.id.editTextTbrAmount);
124 |
125 | return rootView;
126 | }
127 |
128 | public void onButtonPressed(Uri uri) {
129 | if (mListener != null) {
130 | mListener.onFragmentInteraction(uri);
131 | }
132 | }
133 |
134 | @Override
135 | public void onAttach(Context context) {
136 | super.onAttach(context);
137 | if (context instanceof OnFragmentInteractionListener) {
138 | mListener = (OnFragmentInteractionListener) context;
139 | } else {
140 | throw new RuntimeException(context.toString()
141 | + " must implement OnFragmentInteractionListener");
142 | }
143 | }
144 |
145 | @Override
146 | public void onDetach() {
147 | super.onDetach();
148 | mListener = null;
149 | }
150 |
151 |
152 | /**
153 | * This interface must be implemented by activities that contain this
154 | * fragment to allow an interaction in this fragment to be communicated
155 | * to the activity and potentially other fragments contained in that
156 | * activity.
157 | *
158 | * See the Android Training lesson Communicating with Other Fragments for more information.
161 | */
162 | public interface OnFragmentInteractionListener {
163 | void onFragmentInteraction(Uri uri);
164 | }
165 |
166 | public void processCommand(PodCommandQueueUi podCommandQueueUi) {
167 | podCommandQueueUi.updateUi(this);
168 | }
169 |
170 | public void processCommandFinished(PodCommandQueueUi podCommandQueueUi) {
171 | podCommandQueueUi.updateUiOnFinalize(this);
172 | }
173 |
174 | public void setBolus(UiStatusType statusType) {
175 | getActivity().runOnUiThread(() -> {
176 |
177 | if (statusType == UiStatusType.AllDisabled) {
178 | buttonBolusStart.setEnabled(false);
179 | buttonBolusCancel.setEnabled(false);
180 | } else if (statusType == UiStatusType.StartEnabled) {
181 | buttonBolusStart.setEnabled(true);
182 | buttonBolusCancel.setEnabled(false);
183 | } else if (statusType == UiStatusType.CancelEnabled) {
184 | buttonBolusStart.setEnabled(false);
185 | buttonBolusCancel.setEnabled(true);
186 | }
187 | });
188 | }
189 |
190 |
191 | @Override
192 | public void onResume() {
193 | super.onResume();
194 |
195 | setPod(DashAapsService.pod);
196 | }
197 |
198 |
199 | public void setPod(Pod pod) {
200 | if (pod != null && pod.getPodStateObject() == PodState.Active) {
201 | setBolus(UiStatusType.StartEnabled);
202 | setTBR(UiStatusType.StartEnabled);
203 | } else {
204 | setBolus(UiStatusType.AllDisabled);
205 | setTBR(UiStatusType.AllDisabled);
206 | }
207 | }
208 |
209 | public void setTBR(UiStatusType statusType) {
210 | getActivity().runOnUiThread(() -> {
211 |
212 | if (statusType == UiStatusType.AllDisabled) {
213 | buttonTbrStart.setEnabled(false);
214 | buttonTbrCancel.setEnabled(false);
215 | } else if (statusType == UiStatusType.StartEnabled) {
216 | buttonTbrStart.setEnabled(true);
217 | buttonTbrCancel.setEnabled(false);
218 | } else if (statusType == UiStatusType.CancelEnabled) {
219 | buttonTbrStart.setEnabled(false);
220 | buttonTbrCancel.setEnabled(true);
221 | }
222 | });
223 | }
224 |
225 |
226 | }
227 |
--------------------------------------------------------------------------------