Commit 446b489e authored by Loris's avatar Loris
Browse files

working prototype

parent d733834b
......@@ -5,12 +5,14 @@ import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.androidplot.util.Redrawer;
......@@ -38,9 +40,15 @@ public class MainActivity extends AppCompatActivity {
private ToggleButton recButton;
private TextView txtViewFilename;
private TextInputEditText inputUser;
private Button confirmUser;
private Button sendFiles;
private PhoneSensors phoneSensors;
private final Logger dataLogger = new Logger(this);
private String appUser;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -57,10 +65,11 @@ public class MainActivity extends AppCompatActivity {
phoneSensors = new PhoneSensors(this);
//find ui elements in main
inputUser = findViewById(R.id.user_field);
confirmUser = findViewById(R.id.confirm_user);
sendFiles = findViewById(R.id.button_send);
recButton = findViewById(R.id.toggleButton);
// txtViewTimeCounter = findViewById(R.id.textViewTimeCounter);
txtViewFilename = findViewById(R.id.textViewFilename);
// txtViewFilesize = findViewById(R.id.textViewFilesize);
//set the listener
......@@ -74,6 +83,23 @@ public class MainActivity extends AppCompatActivity {
}
});
sendFiles.setOnClickListener(new CompoundButton.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Functionality not implemented yet !",
Toast.LENGTH_SHORT).show();
}
});
confirmUser.setOnClickListener(new CompoundButton.OnClickListener() {
@Override
public void onClick(View v) {
appUser = inputUser.getText().toString();
Toast.makeText(MainActivity.this, "User set to " + appUser, Toast.LENGTH_SHORT).show();
}
});
recButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
......@@ -97,7 +123,11 @@ public class MainActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void startRecording() {
phoneSensors.onResume(this);
dataLogger.setAndroidUser("dummy");
if (appUser == "") {
dataLogger.setAndroidUser("dummy");
} else {
dataLogger.setAndroidUser(appUser);
}
dataLogger.start();
String path = dataLogger.getFile().getAbsolutePath();
txtViewFilename.setText(path.substring(path.length()-17));
......
......@@ -18,7 +18,9 @@ public class Entry implements Serializable {
private float x;
private float y;
private float z;
private int prediction;
public Entry(long ts, float x, float y, float z, int sId) {
this.ts = ts;
this.sensorId = sId;
......
......@@ -27,7 +27,7 @@ public final class Logger {
private static final int FLUSH_LIMIT = 2*1024*1024;
private StringBuilder sb = new StringBuilder();
private final CborBuilder cborBuilder = new CborBuilder();
private CborBuilder cborBuilder = new CborBuilder();
private ArrayBuilder arrayBuilder;
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private CborEncoder cborEncoder = new CborEncoder(baos);
......@@ -38,9 +38,6 @@ public final class Logger {
private String androidUser;
private String androidId;
private int entries = 0;
private int sizeCurrent = 0;
private int sizeTotal = 0;
/** timestamp of logging start. all entries are relative to this one */
private long startTS = 0;
......@@ -57,15 +54,11 @@ public final class Logger {
Secure.ANDROID_ID);
// start empty
sb.setLength(0);
entries = 0;
sizeTotal = 0;
sizeCurrent = 0;
// starting timestamp
startTS = System.currentTimeMillis();
// open the output-file immeditaly (to get permission errors)
// open the output-file immediately (to get permission errors)
// but do NOT yet write anything to the file
final DataFolder folder = new DataFolder(context, "sensorOutFiles");
file = new File(folder.getFolder(), startTS + ".cbor");
......@@ -96,30 +89,6 @@ public final class Logger {
return file;
}
public int getCurrentSize() {return sizeCurrent;}
public int getTotalSize() {return sizeTotal;}
public int getNumEntries() {return entries;}
/** add a new CSV entry for the given sensor number to the internal buffer */
// public final void addCSV(final SensorType sensorNr, final String csv) throws CborException {
// synchronized (this) {
// final long relTS = System.currentTimeMillis() - startTS;
// sb.append(relTS); // relative timestamp (uses less space)
// sb.append(';');
// sb.append(sensorNr.id());
// sb.append(';');
// sb.append(csv);
// Log.d("TAG", "addCSV: " + csv);
// sb.append('\n');
// ++entries;
// sizeTotal += csv.length() + 10; // approx!
// sizeCurrent = sb.length();
// if (sb.length() > FLUSH_LIMIT) {flush(false);}
// }
//
// debug();
// }
public final void addEntry(final Entry entry) {
synchronized (this) {
final long relTS = entry.getTs() - startTS;
......@@ -131,8 +100,6 @@ public final class Logger {
.add(entry.getSensorId())
.end();
}
++entries;
debug();
}
......@@ -166,7 +133,7 @@ public final class Logger {
Log.d("baos", "flush: " + data.toString());
// data = sb.toString().getBytes(); // fetch data to write
// sb.setLength(0); // reset the buffer
sizeCurrent = 0;
cborBuilder = new CborBuilder();
}
// write
......@@ -195,9 +162,9 @@ public final class Logger {
int cnt = 0;
private final void debug() {
if (++cnt % 1000 == 0) {
Log.d("buffer", "size: " + sizeCurrent);
}
// if (++cnt % 1000 == 0) {
// Log.d("buffer", "size: " + sizeCurrent);
// }
}
public void setAndroidUser(String u) {
......
......@@ -32,17 +32,14 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
/** ctor */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public PhoneSensors(final Activity act){
// fetch the sensor manager from the activity
sensorManager = (SensorManager) act.getSystemService(Context.SENSOR_SERVICE);
// try to get each sensor
acc = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
lin_acc = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
gyro = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
// dump sensor-vendor info to file
dumpVendors(act);
}
private final char NL = '\n';
......@@ -118,9 +115,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
e.printStackTrace();
}
}
}
else if(event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
// inform listeners
if (listener != null){
......@@ -131,9 +126,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
e.printStackTrace();
}
}
}
else if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
// inform listeners
if (listener != null){
......@@ -144,9 +137,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
e.printStackTrace();
}
}
}
}
@Override
......@@ -156,8 +147,8 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
@Override
public void onResume(final Activity act) {
// attach as listener to each of the available sensors
// for now we just user delay fastest, but we'll adjust that.
registerIfPresent(acc, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(gyro, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(lin_acc, SensorManager.SENSOR_DELAY_FASTEST);
......@@ -175,10 +166,8 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
@Override
public void onPause(final Activity act) {
// detach from all events
sensorManager.unregisterListener(this);
}
}
......@@ -5,81 +5,104 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333"
android:clickable="true"
android:keepScreenOn="true"
tools:context=".MainActivity">
tools:context=".MainActivity"
android:focusable="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
android:layout_height="wrap_content"
android:text="@string/sensor_recorder"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Username:"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="368dp"
android:layout_height="152dp">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@android:string/ok" />
</LinearLayout>
android:orientation="vertical">
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/username"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="82dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="83dp"
android:background="@drawable/btnstartcolor"
android:padding="10dp"
android:text="@string/togglebutton"
android:textOff="@string/start_recording"
android:textOn="@string/stop_recording"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.694" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewFilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:text="@string/file"
android:textColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<android.support.design.widget.TextInputEditText
android:id="@+id/user_field"
android:layout_width="269dp"
android:layout_height="56dp"
android:hint="@string/type_here"
android:lineSpacingExtra="12sp"
android:textColor="@android:color/white"
android:textColorHint="@android:color/darker_gray" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="type here"
android:lineSpacingExtra="12sp"
android:textColor="@android:color/white"
android:textColorHint="@android:color/darker_gray"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
tools:layout_editor_absoluteX="0dp" />
<Button
android:id="@+id/confirm_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
</LinearLayout>
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:text="@string/send_files" />
</LinearLayout>
</android.support.design.widget.TextInputLayout>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="82dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="83dp"
android:background="@drawable/btnstartcolor"
android:padding="10dp"
android:text="@string/togglebutton"
android:textOff="@string/start_recording"
android:textOn="@string/stop_recording" />
<TextView
android:id="@+id/textViewFilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:text="@string/file"
android:textColor="#ffffff" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -4,4 +4,8 @@
<string name="togglebutton">ToggleButton</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</string>
<string name="username">Username:</string>
<string name="type_here">type here</string>
<string name="send_files">Send files</string>
<string name="sensor_recorder">Sensor Recorder</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment