Skip to content

Commit

Permalink
Added Requests.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 19, 2014
1 parent 899a6fb commit 02e8172
Show file tree
Hide file tree
Showing 55 changed files with 101 additions and 5,252 deletions.
2 changes: 1 addition & 1 deletion app/Locabean/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Expand Down
Binary file added app/Locabean/libs/musicg-1.4.2.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.locaudio.locabean;
package com.locaudio.io;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -8,6 +8,7 @@

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Environment;

public class WaveWriter {
Expand All @@ -26,7 +27,7 @@ public class WaveWriter {
protected static final int BUFFER_SIZE = AudioRecord.getMinBufferSize(
RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING);

protected static void writeWaveFileHeader(FileOutputStream out,
public static void writeWaveFileHeader(FileOutputStream out,
long totalAudioLen, long totalDataLen, long longSampleRate,
int channels, long byteRate, int bitsPerSample) throws IOException {

Expand Down Expand Up @@ -80,7 +81,7 @@ protected static void writeWaveFileHeader(FileOutputStream out,
out.write(header, 0, 44);
}

protected static void copyWaveFile(String inFilename, String outFilename) {
public static void copyWaveFile(String inFilename, String outFilename) {
FileInputStream in = null;
FileOutputStream out = null;
long totalAudioLen = 0;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected static void copyWaveFile(String inFilename, String outFilename) {
}
}

protected static String getFilename() {
public static String getFilename() {
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath, AUDIO_RECORDER_FOLDER);

Expand All @@ -126,7 +127,7 @@ protected static String getFilename() {
return (file.getAbsolutePath() + "/" + AUDIO_RECORDER_FILENAME + AUDIO_RECORDER_FILE_EXT_WAV);
}

protected static String getTempFilename() {
public static String getTempFilename() {
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath, AUDIO_RECORDER_FOLDER);

Expand All @@ -142,13 +143,13 @@ protected static String getTempFilename() {
return (file.getAbsolutePath() + "/" + AUDIO_RECORDER_TEMP_FILE);
}

protected static void deleteTempFile() {
public static void deleteTempFile() {
File file = new File(getTempFilename());

file.delete();
}

protected static void writeAudioDataToFile(AudioRecord recorder,
public static void writeAudioDataToFile(AudioRecord recorder,
boolean isRecording) {
byte data[] = new byte[WaveWriter.BUFFER_SIZE];
String filename = getTempFilename();
Expand Down Expand Up @@ -183,4 +184,10 @@ protected static void writeAudioDataToFile(AudioRecord recorder,
}
}
}

public static AudioRecord getAudioRecord() {
return new AudioRecord(MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING, BUFFER_SIZE);
}
}
7 changes: 3 additions & 4 deletions app/Locabean/src/com/locaudio/locabean/NodeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import android.app.Activity;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
Expand All @@ -13,6 +12,8 @@

import com.musicg.wave.Wave;

import com.locaudio.io.WaveWriter;

public class NodeActivity extends Activity {

private AudioRecord recorder = null;
Expand Down Expand Up @@ -46,9 +47,7 @@ private void enableButtons(boolean isRecording) {
}

private void startRecording() {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
WaveWriter.RECORDER_SAMPLERATE, WaveWriter.RECORDER_CHANNELS,
WaveWriter.RECORDER_AUDIO_ENCODING, WaveWriter.BUFFER_SIZE);
recorder = WaveWriter.getAudioRecord();

int i = recorder.getState();
if (i == 1)
Expand Down
83 changes: 83 additions & 0 deletions app/Locabean/src/com/locaudio/net/Requests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.locaudio.net;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

public class Requests {

private String ipAddress = null;
private int port = 80;
private String url = null;
private static final int CHAR_BUFFER_SIZE = 256;

public Requests() {
this.ipAddress = "localhost";
this.port = 8000;
this.url = this.ipAddress + ":" + this.port;
}

public Requests(String ipAddress, int port) {
this.ipAddress = ipAddress;
this.port = port;
this.url = this.ipAddress + ":" + this.port;
}

public JSONObject post(Map<String, String> paramMap)
throws ClientProtocolException, IOException, JSONException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(this.url);

// Request parameters and other properties.
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();

Iterator<Entry<String, String>> it = paramMap.entrySet().iterator();
Entry<String, String> pair = null;

while (it.hasNext()) {
pair = (Entry<String, String>) it.next();
params.add(new BasicNameValuePair(pair.getKey(), pair.getValue()));
}

httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

// Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
InputStreamReader reader = new InputStreamReader(
entity.getContent());
try {
CharBuffer target = CharBuffer.allocate(CHAR_BUFFER_SIZE);
reader.read(target);
return new JSONObject(target.toString());
} finally {
reader.close();
}
} else {
return new JSONObject();
}
}

public JSONObject get(String... params) {
return new JSONObject();
}
}
57 changes: 0 additions & 57 deletions app/Locabean/src/com/musicg/api/ClapApi.java

This file was deleted.

Loading

0 comments on commit 02e8172

Please sign in to comment.