17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 | #00afaa
5 | #00272c
6 | #00afaa
7 | #00afaa
8 | #808080
9 | #D3D3D3
10 | #000000
11 | #00afaa
12 | #808080
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/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 /home/fjordonez/Android/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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_pref_sensors_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
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
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion '27.0.3'
6 |
7 | defaultConfig {
8 | applicationId "uk.ac.sussex.wear.android.datalogger"
9 | minSdkVersion 19
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | testImplementation 'junit:junit:4.12'
25 | implementation 'com.android.support:appcompat-v7:26.1.0'
26 | implementation 'com.android.support:design:26.1.0'
27 | implementation 'com.google.android.gms:play-services-location:12.0.0'
28 | implementation 'com.google.code.gson:gson:2.8.0'
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Mathias Ciliberto, Francisco Javier Ordoñez Morales, Hristijan Gjoreski, Daniel Roggen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PHP_upload_script.txt:
--------------------------------------------------------------------------------
1 | $error) {
3 | if ($error == UPLOAD_ERR_OK) {
4 | $tmp_name = $_FILES["fileToUpload"]["tmp_name"][$key];
5 | $name = $_FILES["fileToUpload"]["name"][$key];
6 | $file_path = "./uploads/";
7 | $file_path = $file_path . $name;
8 | if(move_uploaded_file($tmp_name, $file_path))
9 | {
10 | echo "OK:".$name."\r\n";
11 |
12 | } else{
13 | echo "ERR:".$name."\r\n";
14 | }
15 | }
16 |
17 | }
18 | ?>
19 |
20 | $error) {
23 | $name = $_FILES["fileToUpload"]["name"][$key];
24 | if ($error == UPLOAD_ERR_OK) {
25 | $tmp_name = $_FILES["fileToUpload"]["tmp_name"][$key];
26 | $target_file = $target_dir . $name;
27 | if(move_uploaded_file($tmp_name, $target_file))
28 | {
29 | echo "OK:".$error.":".$name."\r\n";
30 | } else{
31 | echo "ERR:UPLOAD_ERR_MOVE:".$name."\r\n";
32 | }
33 | } else {
34 | echo "ERR:".$error.":".$name."\r\n";
35 | }
36 | }
37 | ?>
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.idea/copyright/WearlabMITLicence.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/BondedDevice.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 21/04/2014.
27 | */
28 | public class BondedDevice {
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/ClientConnectionFail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 13/04/2014.
27 | */
28 | public class ClientConnectionFail {
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/ClientConnectionSuccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 13/04/2014.
27 | */
28 | public class ClientConnectionSuccess {
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bluetooth_device_name.xml:
--------------------------------------------------------------------------------
1 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandBTS.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | public class CommandBTS extends CommandBase {
26 |
27 | @Override
28 | public String getMessage() {
29 | return COMMAND_START
30 | + COMMAND_BLUETOOTH_START + COMMAND_SEPARATOR;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandFUC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | public class CommandFUC extends CommandBase {
26 |
27 | @Override
28 | public String getMessage() {
29 | return COMMAND_START
30 | + COMMAND_FILES_UPLOAD_CANCEL + COMMAND_SEPARATOR;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandFUS.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | public class CommandFUS extends CommandBase {
26 |
27 | @Override
28 | public String getMessage() {
29 | return COMMAND_START
30 | + COMMAND_FILES_UPLOAD_START + COMMAND_SEPARATOR;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 | >
24 |
25 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
27 | 64dp
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/BluetoothCommunicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 13/04/2014.
27 | */
28 | public class BluetoothCommunicator {
29 |
30 | public String mMessageReceive;
31 |
32 | public BluetoothCommunicator(String messageReceive){
33 | mMessageReceive = messageReceive;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/DataLoggerStatusDelegate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 |
26 | public interface DataLoggerStatusDelegate {
27 |
28 | void onError(final int errorCode);
29 |
30 | void onUploadProgress(final int nbFilesUpload, final int nbRemainingFilesUpload, final String uploadRate, final long pct);
31 |
32 | void onUploadCancelled();
33 |
34 | void onUploadComplete();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/ServeurConnectionSuccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 13/04/2014.
27 | */
28 | public class ServeurConnectionSuccess {
29 |
30 | public String mClientAdressConnected;
31 |
32 | public ServeurConnectionSuccess(String clientAdressConnected){
33 | mClientAdressConnected = clientAdressConnected;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bus/ServeurConnectionFail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bus;
24 |
25 | /**
26 | * Created by Rami MARTIN on 13/04/2014.
27 | */
28 | public class ServeurConnectionFail {
29 |
30 | public String mClientAdressConnectionFail;
31 |
32 | public ServeurConnectionFail(String clientAdressConnectionFail){
33 | mClientAdressConnectionFail = clientAdressConnectionFail;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandBTC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | public class CommandBTC extends CommandBase {
26 |
27 | String mAddress;
28 |
29 | public CommandBTC(String address) {
30 | mAddress = address;
31 | }
32 |
33 | @Override
34 | public String getMessage() {
35 | return COMMAND_START
36 | + COMMAND_BLUETOOTH_CONNECT + COMMAND_SEPARATOR
37 | + mAddress + PARAMETER_SEPARATOR;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/AboutActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 | import android.os.Bundle;
26 | import android.support.annotation.Nullable;
27 | import android.support.v7.app.AppCompatActivity;
28 |
29 | /**
30 | * Created by ThiasTux.
31 | */
32 |
33 | public class AboutActivity extends AppCompatActivity {
34 |
35 | @Override
36 | protected void onCreate(@Nullable Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_about);
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/collector/AbstractDataCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.collector;
24 |
25 |
26 | public abstract class AbstractDataCollector {
27 |
28 | protected long mNanosOffset = 0;
29 | protected String mSensorName;
30 |
31 | public String getSensorName() {
32 | return mSensorName;
33 | }
34 |
35 | public abstract void start();
36 | public abstract void stop();
37 | public abstract void haltAndRestartLogging();
38 |
39 | public abstract void updateNanosOffset(long nanosOffset);
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandFLE.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | /**
26 | * Created by mathias on 01/02/17.
27 | */
28 | public class CommandFLE extends CommandBase {
29 |
30 | String flag;
31 | String notes;
32 |
33 | public CommandFLE(String flag, String notes) {
34 | this.flag = flag;
35 | this.notes = notes;
36 | }
37 |
38 | public String getMessage() {
39 | return COMMAND_START
40 | + COMMAND_FLAG_EVENT + COMMAND_SEPARATOR
41 | + flag + PARAMETER_SEPARATOR
42 | + notes + PARAMETER_SEPARATOR;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/StartAtBootReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 |
26 | import android.content.BroadcastReceiver;
27 | import android.content.Context;
28 | import android.content.Intent;
29 |
30 | public class StartAtBootReceiver extends BroadcastReceiver {
31 | @Override
32 | public void onReceive(Context context, Intent intent) {
33 |
34 | if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
35 | Intent myStarterIntent = new Intent(context, DisplayActivity.class);
36 | myStarterIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
37 | context.startActivity(myStarterIntent);
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/HttpStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * Defines the methods that has to be implemented by an HTTP stack.
29 | * @author gotev (Aleksandar Gotev)
30 | */
31 | public interface HttpStack {
32 |
33 | /**
34 | * Creates a new connection for a given URL and HTTP Method.
35 | * @param method HTTP Method
36 | * @param url URL to which to connect to
37 | * @return new connection object
38 | * @throws IOException if an error occurs while creating the connection object
39 | */
40 | HttpConnection createNewConnection(String method, String url) throws IOException;
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_icons_list_item.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
27 |
28 |
33 |
34 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_headers.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
25 |
29 |
30 |
34 |
35 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/db/DataLoggerOpenHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.db;
24 |
25 | import android.content.Context;
26 | import android.database.sqlite.SQLiteDatabase;
27 | import android.database.sqlite.SQLiteOpenHelper;
28 |
29 | public class DataLoggerOpenHelper extends SQLiteOpenHelper {
30 |
31 | private static final String DATABASE_NAME = "datalogger.db";
32 | private static final int DATABASE_VERSION = 3;
33 |
34 |
35 | public DataLoggerOpenHelper(Context context) {
36 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
37 | }
38 |
39 | // Method is called during creation of the database
40 | @Override
41 | public void onCreate(SQLiteDatabase db) {
42 |
43 | DataCollectionSessionTable.onCreate(db);
44 | LogFileTable.onCreate(db);
45 | }
46 |
47 | // Method is called during an upgrade of the database,
48 | // e.g. if increase of database version
49 | @Override
50 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
51 | DataCollectionSessionTable.onUpgrade(db, oldVersion, newVersion);
52 | LogFileTable.onUpgrade(db, oldVersion, newVersion);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/HurlStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * HttpUrlConnection stack implementation.
29 | * @author gotev (Aleksandar Gotev)
30 | */
31 | public class HurlStack implements HttpStack {
32 |
33 | private boolean mFollowRedirects;
34 | private boolean mUseCaches;
35 | private int mConnectTimeout;
36 | private int mReadTimeout;
37 |
38 | public HurlStack() {
39 | mFollowRedirects = true;
40 | mUseCaches = false;
41 | mConnectTimeout = 15000;
42 | mReadTimeout = 30000;
43 | }
44 |
45 | public HurlStack(boolean followRedirects,
46 | boolean useCaches,
47 | int connectTimeout,
48 | int readTimeout) {
49 | mFollowRedirects = followRedirects;
50 | mUseCaches = useCaches;
51 | mConnectTimeout = connectTimeout;
52 | mReadTimeout = readTimeout;
53 | }
54 |
55 | @Override
56 | public HttpConnection createNewConnection(String method, String url) throws IOException {
57 | return new HurlStackConnection(method, url, mFollowRedirects, mUseCaches,
58 | mConnectTimeout, mReadTimeout);
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
31 |
32 |
36 |
37 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/Placeholders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | /**
26 | * Contains all the placeholders that is possible to use in the notification text strings.
27 | * @author Aleksandar Gotev
28 | */
29 | public class Placeholders {
30 |
31 | /**
32 | * Placeholder to display the total elapsed upload time in minutes and seconds.
33 | * E.g.: 34s, 4m 33s, 45m 21s
34 | */
35 | public static final String ELAPSED_TIME = "[[ELAPSED_TIME]]";
36 |
37 | /**
38 | * Placeholder to display the average upload rate. E.g.: 6 Mbit/s, 634 Kbit/s, 232 bit/s
39 | */
40 | public static final String UPLOAD_RATE = "[[UPLOAD_RATE]]";
41 |
42 | /**
43 | * Placeholder to display the integer progress percent from 0 to 100. E.g.: 75%
44 | */
45 | public static final String PROGRESS = "[[PROGRESS]]";
46 |
47 | /**
48 | * Placeholder to display the number of successfully uploaded files.
49 | * Bear in mind that in case of HTTP/Multipart or Binary uploads which does not support
50 | * resume, if the request gets restarted due to an error, the number of uploaded files will
51 | * be reset to zero.
52 | */
53 | public static final String UPLOADED_FILES = "[[UPLOADED_FILES]]";
54 |
55 | /**
56 | * Placeholder to display the total number of files to upload.
57 | */
58 | public static final String TOTAL_FILES = "[[TOTAL_FILES]]";
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/UploadStatusDelegate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | /**
26 | * Defines the methods that has to be implemented by a class who wants to listen for upload status
27 | * events.
28 | *
29 | * @author Aleksandar Gotev
30 | */
31 | public interface UploadStatusDelegate {
32 | /**
33 | * Called when the upload progress changes. Override this method to add your own logic.
34 | *
35 | * @param uploadInfo upload status information
36 | */
37 | void onProgress(final UploadInfo uploadInfo);
38 |
39 | /**
40 | * Called when an error happens during the upload. Override this method to add your own logic.
41 | *
42 | * @param uploadInfo upload status information
43 | * @param exception exception that caused the error
44 | */
45 | void onError(final UploadInfo uploadInfo, final Exception exception);
46 |
47 | /**
48 | * Called when the upload is completed successfully. Override this method to add your own logic.
49 | *
50 | * @param uploadInfo upload status information
51 | * @param serverResponse response got from the server
52 | */
53 | void onCompleted(final UploadInfo uploadInfo, final ServerResponse serverResponse);
54 |
55 | /**
56 | * Called when the upload is cancelled. Override this method to add your own logic.
57 | *
58 | * @param uploadInfo upload status information
59 | */
60 | void onCancelled(final UploadInfo uploadInfo);
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
27 |
28 |
37 |
38 |
39 |
48 |
49 |
59 |
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_show_stats.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
29 |
30 |
36 |
37 |
41 |
42 |
48 |
49 |
50 |
56 |
57 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/db/DataCollectionSessionTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.db;
24 |
25 | import android.database.sqlite.SQLiteDatabase;
26 | import android.util.Log;
27 |
28 |
29 | public class DataCollectionSessionTable {
30 |
31 | private static final String TAG = DataCollectionSessionTable.class.getSimpleName();
32 |
33 | public static final String TABLE_NAME_SESSIONS = "sessions";
34 | public static final String COLUMN_ID = "id";
35 | public static final String COLUMN_START = "start";
36 | public static final String COLUMN_END = "end";
37 | public static final String COLUMN_LENGTH = "length";
38 |
39 | // Database creation sql statement
40 | private static final String CREATE_TABLE_SESSIONS =
41 | "CREATE TABLE " + TABLE_NAME_SESSIONS + " ("
42 | + COLUMN_ID + " TEXT PRIMARY KEY, "
43 | + COLUMN_START + " TEXT NOT NULL, "
44 | + COLUMN_END + " TEXT NOT NULL DEFAULT '', "
45 | + COLUMN_LENGTH + " INTEGER DEFAULT 0);";
46 |
47 | public static void onCreate(SQLiteDatabase database) {
48 | database.execSQL(CREATE_TABLE_SESSIONS);
49 | }
50 |
51 | public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
52 | Log.w(TAG,
53 | "Upgrading database from version " + oldVersion + " to "
54 | + newVersion + ", which will destroy all old data");
55 |
56 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_SESSIONS);
57 | onCreate(db);
58 | }
59 |
60 | public static String[] getAllColumns(){
61 | return new String[] {COLUMN_ID, COLUMN_START, COLUMN_END, COLUMN_LENGTH};
62 | }
63 |
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
25 | Still
26 | Walk
27 | Run
28 | Bike
29 | Car
30 | Bus
31 | Train
32 | Subway
33 |
34 |
35 |
36 | Stand
37 | Sit
38 |
39 |
40 |
41 | @drawable/ic_act_stl_128
42 | @drawable/ic_act_wlk_128
43 | @drawable/ic_act_run_128
44 | @drawable/ic_act_bik_128
45 | @drawable/ic_act_car_128
46 | @drawable/ic_act_bus_128
47 | @drawable/ic_act_trn_128
48 | @drawable/ic_act_sbw_128
49 |
50 |
51 |
52 | @drawable/ic_pos_std_on_128
53 | @drawable/ic_pos_sit_on_128
54 |
55 |
56 |
57 | @drawable/ic_pos_std_off_128
58 | @drawable/ic_pos_sit_off_128
59 |
60 |
61 |
62 | @string/forgot_to_start
63 | @string/forgot_to_stop
64 | @string/wrong_activity_label
65 | @string/wrong_posture_label
66 | @string/wrong_location_label
67 | @string/other
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
66 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/har/HARecognizerApiIntentService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.har;
24 |
25 | import android.app.IntentService;
26 | import android.content.Intent;
27 | import android.support.v4.content.LocalBroadcastManager;
28 |
29 | import com.google.android.gms.location.ActivityRecognitionResult;
30 | import com.google.android.gms.location.DetectedActivity;
31 |
32 | import java.util.ArrayList;
33 |
34 | import uk.ac.sussex.wear.android.datalogger.Constants;
35 |
36 | public class HARecognizerApiIntentService extends IntentService {
37 |
38 | private static final String TAG = HARecognizerApiIntentService.class.getSimpleName();
39 |
40 | public HARecognizerApiIntentService() {
41 | super(TAG);
42 | }
43 |
44 | /**
45 | * Creates an IntentService. Invoked by your subclass's constructor.
46 | *
47 | * @param name Used to name the worker thread, important only for debugging.
48 | */
49 | public HARecognizerApiIntentService(String name) {
50 | super(name);
51 | }
52 |
53 | @Override
54 | protected void onHandleIntent(Intent intent) {
55 | ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
56 |
57 | // Get the list of the probable activities associated with the current state of the
58 | // device. Each activity is associated with a confidence level, which is an int between
59 | // 0 and 100.
60 | ArrayList detectedActivities = (ArrayList) result.getProbableActivities();
61 |
62 | // Broadcast the list of detected activities.
63 | LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.BROADCAST_ACTION)
64 | .putExtra(Constants.DETECTED_ACTIVITIES_INTENT_KEY, detectedActivities)
65 | );
66 |
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/db/LogFileTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.db;
24 |
25 | import android.database.sqlite.SQLiteDatabase;
26 | import android.util.Log;
27 |
28 | public class LogFileTable {
29 |
30 | private static final String TAG = LogFileTable.class.getSimpleName();
31 |
32 | public static final String TABLE_NAME_LOGFILES = "logFiles";
33 | public static final String COLUMN_PATH = "absolute_path";
34 | public static final String COLUMN_SENSOR_NAME = "sensor_name";
35 | public static final String COLUMN_SESSION_ID = "session_id";
36 | public static final String COLUMN_SYNC = "is_sync";
37 |
38 | // Database creation sql statement
39 | private static final String CREATE_TABLE_LOGFILES =
40 | "CREATE TABLE " + TABLE_NAME_LOGFILES + " ("
41 | + COLUMN_PATH + " TEXT PRIMARY KEY, "
42 | + COLUMN_SENSOR_NAME + " TEXT NOT NULL, "
43 | + COLUMN_SESSION_ID + " TEXT NOT NULL, "
44 | + COLUMN_SYNC + " INTEGER DEFAULT 0, "
45 | + "FOREIGN KEY(" + COLUMN_SESSION_ID + ") REFERENCES "
46 | + DataCollectionSessionTable.TABLE_NAME_SESSIONS + "("
47 | + DataCollectionSessionTable.COLUMN_ID + ") );";
48 |
49 | public static void onCreate(SQLiteDatabase database) {
50 | database.execSQL(CREATE_TABLE_LOGFILES);
51 | }
52 |
53 | public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
54 | Log.w(TAG,
55 | "Upgrading database from version " + oldVersion + " to "
56 | + newVersion + ", which will destroy all old data");
57 |
58 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_LOGFILES);
59 | onCreate(db);
60 | }
61 |
62 | public static String[] getAllColumns(){
63 | return new String[] {COLUMN_PATH, COLUMN_SENSOR_NAME, COLUMN_SESSION_ID, COLUMN_SYNC};
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandDCE.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | import java.util.Iterator;
26 |
27 | public class CommandDCE extends CommandBase {
28 |
29 | private boolean mState;
30 | private String mMasterSessionId;
31 | private long mNanosOffset;
32 |
33 | public CommandDCE(){
34 | this(true, "", -1);
35 | }
36 |
37 | public CommandDCE(boolean state){
38 | this(state, "", -1);
39 | }
40 |
41 | public CommandDCE(boolean state, String masterSessionId, long nanosOffset){
42 | mState = state;
43 | mMasterSessionId = masterSessionId;
44 | mNanosOffset = nanosOffset;
45 | }
46 |
47 | public boolean getState(){
48 | return mState;
49 | }
50 |
51 | public String getMasterSessionId(){
52 | return mMasterSessionId;
53 | }
54 |
55 | public long getNanosOffset(){
56 | return mNanosOffset;
57 | }
58 |
59 | public Iterator setParams(Iterator itr) throws Exception {
60 | if (!itr.hasNext())
61 | throw new Exception("Command '" + COMMAND_DATA_COLLECTION_EVENT + "' is malformed or missing parameters");
62 | mState = Boolean.parseBoolean(itr.next());
63 | if (!itr.hasNext())
64 | throw new Exception("Command '" + COMMAND_DATA_COLLECTION_EVENT + "' is malformed or missing parameters");
65 | mMasterSessionId = itr.next();
66 | if (!itr.hasNext())
67 | throw new Exception("Command '" + COMMAND_DATA_COLLECTION_EVENT + "' is malformed or missing parameters");
68 | mNanosOffset = Long.parseLong(itr.next());
69 | return itr;
70 | }
71 |
72 | @Override
73 | public String getMessage() {
74 | return this.COMMAND_START
75 | + COMMAND_DATA_COLLECTION_EVENT + COMMAND_SEPARATOR
76 | + Boolean.toString(mState) + PARAMETER_SEPARATOR
77 | + mMasterSessionId + PARAMETER_SEPARATOR
78 | + Long.toString(mNanosOffset) + PARAMETER_SEPARATOR;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/CustomIconsListAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 | import android.content.Context;
26 | import android.content.res.TypedArray;
27 | import android.support.v4.content.ContextCompat;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.BaseAdapter;
32 | import android.widget.ImageView;
33 | import android.widget.TextView;
34 |
35 | public class CustomIconsListAdapter extends BaseAdapter {
36 | private TypedArray mIcons;
37 | private String[] mNames;
38 | private int mColorText;
39 | private LayoutInflater mInflater;
40 |
41 | public CustomIconsListAdapter(Context applicationContext, TypedArray icons, String[] names) {
42 | this(applicationContext, icons, names, ContextCompat.getColor(applicationContext, R.color.colorSpinnerOn));
43 | }
44 |
45 | public CustomIconsListAdapter(Context context, TypedArray icons, String[] names, int colorText) {
46 | mNames = names;
47 | mIcons = icons;
48 | mColorText = colorText;
49 | mInflater = (LayoutInflater.from(context));
50 | }
51 |
52 | @Override
53 | public int getCount() {
54 | return mNames.length;
55 | }
56 |
57 | @Override
58 | public Object getItem(int i) {
59 | return null;
60 | }
61 |
62 | @Override
63 | public long getItemId(int i) {
64 | return 0;
65 | }
66 |
67 | @Override
68 | public View getView(int i, View view, ViewGroup viewGroup) {
69 | view = mInflater.inflate(R.layout.custom_icons_list_item, null);
70 | ImageView icon = (ImageView) view.findViewById(R.id.imageView);
71 | icon.setImageResource(mIcons.getResourceId(i, -1));
72 | TextView names = (TextView) view.findViewById(R.id.textView);
73 | names.setTextColor(mColorText);
74 | names.setText(mNames[i]);
75 | return view;
76 | }
77 |
78 | public void clearAll() {
79 | mNames = new String[mNames.length];
80 | }
81 |
82 |
83 | public void addAll(String[] names) {
84 | mNames = names;
85 | }
86 | }
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/log/HARecognizerApiLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.log;
24 |
25 | import android.content.Context;
26 | import android.os.SystemClock;
27 |
28 | import com.google.android.gms.location.DetectedActivity;
29 |
30 | import java.util.ArrayList;
31 | import java.util.Date;
32 | import java.util.HashMap;
33 |
34 | import uk.ac.sussex.wear.android.datalogger.Constants;
35 |
36 | public class HARecognizerApiLogger extends CustomLogger {
37 |
38 | private static final String TAG = HARecognizerApiLogger.class.getSimpleName();
39 |
40 | public HARecognizerApiLogger(Context context, String path, String sessionName, long nanosOffset, int logFileMaxSize) {
41 | super(context, path, sessionName, Constants.SENSOR_NAME_API_HAR, "txt", false, nanosOffset, logFileMaxSize);
42 | }
43 |
44 | public void logDetectedActivities (ArrayList detectedActivities){
45 | HashMap detectedActivitiesMap = new HashMap<>();
46 | for (DetectedActivity activity : detectedActivities) {
47 | detectedActivitiesMap.put(activity.getType(), activity.getConfidence());
48 | }
49 |
50 | // Timestamp in system nanoseconds since boot, including time spent in sleep.
51 | long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
52 |
53 | // System local time in millis
54 | long currentMillis = (new Date()).getTime();
55 |
56 | String message = String.format("%s", currentMillis) + ";"
57 | + String.format("%s", nanoTime) + ";"
58 | + String.format("%s", mNanosOffset);
59 | for (int i = 0; i < Constants.API_ACTIVITY_RECOGNIZER_LIST.length; i++) {
60 | message += ";" + Integer.toString(
61 | detectedActivitiesMap.containsKey(Constants.API_ACTIVITY_RECOGNIZER_LIST[i]) ?
62 | detectedActivitiesMap.get(Constants.API_ACTIVITY_RECOGNIZER_LIST[i]) : 0);
63 | }
64 |
65 | log(message);
66 | log(System.lineSeparator());
67 | }
68 |
69 | public void updateNanosOffset(long nanosOffset) {
70 | mNanosOffset = nanosOffset;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bluetooth_device_list.xml:
--------------------------------------------------------------------------------
1 |
22 |
27 |
28 |
39 |
40 |
49 |
50 |
60 |
61 |
70 |
71 |
80 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/FlagEventActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 | import android.app.Activity;
26 | import android.content.Intent;
27 | import android.os.Bundle;
28 | import android.view.View;
29 | import android.widget.Button;
30 | import android.widget.EditText;
31 | import android.widget.RadioGroup;
32 |
33 | import uk.ac.sussex.wear.android.datalogger.data.CommandFLE;
34 |
35 | public class FlagEventActivity extends Activity implements View.OnClickListener {
36 |
37 | Button confirmButton;
38 | Button cancelButton;
39 | EditText notesEditText;
40 | RadioGroup flagsRadioGroup;
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_flag_event);
46 |
47 | flagsRadioGroup = (RadioGroup) findViewById(R.id.flags_radio_group);
48 |
49 | confirmButton = (Button) findViewById(R.id.confirm_button);
50 | confirmButton.setOnClickListener(this);
51 |
52 | cancelButton = (Button) findViewById(R.id.cancel_button);
53 | cancelButton.setOnClickListener(this);
54 |
55 | notesEditText = (EditText) findViewById(R.id.notes_text);
56 | }
57 |
58 | @Override
59 | public void onClick(View v) {
60 | int id = v.getId();
61 |
62 | switch (id) {
63 | case R.id.confirm_button:
64 | String notes = notesEditText.getText().toString();
65 | if ("".equals(notes))
66 | notes = " ";
67 | int radioButtonID = flagsRadioGroup.getCheckedRadioButtonId();
68 | View radioButton = flagsRadioGroup.findViewById(radioButtonID);
69 | int idx = flagsRadioGroup.indexOfChild(radioButton);
70 | startService(new Intent(FlagEventActivity.this, DataLoggerService.class)
71 | .putExtra(Constants.COMMAND_SERVICE_INTENT_KEY,
72 | new CommandFLE(this.getResources().getStringArray(R.array.flaggable_events)[idx], notes).getMessage()));
73 | this.finish();
74 | break;
75 | case R.id.cancel_button:
76 | this.finish();
77 | break;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/BluetoothConnectionHelper2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt;
24 |
25 | import android.bluetooth.BluetoothAdapter;
26 | import android.content.Context;
27 | import android.os.Handler;
28 |
29 | import uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bluetooth.client.BluetoothClient;
30 | import uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bluetooth.server.BluetoothServer;
31 |
32 | public class BluetoothConnectionHelper2 {
33 |
34 | public static final String TAG = BluetoothConnectionHelper2.class.getSimpleName();
35 |
36 | public static final String NAME = "BluetoothConnectionHelper2";
37 |
38 | private final BluetoothAdapter mBluetoothAdapter;
39 | private final Handler mHandler;
40 | private final Context mContext;
41 | private boolean mIsServer;
42 | private BluetoothClient mClient = null;
43 | private BluetoothServer[] mServers = null;
44 | private int[] mStates;
45 |
46 | // Constants that indicate the current connection state
47 | public static final int STATE_NONE = 0; // we're doing nothing
48 | public static final int STATE_LISTEN = 1; // now listening for incoming connections
49 | public static final int STATE_CONNECTING = 2; // now initiating an outgoing connection
50 | public static final int STATE_CONNECTED = 3; // now connected to a remote device
51 |
52 | // Unique UUIDs for this application. Randomly generated
53 | private static final String[] mUUIDs = {
54 | "70a7c5d0-9aa6-11e6-9f33-a24fc0d9649c",
55 | "70a7c832-9aa6-11e6-9f33-a24fc0d9649c",
56 | "70a7c972-9aa6-11e6-9f33-a24fc0d9649c"
57 | };
58 |
59 | public BluetoothConnectionHelper2(Context context, Handler handler, boolean isServer) {
60 | mContext = context;
61 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
62 | mHandler = handler;
63 | mIsServer = isServer;
64 | mStates = new int[]{STATE_NONE, STATE_NONE, STATE_NONE};
65 | }
66 |
67 | public void stop(int indexSocketLost) {
68 |
69 | }
70 |
71 | public void start(int deviceLocation) {
72 |
73 | }
74 |
75 | public void connect(String mMasterAddress, int deviceLocation) {
76 |
77 | }
78 |
79 | public boolean isConnected(int deviceLocation) {
80 | return false;
81 | }
82 |
83 | public void broadcastMessage(String broadcastMessage) {
84 |
85 | }
86 |
87 | public int getState(int location) {
88 | return 0;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/log/LoggerHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.log;
24 |
25 | import android.content.Context;
26 | import android.os.SystemClock;
27 |
28 | import java.io.File;
29 |
30 | /**
31 | * Created by fjordonez on 13/10/16.
32 | */
33 |
34 | public final class LoggerHelper {
35 |
36 | private static final String TAG = LoggerHelper.class.getSimpleName();
37 |
38 | public static File defineLogFilename(Context context, String path, String baseFilename, String extension, boolean toAppend, long nanosOffset){
39 |
40 | // Get the absolute path to the directory on the primary shared/external storage device
41 | // where the application can place persistent files.
42 | File absoluteDir = new File(context.getExternalFilesDir(null), path);
43 | if (!absoluteDir.exists()){
44 | absoluteDir.mkdirs();
45 | }
46 |
47 | String nanoTimeString = Long.toString(SystemClock.elapsedRealtimeNanos() + nanosOffset);
48 | File[] files = absoluteDir.listFiles();
49 | if (files.length == 0) { // In case there are no files in the dir
50 | // The first logging file is indexed as 0
51 | baseFilename = baseFilename + "__" + nanoTimeString + "__0" + "." + extension;
52 | } else {
53 | int lastIndex = -1;
54 | for (File file : files){
55 | if (file.isFile()){
56 | String[] items = file.getName().split("\\.")[0].split("__");
57 | // There must be two "__" tokens in the file name: sessionName__nanoTime__index
58 | // items[0]=sessionName, items[1]=nanoTime. items[2]=index
59 | int index = Integer.parseInt(items[2]);
60 | // The index of the last file is obtained
61 | if ((index > lastIndex) && (items[0].equals(baseFilename))){
62 | lastIndex = index;
63 | if (toAppend){
64 | nanoTimeString = items[1];
65 | }
66 | }
67 | }
68 | }
69 | if (toAppend){
70 | baseFilename = baseFilename + "__" + nanoTimeString + "__" + lastIndex + "." + extension;
71 | } else {
72 | baseFilename = baseFilename + "__" + nanoTimeString + "__" + (lastIndex+1) + "." + extension;
73 | }
74 | }
75 |
76 | return new File(absoluteDir.getAbsolutePath() + File.separator + baseFilename);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | import android.util.Log;
26 |
27 | import java.util.ArrayList;
28 |
29 | public abstract class CommandBase {
30 |
31 | private static final String TAG = CommandBase.class.getSimpleName();
32 |
33 | public static final int MAX_LENGTH = 70;
34 |
35 | protected static final String COMMAND_START = "##";
36 | protected static final String COMMAND_SEPARATOR = "!";
37 | protected static final String PARAMETER_SEPARATOR = ";";
38 | protected static final String FILLING_TOKEN = "*";
39 |
40 | public static final String COMMAND_DATA_COLLECTION_EVENT = "DCE";
41 | public static final String COMMAND_LABEL_ANNOTATION_EVENT = "LAE";
42 | public static final String COMMAND_BLUETOOTH_START = "BTS";
43 | public static final String COMMAND_BLUETOOTH_CONNECT = "BTC";
44 | public static final String COMMAND_FILES_UPLOAD_START = "FUS";
45 | public static final String COMMAND_FILES_UPLOAD_CANCEL = "FUC";
46 | public static final String COMMAND_KEEP_ALIVE_EVENT = "KAE";
47 | public static final String COMMAND_FLAG_EVENT = "FLE";
48 |
49 | public abstract String getMessage();
50 |
51 | protected static String extendCommand(String command){
52 | while (command.length() < MAX_LENGTH){
53 | command += FILLING_TOKEN;
54 | }
55 | return command;
56 | }
57 |
58 | public String getMessageBluetooth(){
59 | return extendCommand(getMessage());
60 | }
61 |
62 | public static ArrayList parseMessage(String message) {
63 | ArrayList ret = new ArrayList<>();
64 | Log.i(TAG, "::parseCommand Parsing message '" + message + "'. Size in bytes: " + message.length());
65 | for (String command : message.split(COMMAND_START)) {
66 | String code = command.split(COMMAND_SEPARATOR)[0];
67 | if (!code.equals("")){
68 | ret.add(code);
69 | if (command.split(COMMAND_SEPARATOR).length > 1) {
70 | String[] params = command.split(COMMAND_SEPARATOR)[1].split(PARAMETER_SEPARATOR);
71 | for (String param : params) {
72 | if (param.indexOf(FILLING_TOKEN) == -1) {
73 | ret.add(param);
74 | }
75 | }
76 | }
77 | }
78 | }
79 | return ret;
80 | }
81 |
82 | public static boolean containsCommand(ArrayList list, String command){
83 | for (String element : list){
84 | if (element.equals(command))
85 | return true;
86 | }
87 | return false;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_general.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
25 |
34 |
35 |
43 |
44 |
45 |
49 |
50 |
59 |
60 |
61 |
62 |
63 |
71 |
72 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/NameValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import android.os.Parcel;
26 | import android.os.Parcelable;
27 |
28 | import java.io.UnsupportedEncodingException;
29 | import java.nio.charset.Charset;
30 |
31 | /**
32 | * Represents a request parameter.
33 | *
34 | * @author gotev (Aleksandar Gotev)
35 | *
36 | */
37 | public final class NameValue implements Parcelable {
38 |
39 | private static final String NEW_LINE = "\r\n";
40 |
41 | private final String name;
42 | private final String value;
43 |
44 | private final Charset US_ASCII = Charset.forName("US-ASCII");
45 | private final Charset UTF8 = Charset.forName("UTF-8");
46 |
47 | public NameValue(final String name, final String value) {
48 | this.name = name;
49 | this.value = value;
50 | }
51 |
52 | public final String getName() {
53 | return name;
54 | }
55 |
56 | public final String getValue() {
57 | return value;
58 | }
59 |
60 | public byte[] getMultipartBytes(boolean isUtf8) throws UnsupportedEncodingException {
61 | return ("Content-Disposition: form-data; name=\"" + name + "\""
62 | + NEW_LINE + NEW_LINE + value).getBytes(isUtf8 ? UTF8 : US_ASCII);
63 | }
64 |
65 | @Override
66 | public boolean equals(Object object) {
67 | final boolean areEqual;
68 |
69 | if (object instanceof NameValue) {
70 | final NameValue other = (NameValue) object;
71 | areEqual = this.name.equals(other.name) && this.value.equals(other.value);
72 | } else {
73 | areEqual = false;
74 | }
75 |
76 | return areEqual;
77 | }
78 |
79 | // This is used to regenerate the object.
80 | // All Parcelables must have a CREATOR that implements these two methods
81 | public static final Parcelable.Creator CREATOR =
82 | new Parcelable.Creator() {
83 | @Override
84 | public NameValue createFromParcel(final Parcel in) {
85 | return new NameValue(in);
86 | }
87 |
88 | @Override
89 | public NameValue[] newArray(final int size) {
90 | return new NameValue[size];
91 | }
92 | };
93 |
94 | @Override
95 | public int describeContents() {
96 | return 0;
97 | }
98 |
99 | @Override
100 | public void writeToParcel(Parcel parcel, int arg1) {
101 | parcel.writeString(name);
102 | parcel.writeString(value);
103 | }
104 |
105 | private NameValue(Parcel in) {
106 | name = in.readString();
107 | value = in.readString();
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/HttpConnection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import java.io.IOException;
26 | import java.util.LinkedHashMap;
27 | import java.util.List;
28 |
29 | /**
30 | * Defines the methods that has to be implemented by an HTTP connection.
31 | * If you're implementing your custom HTTP connection, remember to never cache anything,
32 | * especially in writeBody methods, as this will surely cause memory issues when uploading
33 | * large files. The only things which you are allowed to cache are the response code and body
34 | * from the server, which must not be large though.
35 | * @author gotev (Aleksandar Gotev)
36 | */
37 | public interface HttpConnection {
38 |
39 | /**
40 | * Set request headers.
41 | * @param requestHeaders request headers to set
42 | * @param isFixedLengthStreamingMode true if the fixed length streaming mode must be used. If
43 | * it's false, chunked streaming mode has to be used
44 | * @param totalBodyBytes total number of bytes
45 | * @throws IOException if an error occurs while setting request headers
46 | */
47 | void setHeaders(List requestHeaders, boolean isFixedLengthStreamingMode,
48 | long totalBodyBytes) throws IOException;
49 |
50 | /**
51 | * Write a byte array into the request body.
52 | * @param bytes array with the bytes to write
53 | * @throws IOException if an error occurs while writing
54 | */
55 | void writeBody(byte[] bytes) throws IOException;
56 |
57 | /**
58 | * Write a portion of a byte array into the request body.
59 | * @param bytes array with the bytes to write
60 | * @param lengthToWriteFromStart how many bytes to write, starting from the first one in
61 | * the array
62 | * @throws IOException if an error occurs while writing
63 | */
64 | void writeBody(byte[] bytes, int lengthToWriteFromStart) throws IOException;
65 |
66 | /**
67 | * Gets the HTTP response code from the server.
68 | * @return an integer representing the HTTP response code (e.g. 200)
69 | * @throws IOException if an error occurs while getting the server response code
70 | */
71 | int getServerResponseCode() throws IOException;
72 |
73 | /**
74 | * Gets the server response body.
75 | * @return response body bytes
76 | * @throws IOException if an error occurs while getting the server response body
77 | */
78 | byte[] getServerResponseBody() throws IOException;
79 |
80 | /**
81 | * Gets the server response headers.
82 | * @return map containing all the response headers
83 | * @throws IOException if an error occurs while getting the server response headers
84 | */
85 | LinkedHashMap getServerResponseHeaders() throws IOException;
86 |
87 | /**
88 | * Closes the connection and frees all the allocated resources.
89 | */
90 | void close();
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_data_sync.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
45 |
46 |
47 |
48 |
49 |
50 |
58 |
59 |
63 |
64 |
74 |
75 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/DataCollectionSession.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | import java.text.SimpleDateFormat;
26 | import java.util.Date;
27 |
28 | /**
29 | * Created by fjordonez on 01/10/16.
30 | */
31 | public class DataCollectionSession {
32 | private Date mStartDate;
33 | private Date mEndDate;
34 | private String mDateFormat;
35 | private String mUserName;
36 | private String mDeviceLocation;
37 | private long mMillisSignature;
38 | private String mMasterSessionId;
39 | private long mNanosOffset;
40 | private long mLength;
41 | private static String dateFormatISO8601 = "yyyy-MM-dd HH:mm:ss.SSS";
42 |
43 | public DataCollectionSession(Date startDate, String dateFormat, String userName, String deviceLocation, long millisSignature, String masterSessionId, long nanosOffset){
44 | mStartDate = startDate;
45 | mEndDate = null;
46 | mDateFormat = dateFormat;
47 | mUserName = userName;
48 | mDeviceLocation = deviceLocation;
49 | mMillisSignature = millisSignature;
50 | mMasterSessionId = masterSessionId;
51 | mNanosOffset = nanosOffset;
52 | mLength = 0;
53 | }
54 |
55 | public String getUserName(){
56 | return mUserName;
57 | }
58 |
59 | public String getDeviceLocation(){
60 | return mDeviceLocation;
61 | }
62 |
63 | public Date getStartDate(){
64 | return mStartDate;
65 | }
66 |
67 | public Date getEndDate(){
68 | return mEndDate;
69 | }
70 |
71 | public long getMillisSignature(){
72 | return mMillisSignature;
73 | }
74 |
75 | public long getLength(){
76 | return mLength;
77 | }
78 |
79 | public long getNanosOffset() {
80 | return mNanosOffset;
81 | }
82 |
83 | public void setEndDate(Date endDate){
84 | mEndDate = endDate;
85 | setLength((mEndDate.getTime()-mStartDate.getTime())/1000);
86 | }
87 |
88 | public void setLength(long length){
89 | mLength = length;
90 | }
91 |
92 | public String getSessionId(){
93 | return new SimpleDateFormat(mDateFormat).format(getStartDate())
94 | + String.valueOf(getMillisSignature() % 100000);
95 | }
96 |
97 | public String getSessionName(){
98 | String ret = getUserName() + "_"
99 | + getDeviceLocation() + "_"
100 | + getSessionId();
101 | ret += ("".equals(mMasterSessionId)) ? "" : "_" + mMasterSessionId;
102 | return ret;
103 | }
104 |
105 | public String getStartDateISO8601(){
106 | return new SimpleDateFormat(dateFormatISO8601).format(getStartDate());
107 | }
108 |
109 | public String getEndDateISO8601(){
110 | if (getEndDate() != null){
111 | return new SimpleDateFormat(dateFormatISO8601).format(getEndDate());
112 | }else{
113 | return "";
114 | }
115 | }
116 |
117 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DataLogger
2 | [](https://opensource.org/licenses/MIT)
3 |
4 | DataLogger is an high reliability Android application for multidevice multimodal mobile data acquisition and annotation.
5 |
6 | ## Functionalities
7 | Application features:
8 | - Logging of sensor data:
9 | - Inertial sensors data such as accelerometer, gyroscope, magnetometer, as well as software sensors data for linear acceleration, orientation (quaternions), gravity;
10 | - Environmental sensors data as temperature, light, pressure and humidity;
11 | - Positioning sensors data such as location and satellites;
12 | - Networks connectivity data, as network cells and WiFi networks;
13 | - Battery level
14 | - Microphone audio
15 | - Google activity recognition labels
16 | - Every sensors can be configured in the settings to enable/disable it, set the sampling frequency, the remote upload of its data.
17 | - Remote upload of data (`PHP_upload_script.txt` contains the PHP code for the server)
18 | - Multidevice (master-slaves) configuration
19 | - Bluetooth connection for synchronization among device of time and status (logging/no logging, labels, sublabels)
20 | - Autostart at boot/reboot
21 | - Background logging using persistent notification
22 | - Logging of data on files (a new file is created at regular interval to reduce data loss)
23 |
24 | ## Requirement
25 | - Android, minimum SDK 19.
26 | - Google play service (for Google activity recognition)
27 |
28 | ## Configuration required
29 | ### Settings' password
30 | In order to prevent changes to the setting by the users, the setting menu is protected by a password. It is recommended to change the password in the code before to deploy the application. Set the value of `ADMIN_CODE` in `Constants.java` to change the password before to install the application.
31 |
32 | ### Master & Slave configuration
33 | It can be configured for collecting data on multiple devices synchronously, in a master-slave configuration. The configuration is set changing the position of the device in the settings. The Hand device is the master, while Hips, Torso and Bag device are the slaves.
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | ### Remote upload
48 | The remote upload functionality requires to set up the remote address for the upload. The address is in `string.xml` in the value folder.
49 |
50 | ### Permissions
51 | Due to the changes to the permissions systems in the latest versions of Android, please check and authorize the access to Microphone,
52 | Storage, Telephone and Location in the system settings before to use the application.
53 |
54 | ## LICENSE
55 | This application has been developed for research purpose and release under MIT License. The usage of this application in research and publications must be acknowledged by citing the following publication:
56 |
57 | [1] Mathias Ciliberto, Francisco Javier Ordoñez Morales, Hristijan Gjoreski, Daniel Roggen, Sami Mekki, Stefan Valentin. *"High reliability Android application for multidevice multimodal mobile data acquisition and annotation"* in ACM Conference on Embedded Networked Sensor Systems (Sensys), 2017.
58 |
59 | ```
60 | The MIT License
61 |
62 | Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
63 | Hristijan Gjoreski, Daniel Roggen
64 |
65 | Permission is hereby granted, free of charge, to any person obtaining a copy of
66 | this software and associated documentation files (the "Software"), to deal in
67 | the Software without restriction, including without limitation the rights to use,
68 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
69 | Software, and to permit persons to whom the Software is furnished to do so,
70 | subject to the following conditions:
71 |
72 | The above copyright notice and this permission notice shall be included in all
73 | copies or substantial portions of the Software.
74 |
75 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
77 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
78 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
79 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
80 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 | ```
82 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/log/LabelsLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.log;
24 |
25 | import android.content.Context;
26 | import android.os.SystemClock;
27 |
28 | import java.util.Date;
29 |
30 | import uk.ac.sussex.wear.android.datalogger.Constants;
31 | import uk.ac.sussex.wear.android.datalogger.R;
32 |
33 | /**
34 | * Created by fjordonez on 01/10/16.
35 | */
36 | public class LabelsLogger extends CustomLogger {
37 |
38 | private static final String TAG = LabelsLogger.class.getSimpleName();
39 |
40 | private int mCurrentActivity;
41 |
42 | private int mCurrentBodyPosition;
43 |
44 | private int mCurrentLocation;
45 |
46 | private long mCurrentLabelStartMillis;
47 |
48 | public LabelsLogger(Context context, String path, String sessionName, long nanoOffset) {
49 | super(context, path, sessionName, Constants.SENSOR_NAME_LABELS, "txt", true, nanoOffset);
50 | }
51 |
52 | public void setup(int activity, int bodyPosition, int location){
53 | setCurrentActivity(activity);
54 | setCurrentBodyPosition(bodyPosition);
55 | setCurrentLocation(location);
56 | mCurrentLabelStartMillis = 0;
57 | }
58 |
59 | public void setCurrentActivity(int activity){
60 | mCurrentActivity = activity;
61 | }
62 |
63 | public int getCurrentActivity(){
64 | return mCurrentActivity;
65 | }
66 |
67 | public void setCurrentBodyPosition(int bodyPosition){
68 | mCurrentBodyPosition = bodyPosition;
69 | }
70 |
71 | public int getCurrentBodyPosition(){
72 | return mCurrentBodyPosition;
73 | }
74 |
75 | public void setCurrentLocation(int location){
76 | mCurrentLocation = location;
77 | }
78 |
79 | public int getCurrentLocation(){
80 | return mCurrentLocation;
81 | }
82 |
83 | private String getBaseLabelMessage(int activity, int bodyPosition, int location) {
84 |
85 | // System local time in millis
86 | long currentMillis = (new Date()).getTime();
87 |
88 | // Timestamp in system nanoseconds since boot, including time spent in sleep.
89 | long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
90 |
91 | String message = String.format("%s", currentMillis) + ";"
92 | + String.format("%s", nanoTime) + ";"
93 | + String.format("%s", mNanosOffset) + ";"
94 | + Integer.toString(activity) + ";";
95 | message += ((activity >= mContext.getResources().getInteger(R.integer.num_labels_wo_pos)) || activity == 0) ? Integer.toString(bodyPosition) + ";" : "-1;";
96 | message += (location == R.id.ui_iolocation_radioButton_outside) ? "0;" : "1;";
97 | return message;
98 | }
99 |
100 | public void logState(String state){
101 | String message = getBaseLabelMessage(mCurrentActivity, mCurrentBodyPosition, mCurrentLocation) + state;
102 | log(message);
103 | log(System.lineSeparator());
104 | }
105 |
106 | public void logStart(){
107 | logState("1");
108 | mCurrentLabelStartMillis = System.currentTimeMillis();
109 | }
110 |
111 | public void logEnd(){
112 | logState("0");
113 | }
114 |
115 | }
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/collector/AudioDataCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.collector;
24 |
25 | import android.content.Context;
26 | import android.media.MediaRecorder;
27 | import android.util.Log;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 |
32 | import uk.ac.sussex.wear.android.datalogger.db.DataLoggerDataSource;
33 | import uk.ac.sussex.wear.android.datalogger.log.LoggerHelper;
34 |
35 |
36 | public class AudioDataCollector extends AbstractDataCollector {
37 |
38 | private static final String TAG = AudioDataCollector.class.getSimpleName();
39 |
40 | private int mSamplingRate;
41 |
42 | private Context mContext;
43 |
44 | private MediaRecorder mRecorder = null;
45 |
46 | private String mPath;
47 |
48 | private String mBaseLogFilename;
49 |
50 | private String mSessionName;
51 |
52 | private File logFile;
53 |
54 | public AudioDataCollector(Context context, String sessionName, String sensorName, int samplingRate, long nanosOffset) {
55 |
56 | mSensorName = sensorName;
57 | mSessionName = sessionName;
58 | mPath = sessionName+ File.separator + mSensorName + "_" + sessionName;
59 | mBaseLogFilename = sessionName + "_" + mSensorName;
60 |
61 | mSamplingRate = samplingRate;
62 |
63 | mContext = context;
64 |
65 | // Offset to match timestamps both in master and slaves devices
66 | mNanosOffset = nanosOffset;
67 |
68 | }
69 |
70 | public void prepare(int samplingRate) {
71 | Log.i(TAG,"prepare:: Preparing listener for sensor "+getSensorName());
72 | mRecorder = new MediaRecorder();
73 | mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
74 | mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
75 | mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
76 | if (samplingRate != 0){
77 | mRecorder.setAudioSamplingRate(samplingRate);
78 | }
79 | logFile = LoggerHelper.defineLogFilename(mContext, mPath, mBaseLogFilename, "3gp", false, mNanosOffset);
80 | mRecorder.setOutputFile(logFile.getAbsolutePath());
81 | try {
82 | mRecorder.prepare();
83 | } catch (IOException e) {
84 | Log.e(TAG, "::prepare Error creating collector: " + e.getMessage());
85 | }
86 | }
87 |
88 | @Override
89 | public void start() {
90 | prepare(mSamplingRate);
91 | Log.i(TAG, "start:: Starting listener for sensor: "+getSensorName());
92 | mRecorder.start();
93 | }
94 |
95 | @Override
96 | public void stop() {
97 | Log.i(TAG,"stop:: Stopping listener for sensor "+getSensorName());
98 | if (mRecorder != null) {
99 | try {
100 | mRecorder.stop();
101 | } catch(RuntimeException ex) {
102 | Log.d(TAG,"No valid audio data has been received when stop() is called");
103 | }
104 | mRecorder.reset();
105 | mRecorder.release();
106 | mRecorder = null;
107 | DataLoggerDataSource.insertLogFile(mContext, logFile.getAbsolutePath(), getSensorName(), mSessionName);
108 | }
109 | }
110 |
111 | @Override
112 | public void haltAndRestartLogging() {
113 | stop();
114 | start();
115 | }
116 |
117 | @Override
118 | public void updateNanosOffset(long nanosOffset) {
119 | mNanosOffset = nanosOffset;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/AppCompatPreferenceActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger;
24 |
25 | import android.content.res.Configuration;
26 | import android.os.Bundle;
27 | import android.preference.PreferenceActivity;
28 | import android.support.annotation.LayoutRes;
29 | import android.support.annotation.Nullable;
30 | import android.support.v7.app.ActionBar;
31 | import android.support.v7.app.AppCompatDelegate;
32 | import android.support.v7.widget.Toolbar;
33 | import android.view.MenuInflater;
34 | import android.view.View;
35 | import android.view.ViewGroup;
36 |
37 | /**
38 | * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
39 | * to be used with AppCompat.
40 | */
41 | public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
42 |
43 | private AppCompatDelegate mDelegate;
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | getDelegate().installViewFactory();
48 | getDelegate().onCreate(savedInstanceState);
49 | super.onCreate(savedInstanceState);
50 | }
51 |
52 | @Override
53 | protected void onPostCreate(Bundle savedInstanceState) {
54 | super.onPostCreate(savedInstanceState);
55 | getDelegate().onPostCreate(savedInstanceState);
56 | }
57 |
58 | public ActionBar getSupportActionBar() {
59 | return getDelegate().getSupportActionBar();
60 | }
61 |
62 | public void setSupportActionBar(@Nullable Toolbar toolbar) {
63 | getDelegate().setSupportActionBar(toolbar);
64 | }
65 |
66 | @Override
67 | public MenuInflater getMenuInflater() {
68 | return getDelegate().getMenuInflater();
69 | }
70 |
71 | @Override
72 | public void setContentView(@LayoutRes int layoutResID) {
73 | getDelegate().setContentView(layoutResID);
74 | }
75 |
76 | @Override
77 | public void setContentView(View view) {
78 | getDelegate().setContentView(view);
79 | }
80 |
81 | @Override
82 | public void setContentView(View view, ViewGroup.LayoutParams params) {
83 | getDelegate().setContentView(view, params);
84 | }
85 |
86 | @Override
87 | public void addContentView(View view, ViewGroup.LayoutParams params) {
88 | getDelegate().addContentView(view, params);
89 | }
90 |
91 | @Override
92 | protected void onPostResume() {
93 | super.onPostResume();
94 | getDelegate().onPostResume();
95 | }
96 |
97 | @Override
98 | protected void onTitleChanged(CharSequence title, int color) {
99 | super.onTitleChanged(title, color);
100 | getDelegate().setTitle(title);
101 | }
102 |
103 | @Override
104 | public void onConfigurationChanged(Configuration newConfig) {
105 | super.onConfigurationChanged(newConfig);
106 | getDelegate().onConfigurationChanged(newConfig);
107 | }
108 |
109 | @Override
110 | protected void onStop() {
111 | super.onStop();
112 | getDelegate().onStop();
113 | }
114 |
115 | @Override
116 | protected void onDestroy() {
117 | super.onDestroy();
118 | getDelegate().onDestroy();
119 | }
120 |
121 | public void invalidateOptionsMenu() {
122 | getDelegate().invalidateOptionsMenu();
123 | }
124 |
125 | private AppCompatDelegate getDelegate() {
126 | if (mDelegate == null) {
127 | mDelegate = AppCompatDelegate.create(this, null);
128 | }
129 | return mDelegate;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/BroadcastData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import android.content.Intent;
26 | import android.os.Parcel;
27 | import android.os.Parcelable;
28 | import android.util.Log;
29 |
30 | /**
31 | * Class which contains all the data passed in broadcast intents to notify task progress, errors,
32 | * completion or cancellation.
33 | *
34 | * @author gotev (Aleksandar Gotev)
35 | */
36 | class BroadcastData implements Parcelable {
37 |
38 | private static final String TAG = BroadcastData.class.getSimpleName();
39 |
40 | public enum Status {
41 | IN_PROGRESS,
42 | ERROR,
43 | COMPLETED,
44 | CANCELLED
45 | }
46 |
47 | private Status status;
48 | private Exception exception;
49 | private UploadInfo uploadInfo;
50 | private ServerResponse serverResponse;
51 |
52 | public BroadcastData() {
53 |
54 | }
55 |
56 | public Intent getIntent() {
57 | Intent intent = new Intent(UploadService.getActionBroadcast());
58 | intent.putExtra(UploadService.PARAM_BROADCAST_DATA, this);
59 | return intent;
60 | }
61 |
62 | // This is used to regenerate the object.
63 | // All Parcelables must have a CREATOR that implements these two methods
64 | public static final Parcelable.Creator CREATOR =
65 | new Parcelable.Creator() {
66 | @Override
67 | public BroadcastData createFromParcel(final Parcel in) {
68 | return new BroadcastData(in);
69 | }
70 |
71 | @Override
72 | public BroadcastData[] newArray(final int size) {
73 | return new BroadcastData[size];
74 | }
75 | };
76 |
77 | @Override
78 | public void writeToParcel(Parcel parcel, int flags) {
79 | parcel.writeInt(status.ordinal());
80 | parcel.writeSerializable(exception);
81 | parcel.writeParcelable(uploadInfo, flags);
82 | parcel.writeParcelable(serverResponse, flags);
83 | }
84 |
85 | private BroadcastData(Parcel in) {
86 | status = Status.values()[in.readInt()];
87 | exception = (Exception) in.readSerializable();
88 | uploadInfo = in.readParcelable(UploadInfo.class.getClassLoader());
89 | serverResponse = in.readParcelable(ServerResponse.class.getClassLoader());
90 | }
91 |
92 | @Override
93 | public int describeContents() {
94 | return 0;
95 | }
96 |
97 | public Status getStatus() {
98 | if (status == null) {
99 | Log.e(TAG, "Status not defined! Returning " + Status.CANCELLED);
100 | return Status.CANCELLED;
101 | }
102 |
103 | return status;
104 | }
105 |
106 | public BroadcastData setStatus(Status status) {
107 | this.status = status;
108 | return this;
109 | }
110 |
111 | public Exception getException() {
112 | return exception;
113 | }
114 |
115 | public BroadcastData setException(Exception exception) {
116 | this.exception = exception;
117 | return this;
118 | }
119 |
120 | public UploadInfo getUploadInfo() {
121 | return uploadInfo;
122 | }
123 |
124 | public BroadcastData setUploadInfo(UploadInfo uploadInfo) {
125 | this.uploadInfo = uploadInfo;
126 | return this;
127 | }
128 |
129 | public ServerResponse getServerResponse() {
130 | return serverResponse;
131 | }
132 |
133 | public BroadcastData setServerResponse(ServerResponse serverResponse) {
134 | this.serverResponse = serverResponse;
135 | return this;
136 | }
137 | }
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/ServerResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import android.os.Parcel;
26 | import android.os.Parcelable;
27 |
28 | import java.util.LinkedHashMap;
29 |
30 | /**
31 | * Contains the server response.
32 | * @author Aleksandar Gotev
33 | */
34 | public class ServerResponse implements Parcelable {
35 |
36 | private int httpCode;
37 | private byte[] body;
38 | private LinkedHashMap headers;
39 |
40 | // This is used to regenerate the object.
41 | // All Parcelables must have a CREATOR that implements these two methods
42 | public static final Parcelable.Creator CREATOR =
43 | new Parcelable.Creator() {
44 | @Override
45 | public ServerResponse createFromParcel(final Parcel in) {
46 | return new ServerResponse(in);
47 | }
48 |
49 | @Override
50 | public ServerResponse[] newArray(final int size) {
51 | return new ServerResponse[size];
52 | }
53 | };
54 |
55 | /**
56 | * Creates a new server response object.
57 | * @param httpCode HTTP response code
58 | * @param body HTTP response body
59 | * @param headers HTTP response headers
60 | */
61 | protected ServerResponse(int httpCode, byte[] body, LinkedHashMap headers) {
62 | this.httpCode = httpCode;
63 |
64 | if (body != null && body.length > 0)
65 | this.body = body;
66 | else
67 | this.body = new byte[1];
68 |
69 | if (headers != null && !headers.isEmpty())
70 | this.headers = headers;
71 | else
72 | this.headers = new LinkedHashMap<>(1);
73 | }
74 |
75 | @SuppressWarnings("unchecked")
76 | protected ServerResponse(Parcel in) {
77 | httpCode = in.readInt();
78 | body = new byte[in.readInt()];
79 | in.readByteArray(body);
80 | headers = (LinkedHashMap) in.readSerializable();
81 | }
82 |
83 | @Override
84 | public void writeToParcel(Parcel parcel, int flags) {
85 | parcel.writeInt(httpCode);
86 | parcel.writeInt(body.length);
87 | parcel.writeByteArray(body);
88 | parcel.writeSerializable(headers);
89 | }
90 |
91 | @Override
92 | public int describeContents() {
93 | return 0;
94 | }
95 |
96 | /**
97 | * Gets server HTTP response code.
98 | * @return integer value
99 | */
100 | public int getHttpCode() {
101 | return httpCode;
102 | }
103 |
104 | /**
105 | * Gets server response body.
106 | * If your server responds with a string, you can get it with
107 | * {@link ServerResponse#getBodyAsString()}.
108 | * If the string is a JSON, you can parse it using a library such as org.json
109 | * (embedded in Android) or google's gson
110 | * @return response bytes
111 | */
112 | public byte[] getBody() {
113 | return body;
114 | }
115 |
116 | /**
117 | * Gets server response body as string.
118 | * If the string is a JSON, you can parse it using a library such as org.json
119 | * (embedded in Android) or google's gson
120 | * @return string
121 | */
122 | public String getBodyAsString() {
123 | return new String(body);
124 | }
125 |
126 | /**
127 | * Gets all the server response headers.
128 | * @return map containing all the headers (key = header name, value = header value)
129 | */
130 | public LinkedHashMap getHeaders() {
131 | return headers;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/log/CustomLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.log;
24 |
25 | import android.content.Context;
26 | import android.util.Log;
27 |
28 | import java.io.BufferedOutputStream;
29 | import java.io.File;
30 | import java.io.FileNotFoundException;
31 | import java.io.FileOutputStream;
32 | import java.io.IOException;
33 |
34 | import uk.ac.sussex.wear.android.datalogger.db.DataLoggerDataSource;
35 |
36 | public class CustomLogger {
37 |
38 | private static final String TAG = CustomLogger.class.getSimpleName();
39 |
40 | private BufferedOutputStream mOutputStream = null;
41 | private int mMaxSizeKByte;
42 | private int mByteCounter;
43 |
44 | protected Context mContext;
45 | protected long mNanosOffset = 0;
46 | private String mPath;
47 | private String mSessionName;
48 | private String mSensorName;
49 | private String mExtension;
50 | private boolean mAppend;
51 | private File logFile;
52 |
53 | public CustomLogger(Context context, String path, String sessionName, String sensorName, String extension, boolean toAppend, long nanoOffset) {
54 | this(context, path, sessionName, sensorName, extension, toAppend, nanoOffset, 0);
55 | }
56 |
57 | public CustomLogger(Context context, String path, String sessionName, String sensorName, String extension, boolean toAppend, long nanoOffset, int maxSizeKByte) {
58 | mContext = context;
59 | mPath = path;
60 | mSessionName = sessionName;
61 | mSensorName = sensorName;
62 | mExtension = extension;
63 | mAppend = toAppend;
64 | mMaxSizeKByte = maxSizeKByte;
65 | mNanosOffset = nanoOffset;
66 | }
67 |
68 | private String getBaseFilename(){
69 | return mSessionName + "_" + mSensorName;
70 | }
71 |
72 | public void start() {
73 | Log.i(TAG,"start:: Starting "+getBaseFilename());
74 | try {
75 | logFile = LoggerHelper.defineLogFilename(mContext, mPath, getBaseFilename(), mExtension, mAppend, mNanosOffset);
76 | Log.i(TAG, "Creating file: "+logFile.getAbsolutePath());
77 | mOutputStream = new BufferedOutputStream(new FileOutputStream(logFile, mAppend));
78 | }catch (FileNotFoundException e) {
79 | Log.e(TAG, "::start Error starting log file "+getBaseFilename());
80 | }
81 | }
82 |
83 | public void resetByteCounter(){
84 | mByteCounter = 0;
85 | }
86 |
87 | public void log(String s) {
88 | try {
89 | mOutputStream.write(s.getBytes());
90 | }catch(IOException e){
91 | Log.e(TAG, "::log Error writing in log file "+getBaseFilename());
92 | }
93 | if (mMaxSizeKByte>0){
94 | mByteCounter += s.getBytes().length;
95 | if (mByteCounter >= mMaxSizeKByte * 1024){
96 | stop();
97 | resetByteCounter();
98 | start();
99 | }
100 | }
101 | }
102 |
103 | public void stop() {
104 | Log.i(TAG,"stop:: Closing "+getBaseFilename());
105 | if (mOutputStream!=null) {
106 | try {
107 | if (!DataLoggerDataSource.existLogFile(mContext, logFile.getAbsolutePath())){
108 | Log.i(TAG, "Adding file to database: "+logFile.getAbsolutePath());
109 | DataLoggerDataSource.insertLogFile(mContext, logFile.getAbsolutePath(), mSensorName, mSessionName);
110 | }
111 | mOutputStream.flush();
112 | mOutputStream.close();
113 | logFile = null;
114 | } catch (IOException e) {
115 | Log.e(TAG, "::stop Error closing log file " + getBaseFilename());
116 | }
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
60 |
63 |
64 |
65 |
70 |
71 |
77 |
78 |
84 |
85 |
90 |
91 |
92 |
94 |
95 |
97 |
98 |
100 |
101 |
103 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/collector/BatteryDataCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.collector;
24 |
25 | import android.content.BroadcastReceiver;
26 | import android.content.Context;
27 | import android.content.Intent;
28 | import android.content.IntentFilter;
29 | import android.os.BatteryManager;
30 | import android.os.SystemClock;
31 | import android.util.Log;
32 |
33 | import java.io.File;
34 | import java.util.Date;
35 |
36 | import uk.ac.sussex.wear.android.datalogger.log.CustomLogger;
37 |
38 | public class BatteryDataCollector extends AbstractDataCollector {
39 |
40 | private static final String TAG = BatteryDataCollector.class.getSimpleName();
41 |
42 | private CustomLogger logger = null;
43 |
44 | private Context mContext;
45 |
46 | private BroadcastReceiver mBatteryInfoReceiver;
47 |
48 | public BatteryDataCollector(Context context, String sessionName, String sensorName, long nanosOffset, int logFileMaxSize){
49 |
50 | mSensorName = sensorName;
51 | String path = sessionName + File.separator + mSensorName + "_" + sessionName;
52 |
53 | logger = new CustomLogger(context, path, sessionName, mSensorName, "txt", false, mNanosOffset, logFileMaxSize);
54 |
55 | mContext = context;
56 |
57 | // Offset to match timestamps both in master and slaves devices
58 | mNanosOffset = nanosOffset;
59 |
60 | mBatteryInfoReceiver = new BroadcastReceiver(){
61 | @Override
62 | public void onReceive(Context context, Intent intent) {
63 | int currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
64 | int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
65 | float temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0) / 10);
66 | int level = -1;
67 | if (currentLevel >= 0 && scale > 0) {
68 | level = (currentLevel * 100) / scale;
69 | }
70 |
71 | // System nanoseconds since boot, including time spent in sleep.
72 | long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
73 |
74 | // System local time in millis
75 | long currentMillis = (new Date()).getTime();
76 |
77 | String message = String.format("%s", currentMillis) + ";"
78 | + String.format("%s", nanoTime) + ";"
79 | + String.format("%s", mNanosOffset) + ";";
80 |
81 | // Field containing the current battery level, from 0 to scale.
82 | message += Integer.toString(level) + ";";
83 |
84 | // Integer containing the current battery temperature
85 | message += Float.toString(temperature);
86 |
87 | logger.log(message);
88 | logger.log(System.lineSeparator());
89 | }
90 | };
91 |
92 | }
93 |
94 | @Override
95 | public void start() {
96 | mContext.registerReceiver(mBatteryInfoReceiver,
97 | new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
98 | Log.i(TAG, "start:: Starting listener for sensor: " + getSensorName());
99 | logger.start();
100 | }
101 |
102 | @Override
103 | public void stop() {
104 | Log.i(TAG,"stop:: Stopping listener for sensor " + getSensorName());
105 | mContext.unregisterReceiver(mBatteryInfoReceiver);
106 | logger.stop();
107 | }
108 |
109 | @Override
110 | public void haltAndRestartLogging() {
111 | logger.stop();
112 | logger.resetByteCounter();
113 | logger.start();
114 | }
115 |
116 | @Override
117 | public void updateNanosOffset(long nanosOffset) {
118 | mNanosOffset = nanosOffset;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/bt/multibluetooth/bluetooth/server/BluetoothServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.bt.multibluetooth.bluetooth.server;
24 |
25 | import android.bluetooth.BluetoothAdapter;
26 | import android.bluetooth.BluetoothServerSocket;
27 | import android.bluetooth.BluetoothSocket;
28 | import android.util.Log;
29 |
30 | import java.io.IOException;
31 | import java.io.InputStream;
32 | import java.io.OutputStreamWriter;
33 | import java.util.UUID;
34 |
35 |
36 | /**
37 | * Created by Rami MARTIN on 13/04/2014.
38 | */
39 | public class BluetoothServer implements Runnable {
40 |
41 | private boolean CONTINUE_READ_WRITE = true;
42 |
43 | private UUID mUUID;
44 | public String mClientAddress;
45 | private BluetoothAdapter mBluetoothAdapter;
46 | private BluetoothServerSocket mServerSocket;
47 | private BluetoothSocket mSocket;
48 | private InputStream mInputStream;
49 | private OutputStreamWriter mOutputStreamWriter;
50 |
51 | public BluetoothServer(BluetoothAdapter bluetoothAdapter, String clientAddress){
52 | mBluetoothAdapter = bluetoothAdapter;
53 | mClientAddress = clientAddress;
54 | mUUID = UUID.fromString("e0917680-d427-11e4-8830-" + mClientAddress.replace(":", ""));
55 | }
56 |
57 | @Override
58 | public void run() {
59 | try {
60 | mServerSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("BLTServer", mUUID);
61 | mSocket = mServerSocket.accept();
62 | mInputStream = mSocket.getInputStream();
63 | mOutputStreamWriter = new OutputStreamWriter(mSocket.getOutputStream());
64 |
65 | int bufferSize = 1024;
66 | int bytesRead = -1;
67 | byte[] buffer = new byte[bufferSize];
68 |
69 | //EventBus.getDefault().post(new ServeurConnectionSuccess(mClientAddress));
70 |
71 | while(CONTINUE_READ_WRITE) {
72 | final StringBuilder sb = new StringBuilder();
73 | bytesRead = mInputStream.read(buffer);
74 | if (bytesRead != -1) {
75 | String result = "";
76 | while ((bytesRead == bufferSize) && (buffer[bufferSize] != 0)) {
77 | result = result + new String(buffer, 0, bytesRead);
78 | bytesRead = mInputStream.read(buffer);
79 | }
80 | result = result + new String(buffer, 0, bytesRead);
81 | sb.append(result);
82 | }
83 | //EventBus.getDefault().post(new BluetoothCommunicator(sb.toString()));
84 |
85 | }
86 | } catch (IOException e) {
87 | Log.e("", "ERROR : " + e.getMessage());
88 | //EventBus.getDefault().post(new ServeurConnectionFail(mClientAddress));
89 | }
90 | }
91 |
92 | public void write(String message) {
93 | try {
94 | if(mOutputStreamWriter != null) {
95 | mOutputStreamWriter.write(message);
96 | mOutputStreamWriter.flush();
97 | }
98 | } catch (IOException e) {
99 | e.printStackTrace();
100 | }
101 | }
102 |
103 | public String getClientAddress(){
104 | return mClientAddress;
105 | }
106 |
107 | public void closeConnection(){
108 | if(mSocket != null){
109 | try{
110 | mInputStream.close();
111 | mInputStream = null;
112 | mOutputStreamWriter.close();
113 | mOutputStreamWriter = null;
114 | mSocket.close();
115 | mSocket = null;
116 | mServerSocket.close();
117 | mServerSocket = null;
118 | CONTINUE_READ_WRITE = false;
119 | }catch(Exception e){}
120 | CONTINUE_READ_WRITE = false;
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/UploadServiceBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import android.content.BroadcastReceiver;
26 | import android.content.Context;
27 | import android.content.Intent;
28 | import android.content.IntentFilter;
29 | import android.util.Log;
30 |
31 | /**
32 | * Broadcast receiver to subclass to create a receiver for {@link UploadService} events.
33 | *
34 | * It provides the boilerplate code to properly handle broadcast messages coming from the
35 | * upload service and dispatch them to the proper handler method.
36 | *
37 | * @author gotev (Aleksandar Gotev)
38 | * @author eliasnaur
39 | * @author cankov
40 | * @author mabdurrahman
41 | *
42 | */
43 | public class UploadServiceBroadcastReceiver extends BroadcastReceiver
44 | implements UploadStatusDelegate {
45 |
46 | private static final String TAG = UploadService.class.getSimpleName();
47 |
48 | @Override
49 | public void onReceive(Context context, Intent intent) {
50 | if (intent == null || !UploadService.getActionBroadcast().equals(intent.getAction()))
51 | return;
52 |
53 | BroadcastData data = intent.getParcelableExtra(UploadService.PARAM_BROADCAST_DATA);
54 |
55 | if (data == null) {
56 | Log.e(TAG, "Missing intent parameter: " + UploadService.PARAM_BROADCAST_DATA);
57 | return;
58 | }
59 |
60 | switch (data.getStatus()) {
61 | case ERROR:
62 | onError(data.getUploadInfo(), data.getException());
63 | break;
64 |
65 | case COMPLETED:
66 | onCompleted(data.getUploadInfo(), data.getServerResponse());
67 | break;
68 |
69 | case IN_PROGRESS:
70 | onProgress(data.getUploadInfo());
71 | break;
72 |
73 | case CANCELLED:
74 | onCancelled(data.getUploadInfo());
75 | break;
76 |
77 | default:
78 | break;
79 | }
80 | }
81 |
82 | /**
83 | * Register this upload receiver.
84 | * If you use this receiver in an {@link android.app.Activity}, you have to call this method inside
85 | * {@link android.app.Activity#onResume()}, after {@code super.onResume();}.
86 | * If you use it in a {@link android.app.Service}, you have to
87 | * call this method inside {@link android.app.Service#onCreate()}, after {@code super.onCreate();}.
88 | *
89 | * @param context context in which to register this receiver
90 | */
91 | public void register(final Context context) {
92 | final IntentFilter intentFilter = new IntentFilter();
93 | intentFilter.addAction(UploadService.getActionBroadcast());
94 | context.registerReceiver(this, intentFilter);
95 | }
96 |
97 | /**
98 | * Unregister this upload receiver.
99 | * If you use this receiver in an {@link android.app.Activity}, you have to call this method inside
100 | * {@link android.app.Activity#onPause()}, after {@code super.onPause();}.
101 | * If you use it in a {@link android.app.Service}, you have to
102 | * call this method inside {@link android.app.Service#onDestroy()}.
103 | *
104 | * @param context context in which to unregister this receiver
105 | */
106 | public void unregister(final Context context) {
107 | context.unregisterReceiver(this);
108 | }
109 |
110 | @Override
111 | public void onProgress(final UploadInfo uploadInfo) {
112 | }
113 |
114 | @Override
115 | public void onError(final UploadInfo uploadInfo, final Exception exception) {
116 | }
117 |
118 | @Override
119 | public void onCompleted(final UploadInfo uploadInfo, final ServerResponse serverResponse) {
120 | }
121 |
122 | @Override
123 | public void onCancelled(final UploadInfo uploadInfo) {
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/upload/HttpUploadTaskParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.upload;
24 |
25 | import android.os.Parcel;
26 | import android.os.Parcelable;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | /**
32 | * Class which contains specific parameters for HTTP uploads.
33 | *
34 | * @author gotev (Aleksandar Gotev)
35 | */
36 | public final class HttpUploadTaskParameters implements Parcelable {
37 |
38 | protected static final String PARAM_HTTP_TASK_PARAMETERS = "httpTaskParameters";
39 |
40 | private String customUserAgent;
41 | private String method = "POST";
42 | private boolean usesFixedLengthStreamingMode = true;
43 | private ArrayList requestHeaders = new ArrayList<>();
44 | private ArrayList requestParameters = new ArrayList<>();
45 |
46 | public HttpUploadTaskParameters() {
47 |
48 | }
49 |
50 | // This is used to regenerate the object.
51 | // All Parcelables must have a CREATOR that implements these two methods
52 | public static final Parcelable.Creator CREATOR =
53 | new Parcelable.Creator() {
54 | @Override
55 | public HttpUploadTaskParameters createFromParcel(final Parcel in) {
56 | return new HttpUploadTaskParameters(in);
57 | }
58 |
59 | @Override
60 | public HttpUploadTaskParameters[] newArray(final int size) {
61 | return new HttpUploadTaskParameters[size];
62 | }
63 | };
64 |
65 | @Override
66 | public void writeToParcel(Parcel parcel, int arg1) {
67 | parcel.writeString(method);
68 | parcel.writeString(customUserAgent);
69 | parcel.writeByte((byte) (usesFixedLengthStreamingMode ? 1 : 0));
70 | parcel.writeList(requestHeaders);
71 | parcel.writeList(requestParameters);
72 | }
73 |
74 | private HttpUploadTaskParameters(Parcel in) {
75 | method = in.readString();
76 | customUserAgent = in.readString();
77 | usesFixedLengthStreamingMode = in.readByte() == 1;
78 | in.readList(requestHeaders, NameValue.class.getClassLoader());
79 | in.readList(requestParameters, NameValue.class.getClassLoader());
80 | }
81 |
82 | @Override
83 | public int describeContents() {
84 | return 0;
85 | }
86 |
87 | public void addRequestHeader(String name, String value) {
88 | requestHeaders.add(new NameValue(name, value));
89 | }
90 |
91 | public void addRequestParameter(String name, String value) {
92 | requestParameters.add(new NameValue(name, value));
93 | }
94 |
95 | public List getRequestHeaders() {
96 | return requestHeaders;
97 | }
98 |
99 | public List getRequestParameters() {
100 | return requestParameters;
101 | }
102 |
103 | public String getMethod() {
104 | return method;
105 | }
106 |
107 | public HttpUploadTaskParameters setMethod(String method) {
108 | if (method != null && method.length() > 0)
109 | this.method = method;
110 | return this;
111 | }
112 |
113 | public boolean isUsesFixedLengthStreamingMode() {
114 | return usesFixedLengthStreamingMode;
115 | }
116 |
117 | public HttpUploadTaskParameters setUsesFixedLengthStreamingMode(boolean usesFixedLengthStreamingMode) {
118 | this.usesFixedLengthStreamingMode = usesFixedLengthStreamingMode;
119 | return this;
120 | }
121 |
122 | public String getCustomUserAgent() {
123 | return customUserAgent;
124 | }
125 |
126 | public boolean isCustomUserAgentDefined() {
127 | return customUserAgent != null && !"".equals(customUserAgent);
128 | }
129 |
130 | public HttpUploadTaskParameters setCustomUserAgent(String customUserAgent) {
131 | this.customUserAgent = customUserAgent;
132 | return this;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/uk/ac/sussex/wear/android/datalogger/data/CommandKA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017. Mathias Ciliberto, Francisco Javier Ordoñez Morales,
3 | * Hristijan Gjoreski, Daniel Roggen
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | * this software and associated documentation files (the "Software"), to deal in
7 | * the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | * Software, and to permit persons to whom the Software is furnished to do so,
10 | * subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | package uk.ac.sussex.wear.android.datalogger.data;
24 |
25 | import java.util.Iterator;
26 |
27 | import uk.ac.sussex.wear.android.datalogger.R;
28 |
29 | public class CommandKA extends CommandBase {
30 |
31 | private boolean mDataCollectionState;
32 | private String mMasterSessionId;
33 | private long mNanosOffset;
34 | private boolean mLabelsAnnotationState;
35 | private int mActivityLabel;
36 | private int mBodyPositionLabel;
37 | private int mLocationLabel;
38 |
39 | public CommandKA() {
40 | this(false, "", -1, false, -1, -1, R.id.ui_iolocation_radioButton_outside);
41 | }
42 |
43 | public CommandKA(boolean dataCollectionState, String masterSessionId, long nanosOffset, boolean labelsAnnotationState, int activityLabel, int bodyPositionLabel, int locationLabel) {
44 | mDataCollectionState = dataCollectionState;
45 | mMasterSessionId = masterSessionId;
46 | mNanosOffset = nanosOffset;
47 | mLabelsAnnotationState = labelsAnnotationState;
48 | mActivityLabel = activityLabel;
49 | mBodyPositionLabel = bodyPositionLabel;
50 | mLocationLabel = locationLabel;
51 | }
52 |
53 | public boolean getDataCollectionState(){ return mDataCollectionState; }
54 | public String getMasterSessionId(){ return mMasterSessionId; }
55 | public long getNanosOffset(){ return mNanosOffset; }
56 | public boolean getLabelsAnnotationState(){ return mLabelsAnnotationState; }
57 | public int getActivityLabel(){ return mActivityLabel; }
58 | public int getBodyPositionLabel(){ return mBodyPositionLabel; }
59 | public int getLocationLabel(){ return mLocationLabel; }
60 |
61 | public Iterator getParams(Iterator itr) throws Exception {
62 | //Processing data collection event
63 | if (!itr.hasNext())
64 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
65 | mDataCollectionState = Boolean.parseBoolean(itr.next());
66 | if (!itr.hasNext())
67 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
68 | mMasterSessionId = itr.next();
69 | if (!itr.hasNext())
70 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
71 | mNanosOffset = Long.parseLong(itr.next());
72 |
73 | //Processing label annotation event
74 | if (!itr.hasNext())
75 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
76 | mLabelsAnnotationState = Boolean.parseBoolean(itr.next());
77 | if (!itr.hasNext())
78 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
79 | mActivityLabel = Integer.parseInt(itr.next());
80 | if (!itr.hasNext())
81 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
82 | mBodyPositionLabel = Integer.parseInt(itr.next());
83 | if (!itr.hasNext())
84 | throw new Exception("Command '" + COMMAND_KEEP_ALIVE_EVENT + "' is malformed or missing parameters");
85 | mLocationLabel = Integer.parseInt(itr.next());
86 |
87 | return itr;
88 | }
89 |
90 | @Override
91 | public String getMessage() {
92 | return COMMAND_START
93 | + COMMAND_KEEP_ALIVE_EVENT + COMMAND_SEPARATOR
94 | + Boolean.toString(mDataCollectionState) + PARAMETER_SEPARATOR
95 | + mMasterSessionId + PARAMETER_SEPARATOR
96 | + Long.toString(mNanosOffset) + PARAMETER_SEPARATOR
97 | + Boolean.toString(mLabelsAnnotationState) + PARAMETER_SEPARATOR
98 | + Integer.toString(mActivityLabel) + PARAMETER_SEPARATOR
99 | + Integer.toString(mBodyPositionLabel) + PARAMETER_SEPARATOR
100 | + Integer.toString(mLocationLabel) + PARAMETER_SEPARATOR;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_flag_event.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
29 |
30 |
36 |
37 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
70 |
71 |
77 |
78 |
85 | />
86 |
87 |
88 |
95 |
96 |
101 |
102 |
108 |
109 |
110 |
116 |
117 |
123 |
124 |
125 |
--------------------------------------------------------------------------------