Browse Source

First logging on console of touch event

Sebastian Vendt 6 năm trước cách đây
mục cha
commit
a37a00c2c2

+ 20 - 0
app/src/main/java/com/motionlogger/sebastianvendt/motionlogger/MainActivity.java

@@ -1,5 +1,8 @@
 package com.motionlogger.sebastianvendt.motionlogger;
 
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.util.Log;
@@ -8,15 +11,32 @@ import android.view.View;
 import android.widget.EditText;
 import android.content.Intent;
 
+import java.util.Iterator;
+import java.util.List;
+
 
 public class MainActivity extends AppCompatActivity {
     public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
+    private SensorManager mSensorManager;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         findViewById(android.R.id.content).setOnTouchListener(handleTouch);
 
+        //list the sensors available on the device
+        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+        List<Sensor> deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
+
+        Iterator<Sensor> sensorIterator = deviceSensors.iterator();
+
+        while (sensorIterator.hasNext()){
+            Sensor sens = sensorIterator.next();
+            EditText console = (EditText) findViewById(R.id.Console);
+            console.setText(sens.getName());
+        }
+
+
 
 
 

+ 18 - 21
app/src/main/res/layout/activity_main.xml

@@ -6,34 +6,31 @@
     android:layout_height="match_parent"
     tools:context=".MainActivity">
 
-    <EditText
-        android:id="@+id/editText"
-        android:layout_width="0dp"
-        android:layout_height="85dp"
-        android:layout_marginStart="16dp"
-        android:layout_marginLeft="16dp"
-        android:layout_marginTop="16dp"
-        android:ems="10"
-        android:hint="@string/edit_message"
-        android:inputType="textPersonName"
-        app:layout_constraintEnd_toStartOf="@+id/button"
-        app:layout_constraintHorizontal_bias="0.5"
-        app:layout_constraintHorizontal_chainStyle="packed"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-
     <Button
         android:id="@+id/button"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginEnd="24dp"
+        android:layout_marginRight="24dp"
+        android:layout_marginBottom="16dp"
+        android:onClick="sendMessage"
+        android:text="@string/button_start"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent" />
+
+    <EditText
+        android:id="@+id/Console"
+        android:layout_width="334dp"
+        android:layout_height="194dp"
         android:layout_marginStart="16dp"
         android:layout_marginLeft="16dp"
+        android:layout_marginTop="8dp"
         android:layout_marginEnd="16dp"
         android:layout_marginRight="16dp"
-        android:onClick="sendMessage"
-        android:text="@string/button_send"
-        app:layout_constraintBaseline_toBaselineOf="@+id/editText"
+        android:ems="10"
+        android:inputType="textPersonName"
+        android:text="@string/Console_text"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintHorizontal_bias="0.5"
-        app:layout_constraintStart_toEndOf="@+id/editText" />
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
 </android.support.constraint.ConstraintLayout>

+ 2 - 1
app/src/main/res/values/strings.xml

@@ -1,5 +1,6 @@
 <resources>
     <string name="app_name">MotionLogger</string>
     <string name="edit_message">test</string>
-    <string name="button_send">Send</string>
+    <string name="button_start">Start</string>
+    <string name="Console_text">Console</string>
 </resources>