-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from GeoTecINIT/background-sensors
Background sensors
- Loading branch information
Showing
40 changed files
with
256 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ allprojects { | |
repositories { | ||
google() | ||
jcenter() | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...rossensors/src/main/java/es/uji/geotec/wearossensors/collection/WearCollectorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package es.uji.geotec.wearossensors.collection; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.hardware.SensorEventListener; | ||
|
||
import com.google.android.gms.location.LocationCallback; | ||
import com.google.android.gms.location.LocationRequest; | ||
import com.google.android.gms.location.LocationServices; | ||
import com.google.android.gms.location.Priority; | ||
|
||
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; | ||
|
||
public class WearCollectorManager extends CollectorManager { | ||
|
||
private LocationCallback locationListener; | ||
|
||
public WearCollectorManager(Context context) { | ||
super(context, new DefaultTimeProvider()); | ||
} | ||
|
||
public WearCollectorManager(Context context, TimeProvider timeProvider) { | ||
super(context, timeProvider); | ||
} | ||
|
||
@SuppressLint("MissingPermission") | ||
@Override | ||
public boolean startCollectingFrom( | ||
CollectionConfiguration collectionConfiguration, | ||
RecordCallback recordCallback | ||
) { | ||
WearSensor sensor = (WearSensor) collectionConfiguration.getSensor(); | ||
|
||
if (!sensorManager.isSensorAvailable(sensor)) | ||
return false; | ||
|
||
RecordAccumulator accumulator = new RecordAccumulator( | ||
recordCallback, | ||
collectionConfiguration.getBatchSize() | ||
); | ||
|
||
switch(sensor) { | ||
case ACCELEROMETER: | ||
case GYROSCOPE: | ||
case MAGNETOMETER: | ||
case HEART_RATE: | ||
SensorEventListener listener = SensorListenerProvider.getListenerFor(sensor, accumulator, timeProvider); | ||
if (listener == null) | ||
return false; | ||
|
||
listeners.put(sensor, listener); | ||
|
||
android.hardware.Sensor androidSensor = this.getAndroidSensor(sensor); | ||
return androidSensorManager.registerListener( | ||
listener, | ||
androidSensor, | ||
collectionConfiguration.getSensorDelay() | ||
); | ||
case LOCATION: | ||
locationListener = SensorListenerProvider.getLocationListener(accumulator, timeProvider); | ||
if (locationListener == null) | ||
return false; | ||
|
||
LocationRequest request = LocationRequest.create() | ||
.setPriority(Priority.PRIORITY_HIGH_ACCURACY) | ||
.setInterval(collectionConfiguration.getSensorDelay()); | ||
|
||
LocationServices.getFusedLocationProviderClient(context) | ||
.requestLocationUpdates(request, locationListener, null); | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void stopCollectingFrom(Sensor sensor) { | ||
switch ((WearSensor) sensor) { | ||
case ACCELEROMETER: | ||
case GYROSCOPE: | ||
case MAGNETOMETER: | ||
case HEART_RATE: | ||
SensorEventListener listener = listeners.get(sensor); | ||
if (listener == null) | ||
return; | ||
|
||
listeners.remove(sensor); | ||
android.hardware.Sensor androidSensor = this.getAndroidSensor(sensor); | ||
androidSensorManager.unregisterListener(listener, androidSensor); | ||
return; | ||
case LOCATION: | ||
if (locationListener == null) | ||
return; | ||
|
||
LocationServices.getFusedLocationProviderClient(context) | ||
.removeLocationUpdates(locationListener); | ||
|
||
locationListener = null; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void ensureStopCollecting() { | ||
for (Sensor sensor : listeners.keySet()) { | ||
stopCollectingFrom(sensor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
...ossensors/src/main/java/es/uji/geotec/wearossensors/listeners/TriAxialSensorListener.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...wearossensors/src/main/java/es/uji/geotec/wearossensors/listeners/WearSensorListener.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.