1
1
package com .github .developerpaul123 .filepickerlibrary ;
2
2
3
3
import android .app .Activity ;
4
+ import android .content .Context ;
4
5
import android .content .Intent ;
5
6
import android .support .annotation .ColorRes ;
6
7
7
- import com .github .developerpaul123 .filepickerlibrary .enums .Scope ;
8
8
import com .github .developerpaul123 .filepickerlibrary .enums .FileType ;
9
+ import com .github .developerpaul123 .filepickerlibrary .enums .Scope ;
9
10
10
11
/**
11
12
* Created by Paul on 11/23/2015.
12
13
*/
13
14
public class FilePickerBuilder {
14
15
15
- private final Activity mActivity ;
16
- boolean useMaterial ;
17
- private Scope mScope ;
18
- private int requestCode ;
19
- private int color ;
20
- private FileType mimeType ;
16
+ private final Context mContext ;
17
+ private boolean useMaterial ;
18
+ private Scope mScope = Scope . ALL ;
19
+ private int requestCode = FilePicker . REQUEST_FILE ;
20
+ private int color = android . R . color . holo_blue_bright ;
21
+ private FileType mimeType = FileType . NONE ;
21
22
22
23
/**
23
24
* Builder class to build a filepicker activity.
24
25
*
25
- * @param activity the calling activity.
26
+ * @param context the calling activity.
26
27
*/
27
- public FilePickerBuilder (Activity activity ) {
28
- color = android .R .color .holo_blue_bright ;
29
- mScope = Scope .ALL ;
30
- mimeType = FileType .NONE ;
31
- requestCode = FilePicker .REQUEST_FILE ;
32
- mActivity = activity ;
33
- useMaterial = false ;
28
+ public FilePickerBuilder (Context context ) {
29
+ mContext = context ;
34
30
}
35
31
36
32
/**
@@ -93,7 +89,7 @@ public FilePickerBuilder useMaterialActivity(boolean use) {
93
89
@ Deprecated
94
90
public void launch () {
95
91
Intent intent = build ();
96
- mActivity .startActivityForResult (intent , requestCode );
92
+ (( Activity ) mContext ) .startActivityForResult (intent , requestCode );
97
93
}
98
94
99
95
/**
@@ -102,7 +98,7 @@ public void launch() {
102
98
* @return a filepicker intent.
103
99
*/
104
100
public Intent build () {
105
- Intent filePicker = new Intent (mActivity , useMaterial ? FilePicker .class : FilePickerActivity .class );
101
+ Intent filePicker = new Intent (mContext , useMaterial ? FilePicker .class : FilePickerActivity .class );
106
102
filePicker .putExtra (FilePicker .SCOPE_TYPE , mScope );
107
103
filePicker .putExtra (FilePicker .REQUEST_CODE , requestCode );
108
104
filePicker .putExtra (FilePicker .INTENT_EXTRA_COLOR_ID , color );
@@ -117,6 +113,6 @@ public Intent build() {
117
113
*/
118
114
public void launch (int requestCode ) {
119
115
Intent intent = build ();
120
- mActivity .startActivityForResult (intent , requestCode );
116
+ (( Activity ) mContext ) .startActivityForResult (intent , requestCode );
121
117
}
122
118
}
0 commit comments