From 565894f6614a83381f3fc3979c7e1d52c02ca87b Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 23 May 2012 17:14:06 -0700 Subject: [PATCH] Localize some strings, clean up the code --- .../src/com/todoroo/aacenc/AACRecorder.java | 29 +++++++------------ .../astrid/files/AACRecordingActivity.java | 8 ++--- astrid/res/values/strings-premium.xml | 2 ++ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/android-aac-enc/src/com/todoroo/aacenc/AACRecorder.java b/android-aac-enc/src/com/todoroo/aacenc/AACRecorder.java index 6a91caca8..b7ac2a27d 100644 --- a/android-aac-enc/src/com/todoroo/aacenc/AACRecorder.java +++ b/android-aac-enc/src/com/todoroo/aacenc/AACRecorder.java @@ -8,12 +8,19 @@ import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder.AudioSource; +/** + * This class combines an Android AudioRecord and our own AACEncoder + * to directly record an AAC audio file from the mic. Users should call + * startRecording() and stopRecording() in sequence, and then listen + * for the encodingFinished() callback to perform final actions like + * converting to M4A format. + * @author Sam + * + */ public class AACRecorder { private AudioRecord audioRecord; private AACEncoder encoder; - private Context context; - private String tempFile; private boolean recording; private AACRecorderCallbacks listener; @@ -34,7 +41,6 @@ public class AACRecorder { int bytesRead = 0; while(recording) { bytesRead = audioRecord.read(readBuffer, 0, readBuffer.length); - System.err.println("Bytes read: " + bytesRead); try { baos.write(readBuffer); } catch (IOException e) { @@ -50,7 +56,7 @@ public class AACRecorder { }; - public AACRecorder(Context context) { + public AACRecorder() { encoder = new AACEncoder(); } @@ -58,7 +64,6 @@ public class AACRecorder { if (recording) return; - this.tempFile = tempFile; audioRecord = new AudioRecord(AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE); @@ -83,7 +88,6 @@ public class AACRecorder { public synchronized void finishRecording() { recording = false; audioRecord.release(); - System.err.println("Uninit"); encoder.uninit(); if (listener != null) listener.encodingFinished(); @@ -93,17 +97,4 @@ public class AACRecorder { this.listener = listener; } - public synchronized boolean convert(String outFile) { - if (recording || tempFile == null) - return false; - - try { - new AACToM4A().convert(context, tempFile, outFile); - tempFile = null; - return true; - } catch (IOException e) { - return false; - } - } - } diff --git a/astrid/plugin-src/com/todoroo/astrid/files/AACRecordingActivity.java b/astrid/plugin-src/com/todoroo/astrid/files/AACRecordingActivity.java index 03672cc1b..97fa0a0d3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/files/AACRecordingActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/files/AACRecordingActivity.java @@ -42,7 +42,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac tempFile = getIntent().getStringExtra(EXTRA_TEMP_FILE); taskId = getIntent().getLongExtra(EXTRA_TASK_ID, 0L); - recorder = new AACRecorder(this); + recorder = new AACRecorder(); recorder.setListener(this); recorder.startRecording(tempFile); } @@ -71,15 +71,15 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac speechBubble.setText(R.string.audio_speak_now); } - @SuppressWarnings("nls") private void stopRecording() { recorder.stopRecording(); - pd = DialogUtilities.progressDialog(this, "Encoding..."); + pd = DialogUtilities.progressDialog(this, getString(R.string.audio_err_encoding)); pd.show(); } @SuppressWarnings("nls") + @Override public void encodingFinished() { try { StringBuilder filePathBuilder = new StringBuilder(); @@ -99,7 +99,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac finish(); } catch (IOException e) { e.printStackTrace(); - Toast.makeText(this, "Error :(", Toast.LENGTH_LONG); + Toast.makeText(this, R.string.audio_err_encoding, Toast.LENGTH_LONG); } pd.dismiss(); } diff --git a/astrid/res/values/strings-premium.xml b/astrid/res/values/strings-premium.xml index 3529abb2b..456bbdf62 100644 --- a/astrid/res/values/strings-premium.xml +++ b/astrid/res/values/strings-premium.xml @@ -12,4 +12,6 @@ Recording Audio Stop Recording Speak Now! + Encoding... + Error encoding audio