diff --git a/app/Locabean/res/layout/activity_node.xml b/app/Locabean/res/layout/activity_node.xml
index 760c051..46f64f8 100644
--- a/app/Locabean/res/layout/activity_node.xml
+++ b/app/Locabean/res/layout/activity_node.xml
@@ -9,16 +9,6 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".NodeActivity" >
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/Locabean/res/layout/setup_dialog.xml b/app/Locabean/res/layout/setup_dialog.xml
new file mode 100644
index 0000000..664a4cf
--- /dev/null
+++ b/app/Locabean/res/layout/setup_dialog.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/Locabean/src/com/locaudio/api/AcquisitionThread.java b/app/Locabean/src/com/locaudio/api/AcquisitionThread.java
new file mode 100644
index 0000000..553c8b7
--- /dev/null
+++ b/app/Locabean/src/com/locaudio/api/AcquisitionThread.java
@@ -0,0 +1,44 @@
+package com.locaudio.api;
+
+import android.content.Context;
+import android.os.Looper;
+
+import com.locaudio.functional.UIFunction;
+import com.locaudio.io.WaveWriter;
+import com.musicg.wave.Wave;
+
+public class AcquisitionThread extends Thread {
+
+ private static final int RECORD_LENGTH = 5;
+
+ private Locaudio locaudio;
+ private UIFunction postCallback;
+ private Context context;
+ private boolean shouldContinue;
+
+ public AcquisitionThread(Locaudio locaudio, Context context,
+ UIFunction postCallback) {
+ //super();
+ this.locaudio = locaudio;
+ this.context = context;
+ this.postCallback = postCallback;
+ this.shouldContinue = true;
+ }
+
+ public void kill() {
+ this.shouldContinue = false;
+ }
+
+ @Override
+ public void run() {
+ Looper.prepare();
+ while (this.shouldContinue) {
+
+ Wave wave = WaveWriter.record(RECORD_LENGTH);
+
+ locaudio.notifyEvent(this.context, wave, this.postCallback);
+
+ }
+ }
+
+}
diff --git a/app/Locabean/src/com/locaudio/api/Locaudio.java b/app/Locabean/src/com/locaudio/api/Locaudio.java
index c37703d..0b412a4 100644
--- a/app/Locabean/src/com/locaudio/api/Locaudio.java
+++ b/app/Locabean/src/com/locaudio/api/Locaudio.java
@@ -3,7 +3,7 @@
import android.content.Context;
import com.locaudio.functional.Function;
-import com.locaudio.io.WaveWriter;
+import com.locaudio.functional.UIFunction;
import com.locaudio.net.*;
import com.musicg.wave.Wave;
@@ -83,7 +83,7 @@ public void runOnceReceivedResponse(String[] response) {
}
public AsyncPostRequest notifyEvent(Context context,
- final Function callback) {
+ Wave wave, final Function callback) {
AsyncPostRequest apr = new AsyncPostRequest(
NotifyResponse.class, NOTIFY_ROUTE) {
@@ -96,7 +96,6 @@ public void runOnceReceivedResponse(NotifyResponse response) {
};
- Wave wave = WaveWriter.getWave();
apr.setPostForm(NotifyForm.getDefaultNotifyForm(wave, context));
apr.execute(this);
@@ -136,4 +135,10 @@ public void runOnceReceivedResponse(NotifyResponse response) {
return apr.getResponse(this);
}
+
+ public AcquisitionThread getAcquisitionThread(Context context,
+ UIFunction callback) {
+ return new AcquisitionThread(this, context, callback);
+
+ }
}
diff --git a/app/Locabean/src/com/locaudio/io/WaveWriter.java b/app/Locabean/src/com/locaudio/io/WaveWriter.java
index b5ed99c..baf1e7e 100644
--- a/app/Locabean/src/com/locaudio/io/WaveWriter.java
+++ b/app/Locabean/src/com/locaudio/io/WaveWriter.java
@@ -210,7 +210,7 @@ public static AudioRecord getAudioRecord() {
RECORDER_AUDIO_ENCODING, BUFFER_SIZE);
}
- public static Wave getWave() {
+ private static Wave getWave() {
return new Wave(getFilename());
}
@@ -228,7 +228,7 @@ public static void startRecording() {
recordingThread.start();
}
- public static void stopRecording() {
+ public static Wave stopRecording() {
if (null != recorder) {
isRecording = false;
@@ -246,6 +246,22 @@ public static void stopRecording() {
copyWaveFile(getTempFilename(), getFilename());
deleteTempFile();
+ return getWave();
+ }
+
+ public static Wave record(int seconds) {
+
+ try {
+ startRecording();
+ Thread.sleep(seconds * 1000);
+ stopRecording();
+ return getWave();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ stopRecording();
+ return null;
+ }
+
}
}
diff --git a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java
index ad954b2..84089c8 100644
--- a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java
+++ b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java
@@ -2,99 +2,61 @@
import android.app.Activity;
import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
import android.widget.TextView;
-import com.musicg.wave.Wave;
-
import com.locaudio.functional.UIFunction;
-import com.locaudio.io.WaveWriter;
-import com.locaudio.signal.WaveProcessing;
+import com.locaudio.api.AcquisitionThread;
import com.locaudio.api.Locaudio;
import com.locaudio.api.NotifyResponse;
public class NodeActivity extends Activity {
- private TextView nameTextView = null;
- private TextView confidenceTextView = null;
- private TextView splTextView = null;
+ private TextView nameTextView;
+ private TextView confidenceTextView;
- private Locaudio locaudio = null;
+ private Locaudio locaudio;
- private static final String IP_ADDRESS = "192.168.1.9";
+ private static final String IP_ADDRESS = "138.251.207.84";
private static final int PORT = 8000;
+ private AcquisitionThread acquisitionThread;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_node);
+
+ setupTextViews();
+ setupLocaudio();
+ }
- setButtonHandlers();
- enableButtons(false);
+ @Override
+ public void onStop() {
+ super.onStop();
+ acquisitionThread.kill();
+ }
+ private void setupTextViews() {
nameTextView = (TextView) findViewById(R.id.nameTextView);
confidenceTextView = (TextView) findViewById(R.id.confidenceTextView);
- splTextView = (TextView) findViewById(R.id.splTextView);
+ }
+ private void setupLocaudio() {
locaudio = new Locaudio(IP_ADDRESS, PORT);
- }
- private void setButtonHandlers() {
- ((Button) findViewById(R.id.btnStart))
- .setOnClickListener(btnStartClick);
- ((Button) findViewById(R.id.btnStop)).setOnClickListener(btnStopClick);
- ((Button) findViewById(R.id.btnSend)).setOnClickListener(btnSendClick);
- }
+ acquisitionThread = locaudio.getAcquisitionThread(
+ getApplicationContext(), new UIFunction(this) {
- private void enableButton(int id, boolean isEnable) {
- ((Button) findViewById(id)).setEnabled(isEnable);
- }
+ @Override
+ public Void body(NotifyResponse nr) {
+ nameTextView.setText(nr.name);
+ confidenceTextView.setText("" + nr.confidence);
- private void enableButtons(boolean isRecording) {
- enableButton(R.id.btnStart, !isRecording);
- enableButton(R.id.btnStop, isRecording);
- }
+ return null;
+ }
+
+ });
- private View.OnClickListener btnStartClick = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- System.out.println("Start Recording");
- enableButtons(true);
-
- WaveWriter.startRecording();
- }
- };
-
- private View.OnClickListener btnStopClick = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- System.out.println("Stop Recording");
- enableButtons(false);
- WaveWriter.stopRecording();
-
- Wave wave = WaveWriter.getWave();
- splTextView.setText(""
- + WaveProcessing.determineAverageSoundPressureLevel(wave));
- }
- };
-
- private View.OnClickListener btnSendClick = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- locaudio.notifyEvent(getApplicationContext(),
- new UIFunction(NodeActivity.this) {
-
- @Override
- public Void body(NotifyResponse nr) {
- nameTextView.setText(nr.name);
- confidenceTextView.setText("" + nr.confidence);
-
- return null;
- }
-
- });
- }
- };
+ acquisitionThread.start();
+ }
}