Commit d733834b authored by Loris's avatar Loris
Browse files

add messed up ui

parent ed75569d
......@@ -16,6 +16,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '29.0.2'
}
dependencies {
......@@ -23,6 +28,7 @@ dependencies {
implementation 'co.nstant.in:cbor:0.9'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
......
......@@ -3,6 +3,8 @@ package de.tonifetzer.sensorrecorder;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
......@@ -34,17 +36,12 @@ public class MainActivity extends AppCompatActivity {
//ui in main layout
private View mainView;
private ToggleButton recButton;
private Button plotButton;
private TextView txtViewTimeCounter;
private TextView txtViewFilename;
private TextView txtViewFilesize;
private boolean isMainView = true;
private PhoneSensors phoneSensors;
private final Logger dataLogger = new Logger(this);
private int loadCounter = 0;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -63,7 +60,7 @@ public class MainActivity extends AppCompatActivity {
recButton = findViewById(R.id.toggleButton);
// txtViewTimeCounter = findViewById(R.id.textViewTimeCounter);
txtViewFilename = findViewById(R.id.textViewFilename);
txtViewFilesize = findViewById(R.id.textViewFilesize);
// txtViewFilesize = findViewById(R.id.textViewFilesize);
//set the listener
......@@ -79,6 +76,7 @@ public class MainActivity extends AppCompatActivity {
recButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
buttonView.setBackgroundColor(Color.parseColor("#FFCC0000"));
......@@ -96,9 +94,10 @@ public class MainActivity extends AppCompatActivity {
});
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void startRecording() {
phoneSensors.onResume(this);
loadCounter = 0;
dataLogger.setAndroidUser("dummy");
dataLogger.start();
String path = dataLogger.getFile().getAbsolutePath();
txtViewFilename.setText(path.substring(path.length()-17));
......@@ -114,21 +113,7 @@ public class MainActivity extends AppCompatActivity {
dataLogger.addEntry(entry);
runOnUiThread(new Runnable() {
@Override public void run() {
// dump buffer stats every x entries
if (++loadCounter % 250 == 0) {
//set filesize and buffer dump
final int kbPerMin = (int) (dataLogger.getTotalSize() / 1024 * 1000 * 60 / (System.currentTimeMillis() - dataLogger.getStartTS()));
txtViewFilesize.setText( (dataLogger.getCurrentSize() / 1024) + "kb, " + kbPerMin + "kb/min");
//set time (of course, this is not perfectly accurate, however for this purpose its okay)
long minutes = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - dataLogger.getStartTS());
long seconds = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - dataLogger.getStartTS());
}
}
@Override public void run() { }
});
}
......
......@@ -3,6 +3,7 @@ package de.tonifetzer.sensorrecorder.sensors;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.RequiresApi;
import android.util.Log;
import java.io.File;
......@@ -16,6 +17,7 @@ public class DataFolder {
private Context context;
private File folder;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public DataFolder(Context context, String folderName){
this.context = context;
......
......@@ -2,6 +2,8 @@ package de.tonifetzer.sensorrecorder.sensors;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import java.io.ByteArrayOutputStream;
......@@ -25,15 +27,15 @@ public final class Logger {
private static final int FLUSH_LIMIT = 2*1024*1024;
private StringBuilder sb = new StringBuilder();
final CborBuilder cborBuilder = new CborBuilder();
ArrayBuilder arrayBuilder;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CborEncoder cborEncoder = new CborEncoder(baos);
CborEncoder encoder;
private final CborBuilder cborBuilder = new CborBuilder();
private ArrayBuilder arrayBuilder;
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private CborEncoder cborEncoder = new CborEncoder(baos);
private File file;
private FileOutputStream fos;
private Context context;
private String androidUser;
private String androidId;
private int entries = 0;
......@@ -48,6 +50,7 @@ public final class Logger {
}
/** start logging (into RAM) */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public final void start() {
androidId = Secure.getString(context.getContentResolver(),
......@@ -59,7 +62,6 @@ public final class Logger {
sizeTotal = 0;
sizeCurrent = 0;
// starting timestamp
startTS = System.currentTimeMillis();
......@@ -78,6 +80,7 @@ public final class Logger {
arrayBuilder = cborBuilder.addArray();
arrayBuilder.add(startTS);
arrayBuilder.add(androidId);
arrayBuilder.add(androidUser);
}
/** stop logging and flush RAM-data to the flash-chip */
......@@ -95,28 +98,27 @@ public final class Logger {
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 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) {
......@@ -129,10 +131,10 @@ public final class Logger {
.add(entry.getSensorId())
.end();
}
}
++entries;
debug();
}
/** helper method for exception-less writing. DO NOT CALL DIRECTLY! */
private final void _write(final byte[] data) {
......@@ -151,21 +153,19 @@ public final class Logger {
_write(data[0]);
return null;
}
};
}
/** flush current buffer-contents to disk */
private final void flush(boolean sync) throws CborException {
// fetch current buffer contents to write and hereafter empty the buffer
// this action MUST be atomic, just like the add-method
byte[] data = null;
synchronized (this) {
//TODO data = Byte
cborEncoder.encode(cborBuilder.build());
data = baos.toByteArray();
Log.d("baos", "flush: " + data.toString());
// data = sb.toString().getBytes(); // fetch data to write
sb.setLength(0); // reset the buffer
// sb.setLength(0); // reset the buffer
sizeCurrent = 0;
}
......@@ -200,4 +200,12 @@ public final class Logger {
}
}
public void setAndroidUser(String u) {
this.androidUser = u;
}
public String getAndroidUser() {
return androidUser;
}
}
......@@ -12,12 +12,12 @@ public abstract class MySensor {
/** listen for sensor events */
public interface SensorListener {
public void onData(final String csv);
void onData(final String csv);
/** received data from the given sensor */
public void onData(final SensorType id, final String csv) throws CborException;
void onData(final SensorType id, final String csv) throws CborException;
public void onData(final Entry entry) throws CborException;
void onData(final Entry entry) throws CborException;
}
......
......@@ -7,6 +7,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import java.io.File;
......@@ -29,7 +30,8 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
/** ctor */
public PhoneSensors(final Activity act){
@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);
......@@ -46,6 +48,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
private final char NL = '\n';
/** Write Vendors to file */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void dumpVendors(final Activity act) {
final DataFolder folder = new DataFolder(act, "sensorOutFiles");
......
......@@ -8,6 +8,36 @@
android:keepScreenOn="true"
tools:context=".MainActivity">
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<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" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok" />
</LinearLayout>
</android.support.design.widget.TextInputLayout>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
......@@ -20,13 +50,15 @@
android:layout_marginBottom="83dp"
android:background="@drawable/btnstartcolor"
android:padding="10dp"
android:text="ToggleButton"
android:textOff="Start Recording"
android:textOn="Stop Recording"
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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.694" />
<TextView
android:id="@+id/textViewFilename"
......@@ -34,20 +66,20 @@
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:text="File: "
android:text="@string/file"
android:textColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toggleButton" />
<TextView
android:id="@+id/textViewFilesize"
android:layout_width="wrap_content"
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:text="Size: "
android:textColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewFilename" />
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" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<resources>
<string name="app_name">Sensor Recorder</string>
<string name="file">File:</string>
<string name="togglebutton">ToggleButton</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</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