Handle live activity for Mi2 and Mi1 in the same way #448

Realtime samples now use ActivitySample.NOT_MEASURED for unknown or
invalid values.
here
cpfeiffer 2016-12-26 11:33:01 +01:00
parent 8719cadc43
commit da494cde7b
4 changed files with 29 additions and 15 deletions

View File

@ -72,8 +72,6 @@ public class LiveActivityFragment extends AbstractChartFragment {
private TimestampTranslation tsTranslation;
private class Steps {
private int initialSteps;
private int steps;
private int lastTimestamp;
private int currentStepsPerMinute;
@ -90,7 +88,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
}
public int getTotalSteps() {
return steps - initialSteps;
return steps;
}
public int getMaxStepsPerMinute() {
@ -102,10 +100,6 @@ public class LiveActivityFragment extends AbstractChartFragment {
if (steps == 0) {
steps += stepsDelta;
lastTimestamp = timestamp;
// if (stepsDelta > 0) {
// initialSteps = stepsDelta;
// }
return;
}
@ -162,7 +156,9 @@ public class LiveActivityFragment extends AbstractChartFragment {
setCurrentHeartRate(heartRate, timestamp);
}
int steps = sample.getSteps();
addEntries(steps, timestamp);
if (steps != ActivitySample.NOT_MEASURED) {
addEntries(steps, timestamp);
}
}
private int translateTimestampFrom(Intent intent) {

View File

@ -953,7 +953,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
sample.setRawKind(MiBandSampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
LOG.debug("Storing realtime sample: " + sample);
provider.addGBActivitySample(sample);
// set the steps only afterwards, since realtime steps are also recorded
@ -962,6 +961,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
// change the value here in memory.
sample.setSteps(getSteps());
if (LOG.isDebugEnabled()) {
LOG.debug("realtime sample: " + sample);
}
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);

View File

@ -61,12 +61,17 @@ public abstract class RealtimeSamplesSupport {
this.steps = stepsPerMinute;
}
/**
* Returns the number of steps recorded since the last measurements. If no
* steps are available yet, ActivitySample.NOT_MEASURED is returned.
* @return
*/
public synchronized int getSteps() {
if (lastSteps == 0) {
return 0; // wait until we have a delta between two samples
}
if (steps == ActivitySample.NOT_MEASURED) {
return 0;
return ActivitySample.NOT_MEASURED;
}
if (lastSteps == 0) {
return ActivitySample.NOT_MEASURED; // wait until we have a delta between two samples
}
int delta = steps - lastSteps;
if (delta < 0) {

View File

@ -982,12 +982,22 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
sample.setRawKind(MiBand2SampleProvider.TYPE_ACTIVITY); // to make it visible in the charts TODO: add a MANUAL kind for that?
provider.addGBActivitySample(sample);
// set the steps only afterwards, since realtime steps are also recorded
// in the regular samples and we must not count them twice
// Note: we know that the DAO sample is never committed again, so we simply
// change the value here in memory.
sample.setSteps(getSteps());
if (LOG.isDebugEnabled()) {
LOG.debug("realtime sample: " + sample);
}
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
LOG.debug("Storing realtime sample: " + sample);
provider.addGBActivitySample(sample);
} catch (Exception e) {
LOG.warn("Unable to acquire db for saving realtime samples", e);
}