Skip to content

Commit

Permalink
Merge pull request #25 from icyicarus/master
Browse files Browse the repository at this point in the history
Now can be started from a fragment
  • Loading branch information
adrielcafe authored Apr 20, 2017
2 parents 50b62db + b79c0e5 commit eabc4c0
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.graphics.Color;
import android.os.Environment;
import android.support.v4.app.Fragment;

import cafe.adriel.androidaudiorecorder.model.AudioChannel;
import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
Expand All @@ -20,6 +21,7 @@ public class AndroidAudioRecorder {
protected static final String EXTRA_KEEP_DISPLAY_ON = "keepDisplayOn";

private Activity activity;
private Fragment fragment;

private String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";
private AudioSource source = AudioSource.MIC;
Expand All @@ -34,10 +36,18 @@ private AndroidAudioRecorder(Activity activity) {
this.activity = activity;
}

private AndroidAudioRecorder(Fragment fragment) {
this.fragment = fragment;
}

public static AndroidAudioRecorder with(Activity activity) {
return new AndroidAudioRecorder(activity);
}

public static AndroidAudioRecorder with(Fragment fragment) {
return new AndroidAudioRecorder(fragment);
}

public AndroidAudioRecorder setFilePath(String filePath) {
this.filePath = filePath;
return this;
Expand Down Expand Up @@ -90,4 +100,16 @@ public void record() {
activity.startActivityForResult(intent, requestCode);
}

}
public void recordFromFragment() {
Intent intent = new Intent(fragment.getActivity(), AudioRecorderActivity.class);
intent.putExtra(EXTRA_FILE_PATH, filePath);
intent.putExtra(EXTRA_COLOR, color);
intent.putExtra(EXTRA_SOURCE, source);
intent.putExtra(EXTRA_CHANNEL, channel);
intent.putExtra(EXTRA_SAMPLE_RATE, sampleRate);
intent.putExtra(EXTRA_AUTO_START, autoStart);
intent.putExtra(EXTRA_KEEP_DISPLAY_ON, keepDisplayOn);
fragment.startActivityForResult(intent, requestCode);
}

}

0 comments on commit eabc4c0

Please sign in to comment.