diff --git a/README.md b/README.md index be5570d..0bc5663 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # AndroidAudioRecorder -> A pretty way to record .WAV audio on Android +> A pretty way to record .wav audio on Android ![Screenshots](https://raw.githubusercontent.com/adrielcafe/AndroidAudioRecorder/master/screenshots.png) @@ -57,7 +57,7 @@ dependencies { ## TODO - [X] Record audio -- [X] Tint images to black when background color is too bright +- [X] Tint images to black when background color is too bright (thanks to [@prakh25](https://github.com/prakh25)) - [X] Wave visualization based on this [player concept](https://dribbble.com/shots/2369760-Player-Concept) - [ ] Pause audio - [ ] Play recorded audio diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9163642..2a54c93 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -5,5 +5,4 @@ #FF4081 #039BE5 - \ No newline at end of file diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java index 7005433..4949516 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java @@ -29,16 +29,18 @@ public class AudioRecorderActivity extends AppCompatActivity implements PullTran private VisualizerHandler visualizerHandler; private Timer timer; - private MenuItem selectMenuItem; + private MenuItem saveMenuItem; private String filePath; - private int secondsRecorded; private int color; + private int secondsRecorded; private boolean isRecording; private RelativeLayout contentLayout; private GLAudioVisualizationView audioVisualizationView; private TextView timerView; + private ImageButton restartView; private ImageButton recordView; + private ImageButton playView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -61,10 +63,10 @@ protected void onCreate(Bundle savedInstanceState) { audioVisualizationView = new GLAudioVisualizationView.Builder(this) .setLayersCount(1) - .setWavesCount(5) + .setWavesCount(6) .setWavesHeight(R.dimen.wave_height) .setWavesFooterHeight(R.dimen.footer_height) - .setBubblesPerLayer(16) + .setBubblesPerLayer(20) .setBubblesSize(R.dimen.bubble_size) .setBubblesRandomizeSize(true) .setBackgroundColor(Util.getDarkerColor(color)) @@ -73,16 +75,22 @@ protected void onCreate(Bundle savedInstanceState) { contentLayout = (RelativeLayout) findViewById(R.id.content); timerView = (TextView) findViewById(R.id.timer); + restartView = (ImageButton) findViewById(R.id.restart); recordView = (ImageButton) findViewById(R.id.record); + playView = (ImageButton) findViewById(R.id.play); contentLayout.setBackgroundColor(Util.getDarkerColor(color)); contentLayout.addView(audioVisualizationView, 0); + restartView.setVisibility(View.INVISIBLE); + playView.setVisibility(View.INVISIBLE); visualizerHandler = new VisualizerHandler(); audioVisualizationView.linkTo(visualizerHandler); if(Util.isBrightColor(color)) { + restartView.setColorFilter(Color.BLACK); recordView.setColorFilter(Color.BLACK); + playView.setColorFilter(Color.BLACK); timerView.setTextColor(Color.BLACK); getResources().getDrawable(R.drawable.ic_clear) .setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); @@ -99,7 +107,7 @@ public void onResume() { @Override protected void onPause() { - stopRecoding(); + stopRecording(); audioVisualizationView.onPause(); super.onPause(); } @@ -114,8 +122,8 @@ protected void onDestroy() { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.audio_recorder, menu); - selectMenuItem = menu.findItem(R.id.action_select); - selectMenuItem.setIcon(getResources().getDrawable(R.drawable.ic_check)); + saveMenuItem = menu.findItem(R.id.action_save); + saveMenuItem.setIcon(getResources().getDrawable(R.drawable.ic_check)); return super.onCreateOptionsMenu(menu); } @@ -124,7 +132,7 @@ public boolean onOptionsItemSelected(MenuItem item) { int i = item.getItemId(); if (i == android.R.id.home) { onBackPressed(); - } else if (i == R.id.action_select) { + } else if (i == R.id.action_save) { selectAudio(); } return super.onOptionsItemSelected(item); @@ -136,22 +144,38 @@ public void onAudioChunkPulled(AudioChunk audioChunk) { visualizerHandler.onDataReceived(amplitude); } - public void toggleRecord(View v) { + public void toggleRecording(View v) { if (isRecording) { - stopRecoding(); + stopRecording(); } else { - startRecoding(); + startRecording(); } } + public void restartRecording(View v){ + stopRecording(); + saveMenuItem.setVisible(false); + restartView.setVisibility(View.INVISIBLE); + playView.setVisibility(View.INVISIBLE); + recordView.setImageResource(R.drawable.ic_rec); + timerView.setText("00:00:00"); + secondsRecorded = 0; + } + + public void playRecording(View v){ + // TODO play recorded audio + } + private void selectAudio() { setResult(RESULT_OK); finish(); } - private void startRecoding() { + private void startRecording() { isRecording = true; - selectMenuItem.setVisible(false); + saveMenuItem.setVisible(false); + restartView.setVisibility(View.INVISIBLE); + playView.setVisibility(View.INVISIBLE); recordView.setImageResource(R.drawable.ic_stop); timerView.setText("00:00:00"); @@ -170,12 +194,14 @@ public void run() { }, 0, 1000); } - private void stopRecoding() { + private void stopRecording() { isRecording = false; if(!isFinishing()) { - selectMenuItem.setVisible(true); + saveMenuItem.setVisible(true); } - recordView.setImageResource(R.drawable.ic_play); +// restartView.setVisibility(View.VISIBLE); +// playView.setVisibility(View.VISIBLE); + recordView.setImageResource(R.drawable.ic_rec); if(visualizerHandler != null) { visualizerHandler.stop(); diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/VisualizerHandler.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/VisualizerHandler.java index 729e357..a9d3b2a 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/VisualizerHandler.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/VisualizerHandler.java @@ -16,12 +16,16 @@ protected void onDataReceivedImpl(Float amplitude, int layersCount, float[] dBmA } else if(amplitude > 0.7){ amplitude = 1f; } - dBmArray[0] = amplitude; - ampsArray[0] = amplitude; + try { + dBmArray[0] = amplitude; + ampsArray[0] = amplitude; + } catch (Exception e){ } } public void stop() { - calmDownAndStopRendering(); + try { + calmDownAndStopRendering(); + } catch (Exception e){ } } } \ No newline at end of file diff --git a/lib/src/main/res/drawable/ic_mic.png b/lib/src/main/res/drawable/ic_mic.png deleted file mode 100644 index 2f1e60c..0000000 Binary files a/lib/src/main/res/drawable/ic_mic.png and /dev/null differ diff --git a/lib/src/main/res/drawable/ic_pause.png b/lib/src/main/res/drawable/ic_pause.png new file mode 100644 index 0000000..995dbe0 Binary files /dev/null and b/lib/src/main/res/drawable/ic_pause.png differ diff --git a/lib/src/main/res/drawable/ic_play.png b/lib/src/main/res/drawable/ic_play.png index 2745c3a..c34a5d8 100644 Binary files a/lib/src/main/res/drawable/ic_play.png and b/lib/src/main/res/drawable/ic_play.png differ diff --git a/lib/src/main/res/drawable/ic_rec.png b/lib/src/main/res/drawable/ic_rec.png new file mode 100644 index 0000000..3550c84 Binary files /dev/null and b/lib/src/main/res/drawable/ic_rec.png differ diff --git a/lib/src/main/res/drawable/ic_restart.png b/lib/src/main/res/drawable/ic_restart.png new file mode 100644 index 0000000..7dd06f1 Binary files /dev/null and b/lib/src/main/res/drawable/ic_restart.png differ diff --git a/lib/src/main/res/drawable/ic_stop.png b/lib/src/main/res/drawable/ic_stop.png index 5239336..6587135 100644 Binary files a/lib/src/main/res/drawable/ic_stop.png and b/lib/src/main/res/drawable/ic_stop.png differ diff --git a/lib/src/main/res/layout/activity_audio_recorder.xml b/lib/src/main/res/layout/activity_audio_recorder.xml index 161e65b..8f5e62a 100644 --- a/lib/src/main/res/layout/activity_audio_recorder.xml +++ b/lib/src/main/res/layout/activity_audio_recorder.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" - android:layout_marginTop="40dp" + android:layout_marginTop="50dp" android:textSize="60sp" android:textColor="@android:color/white" android:fontFamily="sans-serif-thin" @@ -25,15 +25,46 @@ android:layout_alignParentBottom="true"> + + + + diff --git a/lib/src/main/res/menu/audio_recorder.xml b/lib/src/main/res/menu/audio_recorder.xml index 567f417..95448a7 100644 --- a/lib/src/main/res/menu/audio_recorder.xml +++ b/lib/src/main/res/menu/audio_recorder.xml @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> diff --git a/lib/src/main/res/values/dimens.xml b/lib/src/main/res/values/dimens.xml index c39c0db..63fd275 100644 --- a/lib/src/main/res/values/dimens.xml +++ b/lib/src/main/res/values/dimens.xml @@ -1,6 +1,6 @@ 60dp - 25dp + 30dp 200dp \ No newline at end of file diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml index df344ef..fe68eea 100644 --- a/lib/src/main/res/values/strings.xml +++ b/lib/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ AndroidAudioRecorder - Select + Save \ No newline at end of file diff --git a/screenshots.png b/screenshots.png index 083df53..6e248a7 100644 Binary files a/screenshots.png and b/screenshots.png differ