From 49b797030294072a626b21dec992c9f1c18828fd Mon Sep 17 00:00:00 2001
From: BB <boqi.ren@tu-dresden.de>
Date: Mon, 13 May 2019 10:49:14 +0200
Subject: [PATCH] add smartphone acceleration

---
 build.gradle                                  |  2 +-
 gradle/wrapper/gradle-wrapper.properties      |  4 ++--
 .../inf/st/sensorsharing/MainActivity.java    | 20 +++++++++++++++-
 mobile/src/main/res/layout/fragment_first.xml | 24 ++++++++++++++++---
 .../src/main/res/layout/fragment_second.xml   | 10 +++++++-
 5 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/build.gradle b/build.gradle
index 06b112e..2e533af 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,7 +10,7 @@ buildscript {
         }
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.3'
+        classpath 'com.android.tools.build:gradle:3.4.0'
         
 
         // NOTE: Do not place your application dependencies here; they belong
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index ed81f1e..32f3585 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Nov 28 11:04:23 CET 2018
+#Fri May 10 15:21:13 CEST 2019
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
diff --git a/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java b/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java
index 4d73906..138edac 100644
--- a/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java
+++ b/mobile/src/main/java/de/tudresden/inf/st/sensorsharing/MainActivity.java
@@ -439,6 +439,7 @@ public class MainActivity extends AppCompatActivity implements
         final CheckBox sendUpdates = findViewById(R.id.checkBox_send_brightness);
         final CheckBox sendUpdatesRotation = findViewById(R.id.checkBox_send_rotation_ahrs);
         final CheckBox sendUpdatesRotationQuat = findViewById(R.id.checkBox_send_rotation_quaternion);
+        final CheckBox sendUpdatesAcceleration = findViewById(R.id.checkBox_send_acceleration);
 
         final CheckBox sendUpdatesWearBrightness = findViewById(R.id.checkBox_send_wear_brightness);
         final CheckBox sendUpdatesWearAcc= findViewById(R.id.checkBox_send_wear_acceleration);
@@ -450,6 +451,7 @@ public class MainActivity extends AppCompatActivity implements
         sendMqttUpdates.put(phoneTopics.mqtt_topic_brightness, sendUpdates.isChecked());
         sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation_ahrs, sendUpdatesRotation.isChecked());
         sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked());
+        sendMqttUpdates.put(phoneTopics.mqtt_topic_acceleration, sendUpdatesAcceleration.isChecked());
 
         sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
         sendMqttUpdates.put(wearTopics.mqtt_topic_acceleration, sendUpdatesWearAcc.isChecked());
@@ -471,6 +473,9 @@ public class MainActivity extends AppCompatActivity implements
                         sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked());
                         break;
                         //test wear
+                    case R.id.checkBox_send_acceleration:
+                        sendMqttUpdates.put(phoneTopics.mqtt_topic_acceleration, sendUpdatesAcceleration.isChecked());
+                        break;
                     case R.id.checkBox_send_wear_brightness:
                         sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
                         break;
@@ -495,6 +500,7 @@ public class MainActivity extends AppCompatActivity implements
         sendUpdates.setOnCheckedChangeListener(onCheckedChangeListener);
         sendUpdatesRotation.setOnCheckedChangeListener(onCheckedChangeListener);
         sendUpdatesRotationQuat.setOnCheckedChangeListener(onCheckedChangeListener);
+        sendUpdatesAcceleration.setOnCheckedChangeListener(onCheckedChangeListener);
         sendUpdatesWearBrightness.setOnCheckedChangeListener(onCheckedChangeListener);
         sendUpdatesWearAcc.setOnCheckedChangeListener(onCheckedChangeListener);
         sendUpdatesWearRotation.setOnCheckedChangeListener(onCheckedChangeListener);
@@ -687,6 +693,8 @@ public class MainActivity extends AppCompatActivity implements
                 break;
             case Sensor.TYPE_ACCELEROMETER:
                 accelVectorValues = sensorEvent.values;
+                textView = findViewById(R.id.value_own_acceleration);
+                textView.setText(Utils.formatArray3(accelVectorValues));
             case Sensor.TYPE_GYROSCOPE:
                 gyroVectorValues = sensorEvent.values;
                 break;
@@ -715,7 +723,6 @@ public class MainActivity extends AppCompatActivity implements
         mSensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_UI);
         mSensorManager.registerListener(this, magSensor, SensorManager.SENSOR_DELAY_UI);
         Wearable.getMessageClient(this).addListener(this);
-
     }
 
     @Override
@@ -886,6 +893,17 @@ public class MainActivity extends AppCompatActivity implements
         } catch (JsonProcessingException e) {
             e.printStackTrace();
         }
+        // Acceleration data
+        HashMap<String, Float> acceleration = new HashMap<>();
+        acceleration.put("x", accelVectorValues[0]);
+        acceleration.put("y", accelVectorValues[1]);
+        acceleration.put("z", accelVectorValues[2]);
+        try {
+            String s = mapper.writeValueAsString(acceleration);
+            sendUpdate(phoneTopics.mqtt_topic_acceleration, String.valueOf(acceleration));
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+        }
 
         // AHRS data
         filter.Update(gyroVectorValues[0], gyroVectorValues[1], gyroVectorValues[2],
diff --git a/mobile/src/main/res/layout/fragment_first.xml b/mobile/src/main/res/layout/fragment_first.xml
index 1522056..f3e4d04 100644
--- a/mobile/src/main/res/layout/fragment_first.xml
+++ b/mobile/src/main/res/layout/fragment_first.xml
@@ -17,7 +17,7 @@
             android:layout_marginTop="8dp"
             android:text="@string/text_rotation"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
+            app:layout_constraintTop_toBottomOf="@+id/label_own_acceleration" />
 
         <TextView
             android:id="@+id/value_own_rotation"
@@ -27,7 +27,25 @@
             android:layout_marginTop="8dp"
             android:text="@android:string/unknownName"
             app:layout_constraintStart_toEndOf="@+id/label_own_rotation"
-            app:layout_constraintTop_toBottomOf="@+id/value_own_brightness" />
+            app:layout_constraintTop_toBottomOf="@+id/value_own_acceleration" />
+        <TextView
+            android:id="@+id/label_own_acceleration"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:text="Acceleration"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
+        <TextView
+            android:id="@+id/value_own_acceleration"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:text="unknown"
+            app:layout_constraintLeft_toRightOf="@id/label_own_acceleration"
+            app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
 
         <TextView
             android:id="@+id/label_wear_name"
@@ -97,7 +115,7 @@
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintHorizontal_bias="0.0"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/label_own_brightness" />
+            app:layout_constraintTop_toBottomOf="@+id/label_own_rotation" />
 
         <TextView
             android:id="@+id/label_own_brightness"
diff --git a/mobile/src/main/res/layout/fragment_second.xml b/mobile/src/main/res/layout/fragment_second.xml
index ecca488..c619fdf 100644
--- a/mobile/src/main/res/layout/fragment_second.xml
+++ b/mobile/src/main/res/layout/fragment_second.xml
@@ -81,6 +81,14 @@
             android:text="@string/send_updates_rotation_quaternion"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_ahrs" />
+        <CheckBox
+            android:id="@+id/checkBox_send_acceleration"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:text="Send Updates Acceleration"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" />
 
         <CheckBox
             android:id="@+id/checkBox_send_wear_brightness"
@@ -89,7 +97,7 @@
             android:layout_marginStart="8dp"
             android:text="@string/send_updates_wear_brightness"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" />
+            app:layout_constraintTop_toBottomOf="@+id/checkBox_send_acceleration" />
 
         <CheckBox
             android:id="@+id/checkBox_send_wear_acceleration"
-- 
GitLab