├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── SensingKit-Android.iml
├── SensingKitLib
├── .gitignore
├── SensingKitLib.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── org
│ └── sensingkit
│ └── sensingkitlib
│ ├── SKException.java
│ ├── SKExceptionErrorCode.java
│ ├── SKSensorDataListener.java
│ ├── SKSensorModuleManager.java
│ ├── SKSensorModuleType.java
│ ├── SKUtilities.java
│ ├── SensingKitLib.java
│ ├── SensingKitLibInterface.java
│ ├── data
│ ├── SKAbstractData.java
│ ├── SKAccelerometerData.java
│ ├── SKActivityData.java
│ ├── SKAmbientTemperatureData.java
│ ├── SKAudioLevelData.java
│ ├── SKBatteryData.java
│ ├── SKBluetoothData.java
│ ├── SKBluetoothDeviceData.java
│ ├── SKGravityData.java
│ ├── SKGyroscopeData.java
│ ├── SKLightData.java
│ ├── SKLinearAccelerationData.java
│ ├── SKLocationData.java
│ ├── SKMagnetometerData.java
│ ├── SKRotationData.java
│ ├── SKScreenStatusData.java
│ ├── SKSensorData.java
│ ├── SKStepCounterData.java
│ └── SKStepDetectorData.java
│ └── modules
│ ├── SKAbstractGoogleServicesSensorModule.java
│ ├── SKAbstractNativeSensorModule.java
│ ├── SKAbstractSensorModule.java
│ ├── SKAccelerometer.java
│ ├── SKActivity.java
│ ├── SKActivityRecognitionIntentService.java
│ ├── SKAmbientTemperature.java
│ ├── SKAudioLevel.java
│ ├── SKAudioRecorder.java
│ ├── SKBattery.java
│ ├── SKBluetooth.java
│ ├── SKGravity.java
│ ├── SKGyroscope.java
│ ├── SKLight.java
│ ├── SKLinearAcceleration.java
│ ├── SKLocation.java
│ ├── SKMagnetometer.java
│ ├── SKRotation.java
│ ├── SKScreenStatus.java
│ ├── SKSensorModuleInterface.java
│ ├── SKSensorModuleUtilities.java
│ ├── SKStepCounter.java
│ └── SKStepDetector.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve SensingKit-Android
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | A clear and concise description of the steps required to reproduce the behavior.
12 |
13 | **Expected behavior**
14 | A clear and concise description of what you expected to happen.
15 |
16 | **Screenshots**
17 | If applicable, add screenshots to help explain your problem.
18 |
19 | **Smartphone (please complete the following information):**
20 | - Device: [e.g. Nexus 4]
21 | - OS: Android
22 | - Version [e.g. 9.0 (Pie)]
23 |
24 | **Additional context**
25 | Add any other context about the problem here.
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Android Studio
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.idea/workspace.xml
6 | .DS_Store
7 | /build
8 |
9 | #built application files
10 | *.apk
11 | *.ap_
12 |
13 | # files for the dex VM
14 | *.dex
15 |
16 | # Java class files
17 | *.class
18 |
19 | # generated files
20 | bin/
21 | gen/
22 |
23 | # Local configuration file (sdk path, etc)
24 | local.properties
25 |
26 | # Windows thumbnail db
27 | Thumbs.db
28 |
29 | # OSX files
30 | .DS_Store
31 |
32 | # Eclipse project files
33 | .classpath
34 | .project
35 |
36 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ### 0.2.0
4 | - Added support for Bluetooth sensor module.
5 | - DataInterface method getDataInString() has been renamed to getDataInCSV()
6 | - SKDataInterface has been renamed to SKSensorData
7 | - Added getSensorModuleType() to SKSensorData
8 | - Added SK prefix to all source files
9 | - Added support for Android Studio 1.3
10 | - Updated Build Tools version to 22.0.1
11 |
12 | ### 0.1.0
13 | - Initial Release
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SensingKit-Android Library
2 |
3 | An Android library that provides Continuous Sensing functionality to your applications. For more information, please refer to the [project website](http://www.sensingkit.org).
4 |
5 |
6 | ## Supported Sensors
7 |
8 | The following sensor modules are currently supported in SensingKit-Android, (listed in [SKSensorModuleType](SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorModuleType.java) enum):
9 |
10 | - Accelerometer
11 | - Gravity
12 | - Linear Acceleration
13 | - Gyroscope
14 | - Rotation
15 | - Magnetometer
16 | - Ambient Temperature
17 | - Step Detector
18 | - Step Counter
19 | - Light
20 | - Location
21 | - Activity
22 | - Battery
23 | - Screen Status
24 | - Audio Recorder
25 | - Audio Level
26 | - Bluetooth
27 |
28 | ## Configuring the Library
29 |
30 | - Build the library using the command:
31 |
32 | ```
33 | ./gradlew build
34 | ```
35 |
36 | - Create an app/libs directory inside your project and copy the generated SensingKitLib/build/outputs/aar/SensingKitLib-release.aar (or the equivalent debug) file there.
37 |
38 | - Edit your app/build.gradle file and add a flatDir entry as shown bellow:
39 |
40 | ```
41 | repositories {
42 | mavenCentral()
43 | flatDir {
44 | dirs 'libs'
45 | }
46 | }
47 | ```
48 |
49 |
50 | - In the same app/build.gradle file, add SensingKitLib as a dependency as shown below:
51 |
52 | ```
53 | dependencies {
54 | compile fileTree(dir: 'libs', include: ['*.jar'])
55 | compile 'org.sensingkit:SensingKitLib-release@aar'
56 | compile 'com.android.support:appcompat-v7:22.2.1’
57 | compile 'com.google.android.gms:play-services-location:7.5.0'
58 | }
59 | ```
60 |
61 |
62 | ## How to Use this Library
63 |
64 | - Import and init SensingKit into your Activity class as shown bellow:
65 |
66 | ```java
67 | import org.sensingkit.sensingkitlib.SensingKitLib;
68 |
69 | SensingKitLibInterface mSensingKitLib = SensingKitLib.getSensingKitLib(this);
70 | ```
71 |
72 |
73 | - Register a sensor module (e.g. a Light sensor) as shown bellow:
74 |
75 | ```java
76 | mSensingKitLib.registerSensorModule(SKSensorModuleType.LIGHT);
77 | ```
78 |
79 |
80 | - Subscribe a sensor data listener:
81 |
82 | ```java
83 | mSensingKitLib.subscribeSensorDataListener(SKSensorModuleType.LIGHT, new SKSensorDataListener() {
84 | @Override
85 | public void onDataReceived(final SKSensorModuleType moduleType, final SKSensorData sensorData) {
86 | System.out.println(sensorData.getDataInCSV()); // Print data in CSV format
87 | }
88 | });
89 | ```
90 |
91 |
92 | - You can cast the data object into the actual sensor data object in order to access all the sensor data properties:
93 |
94 | ```java
95 | SKLightData lightData = (SKLightData)sensorData;
96 | ```
97 |
98 |
99 |
100 | - You can Start and Stop the Continuous Sensing using the following commands:
101 |
102 | ```java
103 | mSensingKitLib.startContinuousSensingWithSensor(SKSensorModuleType.LIGHT);
104 | mSensingKitLib.stopContinuousSensingWithSensor(SKSensorModuleType.LIGHT);
105 | ```
106 |
107 |
108 | For a complete description of our API, please refer to the [project website](http://www.sensingkit.org).
109 |
110 | ## License
111 |
112 | ```
113 | Copyright (c) 2014. Queen Mary University of London
114 | Kleomenis Katevas, k.katevas@qmul.ac.uk.
115 |
116 | This file is part of SensingKit-Android library.
117 | For more information, please visit http://www.sensingkit.org.
118 |
119 | SensingKit-Android is free software: you can redistribute it and/or modify
120 | it under the terms of the GNU Lesser General Public License as published by
121 | the Free Software Foundation, either version 3 of the License, or
122 | (at your option) any later version.
123 |
124 | SensingKit-Android is distributed in the hope that it will be useful,
125 | but WITHOUT ANY WARRANTY; without even the implied warranty of
126 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127 | GNU Lesser General Public License for more details.
128 |
129 | You should have received a copy of the GNU Lesser General Public License
130 | along with SensingKit-Android. If not, see .
131 | ```
132 |
133 | This library is available under the GNU Lesser General Public License 3.0, allowing to use the library in your applications.
134 |
135 | If you want to help with the open source project, contact hello@sensingkit.org.
136 |
--------------------------------------------------------------------------------
/SensingKit-Android.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/SensingKitLib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/SensingKitLib/SensingKitLib.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/SensingKitLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "0.2.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.google.android.gms:play-services-location:7.5.0'
24 | }
25 |
--------------------------------------------------------------------------------
/SensingKitLib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | -keep class * extends java.util.ListResourceBundle {
20 | protected Object[][] getContents();
21 | }
22 |
23 | -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
24 | public static final *** NULL;
25 | }
26 |
27 | -keepnames @com.google.android.gms.common.annotation.KeepName class *
28 | -keepclassmembernames class * {
29 | @com.google.android.gms.common.annotation.KeepName *;
30 | }
31 |
32 | -keepnames class * implements android.os.Parcelable {
33 | public static final ** CREATOR;
34 | }
--------------------------------------------------------------------------------
/SensingKitLib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | public class SKException extends Exception {
25 |
26 | private final SKExceptionErrorCode errorCode;
27 | private final String TAG;
28 |
29 | public SKException(String TAG, String message, SKExceptionErrorCode errorCode) {
30 | super(message);
31 | this.TAG = TAG;
32 | this.errorCode = errorCode;
33 | }
34 |
35 | @SuppressWarnings("unused")
36 | public SKExceptionErrorCode getErrorCode() {
37 | return this.errorCode;
38 | }
39 |
40 | @SuppressWarnings("unused")
41 | public String getTAG() {
42 | return this.TAG;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKExceptionErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | public enum SKExceptionErrorCode {
25 | UNKNOWN_ERROR
26 | }
27 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorDataListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | import org.sensingkit.sensingkitlib.data.SKSensorData;
25 |
26 | public interface SKSensorDataListener {
27 |
28 | void onDataReceived(final SKSensorModuleType moduleType, final SKSensorData sensorData);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorModuleManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | import android.content.Context;
25 | import android.util.Log;
26 | import android.util.SparseArray;
27 |
28 | import org.sensingkit.sensingkitlib.data.SKSensorData;
29 | import org.sensingkit.sensingkitlib.modules.*;
30 |
31 | public class SKSensorModuleManager {
32 |
33 | @SuppressWarnings("unused")
34 | private static final String TAG = "SKSensorModuleManager";
35 |
36 | private static final int TOTAL_SENSOR_MODULES = 17;
37 |
38 | private static SKSensorModuleManager sSensorModuleManager;
39 | private final Context mApplicationContext;
40 |
41 | private final SparseArray mSensors;
42 |
43 | public static SKSensorModuleManager getSensorManager(final Context context) throws SKException {
44 |
45 | if (context == null) {
46 | throw new SKException(TAG, "Context cannot be null.", SKExceptionErrorCode.UNKNOWN_ERROR);
47 | }
48 |
49 | if (sSensorModuleManager == null) {
50 | sSensorModuleManager = new SKSensorModuleManager(context);
51 | }
52 |
53 | return sSensorModuleManager;
54 | }
55 |
56 | private SKSensorModuleManager(final Context context) throws SKException {
57 |
58 | mApplicationContext = context;
59 |
60 | // Init Sensor Array
61 | mSensors = new SparseArray<>(TOTAL_SENSOR_MODULES);
62 | }
63 |
64 | public void registerSensorModule(SKSensorModuleType moduleType) throws SKException {
65 |
66 | Log.i(TAG, "Register sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
67 |
68 | if (isSensorModuleRegistered(moduleType)) {
69 | throw new SKException(TAG, "SensorModule is already registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
70 | }
71 |
72 | // Register the SensorModule
73 | int sensorIndex = moduleType.ordinal();
74 | SKAbstractSensorModule sensorModule = createSensorModule(moduleType);
75 | mSensors.put(sensorIndex, sensorModule);
76 | }
77 |
78 | public void deregisterSensorModule(SKSensorModuleType moduleType) throws SKException {
79 |
80 | Log.i(TAG, "Deregister sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
81 |
82 | if (!isSensorModuleRegistered(moduleType)) {
83 | throw new SKException(TAG, "SensorModule is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
84 | }
85 |
86 | if (isSensorModuleSensing(moduleType)) {
87 | throw new SKException(TAG, "SensorModule is currently sensing.", SKExceptionErrorCode.UNKNOWN_ERROR);
88 | }
89 |
90 | // Clear all Callbacks from that sensor
91 | getSensorModule(moduleType).unsubscribeAllSensorDataListeners();
92 |
93 | // Deregister the SensorModule
94 | int sensorIndex = moduleType.ordinal();
95 | mSensors.delete(sensorIndex);
96 | }
97 |
98 | public boolean isSensorModuleRegistered(SKSensorModuleType moduleType) throws SKException {
99 |
100 | int sensorIndex = moduleType.ordinal();
101 | return (mSensors.get(sensorIndex) != null);
102 | }
103 |
104 | public boolean isSensorModuleSensing(SKSensorModuleType moduleType) throws SKException {
105 |
106 | if (!isSensorModuleRegistered(moduleType)) {
107 | throw new SKException(TAG, "SensorModule is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
108 | }
109 |
110 | return getSensorModule(moduleType).isSensing();
111 | }
112 |
113 | protected SKAbstractSensorModule getSensorModule(SKSensorModuleType moduleType) throws SKException {
114 |
115 | if (!isSensorModuleRegistered(moduleType)) {
116 | throw new SKException(TAG, "SensorModule is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
117 | }
118 |
119 | int sensorIndex = moduleType.ordinal();
120 | return mSensors.get(sensorIndex);
121 | }
122 |
123 | protected SKAbstractSensorModule createSensorModule(SKSensorModuleType moduleType) throws SKException {
124 |
125 | SKAbstractSensorModule sensorModule;
126 |
127 | switch (moduleType) {
128 |
129 | case ACCELEROMETER:
130 | sensorModule = new SKAccelerometer(mApplicationContext);
131 | break;
132 |
133 | case GRAVITY:
134 | sensorModule = new SKGravity(mApplicationContext);
135 | break;
136 |
137 | case LINEAR_ACCELERATION:
138 | sensorModule = new SKLinearAcceleration(mApplicationContext);
139 | break;
140 |
141 | case GYROSCOPE:
142 | sensorModule = new SKGyroscope(mApplicationContext);
143 | break;
144 |
145 | case ROTATION:
146 | sensorModule = new SKRotation(mApplicationContext);
147 | break;
148 |
149 | case MAGNETOMETER:
150 | sensorModule = new SKMagnetometer(mApplicationContext);
151 | break;
152 |
153 | case AMBIENT_TEMPERATURE:
154 | sensorModule = new SKAmbientTemperature(mApplicationContext);
155 | break;
156 |
157 | case STEP_DETECTOR:
158 | sensorModule = new SKStepDetector(mApplicationContext);
159 | break;
160 |
161 | case STEP_COUNTER:
162 | sensorModule = new SKStepCounter(mApplicationContext);
163 | break;
164 |
165 | case LIGHT:
166 | sensorModule = new SKLight(mApplicationContext);
167 | break;
168 |
169 | case LOCATION:
170 | sensorModule = new SKLocation(mApplicationContext);
171 | break;
172 |
173 | case ACTIVITY:
174 | sensorModule = new SKActivity(mApplicationContext);
175 | break;
176 |
177 | case BATTERY:
178 | sensorModule = new SKBattery(mApplicationContext);
179 | break;
180 |
181 | case SCREEN_STATUS:
182 | sensorModule = new SKScreenStatus(mApplicationContext);
183 | break;
184 |
185 | case AUDIO_RECORDER:
186 | sensorModule = new SKAudioRecorder(mApplicationContext);
187 | break;
188 |
189 | case AUDIO_LEVEL:
190 | sensorModule = new SKAudioLevel(mApplicationContext);
191 | break;
192 |
193 | case BLUETOOTH:
194 | sensorModule = new SKBluetooth(mApplicationContext);
195 | break;
196 |
197 | // Don't forget the break; here
198 |
199 | default:
200 | throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
201 | }
202 |
203 | return sensorModule;
204 | }
205 |
206 | public SKSensorData getDataFromSensor(SKSensorModuleType moduleType) throws SKException {
207 |
208 | Log.i(TAG, "Get data from sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
209 |
210 | throw new SKException(TAG, "This feature is not supported just yet!", SKExceptionErrorCode.UNKNOWN_ERROR);
211 | }
212 |
213 | public void subscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
214 |
215 | Log.i(TAG, "Subscribe to sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
216 |
217 | getSensorModule(moduleType).subscribeSensorDataListener(dataListener);
218 | }
219 |
220 | public void unsubscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
221 |
222 | Log.i(TAG, "Unsubscribe from sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
223 |
224 | getSensorModule(moduleType).unsubscribeSensorDataListener(dataListener);
225 | }
226 |
227 | public void unsubscribeAllSensorDataListeners(SKSensorModuleType moduleType) throws SKException {
228 |
229 | Log.i(TAG, "Unsubscribe from all sensors.");
230 |
231 | getSensorModule(moduleType).unsubscribeAllSensorDataListeners();
232 | }
233 |
234 | public void startContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException {
235 |
236 | Log.i(TAG, "Start sensing with sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
237 |
238 | if (isSensorModuleSensing(moduleType)) {
239 | throw new SKException(TAG, "SensorModule is already sensing.", SKExceptionErrorCode.UNKNOWN_ERROR);
240 | }
241 |
242 | // Start Sensing
243 | getSensorModule(moduleType).startSensing();
244 | }
245 |
246 | public void stopContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException {
247 |
248 | Log.i(TAG, "Stop sensing with sensor: " + SKSensorModuleUtilities.getSensorModuleInString(moduleType) + ".");
249 |
250 | if (!isSensorModuleSensing(moduleType)) {
251 | throw new SKException(TAG, "SensorModule is already not sensing.", SKExceptionErrorCode.UNKNOWN_ERROR);
252 | }
253 |
254 | SKSensorModuleInterface sensorModule = getSensorModule(moduleType);
255 |
256 | // Stop Sensing
257 | sensorModule.stopSensing();
258 | }
259 |
260 | }
261 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorModuleType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | public enum SKSensorModuleType {
25 | ACCELEROMETER,
26 | GRAVITY,
27 | LINEAR_ACCELERATION,
28 | GYROSCOPE,
29 | ROTATION,
30 | MAGNETOMETER,
31 | AMBIENT_TEMPERATURE,
32 | STEP_DETECTOR,
33 | STEP_COUNTER,
34 | LIGHT,
35 | LOCATION,
36 | ACTIVITY,
37 | BATTERY,
38 | SCREEN_STATUS,
39 | AUDIO_RECORDER,
40 | AUDIO_LEVEL,
41 | BLUETOOTH
42 | }
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKUtilities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | import android.content.Context;
25 | import android.content.pm.PackageManager;
26 |
27 | public final class SKUtilities {
28 |
29 | @SuppressWarnings("unused")
30 | private static final String TAG = "SKUtilities";
31 |
32 | public static boolean checkPermission(Context context, String permission) throws SKException {
33 |
34 | if (context == null) {
35 | throw new SKException(TAG, "Context cannot be null.", SKExceptionErrorCode.UNKNOWN_ERROR);
36 | }
37 |
38 | int res = context.checkCallingOrSelfPermission(permission);
39 | return (res == PackageManager.PERMISSION_GRANTED);
40 | }
41 |
42 | public static long getCurrentTimeMillis() {
43 | return System.currentTimeMillis();
44 | }
45 |
46 | public static long getNanoTime() {
47 | return System.nanoTime();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SensingKitLib.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | import android.content.Context;
25 | import android.os.PowerManager;
26 |
27 | import org.sensingkit.sensingkitlib.data.SKSensorData;
28 |
29 |
30 | public class SensingKitLib implements SensingKitLibInterface {
31 |
32 | @SuppressWarnings("unused")
33 | private static final String TAG = "SensingKitLib";
34 |
35 | private static SensingKitLib sSensingKitLib;
36 |
37 | private final Context mApplicationContext;
38 | private PowerManager.WakeLock mWakeLock;
39 |
40 | private SKSensorModuleManager mSensorModuleManager;
41 |
42 | @SuppressWarnings("unused")
43 | public static SensingKitLibInterface getSensingKitLib(final Context context) throws SKException {
44 |
45 | if (context == null) {
46 | throw new SKException(TAG, "Context cannot be null", SKExceptionErrorCode.UNKNOWN_ERROR);
47 | }
48 |
49 | if (sSensingKitLib == null) {
50 | sSensingKitLib = new SensingKitLib(context);
51 | }
52 |
53 | return sSensingKitLib;
54 | }
55 |
56 | private SensingKitLib(final Context context) throws SKException {
57 | mApplicationContext = context;
58 | mSensorModuleManager = SKSensorModuleManager.getSensorManager(context);
59 | }
60 |
61 | @Override
62 | public void registerSensorModule(SKSensorModuleType moduleType) throws SKException {
63 | mSensorModuleManager.registerSensorModule(moduleType);
64 | }
65 |
66 | @Override
67 | public void deregisterSensorModule(SKSensorModuleType moduleType) throws SKException {
68 | mSensorModuleManager.deregisterSensorModule(moduleType);
69 | }
70 |
71 | @Override
72 | public boolean isSensorModuleRegistered(SKSensorModuleType moduleType) throws SKException {
73 | return mSensorModuleManager.isSensorModuleRegistered(moduleType);
74 | }
75 |
76 | @Override
77 | public SKSensorData getDataFromSensor(SKSensorModuleType moduleType) throws SKException {
78 | return mSensorModuleManager.getDataFromSensor(moduleType);
79 | }
80 |
81 | @Override
82 | public void subscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
83 | mSensorModuleManager.subscribeSensorDataListener(moduleType, dataListener);
84 | }
85 |
86 | @Override
87 | public void unsubscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException {
88 | mSensorModuleManager.unsubscribeSensorDataListener(moduleType, dataListener);
89 | }
90 |
91 | @Override
92 | public void unsubscribeAllSensorDataListeners(SKSensorModuleType moduleType) throws SKException {
93 | mSensorModuleManager.unsubscribeAllSensorDataListeners(moduleType);
94 | }
95 |
96 | @Override
97 | public void startContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException {
98 | mSensorModuleManager.startContinuousSensingWithSensor(moduleType);
99 | }
100 |
101 | @Override
102 | public void stopContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException {
103 | mSensorModuleManager.stopContinuousSensingWithSensor(moduleType);
104 | }
105 |
106 | @Override
107 | public boolean isSensorModuleSensing(SKSensorModuleType moduleType) throws SKException {
108 | return mSensorModuleManager.isSensorModuleSensing(moduleType);
109 | }
110 |
111 | @Override
112 | public long getCurrentTimeMillis() {
113 | return SKUtilities.getCurrentTimeMillis();
114 | }
115 |
116 | @Override
117 | public long getNanoTime() {
118 | return SKUtilities.getNanoTime();
119 | }
120 |
121 | //region Wake Lock methods
122 |
123 | private void acquireWakeLock() {
124 | if ((mWakeLock == null) || (!mWakeLock.isHeld())) {
125 | PowerManager pm = (PowerManager) mApplicationContext.getSystemService(Context.POWER_SERVICE);
126 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLock");
127 | mWakeLock.acquire();
128 | }
129 | }
130 |
131 | private void releaseWakeLock() {
132 | if (mWakeLock != null && mWakeLock.isHeld()) {
133 | mWakeLock.release();
134 | }
135 | }
136 |
137 | private boolean checkWakeLockPermission() throws SKException {
138 | return SKUtilities.checkPermission(
139 | mApplicationContext,
140 | "android.permission.WAKE_LOCK");
141 | }
142 |
143 | //endregion
144 | }
145 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SensingKitLibInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib;
23 |
24 | import org.sensingkit.sensingkitlib.data.SKSensorData;
25 |
26 | @SuppressWarnings("unused")
27 | public interface SensingKitLibInterface {
28 |
29 | /** Sensor Registration */
30 |
31 | void registerSensorModule(SKSensorModuleType moduleType) throws SKException;
32 |
33 | void deregisterSensorModule(SKSensorModuleType moduleType) throws SKException;
34 |
35 | boolean isSensorModuleRegistered(SKSensorModuleType moduleType) throws SKException;
36 |
37 | /** Configuration */
38 | // TODO: Add Configuration
39 |
40 |
41 | /** One Shot Sensing */
42 |
43 | SKSensorData getDataFromSensor(SKSensorModuleType moduleType) throws SKException;
44 |
45 |
46 | /** Continuous Sensing */
47 |
48 | void subscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException;
49 |
50 | void unsubscribeSensorDataListener(SKSensorModuleType moduleType, SKSensorDataListener dataListener) throws SKException;
51 |
52 | void unsubscribeAllSensorDataListeners(SKSensorModuleType moduleType) throws SKException;
53 |
54 | void startContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException;
55 |
56 | void stopContinuousSensingWithSensor(SKSensorModuleType moduleType) throws SKException;
57 |
58 | boolean isSensorModuleSensing(SKSensorModuleType moduleType) throws SKException;
59 |
60 | /** Time */
61 |
62 | long getCurrentTimeMillis();
63 |
64 | long getNanoTime();
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKAbstractData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | public abstract class SKAbstractData implements SKSensorData
27 | {
28 | @SuppressWarnings("unused")
29 | private static final String TAG = "SKAbstractData";
30 |
31 | protected final SKSensorModuleType moduleType;
32 | protected final long timestamp;
33 |
34 | public SKAbstractData(SKSensorModuleType moduleType, long timestamp) {
35 | this.moduleType = moduleType;
36 | this.timestamp = timestamp;
37 | }
38 |
39 | public String toString() {
40 | return this.getDataInCSV();
41 | }
42 |
43 | @SuppressWarnings("unused")
44 | public SKSensorModuleType getSensorModuleType() {
45 | return moduleType;
46 | }
47 |
48 | @SuppressWarnings("unused")
49 | public long getTimestamp() {
50 | return timestamp;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKAccelerometerData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKAccelerometerData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKAccelerometerData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 |
37 | public SKAccelerometerData(long timestamp, float x, float y, float z) {
38 |
39 | super(SKSensorModuleType.ACCELEROMETER, timestamp);
40 |
41 | this.x = x;
42 | this.y = y;
43 | this.z = z;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public float getX() {
53 | return this.x;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public float getY() {
58 | return this.y;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public float getZ() {
63 | return this.z;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKActivityData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import com.google.android.gms.location.DetectedActivity;
25 |
26 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
27 |
28 | import java.util.Locale;
29 |
30 | public class SKActivityData extends SKAbstractData {
31 |
32 | @SuppressWarnings("unused")
33 | private static final String TAG = "SKActivityData";
34 |
35 | protected final int activityType;
36 | protected final int confidence;
37 |
38 | public SKActivityData(long timestamp, int activityType, int confidence) {
39 |
40 | super(SKSensorModuleType.ACTIVITY, timestamp);
41 |
42 | this.activityType = activityType;
43 | this.confidence = confidence;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%d,%s,%d", this.timestamp, this.activityType, getActivityString(), this.confidence);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public int getActivityType() {
53 | return this.activityType;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public int getConfidence() {
58 | return this.confidence;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public String getActivityString() {
63 | return getNameFromActivityType(this.activityType);
64 | }
65 |
66 | public static String getNameFromActivityType(int activityType) {
67 |
68 | switch (activityType) {
69 |
70 | case DetectedActivity.IN_VEHICLE:
71 | return "in_vehicle";
72 |
73 | case DetectedActivity.ON_BICYCLE:
74 | return "on_bicycle";
75 |
76 | case DetectedActivity.ON_FOOT:
77 | return "on_foot";
78 |
79 | case DetectedActivity.STILL:
80 | return "still";
81 |
82 | case DetectedActivity.UNKNOWN:
83 | return "unknown";
84 |
85 | case DetectedActivity.TILTING:
86 | return "tilting";
87 |
88 | case DetectedActivity.WALKING:
89 | return "walking";
90 |
91 | case DetectedActivity.RUNNING:
92 | return "running";
93 |
94 | default:
95 | return "unsupported";
96 | }
97 |
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKAmbientTemperatureData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKAmbientTemperatureData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKAmbientTemperatureData";
32 |
33 | protected final float temperature;
34 |
35 | public SKAmbientTemperatureData(long timestamp, float temperature) {
36 |
37 | super(SKSensorModuleType.AMBIENT_TEMPERATURE, timestamp);
38 |
39 | this.temperature = temperature;
40 | }
41 |
42 | @Override
43 | public String getDataInCSV() {
44 | return String.format(Locale.US, "%d,%f", this.timestamp, this.temperature);
45 | }
46 |
47 | @SuppressWarnings("unused")
48 | public float getTemperature() {
49 | return this.temperature;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKAudioLevelData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKAudioLevelData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKAudioLevelData";
32 |
33 | protected final int level;
34 |
35 | public SKAudioLevelData(long timestamp, int level) {
36 |
37 | super(SKSensorModuleType.AUDIO_LEVEL, timestamp);
38 |
39 | this.level = level;
40 | }
41 |
42 | @Override
43 | public String getDataInCSV() {
44 | return String.format(Locale.US, "%d,%d", this.timestamp, this.level);
45 | }
46 |
47 | @SuppressWarnings("unused")
48 | public int getLevel() {
49 | return this.level;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBatteryData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import android.os.BatteryManager;
25 |
26 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
27 |
28 | import java.util.Locale;
29 |
30 | import static android.os.BatteryManager.*;
31 |
32 | public class SKBatteryData extends SKAbstractData {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKBatteryData";
36 |
37 | protected final int level;
38 | protected final int scale;
39 | protected final int temperature;
40 | protected final int voltage;
41 | protected final int plugged;
42 | protected final int status;
43 | protected final int health;
44 |
45 | public SKBatteryData(long timestamp, int level, int scale, int temperature, int voltage, int plugged, int status, int health) {
46 |
47 | super(SKSensorModuleType.BATTERY, timestamp);
48 |
49 | this.level = level;
50 | this.scale = scale;
51 | this.temperature = temperature;
52 | this.voltage = voltage;
53 | this.plugged = plugged;
54 | this.status = status;
55 | this.health = health;
56 | }
57 |
58 | @Override
59 | public String getDataInCSV() {
60 | return String.format(Locale.US, "%d,%f,%d,%d,%s,%s,%s", this.timestamp, this.getLevelRatio(), this.temperature, this.voltage, getPluggedString(), getBatteryStatusString(), getBatteryHealthString());
61 | }
62 |
63 | @SuppressWarnings("unused")
64 | public float getLevelRatio() {
65 |
66 | // Calculate the level: level/scale
67 | if (level >= 0 && scale > 0) {
68 | return level / (float)scale;
69 | }
70 | else {
71 | return 0;
72 | }
73 | }
74 |
75 | @SuppressWarnings("unused")
76 | public int getLevel() {
77 | return this.level;
78 | }
79 |
80 | @SuppressWarnings("unused")
81 | public int getScale() {
82 | return this.scale;
83 | }
84 |
85 | @SuppressWarnings("unused")
86 | public int getTemperature() {
87 | return this.temperature;
88 | }
89 |
90 | @SuppressWarnings("unused")
91 | public int getVoltage() {
92 | return this.voltage;
93 | }
94 |
95 | @SuppressWarnings("unused")
96 | public int getPlugged() {
97 | return this.plugged;
98 | }
99 |
100 | @SuppressWarnings("unused")
101 | public int getBatteryStatus() {
102 | return this.status;
103 | }
104 |
105 | @SuppressWarnings("unused")
106 | public int getBatteryHealth() {
107 | return this.health;
108 | }
109 |
110 | @SuppressWarnings("unused")
111 | public String getPluggedString() {
112 | return getPluggedString(this.plugged);
113 | }
114 |
115 | @SuppressWarnings("unused")
116 | public String getBatteryStatusString() {
117 | return getBatteryStatusString(this.status);
118 | }
119 |
120 | @SuppressWarnings("unused")
121 | public String getBatteryHealthString() {
122 | return getBatteryHealthString(this.health);
123 | }
124 |
125 | private static String getPluggedString(int pluggedType) {
126 |
127 | switch (pluggedType) {
128 |
129 | case BATTERY_PLUGGED_USB:
130 | return "usb";
131 |
132 | case BATTERY_PLUGGED_AC:
133 | return "ac";
134 |
135 | case BATTERY_PLUGGED_WIRELESS:
136 | return "wireless";
137 |
138 | default:
139 | return "unknown";
140 | }
141 | }
142 |
143 | private static String getBatteryStatusString(int status) {
144 |
145 | switch (status) {
146 |
147 | case BatteryManager.BATTERY_STATUS_CHARGING:
148 | return "charging";
149 |
150 | case BatteryManager.BATTERY_STATUS_DISCHARGING:
151 | return "discharging";
152 |
153 | case BatteryManager.BATTERY_STATUS_FULL:
154 | return "full";
155 |
156 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
157 | return "not Charging";
158 |
159 | case BatteryManager.BATTERY_STATUS_UNKNOWN:
160 | return "unknown";
161 |
162 | default:
163 | return "unsupported";
164 | }
165 | }
166 |
167 | private String getBatteryHealthString(int health) {
168 |
169 | switch (health) {
170 |
171 | case BatteryManager.BATTERY_HEALTH_COLD:
172 | return "cold";
173 |
174 | case BatteryManager.BATTERY_HEALTH_DEAD:
175 | return "dead";
176 |
177 | case BatteryManager.BATTERY_HEALTH_GOOD:
178 | return "good";
179 |
180 | case BatteryManager.BATTERY_HEALTH_OVERHEAT:
181 | return "over heat";
182 |
183 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
184 | return "over voltage";
185 |
186 | case BatteryManager.BATTERY_HEALTH_UNKNOWN:
187 | return "unknown";
188 |
189 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
190 | return "failure";
191 |
192 | default:
193 | return "unsupported";
194 | }
195 | }
196 |
197 | }
198 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBluetoothData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.ArrayList;
27 | import java.util.Locale;
28 |
29 | public class SKBluetoothData extends SKAbstractData {
30 |
31 | @SuppressWarnings("unused")
32 | private static final String TAG = "SKBluetoothData";
33 |
34 | private final ArrayList mBluetoothDevices;
35 |
36 | public SKBluetoothData(long timestamp, ArrayList bluetoothDevices) {
37 |
38 | super(SKSensorModuleType.BLUETOOTH, timestamp);
39 |
40 | this.mBluetoothDevices = bluetoothDevices;
41 | }
42 |
43 | @Override
44 | public String getDataInCSV() {
45 |
46 | // Calculate capacity and init StringBuilder
47 | int capacity = 10 * mBluetoothDevices.size();
48 | StringBuilder stringBuilder = new StringBuilder(capacity);
49 |
50 | // Add deviceData
51 | for (SKBluetoothDeviceData deviceData : mBluetoothDevices) {
52 |
53 | stringBuilder.append(String.format(Locale.US, "%d,%s\n", this.timestamp, deviceData.getDataInCSV()));
54 | }
55 |
56 | // Delete last \n
57 | stringBuilder.deleteCharAt(stringBuilder.length()-1);
58 |
59 | // Return in String
60 | return stringBuilder.toString();
61 | }
62 |
63 | @SuppressWarnings("unused")
64 | public ArrayList getBluetoothDevices() {
65 | return this.mBluetoothDevices;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKBluetoothDeviceData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKBluetoothDeviceData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKBluetoothDeviceData";
32 |
33 | protected final String name;
34 | protected final String address;
35 | protected final int rssi;
36 |
37 | public SKBluetoothDeviceData(long timestamp, String name, String address, int rssi) {
38 |
39 | super(SKSensorModuleType.BLUETOOTH, timestamp);
40 |
41 | this.name = name;
42 | this.address = address;
43 | this.rssi = rssi;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%s,%s,%d", this.timestamp, this.name, this.address, this.rssi);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public String getName() {
53 | return this.name;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public String getAddress() {
58 | return this.address;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public int getRssi() {
63 | return this.rssi;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGravityData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKGravityData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKGravityData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 |
37 | public SKGravityData(long timestamp, float x, float y, float z) {
38 |
39 | super(SKSensorModuleType.GRAVITY, timestamp);
40 |
41 | this.x = x;
42 | this.y = y;
43 | this.z = z;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public float getX() {
53 | return this.x;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public float getY() {
58 | return this.y;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public float getZ() {
63 | return this.z;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKGyroscopeData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKGyroscopeData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKGyroscopeData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 |
37 | public SKGyroscopeData(long timestamp, float x, float y, float z) {
38 |
39 | super(SKSensorModuleType.GYROSCOPE, timestamp);
40 |
41 | this.x = x;
42 | this.y = y;
43 | this.z = z;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public float getX() {
53 | return this.x;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public float getY() {
58 | return this.y;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public float getZ() {
63 | return this.z;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLightData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKLightData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKLightData";
32 |
33 | protected final float light;
34 |
35 | public SKLightData(long timestamp, float light) {
36 |
37 | super(SKSensorModuleType.LIGHT, timestamp);
38 |
39 | this.light = light;
40 | }
41 |
42 | @Override
43 | public String getDataInCSV() {
44 | return String.format(Locale.US, "%d,%f", this.timestamp, this.light);
45 | }
46 |
47 | @SuppressWarnings("unused")
48 | public float getLight() {
49 | return this.light;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLinearAccelerationData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKLinearAccelerationData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKLinearAccelerationData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 |
37 | public SKLinearAccelerationData(long timestamp, float x, float y, float z) {
38 |
39 | super(SKSensorModuleType.LINEAR_ACCELERATION, timestamp);
40 |
41 | this.x = x;
42 | this.y = y;
43 | this.z = z;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public float getX() {
53 | return this.x;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public float getY() {
58 | return this.y;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public float getZ() {
63 | return this.z;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKLocationData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import android.location.Location;
25 |
26 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
27 |
28 | import java.util.Locale;
29 |
30 |
31 | public class SKLocationData extends SKAbstractData {
32 |
33 | @SuppressWarnings("unused")
34 | private static final String TAG = "SKLocationData";
35 |
36 | protected final Location location;
37 |
38 | public SKLocationData(long timestamp, Location location) {
39 |
40 | super(SKSensorModuleType.LOCATION, timestamp);
41 |
42 | this.location = location;
43 | }
44 |
45 | @Override
46 | public String getDataInCSV() {
47 | return String.format(Locale.US, "%d,%s", this.timestamp, this.location);
48 | }
49 |
50 | @SuppressWarnings("unused")
51 | public Location getLocation() {
52 | return location;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKMagnetometerData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKMagnetometerData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKMagnetometerData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 |
37 | public SKMagnetometerData(long timestamp, float x, float y, float z) {
38 |
39 | super(SKSensorModuleType.MAGNETOMETER, timestamp);
40 |
41 | this.x = x;
42 | this.y = y;
43 | this.z = z;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%f,%f,%f", this.timestamp, this.x, this.y, this.z);
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public float getX() {
53 | return this.x;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public float getY() {
58 | return this.y;
59 | }
60 |
61 | @SuppressWarnings("unused")
62 | public float getZ() {
63 | return this.z;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKRotationData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKRotationData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKRotationData";
32 |
33 | protected final float x;
34 | protected final float y;
35 | protected final float z;
36 | protected final float cos;
37 | protected final float headingAccuracy;
38 |
39 | public SKRotationData(long timestamp, float x, float y, float z, float cos, float headingAccuracy) {
40 |
41 | super(SKSensorModuleType.ROTATION, timestamp);
42 |
43 | this.x = x;
44 | this.y = y;
45 | this.z = z;
46 | this.cos = cos;
47 | this.headingAccuracy = headingAccuracy;
48 | }
49 |
50 | public SKRotationData(long timestamp, float x, float y, float z) {
51 | this(timestamp, x, y, z, 0, 0);
52 | }
53 |
54 | @Override
55 | public String getDataInCSV() {
56 | return String.format(Locale.US, "%d,%f,%f,%f,%f,%f", this.timestamp, this.x, this.y, this.z, this.cos, this.headingAccuracy);
57 | }
58 |
59 | @SuppressWarnings("unused")
60 | public float getX() {
61 | return this.x;
62 | }
63 |
64 | @SuppressWarnings("unused")
65 | public float getY() {
66 | return this.y;
67 | }
68 |
69 | @SuppressWarnings("unused")
70 | public float getZ() {
71 | return this.z;
72 | }
73 |
74 | @SuppressWarnings("unused")
75 | public float getCos() {
76 | return this.cos;
77 | }
78 |
79 | @SuppressWarnings("unused")
80 | public float getHeadingAccuracy() {
81 | return this.headingAccuracy;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKScreenStatusData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKScreenStatusData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKScreenStatusData";
32 |
33 | public static final int SCREEN_OFF = 0;
34 | public static final int SCREEN_ON = 1;
35 | public static final int SCREEN_UNKNOWN = 2;
36 |
37 | protected final int status;
38 |
39 | public SKScreenStatusData(long timestamp, int status) {
40 |
41 | super(SKSensorModuleType.SCREEN_STATUS, timestamp);
42 |
43 | this.status = status;
44 | }
45 |
46 | @Override
47 | public String getDataInCSV() {
48 | return String.format(Locale.US, "%d,%s", this.timestamp, this.getStatusString());
49 | }
50 |
51 | @SuppressWarnings("unused")
52 | public int getStatus() {
53 | return this.status;
54 | }
55 |
56 | @SuppressWarnings("unused")
57 | public String getStatusString() {
58 |
59 | switch (this.status) {
60 | case SCREEN_OFF:
61 | return "screen off";
62 |
63 | case SCREEN_ON:
64 | return "screen on";
65 |
66 | default:
67 | return "unknown";
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKSensorData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | @SuppressWarnings("unused")
27 | public interface SKSensorData {
28 |
29 | SKSensorModuleType getSensorModuleType();
30 | String getDataInCSV();
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepCounterData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKStepCounterData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKStepCounterData";
32 |
33 | protected final float steps;
34 |
35 | public SKStepCounterData(long timestamp, float steps) {
36 |
37 | super(SKSensorModuleType.STEP_COUNTER, timestamp);
38 |
39 | this.steps = steps;
40 | }
41 |
42 | @Override
43 | public String getDataInCSV() {
44 | return String.format(Locale.US, "%d,%f", this.timestamp, this.steps);
45 | }
46 |
47 | @SuppressWarnings("unused")
48 | public float getSteps() {
49 | return this.steps;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/data/SKStepDetectorData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.data;
23 |
24 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
25 |
26 | import java.util.Locale;
27 |
28 | public class SKStepDetectorData extends SKAbstractData {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKStepDetectorData";
32 |
33 | public SKStepDetectorData(long timestamp) {
34 |
35 | super(SKSensorModuleType.STEP_DETECTOR, timestamp);
36 | }
37 |
38 | @Override
39 | public String getDataInCSV() {
40 | return String.format(Locale.US, "%d", this.timestamp);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractGoogleServicesSensorModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.os.Bundle;
26 |
27 | import com.google.android.gms.common.ConnectionResult;
28 | import com.google.android.gms.common.api.GoogleApiClient;
29 |
30 | import org.sensingkit.sensingkitlib.SKException;
31 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
32 |
33 |
34 | public abstract class SKAbstractGoogleServicesSensorModule extends SKAbstractSensorModule implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
35 |
36 | @SuppressWarnings("unused")
37 | private static final String TAG = "SKAbstractGoogleServicesSensorModule";
38 |
39 | protected GoogleApiClient mClient;
40 |
41 | protected SKAbstractGoogleServicesSensorModule(final Context context, final SKSensorModuleType sensorModuleType) throws SKException {
42 | super(context, sensorModuleType);
43 |
44 |
45 | }
46 |
47 | protected abstract void serviceConnected();
48 |
49 | @Override
50 | public void onConnected(Bundle connectionHint) {
51 | serviceConnected();
52 | }
53 |
54 | @Override
55 | public void onConnectionSuspended(int cause) {
56 | // Ignore, will try to reconnect automatically
57 | }
58 |
59 | @Override
60 | public void onConnectionFailed(ConnectionResult result) {
61 | // At least one of the API client connect attempts failed
62 | // No client is connected
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractNativeSensorModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.annotation.SuppressLint;
25 | import android.content.Context;
26 | import android.hardware.Sensor;
27 | import android.hardware.SensorEvent;
28 | import android.hardware.SensorEventListener;
29 | import android.hardware.SensorManager;
30 | import android.os.Build;
31 |
32 | import org.sensingkit.sensingkitlib.SKException;
33 | import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
34 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
35 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
36 |
37 | public abstract class SKAbstractNativeSensorModule extends SKAbstractSensorModule {
38 |
39 | @SuppressWarnings("unused")
40 | private static final String TAG = "SKAbstractNativeSensorModule";
41 |
42 | private final SensorManager mSensorManager;
43 | private final Sensor mSensor;
44 | private final SensorEventListener mSensorEventListener;
45 |
46 | protected SKAbstractNativeSensorModule(final Context context, final SKSensorModuleType sensorModuleType) throws SKException {
47 | super(context, sensorModuleType);
48 |
49 | mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
50 | mSensor = mSensorManager.getDefaultSensor(getSensorType(sensorModuleType));
51 |
52 | mSensorEventListener = new SensorEventListener() {
53 |
54 | @Override
55 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
56 | // Ignore
57 | }
58 |
59 | @Override
60 | public void onSensorChanged(SensorEvent event) {
61 |
62 | // Build the data object
63 | SKAbstractData data = buildData(event);
64 |
65 | // Submit sensor data object
66 | submitSensorData(data);
67 | }
68 | };
69 | }
70 |
71 | @Override
72 | public void startSensing() throws SKException {
73 |
74 | this.isSensing = true;
75 |
76 | boolean status = mSensorManager.registerListener(mSensorEventListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
77 |
78 | if (!status) {
79 | throw new SKException(TAG, "SensorModule '" + getSensorName() + "' could not be started.", SKExceptionErrorCode.UNKNOWN_ERROR);
80 | }
81 | }
82 |
83 | @Override
84 | public void stopSensing() {
85 |
86 | mSensorManager.unregisterListener(mSensorEventListener);
87 |
88 | this.isSensing = false;
89 | }
90 |
91 | protected abstract SKAbstractData buildData(SensorEvent event);
92 |
93 | @SuppressLint("InlinedApi") // There is a check in STEP_DETECTOR and STEP_COUNTER
94 | private static int getSensorType(SKSensorModuleType sensorType) throws SKException{
95 |
96 | switch (sensorType) {
97 |
98 | case ACCELEROMETER:
99 | return Sensor.TYPE_ACCELEROMETER;
100 |
101 | case GRAVITY:
102 | return Sensor.TYPE_GRAVITY;
103 |
104 | case LINEAR_ACCELERATION:
105 | return Sensor.TYPE_LINEAR_ACCELERATION;
106 |
107 | case GYROSCOPE:
108 | return Sensor.TYPE_GYROSCOPE;
109 |
110 | case ROTATION:
111 | return Sensor.TYPE_ROTATION_VECTOR;
112 |
113 | case MAGNETOMETER:
114 | return Sensor.TYPE_MAGNETIC_FIELD;
115 |
116 | case AMBIENT_TEMPERATURE:
117 | return Sensor.TYPE_AMBIENT_TEMPERATURE;
118 |
119 | case STEP_DETECTOR:
120 |
121 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
122 | return Sensor.TYPE_STEP_DETECTOR;
123 | }
124 | else
125 | {
126 | throw new SKException(TAG, "STEP_DETECTOR requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
127 | }
128 |
129 | case STEP_COUNTER:
130 |
131 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
132 | return Sensor.TYPE_STEP_COUNTER;
133 | }
134 | else
135 | {
136 | throw new SKException(TAG, "STEP_COUNTER requires Android KitKat or greater.", SKExceptionErrorCode.UNKNOWN_ERROR);
137 | }
138 |
139 | case LIGHT:
140 | return Sensor.TYPE_LIGHT;
141 |
142 | case LOCATION:
143 | case ACTIVITY:
144 | case BATTERY:
145 | throw new SKException(TAG, "Not a native SensorModule.", SKExceptionErrorCode.UNKNOWN_ERROR);
146 |
147 | default:
148 | throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
149 |
150 | }
151 | }
152 |
153 | }
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractSensorModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 |
26 | import org.sensingkit.sensingkitlib.SKException;
27 | import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
28 | import org.sensingkit.sensingkitlib.SKSensorDataListener;
29 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
30 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
31 |
32 | import java.util.ArrayList;
33 |
34 | public abstract class SKAbstractSensorModule implements SKSensorModuleInterface {
35 |
36 | @SuppressWarnings("unused")
37 | private static final String TAG = "SKAbstractSensorModule";
38 |
39 | protected final Context mApplicationContext;
40 | protected final SKSensorModuleType mSensorModuleType;
41 | protected boolean isSensing = false;
42 | protected ArrayList mSensorDataListeners;
43 |
44 | protected SKAbstractSensorModule(final Context context, final SKSensorModuleType sensorModuleType) {
45 |
46 | this.mApplicationContext = context;
47 | this.mSensorModuleType = sensorModuleType;
48 | }
49 |
50 | public boolean isSensing() {
51 | return isSensing;
52 | }
53 |
54 | public SKSensorModuleType getSensorType() {
55 | return this.mSensorModuleType;
56 | }
57 |
58 | public String getSensorName() throws SKException {
59 | return SKSensorModuleUtilities.getSensorModuleInString(mSensorModuleType);
60 | }
61 |
62 | public void subscribeSensorDataListener(SKSensorDataListener callback) throws SKException {
63 |
64 | // Init the list
65 | if (this.mSensorDataListeners == null) {
66 | this.mSensorDataListeners = new ArrayList<>();
67 | }
68 |
69 | // Register the callback
70 | if (this.mSensorDataListeners.contains(callback)) {
71 | throw new SKException(TAG, "SKSensorDataListener already registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
72 | }
73 |
74 | this.mSensorDataListeners.add(callback);
75 | }
76 |
77 | public void unsubscribeSensorDataListener(SKSensorDataListener callback) throws SKException {
78 |
79 | // Unregister the callback
80 | if (this.mSensorDataListeners == null || !this.mSensorDataListeners.remove(callback)) {
81 | throw new SKException(TAG, "SKSensorDataListener is not registered.", SKExceptionErrorCode.UNKNOWN_ERROR);
82 | }
83 |
84 | // Delete the callBackList if it is empty
85 | if (this.mSensorDataListeners.size() == 0) {
86 | this.mSensorDataListeners = null;
87 | }
88 | }
89 |
90 | public void unsubscribeAllSensorDataListeners() throws SKException {
91 |
92 | // Clear all callbacks
93 | if (this.mSensorDataListeners != null) {
94 | this.mSensorDataListeners.clear();
95 | this.mSensorDataListeners = null;
96 | }
97 | }
98 |
99 | protected abstract boolean shouldPostSensorData(SKAbstractData data);
100 |
101 | protected void submitSensorData(SKAbstractData data) {
102 |
103 | // If there is a significant change
104 | if (shouldPostSensorData(data)) {
105 |
106 | if (mSensorDataListeners != null) {
107 |
108 | // CallBack with data as parameter
109 | for (SKSensorDataListener callback : mSensorDataListeners) {
110 | callback.onDataReceived(mSensorModuleType, data);
111 | }
112 | }
113 | }
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAccelerometer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKAccelerometerData;
31 |
32 | public class SKAccelerometer extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKAccelerometer";
36 |
37 | public SKAccelerometer(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.ACCELEROMETER);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKAccelerometerData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.app.PendingIntent;
25 | import android.content.BroadcastReceiver;
26 | import android.content.Context;
27 | import android.content.Intent;
28 | import android.content.IntentFilter;
29 | import android.support.v4.content.LocalBroadcastManager;
30 | import android.util.Log;
31 | import com.google.android.gms.location.ActivityRecognitionApi;
32 | import com.google.android.gms.common.api.GoogleApiClient;
33 | import com.google.android.gms.location.ActivityRecognition;
34 | import com.google.android.gms.location.ActivityRecognitionResult;
35 | import com.google.android.gms.location.DetectedActivity;
36 |
37 |
38 | import org.sensingkit.sensingkitlib.SKException;
39 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
40 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
41 | import org.sensingkit.sensingkitlib.data.SKActivityData;
42 |
43 | public class SKActivity extends SKAbstractGoogleServicesSensorModule {
44 |
45 | @SuppressWarnings("unused")
46 | private static final String TAG = "SKActivity";
47 |
48 | private ActivityRecognitionApi mActivityRecognition;
49 | private PendingIntent mRecognitionPendingIntent;
50 | private BroadcastReceiver mBroadcastReceiver;
51 |
52 | // Last data sensed
53 | private int mLastActivityTypeSensed = Integer.MAX_VALUE;
54 | private int mLastConfidenceSensed = Integer.MAX_VALUE;
55 |
56 | public SKActivity(final Context context) throws SKException {
57 | super(context, SKSensorModuleType.ACTIVITY);
58 |
59 | mClient = new GoogleApiClient.Builder(context)
60 | .addApi(ActivityRecognition.API)
61 | .addConnectionCallbacks(this)
62 | .addOnConnectionFailedListener(this)
63 | .build();
64 |
65 | mActivityRecognition = ActivityRecognition.ActivityRecognitionApi;
66 |
67 | mBroadcastReceiver = new BroadcastReceiver() {
68 | @Override
69 | public void onReceive(Context context, Intent intent) {
70 |
71 | ActivityRecognitionResult result = intent.getParcelableExtra(SKActivityRecognitionIntentService.RECOGNITION_RESULT);
72 |
73 | // Get activity from the list of activities
74 | DetectedActivity activity = getActivity(result);
75 |
76 | // Get the type of activity
77 | int activityType = activity.getType();
78 |
79 | // Get the confidence percentage for the most probable activity
80 | int confidence = activity.getConfidence();
81 |
82 | // Build the data object
83 | SKAbstractData data = new SKActivityData(result.getTime(), activityType, confidence);
84 |
85 | // Submit sensor data object
86 | submitSensorData(data);
87 | }
88 | };
89 | }
90 |
91 | private DetectedActivity getActivity(ActivityRecognitionResult result) {
92 |
93 | // Get the most probable activity from the list of activities in the result
94 | DetectedActivity mostProbableActivity = result.getMostProbableActivity();
95 |
96 | // If the activity is ON_FOOT, choose between WALKING or RUNNING
97 | if (mostProbableActivity.getType() == DetectedActivity.ON_FOOT) {
98 |
99 | // Iterate through all possible activities. The activities are sorted by most probable activity first.
100 | for (DetectedActivity activity : result.getProbableActivities()) {
101 |
102 | if (activity.getType() == DetectedActivity.WALKING || activity.getType() == DetectedActivity.RUNNING) {
103 | return activity;
104 | }
105 | }
106 |
107 | // It is ON_FOOT, but not sure if it is WALKING or RUNNING
108 | Log.i(TAG, "Activity ON_FOOT, but not sure if it is WALKING or RUNNING.");
109 | return mostProbableActivity;
110 | }
111 | else
112 | {
113 | return mostProbableActivity;
114 | }
115 |
116 | }
117 |
118 | @Override
119 | public void startSensing() {
120 |
121 | this.isSensing = true;
122 |
123 | mClient.connect();
124 | }
125 |
126 | @Override
127 | public void stopSensing() {
128 |
129 | unregisterIntent();
130 | unregisterLocalBroadcastManager();
131 |
132 | mClient.disconnect();
133 |
134 | this.isSensing = false;
135 |
136 | // Clear last sensed values
137 | mLastActivityTypeSensed = Integer.MAX_VALUE;
138 | mLastConfidenceSensed = Integer.MAX_VALUE;
139 | }
140 |
141 | @Override
142 | protected void serviceConnected()
143 | {
144 | Log.i(TAG, "GoogleApiClient Connected!");
145 |
146 | registerLocalBroadcastManager();
147 | registerIntent();
148 | }
149 |
150 | private void registerIntent() {
151 |
152 | if (mRecognitionPendingIntent == null) {
153 | Intent intent = new Intent(mApplicationContext, SKActivityRecognitionIntentService.class);
154 | mRecognitionPendingIntent = PendingIntent.getService(mApplicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
155 | }
156 |
157 | mActivityRecognition.requestActivityUpdates(mClient, 0, mRecognitionPendingIntent);
158 | }
159 |
160 | private void unregisterIntent() {
161 |
162 | mActivityRecognition.removeActivityUpdates(mClient, mRecognitionPendingIntent);
163 | mRecognitionPendingIntent.cancel();
164 | mRecognitionPendingIntent = null;
165 | }
166 |
167 | private void registerLocalBroadcastManager() {
168 | LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplicationContext);
169 | manager.registerReceiver(mBroadcastReceiver, new IntentFilter(SKActivityRecognitionIntentService.BROADCAST_UPDATE));
170 | }
171 |
172 | private void unregisterLocalBroadcastManager() {
173 | LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplicationContext);
174 | manager.unregisterReceiver(mBroadcastReceiver);
175 | }
176 |
177 | @Override
178 | protected boolean shouldPostSensorData(SKAbstractData data) {
179 |
180 | // Only post when specific values changed
181 |
182 | int activityType = ((SKActivityData)data).getActivityType();
183 | int confidence = ((SKActivityData)data).getConfidence();
184 |
185 | // Ignore Temperature and Voltage
186 | boolean shouldPost = (mLastActivityTypeSensed != activityType ||
187 | mLastConfidenceSensed != confidence );
188 |
189 | if (shouldPost) {
190 |
191 | this.mLastActivityTypeSensed = activityType;
192 | this.mLastConfidenceSensed = confidence;
193 | }
194 |
195 | return shouldPost;
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKActivityRecognitionIntentService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.app.IntentService;
25 | import android.content.Intent;
26 | import android.support.v4.content.LocalBroadcastManager;
27 |
28 | import com.google.android.gms.location.ActivityRecognitionResult;
29 |
30 | public class SKActivityRecognitionIntentService extends IntentService {
31 |
32 | @SuppressWarnings("unused")
33 | private static final String TAG = "SKActivityRecognitionIntentService";
34 |
35 | public static final String RECOGNITION_RESULT = "result";
36 | public static final String BROADCAST_UPDATE = "new_update";
37 |
38 | public SKActivityRecognitionIntentService() {
39 |
40 | // Set the label for the service's background thread
41 | super("ActivityRecognitionIntentService");
42 | }
43 |
44 | @Override
45 | protected void onHandleIntent(Intent intent) {
46 |
47 | // If the intent contains an update
48 | if (ActivityRecognitionResult.hasResult(intent)) {
49 |
50 | // Get the update
51 | ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
52 |
53 | Intent i = new Intent(BROADCAST_UPDATE);
54 | i.putExtra(RECOGNITION_RESULT, result);
55 | LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
56 | manager.sendBroadcast(i);
57 | }
58 |
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAmbientTemperature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKAmbientTemperatureData;
31 |
32 | public class SKAmbientTemperature extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKAmbientTemperature";
36 |
37 | public SKAmbientTemperature(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.AMBIENT_TEMPERATURE);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKAmbientTemperatureData(System.currentTimeMillis(), event.values[0]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioLevel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.media.AudioFormat;
26 | import android.media.AudioRecord;
27 | import android.media.MediaRecorder;
28 |
29 | import org.sensingkit.sensingkitlib.SKException;
30 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
31 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
32 | import org.sensingkit.sensingkitlib.data.SKAudioLevelData;
33 |
34 | public class SKAudioLevel extends SKAbstractSensorModule {
35 |
36 | @SuppressWarnings("unused")
37 | private static final String TAG = "SKAudioLevel";
38 |
39 | private static final int sampleRate = 8000;
40 | private static final int bufferSizeFactor = 1;
41 |
42 | private final int bufferSize = AudioRecord.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) * bufferSizeFactor;
43 |
44 | private final AudioRecord audioRecord;
45 |
46 | public SKAudioLevel(final Context context) throws SKException {
47 | super(context, SKSensorModuleType.AUDIO_LEVEL);
48 |
49 | // Configure the AudioRecord
50 | audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
51 | }
52 |
53 | @Override
54 | protected boolean shouldPostSensorData(SKAbstractData data) {
55 |
56 | // Always post sensor data
57 | return true;
58 | }
59 |
60 | @Override
61 | public void startSensing() {
62 |
63 | this.isSensing = true;
64 |
65 | // monitor audio
66 | audioRecord.startRecording();
67 |
68 | // init the thread that read the audio buffer
69 | Thread thread = new Thread(new Runnable() {
70 | public void run() {
71 | readAudioBuffer();
72 | }
73 | });
74 |
75 | // Set priority to max and start the thread that reads the audio level
76 | thread.setPriority(Thread.currentThread().getThreadGroup().getMaxPriority());
77 | thread.start();
78 | }
79 |
80 | @Override
81 | public void stopSensing() {
82 |
83 | audioRecord.stop();
84 |
85 | this.isSensing = false;
86 | }
87 |
88 | private void readAudioBuffer() {
89 |
90 | short[] buffer = new short[bufferSize];
91 |
92 | int bufferReadResult;
93 |
94 | do {
95 | // read buffer
96 | bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
97 |
98 | // get max audio level
99 | int level = getMaxAbs(buffer);
100 |
101 | // Build the data object
102 | SKAbstractData data = new SKAudioLevelData(System.currentTimeMillis(), level);
103 |
104 | // Submit sensor data object
105 | submitSensorData(data);
106 | }
107 | while (bufferReadResult > 0 && audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING);
108 | }
109 |
110 | // Get the Max Abs of the raw data
111 | private int getMaxAbs(short[] raw) {
112 |
113 | int max = Math.abs(raw[0]);
114 |
115 | for (int i = 1 ; i < raw.length; i++)
116 | {
117 | max = Math.max(max, Math.abs(raw[i]));
118 | }
119 |
120 | return max;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAudioRecorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.media.MediaRecorder;
26 | import android.os.Environment;
27 |
28 | import org.sensingkit.sensingkitlib.SKException;
29 | import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
30 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
31 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
32 |
33 | import java.io.IOException;
34 |
35 | public class SKAudioRecorder extends SKAbstractSensorModule {
36 |
37 | @SuppressWarnings("unused")
38 | private static final String TAG = "SKAudioRecorder";
39 |
40 | private static final String outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.aac";
41 |
42 | private final MediaRecorder recorder;
43 |
44 | public SKAudioRecorder(final Context context) throws SKException {
45 | super(context, SKSensorModuleType.AUDIO_RECORDER);
46 |
47 | recorder = new MediaRecorder();
48 | recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
49 | recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
50 | recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
51 | recorder.setOutputFile(outputFile);
52 | }
53 |
54 | @Override
55 | protected boolean shouldPostSensorData(SKAbstractData data) {
56 |
57 | // This sensor does not post data
58 | return false;
59 | }
60 |
61 | @Override
62 | public void startSensing() throws SKException {
63 |
64 | this.isSensing = true;
65 |
66 | try {
67 | recorder.prepare();
68 | } catch (IOException e) {
69 | e.printStackTrace();
70 | throw new SKException(TAG, "AudioRecorder sensor could not be prepared.", SKExceptionErrorCode.UNKNOWN_ERROR);
71 | }
72 |
73 | recorder.start();
74 | }
75 |
76 | @Override
77 | public void stopSensing() {
78 |
79 | this.isSensing = false;
80 |
81 | recorder.stop();
82 | recorder.reset();
83 | recorder.release();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBattery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.BroadcastReceiver;
25 | import android.content.Context;
26 | import android.content.Intent;
27 | import android.content.IntentFilter;
28 |
29 | import org.sensingkit.sensingkitlib.SKException;
30 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
31 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
32 | import org.sensingkit.sensingkitlib.data.SKBatteryData;
33 |
34 | public class SKBattery extends SKAbstractSensorModule {
35 |
36 | @SuppressWarnings("unused")
37 | private static final String TAG = "SKBattery";
38 |
39 | // Last data sensed
40 | private int mLastLevelSensed = Integer.MAX_VALUE;
41 | private int mLastScaleSensed = Integer.MAX_VALUE;
42 | private int mLastTemperatureSensed = Integer.MAX_VALUE;
43 | private int mLastVoltageSensed = Integer.MAX_VALUE;
44 | private int mLastPluggedSensed = Integer.MAX_VALUE;
45 | private int mLastStatusSensed = Integer.MAX_VALUE;
46 | private int mLastHealthSensed = Integer.MAX_VALUE;
47 |
48 | private final BroadcastReceiver mBroadcastReceiver;
49 |
50 | public SKBattery(final Context context) throws SKException {
51 | super(context, SKSensorModuleType.BATTERY);
52 |
53 | mBroadcastReceiver = new BroadcastReceiver() {
54 | @Override
55 | public void onReceive(Context context, Intent intent) {
56 |
57 | // Read Battery
58 | int level = intent.getIntExtra("level", -1);
59 | int scale = intent.getIntExtra("scale", -1);
60 | int temperature = intent.getIntExtra("temperature", 0);
61 | int voltage = intent.getIntExtra("voltage", 0);
62 | int plugged = intent.getIntExtra("plugged", -1);
63 | int status = intent.getIntExtra("status", 0);
64 | int health = intent.getIntExtra("health", 0);
65 |
66 | // Build the data object
67 | SKAbstractData data = new SKBatteryData(System.currentTimeMillis(), level, scale, temperature, voltage, plugged, status, health);
68 |
69 | // Submit sensor data object
70 | submitSensorData(data);
71 | }
72 | };
73 | }
74 |
75 | @Override
76 | public void startSensing() {
77 |
78 | this.isSensing = true;
79 |
80 | registerLocalBroadcastManager();
81 | }
82 |
83 | @Override
84 | public void stopSensing() {
85 |
86 | unregisterLocalBroadcastManager();
87 |
88 | this.isSensing = false;
89 |
90 | // Clear last sensed values
91 | mLastLevelSensed = Integer.MAX_VALUE;
92 | mLastScaleSensed = Integer.MAX_VALUE;
93 | mLastTemperatureSensed = Integer.MAX_VALUE;
94 | mLastVoltageSensed = Integer.MAX_VALUE;
95 | mLastPluggedSensed = Integer.MAX_VALUE;
96 | mLastStatusSensed = Integer.MAX_VALUE;
97 | mLastHealthSensed = Integer.MAX_VALUE;
98 | }
99 |
100 | private void registerLocalBroadcastManager() {
101 | IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
102 | mApplicationContext.registerReceiver(mBroadcastReceiver, filter);
103 | }
104 |
105 | private void unregisterLocalBroadcastManager() {
106 | mApplicationContext.unregisterReceiver(mBroadcastReceiver);
107 | }
108 |
109 | @Override
110 | protected boolean shouldPostSensorData(SKAbstractData data) {
111 |
112 | // Only post when specific values changed
113 |
114 | int level = ((SKBatteryData)data).getLevel();
115 | int scale = ((SKBatteryData)data).getScale();
116 | int temperature = ((SKBatteryData)data).getTemperature();
117 | int voltage = ((SKBatteryData)data).getVoltage();
118 | int plugged = ((SKBatteryData)data).getPlugged();
119 | int status = ((SKBatteryData)data).getBatteryStatus();
120 | int health = ((SKBatteryData)data).getBatteryHealth();
121 |
122 | // Ignore Temperature and Voltage
123 | boolean shouldPost = (mLastLevelSensed != level ||
124 | mLastScaleSensed != scale ||
125 | mLastPluggedSensed != plugged ||
126 | mLastStatusSensed != status ||
127 | mLastHealthSensed != health );
128 |
129 | if (shouldPost) {
130 | this.mLastLevelSensed = level;
131 | this.mLastScaleSensed = scale;
132 | this.mLastTemperatureSensed = temperature;
133 | this.mLastVoltageSensed = voltage;
134 | this.mLastPluggedSensed = plugged;
135 | this.mLastStatusSensed = status;
136 | this.mLastHealthSensed = health;
137 | }
138 |
139 | return shouldPost;
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKBluetooth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.bluetooth.BluetoothAdapter;
25 | import android.bluetooth.BluetoothDevice;
26 | import android.content.BroadcastReceiver;
27 | import android.content.Context;
28 | import android.content.Intent;
29 | import android.content.IntentFilter;
30 |
31 | import org.sensingkit.sensingkitlib.SKException;
32 | import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
33 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
34 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
35 | import org.sensingkit.sensingkitlib.data.SKBluetoothData;
36 | import org.sensingkit.sensingkitlib.data.SKBluetoothDeviceData;
37 |
38 | import java.util.ArrayList;
39 |
40 | @SuppressWarnings("ResourceType")
41 | public class SKBluetooth extends SKAbstractSensorModule {
42 |
43 | @SuppressWarnings("unused")
44 | private static final String TAG = "SKBluetooth";
45 |
46 | private final BluetoothAdapter mBluetoothAdapter;
47 | private ArrayList mBluetoothDevices;
48 |
49 | public SKBluetooth(Context context) throws SKException {
50 | super(context, SKSensorModuleType.BLUETOOTH);
51 |
52 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
53 | mBluetoothDevices = new ArrayList<>();
54 |
55 | if (mBluetoothAdapter == null) {
56 | throw new SKException(TAG, "Bluetooth sensor module is not supported from the device.", SKExceptionErrorCode.UNKNOWN_ERROR);
57 | }
58 | }
59 |
60 | // Create a BroadcastReceiver for ACTION_FOUND and ACTION_DISCOVERY_FINISHED
61 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
62 |
63 | @Override
64 | public void onReceive(Context context, Intent intent) {
65 |
66 | // Read the action from the intent
67 | String action = intent.getAction();
68 |
69 | if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Device Found
70 |
71 | // Get the BluetoothDevice object from the Intent
72 | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
73 |
74 | String name = device.getName();
75 | String address = device.getAddress();
76 | int rssi = (int) intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
77 |
78 | // Create SKBluetoothDevice and add to mBluetoothDevices array
79 | SKBluetoothDeviceData deviceData = new SKBluetoothDeviceData(System.currentTimeMillis(), name, address, rssi);
80 | mBluetoothDevices.add(deviceData);
81 |
82 | } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { // Discovery Finished
83 |
84 | // Build the data object
85 | SKAbstractData data = new SKBluetoothData(System.currentTimeMillis(), mBluetoothDevices);
86 |
87 | // Clean the arrayList
88 | mBluetoothDevices = new ArrayList<>();
89 |
90 | // Submit sensor data object
91 | submitSensorData(data);
92 |
93 | // Start Discovery again
94 | mBluetoothAdapter.startDiscovery();
95 | }
96 | }
97 | };
98 |
99 | @Override
100 | protected boolean shouldPostSensorData(SKAbstractData data) {
101 |
102 | // Always post sensor data
103 | return true;
104 | }
105 |
106 | @Override
107 | public void startSensing() throws SKException {
108 |
109 | if (mBluetoothAdapter == null) {
110 | throw new SKException(TAG, "Bluetooth sensor module is not supported from the device.", SKExceptionErrorCode.UNKNOWN_ERROR);
111 | }
112 |
113 | if (!mBluetoothAdapter.isEnabled()) {
114 | throw new SKException(TAG, "Bluetooth is not enabled.", SKExceptionErrorCode.UNKNOWN_ERROR);
115 | }
116 |
117 | this.isSensing = true;
118 |
119 | registerLocalBroadcastManager();
120 |
121 | // Start Bluetooth Scanning
122 | mBluetoothAdapter.startDiscovery();
123 | }
124 |
125 | @Override
126 | public void stopSensing() {
127 |
128 | // Stop Bluetooth Scanning
129 | mBluetoothAdapter.cancelDiscovery();
130 |
131 | unregisterLocalBroadcastManager();
132 |
133 | this.isSensing = false;
134 | }
135 |
136 | private void registerLocalBroadcastManager() {
137 |
138 | // Register receivers for ACTION_FOUND and ACTION_DISCOVERY_FINISHED
139 | IntentFilter foundFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
140 | IntentFilter finishedFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
141 | mApplicationContext.registerReceiver(mReceiver, foundFilter);
142 | mApplicationContext.registerReceiver(mReceiver, finishedFilter);
143 | }
144 |
145 | private void unregisterLocalBroadcastManager() {
146 | mApplicationContext.unregisterReceiver(mReceiver);
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGravity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKGravityData;
31 |
32 | public class SKGravity extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKGravity";
36 |
37 | public SKGravity(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.GRAVITY);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKGravityData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKGyroscope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKGyroscopeData;
31 |
32 | public class SKGyroscope extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKGyroscope";
36 |
37 | public SKGyroscope(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.GYROSCOPE);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKGyroscopeData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLight.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKLightData;
31 |
32 | public class SKLight extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKLight";
36 |
37 | private float lastLightSensed = Float.MAX_VALUE;
38 |
39 | public SKLight(final Context context) throws SKException {
40 | super(context, SKSensorModuleType.LIGHT);
41 | }
42 |
43 | @Override
44 | protected SKAbstractData buildData(SensorEvent event)
45 | {
46 | return new SKLightData(System.currentTimeMillis(), event.values[0]);
47 | }
48 |
49 | @Override
50 | protected boolean shouldPostSensorData(SKAbstractData data) {
51 |
52 | // Only post when light value changes
53 |
54 | float light = ((SKLightData)data).getLight();
55 |
56 | boolean shouldPost = (lastLightSensed != light);
57 |
58 | if (shouldPost) {
59 | this.lastLightSensed = light;
60 | }
61 |
62 | return shouldPost;
63 | }
64 |
65 | public void stopSensing() {
66 |
67 | super.stopSensing();
68 |
69 | // Clear last sensed values
70 | lastLightSensed = Float.MAX_VALUE;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLinearAcceleration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKLinearAccelerationData;
31 |
32 | public class SKLinearAcceleration extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKLinearAcceleration";
36 |
37 | public SKLinearAcceleration(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.LINEAR_ACCELERATION);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKLinearAccelerationData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKLocation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.util.Log;
26 |
27 | import com.google.android.gms.common.api.GoogleApiClient;
28 | import com.google.android.gms.location.LocationListener;
29 | import com.google.android.gms.location.LocationRequest;
30 | import com.google.android.gms.location.LocationServices;
31 |
32 | import org.sensingkit.sensingkitlib.SKException;
33 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
34 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
35 | import org.sensingkit.sensingkitlib.data.SKLocationData;
36 |
37 | public class SKLocation extends SKAbstractGoogleServicesSensorModule implements LocationListener {
38 |
39 | @SuppressWarnings("unused")
40 | private static final String TAG = "SKLocation";
41 |
42 | public SKLocation(final Context context) throws SKException {
43 | super(context, SKSensorModuleType.LOCATION);
44 |
45 | mClient = new GoogleApiClient.Builder(context)
46 | .addApi(LocationServices.API)
47 | .addConnectionCallbacks(this)
48 | .addOnConnectionFailedListener(this)
49 | .build();
50 | }
51 |
52 | @Override
53 | public void startSensing() {
54 |
55 | this.isSensing = true;
56 |
57 | mClient.connect();
58 | }
59 |
60 | @Override
61 | public void stopSensing() {
62 |
63 | unregisterForLocationUpdates();
64 | mClient.disconnect();
65 |
66 | this.isSensing = false;
67 | }
68 |
69 | @Override
70 | protected void serviceConnected()
71 | {
72 | Log.i(TAG, "GoogleApiClient Connected!");
73 |
74 | registerForLocationUpdates();
75 | }
76 |
77 | @Override
78 | public void onLocationChanged(android.location.Location location) {
79 |
80 | // Build the data object
81 | SKAbstractData data = new SKLocationData(System.currentTimeMillis(), location);
82 |
83 | // Submit sensor data object
84 | submitSensorData(data);
85 | }
86 |
87 | private void registerForLocationUpdates() {
88 |
89 | LocationRequest locationRequest = LocationRequest.create();
90 | locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
91 | locationRequest.setInterval(1000); // Update location every second
92 |
93 | LocationServices.FusedLocationApi.requestLocationUpdates(mClient, locationRequest, this);
94 | }
95 |
96 | private void unregisterForLocationUpdates() {
97 |
98 | LocationServices.FusedLocationApi.removeLocationUpdates(mClient, this);
99 |
100 | }
101 |
102 | @Override
103 | protected boolean shouldPostSensorData(SKAbstractData data) {
104 |
105 | // Always post sensor data
106 | return true;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKMagnetometer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKMagnetometerData;
31 |
32 | public class SKMagnetometer extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKMagnetometer";
36 |
37 | public SKMagnetometer(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.MAGNETOMETER);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKMagnetometerData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKRotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKRotationData;
31 |
32 | public class SKRotation extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKRotation";
36 |
37 | public SKRotation(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.ROTATION);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | if (event.values.length >= 6) {
45 | return new SKRotationData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2], event.values[3], event.values[4]);
46 | }
47 | else {
48 | return new SKRotationData(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
49 | }
50 | }
51 |
52 | @Override
53 | protected boolean shouldPostSensorData(SKAbstractData data) {
54 |
55 | // Always post sensor data
56 | return true;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKScreenStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.BroadcastReceiver;
25 | import android.content.Context;
26 | import android.content.Intent;
27 | import android.content.IntentFilter;
28 |
29 | import org.sensingkit.sensingkitlib.SKException;
30 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
31 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
32 | import org.sensingkit.sensingkitlib.data.SKScreenStatusData;
33 |
34 | public class SKScreenStatus extends SKAbstractSensorModule {
35 |
36 | private final BroadcastReceiver mBroadcastReceiver;
37 |
38 | @SuppressWarnings("unused")
39 | private static final String TAG = "SKScreenStatus";
40 |
41 | public SKScreenStatus(final Context context) throws SKException {
42 | super(context, SKSensorModuleType.SCREEN_STATUS);
43 |
44 | mBroadcastReceiver = new BroadcastReceiver() {
45 |
46 | @Override
47 | public void onReceive(Context context, Intent intent) {
48 |
49 | // Read Status
50 | int status;
51 |
52 | if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
53 | status = SKScreenStatusData.SCREEN_OFF;
54 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
55 | status = SKScreenStatusData.SCREEN_ON;
56 | } else {
57 | status = SKScreenStatusData.SCREEN_UNKNOWN;
58 | }
59 |
60 | // Build the data object
61 | SKAbstractData data = new SKScreenStatusData(System.currentTimeMillis(), status);
62 |
63 | // Submit sensor data object
64 | submitSensorData(data);
65 | }
66 | };
67 | }
68 |
69 | @Override
70 | protected boolean shouldPostSensorData(SKAbstractData data) {
71 |
72 | // Always post sensor data
73 | return true;
74 | }
75 |
76 | @Override
77 | public void startSensing() {
78 |
79 | this.isSensing = true;
80 |
81 | registerLocalBroadcastManager();
82 | }
83 |
84 | @Override
85 | public void stopSensing() {
86 |
87 | unregisterLocalBroadcastManager();
88 |
89 | this.isSensing = false;
90 | }
91 |
92 | private void registerLocalBroadcastManager() {
93 |
94 | // Register for SCREEN_STATUS ON and OFF notifications
95 | mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
96 | mApplicationContext.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
97 | }
98 |
99 | private void unregisterLocalBroadcastManager() {
100 | mApplicationContext.unregisterReceiver(mBroadcastReceiver);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import org.sensingkit.sensingkitlib.SKException;
25 | import org.sensingkit.sensingkitlib.SKSensorDataListener;
26 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
27 |
28 | @SuppressWarnings("unused")
29 | public interface SKSensorModuleInterface {
30 |
31 | SKSensorModuleType getSensorType();
32 |
33 | void startSensing() throws SKException;
34 | void stopSensing();
35 | boolean isSensing();
36 |
37 | void subscribeSensorDataListener(SKSensorDataListener callback) throws SKException;
38 | void unsubscribeSensorDataListener(SKSensorDataListener callback) throws SKException;
39 | void unsubscribeAllSensorDataListeners() throws SKException;
40 | }
41 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleUtilities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import org.sensingkit.sensingkitlib.SKException;
25 | import org.sensingkit.sensingkitlib.SKExceptionErrorCode;
26 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
27 |
28 | public final class SKSensorModuleUtilities {
29 |
30 | @SuppressWarnings("unused")
31 | private static final String TAG = "SKSensorModuleUtilities";
32 |
33 | public static String getSensorModuleInString(SKSensorModuleType moduleType) throws SKException {
34 |
35 | switch (moduleType) {
36 |
37 | case ACCELEROMETER:
38 | return "Accelerometer";
39 |
40 | case GRAVITY:
41 | return "Gravity";
42 |
43 | case LINEAR_ACCELERATION:
44 | return "Linear Acceleration";
45 |
46 | case GYROSCOPE:
47 | return "Gyroscope";
48 |
49 | case ROTATION:
50 | return "Rotation";
51 |
52 | case MAGNETOMETER:
53 | return "Magnetometer";
54 |
55 | case AMBIENT_TEMPERATURE:
56 | return "Ambient Temperature";
57 |
58 | case STEP_DETECTOR:
59 | return "Step Detector";
60 |
61 | case STEP_COUNTER:
62 | return "Step Counter";
63 |
64 | case LIGHT:
65 | return "Light";
66 |
67 | case LOCATION:
68 | return "Location";
69 |
70 | case ACTIVITY:
71 | return "Activity";
72 |
73 | case BATTERY:
74 | return "Battery";
75 |
76 | case SCREEN_STATUS:
77 | return "Screen Status";
78 |
79 | case AUDIO_RECORDER:
80 | return "Audio Recorder";
81 |
82 | case AUDIO_LEVEL:
83 | return "Audio Level";
84 |
85 | case BLUETOOTH:
86 | return "Bluetooth";
87 |
88 | default:
89 | throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
90 | }
91 |
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKStepCounterData;
31 |
32 | public class SKStepCounter extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKStepCounter";
36 |
37 | public SKStepCounter(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.STEP_COUNTER);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKStepCounterData(System.currentTimeMillis(), event.values[0]);
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKStepDetector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. Queen Mary University of London
3 | * Kleomenis Katevas, k.katevas@qmul.ac.uk
4 | *
5 | * This file is part of SensingKit-Android library.
6 | * For more information, please visit http://www.sensingkit.org
7 | *
8 | * SensingKit-Android is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * SensingKit-Android is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with SensingKit-Android. If not, see .
20 | */
21 |
22 | package org.sensingkit.sensingkitlib.modules;
23 |
24 | import android.content.Context;
25 | import android.hardware.SensorEvent;
26 |
27 | import org.sensingkit.sensingkitlib.SKException;
28 | import org.sensingkit.sensingkitlib.SKSensorModuleType;
29 | import org.sensingkit.sensingkitlib.data.SKAbstractData;
30 | import org.sensingkit.sensingkitlib.data.SKStepDetectorData;
31 |
32 | public class SKStepDetector extends SKAbstractNativeSensorModule {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String TAG = "SKStepDetector";
36 |
37 | public SKStepDetector(final Context context) throws SKException {
38 | super(context, SKSensorModuleType.STEP_DETECTOR);
39 | }
40 |
41 | @Override
42 | protected SKAbstractData buildData(SensorEvent event)
43 | {
44 | return new SKStepDetectorData(System.currentTimeMillis());
45 | }
46 |
47 | @Override
48 | protected boolean shouldPostSensorData(SKAbstractData data) {
49 |
50 | // Always post sensor data
51 | return true;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SensingKit/SensingKit-Android/c1e3a6c7cb60492fdadf61666df9305f4a6e2b75/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 04 21:39:37 GMT 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':SensingKitLib'
2 |
--------------------------------------------------------------------------------