2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.impl;
|
2015-05-30 17:28:03 +02:00
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2015-07-27 23:49:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
2015-05-30 21:52:29 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
public class GBActivitySample implements ActivitySample {
|
2015-05-30 17:28:03 +02:00
|
|
|
private final int timestamp;
|
2015-07-27 23:49:53 +02:00
|
|
|
private final SampleProvider provider;
|
2015-05-30 17:28:03 +02:00
|
|
|
private final short intensity;
|
2015-07-27 23:49:53 +02:00
|
|
|
private final short steps;
|
2015-05-30 17:28:03 +02:00
|
|
|
private final byte type;
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) {
|
2015-05-30 17:28:03 +02:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
this.provider = provider;
|
|
|
|
this.intensity = intensity;
|
|
|
|
this.steps = steps;
|
|
|
|
this.type = type;
|
2015-09-09 20:46:50 +02:00
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void validate() {
|
|
|
|
if (steps < 0) {
|
|
|
|
throw new IllegalArgumentException("steps must be > 0");
|
|
|
|
}
|
|
|
|
if (intensity < 0) {
|
|
|
|
throw new IllegalArgumentException("intensity must be > 0");
|
|
|
|
}
|
|
|
|
if (timestamp < 0) {
|
|
|
|
throw new IllegalArgumentException("timestamp must be > 0");
|
|
|
|
}
|
2015-05-30 17:28:03 +02:00
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
2015-05-30 17:28:03 +02:00
|
|
|
public int getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public SampleProvider getProvider() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public short getRawIntensity() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return intensity;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public float getIntensity() {
|
|
|
|
return getProvider().normalizeIntensity(getRawIntensity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getSteps() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public byte getRawKind() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public int getKind() {
|
|
|
|
return getProvider().normalizeType(getRawKind());
|
|
|
|
}
|
2015-05-30 17:28:03 +02:00
|
|
|
}
|