diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 115301dc49..1e2dc4cf2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -1,12 +1,25 @@ package info.nightscout.androidaps; +import java.io.File; +import java.util.ArrayList; + +import net.danlew.android.joda.JodaTimeAndroid; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import android.app.Application; +import android.bluetooth.BluetoothAdapter; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.annotation.PluralsRes; import android.support.v4.content.LocalBroadcastManager; +import android.util.Log; import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.Answers; @@ -15,14 +28,6 @@ import com.squareup.otto.Bus; import com.squareup.otto.LoggingBus; import com.squareup.otto.ThreadEnforcer; -import net.danlew.android.joda.JodaTimeAndroid; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.ArrayList; - import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PluginBase; @@ -93,8 +98,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.SP; import io.fabric.sdk.android.Fabric; - public class MainApp extends Application { + private static Logger log = LoggerFactory.getLogger(L.CORE); private static KeepAliveReceiver keepAliveReceiver; @@ -117,6 +122,7 @@ public class MainApp extends Application { public static boolean devBranch; public static boolean engineeringMode; + @Override public void onCreate() { super.onCreate(); @@ -158,7 +164,8 @@ public class MainApp extends Application { // Register all tabs in app here pluginsList.add(OverviewPlugin.getPlugin()); pluginsList.add(IobCobCalculatorPlugin.getPlugin()); - if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin()); + if (Config.ACTION) + pluginsList.add(ActionsFragment.getPlugin()); pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin()); @@ -166,29 +173,45 @@ public class MainApp extends Application { pluginsList.add(SensitivityAAPSPlugin.getPlugin()); pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin()); pluginsList.add(SensitivityOref1Plugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(DanaRPlugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(DanaRKoreanPlugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(DanaRPlugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(DanaRKoreanPlugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(DanaRv2Plugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(DanaRSPlugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(LocalInsightPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); - if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); - if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); + if (Config.PUMPDRIVERS) + pluginsList.add(ComboPlugin.getPlugin()); + if (Config.MDI) + pluginsList.add(MDIPlugin.getPlugin()); if (Config.PUMPDRIVERS && engineeringMode) { pluginsList.add(MedtronicPumpPlugin.getPlugin()); } pluginsList.add(VirtualPumpPlugin.getPlugin()); - if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(LoopPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSMAPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSAMAPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSSMBPlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin()); - if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); - if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin()); + if (Config.OTHERPROFILES) + pluginsList.add(SimpleProfilePlugin.getPlugin()); + if (Config.OTHERPROFILES) + pluginsList.add(LocalProfilePlugin.getPlugin()); pluginsList.add(TreatmentsPlugin.getPlugin()); - if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin()); - if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin()); - if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin()); + if (Config.SAFETY) + pluginsList.add(SafetyPlugin.getPlugin()); + if (Config.SAFETY) + pluginsList.add(StorageConstraintPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(ObjectivesPlugin.getPlugin()); pluginsList.add(SourceXdripPlugin.getPlugin()); pluginsList.add(SourceNSClientPlugin.getPlugin()); pluginsList.add(SourceMM640gPlugin.getPlugin()); @@ -198,7 +221,8 @@ public class MainApp extends Application { pluginsList.add(SourcePoctechPlugin.getPlugin()); pluginsList.add(SourceTomatoPlugin.getPlugin()); pluginsList.add(SourceEversensePlugin.getPlugin()); - if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); + if (Config.SMSCOMMUNICATORENABLED) + pluginsList.add(SmsCommunicatorPlugin.getPlugin()); pluginsList.add(FoodPlugin.getPlugin()); pluginsList.add(WearPlugin.initPlugin(this)); @@ -211,7 +235,6 @@ public class MainApp extends Application { pluginsList.add(DstHelperPlugin.getPlugin()); - ConfigBuilderPlugin.getPlugin().initialize(); } @@ -227,6 +250,7 @@ public class MainApp extends Application { } } + private void registerLocalBroadcastReceiver() { lbm = LocalBroadcastManager.getInstance(this); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT)); @@ -242,16 +266,16 @@ public class MainApp extends Application { lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL)); - //register alarms + // register alarms lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ALARM)); lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ANNOUNCEMENT)); lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_CLEAR_ALARM)); lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_URGENT_ALARM)); - //register ack alarm + // register ack alarm lbm.registerReceiver(ackAlarmReciever, new IntentFilter(Intents.ACTION_ACK_ALARM)); - //register dbaccess + // register dbaccess lbm.registerReceiver(dbAccessReciever, new IntentFilter(Intents.ACTION_DATABASE)); } @@ -301,11 +325,13 @@ public class MainApp extends Application { } } + public void stopKeepAliveService() { if (keepAliveReceiver != null) KeepAliveReceiver.cancelAlarm(this); } + public static void subscribe(Object subscriber) { try { bus().register(subscriber); @@ -314,6 +340,7 @@ public class MainApp extends Application { } } + public static void unsubscribe(Object subscriber) { try { bus().unregister(subscriber); @@ -322,34 +349,42 @@ public class MainApp extends Application { } } + public static Bus bus() { return sBus; } + public static String gs(int id) { return sResources.getString(id); } + public static String gs(int id, Object... args) { return sResources.getString(id, args); } + public static String gq(@PluralsRes int id, int quantity, Object... args) { return sResources.getQuantityString(id, quantity, args); } + public static int gc(int id) { return sResources.getColor(id); } + public static MainApp instance() { return sInstance; } + public static DatabaseHelper getDbHelper() { return sDatabaseHelper; } + public static void closeDbHelper() { if (sDatabaseHelper != null) { sDatabaseHelper.close(); @@ -357,14 +392,17 @@ public class MainApp extends Application { } } + public static ConstraintChecker getConstraintChecker() { return sConstraintsChecker; } + public static ArrayList getPluginsList() { return pluginsList; } + public static ArrayList getSpecificPluginsList(PluginType type) { ArrayList newList = new ArrayList<>(); @@ -379,6 +417,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsVisibleInList(PluginType type) { ArrayList newList = new ArrayList<>(); @@ -394,6 +433,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsListByInterface(Class interfaceClass) { ArrayList newList = new ArrayList<>(); @@ -408,6 +448,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) { ArrayList newList = new ArrayList<>(); @@ -423,12 +464,13 @@ public class MainApp extends Application { return newList; } + @Nullable public static T getSpecificPlugin(Class pluginClass) { if (pluginsList != null) { for (PluginBase p : pluginsList) { if (pluginClass.isAssignableFrom(p.getClass())) - return (T) p; + return (T)p; } } else { log.error("pluginsList=null"); @@ -450,10 +492,12 @@ public class MainApp extends Application { return engineeringMode || !devBranch; } + public static boolean isDev() { return devBranch; } + public static int getIcon() { if (Config.NSCLIENT) return R.mipmap.ic_yellowowl; @@ -463,6 +507,7 @@ public class MainApp extends Application { return R.mipmap.ic_launcher; } + public static int getNotificationIcon() { if (Config.NSCLIENT) return R.drawable.ic_notif_nsclient; @@ -472,6 +517,7 @@ public class MainApp extends Application { return R.drawable.ic_notif_aaps; } + @Override public void onTerminate() { if (L.isEnabled(L.CORE)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java index 7201bf9d4d..516b461e0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java @@ -1,5 +1,9 @@ package info.nightscout.androidaps.plugins.general.actions; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import android.app.Activity; import android.content.Intent; @@ -15,18 +19,14 @@ import android.widget.LinearLayout; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.activities.HistoryBrowseActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.activities.HistoryBrowseActivity; import info.nightscout.androidaps.activities.TDDStatsActivity; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.events.EventCustomActionsChanged; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -35,19 +35,17 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.common.SubscriberFragment; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; -import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.SingleClickButton; - /** * A simple {@link Fragment} subclass. */ @@ -55,6 +53,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL static ActionsPlugin actionsPlugin = new ActionsPlugin(); + static public ActionsPlugin getPlugin() { return actionsPlugin; } @@ -70,27 +69,27 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL SingleClickButton tddStats; SingleClickButton history; - private Map pumpCustomActions = new HashMap<>(); + private Map pumpCustomActions = new HashMap<>(); private List pumpCustomButtons = new ArrayList<>(); + public ActionsFragment() { super(); } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { View view = inflater.inflate(R.layout.actions_fragment, container, false); - profileSwitch = (SingleClickButton) view.findViewById(R.id.actions_profileswitch); - tempTarget = (SingleClickButton) view.findViewById(R.id.actions_temptarget); - extendedBolus = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus); - extendedBolusCancel = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus_cancel); - tempBasal = (SingleClickButton) view.findViewById(R.id.actions_settempbasal); - tempBasalCancel = (SingleClickButton) view.findViewById(R.id.actions_canceltempbasal); - fill = (SingleClickButton) view.findViewById(R.id.actions_fill); + profileSwitch = (SingleClickButton)view.findViewById(R.id.actions_profileswitch); + tempTarget = (SingleClickButton)view.findViewById(R.id.actions_temptarget); + extendedBolus = (SingleClickButton)view.findViewById(R.id.actions_extendedbolus); + extendedBolusCancel = (SingleClickButton)view.findViewById(R.id.actions_extendedbolus_cancel); + tempBasal = (SingleClickButton)view.findViewById(R.id.actions_settempbasal); + tempBasalCancel = (SingleClickButton)view.findViewById(R.id.actions_canceltempbasal); + fill = (SingleClickButton)view.findViewById(R.id.actions_fill); tddStats = view.findViewById(R.id.actions_tddstats); history = view.findViewById(R.id.actions_historybrowser); @@ -115,21 +114,25 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return null; } + @Subscribe public void onStatusEvent(final EventInitializationChanged ev) { updateGUI(); } + @Subscribe public void onStatusEvent(final EventRefreshOverview ev) { updateGUI(); } + @Subscribe public void onStatusEvent(final EventExtendedBolusChange ev) { updateGUI(); } + @Subscribe public void onStatusEvent(final EventTempBasalChange ev) { updateGUI(); @@ -147,9 +150,11 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL Activity activity = getActivity(); if (activity != null) activity.runOnUiThread(new Runnable() { + @Override public void run() { - if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() != null) { + if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null + && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() != null) { profileSwitch.setVisibility(View.VISIBLE); } else { profileSwitch.setVisibility(View.GONE); @@ -167,34 +172,37 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); final boolean basalprofileEnabled = MainApp.isEngineeringModeOrRelease() - && pump.getPumpDescription().isSetBasalProfileCapable; + && pump.getPumpDescription().isSetBasalProfileCapable; if (!basalprofileEnabled || !pump.isInitialized() || pump.isSuspended()) profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!pump.getPumpDescription().isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses()) { + if (!pump.getPumpDescription().isExtendedBolusCapable || !pump.isInitialized() + || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses()) { extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.GONE); } else { - ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory( + System.currentTimeMillis()); if (activeExtendedBolus != null) { extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.VISIBLE); - extendedBolusCancel.setText(MainApp.gs(R.string.cancel) + " " + activeExtendedBolus.toString()); + extendedBolusCancel.setText(MainApp.gs(R.string.cancel) + " " + + activeExtendedBolus.toString()); } else { extendedBolus.setVisibility(View.VISIBLE); extendedBolusCancel.setVisibility(View.GONE); } } - if (!pump.getPumpDescription().isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) { tempBasal.setVisibility(View.GONE); tempBasalCancel.setVisibility(View.GONE); } else { - final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); + final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory( + System.currentTimeMillis()); if (activeTemp != null) { tempBasal.setVisibility(View.GONE); tempBasalCancel.setVisibility(View.VISIBLE); @@ -226,7 +234,6 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL }); } - View.OnClickListener pumpCustomActionsListener = v -> { SingleClickButton btn = (SingleClickButton)v; @@ -248,9 +255,10 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return; } + // add new actions List customActions = activePump.getCustomActions(); - if (customActions != null && customActions.size()>0) { + if (customActions != null && customActions.size() > 0) { LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); @@ -263,7 +271,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL btn.setText(MainApp.gs(customAction.getName())); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3 btn.setLayoutParams(layoutParams); @@ -285,7 +293,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL private void removePumpCustomActions() { - if (pumpCustomActions.size()==0) + if (pumpCustomActions.size() == 0) return; LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java index 79f6dac8cb..af1fde8c19 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java @@ -16,34 +16,29 @@ public class CustomAction { public CustomAction(int nameResourceId, CustomActionType actionType) { - this.name = nameResourceId; - this.customActionType = actionType; - this.iconResourceId = R.drawable.icon_actions_profileswitch; + this(nameResourceId, actionType, R.drawable.icon_actions_profileswitch, true); } + public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId) { + this(nameResourceId, actionType, iconResourceId, true); + } + + + public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId, boolean enabled) { this.name = nameResourceId; this.customActionType = actionType; this.iconResourceId = iconResourceId; - } - - public CustomAction(int nameResourceId, CustomActionType actionType, boolean enabled) { - this.name = nameResourceId; - this.customActionType = actionType; this.enabled = enabled; } public int getName() { - return name; } - - public CustomActionType getCustomActionType() { - return customActionType; } @@ -52,6 +47,7 @@ public class CustomAction { return iconResourceId; } + public boolean isEnabled() { return enabled; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 5c0e4e08db..c8ee8ccc88 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -258,6 +258,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } + @Override + public boolean canHandleDST() { + return false; + } + + // Pump Plugin private boolean isServiceSet() { @@ -1377,13 +1383,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // LOG.debug("MedtronicPumpPlugin::stopConnecting"); // } - List customActions = null; + private List customActions = null; - CustomAction customActionWakeUpAndTune = new CustomAction(R.string.medtronic_custom_action_wake_and_tune, + private CustomAction customActionWakeUpAndTune = new CustomAction(R.string.medtronic_custom_action_wake_and_tune, MedtronicCustomActionType.WakeUpAndTune); - CustomAction customActionClearBolusBlock = new CustomAction(R.string.medtronic_custom_action_clear_bolus_block, - MedtronicCustomActionType.ClearBolusBlock); + private CustomAction customActionClearBolusBlock = new CustomAction( + R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock); @Override @@ -1398,7 +1404,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + public void executeCustomAction(CustomActionType customActionType) { MedtronicCustomActionType mcat = (MedtronicCustomActionType)customActionType; @@ -1419,7 +1425,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter break; } - return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index 95ac9ab8f4..64f6505aef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.pump.virtual; -import android.os.SystemClock; - -import com.squareup.otto.Subscribe; +import java.util.List; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; +import android.os.SystemClock; + +import com.squareup.otto.Subscribe; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; @@ -41,11 +41,11 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; - /** * Created by mike on 05.08.2016. */ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { + private Logger log = LoggerFactory.getLogger(L.PUMP); Integer batteryPercent = 50; @@ -56,16 +56,12 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { private long lastDataTime = 0; private PumpDescription pumpDescription = new PumpDescription(); + public VirtualPumpPlugin() { - super(new PluginDescription() - .mainType(PluginType.PUMP) - .fragmentClass(VirtualPumpFragment.class.getName()) - .pluginName(R.string.virtualpump) - .shortName(R.string.virtualpump_shortname) - .preferencesId(R.xml.pref_virtualpump) - .neverVisible(Config.NSCLIENT) - .description(R.string.description_pump_virtual) - ); + super(new PluginDescription().mainType(PluginType.PUMP).fragmentClass(VirtualPumpFragment.class.getName()) + .pluginName(R.string.virtualpump).shortName(R.string.virtualpump_shortname) + .preferencesId(R.xml.pref_virtualpump).neverVisible(Config.NSCLIENT) + .description(R.string.description_pump_virtual)); pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.1d; @@ -85,7 +81,6 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { pumpDescription.tempDurationStep30mAllowed = true; pumpDescription.tempMaxDuration = 24 * 60; - pumpDescription.isSetBasalProfileCapable = true; pumpDescription.basalStep = 0.01d; pumpDescription.basalMinimumRate = 0.01d; @@ -96,6 +91,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { pumpDescription.is30minBasalRatesCapable = true; } + public static VirtualPumpPlugin getPlugin() { if (plugin == null) plugin = new VirtualPumpPlugin(); @@ -103,19 +99,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return plugin; } + private void loadFakingStatus() { fromNSAreCommingFakedExtendedBoluses = SP.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false); } + public boolean getFakingStatus() { return fromNSAreCommingFakedExtendedBoluses; } + public void setFakingStatus(boolean newStatus) { fromNSAreCommingFakedExtendedBoluses = newStatus; SP.putBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, fromNSAreCommingFakedExtendedBoluses); } + @Override protected void onStart() { super.onStart(); @@ -123,72 +123,86 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { refreshConfiguration(); } + @Override protected void onStop() { MainApp.bus().unregister(this); } + @Subscribe public void onStatusEvent(final EventPreferenceChange s) { if (s.isChanged(R.string.key_virtualpump_type)) refreshConfiguration(); } + @Override public boolean isFakingTempsByExtendedBoluses() { return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses; } + @Override public PumpEnactResult loadTDDs() { - //no result, could read DB in the future? + // no result, could read DB in the future? return new PumpEnactResult(); } + @Override public List getCustomActions() { return null; } + @Override public void executeCustomAction(CustomActionType customActionType) { } + @Override public boolean isInitialized() { return true; } + @Override public boolean isSuspended() { return false; } + @Override public boolean isBusy() { return false; } + @Override public boolean isConnected() { return true; } + @Override public boolean isConnecting() { return false; } + @Override public boolean isHandshakeInProgress() { return false; } + @Override public void finishHandshaking() { } + @Override public void connect(String reason) { if (!Config.NSCLIENT) @@ -196,40 +210,48 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { lastDataTime = System.currentTimeMillis(); } + @Override public void disconnect(String reason) { } + @Override public void stopConnecting() { } + @Override public void getPumpStatus() { lastDataTime = System.currentTimeMillis(); } + @Override public PumpEnactResult setNewBasalProfile(Profile profile) { lastDataTime = System.currentTimeMillis(); // Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile(); PumpEnactResult result = new PumpEnactResult(); result.success = true; - Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); + Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), + Notification.INFO, 60); MainApp.bus().post(new EventNewNotification(notification)); return result; } + @Override public boolean isThisProfileSet(Profile profile) { return true; } + @Override public long lastDataTime() { return lastDataTime; } + @Override public double getBaseBasalRate() { Profile profile = ProfileFunctions.getInstance().getProfile(); @@ -241,10 +263,16 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override - public double getReservoirLevel() { return reservoirInUnits; } + public double getReservoirLevel() { + return reservoirInUnits; + } + @Override - public int getBatteryLevel() { return batteryPercent; } + public int getBatteryLevel() { + return batteryPercent; + } + @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { @@ -262,7 +290,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { SystemClock.sleep(200); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), delivering); - bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100); + bolusingEvent.percent = Math.min((int)(delivering / detailedBolusInfo.insulin * 100), 100); MainApp.bus().post(bolusingEvent); delivering += 0.1d; } @@ -273,25 +301,26 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { MainApp.bus().post(bolusingEvent); SystemClock.sleep(1000); if (L.isEnabled(L.PUMPCOMM)) - log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); + log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + + detailedBolusInfo.carbs + "g " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); lastDataTime = System.currentTimeMillis(); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); return result; } + @Override public void stopBolusDelivering() { } - @Override - public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { - TemporaryBasal tempBasal = new TemporaryBasal() - .date(System.currentTimeMillis()) - .absolute(absoluteRate) - .duration(durationInMinutes) - .source(Source.USER); + @Override + public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, + boolean enforceNew) { + + TemporaryBasal tempBasal = new TemporaryBasal().date(System.currentTimeMillis()).absolute(absoluteRate) + .duration(durationInMinutes).source(Source.USER); PumpEnactResult result = new PumpEnactResult(); result.success = true; result.enacted = true; @@ -307,13 +336,12 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return result; } + @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { - TemporaryBasal tempBasal = new TemporaryBasal() - .date(System.currentTimeMillis()) - .percent(percent) - .duration(durationInMinutes) - .source(Source.USER); + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, + boolean enforceNew) { + TemporaryBasal tempBasal = new TemporaryBasal().date(System.currentTimeMillis()).percent(percent) + .duration(durationInMinutes).source(Source.USER); PumpEnactResult result = new PumpEnactResult(); result.success = true; result.enacted = true; @@ -330,17 +358,15 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return result; } + @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { PumpEnactResult result = cancelExtendedBolus(); if (!result.success) return result; - ExtendedBolus extendedBolus = new ExtendedBolus() - .date(System.currentTimeMillis()) - .insulin(insulin) - .durationInMinutes(durationInMinutes) - .source(Source.USER); + ExtendedBolus extendedBolus = new ExtendedBolus().date(System.currentTimeMillis()).insulin(insulin) + .durationInMinutes(durationInMinutes).source(Source.USER); result.success = true; result.enacted = true; result.bolusDelivered = insulin; @@ -355,6 +381,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return result; } + @Override public PumpEnactResult cancelTempBasal(boolean force) { PumpEnactResult result = new PumpEnactResult(); @@ -365,7 +392,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { result.enacted = true; TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); - //tempBasal = null; + // tempBasal = null; if (L.isEnabled(L.PUMPCOMM)) log.debug("Canceling temp basal: " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); @@ -374,6 +401,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return result; } + @Override public PumpEnactResult cancelExtendedBolus() { PumpEnactResult result = new PumpEnactResult(); @@ -393,6 +421,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return result; } + @Override public JSONObject getJSONStatus(Profile profile, String profileName) { long now = System.currentTimeMillis(); @@ -436,25 +465,30 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return pump; } + @Override public String deviceID() { return "VirtualPump"; } + @Override public PumpDescription getPumpDescription() { return pumpDescription; } + @Override public String shortStatus(boolean veryShort) { return "Virtual Pump"; } + public PumpType getPumpType() { return pumpType; } + @Override public boolean canHandleDST() { return true; @@ -481,15 +515,4 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { } - - @Override - public List getCustomActions() { - return null; - } - - - @Override - public void executeCustomAction(CustomActionType customActionType) { - return null; - } } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index ddc5a3bc49..f5804e2a86 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1,5 +1,4 @@ - - + Sécurités des traitements Maximum Bolus autorisé [U] @@ -344,7 +343,7 @@ L\'ENSEMBLE DES RISQUES LIÉS À LA QUALITÉ ET À LA PERFORMANCE DU PROGRAMME S Pour démarrer Basal %1$.2fU/h pendant %2$d min, renvoyer le code %3$s Pour changer le profil vers %1$s %2$d%%, renvoyer le code %3$s Pour démarrer le Bolus étendu %1$.2fU pendant %2$d min, renvoyer le code %3$s - Pour démarrer le Basal %1$d% pendant %2$d min, renvoyer le code %3$s + Pour démarrer le Basal %1$d%% pendant %2$d min, renvoyer le code %3$s Envoyer le code %2$s pour suspendre la Boucle pour %1$d minutes Démarrage réussi pour %1$.2fU/h de basal temporaire pour %2$d min Le Bolus étendu %1$.2fU pendant %2$d min a commencé avec succès