11package cafe .adriel .androidaudiorecorder ;
22
3- import android .app .Activity ;
4- import android .content .pm .PackageManager ;
53import android .graphics .Color ;
64import android .media .AudioFormat ;
7- import android .media .MediaRecorder ;
85import android .os .Handler ;
9- import android .support .v4 .app .ActivityCompat ;
10- import android .support .v4 .content .ContextCompat ;
116
12- import omrecorder .AudioSource ;
7+ import cafe .adriel .androidaudiorecorder .model .AudioChannel ;
8+ import cafe .adriel .androidaudiorecorder .model .AudioSampleRate ;
9+ import cafe .adriel .androidaudiorecorder .model .AudioSource ;
10+
1311
1412public class Util {
1513 private static final Handler HANDLER = new Handler ();
16- private static final int AUDIO_FREQUENCY = 44100 ;
1714
1815 private Util () {
1916 }
2017
21- public static void requestPermission (Activity activity , String permission ) {
22- if (ContextCompat .checkSelfPermission (activity , permission )
23- != PackageManager .PERMISSION_GRANTED ) {
24- ActivityCompat .requestPermissions (activity , new String []{permission }, 0 );
25- }
26- }
27-
2818 public static void wait (int millis , Runnable callback ){
2919 HANDLER .postDelayed (callback , millis );
3020 }
3121
32- public static AudioSource getMic () {
33- return new AudioSource .Smart (
34- MediaRecorder .AudioSource .MIC ,
22+ public static omrecorder .AudioSource getMic (AudioSource source ,
23+ AudioChannel channel ,
24+ AudioSampleRate sampleRate ) {
25+ return new omrecorder .AudioSource .Smart (
26+ source .getSource (),
3527 AudioFormat .ENCODING_PCM_16BIT ,
36- AudioFormat . CHANNEL_IN_STEREO ,
37- AUDIO_FREQUENCY );
28+ channel . getChannel () ,
29+ sampleRate . getSampleRate () );
3830 }
3931
40- /**
41- * Function to check brightness of background color
42- * @param color
43- * @return true if color is bright
44- */
4532 public static boolean isBrightColor (int color ) {
4633 if (android .R .color .transparent == color ) {
4734 return true ;
@@ -51,7 +38,6 @@ public static boolean isBrightColor(int color) {
5138 rgb [0 ] * rgb [0 ] * 0.241 +
5239 rgb [1 ] * rgb [1 ] * 0.691 +
5340 rgb [2 ] * rgb [2 ] * 0.068 );
54- //color is bright
5541 return brightness >= 200 ;
5642 }
5743
0 commit comments