Skip to content

Commit

Permalink
Merge pull request #39 from alirezaaa/master
Browse files Browse the repository at this point in the history
v3.5.1
  • Loading branch information
DeveloperPaul123 committed Feb 25, 2016
2 parents 542ec23 + d01f8dd commit 35c256f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 114 deletions.
3 changes: 0 additions & 3 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

175 changes: 80 additions & 95 deletions README.md
@@ -1,116 +1,101 @@
FilePickerLibrary
=================
# FilePickerLibrary

[![Android Arsenal](http://img.shields.io/badge/Android%20Arsenal-FilePickerLibrary-blue.svg?style=flat)](http://android-arsenal.com/details/1/785)

[![](https://jitpack.io/v/DeveloperPaul123/FilePickerLibrary.svg)](https://jitpack.io/#DeveloperPaul123/FilePickerLibrary)
[![Release](https://jitpack.io/v/com.github.alirezaaa/FilePickerLibrary.svg)](https://jitpack.io/#alirezaaa/FilePickerLibrary)

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.


![image] (images/main_framed.png)

<h2>Requirements</h2>
Min SDK Level is 16

<h2>Dependency</h2>

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.

Alternatively you can use gradle.

Add the following code to your gradle build script.
````java
repositories {
...
maven {url "https://jitpack.io"}
}
dependencies {
compile 'com.github.DeveloperPaul123:FilePickerLibrary:2.1.1'
}
````

<h2>Usage</h2>
Simply do the following.
```java
Intent filePickerIntent = new Intent(this, FilePickerActivity.class);
filePickerIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_DIRECTORY);
startActivityForResult(filePickerIntent, FilePickerActivity.REQUEST_DIRECTORY);
## A Quick Overview What's In
* compatible down to API Level 16

## Include to Project
### Provide the Gradle Dependency
#### Step 1
Add the JitPack in your root `build.gradle` at the end of repositories:
```gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```
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.
#### Step 2
Add the dependency
```gradle
dependencies {
compile 'com.github.alirezaaa:FilePickerLibrary:3.5.1'
}
```
### Clone or Download `.zip` file
Clone this repository or download the compressed file, then extract to your computer. Simply import the `library` module to your project.

## Usages
Use one of the following samples or simply compile and test the sample `app` provided:
### Material Theme Used (with Modern Builder)
```java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

if(requestCode == FilePickerActivity.REQUEST_DIRECTORY
&& resultCode == RESULT_OK) {

String filePath = data.
getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH);
if(filePath != null) {
//do something with filePath...
}
}
super.onActivityResult(requestCode, resultCode, data);
}
new FilePickerBuilder(this)
.withColor(android.R.color.holo_blue_bright)
.withRequest(Request.FILE)
.withScope(Scope.ALL)
.withMimeType(MimeType.JPEG)
.useMaterialActivity(true)
.launch(REQUEST_FILE);
```

<h2>Customization</h2>
You can change the header background in the activity by adding resorce ids to your calling intent as int extras. Below is an example.

### `image/png` Mime Type
```java
Intent filePickerIntent = new Intent(this, FilePickerActivity.class);
filePickerIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_DIRECTORY);
filePickerIntent.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, R.color.myColor);
startActivityForResult(filePickerIntent, FilePickerActivity.REQUEST_DIRECTORY);
Intent filePicker = new Intent(this, FilePickerActivity.class);
filePicker.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
filePicker.putExtra(FilePickerActivity.REQUEST, Request.FILE);
filePicker.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, android.R.color.holo_green_dark);
filePicker.putExtra(FilePickerActivity.MIME_TYPE, MimeType.PNG);
startActivityForResult(filePicker, REQUEST_FILE);
```
You can also change the theme for the activity to make it look like a dialog.
### Show as a Dialog
```java
Intent filePickerDialogIntent = new Intent(getActivity(), FilePickerActivity.class);
Intent filePickerDialogIntent = new Intent(this, FilePickerActivity.class);
filePickerDialogIntent.putExtra(FilePickerActivity.THEME_TYPE, ThemeType.DIALOG);
filePickerDialogIntent.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_FILE);
startActivityForResult(filePickerDialogIntent, FilePickerActivity.REQUEST_FILE);
filePickerDialogIntent.putExtra(FilePickerActivity.REQUEST, Request.FILE);
startActivityForResult(filePickerDialogIntent, REQUEST_FILE);
```
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:

### Select a Directory
```java
Intent filePicker = new Intent(getActivity(), FilePickerActivity.class);
filePicker.putExtra(FilePickerActivity.SCOPE_TYPE, FileScopeType.ALL);
filePicker.putExtra(FilePickerActivity.REQUEST_CODE, FilePickerActivity.REQUEST_FILE);
filePicker.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, android.R.color.holo_green_dark);
filePicker.putExtra(FilePickerActivity.MIME_TYPE, FileType.PNG);
startActivityForResult(filePicker, FilePickerActivity.REQUEST_FILE);
Intent filePickerActivity = new Intent(this, FilePickerActivity.class);
filePickerActivity.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
filePickerActivity.putExtra(FilePickerActivity.REQUEST, Request.DIRECTORY);
filePickerActivity.putExtra(FilePickerActivity.INTENT_EXTRA_FAB_COLOR_ID, android.R.color.holo_green_dark);
startActivityForResult(filePickerActivity, REQUEST_DIRECTORY);
```

Finally, you can now use a builder class to simplify intent creation:
To have the result, you must override `onActivityResult(int, int, Intent)` method as I did below:

```java
new FilePickerBuilder(getActivity()).withColor(android.R.color.holo_blue_bright)
.withRequestCode(FilePicker.REQUEST_FILE)
.withScopeType(FileScopeType.ALL)
.withMimeType(FileType.PNG)
.useMaterialActivity(true)
.launch();
```
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.

<h2>Demo App</h2>
* **Check out the sample on google play.**

[![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)
<h2>Developed By</h2>
**Paul T**

<h2>License</h2>

Copyright 2014 Paul T

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

You may obtain a copy of the License at
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

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

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.
## License
Copyright 2014 Paul T

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.
17 changes: 7 additions & 10 deletions app/app.iml
Expand Up @@ -61,20 +61,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -85,13 +85,10 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.DeveloperPaul123/MaterialLibrary/1.0.5/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionName '3.5'
versionCode 8
versionName '3.5.1'
versionCode 9
}
buildTypes {
release {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
Expand Down Expand Up @@ -481,7 +482,7 @@ public void onClick(View view) {
curDirectory = currentFile;
new UpdateFilesTask(FilePicker.this).execute(curDirectory);
} else {
if (mimeType != null) {
if (!TextUtils.isEmpty(mimeType)) {
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String requiredExtension = "." + mimeTypeMap.getExtensionFromMimeType(mimeType);
if (requiredExtension.equalsIgnoreCase(fileExt(currentFile.toString()))) {
Expand Down
Expand Up @@ -33,6 +33,7 @@
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
Expand Down Expand Up @@ -463,7 +464,7 @@ public void onClick(View view) {
curDirectory = currentFile;
new UpdateFilesTask(FilePickerActivity.this).execute(curDirectory);
} else {
if (mimeType != null && !mimeType.equalsIgnoreCase(MimeType.NONE.getMimeType())) {
if (!TextUtils.isEmpty(mimeType)) {
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String requiredExtension = "." + mimeTypeMap.getExtensionFromMimeType(mimeType);
if (requiredExtension.equalsIgnoreCase(fileExt(currentFile.toString()))) {
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class FilePickerBuilder {
private Scope mScope = Scope.ALL;
private Request requestCode = Request.FILE;
private int color = android.R.color.holo_blue_bright;
private MimeType mimeType = MimeType.NONE;
private MimeType mimeType;

/**
* Builder class to build a filepicker activity.
Expand Down
Expand Up @@ -20,7 +20,7 @@
* Created by Paul Tsouchlos
*/
public enum MimeType {
NONE(""), JPEG("image/jpeg"), PNG("image/png"), XML("application/xml"),
JPEG("image/jpeg"), PNG("image/png"), XML("application/xml"),
XLS("application/vnd.ms-excel"), XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
DOC("application/msword"), DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
HTML("text/html"), TXT("text/plain"), PDF("application/pdf");
Expand Down

0 comments on commit 35c256f

Please sign in to comment.