Skip to content

Commit

Permalink
Working on 0.0.6
Browse files Browse the repository at this point in the history
* New images
* Restart recording
* Update screenshots
* Refactoring
  • Loading branch information
adrielcafe committed Aug 17, 2016
1 parent 37df90d commit bb41b08
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<color name="colorAccent">#FF4081</color>

<color name="recorder_bg">#039BE5</color>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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);
Expand All @@ -99,7 +107,7 @@ public void onResume() {

@Override
protected void onPause() {
stopRecoding();
stopRecording();
audioVisualizationView.onPause();
super.onPause();
}
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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");

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){ }
}

}
Binary file removed lib/src/main/res/drawable/ic_mic.png
Binary file not shown.
Binary file added lib/src/main/res/drawable/ic_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/src/main/res/drawable/ic_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/src/main/res/drawable/ic_rec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/src/main/res/drawable/ic_restart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/src/main/res/drawable/ic_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 34 additions & 3 deletions lib/src/main/res/layout/activity_audio_recorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,15 +25,46 @@
android:layout_alignParentBottom="true">

<ImageButton
android:id="@+id/record"
android:id="@+id/restart"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/record"
android:layout_toLeftOf="@+id/record"
android:layout_marginTop="50dp"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_restart"
android:onClick="restartRecording"
android:visibility="invisible"
style="@style/Widget.AppCompat.Button.Borderless"/>

<ImageButton
android:id="@+id/record"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:layout_marginTop="50dp"
android:layout_margin="15dp"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_rec"
android:onClick="toggleRecording"
style="@style/Widget.AppCompat.Button.Borderless"/>

<ImageButton
android:id="@+id/play"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/record"
android:layout_toRightOf="@+id/record"
android:layout_marginTop="50dp"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_play"
android:onClick="toggleRecord"
android:onClick="playRecording"
android:visibility="invisible"
style="@style/Widget.AppCompat.Button.Borderless"/>

</RelativeLayout>
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/res/menu/audio_recorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_select"
android:title="@string/select"
android:id="@+id/action_save"
android:title="@string/save"
android:visible="false"
app:showAsAction="always"/>

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="wave_height">60dp</dimen>
<dimen name="bubble_size">25dp</dimen>
<dimen name="bubble_size">30dp</dimen>
<dimen name="footer_height">200dp</dimen>
</resources>
2 changes: 1 addition & 1 deletion lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<string name="app_name">AndroidAudioRecorder</string>
<string name="select">Select</string>
<string name="save">Save</string>
</resources>
Binary file modified screenshots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bb41b08

Please sign in to comment.