From c23ae6007117456d6a7bf121b62d64e77a7e3ceb Mon Sep 17 00:00:00 2001 From: IcyIcarus Date: Sat, 15 Apr 2017 14:59:29 -0400 Subject: [PATCH] Update AndroidAudioRecorder.java --- .../AndroidAudioRecorder.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java index 29a3eb3..3dd94ff 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java @@ -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; @@ -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; @@ -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; @@ -90,4 +100,16 @@ public void record() { activity.startActivityForResult(intent, requestCode); } -} \ No newline at end of file + public void recordInFragment() { + 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); + } + +}