diff --git a/wear-app/app/src/main/java/org/nativescript/demo/MainActivity.java b/wear-app/app/src/main/java/org/nativescript/demo/MainActivity.java index 3398c06..d799a65 100644 --- a/wear-app/app/src/main/java/org/nativescript/demo/MainActivity.java +++ b/wear-app/app/src/main/java/org/nativescript/demo/MainActivity.java @@ -10,6 +10,8 @@ import android.widget.LinearLayout; import android.widget.Spinner; +import es.uji.geotec.backgroundsensors.sensor.Sensor; +import es.uji.geotec.backgroundsensors.sensor.SensorManager; import es.uji.geotec.wearossensors.command.CommandClient; import es.uji.geotec.wearossensors.freemessage.FreeMessage; import es.uji.geotec.wearossensors.freemessage.FreeMessageClient; @@ -98,9 +100,11 @@ private void setupButtons() { private void setupSpinner() { sensorSpinner = findViewById(R.id.sensor_spinner); + SensorManager sensorManager = new SensorManager(this); + ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - for (WearSensor sensor : WearSensor.values()) { + for (Sensor sensor : sensorManager.availableSensors(WearSensor.values())) { adapter.add(sensor.toString()); } diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/capabilities/CapabilityAdvertisementHandler.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/capabilities/CapabilityAdvertisementHandler.java index 7eb54dc..33cb011 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/capabilities/CapabilityAdvertisementHandler.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/capabilities/CapabilityAdvertisementHandler.java @@ -9,20 +9,21 @@ import java.util.List; import es.uji.geotec.backgroundsensors.sensor.Sensor; -import es.uji.geotec.wearossensors.collection.WearCollectorManager; +import es.uji.geotec.backgroundsensors.sensor.SensorManager; +import es.uji.geotec.wearossensors.sensor.WearSensor; public class CapabilityAdvertisementHandler { private MessageClient messageClient; - private WearCollectorManager collectorManager; + private SensorManager sensorManager; public CapabilityAdvertisementHandler(Context context) { this.messageClient = Wearable.getMessageClient(context); - this.collectorManager = new WearCollectorManager(context); + this.sensorManager = new SensorManager(context); } public void handleRequest(MessageEvent event) { - List availableSensors = this.collectorManager.availableSensors(); + List availableSensors = this.sensorManager.availableSensors(WearSensor.values()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < availableSensors.size(); i++) { diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/collection/WearCollectorManager.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/collection/WearCollectorManager.java index 3f87862..dbc6ebe 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/collection/WearCollectorManager.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/collection/WearCollectorManager.java @@ -9,13 +9,13 @@ import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.Priority; -import java.util.Arrays; - import es.uji.geotec.backgroundsensors.collection.CollectionConfiguration; import es.uji.geotec.backgroundsensors.collection.CollectorManager; import es.uji.geotec.backgroundsensors.record.accumulator.RecordAccumulator; import es.uji.geotec.backgroundsensors.record.callback.RecordCallback; import es.uji.geotec.backgroundsensors.sensor.Sensor; +import es.uji.geotec.backgroundsensors.time.DefaultTimeProvider; +import es.uji.geotec.backgroundsensors.time.TimeProvider; import es.uji.geotec.wearossensors.listeners.SensorListenerProvider; import es.uji.geotec.wearossensors.sensor.WearSensor; @@ -24,7 +24,11 @@ public class WearCollectorManager extends CollectorManager { private LocationCallback locationListener; public WearCollectorManager(Context context) { - super(context, Arrays.asList(WearSensor.values())); + super(context, new DefaultTimeProvider()); + } + + public WearCollectorManager(Context context, TimeProvider timeProvider) { + super(context, timeProvider); } @SuppressLint("MissingPermission") @@ -35,7 +39,7 @@ public boolean startCollectingFrom( ) { WearSensor sensor = (WearSensor) collectionConfiguration.getSensor(); - if (!isSensorAvailable(sensor)) + if (!sensorManager.isSensorAvailable(sensor)) return false; RecordAccumulator accumulator = new RecordAccumulator( @@ -48,20 +52,20 @@ public boolean startCollectingFrom( case GYROSCOPE: case MAGNETOMETER: case HEART_RATE: - SensorEventListener listener = SensorListenerProvider.getListenerFor(sensor, accumulator); + SensorEventListener listener = SensorListenerProvider.getListenerFor(sensor, accumulator, timeProvider); if (listener == null) return false; listeners.put(sensor, listener); android.hardware.Sensor androidSensor = this.getAndroidSensor(sensor); - return sensorManager.registerListener( + return androidSensorManager.registerListener( listener, androidSensor, collectionConfiguration.getSensorDelay() ); case LOCATION: - locationListener = SensorListenerProvider.getLocationListener(accumulator); + locationListener = SensorListenerProvider.getLocationListener(accumulator, timeProvider); if (locationListener == null) return false; @@ -90,7 +94,7 @@ public void stopCollectingFrom(Sensor sensor) { listeners.remove(sensor); android.hardware.Sensor androidSensor = this.getAndroidSensor(sensor); - sensorManager.unregisterListener(listener, androidSensor); + androidSensorManager.unregisterListener(listener, androidSensor); return; case LOCATION: if (locationListener == null) diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/LocationSensorListener.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/LocationSensorListener.java index 544f812..88316b8 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/LocationSensorListener.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/LocationSensorListener.java @@ -7,19 +7,23 @@ import com.google.android.gms.location.LocationResult; import es.uji.geotec.backgroundsensors.record.accumulator.RecordAccumulator; +import es.uji.geotec.backgroundsensors.time.TimeProvider; import es.uji.geotec.wearossensors.records.LocationRecord; public class LocationSensorListener extends LocationCallback { private RecordAccumulator accumulator; + private TimeProvider timeProvider; - public LocationSensorListener(RecordAccumulator accumulator) { + public LocationSensorListener(RecordAccumulator accumulator, TimeProvider timeProvider) { this.accumulator = accumulator; + this.timeProvider = timeProvider; } @Override public void onLocationResult(LocationResult locationResult) { for (Location location : locationResult.getLocations()) { + location.setTime(timeProvider.getTimestamp()); LocationRecord record = new LocationRecord(location); accumulator.accumulateRecord(record); } diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/SensorListenerProvider.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/SensorListenerProvider.java index af5163d..b78bdca 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/SensorListenerProvider.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/SensorListenerProvider.java @@ -6,6 +6,7 @@ import es.uji.geotec.backgroundsensors.listener.TriAxialSensorListener; import es.uji.geotec.backgroundsensors.record.accumulator.RecordAccumulator; +import es.uji.geotec.backgroundsensors.time.TimeProvider; import es.uji.geotec.wearossensors.sensor.WearSensor; public class SensorListenerProvider { @@ -14,13 +15,14 @@ private SensorListenerProvider() { public static SensorEventListener getListenerFor( WearSensor wearSensor, - RecordAccumulator recordAccumulator + RecordAccumulator recordAccumulator, + TimeProvider timeProvider ) { switch (wearSensor) { case ACCELEROMETER: case GYROSCOPE: case MAGNETOMETER: - return new TriAxialSensorListener(wearSensor, recordAccumulator); + return new TriAxialSensorListener(wearSensor, recordAccumulator, timeProvider); case HEART_RATE: return new HeartRateSensorListener(recordAccumulator); default: @@ -28,7 +30,7 @@ public static SensorEventListener getListenerFor( } } - public static LocationCallback getLocationListener(RecordAccumulator recordAccumulator) { - return new LocationSensorListener(recordAccumulator); + public static LocationCallback getLocationListener(RecordAccumulator recordAccumulator, TimeProvider timeProvider) { + return new LocationSensorListener(recordAccumulator, timeProvider); } } diff --git a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/messaging/handlers/AbstractMessagingHandler.java b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/messaging/handlers/AbstractMessagingHandler.java index 96bde53..3ac0dbc 100644 --- a/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/messaging/handlers/AbstractMessagingHandler.java +++ b/wear-app/wearossensors/src/main/java/es/uji/geotec/wearossensors/messaging/handlers/AbstractMessagingHandler.java @@ -7,8 +7,8 @@ import java.util.ArrayList; import es.uji.geotec.backgroundsensors.collection.CollectionConfiguration; +import es.uji.geotec.backgroundsensors.sensor.SensorManager; import es.uji.geotec.backgroundsensors.service.manager.ServiceManager; -import es.uji.geotec.wearossensors.collection.WearCollectorManager; import es.uji.geotec.wearossensors.messaging.MessagingClient; import es.uji.geotec.wearossensors.messaging.MessagingProtocol; import es.uji.geotec.wearossensors.messaging.ResultMessagingProtocol; @@ -111,9 +111,9 @@ private void handleStopRequest() { } private boolean isSensorSupported() { - WearCollectorManager collectorManager = new WearCollectorManager(context); + SensorManager sensorManager = new SensorManager(context); WearSensor wearSensor = getWearSensorType(); - return collectorManager.isSensorAvailable(wearSensor); + return sensorManager.isSensorAvailable(wearSensor); } protected abstract ArrayList getRequiredPermissions();