23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/font/aller.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
15 |
16 |
17 |
21 |
22 |
23 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/filepicker/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/filepicker/src/main/res/drawable/ic_folder.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/filepicker/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: file('publish.gradle')
3 |
4 | ext {
5 | publishedGroupId = 'com.rmartinper'
6 | orgName = 'rmartinper'
7 | artifact = 'filepicker'
8 |
9 | libraryName = 'File Picker'
10 | libraryDescription = 'Android Library to pick Files from Device Storage.'
11 | libraryVersion = '1.0'
12 | }
13 |
14 | android {
15 | compileSdkVersion 30
16 | buildToolsVersion '30.0.1'
17 | defaultConfig {
18 | minSdkVersion 15
19 | targetSdkVersion 30
20 | versionCode 1
21 | versionName '1.0'
22 | }
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | lintOptions {
30 | abortOnError false
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
36 | }
--------------------------------------------------------------------------------
/filepicker/src/main/res/layout/dialog_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
22 |
23 |
26 |
--------------------------------------------------------------------------------
/filepicker/src/main/res/drawable/ic_folder_opened.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 | * Created by Raul Martin on 22-07-2020.
13 | *
14 | */
15 |
16 | /* Class to filter the list of files.
17 | */
18 | public class ExtensionFilter implements FileFilter {
19 | private final String[] validExtensions;
20 | private DialogProperties properties;
21 |
22 | public ExtensionFilter(DialogProperties properties) {
23 | String[] extensions = properties.getExtensions();
24 | if(extensions != null) {
25 | this.validExtensions = extensions;
26 | } else {
27 | this.validExtensions = new String[]{""};
28 | }
29 | this.properties = properties;
30 | }
31 |
32 | /**Function to filter files based on defined rules.
33 | */
34 | @Override
35 | public boolean accept(File file) {
36 | //All directories are added in the least that can be read by the Application
37 | if(file.isDirectory() && file.canRead()) {
38 | return true;
39 | } else if(properties.getSelectionType() == DialogConfigs.DIR_SELECT) {
40 | /* True for files, If the selection type is Directory type, ie.
41 | * Only directory has to be selected from the list, then all files are
42 | * ignored.
43 | */
44 | return false;
45 | } else {
46 | /* Check whether name of the file ends with the extension. Added if it
47 | * does.
48 | */
49 | String name = file.getName().toLowerCase(Locale.getDefault());
50 | for(String ext: validExtensions) {
51 | if(name.endsWith(ext)) {
52 | return true;
53 | }
54 | }
55 | }
56 | return false;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/filepicker/src/main/java/com/rmartinper/filepicker/model/DialogConfigs.java:
--------------------------------------------------------------------------------
1 | package com.rmartinper.filepicker.model;
2 |
3 | /**
4 | *
5 | * Created by Raul Martin on 02-07-2020.
6 | *
7 | */
8 |
9 | /* Helper class for setting properties of Dialog.
10 | */
11 | public abstract class DialogConfigs {
12 | /* SELECTION_MODES */
13 |
14 | /* SINGLE_MODE specifies that a single File/Directory has to be selected
15 | * from the list of Files/Directories. It is the default Selection Mode.
16 | */
17 | public static final int SINGLE_MODE = 0;
18 |
19 | /* MULTI_MODE specifies that multiple Files/Directories has to be selected
20 | * from the list of Files/Directories.
21 | */
22 | public static final int MULTI_MODE = 1;
23 |
24 | /* SELECTION_TYPES */
25 |
26 | /* FILE_SELECT specifies that from list of Files/Directories a File has to
27 | * be selected. It is the default Selection Type.
28 | */
29 | public static final int FILE_SELECT = 0;
30 |
31 | /* DIR_SELECT specifies that from list of Files/Directories a Directory has to
32 | * be selected.
33 | */
34 | public static final int DIR_SELECT = 1;
35 |
36 | /* FILE_AND_DIR_SELECT specifies that from list of Files/Directories both
37 | * can be selected.
38 | */
39 | public static final int FILE_AND_DIR_SELECT = 2;
40 |
41 | /* PARENT_DIRECTORY */
42 | public static final String DIRECTORY_SEPERATOR = "/";
43 | public static final String MOUNT_POINT = "mnt";
44 | public static final String SDCARD_DIR = "sdcard";
45 |
46 | /* DEFAULT_DIR is the default mount point of the device. It is the default
47 | * mount point.
48 | */
49 | public static final String DEFAULT_DIR = DIRECTORY_SEPERATOR + MOUNT_POINT;
50 |
51 | /* EXTERNAL_DIR is the external storage directory of the device.
52 | */
53 | public static final String EXTERNAL_DIR = DIRECTORY_SEPERATOR + SDCARD_DIR;
54 |
55 | /* Constructs a new DialogConfigs.
56 | */
57 | private DialogConfigs() {
58 | super();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/filepicker/src/main/res/layout-v21/dialog_file_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
30 |
31 |
38 |
39 |
45 |
46 |
47 |
48 |
56 |
57 |
--------------------------------------------------------------------------------
/filepicker/src/main/res/layout/dialog_file_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
32 |
33 |
40 |
41 |
47 |
48 |
49 |
50 |
59 |
60 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/filepicker/src/main/res/layout/dialog_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
25 |
26 |
30 |
31 |
40 |
41 |
51 |
52 |
53 |
54 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/filepicker/src/main/java/com/rmartinper/filepicker/model/FileListItem.java:
--------------------------------------------------------------------------------
1 | package com.rmartinper.filepicker.model;
2 |
3 | /*
9 | */
10 |
11 | /* Descriptor class to define properties of the Dialog. Actions are performed upon
12 | * these Properties
13 | */
14 | public class DialogProperties {
15 | /** Selection Mode defines whether a single of multiple Files/Directories
16 | * have to be selected.
17 | *
18 | * SINGLE_MODE and MULTI_MODE are the two selection modes, See DialogConfigs
19 | * for more info. Set to SINGLE_MODE as default value by constructor.
20 | */
21 | private int selectionMode;
22 |
23 | /** Selection Type defines that whether a File/Directory or both of these has
24 | * to be selected.
25 | *
26 | * FILE_SELECT ,DIR_SELECT, FILE_AND_DIR_SELECT are the three selection modes,
27 | * See DialogConfigs for more info. Set to FILE_SELECT as default value by constructor.
28 | */
29 | private int selectionType;
30 |
31 | /** The Parent/Root Directory. List of Files are populated from here. Can be set
32 | * to any readable directory. /sdcard is the default location.
33 | *
34 | * Eg. /sdcard
35 | * Eg. /mnt
36 | */
37 | private File root;
38 |
39 | /** The Directory is used when Root Directory is not readable or accessible.
40 | * /sdcard is the default location.
41 | *
42 | * Eg. /sdcard
43 | * Eg. /mnt
44 | */
45 | private File errorDir;
46 |
47 | /** The Directory can be used as an offset. It is the first directory that is
48 | * shown in dialog. Consider making it Root's sub-directory.
49 | *
50 | * Eg. Root: /sdcard
51 | * Eg. Offset: /sdcard/Music/Country
52 | */
53 | private File offset;
54 |
55 | /** An Array of String containing extensions, Files with only that will be shown.
56 | * Others will be ignored. Set to null as default value by constructor.
57 | * Eg. String ext={"jpg","jpeg","png","gif"};
58 | */
59 | private String[] extensions;
60 |
61 | /** The indicator of if the hidden files are shown. If it is false, they are shown.
62 | * Otherwise, they are not shown. Set to false as default value by constructor.
63 | */
64 | private boolean showHiddenFiles;
65 |
66 | /**
67 | * Gets the selection mode of these Properties and returns it.
68 | *
69 | * @return the selection mode of these Properties.
70 | */
71 | public int getSelectionMode() {
72 | return selectionMode;
73 | }
74 |
75 | /**
76 | * Sets the new selection mode of these Properties.
77 | *
78 | * @param selectionMode the new selection mode of these Properties.
79 | */
80 | public void setSelectionMode(int selectionMode) {
81 | this.selectionMode = selectionMode;
82 | }
83 |
84 | /**
85 | * Gets the selection type of these Properties and returns it.
86 | *
87 | * @return the selection mode of these Properties.
88 | */
89 | public int getSelectionType() {
90 | return selectionType;
91 | }
92 |
93 | /**
94 | * Sets the new selection type of these Properties.
95 | *
96 | * @param selectionType the new selection type of these Properties.
97 | */
98 | public void setSelectionType(int selectionType) {
99 | this.selectionType = selectionType;
100 | }
101 |
102 | /**
103 | * Gets the root of these Properties and returns it.
104 | *
105 | * @return the root of these Properties.
106 | */
107 | public File getRoot() {
108 | return root;
109 | }
110 |
111 | /**
112 | * Sets the new root of these Properties.
113 | *
114 | * @param root the new root of these Properties.
115 | */
116 | public void setRoot(File root) {
117 | this.root = root;
118 | }
119 |
120 | /**
121 | * Gets the error directory of these Properties and returns it.
122 | *
123 | * @return the error directory of these Properties.
124 | */
125 | public File getErrorDir() {
126 | return errorDir;
127 | }
128 |
129 | /**
130 | * Sets the new error directory of these Properties.
131 | *
132 | * @param errorDir the new error directory of these Properties.
133 | */
134 | public void setErrorDir(File errorDir) {
135 | this.errorDir = errorDir;
136 | }
137 |
138 | /**
139 | * Gets the offset of these Properties and returns it.
140 | *
141 | * @return the offset of these Properties.
142 | */
143 | public File getOffset() {
144 | return offset;
145 | }
146 |
147 | /**
148 | * Sets the new offset of these Properties.
149 | *
150 | * @param offset the new offset of these Properties.
151 | */
152 | public void setOffset(File offset) {
153 | this.offset = offset;
154 | }
155 |
156 | /**
157 | * Gets the extensions of these Properties and returns it.
158 | *
159 | * @return the extensions of these Properties.
160 | */
161 | public String[] getExtensions() {
162 | return extensions;
163 | }
164 |
165 | /**
166 | * Sets the new extensions of these Properties.
167 | *
168 | * @param extensions the new extensions of these Properties.
169 | */
170 | public void setExtensions(String[] extensions) {
171 | this.extensions = extensions;
172 | }
173 |
174 | /**
175 | * Gets the indicator of if the hidden files are shown of these Properties and returns it.
176 | *
177 | * @return the indicator of if the hidden files are shown of these Properties.
178 | */
179 | public boolean areHiddenFilesShown() {
180 | return showHiddenFiles;
181 | }
182 |
183 | /**
184 | * Sets the new indicator of if the hidden files are shown of these Properties.
185 | *
186 | * @param showHiddenFiles the new indicator of if the hidden files are shown of these Properties.
187 | */
188 | public void setHiddenFilesShown(boolean showHiddenFiles) {
189 | this.showHiddenFiles = showHiddenFiles;
190 | }
191 |
192 | public DialogProperties() {
193 | this(false);
194 | }
195 |
196 | public DialogProperties(boolean isExternal) {
197 | selectionMode = DialogConfigs.SINGLE_MODE;
198 | selectionType = DialogConfigs.FILE_SELECT;
199 |
200 | if (isExternal) {
201 | root = new File(DialogConfigs.EXTERNAL_DIR);
202 | errorDir = new File(DialogConfigs.EXTERNAL_DIR);
203 | offset = new File(DialogConfigs.EXTERNAL_DIR);
204 | } else {
205 | root = new File(DialogConfigs.DEFAULT_DIR);
206 | errorDir = new File(DialogConfigs.DEFAULT_DIR);
207 | offset = new File(DialogConfigs.DEFAULT_DIR);
208 | }
209 |
210 | extensions = null;
211 | showHiddenFiles = false;
212 | }
213 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # File Picker  [](https://opensource.org/licenses/Apache-2.0) [](https://jitpack.io/#Ru95Gasol/File-Picker)
4 | Android Library to select Files/Directories from Device Storage.
5 |
6 | ## Features
7 |
8 | * Easy to Implement.
9 | * No permissions required.
10 | * File, Directory Selection.
11 | * Single or Multiple File/Directory Selection.
12 | * Internationalization: Arabic, Bengali, Catalan, Chinese, Czech, Dutch, English, French, German, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean, Polish, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian and Urdu.
13 |
14 | ## Installation
15 |
16 | Add it in your root build.gradle at the end of repositories:
17 |
18 | allprojects {
19 | repositories {
20 | ...
21 | maven { url 'https://jitpack.io' }
22 | }
23 | }
24 | Step 2. Add the dependency
25 |
26 | dependencies {
27 | implementation 'com.github.Ru95Gasol:File-Picker:1.0'
28 | }
29 |
30 | ## Usage
31 |
32 | **If you are targeting Android 10 or higher. Set this to your manifest**
33 | ```
34 |
35 |
37 |
39 | ......
40 |
41 |
42 | ```
43 |
44 | ## FilePickerDialog
45 | 1. Start by creating an instance of `DialogProperties`.
46 |
47 | ```java
48 | DialogProperties properties = new DialogProperties();
49 | DialogProperties properties = new DialogProperties(isExternal: false or true);
50 | ```
51 |
52 | Note: If you pass false to the second constructor is like calling the first constructor and loads the default directory, if you pass true loads the external storage directory.
53 |
54 | Now 'DialogProperties' has certain parameters.
55 |
56 | 2. Assign values to each Dialog Property using `DialogConfig` class.
57 |
58 | ```java
59 | properties.setSelectionMode(DialogConfigs.SINGLE_MODE or DialogConfigs.MULTI_MODE);
60 | properties.setSelectionType(DialogConfigs.FILE_SELECT, DialogConfigs.DIR_SELECT or DialogConfigs.FILE_AND_DIR_SELECT);
61 | properties.setRoot(new File(DialogConfigs.DEFAULT_DIR or DialogConfigs.EXTERNAL_DIR));
62 | properties.setErrorDir(new File(DialogConfigs.DEFAULT_DIR or DialogConfigs.EXTERNAL_DIR));
63 | properties.setOffset(new File(DialogConfigs.DEFAULT_DIR or DialogConfigs.EXTERNAL_DIR));
64 | properties.setExtensions(null or new String[]{".ext1", ".ext2"});
65 | properties.setHiddenFilesShown(false or true);
66 | ```
67 |
68 | Note: For the root, error directory, and offset, be sure to pass them valid directory/file paths.
69 |
70 | 3. Next create an instance of `FilePickerDialog`, and pass `Context` and `DialogProperties` references as parameters. Optional: You can change the title of dialog. Default is current directory name. Set the positive button string. Default is Select. Set the negative button string. Defalut is Cancel.
71 |
72 | ```java
73 | FilePickerDialog dialog = new FilePickerDialog(MainActivity.this, properties);
74 | dialog.setTitle("Select a File");
75 | ```
76 |
77 | 4. Next, Attach `DialogSelectionListener` to `FilePickerDialog` as below,
78 | ```java
79 | dialog.setDialogSelectionListener(new DialogSelectionListener() {
80 | @Override
81 | public void onSelectedFilePaths(String[] files) {
82 | //files is the array of the paths of files selected by the Application User.
83 | }
84 | });
85 | ```
86 | An array of paths is returned whenever user press the `select` button`.
87 |
88 | 5. Use ```dialog.show()``` method to show dialog.
89 |
90 | ## NOTE:
91 | Marshmallow and above requests for the permission on runtime. You should override `onRequestPermissionsResult` in Activity/AppCompatActivity class and show the dialog only if permissions have been granted.
92 |
93 | ```java
94 | //Add this method to show Dialog when the required permission has been granted to the app.
95 | @Override
96 | public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
97 | switch (requestCode) {
98 | case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: {
99 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
100 | if(dialog!=null) {
101 | //Show dialog if the read permission has been granted.
102 | dialog.show();
103 | }
104 | } else {
105 | //Permission has not been granted. Notify the user.
106 | Toast.makeText(MainActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show();
107 | }
108 | }
109 | }
110 | }
111 | ```
112 |
113 | That's It. You are good to proceed further.
114 |
115 | ## Screenshot
116 |
117 | ### Select file
118 |
119 | #### Initial dialog at the root
120 |
121 | 
122 |
123 | #### Dialog after opening a folder
124 |
125 | 
126 |
127 | #### Dialog after selecting a file in single mode
128 |
129 | 
130 |
131 | #### Dialog after selecting some files in multi mode
132 |
133 | 
134 |
135 | ### Select folder
136 |
137 | #### Initial dialog at the root
138 |
139 | 
140 |
141 | #### Dialog after opening a folder
142 |
143 | 
144 |
145 | #### Dialog after selecting a folder in single mode
146 |
147 | 
148 |
149 | #### Dialog after selecting some folders in multi mode
150 |
151 | 
152 |
153 | ## License
154 | Copyright (C) 2020 File-Picker
155 |
156 | Licensed under the Apache License, Version 2.0 (the "License");
157 | you may not use this file except in compliance with the License.
158 | You may obtain a copy of the License at
159 |
160 | http://www.apache.org/licenses/LICENSE-2.0
161 |
162 | Unless required by applicable law or agreed to in writing, software
163 | distributed under the License is distributed on an "AS IS" BASIS,
164 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
165 | See the License for the specific language governing permissions and
166 | limitations under the License.
167 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/filepicker/src/main/java/com/rmartinper/filepicker/view/FilePickerDialog.java:
--------------------------------------------------------------------------------
1 | package com.rmartinper.filepicker.view;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.app.Dialog;
6 | import android.content.Context;
7 | import android.graphics.Color;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.view.View;
11 | import android.view.Window;
12 | import android.widget.AdapterView;
13 | import android.widget.Button;
14 | import android.widget.ImageView;
15 | import android.widget.ListView;
16 | import android.widget.TextView;
17 | import android.widget.Toast;
18 |
19 | import androidx.core.content.ContextCompat;
20 |
21 | import com.rmartinper.filepicker.R;
22 | import com.rmartinper.filepicker.controller.DialogSelectionListener;
23 | import com.rmartinper.filepicker.controller.NotifyItemChecked;
24 | import com.rmartinper.filepicker.controller.adapters.FileListAdapter;
25 | import com.rmartinper.filepicker.model.DialogConfigs;
26 | import com.rmartinper.filepicker.model.DialogProperties;
27 | import com.rmartinper.filepicker.model.FileListItem;
28 | import com.rmartinper.filepicker.model.MarkedItemList;
29 | import com.rmartinper.filepicker.utils.ExtensionFilter;
30 | import com.rmartinper.filepicker.utils.Utility;
31 | import com.rmartinper.filepicker.widget.MaterialCheckbox;
32 |
33 | import java.io.File;
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | /**
38 | *
39 | * Created by Raul Martin on 02-07-2020.
40 | *