Skip to content

Commit 35c256f

Browse files
Merge pull request #39 from alirezaaa/master
v3.5.1
2 parents 542ec23 + d01f8dd commit 35c256f

File tree

8 files changed

+95
-114
lines changed

8 files changed

+95
-114
lines changed

.idea/inspectionProfiles/Project_Default.xml

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

README.md

Lines changed: 80 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,101 @@
1-
FilePickerLibrary
2-
=================
1+
# FilePickerLibrary
32

4-
[![Android Arsenal](http://img.shields.io/badge/Android%20Arsenal-FilePickerLibrary-blue.svg?style=flat)](http://android-arsenal.com/details/1/785)
5-
6-
[![](https://jitpack.io/v/DeveloperPaul123/FilePickerLibrary.svg)](https://jitpack.io/#DeveloperPaul123/FilePickerLibrary)
3+
[![Release](https://jitpack.io/v/com.github.alirezaaa/FilePickerLibrary.svg)](https://jitpack.io/#alirezaaa/FilePickerLibrary)
74

85
Simple library that allows for picking of files and directories. This is a clean and simple way to allow your user to easily select a file. This library is inspired by Android L and the new Material Design guidelines adding to its sleekness and beauty.
96

10-
117
![image] (images/main_framed.png)
128

13-
<h2>Requirements</h2>
14-
Min SDK Level is 16
15-
16-
<h2>Dependency</h2>
17-
18-
Clone this repository or download the zip. Then extract to your computer. Simply import the library to your project but only include the FPlib module (that's where the library is). If you're using Android Studio then import a module and only include the FPlib module. See the license for usage terms.
19-
20-
Alternatively you can use gradle.
21-
22-
Add the following code to your gradle build script.
23-
````java
24-
repositories {
25-
...
26-
maven {url "https://jitpack.io"}
27-
}
28-
dependencies {
29-
compile 'com.github.DeveloperPaul123:FilePickerLibrary:2.1.1'
30-
}
31-
````
32-
33-
<h2>Usage</h2>
34-
Simply do the following.
35-
```java
36-
Intent filePickerIntent = new Intent(this, FilePickerActivity.class);
37-
filePickerIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_DIRECTORY);
38-
startActivityForResult(filePickerIntent, FilePickerActivity.REQUEST_DIRECTORY);
9+
## A Quick Overview What's In
10+
* compatible down to API Level 16
11+
12+
## Include to Project
13+
### Provide the Gradle Dependency
14+
#### Step 1
15+
Add the JitPack in your root `build.gradle` at the end of repositories:
16+
```gradle
17+
allprojects {
18+
repositories {
19+
...
20+
maven { url "https://jitpack.io" }
21+
}
22+
}
3923
```
40-
Make sure to add the int extra for your request code. You can also request for a file path instead of a directory. See the javadocs for more info. To get the file path do the following.
24+
#### Step 2
25+
Add the dependency
26+
```gradle
27+
dependencies {
28+
compile 'com.github.alirezaaa:FilePickerLibrary:3.5.1'
29+
}
30+
```
31+
### Clone or Download `.zip` file
32+
Clone this repository or download the compressed file, then extract to your computer. Simply import the `library` module to your project.
4133

34+
## Usages
35+
Use one of the following samples or simply compile and test the sample `app` provided:
36+
### Material Theme Used (with Modern Builder)
4237
```java
43-
@Override
44-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
45-
46-
if(requestCode == FilePickerActivity.REQUEST_DIRECTORY
47-
&& resultCode == RESULT_OK) {
48-
49-
String filePath = data.
50-
getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH);
51-
if(filePath != null) {
52-
//do something with filePath...
53-
}
54-
}
55-
super.onActivityResult(requestCode, resultCode, data);
56-
}
38+
new FilePickerBuilder(this)
39+
.withColor(android.R.color.holo_blue_bright)
40+
.withRequest(Request.FILE)
41+
.withScope(Scope.ALL)
42+
.withMimeType(MimeType.JPEG)
43+
.useMaterialActivity(true)
44+
.launch(REQUEST_FILE);
5745
```
58-
59-
<h2>Customization</h2>
60-
You can change the header background in the activity by adding resorce ids to your calling intent as int extras. Below is an example.
61-
46+
### `image/png` Mime Type
6247
```java
63-
Intent filePickerIntent = new Intent(this, FilePickerActivity.class);
64-
filePickerIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_DIRECTORY);
65-
filePickerIntent.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, R.color.myColor);
66-
startActivityForResult(filePickerIntent, FilePickerActivity.REQUEST_DIRECTORY);
48+
Intent filePicker = new Intent(this, FilePickerActivity.class);
49+
filePicker.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
50+
filePicker.putExtra(FilePickerActivity.REQUEST, Request.FILE);
51+
filePicker.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, android.R.color.holo_green_dark);
52+
filePicker.putExtra(FilePickerActivity.MIME_TYPE, MimeType.PNG);
53+
startActivityForResult(filePicker, REQUEST_FILE);
6754
```
68-
You can also change the theme for the activity to make it look like a dialog.
55+
### Show as a Dialog
6956
```java
70-
Intent filePickerDialogIntent = new Intent(getActivity(), FilePickerActivity.class);
57+
Intent filePickerDialogIntent = new Intent(this, FilePickerActivity.class);
7158
filePickerDialogIntent.putExtra(FilePickerActivity.THEME_TYPE, ThemeType.DIALOG);
72-
filePickerDialogIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_FILE);
73-
startActivityForResult(filePickerDialogIntent, FilePickerActivity.REQUEST_FILE);
59+
filePickerDialogIntent.putExtra(FilePickerActivity.REQUEST, Request.FILE);
60+
startActivityForResult(filePickerDialogIntent, REQUEST_FILE);
7461
```
75-
In addition you can set a mime type that you want the user to select. The activity will not return a result until that type of file is selected. For example:
76-
62+
### Select a Directory
7763
```java
78-
Intent filePicker = new Intent(getActivity(), FilePickerActivity.class);
79-
filePicker.putExtra(FilePickerActivity.SCOPE_TYPE, FileScopeType.ALL);
80-
filePicker.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_FILE);
81-
filePicker.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, android.R.color.holo_green_dark);
82-
filePicker.putExtra(FilePickerActivity.MIME_TYPE, FileType.PNG);
83-
startActivityForResult(filePicker, FilePickerActivity.REQUEST_FILE);
64+
Intent filePickerActivity = new Intent(this, FilePickerActivity.class);
65+
filePickerActivity.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
66+
filePickerActivity.putExtra(FilePickerActivity.REQUEST, Request.DIRECTORY);
67+
filePickerActivity.putExtra(FilePickerActivity.INTENT_EXTRA_FAB_COLOR_ID, android.R.color.holo_green_dark);
68+
startActivityForResult(filePickerActivity, REQUEST_DIRECTORY);
8469
```
85-
86-
Finally, you can now use a builder class to simplify intent creation:
70+
To have the result, you must override `onActivityResult(int, int, Intent)` method as I did below:
8771

8872
```java
89-
new FilePickerBuilder(getActivity()).withColor(android.R.color.holo_blue_bright)
90-
.withRequestCode(FilePicker.REQUEST_FILE)
91-
.withScopeType(FileScopeType.ALL)
92-
.withMimeType(FileType.PNG)
93-
.useMaterialActivity(true)
94-
.launch();
95-
```
96-
You can also call ` build() ` instead of ` launch() ` and you will get back an activity. Note that `launch()` starts the activity with `startActivityForResult() ` and uses the request code you passed into the builder as the request code for the activity result extra. So when listening for activity results be sure to use the same request code.
97-
98-
<h2>Demo App</h2>
99-
* **Check out the sample on google play.**
100-
101-
[![Get it on Google Play](http://www.android.com/images/brand/get_it_on_play_logo_small.png)](https://play.google.com/store/apps/details?id=com.devpaul.filepicker)
102-
103-
<h2>Developed By</h2>
104-
**Paul T**
105-
106-
<h2>License</h2>
107-
108-
Copyright 2014 Paul T
109-
110-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
111-
112-
You may obtain a copy of the License at
73+
@Override
74+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
75+
super.onActivityResult(requestCode, resultCode, data);
11376

114-
http://www.apache.org/licenses/LICENSE-2.0
77+
if ((requestCode == REQUEST_DIRECTORY) && (resultCode == RESULT_OK)) {
78+
Toast.makeText(this, "Directory Selected: " + data.getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), Toast.LENGTH_LONG).show();
79+
} else if ((requestCode == REQUEST_FILE) && (resultCode == RESULT_OK)) {
80+
Toast.makeText(this, "File Selected: " + data.getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), Toast.LENGTH_LONG).show();
81+
}
82+
}
83+
```
84+
## Contributors
85+
- [Paul T](mailto:developer.paul.123@gmail.com) (developer)
86+
- [Alireza Eskandarpour Shoferi](https://twitter.com/enormoustheory) (contributor)
11587

116-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
88+
## License
89+
Copyright 2014 Paul T
90+
91+
Licensed under the Apache License, Version 2.0 (the "License");
92+
you may not use this file except in compliance with the License.
93+
You may obtain a copy of the License at
94+
95+
http://www.apache.org/licenses/LICENSE-2.0
96+
97+
Unless required by applicable law or agreed to in writing, software
98+
distributed under the License is distributed on an "AS IS" BASIS,
99+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
100+
See the License for the specific language governing permissions and
101+
limitations under the License.

app/app.iml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@
6161
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
6262
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6363
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
64-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
65-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
66-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
67-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
7164
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7265
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7366
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
7467
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
7568
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
7669
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
7770
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
7878
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
7979
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8080
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
@@ -85,13 +85,10 @@
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.DeveloperPaul123/MaterialLibrary/1.0.5/jars" />
8787
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
88-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8988
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
90-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
9189
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
9290
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
9391
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
94-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
9592
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
9693
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9794
</content>

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
defaultConfig {
77
minSdkVersion 16
88
targetSdkVersion 23
9-
versionName '3.5'
10-
versionCode 8
9+
versionName '3.5.1'
10+
versionCode 9
1111
}
1212
buildTypes {
1313
release {

library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePicker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.support.v7.widget.LinearLayoutManager;
2121
import android.support.v7.widget.RecyclerView;
2222
import android.support.v7.widget.Toolbar;
23+
import android.text.TextUtils;
2324
import android.view.MenuItem;
2425
import android.view.View;
2526
import android.view.ViewTreeObserver;
@@ -481,7 +482,7 @@ public void onClick(View view) {
481482
curDirectory = currentFile;
482483
new UpdateFilesTask(FilePicker.this).execute(curDirectory);
483484
} else {
484-
if (mimeType != null) {
485+
if (!TextUtils.isEmpty(mimeType)) {
485486
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
486487
String requiredExtension = "." + mimeTypeMap.getExtensionFromMimeType(mimeType);
487488
if (requiredExtension.equalsIgnoreCase(fileExt(currentFile.toString()))) {

library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.support.design.widget.Snackbar;
3434
import android.support.v4.app.ActivityCompat;
3535
import android.support.v4.content.ContextCompat;
36+
import android.text.TextUtils;
3637
import android.view.MenuItem;
3738
import android.view.View;
3839
import android.view.animation.Animation;
@@ -463,7 +464,7 @@ public void onClick(View view) {
463464
curDirectory = currentFile;
464465
new UpdateFilesTask(FilePickerActivity.this).execute(curDirectory);
465466
} else {
466-
if (mimeType != null && !mimeType.equalsIgnoreCase(MimeType.NONE.getMimeType())) {
467+
if (!TextUtils.isEmpty(mimeType)) {
467468
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
468469
String requiredExtension = "." + mimeTypeMap.getExtensionFromMimeType(mimeType);
469470
if (requiredExtension.equalsIgnoreCase(fileExt(currentFile.toString()))) {

library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class FilePickerBuilder {
1919
private Scope mScope = Scope.ALL;
2020
private Request requestCode = Request.FILE;
2121
private int color = android.R.color.holo_blue_bright;
22-
private MimeType mimeType = MimeType.NONE;
22+
private MimeType mimeType;
2323

2424
/**
2525
* Builder class to build a filepicker activity.

library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/MimeType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Created by Paul Tsouchlos
2121
*/
2222
public enum MimeType {
23-
NONE(""), JPEG("image/jpeg"), PNG("image/png"), XML("application/xml"),
23+
JPEG("image/jpeg"), PNG("image/png"), XML("application/xml"),
2424
XLS("application/vnd.ms-excel"), XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
2525
DOC("application/msword"), DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
2626
HTML("text/html"), TXT("text/plain"), PDF("application/pdf");

0 commit comments

Comments
 (0)