diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AndroidAudioRecorder.java index 29a3eb3..27c6375 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 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); + } + +}