99
1010<img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/ReadmeEmojiBadges/HackerCatEmoji-v1.png " /><img src =" https://badges.frapsoft.com/os/v2/open-source-175x29.png?v=103 " /><img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/ReadmeEmojiBadges/tRUTH.png " />
1111
12- #### A polite request from the developer
13-
14- In the event that this library and the documentation of new Android features this code provides is useful, please
15- :star ::star ::star ::star ::star : my application. I have taken my free time on this project to
16- * Hack for freedom with free software (TM, so to speak, as I like to say it)* by providing users and
17- fellow Android developers alike with a quality code base.
18- It will make me just * so happy* all over if you all that appreciate this source code contribution as much as I have writing it
19- can help me reach out to my first ** 100-star** repository on GitHub.
20-
2112## About the library
2213
2314A file and directory chooser widget for Android that focuses on presenting an easy to configure lightweight UI.
@@ -42,17 +33,18 @@ media file processing minimal.
4233### Feature set
4334
4435Key features in the library include the following:
45- * Easy to configure theming and UI display settings including icons and color choices
36+ * Easy to configure themes and UI display settings including icons and color choices
37+ (see [ docs link below] ( https://github.com/maxieds/AndroidFileChooserLight#configuring-the-client-theme-and-ui-look-and-feel-properties ) )
4638* Simple actions and extendable Java interface to select and filter files/directories
39+ (see [ docs link below] ( https://github.com/maxieds/AndroidFileChooserLight#extending-file-types-for-filtering-and-sorting-purposes-in-the-picker-ui ) )
4740* Allows client code to access many standard file system types on the Android device without
48- complicated procedures and permissions headaches inherited by the new Android 11 policy changes
49- * Exceptions and errors thrown at runtime extend the standard Java `` RuntimeException `` class for
50- ease of handling. Many of these exceptions are just wrappers around data returned by a newly
51- spawned file picker activity and do not necessarily indicate errors in the file selection process.
41+ complicated procedures and permissions issues inherited by the new Android 11 policy changes
5242
5343### Screenshots of the library in action (Default theme)
5444
55- <img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201112-052224.png " width =" 250 " /> <img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201113-134724.png " width =" 250 " /> <img src =" https://raw.githubusercontent.com/maxieds/AndroidFilePickerLight/master/Screenshots/SampleApplicationDemo-ProgressBarDisplay.png " width =" 250 " />
45+ <img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201112-052224.png " width =" 250 " />
46+ <img src =" https://raw.githubusercontent.com/maxieds/AndroidFileChooserLight/master/Screenshots/WorkingUI-Screenshot_20201113-134724.png " width =" 250 " />
47+ <img src =" https://raw.githubusercontent.com/maxieds/AndroidFilePickerLight/master/Screenshots/SampleApplicationDemo-ProgressBarDisplay.png " width =" 250 " />
5648
5749## Including the library for use in a client Android application
5850
@@ -63,9 +55,6 @@ library can be included in the client Android application:
6355* Update the project * AndroidManifest.xml* file to extend the documents provider,
6456 request required permissions, and setup some helpful legacy file handling options for devices
6557 targeting Android platforms with SDK < Android OS 11.
66-
67- Examples of using the library to pick files and directories from client Java code is also
68- included in the detailed documentation in the next section.
6958
7059### Application build.gradle modifications
7160
@@ -95,16 +84,6 @@ allprojects {
9584
9685### Project manifest modifications
9786
98- Near the top of the project manifest file, append the following permissions-related
99- statements:
100- ``` xml
101- <!-- Core storage permissions required: -->
102- <uses-permission android : name =" android.permission.WRITE_EXTERNAL_STORAGE" android : required =" true" />
103- <uses-permission android : name =" android.permission.READ_EXTERNAL_STORAGE" android : required =" true" />
104- <uses-permission android : name =" android.permission.MANAGE_EXTERNAL_STORAGE" android : required =" false" />
105- <uses-permission android : name =" android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION" android : required =" false" />
106- <uses-permission android : name =" android.permission.INTERNET" android : required =" false" />
107- ```
10887For applications targeting so-called legacy platforms, that is Android devices where the new
10988Android 11 storage management options are not explicitly required, it is
11089recommended for compatibility sake by the Google developer docs
@@ -263,64 +242,6 @@ FileChooserBuilder fcBuilderConfig = new FileChooserBuilder.getDirectoryChooserI
263242 .setRecyclerViewPrefetchThreadUpdateDelay(550L )
264243```
265244
266- ### Extending file types for filtering and sorting purposes in the picker UI
267-
268- Many other good file chooser libraries for Android implement extendable ways for users to filter,
269- select and sort the files that are presented to the user. We choose to offer the same extendable
270- functionality here while staying tightly coupled with more Java language standard constructs.
271-
272- The following is an example of how to create a custom file filter for use with this library.
273- The full interface specification is found in the source file
274- [ FileFilter.java] ( https://github.com/maxieds/AndroidFileChooserLight/blob/master/AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileFilter.java#L35 ) :
275- ``` java
276- public static class FileFilterByRegex extends FileFilterBase {
277- private Pattern patternSpec;
278- public FileFilterByRegex (String regexPatternSpec , boolean inclExcl ) {
279- patternSpec = Pattern . compile(regexPatternSpec);
280- setIncludeExcludeMatchesOption(inclExcl);
281- }
282- public boolean fileMatchesFilter (String fileAbsName ) {
283- if (patternSpec. matcher(fileAbsName). matches()) {
284- return includeExcludeMatches == INCLUDE_FILES_IN_FILTER_PATTERN ;
285- }
286- return includeExcludeMatches == EXCLUDE_FILES_IN_FILTER_PATTERN ;
287- }
288- }
289- ```
290- The main interface in the base class for the example above extends the stock Java `` FilenameFilter ``
291- interface. There is a difference in what our derived classes must implement. Namely, subject to the
292- next defines, the code can decide whether to include or exclude the file matches based on whether the
293- filename filter matches the user specified pattern:
294- ``` java
295- static final boolean INCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . INCLUDE_FILES_IN_FILTER_PATTERN ;
296- static final boolean EXCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . EXCLUDE_FILES_IN_FILTER_PATTERN ;
297- ```
298- Similarly, an overloaded sorting class that can be extended is sampled below:
299- ``` java
300- public static class FileItemsSortFunc implements Comparator<File > {
301- public File [] sortFileItemsList (File [] folderContentsList ) {
302- Arrays . sort(folderContentsList, this );
303- return folderContentsList;
304- }
305- @Override
306- public int compare (File f1 , File f2 ) {
307- // default is standard lexicographical ordering (override the compare functor base classes for customized sorting):
308- return f1. getAbsolutePath(). compareTo(f2. getAbsolutePath());
309- }
310- }
311- ```
312- Here is an example of how to utilize these customized classes with the library's core
313- `` FileChooserBuilder `` class instances:
314- ``` java
315- FileChooserBuilder fcConfig = new FileChooserBuilder ();
316- fcConfig. setFilesListSortCompareFunction(FileFilter . FileItemsSortFunc );
317-
318- // Some defaults for convenience:
319- fcConfig. filterByDefaultFileTypes(List<DefaultFileTypes > fileTypesList, boolean includeExcludeInList);
320- fcConfig. filterByMimeTypes(List<String > fileTypesList, boolean includeExcludeInList);
321- fcConfig. filterByRegex(String fileFilterPattern, boolean includeExcludeInList);
322- ```
323-
324245### Configuring the client theme and UI look-and-feel properties
325246
326247Now that we have the scheme for passing resources to the library to skin/color/custom theme its UI down,
@@ -374,21 +295,79 @@ fcbConfig.setCustomThemeStylizerConfig(customThemeBuilder);
374295```
375296Alternately, the exact colors for the theme can be specified explicitly using:
376297``` java
377- public static final int COLOR_PRIMARY = 0 ;
378- public static final int COLOR_PRIMARY_DARK = 1 ;
298+ public static final int COLOR_PRIMARY = 0 ; /* The main RecyclerView (file items list) background color */
299+ public static final int COLOR_PRIMARY_DARK = 1 ; /* Text color of the upper paths folder history views */
379300public static final int COLOR_PRIMARY_VERY_DARK = 2 ;
380- public static final int COLOR_ACCENT = 3 ;
381- public static final int COLOR_ACCENT_MEDIUM = 4 ;
382- public static final int COLOR_ACCENT_LIGHT = 5 ;
383- public static final int COLOR_TOOLBAR_BG = 6 ;
384- public static final int COLOR_TOOLBAR_FG = 7 ;
385- public static final int COLOR_TOOLBAR_NAV = 8 ;
386- public static final int COLOR_TOOLBAR_DIVIDER = 9 ;
301+ public static final int COLOR_ACCENT = 3 ; /* Text color of the file items list */
302+ public static final int COLOR_ACCENT_MEDIUM = 4 ; /* Text color of the Done/Cancel action buttons */
303+ public static final int COLOR_ACCENT_LIGHT = 5 ; /* Background color of the Done/Cancel action buttons navigation bar */
304+ public static final int COLOR_TOOLBAR_BG = 6 ; /* The darker background color of the topmost toolbar */
305+ public static final int COLOR_TOOLBAR_FG = 7 ; /* The lighter text color of the topmost toolbar */
306+ public static final int COLOR_TOOLBAR_NAV = 8 ; /* The background of the navigate to stock paths navigation bar (prefixed with "Navigate: ") */
307+ public static final int COLOR_TOOLBAR_DIVIDER = 9 ; /* The in-between divider color separating the top toolbar and lower navigation */
387308
388309CustomThemeBuilder customThemeBuilder = new CustomThemeBuilder ((Activity ) myActivityInst)
389310 .setThemeColors(@ColorRes int [] colorsList);
390311```
391312
313+ ### Extending file types for filtering and sorting purposes in the picker UI
314+
315+ Many other good file chooser libraries for Android implement extendable ways for users to filter,
316+ select and sort the files that are presented to the user. We choose to offer the same extendable
317+ functionality here while staying tightly coupled with more Java language standard constructs.
318+
319+ The following is an example of how to create a custom file filter for use with this library.
320+ The full interface specification is found in the source file
321+ [ FileFilter.java] ( https://github.com/maxieds/AndroidFileChooserLight/blob/master/AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileFilter.java#L35 ) :
322+ ``` java
323+ public static class FileFilterByRegex extends FileFilterBase {
324+ private Pattern patternSpec;
325+ public FileFilterByRegex (String regexPatternSpec , boolean inclExcl ) {
326+ patternSpec = Pattern . compile(regexPatternSpec);
327+ setIncludeExcludeMatchesOption(inclExcl);
328+ }
329+ public boolean fileMatchesFilter (String fileAbsName ) {
330+ if (patternSpec. matcher(fileAbsName). matches()) {
331+ return includeExcludeMatches == INCLUDE_FILES_IN_FILTER_PATTERN ;
332+ }
333+ return includeExcludeMatches == EXCLUDE_FILES_IN_FILTER_PATTERN ;
334+ }
335+ }
336+ ```
337+ The main interface in the base class for the example above extends the stock Java `` FilenameFilter ``
338+ interface. There is a difference in what our derived classes must implement. Namely, subject to the
339+ next defines, the code can decide whether to include or exclude the file matches based on whether the
340+ filename filter matches the user specified pattern:
341+ ``` java
342+ static final boolean INCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . INCLUDE_FILES_IN_FILTER_PATTERN ;
343+ static final boolean EXCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . EXCLUDE_FILES_IN_FILTER_PATTERN ;
344+ ```
345+ Similarly, an overloaded sorting class that can be extended is sampled below:
346+ ``` java
347+ public static class FileItemsSortFunc implements Comparator<File > {
348+ public File [] sortFileItemsList (File [] folderContentsList ) {
349+ Arrays . sort(folderContentsList, this );
350+ return folderContentsList;
351+ }
352+ @Override
353+ public int compare (File f1 , File f2 ) {
354+ // default is standard lexicographical ordering (override the compare functor base classes for customized sorting):
355+ return f1. getAbsolutePath(). compareTo(f2. getAbsolutePath());
356+ }
357+ }
358+ ```
359+ Here is an example of how to utilize these customized classes with the library's core
360+ `` FileChooserBuilder `` class instances:
361+ ``` java
362+ FileChooserBuilder fcConfig = new FileChooserBuilder ();
363+ fcConfig. setFilesListSortCompareFunction(FileFilter . FileItemsSortFunc );
364+
365+ // Some defaults for convenience:
366+ fcConfig. filterByDefaultFileTypes(List<DefaultFileTypes > fileTypesList, boolean includeExcludeInList);
367+ fcConfig. filterByMimeTypes(List<String > fileTypesList, boolean includeExcludeInList);
368+ fcConfig. filterByRegex(String fileFilterPattern, boolean includeExcludeInList);
369+ ```
370+
392371### Misc other useful utilities and customizations bundled with the main library
393372
394373#### Displaying a visual linear bar style progress bar for slow directory loads
@@ -413,7 +392,7 @@ NFC tags on Android (see [the MFCToolLibrary](https://github.com/maxieds/MifareC
413392its demo application). The core of the progress bar is
414393shown by periodically posting Toast messages with a custom layout `` View `` .
415394
416- #### A custom (mostly all config options inclusive) GradientDrawable builder class (TODO)
395+ #### A custom (mostly all config options inclusive) GradientDrawable builder class (TODO -- Reserved for future uses )
417396
418397The specifications (mostly collected as compendia from Android reference manuals) are reproduced as follows:
419398``` java
0 commit comments