Commit 8f2401f8 authored by Loris's avatar Loris
Browse files

position and header ok

parent 7ffabe07
......@@ -33,10 +33,14 @@ public class MainActivity extends AppCompatActivity {
private Button confirmUser;
private Button sendFiles;
private TextInputEditText inputPosition;
private Button confirmPosition;
private PhoneSensors phoneSensors;
private final Logger dataLogger = new Logger(this);
private String appUser;
private String appPosition;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
......@@ -56,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
//find ui elements in main
inputUser = findViewById(R.id.user_field);
confirmUser = findViewById(R.id.confirm_user);
inputPosition = findViewById(R.id.input_position);
confirmPosition = findViewById(R.id.confirm_position);
sendFiles = findViewById(R.id.button_send);
recButton = findViewById(R.id.toggleButton);
txtViewFilename = findViewById(R.id.textViewFilename);
......@@ -87,6 +93,14 @@ public class MainActivity extends AppCompatActivity {
}
});
confirmPosition.setOnClickListener(new CompoundButton.OnClickListener() {
@Override
public void onClick(View v) {
appPosition = inputPosition.getText().toString();
Toast.makeText(MainActivity.this, "Position set to " + appPosition, Toast.LENGTH_LONG).show();
}
});
recButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
......@@ -115,7 +129,12 @@ public class MainActivity extends AppCompatActivity {
} else {
dataLogger.setAndroidUser(appUser);
}
dataLogger.start();
if (appPosition == "") {
dataLogger.setAndroidPosition("dummy");
} else {
dataLogger.setAndroidPosition(appPosition);
}
dataLogger.start(phoneSensors.getAll());
String path = dataLogger.getFile().getAbsolutePath();
txtViewFilename.setText(path.substring(path.length()-17));
}
......
package de.tonifetzer.sensorrecorder.sensors;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.RequiresApi;
......@@ -15,6 +17,7 @@ import co.nstant.in.cbor.CborBuilder;
import co.nstant.in.cbor.CborEncoder;
import co.nstant.in.cbor.CborException;
import co.nstant.in.cbor.builder.ArrayBuilder;
import co.nstant.in.cbor.builder.MapBuilder;
import co.nstant.in.cbor.model.DataItem;
import android.provider.Settings.Secure;
......@@ -29,6 +32,7 @@ public final class Logger {
private StringBuilder sb = new StringBuilder();
private CborBuilder cborBuilder = new CborBuilder();
private ArrayBuilder arrayBuilder;
private MapBuilder mapBuilder;
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private CborEncoder cborEncoder = new CborEncoder(baos);
private File file;
......@@ -37,7 +41,7 @@ public final class Logger {
private String androidUser;
private String androidId;
private String androidPosition;
/** timestamp of logging start. all entries are relative to this one */
private long startTS = 0;
......@@ -46,9 +50,10 @@ public final class Logger {
this.context = context;
}
/** start logging (into RAM) */
/** start logging (into RAM)
* @param all*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public final void start() {
public final void start(List<Sensor> all) {
androidId = Secure.getString(context.getContentResolver(),
Secure.ANDROID_ID);
......@@ -74,6 +79,16 @@ public final class Logger {
arrayBuilder.add(startTS);
arrayBuilder.add(androidId);
arrayBuilder.add(androidUser);
arrayBuilder.add(androidPosition);
mapBuilder = arrayBuilder.addMap();
for (Sensor s: all) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mapBuilder.put(s.getStringType(), s.getType());
}
}
}
}
/** stop logging and flush RAM-data to the flash-chip */
......@@ -171,8 +186,8 @@ public final class Logger {
this.androidUser = u;
}
public String getAndroidUser() {
return androidUser;
public void setAndroidPosition(String u) {
this.androidPosition = u;
}
}
......@@ -64,7 +64,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
// construct sensor details
for (Sensor s: all) {
dumpSensor(sb, s.getType(), s);
dumpSensor(sb, s);
}
// write
fos.write(sb.toString().getBytes());
......@@ -77,9 +77,8 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
}
/** dump all details of the given sensor into the provided stringbuilder */
private void dumpSensor(final StringBuilder sb, final int type, final Sensor sensor) {
private void dumpSensor(final StringBuilder sb, final Sensor sensor) {
sb.append("[Sensor]").append(NL);
sb.append("\tid: ").append(type).append(NL);
if (sensor != null) {
sb.append("\tVendor: ").append(sensor.getVendor()).append(NL);
......@@ -151,4 +150,8 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sensorManager.unregisterListener(this);
}
public List<Sensor> getAll() {
return all;
}
}
......@@ -26,6 +26,12 @@
android:textColor="@android:color/white"
android:textStyle="bold" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="31dp">
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="368dp"
......@@ -103,6 +109,54 @@
android:text="@string/file"
android:textColor="#ffffff" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="50dp">
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="34dp"
android:text="@string/position"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/white"
android:textSize="22sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.design.widget.TextInputEditText
android:id="@+id/input_position"
android:layout_width="276dp"
android:layout_height="wrap_content"
android:hint="@string/type_here"
android:textColor="@android:color/white"
android:textColorHint="@android:color/darker_gray" />
<Button
android:id="@+id/confirm_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -8,4 +8,5 @@
<string name="type_here">type here</string>
<string name="send_files">Send files</string>
<string name="sensor_recorder">Sensor Recorder</string>
<string name="position">Position:</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