Skip to content

Commit ee6605d

Browse files
Merge pull request #3 from MuhammadTouseeq/developer
added File Picker Feature
2 parents 48b2ac3 + 70b8f70 commit ee6605d

5 files changed

Lines changed: 89 additions & 19 deletions

File tree

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ dependencies {
4040
implementation project(':easypicker')
4141
implementation 'com.github.bumptech.glide:glide:4.11.0'
4242
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
43-
43+
// implementation 'com.github.MuhammadTouseeq:EasyImagePicker:v1.0.0'
4444
}

app/src/main/java/com/pakdev/practiceapp/MainActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
4747
@Override
4848
public void onMediaFilePicked(String result) {
4949

50-
51-
Glide.with(MainActivity.this).load(Uri.fromFile(new File(result)))
52-
.apply(new RequestOptions().circleCrop())
53-
// .placeholder(drawable)
54-
.into( ((ImageView)findViewById(R.id.img)));
50+
Toast.makeText(MainActivity.this, ""+result, Toast.LENGTH_SHORT).show();
51+
// Glide.with(MainActivity.this).load(Uri.fromFile(new File(result)))
52+
// .apply(new RequestOptions().circleCrop())
53+
// // .placeholder(drawable)
54+
// .into( ((ImageView)findViewById(R.id.img)));
5555

5656
}
5757

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ allprojects {
1616
repositories {
1717
google()
1818
jcenter()
19+
20+
maven { url 'https://jitpack.io' }
1921
}
2022
}
2123

easypicker/src/main/java/com/pakdev/easypicker/utils/EasyImagePicker.java

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929

3030
public class EasyImagePicker {
3131

32-
33-
public static final int REQUEST_TAKE_PHOTO = 1;
34-
public static final int REQUEST_GALLERY_PHOTO = 2;
32+
enum FILE_TYPE{
33+
CAMERA,GALLERY,FILE
34+
}
35+
public static final int REQUEST_TAKE_PHOTO = 111;
36+
public static final int REQUEST_GALLERY_PHOTO = 222;
37+
public static final int REQUEST_FILE = 777;
3538
File mPhotoFile;
3639
FileCompressor mCompressor;
3740
private Activity mContext;
@@ -53,11 +56,16 @@ public EasyImagePicker openEasyPicker() {
5356
return this;
5457
}
5558
public EasyImagePicker openCamera() {
56-
requestPermissions(true);
59+
requestPermissions(FILE_TYPE.CAMERA);
5760
return this;
5861
}
5962
public EasyImagePicker openGallery() {
60-
requestPermissions(false);
63+
requestPermissions(FILE_TYPE.GALLERY);
64+
return this;
65+
}
66+
67+
public EasyImagePicker openFilePicker() {
68+
requestPermissions(FILE_TYPE.FILE);
6169
return this;
6270
}
6371

@@ -71,7 +79,7 @@ public void showDialog() {
7179
btnCamera.setOnClickListener(new View.OnClickListener() {
7280
@Override
7381
public void onClick(View v) {
74-
requestPermissions(true);
82+
requestPermissions(FILE_TYPE.CAMERA);
7583
dialog.dismiss();
7684

7785
}
@@ -80,7 +88,7 @@ public void onClick(View v) {
8088
btnGallery.setOnClickListener(new View.OnClickListener() {
8189
@Override
8290
public void onClick(View v) {
83-
requestPermissions(false);
91+
requestPermissions(FILE_TYPE.GALLERY);
8492
dialog.dismiss();
8593

8694
}
@@ -99,10 +107,38 @@ public void onClick(View v) {
99107

100108
}
101109

110+
111+
private void intentFilPicker()
112+
{
113+
Intent intent;
114+
if (android.os.Build.MANUFACTURER.equalsIgnoreCase("samsung")) {
115+
intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
116+
intent.putExtra("CONTENT_TYPE", "*/*");
117+
intent.addCategory(Intent.CATEGORY_DEFAULT);
118+
} else {
119+
120+
String[] mimeTypes =
121+
{
122+
"application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // .doc & .docx
123+
"application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", // .ppt & .pptx
124+
"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // .xls & .xlsx
125+
"text/plain",
126+
"application/pdf",
127+
"application/zip", "application/vnd.android.package-archive"};
128+
129+
intent = new Intent(Intent.ACTION_GET_CONTENT); // or ACTION_OPEN_DOCUMENT
130+
intent.setType("*/*");
131+
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
132+
intent.addCategory(Intent.CATEGORY_OPENABLE);
133+
//intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
134+
}
135+
136+
mContext.startActivityForResult(intent,REQUEST_FILE);
137+
}
102138
/**
103139
* Capture image from camera
104140
*/
105-
public void dispatchTakePictureIntent() {
141+
private void dispatchTakePictureIntent() {
106142

107143
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
108144
if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
@@ -125,7 +161,7 @@ public void dispatchTakePictureIntent() {
125161
}
126162
}
127163

128-
private void requestPermissions(final boolean isCamera) {
164+
private void requestPermissions(final FILE_TYPE type) {
129165
Dexter.withActivity(mContext).withPermissions(Manifest.permission.READ_EXTERNAL_STORAGE,
130166
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
131167
.withListener(new MultiplePermissionsListener() {
@@ -134,10 +170,24 @@ public void onPermissionsChecked(MultiplePermissionsReport report) {
134170

135171
// check if all permissions are granted
136172
if (report.areAllPermissionsGranted()) {
137-
if (isCamera) {
138-
dispatchTakePictureIntent();
139-
} else {
140-
dispatchGalleryIntent();
173+
174+
switch (type)
175+
{
176+
case FILE:
177+
{
178+
intentFilPicker();
179+
}
180+
break;
181+
case GALLERY:
182+
{
183+
dispatchGalleryIntent();
184+
}
185+
break;
186+
case CAMERA:
187+
{
188+
dispatchTakePictureIntent();
189+
}
190+
break;
141191
}
142192
}
143193
// check for permanent denial of any permission
@@ -198,6 +248,23 @@ else if (resultCode == Activity.RESULT_CANCELED) {
198248

199249
}
200250
break;
251+
case (REQUEST_FILE): {
252+
253+
if (resultCode == Activity.RESULT_OK) {
254+
Uri selectedImage = data.getData();
255+
256+
257+
// mCompressor = new FileCompressor(mContext);
258+
File mPhotoFile = null;
259+
mPhotoFile = new File(ImageUtil.getRealPathFromUri(mContext, selectedImage));
260+
261+
if (pickerCallback != null) {
262+
pickerCallback.onMediaFilePicked(mPhotoFile.getAbsolutePath());
263+
}
264+
265+
}
266+
}
267+
break;
201268
case (REQUEST_GALLERY_PHOTO): {
202269

203270

0 commit comments

Comments
 (0)