1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Disable live activity tracking when activity is paused

Fixes #496
This commit is contained in:
cpfeiffer 2017-03-20 22:58:45 +01:00
parent b97674ba85
commit 14552a1a80

View File

@ -282,13 +282,14 @@ public class LiveActivityFragment extends AbstractChartFragment {
@Override
public void onPause() {
enableRealtimeTracking(false);
super.onPause();
stopActivityPulse();
}
@Override
public void onResume() {
super.onResume();
enableRealtimeTracking(true);
}
private ScheduledExecutorService startActivityPulse() {
@ -345,23 +346,34 @@ public class LiveActivityFragment extends AbstractChartFragment {
@Override
protected void onMadeVisibleInActivity() {
GBApplication.deviceService().onEnableRealtimeSteps(true);
GBApplication.deviceService().onEnableRealtimeHeartRateMeasurement(true);
super.onMadeVisibleInActivity();
if (getActivity() != null) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
enableRealtimeTracking(true);
}
private void enableRealtimeTracking(boolean enable) {
if (enable && pulseScheduler != null) {
// already running
return;
}
GBApplication.deviceService().onEnableRealtimeSteps(enable);
GBApplication.deviceService().onEnableRealtimeHeartRateMeasurement(enable);
if (enable) {
if (getActivity() != null) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
pulseScheduler = startActivityPulse();
} else {
stopActivityPulse();
if (getActivity() != null) {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
pulseScheduler = startActivityPulse();
}
@Override
protected void onMadeInvisibleInActivity() {
stopActivityPulse();
GBApplication.deviceService().onEnableRealtimeSteps(false);
GBApplication.deviceService().onEnableRealtimeHeartRateMeasurement(false);
if (getActivity() != null) {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
enableRealtimeTracking(false);
super.onMadeInvisibleInActivity();
}