From be8c1c2a832769a2105418ccc95adb6313939017 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 14 Aug 2016 10:13:26 +0200 Subject: [PATCH] change to screen lock, better context handling --- .../ConfigBuilder/ConfigBuilderPlugin.java | 2 +- .../androidaps/plugins/DanaR/DanaRPlugin.java | 2 +- .../Overview/Dialogs/WizardDialog.java | 27 +++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 5bd54a5353..df452796cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -76,7 +76,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain public ConfigBuilderPlugin() { MainApp.bus().register(this); PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ConfigBuilderPlugin");; + mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 715430dc8c..6541671974 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -240,7 +240,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (insulin > 0 || carbs > 0) { Treatment t = new Treatment(); boolean connectionOK = false; - if (insulin > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t); + if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t); PumpEnactResult result = new PumpEnactResult(); result.success = connectionOK; result.bolusDelivered = t.insulin; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 1fdfd2a454..3e845e8419 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -82,10 +82,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener { Context parentContext; - public WizardDialog(Context context) { + public WizardDialog() { mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName()); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); + } + + + public WizardDialog(Context context) { + this(); parentContext = context; } @@ -120,7 +125,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { @Override public void onNothingSelected(AdapterView parent) { - ToastUtils.showToastInUiThread(getContext(), MainApp.sResources.getString(R.string.noprofileselected)); + ToastUtils.showToastInUiThread(parentContext, MainApp.sResources.getString(R.string.noprofileselected)); wizardDialogDeliverButton.setVisibility(View.GONE); } }; @@ -192,10 +197,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener { confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - calculatedTotalInsulin != 0 || carbsAfterConstraints != calculatedCarbs) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput)); - builder.setPositiveButton(getContext().getString(R.string.ok), null); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.show(); return; } @@ -203,8 +208,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener { final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Integer finalCarbsAfterConstraints = carbsAfterConstraints; - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.confirmation)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); builder.setMessage(confirmMessage); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -223,10 +228,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener { boluscalcJSON ); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setMessage(result.comment); - builder.setPositiveButton(getContext().getString(R.string.ok), null); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.show(); } } @@ -253,7 +258,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { ArrayList profileList; profileList = profile.getProfileList(); - ArrayAdapter adapter = new ArrayAdapter(getContext(), + ArrayAdapter adapter = new ArrayAdapter(parentContext, android.R.layout.simple_spinner_item, profileList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); profileSpinner.setAdapter(adapter);