Skip to content

Commit

Permalink
Added individual onClickListeners for each of the buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 21, 2014
1 parent 873a2fd commit 2baa571
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions app/Locabean/src/com/locaudio/locabean/NodeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public void onCreate(Bundle savedInstanceState) {
}

private void setButtonHandlers() {
((Button) findViewById(R.id.btnStart)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnStop)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnSend)).setOnClickListener(btnClick);
((Button) findViewById(R.id.btnStart))
.setOnClickListener(btnStartClick);
((Button) findViewById(R.id.btnStop)).setOnClickListener(btnStopClick);
((Button) findViewById(R.id.btnSend)).setOnClickListener(btnSendClick);
}

private void enableButton(int id, boolean isEnable) {
Expand Down Expand Up @@ -101,52 +102,48 @@ private void stopRecording() {
WaveWriter.deleteTempFile();
}

private View.OnClickListener btnClick = new View.OnClickListener() {
private View.OnClickListener btnStartClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart: {
System.out.println("Start Recording");
enableButtons(true);
System.out.println("Start Recording");
enableButtons(true);

startRecording();
startRecording();
}
};

break;
}
case R.id.btnStop: {
System.out.println("Stop Recording");
enableButtons(false);
stopRecording();
Wave wave = new Wave(WaveWriter.getFilename());
splTextView.setText(""
+ WaveProcessing
.determineAverageSoundPressureLevel(wave));

break;
}
case R.id.btnSend: {

Wave wave = new Wave(WaveWriter.getFilename());
NotifyForm postForm = new NotifyForm();
postForm.setFingerprint(wave.getFingerprint());
postForm.setSoundPressureLevel(100);
postForm.setTimestamp(10);
postForm.setX(1);
postForm.setY(0);

locaudio.notifyEvent(postForm, new UIFunction<NotifyResponse>(
self) {

@Override
public void runUI(NotifyResponse nr) {
nameTextView.setText(nr.name);
confidenceTextView.setText("" + nr.confidence);
}
});

break;
}
}
private View.OnClickListener btnStopClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Stop Recording");
enableButtons(false);
stopRecording();
Wave wave = new Wave(WaveWriter.getFilename());
splTextView.setText(""
+ WaveProcessing.determineAverageSoundPressureLevel(wave));
}
};

private View.OnClickListener btnSendClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Wave wave = new Wave(WaveWriter.getFilename());
NotifyForm postForm = new NotifyForm();
postForm.setFingerprint(wave.getFingerprint());
postForm.setSoundPressureLevel(100);
postForm.setTimestamp(10);
postForm.setX(1);
postForm.setY(0);

locaudio.notifyEvent(postForm,
new UIFunction<NotifyResponse>(self) {

@Override
public void runUI(NotifyResponse nr) {
nameTextView.setText(nr.name);
confidenceTextView.setText("" + nr.confidence);
}
});
}
};
}

0 comments on commit 2baa571

Please sign in to comment.