bind service to application context, adjust messages timing
This commit is contained in:
parent
3e3ad1d515
commit
87dd8712b4
3 changed files with 19 additions and 5 deletions
|
@ -799,7 +799,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
||||||
String settingVisible = "ConfigBuilder_" + type + "_" + p.getName() + "_Visible";
|
String settingVisible = "ConfigBuilder_" + type + "_" + p.getName() + "_Visible";
|
||||||
if (SP.contains(settingEnabled))
|
if (SP.contains(settingEnabled))
|
||||||
p.setFragmentEnabled(type, SP.getBoolean(settingEnabled, true));
|
p.setFragmentEnabled(type, SP.getBoolean(settingEnabled, true));
|
||||||
if (SP.contains("ConfigBuilder" + p.getName() + "Visible"))
|
if (SP.contains(settingVisible))
|
||||||
p.setFragmentVisible(type, SP.getBoolean(settingVisible, true));
|
p.setFragmentVisible(type, SP.getBoolean(settingVisible, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.TempBasal;
|
import info.nightscout.androidaps.db.TempBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
|
@ -102,6 +103,9 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
||||||
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||||
registerBus();
|
registerBus();
|
||||||
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
|
Intent intent = new Intent(context, ExecutionService.class);
|
||||||
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DanaRFragment newInstance() {
|
public static DanaRFragment newInstance() {
|
||||||
|
@ -184,6 +188,12 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventAppExit e) {
|
||||||
|
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
@ -191,6 +201,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
||||||
Intent intent = new Intent(context, ExecutionService.class);
|
Intent intent = new Intent(context, ExecutionService.class);
|
||||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
ServiceConnection mConnection = new ServiceConnection() {
|
ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
|
@ -208,6 +219,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
@ -216,8 +228,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
||||||
mBounded = false;
|
mBounded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
;
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventDanaRConnectionStatus c) {
|
public void onStatusEvent(final EventDanaRConnectionStatus c) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class ExecutionService extends Service {
|
||||||
danaRPump = danaRFragment.getDanaRPump();
|
danaRPump = danaRFragment.getDanaRPump();
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaConnection");
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ExecutionService");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -141,7 +141,6 @@ public class ExecutionService extends Service {
|
||||||
public void onStatusEvent(EventAppExit event) {
|
public void onStatusEvent(EventAppExit event) {
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
log.debug("EventAppExit received");
|
log.debug("EventAppExit received");
|
||||||
// TODO: mDanaConnection.stop();
|
|
||||||
|
|
||||||
if (mSerialIOThread != null)
|
if (mSerialIOThread != null)
|
||||||
mSerialIOThread.disconnect("Application exit");
|
mSerialIOThread.disconnect("Application exit");
|
||||||
|
@ -295,6 +294,7 @@ public class ExecutionService extends Service {
|
||||||
connect("tempBasal");
|
connect("tempBasal");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
|
||||||
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -303,6 +303,7 @@ public class ExecutionService extends Service {
|
||||||
connect("tempBasalStop");
|
connect("tempBasalStop");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||||
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -311,6 +312,7 @@ public class ExecutionService extends Service {
|
||||||
connect("extendedBolus");
|
connect("extendedBolus");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||||
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -319,6 +321,7 @@ public class ExecutionService extends Service {
|
||||||
connect("extendedBolusStop");
|
connect("extendedBolusStop");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||||
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue