4
4
import android .content .Intent ;
5
5
import android .graphics .Color ;
6
6
import android .os .Environment ;
7
+ import android .support .v4 .app .Fragment ;
7
8
8
9
import cafe .adriel .androidaudiorecorder .model .AudioChannel ;
9
10
import cafe .adriel .androidaudiorecorder .model .AudioSampleRate ;
@@ -20,6 +21,7 @@ public class AndroidAudioRecorder {
20
21
protected static final String EXTRA_KEEP_DISPLAY_ON = "keepDisplayOn" ;
21
22
22
23
private Activity activity ;
24
+ private Fragment fragment ;
23
25
24
26
private String filePath = Environment .getExternalStorageDirectory () + "/recorded_audio.wav" ;
25
27
private AudioSource source = AudioSource .MIC ;
@@ -34,10 +36,18 @@ private AndroidAudioRecorder(Activity activity) {
34
36
this .activity = activity ;
35
37
}
36
38
39
+ private AndroidAudioRecorder (Fragment fragment ) {
40
+ this .fragment = fragment ;
41
+ }
42
+
37
43
public static AndroidAudioRecorder with (Activity activity ) {
38
44
return new AndroidAudioRecorder (activity );
39
45
}
40
46
47
+ public static AndroidAudioRecorder with (Fragment fragment ) {
48
+ return new AndroidAudioRecorder (fragment );
49
+ }
50
+
41
51
public AndroidAudioRecorder setFilePath (String filePath ) {
42
52
this .filePath = filePath ;
43
53
return this ;
@@ -90,4 +100,16 @@ public void record() {
90
100
activity .startActivityForResult (intent , requestCode );
91
101
}
92
102
93
- }
103
+ public void recordFromFragment () {
104
+ Intent intent = new Intent (fragment .getActivity (), AudioRecorderActivity .class );
105
+ intent .putExtra (EXTRA_FILE_PATH , filePath );
106
+ intent .putExtra (EXTRA_COLOR , color );
107
+ intent .putExtra (EXTRA_SOURCE , source );
108
+ intent .putExtra (EXTRA_CHANNEL , channel );
109
+ intent .putExtra (EXTRA_SAMPLE_RATE , sampleRate );
110
+ intent .putExtra (EXTRA_AUTO_START , autoStart );
111
+ intent .putExtra (EXTRA_KEEP_DISPLAY_ON , keepDisplayOn );
112
+ fragment .startActivityForResult (intent , requestCode );
113
+ }
114
+
115
+ }
0 commit comments