Sebastian Vendt 6 vuotta sitten
vanhempi
commit
1c858d9741

+ 4 - 29
app/src/main/java/com/motionlogger/sebastianvendt/motionlogger/MainActivity.java

@@ -72,37 +72,12 @@ public class MainActivity extends AppCompatActivity {
     }
 
     public void addMessageToConsole(String message) {
-
-       /* if(console != null){
-            console.append(message);
-            final Layout layout = console.getLayout();
-            if(layout != null){
-                int scrollDelta = layout.getLineBottom(console.getLineCount() - 1)
-                        - console.getScrollY() - console.getHeight();
-                if(scrollDelta > 0)
-                    console.scrollBy(0, scrollDelta);
-            }
-        }*/
-
-        console.append(message);/*
-        Layout consoleLayout = console.getLayout();
-        if(consoleLayout != null) {
-            final int scrollAmount = consoleLayout.getLineTop(console.getLineCount()) - console.getHeight();
-            if(scrollAmount > 0) {
-                console.scrollTo(0, scrollAmount);
-            } else {
-                console.scrollTo(0,0);
-            }
-        }*/
+        console.append(message);
     }
 
-    public void sendMessage(View view) {
-       /* Intent intent = new Intent(this, DisplayMessageActivity.class);
-        EditText editText = (EditText) findViewById(R.id.Console);
-        String message = editText.getText().toString();
-        intent.putExtra(EXTRA_MESSAGE, message);
-        startActivity(intent);*/
-
+    public void recordTrainingData (View view) {
+        Intent recTrainingData = new Intent(this, TouchInterface.class);
+        startActivity(recTrainingData);
     }
 
 

+ 73 - 0
app/src/main/java/com/motionlogger/sebastianvendt/motionlogger/TouchInterface.java

@@ -1,13 +1,86 @@
 package com.motionlogger.sebastianvendt.motionlogger;
 
+import android.os.Environment;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
 
 public class TouchInterface extends AppCompatActivity {
 
+    private File recordFolder;
+    private File recordFile;
+    private FileWriter recordFileWriter;
+
+    private View.OnTouchListener handleTouch = new View.OnTouchListener() {
+
+        public boolean onTouch(View v, MotionEvent event) {
+            int x = (int) event.getX();
+            int y = (int) event.getY();
+            Log.d("TAG", "touched" + x + " " + y + " ");
+            return true;
+        }
+    };
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_touch_interface);
+        findViewById(android.R.id.content).setOnTouchListener(handleTouch);
+
+        //setup the File I/O
+        /*recordFolder = getPublicAlbumStorageDir("MotionLogger");
+        recordFile = new File(recordFolder, "recordA.txt");
+        try {
+            recordFileWriter = new FileWriter(recordFile);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }*/
+
+        File path = this.getExternalFilesDir(null);
+        recordFile = new File(path, "myFile.txt");
+        FileOutputStream stream = null;
+        try {
+            stream = new FileOutputStream(recordFile);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+
+        try {
+            stream.write("texttextext".getBytes());
+            stream.close();
+        } catch (java.io.IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
+    @Override
+    protected void onDestroy() {
+        try {
+            recordFileWriter.flush();
+            recordFileWriter.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public File getPublicAlbumStorageDir(String albumName) {
+
+        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), albumName);
+
+        if(!file.mkdirs()) {
+            Log.e("TAG", "Directory not created");
+        }
+        return file;
     }
 }

+ 13 - 13
app/src/main/res/layout/activity_main.xml

@@ -7,19 +7,7 @@
     tools:context=".MainActivity">
 
     <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" />
-
-    <Button
-        android:id="@+id/readSensors"
+        android:id="@+id/button_readSensors"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="8dp"
@@ -49,4 +37,16 @@
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
+    <Button
+        android:id="@+id/button_start"
+        android:layout_width="wrap_content"
+        android:layout_height="50dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginEnd="24dp"
+        android:layout_marginRight="24dp"
+        android:onClick="recordTrainingData"
+        android:text="@string/button_start"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/button_readSensors" />
+
 </android.support.constraint.ConstraintLayout>

+ 21 - 3
app/src/main/res/layout/activity_touch_interface.xml

@@ -8,11 +8,29 @@
 
     <ImageView
         android:id="@+id/keyboardLayout"
-        android:layout_width="385dp"
-        android:layout_height="322dp"
+        android:layout_width="wrap_content"
+        android:layout_height="899px"
+        android:scaleType="fitXY"
+        android:visibility="visible"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintStart_toStartOf="parent"
+        app:srcCompat="@drawable/googlekeyboardlayout2"
         tools:srcCompat="@drawable/googlekeyboardlayout2" />
+
+    <EditText
+        android:id="@+id/editText"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="8dp"
+        android:layout_marginLeft="8dp"
+        android:layout_marginTop="100dp"
+        android:layout_marginEnd="8dp"
+        android:layout_marginRight="8dp"
+        android:ems="10"
+        android:inputType="textPersonName"
+        android:text="Name"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
 </android.support.constraint.ConstraintLayout>