getBluetoothDevices() {
- return this.mBluetoothDevices;
+ public int getRssi() {
+ return this.rssi;
}
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBluetoothDeviceData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBluetoothDeviceData.java
deleted file mode 100644
index b9c7e64..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBluetoothDeviceData.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.data;
-
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-
-import java.util.Locale;
-
-public class SKBluetoothDeviceData extends SKAbstractData {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKBluetoothDeviceData";
-
- protected final String name;
- protected final String address;
- protected final int rssi;
-
- public SKBluetoothDeviceData(long timestamp, String name, String address, int rssi) {
-
- super(SKSensorModuleType.BLUETOOTH, timestamp);
-
- this.name = name;
- this.address = address;
- this.rssi = rssi;
- }
-
- @Override
- public String getDataInCSV() {
- return String.format(Locale.US, "%d,%s,%s,%d", this.timestamp, this.name, this.address, this.rssi);
- }
-
- @SuppressWarnings("unused")
- public String getName() {
- return this.name;
- }
-
- @SuppressWarnings("unused")
- public String getAddress() {
- return this.address;
- }
-
- @SuppressWarnings("unused")
- public int getRssi() {
- return this.rssi;
- }
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGravityData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGravityData.java
index a589256..d5711da 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGravityData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGravityData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,43 +21,117 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKGravityData encapsulates measurements related to the Gravity sensor.
+ */
public class SKGravityData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKGravityData";
-
- protected final float x;
- protected final float y;
- protected final float z;
+ private static final String TAG = SKGravityData.class.getSimpleName();
- public SKGravityData(long timestamp, float x, float y, float z) {
+ private final float x;
+ private final float y;
+ private final float z;
- super(SKSensorModuleType.GRAVITY, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x X-axis value
+ * @param y Y-axis value
+ * @param z Z-axis value
+ */
+ public SKGravityData(final long timestamp, final float x, final float y, final float z) {
+ super(SKSensorType.GRAVITY, timestamp);
this.x = x;
this.y = y;
this.z = z;
}
+ /**
+ * Get the csv header of the Gravity sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Gravity sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,x,y,z";
+ }
+
+ /**
+ * Get the Gravity sensor data in csv format
+ *
+ * @return String in csv format: timeIntervalSince1970, x-axis, y-axis, z-axis
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
}
+ /**
+ * Get the Gravity sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Gravity sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, x-axis, y-axis, z-axis
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("x", this.x);
+ subJsonObject.put("y", this.y);
+ subJsonObject.put("z", this.z);
+
+ jsonObject.put("gravity", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get the Gravity sensor X-axis value
+ *
+ * @return X-axis value
+ */
@SuppressWarnings("unused")
public float getX() {
return this.x;
}
+ /**
+ * Get the Gravity sensor Y-axis value
+ *
+ * @return Y-axis value
+ */
@SuppressWarnings("unused")
public float getY() {
return this.y;
}
+ /**
+ * Get the Gravity sensor Z-axis value
+ *
+ * @return Z-axis value
+ */
@SuppressWarnings("unused")
public float getZ() {
return this.z;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGyroscopeData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGyroscopeData.java
index b798680..81b2245 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGyroscopeData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGyroscopeData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,43 +21,117 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKGyroscopeData encapsulates measurements related to the Gyroscope sensor.
+ */
public class SKGyroscopeData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKGyroscopeData";
-
- protected final float x;
- protected final float y;
- protected final float z;
+ private static final String TAG = SKGyroscopeData.class.getSimpleName();
- public SKGyroscopeData(long timestamp, float x, float y, float z) {
+ private final float x;
+ private final float y;
+ private final float z;
- super(SKSensorModuleType.GYROSCOPE, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x X-axis of the Gyroscope data
+ * @param y Y-axis of the Gyroscope data
+ * @param z Z-axis of the Gyroscope data
+ */
+ public SKGyroscopeData(final long timestamp, final float x, final float y, final float z) {
+ super(SKSensorType.GYROSCOPE, timestamp);
this.x = x;
this.y = y;
this.z = z;
}
+ /**
+ * Get the csv header of the Gyroscope sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Gyroscope sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,x,y,z";
+ }
+
+ /**
+ * Get the Gyroscope data in csv format
+ *
+ * @return String in csv format: timeIntervalSince1970, X-axis, Y-axis, Z-axis
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
}
+ /**
+ * Get the Gyroscope sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Gyroscope sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, x-axis, y-axis, z-axis
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("x", this.x);
+ subJsonObject.put("y", this.y);
+ subJsonObject.put("z", this.z);
+
+ jsonObject.put("gyroscope", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get the X-axis of the Gyroscope sensor data
+ *
+ * @return X-axis value
+ */
@SuppressWarnings("unused")
public float getX() {
return this.x;
}
+ /**
+ * Get the Y-axis of the Gyroscope sensor data
+ *
+ * @return Y-axis value
+ */
@SuppressWarnings("unused")
public float getY() {
return this.y;
}
+ /**
+ * Get the Z-axis of the Gyroscope sensor data
+ *
+ * @return Z-axis value
+ */
@SuppressWarnings("unused")
public float getZ() {
return this.z;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKHumidityData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKHumidityData.java
new file mode 100644
index 0000000..d3ba04c
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKHumidityData.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.data;
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
+
+import java.util.Locale;
+
+/**
+ * An instance of SKHumidityData encapsulates measurements related to the Humidity sensor.
+ */
+public class SKHumidityData extends SKAbstractData {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKHumidityData.class.getSimpleName();
+
+ private final float humidity;
+
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param humidity Humidity measurement
+ */
+ public SKHumidityData(final long timestamp, final float humidity) {
+
+ super(SKSensorType.HUMIDITY, timestamp);
+
+ this.humidity = humidity;
+ }
+
+ /**
+ * Get the csv header of the Humidity sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Humidity sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,humidity";
+ }
+
+ /**
+ * Get humidity sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, humidity
+ */
+ @Override
+ @NonNull
+ public String getDataInCSV() {
+ return String.format(Locale.US, "%d,%f", this.timestamp, this.humidity);
+ }
+
+ /**
+ * Get humidity sensor data in JSONObject format
+ *
+ * @return JSONObject containing the humidity sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, humidity
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+ jsonObject.put("humidity", this.humidity);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ @SuppressWarnings("unused")
+ public float getHumidity() {
+ return this.humidity;
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLightData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLightData.java
index 5a69bed..1f05440 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLightData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLightData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,29 +21,85 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKLightData encapsulates measurements related to the Light sensor.
+ */
public class SKLightData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKLightData";
-
- protected final float light;
+ private static final String TAG = SKLightData.class.getSimpleName();
- public SKLightData(long timestamp, float light) {
+ private final float light;
- super(SKSensorModuleType.LIGHT, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param light Ambient light in lux
+ */
+ public SKLightData(final long timestamp, final float light) {
+ super(SKSensorType.LIGHT, timestamp);
this.light = light;
}
+ /**
+ * Get the csv header of the Light sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Light sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,lux";
+ }
+
+ /**
+ * Get light sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, ambient light in lux
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f", this.timestamp, this.light);
}
+ /**
+ * Get light sensor data in JSONObject format
+ *
+ * @return JSONObject containing the light sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, light
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+ jsonObject.put("light", this.light);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get light sensor data
+ *
+ * @return Ambient light in lux
+ */
@SuppressWarnings("unused")
public float getLight() {
return this.light;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLinearAccelerationData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLinearAccelerationData.java
index c6280c4..018cba2 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLinearAccelerationData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLinearAccelerationData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,43 +21,118 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKLinearAccelerationData encapsulates measurements related to the Linear Acceleration sensor.
+ * Measures the acceleration force in mass/seconds**2, excluding the force of gravity
+ */
public class SKLinearAccelerationData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKLinearAccelerationData";
-
- protected final float x;
- protected final float y;
- protected final float z;
+ private static final String TAG = SKLinearAccelerationData.class.getSimpleName();
- public SKLinearAccelerationData(long timestamp, float x, float y, float z) {
+ private final float x;
+ private final float y;
+ private final float z;
- super(SKSensorModuleType.LINEAR_ACCELERATION, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x Force in X direction
+ * @param y Force in Y direction
+ * @param z Force in Z direction
+ */
+ public SKLinearAccelerationData(final long timestamp, final float x, final float y, final float z) {
+ super(SKSensorType.LINEAR_ACCELERATION, timestamp);
this.x = x;
this.y = y;
this.z = z;
}
+ /**
+ * Get the csv header of the Linear Acceleration sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Linear Acceleration sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,x,y,z";
+ }
+
+ /**
+ * Get Linear Acceleration sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, x force, y force, z force
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
}
+ /**
+ * Get the Linear Acceleration sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Linear Acceleration sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, x-axis, y-axis, z-axis
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("x", this.x);
+ subJsonObject.put("y", this.y);
+ subJsonObject.put("z", this.z);
+
+ jsonObject.put("linearAcceleration", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get Linear Acceleration force in X direction
+ *
+ * @return force in X direction
+ */
@SuppressWarnings("unused")
public float getX() {
return this.x;
}
+ /**
+ * Get Linear Acceleration force in Y direction
+ *
+ * @return force in Y direction
+ */
@SuppressWarnings("unused")
public float getY() {
return this.y;
}
+ /**
+ * Get Linear Acceleration force in Z direction
+ *
+ * @return force in Z direction
+ */
@SuppressWarnings("unused")
public float getZ() {
return this.z;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLocationData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLocationData.java
index 9772596..0525c5e 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLocationData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLocationData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -22,34 +22,138 @@
package org.sensingkit.sensingkitlib.data;
import android.location.Location;
+import androidx.annotation.NonNull;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKLocationData encapsulates measurements related to the Location sensor.
+ */
public class SKLocationData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKLocationData";
-
- protected final Location location;
+ private static final String TAG = SKLocationData.class.getSimpleName();
- public SKLocationData(long timestamp, Location location) {
+ private final Location location;
- super(SKSensorModuleType.LOCATION, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param location Location object
+ */
+ public SKLocationData(final long timestamp, final @NonNull Location location) {
+ super(SKSensorType.LOCATION, timestamp);
this.location = location;
}
+ /**
+ * Get the csv header of the Location sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Location sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,latitude,longitude,altitude,accuracy";
+ }
+
+ /**
+ * Get location sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, latitude, longitude, altitude, accuracy
+ */
@Override
+ @NonNull
public String getDataInCSV() {
- return String.format(Locale.US, "%d,%s", this.timestamp, this.location);
+ return String.format(Locale.US, "%d,%f,%f,%f,%f", this.timestamp,
+ this.location.getLatitude(), this.location.getLongitude(), this.location.getAltitude(),
+ this.location.getAccuracy());
}
+ /**
+ * Get the location sensor data in JSONObject format
+ *
+ * @return JSONObject containing the location sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, latitude, longitude, altitude, accuracy
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("latitude", this.location.getLatitude());
+ subJsonObject.put("longitude", this.location.getLongitude());
+ subJsonObject.put("altitude", this.location.getAltitude());
+ subJsonObject.put("accuracy", this.location.getAccuracy());
+
+ jsonObject.put("location", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get Location object
+ *
+ * @return Location object
+ */
@SuppressWarnings("unused")
public Location getLocation() {
return location;
}
+ /**
+ * Get Latitude
+ *
+ * @return Latitude
+ */
+ @SuppressWarnings("unused")
+ public double getLatitude() {
+ return location.getLatitude();
+ }
+
+ /**
+ * Get Longitude
+ *
+ * @return Longitude
+ */
+ @SuppressWarnings("unused")
+ public double getLongitude() {
+ return location.getLongitude();
+ }
+
+ /**
+ * Get Altitude
+ *
+ * @return Altitude
+ */
+ @SuppressWarnings("unused")
+ public double getAltitude() {
+ return location.getAltitude();
+ }
+
+ /**
+ * Get Accuracy
+ *
+ * @return Accuracy
+ */
+ @SuppressWarnings("unused")
+ public float getAccuracy() {
+ return location.getAccuracy();
+ }
+
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMagnetometerData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMagnetometerData.java
index 0b109bc..55dbcab 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMagnetometerData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMagnetometerData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,43 +21,121 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+
+/**
+ * An instance of SKMagnetometerData encapsulates measurements related to the Magnetometer sensor.
+ * Measures the magnetic force in micro-Tesla
+ */
+
public class SKMagnetometerData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKMagnetometerData";
+ private static final String TAG = SKMagnetometerData.class.getSimpleName();
- protected final float x;
- protected final float y;
- protected final float z;
+ private final float x;
+ private final float y;
+ private final float z;
- public SKMagnetometerData(long timestamp, float x, float y, float z) {
-
- super(SKSensorModuleType.MAGNETOMETER, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x Force in X-direction
+ * @param y Force in Y-direction
+ * @param z Force in Z-direction
+ */
+ public SKMagnetometerData(final long timestamp, final float x, final float y, final float z) {
+ super(SKSensorType.MAGNETOMETER, timestamp);
this.x = x;
this.y = y;
this.z = z;
}
+ /**
+ * Get the csv header of the Magnetometer sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Magnetometer sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,x,y,z";
+ }
+
+ /**
+ * Get Magnetometer sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, x force, y force, z force
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
}
+
+ /**
+ * Get the Magnetometer sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Magnetometer sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, x force, y force, z force
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("x", this.x);
+ subJsonObject.put("y", this.y);
+ subJsonObject.put("z", this.z);
+
+ jsonObject.put("magnetometer", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get Magnetometer force in X direction
+ *
+ * @return force in X direction
+ */
@SuppressWarnings("unused")
public float getX() {
return this.x;
}
+ /**
+ * Get Magnetometer force in Y direction
+ *
+ * @return force in Y direction
+ */
@SuppressWarnings("unused")
public float getY() {
return this.y;
}
+ /**
+ * Get Magnetometer force in Z direction
+ *
+ * @return force in Z direction
+ */
@SuppressWarnings("unused")
public float getZ() {
return this.z;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMicrophoneData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMicrophoneData.java
new file mode 100644
index 0000000..4079205
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMicrophoneData.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2016. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit https://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.data;
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
+
+import java.util.Locale;
+
+/**
+ * An instance of SKMicrophoneData encapsulates measurements related to the Microphone sensor.
+ */
+public class SKMicrophoneData extends SKAbstractData {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKMicrophoneData.class.getSimpleName();
+
+ private final String state;
+
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param state Microphone sensor status (Start, Stop)
+ */
+ public SKMicrophoneData(final long timestamp, final @NonNull String state) {
+ super(SKSensorType.STEP_DETECTOR, timestamp);
+
+ this.state = state;
+ }
+
+ /**
+ * Get the csv header of the Step Counter sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Step Counter sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,state";
+ }
+
+ /**
+ * Get Step Detector sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970
+ */
+ @Override
+ @NonNull
+ public String getDataInCSV() {
+ return String.format(Locale.US, "%d,%s", this.timestamp, this.state);
+ }
+
+ /**
+ * Get Step Detector sensor data in JSONObject format
+ *
+ * @return JSONObject containing Step Detector sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, state
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+ jsonObject.put("state", this.state);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+
+ /**
+ * Get Microphone Status
+ *
+ * @return String with the status of the Microphone sensor
+ */
+ @SuppressWarnings("unused")
+ public String getState() {
+ return this.state;
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMotionActivityData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMotionActivityData.java
new file mode 100644
index 0000000..4552638
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMotionActivityData.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.data;
+
+import androidx.annotation.NonNull;
+
+import com.google.android.gms.location.ActivityTransition;
+import com.google.android.gms.location.DetectedActivity;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
+
+import java.util.Locale;
+
+/**
+ * An instance of SKMotionActivityData encapsulates measurements related to the Motion Activity sensor.
+ * Activity is classified as Stationary, Walking, Running, Automotive or Cycling.
+ */
+public class SKMotionActivityData extends SKAbstractData {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKMotionActivityData.class.getSimpleName();
+
+ @SuppressWarnings("WeakerAccess")
+ public enum SKActivityType {
+
+ /**
+ * TODO
+ */
+ STATIONARY("Still", DetectedActivity.STILL),
+
+ /**
+ * TODO
+ */
+ WALKING("Walking", DetectedActivity.WALKING),
+
+ /**
+ * TODO
+ */
+ RUNNING("Running", DetectedActivity.RUNNING),
+
+ /**
+ * TODO
+ */
+ AUTOMOTIVE("Automotive", DetectedActivity.IN_VEHICLE),
+
+ /**
+ * TODO
+ */
+ CYCLING("Cycling", DetectedActivity.ON_BICYCLE);
+
+ private final @NonNull String activityType;
+ private final int activityTypeCode;
+
+ SKActivityType(final @NonNull String activityType, final int activityTypeCode) {
+ this.activityType = activityType;
+ this.activityTypeCode = activityTypeCode;
+ }
+
+ public static SKActivityType valueOf(final int activityTypeCode) {
+
+ switch (activityTypeCode) {
+
+ case DetectedActivity.STILL:
+ return STATIONARY;
+
+ case DetectedActivity.WALKING:
+ return WALKING;
+
+ case DetectedActivity.RUNNING:
+ return RUNNING;
+
+ case DetectedActivity.IN_VEHICLE:
+ return AUTOMOTIVE;
+
+ case DetectedActivity.ON_BICYCLE:
+ return CYCLING;
+
+ default:
+ throw new RuntimeException("Unsupported SKActivityType with code: " + activityTypeCode);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public @NonNull String getActivityType() {
+ return this.activityType;
+ }
+
+ @SuppressWarnings("unused")
+ public int getActivityTypeCode() {
+ return this.activityTypeCode;
+ }
+
+ @NonNull
+ @Override
+ public String toString() {
+ return this.getActivityType();
+ }
+ }
+
+ public enum SKTransitionType {
+
+ /**
+ * TODO
+ */
+ ENTER("Enter", ActivityTransition.ACTIVITY_TRANSITION_ENTER),
+
+ /**
+ * TODO
+ */
+ EXIT("Exit", ActivityTransition.ACTIVITY_TRANSITION_EXIT);
+
+ private final @NonNull String transitionType;
+ private final int transitionTypeCode;
+
+ SKTransitionType(final @NonNull String transitionType, final int transitionTypeCode) {
+ this.transitionType = transitionType;
+ this.transitionTypeCode = transitionTypeCode;
+ }
+
+ @SuppressWarnings("WeakerAccess")
+ public static SKTransitionType valueOf(final int transitionTypeCode) {
+
+ switch (transitionTypeCode) {
+
+ case ActivityTransition.ACTIVITY_TRANSITION_ENTER:
+ return ENTER;
+
+ case ActivityTransition.ACTIVITY_TRANSITION_EXIT:
+ return EXIT;
+
+ default:
+ throw new RuntimeException("Unsupported SKTransitionType with code: " + transitionTypeCode);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public @NonNull String getTransitionType() {
+ return this.transitionType;
+ }
+
+ @SuppressWarnings("unused")
+ public int getTransitionTypeCode() {
+ return this.transitionTypeCode;
+ }
+
+ @NonNull
+ @Override
+ public String toString() {
+ return this.getTransitionType();
+ }
+ }
+
+ private final SKActivityType activityType;
+ private final SKTransitionType transitionType;
+
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param activityTypeCode The type of the activity
+ * @param transitionTypeCode TODO
+ */
+ public SKMotionActivityData(final long timestamp, final int activityTypeCode, final int transitionTypeCode) {
+
+ super(SKSensorType.MOTION_ACTIVITY, timestamp);
+
+ this.activityType = SKActivityType.valueOf(activityTypeCode);
+ this.transitionType = SKTransitionType.valueOf(transitionTypeCode);
+ }
+
+ /**
+ * Get the csv header of the Motion Activity sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Motion Activity sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,activityCode,activityString,transitionCode,transitionString";
+ }
+
+ /**
+ * Get the Motion Activity sensor data in csv format
+ *
+ * @return Activity data in csv format: timeIntervalSince1970, activity, activityString
+ *
+ */
+ @Override
+ @NonNull
+ public String getDataInCSV() {
+ return String.format(Locale.US, "%d,%d,%s", this.timestamp, this.activityType.getActivityTypeCode(), this.activityType.getActivityType());
+ }
+
+ /**
+ * Get the Motion Activity sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Motion Activity sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, activity, activityString, confidence
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("activity", this.activityType.getActivityTypeCode());
+ subJsonObject.put("activityString", this.activityType.getActivityType());
+ subJsonObject.put("transition", this.transitionType.getTransitionTypeCode());
+ subJsonObject.put("transitionString", this.transitionType.getTransitionType());
+
+ jsonObject.put("motionActivity", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+
+ /**
+ * Get the activity type
+ *
+ * @return Activity type
+ */
+ @SuppressWarnings("unused")
+ public SKActivityType getActivityType() {
+ return this.activityType;
+ }
+
+ /**
+ * Get the activity type
+ *
+ * @return Activity type
+ *
+ */
+ @SuppressWarnings("unused")
+ public SKTransitionType getTransitionType() {
+ return this.transitionType;
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKNotificationData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKNotificationData.java
new file mode 100644
index 0000000..2093246
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKNotificationData.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2017. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit https://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.data;
+
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
+
+import java.util.Locale;
+
+public class SKNotificationData extends SKAbstractData {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKNotificationData.class.getSimpleName();
+
+ private final String actionType;
+ private final String packageName;
+
+ /**
+ * TODO
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ */
+ public SKNotificationData(final long timestamp, final @NonNull String actionType, final @NonNull String packageName) {
+ super(SKSensorType.NOTIFICATION, timestamp);
+
+ this.actionType = actionType;
+ this.packageName = packageName;
+ }
+
+ /**
+ * Get the csv header of the Notification sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Notification sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,actionType,packageName";
+ }
+
+ /**
+ * Get the Notification sensor data in csv format
+ *
+ * @return Notification data in csv format: timeIntervalSince1970,actionType,packageName
+ */
+ @Override
+ @NonNull
+ public String getDataInCSV() {
+ return String.format(Locale.US, "%d,%s,%s", this.timestamp, this.actionType, this.packageName);
+ }
+
+
+ /**
+ * Get the Notification sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Notification sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, actionType, packageName
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("actionType", this.actionType);
+ subJsonObject.put("packageName", this.packageName);
+
+ jsonObject.put("notification", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get the notification action type (posted, removed)
+ *
+ * @return actionType (posted/removed)
+ */
+ @SuppressWarnings("unused")
+ public String getActionType() {
+ return this.actionType;
+ }
+
+ /**
+ * Get the notification package name
+ *
+ * @return package name
+ */
+ @SuppressWarnings("unused")
+ public String getPackageName() {
+ return this.packageName;
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKRotationData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKRotationData.java
index 51a7fc4..ab6d21d 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKRotationData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKRotationData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,24 +21,42 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKRotationData encapsulates measurements related to the Rotation sensor.
+ */
public class SKRotationData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKRotationData";
-
- protected final float x;
- protected final float y;
- protected final float z;
- protected final float cos;
- protected final float headingAccuracy;
-
- public SKRotationData(long timestamp, float x, float y, float z, float cos, float headingAccuracy) {
-
- super(SKSensorModuleType.ROTATION, timestamp);
+ private static final String TAG = SKRotationData.class.getSimpleName();
+
+ private final float x;
+ private final float y;
+ private final float z;
+ private final float cos;
+ private final float headingAccuracy;
+
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x Rotation axis x-component*sin(theta/2)
+ * @param y Rotation axis y-component*sin(theta/2)
+ * @param z Rotation axis z-component*sin(theta/2)
+ * @param cos Cos(theta)
+ *
+ * where theta is the angle of rotation
+ * @param headingAccuracy Estimated accuracy in radians
+ */
+ public SKRotationData(final long timestamp, final float x, final float y, final float z, final float cos, final float headingAccuracy) {
+ super(SKSensorType.ROTATION, timestamp);
this.x = x;
this.y = y;
@@ -47,35 +65,117 @@ public SKRotationData(long timestamp, float x, float y, float z, float cos, floa
this.headingAccuracy = headingAccuracy;
}
- public SKRotationData(long timestamp, float x, float y, float z) {
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param x Rotation axis x-component*sin(theta/2)
+ * @param y Rotation axis y-component*sin(theta/2)
+ * @param z Rotation axis z-component*sin(theta/2)
+ *
+ * where theta is the angle of rotation
+ */
+ public SKRotationData(final long timestamp, final float x, final float y, final float z) {
this(timestamp, x, y, z, 0, 0);
}
+ /**
+ * Get the csv header of the Rotation sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Rotation sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,x,y,z,cos,headingAccuracy";
+ }
+
+ /**
+ * Get Rotation sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, x, y, z, cos, headingAccuracy
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d,%f,%f,%f,%f,%f", this.timestamp, this.x, this.y, this.z, this.cos, this.headingAccuracy);
}
+ /**
+ * Get the Rotation sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Rotation sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, x, y, z, cos, headingAccuracy
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("x", this.x);
+ subJsonObject.put("y", this.y);
+ subJsonObject.put("z", this.z);
+ subJsonObject.put("cos", this.cos);
+ subJsonObject.put("headingAccuracy", this.headingAccuracy);
+
+ jsonObject.put("rotation", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get X component of rotation
+ *
+ * @return X component
+ */
@SuppressWarnings("unused")
public float getX() {
return this.x;
}
+ /**
+ * Get Y component of rotation
+ *
+ * @return Y component
+ */
@SuppressWarnings("unused")
- public float getY() {
+ public float getY() {
return this.y;
}
+ /**
+ * Get Z component of rotation
+ *
+ * @return Z component
+ */
@SuppressWarnings("unused")
public float getZ() {
return this.z;
}
+ /**
+ * Get cos of the angle of rotation
+ *
+ * @return Cos(theta)
+ */
@SuppressWarnings("unused")
public float getCos() {
return this.cos;
}
+ /**
+ * Get heading accuracy of rotation data
+ *
+ * @return Heading accuracy
+ */
@SuppressWarnings("unused")
public float getHeadingAccuracy() {
return this.headingAccuracy;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKScreenStatusData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKScreenStatusData.java
index 3f28892..1fbfec6 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKScreenStatusData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKScreenStatusData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,47 +21,117 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKScreenStatusData encapsulates measurements related to the Screen Status sensor.
+ */
public class SKScreenStatusData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKScreenStatusData";
+ private static final String TAG = SKScreenStatusData.class.getSimpleName();
public static final int SCREEN_OFF = 0;
public static final int SCREEN_ON = 1;
- public static final int SCREEN_UNKNOWN = 2;
-
- protected final int status;
+ public static final int SCREEN_UNLOCKED = 2;
+ public static final int SCREEN_UNKNOWN = 3;
- public SKScreenStatusData(long timestamp, int status) {
+ private final int status;
- super(SKSensorModuleType.SCREEN_STATUS, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param status Screen status
+ */
+ public SKScreenStatusData(final long timestamp, final int status) {
+ super(SKSensorType.SCREEN_STATUS, timestamp);
this.status = status;
}
+ /**
+ * Get the csv header of the Screen Status sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Screen Status sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,status,statusString";
+ }
+
+ /**
+ * Get Screen Status sensor data in CSV format
+ *
+ * @return String in CSV format: timestamp, status, statusString
+ */
@Override
+ @NonNull
public String getDataInCSV() {
- return String.format(Locale.US, "%d,%s", this.timestamp, this.getStatusString());
+ return String.format(Locale.US, "%d,%d,%s", this.timestamp, this.getStatus(), this.getStatusString());
}
+ /**
+ * Get Screen Status data in JSONObject format
+ *
+ * @return JSONObject containing the Screen Status data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, status, statusString
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ JSONObject subJsonObject = new JSONObject();
+ subJsonObject.put("status", this.getStatus());
+ subJsonObject.put("statusString", this.getStatusString());
+
+ jsonObject.put("screenStatus", subJsonObject);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
+ /**
+ * Get screen status
+ *
+ * @return Screen status as an int
+ */
@SuppressWarnings("unused")
public int getStatus() {
return this.status;
}
+ /**
+ * Get screen status as a string
+ *
+ * @return Screen status as a string: "off", "on", "unlocked" or "unknown"
+ */
@SuppressWarnings("unused")
public String getStatusString() {
switch (this.status) {
case SCREEN_OFF:
- return "screen off";
+ return "off";
case SCREEN_ON:
- return "screen on";
+ return "on";
+
+ case SCREEN_UNLOCKED:
+ return "unlocked";
default:
return "unknown";
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKSensorData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKSensorData.java
index b124970..92f1499 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKSensorData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKSensorData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,12 +21,20 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+
+import androidx.annotation.NonNull;
+
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.json.JSONObject;
@SuppressWarnings("unused")
public interface SKSensorData {
- SKSensorModuleType getSensorModuleType();
+ SKSensorType getSensorType();
+
+ @NonNull
String getDataInCSV();
-}
+ @NonNull
+ JSONObject getDataInJSON();
+}
\ No newline at end of file
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepCounterData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepCounterData.java
index f1d95ca..361b616 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepCounterData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepCounterData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,31 +21,87 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKStepCounterData encapsulates measurements related to the Step Counter sensor.
+ */
public class SKStepCounterData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKStepCounterData";
-
- protected final float steps;
+ private static final String TAG = SKStepCounterData.class.getSimpleName();
- public SKStepCounterData(long timestamp, float steps) {
+ private final int steps;
- super(SKSensorModuleType.STEP_COUNTER, timestamp);
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ * @param steps Number of steps
+ */
+ public SKStepCounterData(final long timestamp, final int steps) {
+ super(SKSensorType.STEP_COUNTER, timestamp);
this.steps = steps;
}
+ /**
+ * Get the csv header of the Step Counter sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Step Counter sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970,numberOfSteps";
+ }
+
+ /**
+ * Get Step Counter sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970, numberOfSteps
+ */
@Override
+ @NonNull
public String getDataInCSV() {
- return String.format(Locale.US, "%d,%f", this.timestamp, this.steps);
+ return String.format(Locale.US, "%d,%d", this.timestamp, this.steps);
+ }
+
+ /**
+ * Get the Step Counter sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Step Counter sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, numberOfSteps
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+ jsonObject.put("numberOfSteps", this.steps);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
}
+ /**
+ * Get number of steps
+ *
+ * @return number of steps
+ */
@SuppressWarnings("unused")
- public float getSteps() {
+ public int getSteps() {
return this.steps;
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepDetectorData.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepDetectorData.java
index 6f584fb..6531672 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepDetectorData.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepDetectorData.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -21,23 +21,74 @@
package org.sensingkit.sensingkitlib.data;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.sensingkit.sensingkitlib.SKSensorType;
import java.util.Locale;
+/**
+ * An instance of SKStepCounterData encapsulates measurements related to the Step Counter sensor.
+ */
public class SKStepDetectorData extends SKAbstractData {
@SuppressWarnings("unused")
- private static final String TAG = "SKStepDetectorData";
+ private static final String TAG = SKStepDetectorData.class.getSimpleName();
- public SKStepDetectorData(long timestamp) {
+ /**
+ * Initialize the instance
+ *
+ * @param timestamp Time in milliseconds (the difference between the current time and midnight, January 1, 1970 UTC)
+ */
+ public SKStepDetectorData(final long timestamp) {
- super(SKSensorModuleType.STEP_DETECTOR, timestamp);
+ super(SKSensorType.STEP_DETECTOR, timestamp);
}
+ /**
+ * Get the csv header of the Step Counter sensor data
+ *
+ * @return String with a CSV formatted header that describes the data of the Step Counter sensor.
+ */
+ @SuppressWarnings({"unused", "SameReturnValue"})
+ @NonNull
+ public static String csvHeader() {
+ return "timeIntervalSince1970";
+ }
+
+ /**
+ * Get Step Detector sensor data in CSV format
+ *
+ * @return String in CSV format: timeIntervalSince1970
+ */
@Override
+ @NonNull
public String getDataInCSV() {
return String.format(Locale.US, "%d", this.timestamp);
}
+
+ /**
+ * Get the Step Detector sensor data in JSONObject format
+ *
+ * @return JSONObject containing the Step Detector sensor data in JSONObject format:
+ * sensor type, sensor type in string, timeIntervalSince1970, numberOfSteps
+ */
+ @Override
+ @NonNull
+ public JSONObject getDataInJSON() {
+ JSONObject jsonObject = new JSONObject();
+ try {
+ jsonObject.put("sensorType", this.getSensorType());
+ jsonObject.put("sensorTypeString", this.getSensorType().toString());
+ jsonObject.put("timestamp", this.timestamp);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return jsonObject;
+ }
+
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractGoogleServicesSensorModule.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractGoogleServicesSensorModule.java
deleted file mode 100644
index 98c1567..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractGoogleServicesSensorModule.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.Context;
-import android.os.Bundle;
-
-import com.google.android.gms.common.ConnectionResult;
-import com.google.android.gms.common.api.GoogleApiClient;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-
-
-public abstract class SKAbstractGoogleServicesSensorModule extends SKAbstractSensorModule implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKAbstractGoogleServicesSensorModule";
-
- protected GoogleApiClient mClient;
-
- protected SKAbstractGoogleServicesSensorModule(final Context context, final SKSensorModuleType sensorModuleType) throws SKException {
- super(context, sensorModuleType);
-
-
- }
-
- protected abstract void serviceConnected();
-
- @Override
- public void onConnected(Bundle connectionHint) {
- serviceConnected();
- }
-
- @Override
- public void onConnectionSuspended(int cause) {
- // Ignore, will try to reconnect automatically
- }
-
- @Override
- public void onConnectionFailed(ConnectionResult result) {
- // At least one of the API client connect attempts failed
- // No client is connected
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractNativeSensorModule.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractNativeSensorModule.java
deleted file mode 100644
index 3b562a7..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractNativeSensorModule.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.os.Build;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-
-public abstract class SKAbstractNativeSensorModule extends SKAbstractSensorModule {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKAbstractNativeSensorModule";
-
- private final SensorManager mSensorManager;
- private final Sensor mSensor;
- private final SensorEventListener mSensorEventListener;
-
- protected SKAbstractNativeSensorModule(final Context context, final SKSensorModuleType sensorModuleType) throws SKException {
- super(context, sensorModuleType);
-
- mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- mSensor = mSensorManager.getDefaultSensor(getSensorType(sensorModuleType));
-
- mSensorEventListener = new SensorEventListener() {
-
- @Override
- public void onAccuracyChanged(Sensor sensor, int accuracy) {
- // Ignore
- }
-
- @Override
- public void onSensorChanged(SensorEvent event) {
-
- // Build the data object
- SKAbstractData data = buildData(event);
-
- // Submit sensor data object
- submitSensorData(data);
- }
- };
- }
-
- @Override
- public void startSensing() throws SKException {
-
- this.isSensing = true;
-
- boolean status = mSensorManager.registerListener(mSensorEventListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
-
- if (!status) {
- throw new SKException(TAG, "SensorModule '" + getSensorName() + "' could not be started.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
- }
-
- @Override
- public void stopSensing() {
-
- mSensorManager.unregisterListener(mSensorEventListener);
-
- this.isSensing = false;
- }
-
- protected abstract SKAbstractData buildData(SensorEvent event);
-
- @SuppressLint("InlinedApi") // There is a check in STEP_DETECTOR and STEP_COUNTER
- private static int getSensorType(SKSensorModuleType sensorType) throws SKException{
-
- switch (sensorType) {
-
- case ACCELEROMETER:
- return Sensor.TYPE_ACCELEROMETER;
-
- case GRAVITY:
- return Sensor.TYPE_GRAVITY;
-
- case LINEAR_ACCELERATION:
- return Sensor.TYPE_LINEAR_ACCELERATION;
-
- case GYROSCOPE:
- return Sensor.TYPE_GYROSCOPE;
-
- case ROTATION:
- return Sensor.TYPE_ROTATION_VECTOR;
-
- case MAGNETOMETER:
- return Sensor.TYPE_MAGNETIC_FIELD;
-
- case AMBIENT_TEMPERATURE:
- return Sensor.TYPE_AMBIENT_TEMPERATURE;
-
- case STEP_DETECTOR:
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- return Sensor.TYPE_STEP_DETECTOR;
- }
- else
- {
- throw new SKException(TAG, "STEP_DETECTOR requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- case STEP_COUNTER:
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- return Sensor.TYPE_STEP_COUNTER;
- }
- else
- {
- throw new SKException(TAG, "STEP_COUNTER requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- case LIGHT:
- return Sensor.TYPE_LIGHT;
-
- case LOCATION:
- case ACTIVITY:
- case BATTERY:
- throw new SKException(TAG, "Not a native SensorModule.", SKExceptionErrorCode.UNKNOWN_ERROR);
-
- default:
- throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
-
- }
- }
-
-}
\ No newline at end of file
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractSensorModule.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractSensorModule.java
deleted file mode 100644
index 8cf134f..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractSensorModule.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.Context;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
-import org.sensingkit.sensingkitlib.SKSensorDataListener;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-
-import java.util.ArrayList;
-
-public abstract class SKAbstractSensorModule implements SKSensorModuleInterface {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKAbstractSensorModule";
-
- protected final Context mApplicationContext;
- protected final SKSensorModuleType mSensorModuleType;
- protected boolean isSensing = false;
- protected ArrayList mSensorDataListeners;
-
- protected SKAbstractSensorModule(final Context context, final SKSensorModuleType sensorModuleType) {
-
- this.mApplicationContext = context;
- this.mSensorModuleType = sensorModuleType;
- }
-
- public boolean isSensing() {
- return isSensing;
- }
-
- public SKSensorModuleType getSensorType() {
- return this.mSensorModuleType;
- }
-
- public String getSensorName() throws SKException {
- return SKSensorModuleUtilities.getSensorModuleInString(mSensorModuleType);
- }
-
- public void subscribeSensorDataListener(SKSensorDataListener callback) throws SKException {
-
- // Init the list
- if (this.mSensorDataListeners == null) {
- this.mSensorDataListeners = new ArrayList<>();
- }
-
- // Register the callback
- if (this.mSensorDataListeners.contains(callback)) {
- throw new SKException(TAG, "SKSensorDataListener already registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- this.mSensorDataListeners.add(callback);
- }
-
- public void unsubscribeSensorDataListener(SKSensorDataListener callback) throws SKException {
-
- // Unregister the callback
- if (this.mSensorDataListeners == null || !this.mSensorDataListeners.remove(callback)) {
- throw new SKException(TAG, "SKSensorDataListener is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- // Delete the callBackList if it is empty
- if (this.mSensorDataListeners.size() == 0) {
- this.mSensorDataListeners = null;
- }
- }
-
- public void unsubscribeAllSensorDataListeners() throws SKException {
-
- // Clear all callbacks
- if (this.mSensorDataListeners != null) {
- this.mSensorDataListeners.clear();
- this.mSensorDataListeners = null;
- }
- }
-
- protected abstract boolean shouldPostSensorData(SKAbstractData data);
-
- protected void submitSensorData(SKAbstractData data) {
-
- // If there is a significant change
- if (shouldPostSensorData(data)) {
-
- if (mSensorDataListeners != null) {
-
- // CallBack with data as parameter
- for (SKSensorDataListener callback : mSensorDataListeners) {
- callback.onDataReceived(mSensorModuleType, data);
- }
- }
- }
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivity.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivity.java
deleted file mode 100644
index 401d75e..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivity.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.support.v4.content.LocalBroadcastManager;
-import android.util.Log;
-import com.google.android.gms.location.ActivityRecognitionApi;
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.location.ActivityRecognition;
-import com.google.android.gms.location.ActivityRecognitionResult;
-import com.google.android.gms.location.DetectedActivity;
-
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-import org.sensingkit.sensingkitlib.data.SKActivityData;
-
-public class SKActivity extends SKAbstractGoogleServicesSensorModule {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKActivity";
-
- private ActivityRecognitionApi mActivityRecognition;
- private PendingIntent mRecognitionPendingIntent;
- private BroadcastReceiver mBroadcastReceiver;
-
- // Last data sensed
- private int mLastActivityTypeSensed = Integer.MAX_VALUE;
- private int mLastConfidenceSensed = Integer.MAX_VALUE;
-
- public SKActivity(final Context context) throws SKException {
- super(context, SKSensorModuleType.ACTIVITY);
-
- mClient = new GoogleApiClient.Builder(context)
- .addApi(ActivityRecognition.API)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .build();
-
- mActivityRecognition = ActivityRecognition.ActivityRecognitionApi;
-
- mBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
-
- ActivityRecognitionResult result = intent.getParcelableExtra(SKActivityRecognitionIntentService.RECOGNITION_RESULT);
-
- // Get activity from the list of activities
- DetectedActivity activity = getActivity(result);
-
- // Get the type of activity
- int activityType = activity.getType();
-
- // Get the confidence percentage for the most probable activity
- int confidence = activity.getConfidence();
-
- // Build the data object
- SKAbstractData data = new SKActivityData(result.getTime(), activityType, confidence);
-
- // Submit sensor data object
- submitSensorData(data);
- }
- };
- }
-
- private DetectedActivity getActivity(ActivityRecognitionResult result) {
-
- // Get the most probable activity from the list of activities in the result
- DetectedActivity mostProbableActivity = result.getMostProbableActivity();
-
- // If the activity is ON_FOOT, choose between WALKING or RUNNING
- if (mostProbableActivity.getType() == DetectedActivity.ON_FOOT) {
-
- // Iterate through all possible activities. The activities are sorted by most probable activity first.
- for (DetectedActivity activity : result.getProbableActivities()) {
-
- if (activity.getType() == DetectedActivity.WALKING || activity.getType() == DetectedActivity.RUNNING) {
- return activity;
- }
- }
-
- // It is ON_FOOT, but not sure if it is WALKING or RUNNING
- Log.i(TAG, "Activity ON_FOOT, but not sure if it is WALKING or RUNNING.");
- return mostProbableActivity;
- }
- else
- {
- return mostProbableActivity;
- }
-
- }
-
- @Override
- public void startSensing() {
-
- this.isSensing = true;
-
- mClient.connect();
- }
-
- @Override
- public void stopSensing() {
-
- unregisterIntent();
- unregisterLocalBroadcastManager();
-
- mClient.disconnect();
-
- this.isSensing = false;
-
- // Clear last sensed values
- mLastActivityTypeSensed = Integer.MAX_VALUE;
- mLastConfidenceSensed = Integer.MAX_VALUE;
- }
-
- @Override
- protected void serviceConnected()
- {
- Log.i(TAG, "GoogleApiClient Connected!");
-
- registerLocalBroadcastManager();
- registerIntent();
- }
-
- private void registerIntent() {
-
- if (mRecognitionPendingIntent == null) {
- Intent intent = new Intent(mApplicationContext, SKActivityRecognitionIntentService.class);
- mRecognitionPendingIntent = PendingIntent.getService(mApplicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- }
-
- mActivityRecognition.requestActivityUpdates(mClient, 0, mRecognitionPendingIntent);
- }
-
- private void unregisterIntent() {
-
- mActivityRecognition.removeActivityUpdates(mClient, mRecognitionPendingIntent);
- mRecognitionPendingIntent.cancel();
- mRecognitionPendingIntent = null;
- }
-
- private void registerLocalBroadcastManager() {
- LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplicationContext);
- manager.registerReceiver(mBroadcastReceiver, new IntentFilter(SKActivityRecognitionIntentService.BROADCAST_UPDATE));
- }
-
- private void unregisterLocalBroadcastManager() {
- LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplicationContext);
- manager.unregisterReceiver(mBroadcastReceiver);
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // Only post when specific values changed
-
- int activityType = ((SKActivityData)data).getActivityType();
- int confidence = ((SKActivityData)data).getConfidence();
-
- // Ignore Temperature and Voltage
- boolean shouldPost = (mLastActivityTypeSensed != activityType ||
- mLastConfidenceSensed != confidence );
-
- if (shouldPost) {
-
- this.mLastActivityTypeSensed = activityType;
- this.mLastConfidenceSensed = confidence;
- }
-
- return shouldPost;
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivityRecognitionIntentService.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivityRecognitionIntentService.java
deleted file mode 100644
index 2738806..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivityRecognitionIntentService.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.support.v4.content.LocalBroadcastManager;
-
-import com.google.android.gms.location.ActivityRecognitionResult;
-
-public class SKActivityRecognitionIntentService extends IntentService {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKActivityRecognitionIntentService";
-
- public static final String RECOGNITION_RESULT = "result";
- public static final String BROADCAST_UPDATE = "new_update";
-
- public SKActivityRecognitionIntentService() {
-
- // Set the label for the service's background thread
- super("ActivityRecognitionIntentService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
-
- // If the intent contains an update
- if (ActivityRecognitionResult.hasResult(intent)) {
-
- // Get the update
- ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
-
- Intent i = new Intent(BROADCAST_UPDATE);
- i.putExtra(RECOGNITION_RESULT, result);
- LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
- manager.sendBroadcast(i);
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioLevel.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioLevel.java
deleted file mode 100644
index 7a62f21..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioLevel.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.Context;
-import android.media.AudioFormat;
-import android.media.AudioRecord;
-import android.media.MediaRecorder;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-import org.sensingkit.sensingkitlib.data.SKAudioLevelData;
-
-public class SKAudioLevel extends SKAbstractSensorModule {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKAudioLevel";
-
- private static final int sampleRate = 8000;
- private static final int bufferSizeFactor = 1;
-
- private final int bufferSize = AudioRecord.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) * bufferSizeFactor;
-
- private final AudioRecord audioRecord;
-
- public SKAudioLevel(final Context context) throws SKException {
- super(context, SKSensorModuleType.AUDIO_LEVEL);
-
- // Configure the AudioRecord
- audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // Always post sensor data
- return true;
- }
-
- @Override
- public void startSensing() {
-
- this.isSensing = true;
-
- // monitor audio
- audioRecord.startRecording();
-
- // init the thread that read the audio buffer
- Thread thread = new Thread(new Runnable() {
- public void run() {
- readAudioBuffer();
- }
- });
-
- // Set priority to max and start the thread that reads the audio level
- thread.setPriority(Thread.currentThread().getThreadGroup().getMaxPriority());
- thread.start();
- }
-
- @Override
- public void stopSensing() {
-
- audioRecord.stop();
-
- this.isSensing = false;
- }
-
- private void readAudioBuffer() {
-
- short[] buffer = new short[bufferSize];
-
- int bufferReadResult;
-
- do {
- // read buffer
- bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
-
- // get max audio level
- int level = getMaxAbs(buffer);
-
- // Build the data object
- SKAbstractData data = new SKAudioLevelData(System.currentTimeMillis(), level);
-
- // Submit sensor data object
- submitSensorData(data);
- }
- while (bufferReadResult > 0 && audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING);
- }
-
- // Get the Max Abs of the raw data
- private int getMaxAbs(short[] raw) {
-
- int max = Math.abs(raw[0]);
-
- for (int i = 1 ; i < raw.length; i++)
- {
- max = Math.max(max, Math.abs(raw[i]));
- }
-
- return max;
- }
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioRecorder.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioRecorder.java
deleted file mode 100644
index 9f447be..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioRecorder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.Context;
-import android.media.MediaRecorder;
-import android.os.Environment;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-
-import java.io.IOException;
-
-public class SKAudioRecorder extends SKAbstractSensorModule {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKAudioRecorder";
-
- private static final String outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.aac";
-
- private final MediaRecorder recorder;
-
- public SKAudioRecorder(final Context context) throws SKException {
- super(context, SKSensorModuleType.AUDIO_RECORDER);
-
- recorder = new MediaRecorder();
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
- recorder.setOutputFile(outputFile);
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // This sensor does not post data
- return false;
- }
-
- @Override
- public void startSensing() throws SKException {
-
- this.isSensing = true;
-
- try {
- recorder.prepare();
- } catch (IOException e) {
- e.printStackTrace();
- throw new SKException(TAG, "AudioRecorder sensor could not be prepared.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- recorder.start();
- }
-
- @Override
- public void stopSensing() {
-
- this.isSensing = false;
-
- recorder.stop();
- recorder.reset();
- recorder.release();
- }
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBattery.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBattery.java
deleted file mode 100644
index c2efefd..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBattery.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-import org.sensingkit.sensingkitlib.data.SKBatteryData;
-
-public class SKBattery extends SKAbstractSensorModule {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKBattery";
-
- // Last data sensed
- private int mLastLevelSensed = Integer.MAX_VALUE;
- private int mLastScaleSensed = Integer.MAX_VALUE;
- private int mLastTemperatureSensed = Integer.MAX_VALUE;
- private int mLastVoltageSensed = Integer.MAX_VALUE;
- private int mLastPluggedSensed = Integer.MAX_VALUE;
- private int mLastStatusSensed = Integer.MAX_VALUE;
- private int mLastHealthSensed = Integer.MAX_VALUE;
-
- private final BroadcastReceiver mBroadcastReceiver;
-
- public SKBattery(final Context context) throws SKException {
- super(context, SKSensorModuleType.BATTERY);
-
- mBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
-
- // Read Battery
- int level = intent.getIntExtra("level", -1);
- int scale = intent.getIntExtra("scale", -1);
- int temperature = intent.getIntExtra("temperature", 0);
- int voltage = intent.getIntExtra("voltage", 0);
- int plugged = intent.getIntExtra("plugged", -1);
- int status = intent.getIntExtra("status", 0);
- int health = intent.getIntExtra("health", 0);
-
- // Build the data object
- SKAbstractData data = new SKBatteryData(System.currentTimeMillis(), level, scale, temperature, voltage, plugged, status, health);
-
- // Submit sensor data object
- submitSensorData(data);
- }
- };
- }
-
- @Override
- public void startSensing() {
-
- this.isSensing = true;
-
- registerLocalBroadcastManager();
- }
-
- @Override
- public void stopSensing() {
-
- unregisterLocalBroadcastManager();
-
- this.isSensing = false;
-
- // Clear last sensed values
- mLastLevelSensed = Integer.MAX_VALUE;
- mLastScaleSensed = Integer.MAX_VALUE;
- mLastTemperatureSensed = Integer.MAX_VALUE;
- mLastVoltageSensed = Integer.MAX_VALUE;
- mLastPluggedSensed = Integer.MAX_VALUE;
- mLastStatusSensed = Integer.MAX_VALUE;
- mLastHealthSensed = Integer.MAX_VALUE;
- }
-
- private void registerLocalBroadcastManager() {
- IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
- mApplicationContext.registerReceiver(mBroadcastReceiver, filter);
- }
-
- private void unregisterLocalBroadcastManager() {
- mApplicationContext.unregisterReceiver(mBroadcastReceiver);
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // Only post when specific values changed
-
- int level = ((SKBatteryData)data).getLevel();
- int scale = ((SKBatteryData)data).getScale();
- int temperature = ((SKBatteryData)data).getTemperature();
- int voltage = ((SKBatteryData)data).getVoltage();
- int plugged = ((SKBatteryData)data).getPlugged();
- int status = ((SKBatteryData)data).getBatteryStatus();
- int health = ((SKBatteryData)data).getBatteryHealth();
-
- // Ignore Temperature and Voltage
- boolean shouldPost = (mLastLevelSensed != level ||
- mLastScaleSensed != scale ||
- mLastPluggedSensed != plugged ||
- mLastStatusSensed != status ||
- mLastHealthSensed != health );
-
- if (shouldPost) {
- this.mLastLevelSensed = level;
- this.mLastScaleSensed = scale;
- this.mLastTemperatureSensed = temperature;
- this.mLastVoltageSensed = voltage;
- this.mLastPluggedSensed = plugged;
- this.mLastStatusSensed = status;
- this.mLastHealthSensed = health;
- }
-
- return shouldPost;
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLocation.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLocation.java
deleted file mode 100644
index 1d267fd..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLocation.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.Context;
-import android.util.Log;
-
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.location.LocationListener;
-import com.google.android.gms.location.LocationRequest;
-import com.google.android.gms.location.LocationServices;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-import org.sensingkit.sensingkitlib.data.SKLocationData;
-
-public class SKLocation extends SKAbstractGoogleServicesSensorModule implements LocationListener {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKLocation";
-
- public SKLocation(final Context context) throws SKException {
- super(context, SKSensorModuleType.LOCATION);
-
- mClient = new GoogleApiClient.Builder(context)
- .addApi(LocationServices.API)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .build();
- }
-
- @Override
- public void startSensing() {
-
- this.isSensing = true;
-
- mClient.connect();
- }
-
- @Override
- public void stopSensing() {
-
- unregisterForLocationUpdates();
- mClient.disconnect();
-
- this.isSensing = false;
- }
-
- @Override
- protected void serviceConnected()
- {
- Log.i(TAG, "GoogleApiClient Connected!");
-
- registerForLocationUpdates();
- }
-
- @Override
- public void onLocationChanged(android.location.Location location) {
-
- // Build the data object
- SKAbstractData data = new SKLocationData(System.currentTimeMillis(), location);
-
- // Submit sensor data object
- submitSensorData(data);
- }
-
- private void registerForLocationUpdates() {
-
- LocationRequest locationRequest = LocationRequest.create();
- locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
- locationRequest.setInterval(1000); // Update location every second
-
- LocationServices.FusedLocationApi.requestLocationUpdates(mClient, locationRequest, this);
- }
-
- private void unregisterForLocationUpdates() {
-
- LocationServices.FusedLocationApi.removeLocationUpdates(mClient, this);
-
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // Always post sensor data
- return true;
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKScreenStatus.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKScreenStatus.java
deleted file mode 100644
index 73e4166..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKScreenStatus.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-import org.sensingkit.sensingkitlib.data.SKAbstractData;
-import org.sensingkit.sensingkitlib.data.SKScreenStatusData;
-
-public class SKScreenStatus extends SKAbstractSensorModule {
-
- private final BroadcastReceiver mBroadcastReceiver;
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKScreenStatus";
-
- public SKScreenStatus(final Context context) throws SKException {
- super(context, SKSensorModuleType.SCREEN_STATUS);
-
- mBroadcastReceiver = new BroadcastReceiver() {
-
- @Override
- public void onReceive(Context context, Intent intent) {
-
- // Read Status
- int status;
-
- if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
- status = SKScreenStatusData.SCREEN_OFF;
- } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
- status = SKScreenStatusData.SCREEN_ON;
- } else {
- status = SKScreenStatusData.SCREEN_UNKNOWN;
- }
-
- // Build the data object
- SKAbstractData data = new SKScreenStatusData(System.currentTimeMillis(), status);
-
- // Submit sensor data object
- submitSensorData(data);
- }
- };
- }
-
- @Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
-
- // Always post sensor data
- return true;
- }
-
- @Override
- public void startSensing() {
-
- this.isSensing = true;
-
- registerLocalBroadcastManager();
- }
-
- @Override
- public void stopSensing() {
-
- unregisterLocalBroadcastManager();
-
- this.isSensing = false;
- }
-
- private void registerLocalBroadcastManager() {
-
- // Register for SCREEN_STATUS ON and OFF notifications
- mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
- mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
- }
-
- private void unregisterLocalBroadcastManager() {
- mApplicationContext.unregisterReceiver(mBroadcastReceiver);
- }
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleUtilities.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleUtilities.java
deleted file mode 100644
index da40807..0000000
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleUtilities.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
- *
- * This file is part of SensingKit-Android library.
- * For more information, please visit http://www.sensingkit.org
- *
- * SensingKit-Android is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SensingKit-Android is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with SensingKit-Android. If not, see .
- */
-
-package org.sensingkit.sensingkitlib.modules;
-
-import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
-
-public final class SKSensorModuleUtilities {
-
- @SuppressWarnings("unused")
- private static final String TAG = "SKSensorModuleUtilities";
-
- public static String getSensorModuleInString(SKSensorModuleType moduleType) throws SKException {
-
- switch (moduleType) {
-
- case ACCELEROMETER:
- return "Accelerometer";
-
- case GRAVITY:
- return "Gravity";
-
- case LINEAR_ACCELERATION:
- return "Linear Acceleration";
-
- case GYROSCOPE:
- return "Gyroscope";
-
- case ROTATION:
- return "Rotation";
-
- case MAGNETOMETER:
- return "Magnetometer";
-
- case AMBIENT_TEMPERATURE:
- return "Ambient Temperature";
-
- case STEP_DETECTOR:
- return "Step Detector";
-
- case STEP_COUNTER:
- return "Step Counter";
-
- case LIGHT:
- return "Light";
-
- case LOCATION:
- return "Location";
-
- case ACTIVITY:
- return "Activity";
-
- case BATTERY:
- return "Battery";
-
- case SCREEN_STATUS:
- return "Screen Status";
-
- case AUDIO_RECORDER:
- return "Audio Recorder";
-
- case AUDIO_LEVEL:
- return "Audio Level";
-
- case BLUETOOTH:
- return "Bluetooth";
-
- default:
- throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
-
- }
-
-}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractNativeSensor.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractNativeSensor.java
new file mode 100644
index 0000000..10afb5c
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractNativeSensor.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKAbstractNativeSensorConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+
+@SuppressWarnings("WeakerAccess")
+public abstract class SKAbstractNativeSensor extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKAbstractNativeSensor.class.getSimpleName();
+
+ private SensorManager mSensorManager;
+ private Sensor mSensor;
+ private SensorEventListener mSensorEventListener;
+
+ protected SKAbstractNativeSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) throws SKException {
+ super(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensor");}
+
+ mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
+
+ if (mSensorManager == null) {
+ throw new SKException(TAG, "Could not access the system service: SENSOR_SERVICE.", SKExceptionErrorCode.UNKNOWN_ERROR);
+ }
+
+ mSensor = mSensorManager.getDefaultSensor(getSensorType(sensorType));
+
+ if (mSensor == null) {
+ throw new SKException(TAG, "Sensor [" + sensorType.getName() + "] is not available in the device.", SKExceptionErrorCode.SENSOR_NOT_AVAILABLE);
+ }
+
+ mSensorEventListener = new SensorEventListener() {
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ // Ignore
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+
+ // Build the data object
+ SKAbstractData data = buildData(event);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensor [" + sensorType.getName() + "]");}
+
+ // Not required for this type of sensor
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // Get the configuration
+ SKAbstractNativeSensorConfiguration configuration = (SKAbstractNativeSensorConfiguration)mConfiguration;
+
+ boolean status = mSensorManager.registerListener(mSensorEventListener, mSensor, configuration.getSamplingRate());
+
+ if (!status) {
+ throw new SKException(TAG, "Sensor '" + getSensorName() + "' could not be started.", SKExceptionErrorCode.SENSOR_ERROR);
+ }
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ mSensorManager.unregisterListener(mSensorEventListener);
+
+ super.stopSensing();
+ }
+
+ @NonNull
+ protected abstract SKAbstractData buildData(final SensorEvent event);
+
+ @SuppressLint("InlinedApi") // There is a check in SKSensorManager
+ private static int getSensorType(final SKSensorType sensorType) {
+
+ switch (sensorType) {
+
+ case ACCELEROMETER:
+ return Sensor.TYPE_ACCELEROMETER;
+
+ case GRAVITY:
+ return Sensor.TYPE_GRAVITY;
+
+ case LINEAR_ACCELERATION:
+ return Sensor.TYPE_LINEAR_ACCELERATION;
+
+ case GYROSCOPE:
+ return Sensor.TYPE_GYROSCOPE;
+
+ case ROTATION:
+ return Sensor.TYPE_ROTATION_VECTOR;
+
+ case MAGNETOMETER:
+ return Sensor.TYPE_MAGNETIC_FIELD;
+
+ case AMBIENT_TEMPERATURE:
+ return Sensor.TYPE_AMBIENT_TEMPERATURE;
+
+ case STEP_DETECTOR:
+ return Sensor.TYPE_STEP_DETECTOR;
+
+ case STEP_COUNTER:
+ return Sensor.TYPE_STEP_COUNTER;
+
+ case LIGHT:
+ return Sensor.TYPE_LIGHT;
+
+ case HUMIDITY:
+ return Sensor.TYPE_RELATIVE_HUMIDITY;
+
+ case BAROMETER:
+ return Sensor.TYPE_PRESSURE;
+
+ default:
+ throw new RuntimeException("Sensor '" + sensorType.getName() + "' is not a native sensor.");
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractSensor.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractSensor.java
new file mode 100644
index 0000000..f880d27
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAbstractSensor.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.Context;
+import androidx.annotation.CallSuper;
+import androidx.annotation.NonNull;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
+import org.sensingkit.sensingkitlib.SKSensorDataHandler;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+
+import java.util.ArrayList;
+
+@SuppressWarnings("WeakerAccess")
+public abstract class SKAbstractSensor implements SKSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKAbstractSensor.class.getSimpleName();
+
+ protected final Context mApplicationContext;
+ protected final SKSensorType mSensorType;
+ protected boolean isSensing = false;
+ protected SKConfiguration mConfiguration;
+
+ private ArrayList mSensorDataListeners;
+
+ protected SKAbstractSensor(final @NonNull Context context, final SKSensorType sensorType, final @NonNull SKConfiguration configuration) throws SKException {
+
+ // Check if the correct configuration type provided
+ if (!configuration.isValidForSensor(sensorType)) {
+ throw new SKException(TAG, "Wrong SKConfiguration class provided (" + configuration.getClass() + ") for sensor " + sensorType.getName() + ".",
+ SKExceptionErrorCode.CONFIGURATION_NOT_VALID);
+ }
+
+ this.mApplicationContext = context;
+ this.mSensorType = sensorType;
+ this.mConfiguration = configuration;
+
+ // call sensor init method
+ initSensor(context, sensorType, configuration);
+ }
+
+ protected abstract void initSensor(final @NonNull Context context, final SKSensorType sensorType, final @NonNull SKConfiguration configuration) throws SKException;
+
+ @SuppressWarnings("unused")
+ protected abstract void updateSensor(final @NonNull Context context, final SKSensorType sensorType, final @NonNull SKConfiguration configuration) throws SKException;
+
+ @CallSuper
+ public void startSensing() throws SKException {
+ this.isSensing = true;
+ }
+
+ @CallSuper
+ public void stopSensing() throws SKException {
+ this.isSensing = false;
+ }
+
+ public boolean isSensing() {
+ return isSensing;
+ }
+
+ public SKSensorType getSensorType() {
+ return this.mSensorType;
+ }
+
+ @NonNull
+ public String getSensorName() {
+ return mSensorType.getName();
+ }
+
+ @Override
+ public void setConfiguration(final @NonNull SKConfiguration configuration) throws SKException {
+
+ // Check if the correct configuration type provided
+ if (!configuration.isValidForSensor(mSensorType)) {
+ throw new SKException(TAG, "Wrong SKConfiguration class provided (" + configuration.getClass() + ") for sensor " + mSensorType.getName() + ".",
+ SKExceptionErrorCode.CONFIGURATION_NOT_VALID);
+ }
+
+ this.mConfiguration = configuration;
+
+ // call update sensor configuration
+ updateSensor(mApplicationContext, mSensorType, configuration);
+ }
+
+ public void subscribeSensorDataHandler(final @NonNull SKSensorDataHandler handler) throws SKException {
+
+ // Init the list
+ if (this.mSensorDataListeners == null) {
+ this.mSensorDataListeners = new ArrayList<>();
+ }
+
+ // Register the callback
+ if (this.mSensorDataListeners.contains(handler)) {
+ throw new SKException(TAG, "SKSensorDataHandler already registered.", SKExceptionErrorCode.DATA_HANDLER_ALREADY_REGISTERED);
+ }
+
+ this.mSensorDataListeners.add(handler);
+ }
+
+ public void unsubscribeSensorDataHandler(final @NonNull SKSensorDataHandler handler) throws SKException {
+
+ // Unregister the callback
+ if (this.mSensorDataListeners == null || !this.mSensorDataListeners.remove(handler)) {
+ throw new SKException(TAG, "SKSensorDataHandler is not registered.", SKExceptionErrorCode.DATA_HANDLER_NOT_REGISTERED);
+ }
+
+ // Delete the callBackList if it is empty
+ if (this.mSensorDataListeners.size() == 0) {
+ this.mSensorDataListeners = null;
+ }
+ }
+
+ public void unsubscribeAllSensorDataHandlers() {
+
+ // Clear all callbacks
+ if (this.mSensorDataListeners != null) {
+ this.mSensorDataListeners.clear();
+ this.mSensorDataListeners = null;
+ }
+ }
+
+ protected abstract boolean shouldPostSensorData(final @NonNull SKAbstractData data);
+
+ protected boolean shouldDebugSensor() {
+ return mConfiguration.getDebugStatus();
+ }
+
+ protected void submitSensorData(final @NonNull SKAbstractData data) {
+
+ // If there is a significant change
+ if (shouldPostSensorData(data)) {
+
+ if (mSensorDataListeners != null) {
+
+ // CallBack with data as parameter
+ for (SKSensorDataHandler callback : mSensorDataListeners) {
+ callback.onDataReceived(mSensorType, data);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void sensorDeregistered() {
+ // Override this method in the sensor subclass if needed.
+ }
+
+ @Override
+ public String[] getRequiredPermissions() {
+ // Override this method in the sensor subclass if a special permission is needed.
+ return new String[]{};
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAccelerometer.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAccelerometer.java
similarity index 55%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAccelerometer.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAccelerometer.java
index 53256c2..01900c4 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAccelerometer.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAccelerometer.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKAccelerometerConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKAccelerometerData;
-public class SKAccelerometer extends SKAbstractNativeSensorModule {
+public class SKAccelerometer extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKAccelerometer";
+ private static final String TAG = SKAccelerometer.class.getSimpleName();
- public SKAccelerometer(final Context context) throws SKException {
- super(context, SKSensorModuleType.ACCELEROMETER);
+ public SKAccelerometer(final Context context, final @NonNull SKAccelerometerConfiguration configuration) throws SKException {
+ super(context, SKSensorType.ACCELEROMETER, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final SensorEvent event) {
return new SKAccelerometerData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKAccelerometerConfiguration((SKAccelerometerConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAmbientTemperature.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAmbientTemperature.java
similarity index 57%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAmbientTemperature.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAmbientTemperature.java
index a2e5ea8..f1c1e62 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAmbientTemperature.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAmbientTemperature.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKAmbientTemperatureConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKAmbientTemperatureData;
-public class SKAmbientTemperature extends SKAbstractNativeSensorModule {
+public class SKAmbientTemperature extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKAmbientTemperature";
+ private static final String TAG = SKAmbientTemperature.class.getSimpleName();
- public SKAmbientTemperature(final Context context) throws SKException {
- super(context, SKSensorModuleType.AMBIENT_TEMPERATURE);
+ public SKAmbientTemperature(final Context context, final @NonNull SKAmbientTemperatureConfiguration configuration) throws SKException {
+ super(context, SKSensorType.AMBIENT_TEMPERATURE, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final SensorEvent event) {
return new SKAmbientTemperatureData(System.currentTimeMillis(), event.values[0]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKAmbientTemperatureConfiguration((SKAmbientTemperatureConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAudioLevel.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAudioLevel.java
new file mode 100644
index 0000000..46f3cfa
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKAudioLevel.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.Manifest;
+import android.content.Context;
+import android.media.AudioFormat;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKAudioLevelConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKAudioLevelData;
+
+public class SKAudioLevel extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKAudioLevel.class.getSimpleName();
+
+ private static final int sampleRate = 8000;
+ private static final int bufferSizeFactor = 1;
+
+ private int bufferSize;
+
+ private AudioRecord audioRecord;
+
+ public SKAudioLevel(final Context context, final SKAudioLevelConfiguration configuration) throws SKException {
+ super(context, SKSensorType.AUDIO_LEVEL, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ this.bufferSize = AudioRecord.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) * bufferSizeFactor;
+ Log.i(TAG, "Init sensor with BufferSize: " + this.bufferSize);
+
+ // Configure the AudioRecord
+ this.audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+
+ // Not required for this type of sensor
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKAudioLevelConfiguration((SKAudioLevelConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // monitor audio
+ audioRecord.startRecording();
+
+ // init the thread that read the audio buffer
+ Thread thread = new Thread(this::readAudioBuffer);
+
+ // Set priority to max and start the thread that reads the audio level
+ thread.setPriority(Thread.currentThread().getThreadGroup().getMaxPriority());
+ thread.start();
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ audioRecord.stop();
+
+ super.stopSensing();
+ }
+
+ private void readAudioBuffer() {
+
+ short[] buffer = new short[bufferSize];
+
+ int bufferReadResult;
+
+ do {
+ // read buffer
+ bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
+
+ // get max audio level
+ int level = getMaxAbs(buffer);
+
+ // Build the data object
+ SKAbstractData data = new SKAudioLevelData(System.currentTimeMillis(), level);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ while (bufferReadResult > 0 && audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING);
+ }
+
+ // Get the Max Abs of the raw data
+ private int getMaxAbs(final short[] raw) {
+
+ int max = Math.abs(raw[0]);
+
+ for (int i = 1 ; i < raw.length; i++)
+ {
+ max = Math.max(max, Math.abs(raw[i]));
+ }
+
+ return max;
+ }
+
+ @Override
+ public void sensorDeregistered() {
+ super.sensorDeregistered();
+
+ // Release sensor
+ audioRecord.release();
+ }
+
+ @Override
+ public String[] getRequiredPermissions() {
+ return new String[]{Manifest.permission.RECORD_AUDIO};
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBarometer.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBarometer.java
new file mode 100644
index 0000000..9985a7e
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBarometer.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.Context;
+import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKBarometerConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKBarometerData;
+
+public class SKBarometer extends SKAbstractNativeSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKBarometer.class.getSimpleName();
+
+ public SKBarometer(final Context context, final SKBarometerConfiguration configuration) throws SKException {
+ super(context, SKSensorType.BAROMETER, configuration);
+ }
+
+ @Override
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
+ return new SKBarometerData(System.currentTimeMillis(), event.values[0]);
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKBarometerConfiguration((SKBarometerConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBatteryStatus.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBatteryStatus.java
new file mode 100644
index 0000000..17ba803
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBatteryStatus.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKBatteryStatusConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKBatteryStatusData;
+
+@SuppressWarnings("unused")
+public class SKBatteryStatus extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKBatteryStatus.class.getSimpleName();
+
+ // Last data sensed
+ private int mLastLevelSensed = Integer.MAX_VALUE;
+ private int mLastScaleSensed = Integer.MAX_VALUE;
+ private int mLastTemperatureSensed = Integer.MAX_VALUE;
+ private int mLastVoltageSensed = Integer.MAX_VALUE;
+ private SKBatteryStatusData.SKBatteryPlugged mLastPluggedSensed = null;
+ private SKBatteryStatusData.SKBatteryStatus mLastStatusSensed = null;
+ private SKBatteryStatusData.SKBatteryHealth mLastHealthSensed = null;
+
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ // Read Battery
+ int level = intent.getIntExtra("level", -1);
+ int scale = intent.getIntExtra("scale", -1);
+ int temperature = intent.getIntExtra("temperature", 0);
+ int voltage = intent.getIntExtra("voltage", 0);
+ int plugged = intent.getIntExtra("plugged", -1);
+ int status = intent.getIntExtra("status", 0);
+ int health = intent.getIntExtra("health", 0);
+
+ // Build the data object
+ SKAbstractData data = new SKBatteryStatusData(System.currentTimeMillis(), level, scale, temperature, voltage, plugged, status, health);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ public SKBatteryStatus(final Context context, SKBatteryStatusConfiguration configuration) throws SKException {
+ super(context, SKSensorType.BATTERY_STATUS, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ registerLocalBroadcastManager();
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ unregisterLocalBroadcastManager();
+
+ super.stopSensing();
+
+ // Clear last sensed values
+ mLastLevelSensed = Integer.MAX_VALUE;
+ mLastScaleSensed = Integer.MAX_VALUE;
+ mLastTemperatureSensed = Integer.MAX_VALUE;
+ mLastVoltageSensed = Integer.MAX_VALUE;
+ mLastPluggedSensed = null;
+ mLastStatusSensed = null;
+ mLastHealthSensed = null;
+ }
+
+ private void registerLocalBroadcastManager() {
+ IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ mApplicationContext.registerReceiver(mBroadcastReceiver, filter);
+ }
+
+ private void unregisterLocalBroadcastManager() {
+ mApplicationContext.unregisterReceiver(mBroadcastReceiver);
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKBatteryStatusConfiguration((SKBatteryStatusConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Only post when specific values changed
+
+ // Cast into SKBatteryStatusData
+ SKBatteryStatusData batteryData = (SKBatteryStatusData)data;
+
+ // Read values
+ int level = batteryData.getLevel();
+ int scale = batteryData.getScale();
+ int temperature = batteryData.getTemperature();
+ int voltage = batteryData.getVoltage();
+ SKBatteryStatusData.SKBatteryPlugged plugged = batteryData.getBatteryPlugged();
+ SKBatteryStatusData.SKBatteryStatus status = batteryData.getBatteryStatus();
+ SKBatteryStatusData.SKBatteryHealth health = batteryData.getBatteryHealth();
+
+ // Ignore Temperature and Voltage
+ boolean shouldPost = (mLastLevelSensed != level ||
+ mLastScaleSensed != scale ||
+ mLastPluggedSensed != plugged ||
+ mLastStatusSensed != status ||
+ mLastHealthSensed != health );
+
+ if (shouldPost) {
+
+ // Save last sensed values
+ this.mLastLevelSensed = level;
+ this.mLastScaleSensed = scale;
+ this.mLastTemperatureSensed = temperature;
+ this.mLastVoltageSensed = voltage;
+ this.mLastPluggedSensed = plugged;
+ this.mLastStatusSensed = status;
+ this.mLastHealthSensed = health;
+ }
+
+ return shouldPost;
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBeaconProximity.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBeaconProximity.java
new file mode 100644
index 0000000..8eb7f3d
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBeaconProximity.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2016. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit https://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.RemoteException;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.altbeacon.beacon.Beacon;
+import org.altbeacon.beacon.BeaconConsumer;
+import org.altbeacon.beacon.BeaconManager;
+import org.altbeacon.beacon.BeaconParser;
+import org.altbeacon.beacon.Identifier;
+import org.altbeacon.beacon.RangeNotifier;
+import org.altbeacon.beacon.Region;
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKBeaconProximityConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKBeaconProximityConfiguration.SKBeaconType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKBeaconProximityCollectionData;
+import org.sensingkit.sensingkitlib.data.SKBeaconProximityData;
+
+import java.util.ArrayList;
+
+@SuppressWarnings("ResourceType")
+public class SKBeaconProximity extends SKAbstractSensor implements BeaconConsumer {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKBeaconProximity.class.getSimpleName();
+
+ private static final String BEACON_RANGING_IDENTIFIER = "org.sensingkit.beaconRangingIdentifier";
+
+ private BeaconManager mBeaconManager;
+ private Region mRegion;
+
+ private final RangeNotifier mRangeNotifier = (beacons, region) -> {
+
+ if (beacons.size() > 0) {
+
+ // Get the timestamp
+ long timestamp = System.currentTimeMillis();
+
+ // Create the SKBeaconProximityData objects and add them to a new list
+ ArrayList deviceData = new ArrayList<>(beacons.size());
+
+ for (Beacon beacon : beacons) {
+ deviceData.add(new SKBeaconProximityData(timestamp, beacon));
+ }
+
+ // Build the data object
+ SKAbstractData data = new SKBeaconProximityCollectionData(timestamp, deviceData);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ public SKBeaconProximity(final @NonNull Context context, final @NonNull SKBeaconProximityConfiguration configuration) throws SKException {
+ super(context, SKSensorType.BEACON_PROXIMITY, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ // Init BeaconManager
+ mBeaconManager = BeaconManager.getInstanceForApplication(mApplicationContext);
+ //BeaconManager.setDebug(true); // Debug only
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+
+ // Unbind first if needed
+ if (mBeaconManager.isBound(this)) {
+ mBeaconManager.unbind(this);
+ }
+
+ // Cast the configuration instance
+ SKBeaconProximityConfiguration beaconProximityConfiguration = (SKBeaconProximityConfiguration) configuration;
+
+ // Configure BeaconParsers
+ mBeaconManager.getBeaconParsers().clear();
+ String layout = SKBeaconProximity.getBeaconLayout(beaconProximityConfiguration.getBeaconType());
+ mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(layout));
+
+ // Configure Region
+ Identifier id1 = (beaconProximityConfiguration.getFilterId1() != null? Identifier.parse(beaconProximityConfiguration.getFilterId1()) : null);
+ Identifier id2 = (beaconProximityConfiguration.getFilterId2() != null? Identifier.parse(beaconProximityConfiguration.getFilterId2()) : null);
+ Identifier id3 = (beaconProximityConfiguration.getFilterId3() != null? Identifier.parse(beaconProximityConfiguration.getFilterId3()) : null);
+ mRegion = new Region(BEACON_RANGING_IDENTIFIER, id1, id2, id3);
+
+ // Bind
+ mBeaconManager.bind(this);
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKBeaconProximityConfiguration((SKBeaconProximityConfiguration)mConfiguration);
+ }
+
+ @Override
+ public void onBeaconServiceConnect() {
+ if (shouldDebugSensor()) {Log.i(TAG, "onBeaconServiceConnect [" + mSensorType.getName() + "]");}
+ }
+
+ @Override
+ public Context getApplicationContext() {
+ return mApplicationContext;
+ }
+
+ @Override
+ public void unbindService(final @NonNull ServiceConnection serviceConnection) {
+ if (shouldDebugSensor()) {Log.i(TAG, "unbindService [" + mSensorType.getName() + "]");}
+
+ mApplicationContext.unbindService(serviceConnection);
+ }
+
+ @Override
+ public boolean bindService(final @NonNull Intent intent, final @NonNull ServiceConnection serviceConnection, final int i) {
+ if (shouldDebugSensor()) {Log.i(TAG, "bindService [" + mSensorType.getName() + "]");}
+
+ return mApplicationContext.bindService(intent, serviceConnection, i);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // Register the callback
+ mBeaconManager.removeAllRangeNotifiers();
+ mBeaconManager.addRangeNotifier(mRangeNotifier);
+
+ try {
+ mBeaconManager.startRangingBeaconsInRegion(mRegion);
+
+ } catch (RemoteException ex) {
+ Log.e(TAG, ex.toString());
+ throw new SKException(TAG, "Beacon Proximity sensor could not be started on this device.", SKExceptionErrorCode.SENSOR_ERROR);
+ }
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ try {
+ mBeaconManager.stopRangingBeaconsInRegion(mRegion);
+ super.stopSensing();
+
+ } catch (RemoteException ex) {
+ throw new SKException(TAG, "Beacon Proximity sensor could not be stopped.", SKExceptionErrorCode.SENSOR_ERROR);
+ }
+ }
+
+ @Override
+ public void sensorDeregistered() {
+ super.sensorDeregistered();
+
+ // Remove callback
+ mBeaconManager.removeRangeNotifier(mRangeNotifier);
+
+ // Release sensor
+ mBeaconManager.unbind(this);
+ }
+
+ private static String getBeaconLayout(final SKBeaconType beaconType) {
+
+ switch (beaconType) {
+
+ case ALTBEACON:
+ return BeaconParser.ALTBEACON_LAYOUT;
+
+ case IBEACON:
+ return "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24";
+
+ case EDDYSTONE_UID:
+ return BeaconParser.EDDYSTONE_UID_LAYOUT;
+
+ //case EDDYSTONE_TLM:
+ // return BeaconParser.EDDYSTONE_TLM_LAYOUT;
+
+ //case EDDYSTONE_URL:
+ // return BeaconParser.EDDYSTONE_URL_LAYOUT;
+
+ default:
+ throw new RuntimeException();
+ }
+ }
+
+ @Override
+ public String[] getRequiredPermissions() {
+ return new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBluetooth.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBluetooth.java
similarity index 59%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBluetooth.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBluetooth.java
index 513344d..58aa17b 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBluetooth.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKBluetooth.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2015. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,42 +19,40 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
+import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import androidx.annotation.NonNull;
+import android.util.Log;
import org.sensingkit.sensingkitlib.SKException;
import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKBluetoothConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKBluetoothCollectionData;
import org.sensingkit.sensingkitlib.data.SKBluetoothData;
-import org.sensingkit.sensingkitlib.data.SKBluetoothDeviceData;
import java.util.ArrayList;
@SuppressWarnings("ResourceType")
-public class SKBluetooth extends SKAbstractSensorModule {
+public class SKBluetooth extends SKAbstractSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKBluetooth";
+ private static final String TAG = SKBluetooth.class.getSimpleName();
- private final BluetoothAdapter mBluetoothAdapter;
- private ArrayList mBluetoothDevices;
+ private BluetoothAdapter mBluetoothAdapter;
+ private ArrayList mBluetoothDevices;
- public SKBluetooth(Context context) throws SKException {
- super(context, SKSensorModuleType.BLUETOOTH);
-
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mBluetoothDevices = new ArrayList<>();
-
- if (mBluetoothAdapter == null) {
- throw new SKException(TAG, "Bluetooth sensor module is not supported from the device.", SKExceptionErrorCode.UNKNOWN_ERROR);
- }
+ public SKBluetooth(final @NonNull Context context, final @NonNull SKBluetoothConfiguration configuration) throws SKException {
+ super(context, SKSensorType.BLUETOOTH, configuration);
}
// Create a BroadcastReceiver for ACTION_FOUND and ACTION_DISCOVERY_FINISHED
@@ -76,13 +74,13 @@ public void onReceive(Context context, Intent intent) {
int rssi = (int) intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
// Create SKBluetoothDevice and add to mBluetoothDevices array
- SKBluetoothDeviceData deviceData = new SKBluetoothDeviceData(System.currentTimeMillis(), name, address, rssi);
+ SKBluetoothData deviceData = new SKBluetoothData(System.currentTimeMillis(), name, address, rssi);
mBluetoothDevices.add(deviceData);
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { // Discovery Finished
// Build the data object
- SKAbstractData data = new SKBluetoothData(System.currentTimeMillis(), mBluetoothDevices);
+ SKAbstractData data = new SKBluetoothCollectionData(System.currentTimeMillis(), mBluetoothDevices);
// Clean the arrayList
mBluetoothDevices = new ArrayList<>();
@@ -97,7 +95,34 @@ public void onReceive(Context context, Intent intent) {
};
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothDevices = new ArrayList<>();
+
+ if (mBluetoothAdapter == null) {
+ throw new SKException(TAG, "Bluetooth sensor is not supported from the device.", SKExceptionErrorCode.SENSOR_NOT_AVAILABLE);
+ }
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKBluetoothConfiguration((SKBluetoothConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
@@ -105,16 +130,17 @@ protected boolean shouldPostSensorData(SKAbstractData data) {
@Override
public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
if (mBluetoothAdapter == null) {
- throw new SKException(TAG, "Bluetooth sensor module is not supported from the device.", SKExceptionErrorCode.UNKNOWN_ERROR);
+ throw new SKException(TAG, "Bluetooth sensor is not supported from the device.", SKExceptionErrorCode.SENSOR_NOT_AVAILABLE);
}
if (!mBluetoothAdapter.isEnabled()) {
- throw new SKException(TAG, "Bluetooth is not enabled.", SKExceptionErrorCode.UNKNOWN_ERROR);
+ throw new SKException(TAG, "Bluetooth is not enabled.", SKExceptionErrorCode.SENSOR_ERROR);
}
- this.isSensing = true;
+ super.startSensing();
registerLocalBroadcastManager();
@@ -123,14 +149,15 @@ public void startSensing() throws SKException {
}
@Override
- public void stopSensing() {
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
// Stop Bluetooth Scanning
mBluetoothAdapter.cancelDiscovery();
unregisterLocalBroadcastManager();
- this.isSensing = false;
+ super.stopSensing();
}
private void registerLocalBroadcastManager() {
@@ -145,4 +172,9 @@ private void registerLocalBroadcastManager() {
private void unregisterLocalBroadcastManager() {
mApplicationContext.unregisterReceiver(mReceiver);
}
+
+ @Override
+ public String[] getRequiredPermissions() {
+ return new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN};
+ }
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGravity.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGravity.java
similarity index 56%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGravity.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGravity.java
index ef89cf9..98ab542 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGravity.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGravity.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKGravityConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKGravityData;
-public class SKGravity extends SKAbstractNativeSensorModule {
+public class SKGravity extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKGravity";
+ private static final String TAG = SKGravity.class.getSimpleName();
- public SKGravity(final Context context) throws SKException {
- super(context, SKSensorModuleType.GRAVITY);
+ public SKGravity(final @NonNull Context context, final @NonNull SKGravityConfiguration configuration) throws SKException {
+ super(context, SKSensorType.GRAVITY, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKGravityData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKGravityConfiguration((SKGravityConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGyroscope.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGyroscope.java
similarity index 56%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGyroscope.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGyroscope.java
index 370e841..4f6fd2b 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGyroscope.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKGyroscope.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKGyroscopeConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKGyroscopeData;
-public class SKGyroscope extends SKAbstractNativeSensorModule {
+public class SKGyroscope extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKGyroscope";
+ private static final String TAG = SKGyroscope.class.getSimpleName();
- public SKGyroscope(final Context context) throws SKException {
- super(context, SKSensorModuleType.GYROSCOPE);
+ public SKGyroscope(final @NonNull Context context, final @NonNull SKGyroscopeConfiguration configuration) throws SKException {
+ super(context, SKSensorType.GYROSCOPE, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKGyroscopeData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKGyroscopeConfiguration((SKGyroscopeConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKHumidity.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKHumidity.java
new file mode 100644
index 0000000..3d94dfd
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKHumidity.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.Context;
+import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKHumidityConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKHumidityData;
+
+public class SKHumidity extends SKAbstractNativeSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKHumidity.class.getSimpleName();
+
+ public SKHumidity(final @NonNull Context context, final @NonNull SKHumidityConfiguration configuration) throws SKException {
+ super(context, SKSensorType.HUMIDITY, configuration);
+ }
+
+ @Override
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
+ return new SKHumidityData(System.currentTimeMillis(), event.values[0]);
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKHumidityConfiguration((SKHumidityConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLight.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLight.java
similarity index 61%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLight.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLight.java
index df76ac0..03d6a53 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLight.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLight.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,35 +19,44 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKLightConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKLightData;
-public class SKLight extends SKAbstractNativeSensorModule {
+public class SKLight extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKLight";
+ private static final String TAG = SKLight.class.getSimpleName();
private float lastLightSensed = Float.MAX_VALUE;
- public SKLight(final Context context) throws SKException {
- super(context, SKSensorModuleType.LIGHT);
+ public SKLight(final @NonNull Context context, final @NonNull SKLightConfiguration configuration) throws SKException {
+ super(context, SKSensorType.LIGHT, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKLightData(System.currentTimeMillis(), event.values[0]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKLightConfiguration((SKLightConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Only post when light value changes
@@ -62,7 +71,7 @@ protected boolean shouldPostSensorData(SKAbstractData data) {
return shouldPost;
}
- public void stopSensing() {
+ public void stopSensing() throws SKException {
super.stopSensing();
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLinearAcceleration.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLinearAcceleration.java
similarity index 57%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLinearAcceleration.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLinearAcceleration.java
index c2dfd01..dd4906f 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLinearAcceleration.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLinearAcceleration.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKLinearAccelerationConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKLinearAccelerationData;
-public class SKLinearAcceleration extends SKAbstractNativeSensorModule {
+public class SKLinearAcceleration extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKLinearAcceleration";
+ private static final String TAG = SKLinearAcceleration.class.getSimpleName();
- public SKLinearAcceleration(final Context context) throws SKException {
- super(context, SKSensorModuleType.LINEAR_ACCELERATION);
+ public SKLinearAcceleration(final @NonNull Context context, final @NonNull SKLinearAccelerationConfiguration configuration) throws SKException {
+ super(context, SKSensorType.LINEAR_ACCELERATION, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKLinearAccelerationData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKLinearAccelerationConfiguration((SKLinearAccelerationConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLocation.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLocation.java
new file mode 100644
index 0000000..f3fd14e
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKLocation.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.location.Location;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import com.google.android.gms.location.FusedLocationProviderClient;
+import com.google.android.gms.location.LocationCallback;
+import com.google.android.gms.location.LocationRequest;
+import com.google.android.gms.location.LocationResult;
+import com.google.android.gms.location.LocationServices;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKLocationConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKLocationData;
+
+
+public class SKLocation extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKLocation.class.getSimpleName();
+
+ private FusedLocationProviderClient mFusedLocationClient;
+ private LocationRequest mLocationRequest;
+
+ private final LocationCallback mLocationCallback = new LocationCallback() {
+ @Override
+ public void onLocationResult(LocationResult locationResult) {
+ super.onLocationResult(locationResult);
+
+ if (locationResult == null) {
+ if (shouldDebugSensor()) {Log.i(TAG, "locationResult is null");}
+ return;
+ }
+
+ // Build the data object
+ Location location = locationResult.getLastLocation();
+ SKAbstractData data = new SKLocationData(System.currentTimeMillis(), location);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ public SKLocation(final @NonNull Context context, final @NonNull SKLocationConfiguration configuration) throws SKException {
+ super(context, SKSensorType.LOCATION, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+
+ // Cast the configuration instance
+ SKLocationConfiguration locationConfiguration = (SKLocationConfiguration)mConfiguration;
+
+ // Configure the LocationRequest
+ mLocationRequest = LocationRequest.create();
+ mLocationRequest.setPriority(locationConfiguration.getPriority().getPriorityCode());
+ mLocationRequest.setInterval(locationConfiguration.getInterval());
+ mLocationRequest.setFastestInterval(locationConfiguration.getFastestInterval());
+ }
+
+ @SuppressLint("MissingPermission")
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // Start the request
+ mFusedLocationClient.requestLocationUpdates(mLocationRequest,
+ mLocationCallback,
+ null);
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ mFusedLocationClient.removeLocationUpdates(mLocationCallback);
+
+ super.stopSensing();
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKLocationConfiguration((SKLocationConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public String[] getRequiredPermissions() {
+ return new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKMagnetometer.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMagnetometer.java
similarity index 55%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKMagnetometer.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMagnetometer.java
index 4320821..962cc06 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKMagnetometer.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMagnetometer.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKMagnetometerConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKMagnetometerData;
-public class SKMagnetometer extends SKAbstractNativeSensorModule {
+public class SKMagnetometer extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKMagnetometer";
+ private static final String TAG = SKMagnetometer.class.getSimpleName();
- public SKMagnetometer(final Context context) throws SKException {
- super(context, SKSensorModuleType.MAGNETOMETER);
+ public SKMagnetometer(final @NonNull Context context, final @NonNull SKMagnetometerConfiguration configuration) throws SKException {
+ super(context, SKSensorType.MAGNETOMETER, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKMagnetometerData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKMagnetometerConfiguration((SKMagnetometerConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMicrophone.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMicrophone.java
new file mode 100644
index 0000000..84dd72c
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMicrophone.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.Manifest;
+import android.content.Context;
+import android.media.MediaRecorder;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKMicrophoneConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKMicrophoneData;
+
+import java.io.IOException;
+
+public class SKMicrophone extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKMicrophone.class.getSimpleName();
+
+ private MediaRecorder mMediaRecorder;
+
+ public SKMicrophone(final @NonNull Context context, final @NonNull SKMicrophoneConfiguration configuration) throws SKException {
+ super(context, SKSensorType.MICROPHONE, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ mMediaRecorder = new MediaRecorder();
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+
+ // Cast the configuration instance
+ SKMicrophoneConfiguration microphoneConfiguration = (SKMicrophoneConfiguration)configuration;
+
+ // Check if permission to file writing is granted
+ if (!microphoneConfiguration.getOutputDirectory().canWrite()) {
+ throw new SKException(TAG, "Microphone sensor does not have the permission to record in the following outputDirectory: " +
+ microphoneConfiguration.getRecordingPath() + ".", SKExceptionErrorCode.FILE_WRITER_PERMISSION_DENIED);
+ }
+
+ // Check if file already exists
+ if (microphoneConfiguration.getRecordingFile().exists()) {
+ throw new SKException(TAG, "Filename already exists (" +
+ microphoneConfiguration.getRecordingFile() + ").", SKExceptionErrorCode.FILE_ALREADY_EXISTS);
+ }
+
+ mMediaRecorder.reset();
+
+ // Set configuration
+ mMediaRecorder.setAudioSource(microphoneConfiguration.getAudioSource().getAudioSourceCode());
+ mMediaRecorder.setOutputFormat(microphoneConfiguration.getOutputFormat().getOutputFormatCode());
+ mMediaRecorder.setAudioEncoder(microphoneConfiguration.getAudioEncoder().getAudioEncoderCode());
+ mMediaRecorder.setOutputFile(microphoneConfiguration.getRecordingPath());
+ mMediaRecorder.setAudioEncodingBitRate(microphoneConfiguration.getBitrate());
+ mMediaRecorder.setAudioSamplingRate(microphoneConfiguration.getSamplingRate());
+ mMediaRecorder.setAudioChannels(microphoneConfiguration.getAudioChannels());
+
+ // Prepare for recording
+ try {
+ mMediaRecorder.prepare();
+ } catch (IOException e) {
+ Log.e(TAG, e.getLocalizedMessage());
+ throw new SKException(TAG, "Microphone sensor could not be prepared.", SKExceptionErrorCode.SENSOR_ERROR);
+ }
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKMicrophoneConfiguration((SKMicrophoneConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ mMediaRecorder.start();
+
+ // Build the data object
+ SKAbstractData data = new SKMicrophoneData(System.currentTimeMillis(), "Started");
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ // Stop recording
+ mMediaRecorder.stop();
+
+ // Build the data object
+ SKAbstractData data = new SKMicrophoneData(System.currentTimeMillis(), "Stopped");
+
+ // Submit sensor data object
+ submitSensorData(data);
+
+ super.stopSensing();
+ }
+
+ @Override
+ public void sensorDeregistered() {
+ super.sensorDeregistered();
+
+ // Release sensor
+ mMediaRecorder.reset();
+ mMediaRecorder.release();
+ }
+
+ @Override
+ public String[] getRequiredPermissions() {
+ return new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE};
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivity.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivity.java
new file mode 100644
index 0000000..d553327
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivity.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.annotation.SuppressLint;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import androidx.annotation.NonNull;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+import android.util.Log;
+
+import com.google.android.gms.location.ActivityRecognition;
+import com.google.android.gms.location.ActivityRecognitionClient;
+import com.google.android.gms.location.ActivityTransition;
+import com.google.android.gms.location.ActivityTransitionRequest;
+import com.google.android.gms.location.DetectedActivity;
+import com.google.android.gms.tasks.Task;
+
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKMotionActivityConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKMotionActivityData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SKMotionActivity extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKMotionActivity.class.getSimpleName();
+
+ private ActivityRecognitionClient mActivityRecognitionClient;
+ private PendingIntent mActivityRecognitionPendingIntent;
+ private List mRegisteredTransitions;
+ private LocalBroadcastManager mLocalBroadcastManager;
+
+ public SKMotionActivity(final @NonNull Context context, final @NonNull SKMotionActivityConfiguration configuration) throws SKException {
+ super(context, SKSensorType.MOTION_ACTIVITY, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+
+ mActivityRecognitionClient = ActivityRecognition.getClient(mApplicationContext);
+ mLocalBroadcastManager = LocalBroadcastManager.getInstance(mApplicationContext);
+
+ Intent intent = new Intent(mApplicationContext, SKMotionActivityIntentService.class);
+ mActivityRecognitionPendingIntent = PendingIntent.getService(mApplicationContext, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+
+ // Cast the configuration instance
+ SKMotionActivityConfiguration motionActivityConfiguration = (SKMotionActivityConfiguration)mConfiguration;
+
+ // update transitions
+ mRegisteredTransitions = buildTransitions(motionActivityConfiguration);
+ }
+
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ int activityType = intent.getIntExtra("activityType", -1);
+ int transitionType = intent.getIntExtra("transitionType", -1);
+ //long timestamp = intent.getLongExtra("elapsedRealTimeNanos", -1); // TODO: fix
+
+ // Build the data object
+ SKAbstractData data = new SKMotionActivityData(System.currentTimeMillis(), activityType, transitionType);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ private @NonNull List buildTransitions(final @NonNull SKMotionActivityConfiguration configuration) {
+
+ // reset list
+ List transitions = new ArrayList<>();
+
+ if (configuration.getTrackStationary()) {
+ registerTrackedActivity(transitions, DetectedActivity.STILL);
+ }
+
+ if (configuration.getTrackWalking()) {
+ registerTrackedActivity(transitions, DetectedActivity.WALKING);
+ }
+
+ if (configuration.getTrackRunning()) {
+ registerTrackedActivity(transitions, DetectedActivity.RUNNING);
+ }
+
+ if (configuration.getTrackAutomotive()) {
+ registerTrackedActivity(transitions, DetectedActivity.IN_VEHICLE);
+ }
+
+ if (configuration.getTrackCycling()) {
+ registerTrackedActivity(transitions, DetectedActivity.ON_BICYCLE);
+ }
+
+ return transitions;
+ }
+
+ private void registerTrackedActivity(@NonNull List transitions, final int activity) {
+ if (shouldDebugSensor()) {Log.i(TAG, "registerTrackedActivity");}
+
+ transitions.add(
+ new ActivityTransition.Builder()
+ .setActivityType(activity)
+ .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
+ .build());
+
+ transitions.add(
+ new ActivityTransition.Builder()
+ .setActivityType(activity)
+ .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
+ .build());
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // Register Receiver
+ IntentFilter filter = new IntentFilter(SKMotionActivityIntentService.ACTIVITY_TRANSITION_ACTION);
+ mLocalBroadcastManager.registerReceiver(mBroadcastReceiver, filter);
+
+ assert(mRegisteredTransitions != null);
+ ActivityTransitionRequest request = new ActivityTransitionRequest(mRegisteredTransitions);
+
+ @SuppressLint("MissingPermission")
+ Task task = mActivityRecognitionClient.requestActivityTransitionUpdates(request, mActivityRecognitionPendingIntent);
+
+ task.addOnSuccessListener(
+ result -> {
+ // Handle success
+ }
+ );
+
+ task.addOnFailureListener(
+ e -> Log.e(TAG, e.getMessage())
+ );
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ @SuppressLint("MissingPermission")
+ Task task = mActivityRecognitionClient.removeActivityTransitionUpdates(mActivityRecognitionPendingIntent);
+
+ task.addOnSuccessListener(
+ result -> mActivityRecognitionPendingIntent.cancel());
+
+ task.addOnFailureListener(
+ e -> Log.e(TAG, e.getMessage()));
+
+ // Unregister receiver
+ this.mLocalBroadcastManager.unregisterReceiver(mBroadcastReceiver);
+
+ super.stopSensing();
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKMotionActivityConfiguration((SKMotionActivityConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivityIntentService.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivityIntentService.java
new file mode 100644
index 0000000..194f2cb
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKMotionActivityIntentService.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.app.IntentService;
+import android.content.Intent;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+
+import com.google.android.gms.location.ActivityTransitionEvent;
+import com.google.android.gms.location.ActivityTransitionResult;
+
+public class SKMotionActivityIntentService extends IntentService {
+
+ public static final String ACTIVITY_TRANSITION_ACTION = "org.sensingkit.SensingKit-Android.SKMotionActivityIntentService";
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKMotionActivityIntentService.class.getSimpleName();
+
+ private final LocalBroadcastManager mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
+
+ public SKMotionActivityIntentService() {
+
+ // Set the label for the service's background thread
+ super("SKMotionActivityIntentService");
+ }
+
+ @Override
+ protected void onHandleIntent(final Intent intent) {
+
+ if (intent == null) {
+ return;
+ }
+
+ // If the intent contains an update
+ if (ActivityTransitionResult.hasResult(intent)) {
+
+ // Get the update
+ ActivityTransitionResult result = ActivityTransitionResult.extractResult(intent);
+
+ if (result == null) {
+ return;
+ }
+
+ for (ActivityTransitionEvent event : result.getTransitionEvents()) {
+ // chronological sequence of events.
+
+ Intent i = new Intent(ACTIVITY_TRANSITION_ACTION);
+ i.putExtra("activityType", event.getActivityType());
+ i.putExtra("transitionType", event.getTransitionType());
+ i.putExtra("elapsedRealTimeNanos", event.getElapsedRealTimeNanos());
+
+ // send the broadcast to the SKMotionActivity.BroadcastReceiver
+ mLocalBroadcastManager.sendBroadcast(i);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotification.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotification.java
new file mode 100644
index 0000000..b001df1
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotification.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2017. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit https://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKNotificationConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKNotificationData;
+
+public class SKNotification extends SKAbstractSensor {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKNotification.class.getSimpleName();
+
+ private final BroadcastReceiver mNotificationReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ if (isSensing) {
+
+ // Get properties
+ String actionType = intent.getStringExtra("actionType");
+ long postTime = intent.getLongExtra("postTime", -1);
+ String packageName = intent.getStringExtra("packageName");
+
+ // Build the data object
+ SKAbstractData data = new SKNotificationData(postTime, actionType, packageName);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+
+ }
+ };
+
+ public SKNotification(final @NonNull Context context, final @NonNull SKNotificationConfiguration configuration) throws SKException {
+ super(context, SKSensorType.NOTIFICATION, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKNotificationConfiguration((SKNotificationConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ // Register Receiver
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ IntentFilter filter = new IntentFilter(SKNotificationListenerService.NOTIFICATION_ACTION);
+ mApplicationContext.registerReceiver(mNotificationReceiver, filter);
+ }
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ // Unregister receiver
+ mApplicationContext.unregisterReceiver(mNotificationReceiver);
+
+ super.stopSensing();
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotificationListenerService.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotificationListenerService.java
new file mode 100644
index 0000000..13b25de
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKNotificationListenerService.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2017. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit https://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.Intent;
+import android.os.Build;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
+import android.util.Log;
+
+@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
+public class SKNotificationListenerService extends NotificationListenerService {
+
+ public static final String NOTIFICATION_ACTION = "org.sensingkit.SensingKit-Android.SKNotificationListenerService";
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKNotificationListenerService.class.getSimpleName();
+
+ @Override
+ public void onListenerConnected() {
+ Log.i(TAG, "Connected!");
+ }
+
+ @Override
+ public void onNotificationPosted(final StatusBarNotification sbn) {
+ sendNotification("posted", sbn);
+ }
+
+ @Override
+ public void onNotificationRemoved(final StatusBarNotification sbn) {
+ sendNotification("removed", sbn);
+ }
+
+ private void sendNotification(final @NonNull String actionType, final @NonNull StatusBarNotification sbn) {
+
+ // Build intent
+ Intent i = new Intent(NOTIFICATION_ACTION);
+ i.putExtra("actionType", actionType);
+ i.putExtra("postTime", sbn.getPostTime());
+ i.putExtra("packageName", sbn.getPackageName());
+
+ // send the broadcast to the SKNotification.NotificationServiceReceiver
+ this.sendBroadcast(i);
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKRotation.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKRotation.java
similarity index 60%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKRotation.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKRotation.java
index 82b359f..bd74288 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKRotation.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKRotation.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,28 +19,31 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKRotationConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKRotationData;
-public class SKRotation extends SKAbstractNativeSensorModule {
+public class SKRotation extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKRotation";
+ private static final String TAG = SKRotation.class.getSimpleName();
- public SKRotation(final Context context) throws SKException {
- super(context, SKSensorModuleType.ROTATION);
+ public SKRotation(final Context context, final SKRotationConfiguration configuration) throws SKException {
+ super(context, SKSensorType.ROTATION, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
if (event.values.length >= 6) {
return new SKRotationData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2], event.values[3], event.values[4]);
}
@@ -50,7 +53,13 @@ protected SKAbstractData buildData(SensorEvent event)
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKRotationConfiguration((SKRotationConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKScreenStatus.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKScreenStatus.java
new file mode 100644
index 0000000..9f2ac97
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKScreenStatus.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2015. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import androidx.annotation.NonNull;
+import android.util.Log;
+
+import org.sensingkit.sensingkitlib.SKException;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKScreenStatusConfiguration;
+import org.sensingkit.sensingkitlib.data.SKAbstractData;
+import org.sensingkit.sensingkitlib.data.SKScreenStatusData;
+
+public class SKScreenStatus extends SKAbstractSensor {
+
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ // Read Status
+ int status;
+
+ String action = intent.getAction();
+
+ if (action == null) {
+ status = SKScreenStatusData.SCREEN_UNKNOWN;
+ }
+ else {
+ switch (action) {
+ case Intent.ACTION_SCREEN_OFF:
+ status = SKScreenStatusData.SCREEN_OFF;
+ break;
+ case Intent.ACTION_SCREEN_ON:
+ status = SKScreenStatusData.SCREEN_ON;
+ break;
+ case Intent.ACTION_USER_PRESENT:
+ status = SKScreenStatusData.SCREEN_UNLOCKED;
+ break;
+ default:
+ status = SKScreenStatusData.SCREEN_UNKNOWN;
+ break;
+ }
+ }
+
+ // Build the data object
+ SKAbstractData data = new SKScreenStatusData(System.currentTimeMillis(), status);
+
+ // Submit sensor data object
+ submitSensorData(data);
+ }
+ };
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKScreenStatus.class.getSimpleName();
+
+ public SKScreenStatus(final @NonNull Context context, final @NonNull SKScreenStatusConfiguration configuration) throws SKException {
+ super(context, SKSensorType.SCREEN_STATUS, configuration);
+ }
+
+ @Override
+ protected void initSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "initSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+
+ // configure sensor
+ updateSensor(context, sensorType, configuration);
+ }
+
+ @Override
+ protected void updateSensor(@NonNull Context context, SKSensorType sensorType, @NonNull SKConfiguration configuration) {
+ if (shouldDebugSensor()) {Log.i(TAG, "updateSensing [" + mSensorType.getName() + "]");}
+ // Not required for this type of sensor
+ }
+
+ @Override
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKScreenStatusConfiguration((SKScreenStatusConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
+
+ // Always post sensor data
+ return true;
+ }
+
+ @Override
+ public void startSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "startSensing [" + mSensorType.getName() + "]");}
+
+ super.startSensing();
+
+ registerLocalBroadcastManager();
+ }
+
+ @Override
+ public void stopSensing() throws SKException {
+ if (shouldDebugSensor()) {Log.i(TAG, "stopSensing [" + mSensorType.getName() + "]");}
+
+ unregisterLocalBroadcastManager();
+
+ super.stopSensing();
+ }
+
+ private void registerLocalBroadcastManager() {
+
+ // Register for SCREEN_STATUS ON, OFF and UNLOCKED (USER_PRESENT) notifications
+ mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
+ mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
+ mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_USER_PRESENT));
+ }
+
+ private void unregisterLocalBroadcastManager() {
+ mApplicationContext.unregisterReceiver(mBroadcastReceiver);
+ }
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleInterface.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensor.java
similarity index 50%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleInterface.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensor.java
index 94bbc18..3d01b86 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleInterface.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensor.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,22 +19,33 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
+
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorDataListener;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorDataHandler;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
@SuppressWarnings("unused")
-public interface SKSensorModuleInterface {
+public interface SKSensor {
- SKSensorModuleType getSensorType();
+ SKSensorType getSensorType();
+ @NonNull String getSensorName();
void startSensing() throws SKException;
- void stopSensing();
+ void stopSensing() throws SKException;
boolean isSensing();
- void subscribeSensorDataListener(SKSensorDataListener callback) throws SKException;
- void unsubscribeSensorDataListener(SKSensorDataListener callback) throws SKException;
- void unsubscribeAllSensorDataListeners() throws SKException;
+ void subscribeSensorDataHandler(final @NonNull SKSensorDataHandler handler) throws SKException;
+ void unsubscribeSensorDataHandler(final @NonNull SKSensorDataHandler handler) throws SKException;
+ void unsubscribeAllSensorDataHandlers();
+
+ void setConfiguration(final @NonNull SKConfiguration configuration) throws SKException;
+ @NonNull SKConfiguration getConfiguration();
+
+ void sensorDeregistered();
+
+ String[] getRequiredPermissions();
}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensorUtilities.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensorUtilities.java
new file mode 100644
index 0000000..0133aa2
--- /dev/null
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKSensorUtilities.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
+ *
+ * This file is part of SensingKit-Android library.
+ * For more information, please visit http://www.sensingkit.org
+ *
+ * SensingKit-Android is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SensingKit-Android is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with SensingKit-Android. If not, see .
+ */
+
+package org.sensingkit.sensingkitlib.sensors;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import androidx.annotation.NonNull;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GoogleApiAvailability;
+
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.data.*;
+
+@SuppressWarnings("WeakerAccess")
+public final class SKSensorUtilities {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = SKSensorUtilities.class.getSimpleName();
+
+ /**
+ * Return a string with a CSV formatted header that describes the data of the particular sensor.
+ */
+ static @NonNull
+ public String csvHeaderForSensor(final SKSensorType sensorType) {
+
+ switch (sensorType) {
+
+ case ACCELEROMETER:
+ return SKAccelerometerData.csvHeader();
+
+ case GRAVITY:
+ return SKGravityData.csvHeader();
+
+ case LINEAR_ACCELERATION:
+ return SKLinearAccelerationData.csvHeader();
+
+ case GYROSCOPE:
+ return SKGyroscopeData.csvHeader();
+
+ case ROTATION:
+ return SKRotationData.csvHeader();
+
+ case MAGNETOMETER:
+ return SKMagnetometerData.csvHeader();
+
+ case AMBIENT_TEMPERATURE:
+ return SKAmbientTemperatureData.csvHeader();
+
+ case STEP_DETECTOR:
+ return SKStepDetectorData.csvHeader();
+
+ case STEP_COUNTER:
+ return SKStepCounterData.csvHeader();
+
+ case LIGHT:
+ return SKLightData.csvHeader();
+
+ case LOCATION:
+ return SKLocationData.csvHeader();
+
+ case MOTION_ACTIVITY:
+ return SKMotionActivityData.csvHeader();
+
+ case BATTERY_STATUS:
+ return SKBatteryStatusData.csvHeader();
+
+ case SCREEN_STATUS:
+ return SKScreenStatusData.csvHeader();
+
+ case MICROPHONE:
+ return SKMicrophoneData.csvHeader();
+
+ case AUDIO_LEVEL:
+ return SKAudioLevelData.csvHeader();
+
+ case BLUETOOTH:
+ return SKBluetoothData.csvHeader();
+
+ case BEACON_PROXIMITY:
+ return SKBeaconProximityData.csvHeader();
+
+ case HUMIDITY:
+ return SKHumidityData.csvHeader();
+
+ case BAROMETER:
+ return SKBarometerData.csvHeader();
+
+ case NOTIFICATION:
+ return SKNotificationData.csvHeader();
+
+ default:
+ throw new RuntimeException("csvHeader for Sensor '" + sensorType.getName() + "' is missing.");
+ }
+ }
+
+ /**
+ * A Boolean value that indicates whether the sensor is available on the device.
+ *
+ * @param sensorType The type of the sensor that will be checked.
+ *
+ * @return TRUE if the sensor is available on the device, or FALSE if it is not.
+ */
+ public static boolean isSensorAvailable(final SKSensorType sensorType, final @NonNull Context context) {
+
+ // Get package manager
+ PackageManager packageManager = context.getPackageManager();
+
+ switch (sensorType) {
+
+ case ACCELEROMETER:
+ case GRAVITY:
+ case LINEAR_ACCELERATION:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
+
+ case GYROSCOPE:
+ case ROTATION:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE);
+
+ case MAGNETOMETER:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
+
+ case AMBIENT_TEMPERATURE:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
+ packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE);
+
+ case STEP_DETECTOR:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
+ packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR);
+
+ case STEP_COUNTER:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
+ packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER);
+
+ case LIGHT:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT);
+
+ case LOCATION:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) &&
+ isGooglePlayServicesAvailable(context);
+
+ case MOTION_ACTIVITY:
+ return isGooglePlayServicesAvailable(context);
+
+ case BATTERY_STATUS:
+ case SCREEN_STATUS:
+ return true;
+
+ case MICROPHONE:
+ case AUDIO_LEVEL:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE);
+
+ case BLUETOOTH:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+
+ case BEACON_PROXIMITY:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
+ packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
+
+ case HUMIDITY:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
+ packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_RELATIVE_HUMIDITY);
+
+ case BAROMETER:
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_BAROMETER);
+
+ case NOTIFICATION:
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
+
+ default:
+ throw new RuntimeException("Availability check for Sensor '" + sensorType.getName() + "' is missing.");
+ }
+ }
+
+ public static boolean isGooglePlayServicesAvailable(final @NonNull Context context) {
+ GoogleApiAvailability api = GoogleApiAvailability.getInstance();
+ int code = api.isGooglePlayServicesAvailable(context);
+ return code == ConnectionResult.SUCCESS;
+ }
+
+}
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepCounter.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepCounter.java
similarity index 54%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepCounter.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepCounter.java
index 8513a5c..751f962 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepCounter.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepCounter.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKStepCounterConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKStepCounterData;
-public class SKStepCounter extends SKAbstractNativeSensorModule {
+public class SKStepCounter extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKStepCounter";
+ private static final String TAG = SKStepCounter.class.getSimpleName();
- public SKStepCounter(final Context context) throws SKException {
- super(context, SKSensorModuleType.STEP_COUNTER);
+ public SKStepCounter(final @NonNull Context context, final @NonNull SKStepCounterConfiguration configuration) throws SKException {
+ super(context, SKSensorType.STEP_COUNTER, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
- return new SKStepCounterData(System.currentTimeMillis(), event.values[0]);
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
+ return new SKStepCounterData(System.currentTimeMillis(), (int)event.values[0]);
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKStepCounterConfiguration((SKStepCounterConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepDetector.java b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepDetector.java
similarity index 54%
rename from SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepDetector.java
rename to SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepDetector.java
index f6c7d1f..763917c 100644
--- a/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepDetector.java
+++ b/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/sensors/SKStepDetector.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2014. Queen Mary University of London
- * Kleomenis Katevas, k.katevas@qmul.ac.uk
+ * Copyright (c) 2014. Kleomenis Katevas
+ * Kleomenis Katevas, k.katevas@imperial.ac.uk
*
* This file is part of SensingKit-Android library.
* For more information, please visit http://www.sensingkit.org
@@ -19,33 +19,42 @@
* along with SensingKit-Android. If not, see .
*/
-package org.sensingkit.sensingkitlib.modules;
+package org.sensingkit.sensingkitlib.sensors;
import android.content.Context;
import android.hardware.SensorEvent;
+import androidx.annotation.NonNull;
import org.sensingkit.sensingkitlib.SKException;
-import org.sensingkit.sensingkitlib.SKSensorModuleType;
+import org.sensingkit.sensingkitlib.SKSensorType;
+import org.sensingkit.sensingkitlib.configuration.SKConfiguration;
+import org.sensingkit.sensingkitlib.configuration.SKStepDetectorConfiguration;
import org.sensingkit.sensingkitlib.data.SKAbstractData;
import org.sensingkit.sensingkitlib.data.SKStepDetectorData;
-public class SKStepDetector extends SKAbstractNativeSensorModule {
+public class SKStepDetector extends SKAbstractNativeSensor {
@SuppressWarnings("unused")
- private static final String TAG = "SKStepDetector";
+ private static final String TAG = SKStepDetector.class.getSimpleName();
- public SKStepDetector(final Context context) throws SKException {
- super(context, SKSensorModuleType.STEP_DETECTOR);
+ public SKStepDetector(final @NonNull Context context, final @NonNull SKStepDetectorConfiguration configuration) throws SKException {
+ super(context, SKSensorType.STEP_DETECTOR, configuration);
}
@Override
- protected SKAbstractData buildData(SensorEvent event)
- {
+ @NonNull
+ protected SKAbstractData buildData(final @NonNull SensorEvent event) {
return new SKStepDetectorData(System.currentTimeMillis());
}
@Override
- protected boolean shouldPostSensorData(SKAbstractData data) {
+ @NonNull
+ public SKConfiguration getConfiguration() {
+ return new SKStepDetectorConfiguration((SKStepDetectorConfiguration)mConfiguration);
+ }
+
+ @Override
+ protected boolean shouldPostSensorData(final @NonNull SKAbstractData data) {
// Always post sensor data
return true;
diff --git a/build.gradle b/build.gradle
index 9405f3f..842090f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,17 +3,49 @@
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.2.3'
+ classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
+plugins {
+ id "com.jfrog.bintray" version "1.7"
+}
+
+bintray {
+ user = System.getenv('bintray.user')
+ key = System.getenv('bintray.api.key')
+ pkg {
+ repo = 'SensingKit-Android'
+ name = 'SensingKit-Android'
+ userOrg = 'SensingKit'
+ licenses = ['LGPL-3.0']
+ vcsUrl = 'https://github.com/SensingKit/SensingKit-Android.git'
+ version {
+ name = project.version
+ released = new Date()
+ gpg {
+ sign = true
+ passphrase = System.getenv('bintray.gpg.password')
+ }
+ mavenCentralSync {
+ sync = true
+ user = System.getenv('maven.user')
+ password = System.getenv('maven.password')
+ close = '1'
+ }
+ }
+ }
+}
+
allprojects {
repositories {
jcenter()
+ maven { url "https://maven.google.com" }
}
}
diff --git a/gradle.properties b/gradle.properties
index 5d08ba7..dde311d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# org.gradle.parallel=true
+android.useAndroidX=true
+android.enableJetifier=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 18f81f8..f5ab9ee 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Dec 04 21:39:37 GMT 2014
+#Wed Aug 21 08:38:09 EEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip