Skip to content
Snippets Groups Projects
Commit 2a557954 authored by boqiren's avatar boqiren
Browse files

1. make the connection (mobil and watch) work,2 changed the mobil ui, add ui...

1. make the connection (mobil and watch) work,2 changed the mobil ui, add ui component for user identification and justy the brightness
parent 90a8501c
Branches
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
......
#Fri May 11 14:09:11 CEST 2018
#Wed Nov 28 11:04:23 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
......@@ -41,4 +41,6 @@ dependencies {
// Wear services
wearApp project(':wear')
implementation 'com.google.android.gms:play-services-wearable:15.0.1'
//Rest API
implementation 'com.android.volley:volley:1.1.1'
}
......@@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<application
android:allowBackup="true"
android:icon="@mipmap/openlicht_launcher"
......
package de.tudresden.inf.st.sensorsharing;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
......@@ -14,6 +15,7 @@ import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
......@@ -21,6 +23,12 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.gms.wearable.MessageClient;
......@@ -36,8 +44,12 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
......@@ -49,6 +61,7 @@ import de.tudresden.inf.st.sensorsharing.common.MqttUtils;
import de.tudresden.inf.st.sensorsharing.common.Utils;
import de.tudresden.inf.st.sensorsharing.settings.AppSettings;
import static de.tudresden.inf.st.sensorsharing.common.Constants.BASE_KEY;
import static de.tudresden.inf.st.sensorsharing.common.Constants.BASE_KEY_LENGTH;
import static de.tudresden.inf.st.sensorsharing.common.Constants.MQTT_CHARSET;
......@@ -58,6 +71,9 @@ import static de.tudresden.inf.st.sensorsharing.common.Constants.SUB_KEY_NAME;
import static de.tudresden.inf.st.sensorsharing.common.Constants.SUB_KEY_ROTATION_VECTOR;
import static de.tudresden.inf.st.sensorsharing.settings.AppSettings.SETTINGS_MQTT_SERVER;
import static java.lang.Math.atan2;
//bbq
public class MainActivity extends AppCompatActivity implements
SensorEventListener,
......@@ -65,7 +81,22 @@ public class MainActivity extends AppCompatActivity implements
private static final String TAG = "SensorSharing";
// private static final String MQTT_TOPIC_SAMSUNG = "sensors/samsung/brightness";
//boqi add
private static final String MQTT_TOPIC_USER1 = "oh2/in/user1/state";
private static final String MQTT_TOPIC_USER2 = "oh2/in/user2/state";
//private static final String MQTT_TOPIC_USER1_BRIGHTNESS = "oh2/in/user1_brightness/state";
//private static final String MQTT_TOPIC_USER2_BRIGHTNESS = "oh2/in/user1_brightness/state";
private static final String MQTT_TOPIC_IRIS1_ITEM = "oh2/in/iris1_item/state";
private static final String MQTT_TOPIC_DATETIME_MONTH = "oh2/in/datetime/month";
private static final String MQTT_TOPIC_DATETIME_DAY = "oh2/in/datetime/day";
private static final String MQTT_TOPIC_DATETIME_HOUR = "oh2/in/datetime/hour";
private static final String MQTT_TOPIC_DATETIME_MINUTE = "oh2/in/datetime/minute";
//variable for the on/off user
private static String user1_status = "off";
private static String user2_status = "off";
//for shake action
private static int i = 0; //user 1 shake action
private static int j = 0; //user 2 shake action
// sensor management
private SensorManager mSensorManager;
private Sensor mLight;
......@@ -101,6 +132,13 @@ public class MainActivity extends AppCompatActivity implements
private AppSettings settings;
MadgwickAHRS filter;
ToggleButton switchLight;
//BOQI ADD
ToggleButton user1;
ToggleButton user2;
Button sendbutton1;
Button sendbutton2;
EditText edittext1;
EditText edittext2;
private EditText valueServerURI;
......@@ -143,8 +181,6 @@ public class MainActivity extends AppCompatActivity implements
Log.w(TAG, "Using alternative rotation sensor!");
}
}
// initialize sensor values
mLightValue = -1;
mRotationVectorValues = new float[3];
......@@ -169,14 +205,12 @@ public class MainActivity extends AppCompatActivity implements
}
};
handler.post(runnable);
}
private void initViews() {
setName();
valueServerURI = findViewById(R.id.value_server_uri);
String mqttServer = settings.get(SETTINGS_MQTT_SERVER, getResources().getString(R.string.default_mqtt_server_uri));
valueServerURI.setText(mqttServer);
......@@ -193,9 +227,176 @@ public class MainActivity extends AppCompatActivity implements
}
});
//bbq
user1=findViewById(R.id.user_1_button);
user2=findViewById(R.id.user_2_button);
sendbutton1 =findViewById(R.id.send_button_1);
sendbutton2=findViewById(R.id.send_button_2);
edittext1=findViewById(R.id.edit_text_1);
edittext2=findViewById(R.id.edit_text_2);
edittext1.setEnabled(false);
edittext2.setEnabled(false);
sendbutton1.setEnabled(false);
sendbutton2.setEnabled(false);
user1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
user1_status="on";
sendMqttUpdates.put(MQTT_TOPIC_USER1,true);
sendUpdate(MQTT_TOPIC_USER1, "ON");
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MONTH,true);
sendUpdate(MQTT_TOPIC_DATETIME_MONTH,getDateTime()[0]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_DAY,true);
sendUpdate(MQTT_TOPIC_DATETIME_DAY,getDateTime()[1]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_HOUR,true);
sendUpdate(MQTT_TOPIC_DATETIME_HOUR,getDateTime()[2]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MINUTE,true);
sendUpdate(MQTT_TOPIC_DATETIME_MINUTE,getDateTime()[3]);
//set up for buttons
user2.setEnabled(false);
sendbutton2.setEnabled(false);
sendbutton1.setEnabled(true);
edittext1.setEnabled(true);
System.out.println(accelVectorValues[0]);
System.out.println(accelVectorValues[1]);
System.out.println(accelVectorValues[2]);
sendbutton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MONTH,true);
sendUpdate(MQTT_TOPIC_DATETIME_MONTH,getDateTime()[0]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_DAY,true);
sendUpdate(MQTT_TOPIC_DATETIME_DAY,getDateTime()[1]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_HOUR,true);
sendUpdate(MQTT_TOPIC_DATETIME_HOUR,getDateTime()[2]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MINUTE,true);
sendUpdate(MQTT_TOPIC_DATETIME_MINUTE,getDateTime()[3]);
//send datetime
String userBrightness= edittext1.getText().toString();
//sendUserId("user1",edittext1.getText().toString());
sendMqttUpdates.put(MQTT_TOPIC_IRIS1_ITEM,true);
sendUpdate(MQTT_TOPIC_IRIS1_ITEM, getBrigtnessValue(userBrightness));
}
});
}else{
user1_status="off";
sendMqttUpdates.put(MQTT_TOPIC_USER1,true);
sendUpdate(MQTT_TOPIC_USER1, "OFF");
user2.setEnabled(true);
edittext1.setEnabled(false);
edittext2.setEnabled(false);
sendbutton1.setEnabled(false);
sendbutton2.setEnabled(false);}
}
});
user2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
user2_status="on";
sendMqttUpdates.put(MQTT_TOPIC_USER2,true);
sendUpdate(MQTT_TOPIC_USER2, "ON");
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MONTH,true);
sendUpdate(MQTT_TOPIC_DATETIME_MONTH,getDateTime()[0]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_DAY,true);
sendUpdate(MQTT_TOPIC_DATETIME_DAY,getDateTime()[1]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_HOUR,true);
sendUpdate(MQTT_TOPIC_DATETIME_HOUR,getDateTime()[2]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MINUTE,true);
sendUpdate(MQTT_TOPIC_DATETIME_MINUTE,getDateTime()[3]);
user1.setEnabled(false);
sendbutton1.setEnabled(false);
sendbutton2.setEnabled(true);
edittext2.setEnabled(true);
sendbutton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MONTH,true);
sendUpdate(MQTT_TOPIC_DATETIME_MONTH,getDateTime()[0]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_DAY,true);
sendUpdate(MQTT_TOPIC_DATETIME_DAY,getDateTime()[1]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_HOUR,true);
sendUpdate(MQTT_TOPIC_DATETIME_HOUR,getDateTime()[2]);
sendMqttUpdates.put(MQTT_TOPIC_DATETIME_MINUTE,true);
sendUpdate(MQTT_TOPIC_DATETIME_MINUTE,getDateTime()[3]);
//send preferences
String userBrightness= edittext2.getText().toString();
System.out.println(userBrightness);
sendMqttUpdates.put(MQTT_TOPIC_IRIS1_ITEM,true);
sendUpdate(MQTT_TOPIC_IRIS1_ITEM, getBrigtnessValue(userBrightness));
}
});
}else {
user2_status="off";
sendMqttUpdates.put(MQTT_TOPIC_USER2,true);
sendUpdate(MQTT_TOPIC_USER2, "OFF");
user1.setEnabled(true);
edittext1.setEnabled(false);
edittext2.setEnabled(false);
sendbutton1.setEnabled(false);
sendbutton2.setEnabled(false);}
}
});
setupSendUpdatesCheckbox();
}
//boqi
private String getBrigtnessValue(String Brightness){
String BrightnessValue= "";
if(Brightness.equals("OFF")){
BrightnessValue="0";
}else if(Brightness.equals("DIM")){
BrightnessValue="25";
}
else if(Brightness.equals("MEDIUM")){
BrightnessValue="60";
}
else if(Brightness.equals("BRIGHT")) {
BrightnessValue="90";}
return BrightnessValue;
}
//boqi
private String [] getDateTime(){
DateFormat df = new SimpleDateFormat("yy:MM:dd:HH:mm");
String date = df.format(Calendar.getInstance().getTime());
String[] datetime_split= new String[5];
datetime_split=date.split(":");
return datetime_split;
}
//boqi
private void sendUserId(String userId, String Text){
String userid=userId;
String text = Text;
System.out.println(userid);
System.out.println(text);
RequestQueue queue= Volley.newRequestQueue(this);
String url ="http://192.168.99.1:5000/user/1";//must in the same wifi phone and host
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println("request working -------------------------------");
System.out.println(response.getClass());
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("That didnt work");
System.out.println(error);
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
private void sendLightOnOffUpdateOfSmartphone(boolean state) {
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Boolean> dataLight = new HashMap<>();
......@@ -229,10 +430,19 @@ 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);
//checkbox for wearable
final CheckBox sendUpdatesWearBrightness = findViewById(R.id.checkBox_send_wear_brightness);
final CheckBox sendUpdatesWearAcc= findViewById(R.id.checkBox_send_wear_acceleration);
final CheckBox sendUpdatesWearRotation= findViewById(R.id.checkBox_send_wear_rotation);
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());
//checkbox for wearable
sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
sendMqttUpdates.put(wearTopics.mqtt_topic_acceleration, sendUpdatesWearAcc.isChecked());
sendMqttUpdates.put(wearTopics.mqtt_topic_rotation, sendUpdatesWearRotation.isChecked());
CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
......@@ -247,16 +457,30 @@ public class MainActivity extends AppCompatActivity implements
case R.id.checkBox_send_rotation_quaternion:
sendMqttUpdates.put(phoneTopics.mqtt_topic_rotation, sendUpdatesRotationQuat.isChecked());
break;
//test wear
case R.id.checkBox_send_wear_brightness:
sendMqttUpdates.put(wearTopics.mqtt_topic_brightness, sendUpdatesWearBrightness.isChecked());
break;
case R.id.checkBox_send_wear_acceleration:
sendMqttUpdates.put(wearTopics.mqtt_topic_acceleration, sendUpdatesWearBrightness.isChecked());
break;
case R.id.checkBox_send_wear_rotation:
sendMqttUpdates.put(wearTopics.mqtt_topic_rotation, sendUpdatesWearBrightness.isChecked());
break;
}
}
};
sendUpdates.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesRotation.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesRotationQuat.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearBrightness.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearAcc.setOnCheckedChangeListener(onCheckedChangeListener);
sendUpdatesWearRotation.setOnCheckedChangeListener(onCheckedChangeListener);
}
private void setName() {
TextView ownName = findViewById(R.id.value_own_name);
TextView wearName = findViewById(R.id.value_wear_name);
ownName.setText(Build.MODEL);
}
......@@ -361,6 +585,64 @@ public class MainActivity extends AppCompatActivity implements
break;
case Sensor.TYPE_ACCELEROMETER:
accelVectorValues = sensorEvent.values;
//boqi
System.out.println("com in case");
System.out.println(i);
System.out.println(j);
float x = accelVectorValues[0];
float y = accelVectorValues[1];
float z = accelVectorValues[2];
if (Math.abs(x) > 17 || Math.abs(y) > 17 || Math
.abs(z) > 17){
System.out.println("com in loop");
System.out.println(i);
System.out.println(j);
edittext1=findViewById(R.id.edit_text_1);
edittext2=findViewById(R.id.edit_text_2);
if (user1_status.equals("on")){
i++;
if (i==1){
edittext1.setText("OFF");
}else if(i==2){
edittext1.setText("DIM");
}
else if (i==3){
edittext1.setText("MEDIUM");
}
else if (i==4){
edittext1.setText("BRIGHT");
}
else {
i=0;
edittext1.setText("OFF");}
}else if (user1_status.equals("off")){
i=0;
edittext1.setText("OFF");
}
if(user2_status.equals("on")){
j++;
if (j == 1){
edittext2.setText("OFF");
}else if(j == 2){
edittext2.setText("DIM");
}
else if (j == 3){
edittext2.setText("MEDIUM");
}
else if (j == 4){
edittext2.setText("BRIGHT");
}
else {j=0;
edittext2.setText("OFF");}
}else if (user2_status.equals("off")){
j = 0;
edittext2.setText("OFF");
}
}
break;
case Sensor.TYPE_GYROSCOPE:
gyroVectorValues = sensorEvent.values;
......@@ -380,7 +662,6 @@ public class MainActivity extends AppCompatActivity implements
public void onAccuracyChanged(Sensor sensor, int i) {
// ignore accuracy changes
}
@Override
protected void onResume() {
super.onResume();
......@@ -423,14 +704,16 @@ public class MainActivity extends AppCompatActivity implements
updatedValue = Float.toString(mWearBrightness);
textViewToUpdate = findViewById(R.id.value_wear_brightness);
topic = wearTopics.mqtt_topic_brightness;
//updateMqttTopics(updatedValue);
break;
case SUB_KEY_LINEAR_ACCELERATION:
// float[] accelerationData = new float[3];
// writeFloatArray(ByteBuffer.wrap(messageEvent.getData()), accelerationData);
// updatedValue = Arrays.toString(accelerationData);
// updatedValue = Arrays.toString(accelerationData)
updatedValue = formatByteFloatArray(ByteBuffer.wrap(messageEvent.getData()));
textViewToUpdate = findViewById(R.id.value_wear_acceleration);
topic = wearTopics.mqtt_topic_acceleration;
//updateMqttTopics(updatedValue);
break;
case SUB_KEY_ROTATION_VECTOR:
// float[] rotationData = new float[3];
......@@ -439,6 +722,7 @@ public class MainActivity extends AppCompatActivity implements
updatedValue = formatByteFloatArray(ByteBuffer.wrap(messageEvent.getData()));
textViewToUpdate = findViewById(R.id.value_wear_rotation);
topic = wearTopics.mqtt_topic_rotation;
//updateMqttTopics(updatedValue);
break;
case SUB_KEY_NAME:
updatedValue = new String(messageEvent.getData(), MQTT_CHARSET);
......@@ -458,13 +742,20 @@ public class MainActivity extends AppCompatActivity implements
}
});
if (topic != null) {
sendUpdateOfWearable(topic, bytesToSendViaMqtt);
//sendUpdateOfWearable(topic, bytesToSendViaMqtt);
sendUpdateOfWearable(topic, updatedValue);
}
}
}
private String formatByteFloatArray(ByteBuffer buffer) {
return formatFloatArray(buffer.asFloatBuffer().array());
float[] arr = new float[3];
arr[0]=buffer.asFloatBuffer().get(0);
arr[1]=buffer.asFloatBuffer().get(1);
arr[2]=buffer.asFloatBuffer().get(2);
return formatFloatArray(arr);
}
private String formatFloatArray(float... values) {
......@@ -484,10 +775,9 @@ public class MainActivity extends AppCompatActivity implements
}
}
private void sendUpdateOfWearable(String topic, byte[] newValue) {
private void sendUpdateOfWearable(String topic, String newValue) {
sendUpdate(topic, newValue);
}
/**
* Method to initiate the mqtt publish action of the required sensor data.
* Whether the data is really published depends on the checkboxes.
......@@ -499,9 +789,10 @@ public class MainActivity extends AppCompatActivity implements
// Brightness data
HashMap<String, Float> dataLight = new HashMap<>();
dataLight.put("brightness", mLightValue);
try {
String s = mapper.writeValueAsString(dataLight);
sendUpdate(phoneTopics.mqtt_topic_brightness, s);
sendUpdate(phoneTopics.mqtt_topic_brightness, String.valueOf(mLightValue) );
} catch (JsonProcessingException e) {
e.printStackTrace();
}
......@@ -521,7 +812,7 @@ public class MainActivity extends AppCompatActivity implements
data.put("roll", roll);
try {
String s = mapper.writeValueAsString(data);
sendUpdate(phoneTopics.mqtt_topic_rotation_ahrs, s);
sendUpdate(phoneTopics.mqtt_topic_rotation_ahrs, String.valueOf(data));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
......@@ -534,7 +825,7 @@ public class MainActivity extends AppCompatActivity implements
//dataQuat.put("w", mRotationVectorValues[3]);
try {
String s = mapper.writeValueAsString(dataQuat);
sendUpdate(phoneTopics.mqtt_topic_rotation, s);
sendUpdate(phoneTopics.mqtt_topic_rotation, String.valueOf(dataQuat));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
......
......@@ -10,6 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label_own_rotation"
android:layout_width="wrap_content"
......@@ -83,7 +84,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/user_2_button" />
<TextView
android:id="@+id/separator_wear"
......@@ -207,8 +208,8 @@
android:id="@+id/value_server_uri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:ems="10"
android:inputType="text|textUri"
android:text="@string/default_mqtt_server_uri"
......@@ -220,8 +221,8 @@
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:onClick="connectMqtt"
android:text="@android:string/ok"
app:layout_constraintEnd_toEndOf="parent"
......@@ -242,7 +243,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/text_send_updates_brightness"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/value_server_uri" />
......@@ -252,7 +252,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/text_send_updates_rotationahrs"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_brightness" />
......@@ -262,11 +261,38 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
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_wear_brightness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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" />
<CheckBox
android:id="@+id/checkBox_send_wear_acceleration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/send_updates_wear_acceleration"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_wear_brightness" />
<CheckBox
android:id="@+id/checkBox_send_wear_rotation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/send_updates_wear_rotation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_wear_acceleration" />
<TextView
android:id="@+id/label_wear_status"
android:layout_width="wrap_content"
......@@ -287,7 +313,110 @@
android:textOff="@string/switch_light_on"
android:textOn="@string/switch_light_off"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_rotation_quaternion" />
app:layout_constraintTop_toBottomOf="@+id/checkBox_send_wear_rotation" />
<TextView
android:id="@+id/user_identification"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"
android:text="@string/user_identification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/label_user_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="User 1: "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/user_identification" />
<ToggleButton
android:id="@+id/user_1_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="172dp"
android:text="User 1"
android:textOff="on"
android:textOn="off"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/label_user_1"
app:layout_constraintTop_toBottomOf="@+id/user_identification" />
<TextView
android:id="@+id/label_user_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="User 2: "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_user_1" />
<ToggleButton
android:id="@+id/user_2_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="172dp"
android:text="User 2"
android:textOff="on"
android:textOn="off"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/label_user_2"
app:layout_constraintTop_toBottomOf="@+id/user_1_button" />
<EditText
android:id="@+id/edit_text_1"
android:layout_width="71dp"
android:layout_height="46dp"
android:ems="10"
android:inputType="number"
app:layout_constraintEnd_toStartOf="@id/send_button_1"
app:layout_constraintStart_toEndOf="@id/user_1_button"
app:layout_constraintLeft_toLeftOf="@+id/user_1_button"
app:layout_constraintTop_toBottomOf="@+id/user_identification"/>
<EditText
android:id="@+id/edit_text_2"
android:layout_width="71dp"
android:layout_height="46dp"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="number"
app:layout_constraintEnd_toStartOf="@id/send_button_1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/user_1_button"
app:layout_constraintStart_toEndOf="@id/user_1_button"
app:layout_constraintTop_toBottomOf="@+id/user_identification" />
<Button
android:id="@+id/send_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="172dp"
android:text="SEND"
app:layout_constraintStart_toEndOf="@id/edit_text_1"
app:layout_constraintLeft_toRightOf="@+id/edit_text_1"
app:layout_constraintTop_toBottomOf="@+id/user_identification" />
<Button
android:id="@+id/send_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:text="SEND"
app:layout_constraintLeft_toRightOf="@+id/edit_text_1"
app:layout_constraintStart_toEndOf="@id/edit_text_1"
app:layout_constraintTop_toBottomOf="@+id/user_identification" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
......@@ -12,9 +12,13 @@
<string name="text_separator_mqtt_settings">MQTT Settings</string>
<string name="text_send_updates_brightness">Send Updates Brightness</string>
<string name="text_send_updates_rotationahrs">Send Updates Rotation (AHRS)</string>
<string name="send_updates_wear_brightness">Send Updates Wearable Brightness</string>
<string name="send_updates_wear_acceleration">Send Updates Wearable Acceleration</string>
<string name="send_updates_wear_rotation">Send Updates Wearable Rotation</string>
<string name="status">Status</string>
<string name="switch_on">Switch On</string>
<string name="switch_light_on">Switch Light ON</string>
<string name="switch_light_off">Switch Light OFF</string>
<string name="send_updates_rotation_quaternion">Send Updates Rotation (Quaternion)</string>
<string name="user_identification">User Identification</string>
</resources>
......@@ -61,6 +61,8 @@ public class MainActivity extends WearableActivity implements SensorEventListene
for (Sensor sensor : allSensors) {
sb.append(sensor.getName()).append(":").append(sensor.getStringType()).append(";");
}
Log.i(TAG, "Available sensors: " + sb.toString());
// initialize sensors
......@@ -87,7 +89,6 @@ public class MainActivity extends WearableActivity implements SensorEventListene
Log.w(TAG, "Using alternative rotation sensor!");
}
}
// initialize sensor values
mLinearAccelerationValues = new float[3];
mRotationVectorValues = new float[3];
......@@ -110,6 +111,8 @@ public class MainActivity extends WearableActivity implements SensorEventListene
case Sensor.TYPE_LINEAR_ACCELERATION:
case Sensor.TYPE_ACCELEROMETER:
mLinearAccelerationValues = sensorEvent.values;
System.out.println("-----------------------------");
System.out.println(Utils.formatArray3(mLinearAccelerationValues));
textView = findViewById(R.id.acceleration_value);
textView.setText(Utils.formatArray3(mLinearAccelerationValues));
break;
......@@ -135,7 +138,7 @@ public class MainActivity extends WearableActivity implements SensorEventListene
if (sendName) {
final byte[] nameData = Build.MODEL.getBytes(MQTT_CHARSET);
messageClient.sendMessage(node.getId(), KEY_NAME, nameData);
sendName = false;
//sendName = false;
}
messageClient.sendMessage(node.getId(), KEY_BRIGHTNESS, brightnessData);
messageClient.sendMessage(node.getId(), KEY_LINEAR_ACCELERATION, accelerationData);
......
......@@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey"
android:background="@color/white"
android:padding="@dimen/box_inset_layout_padding"
tools:context="de.tudresden.inf.st.sensorsharing.MainActivity"
tools:deviceIds="wear">
......@@ -20,12 +20,14 @@
android:id="@+id/brightness_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="top|end" />
<TextView
android:id="@+id/brightness_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="top|start"
android:text="@string/text_brightness" />
......@@ -33,12 +35,14 @@
android:id="@+id/acceleration_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="center|end" />
<TextView
android:id="@+id/acceleration_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="center|start"
android:text="@string/text_acceleration" />
......@@ -46,12 +50,14 @@
android:id="@+id/rotation_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="bottom|end" />
<TextView
android:id="@+id/rotation_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_gravity="bottom|start"
android:text="@string/text_rotation" />
</FrameLayout>
......
......@@ -8,5 +8,6 @@
<string name="text_brightness">Bri</string>
<string name="text_acceleration">Acc</string>
<string name="text_rotation">Rot</string>
<string name="pose">Pose</string>
<string name="error_sensormanager_null">Could not fetch sensor manager</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment