From 909a1f39504191d37ad95950db0fe98c8c6e08d1 Mon Sep 17 00:00:00 2001 From: Miguel Matey Sanz Date: Tue, 26 Jul 2022 16:34:44 +0200 Subject: [PATCH] refactor(wearos-lib): extend from base record and remove already included features --- .../records/HeartRateRecord.java | 5 +++- .../wearossensors/records/LocationRecord.java | 7 +++-- .../geotec/wearossensors/records/Record.java | 13 -------- .../wearossensors/records/TriAxialRecord.java | 25 ---------------- .../accumulator/RecordAccumulator.java | 30 ------------------- .../RecordAccumulatorProvider.java | 27 ----------------- .../callbacks/AbstractRecordCallback.java | 6 ++-- .../callbacks/RecordCallbackProvider.java | 2 +- .../callbacks/TriAxialRecordCallback.java | 2 +- 9 files changed, 15 insertions(+), 102 deletions(-) delete mode 100644 wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/Record.java delete mode 100644 wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/TriAxialRecord.java delete mode 100644 wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulator.java delete mode 100644 wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulatorProvider.java diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/HeartRateRecord.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/HeartRateRecord.java index fb1efe0..6d34f73 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/HeartRateRecord.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/HeartRateRecord.java @@ -1,11 +1,14 @@ package es.uji.geotec.wearossensors.records; +import es.uji.geotec.backgroundsensors.record.Record; +import es.uji.geotec.wearossensors.sensor.WearSensor; + public class HeartRateRecord extends Record { private int value; public HeartRateRecord(long timestamp, int value) { - super(timestamp); + super(WearSensor.HEART_RATE, timestamp); this.value = value; } diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/LocationRecord.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/LocationRecord.java index 7dc2dc6..24247a4 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/LocationRecord.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/LocationRecord.java @@ -2,6 +2,9 @@ import android.location.Location; +import es.uji.geotec.backgroundsensors.record.Record; +import es.uji.geotec.wearossensors.sensor.WearSensor; + public class LocationRecord extends Record { private double latitude; @@ -9,14 +12,14 @@ public class LocationRecord extends Record { private double altitude; public LocationRecord(long timestamp, double latitude, double longitude, double altitude) { - super(timestamp); + super(WearSensor.LOCATION, timestamp); this.latitude = latitude; this.longitude = longitude; this.altitude = altitude; } public LocationRecord(Location location) { - super(location.getTime()); + super(WearSensor.LOCATION, location.getTime()); this.latitude = location.getLatitude(); this.longitude = location.getLongitude(); this.altitude = location.getAltitude(); diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/Record.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/Record.java deleted file mode 100644 index 60e510d..0000000 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/Record.java +++ /dev/null @@ -1,13 +0,0 @@ -package es.uji.geotec.wearossensors.records; - -public class Record { - private long timestamp; - - public Record(long timestamp) { - this.timestamp = timestamp; - } - - public long getTimestamp() { - return timestamp; - } -} diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/TriAxialRecord.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/TriAxialRecord.java deleted file mode 100644 index 297cac8..0000000 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/TriAxialRecord.java +++ /dev/null @@ -1,25 +0,0 @@ -package es.uji.geotec.wearossensors.records; - -public class TriAxialRecord extends Record { - - private float x, y, z; - - public TriAxialRecord(long timestamp, float x, float y, float z) { - super(timestamp); - this.x = x; - this.y = y; - this.z = z; - } - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getZ() { - return z; - } -} diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulator.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulator.java deleted file mode 100644 index 853d964..0000000 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulator.java +++ /dev/null @@ -1,30 +0,0 @@ -package es.uji.geotec.wearossensors.records.accumulator; - - -import java.util.LinkedList; -import java.util.List; - -import es.uji.geotec.wearossensors.records.Record; -import es.uji.geotec.wearossensors.records.callbacks.AbstractRecordCallback; - -public class RecordAccumulator { - - private AbstractRecordCallback callback; - private int limit; - private List records; - - public RecordAccumulator(AbstractRecordCallback callback, int limit) { - this.callback = callback; - this.limit = limit; - this.records = new LinkedList<>(); - } - - public void accumulateRecord(T record) { - records.add(record); - - if (records.size() == limit) { - callback.onRecordsCollected(new LinkedList(records)); - records.clear(); - } - } -} diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulatorProvider.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulatorProvider.java deleted file mode 100644 index ab6eb6d..0000000 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/accumulator/RecordAccumulatorProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -package es.uji.geotec.wearossensors.records.accumulator; - - -import es.uji.geotec.wearossensors.records.HeartRateRecord; -import es.uji.geotec.wearossensors.records.LocationRecord; -import es.uji.geotec.wearossensors.records.TriAxialRecord; -import es.uji.geotec.wearossensors.records.callbacks.AbstractRecordCallback; -import es.uji.geotec.wearossensors.sensoring.WearSensor; - -public class RecordAccumulatorProvider { - private RecordAccumulatorProvider() {} - - public static RecordAccumulator getRecordAccumulatorProviderFor(WearSensor wearSensor, AbstractRecordCallback callback, int limit) { - switch (wearSensor) { - case ACCELEROMETER: - case GYROSCOPE: - case MAGNETOMETER: - return new RecordAccumulator(callback, limit); - case HEART_RATE: - return new RecordAccumulator(callback, limit); - case LOCATION: - return new RecordAccumulator(callback, limit); - default: - return null; - } - } -} diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/AbstractRecordCallback.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/AbstractRecordCallback.java index 6ce7ffe..0414f48 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/AbstractRecordCallback.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/AbstractRecordCallback.java @@ -4,10 +4,11 @@ import java.util.List; +import es.uji.geotec.backgroundsensors.record.Record; +import es.uji.geotec.backgroundsensors.record.callback.RecordCallback; import es.uji.geotec.wearossensors.messaging.MessagingClient; -import es.uji.geotec.wearossensors.records.Record; -public abstract class AbstractRecordCallback { +public abstract class AbstractRecordCallback implements RecordCallback { private MessagingClient messagingClient; private String requesterId; @@ -19,6 +20,7 @@ public AbstractRecordCallback(Context context, String requesterId, String sendin this.sendingPath = sendingPath; } + @Override public void onRecordsCollected(List records) { byte[] recordsEncoded = encodeRecords(records); this.messagingClient.sendNewRecord(requesterId, sendingPath, recordsEncoded); diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/RecordCallbackProvider.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/RecordCallbackProvider.java index 850cd68..beae7c4 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/RecordCallbackProvider.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/RecordCallbackProvider.java @@ -2,7 +2,7 @@ import android.content.Context; -import es.uji.geotec.wearossensors.sensoring.WearSensor; +import es.uji.geotec.wearossensors.sensor.WearSensor; public class RecordCallbackProvider { private RecordCallbackProvider() { diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/TriAxialRecordCallback.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/TriAxialRecordCallback.java index b363026..c816fbd 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/TriAxialRecordCallback.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/records/callbacks/TriAxialRecordCallback.java @@ -5,7 +5,7 @@ import java.nio.ByteBuffer; import java.util.List; -import es.uji.geotec.wearossensors.records.TriAxialRecord; +import es.uji.geotec.backgroundsensors.record.TriAxialRecord; public class TriAxialRecordCallback extends AbstractRecordCallback {