1010
1111<img src =" https://badges.frapsoft.com/os/v2/open-source-175x29.png?v=103 " />
1212
13+ #### A polite request from the developer
14+
15+ In the event that this library and the documentation of new Android features this code provides is useful, please
16+ :star ::star ::star ::star ::star : my application. I have taken my free time on this project to
17+ * Hack for freedom with free software (TM, so to speak, as I like to say it)* by providing users and
18+ fellow Android developers alike with a quality code base.
19+ 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
20+ can help me reach out to my first ** 100-star** repository on GitHub.
21+
22+ [ ![ HitCount] ( http://hits.dwyl.com/maxieds/AndroidFileChooserLight.svg )] ( http://hits.dwyl.com/maxieds/AndroidFileChooserLight )
23+
1324## About the library
1425
1526A file and directory chooser widget for Android that focuses on presenting an easy to configure lightweight UI.
@@ -44,11 +55,9 @@ Key features in the library include the following:
4455
4556### Screenshots of the library in action (Default theme)
4657
47- <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 =" " width =" 250 " />
48-
49- <img src =" " width =" 250 " /><img src =" " width =" 250 " /><img src =" " width =" 250 " />
58+ <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 " />
5059
51- ## Including the library in an Android application
60+ ## Including the library for use in a client Android application
5261
5362There are a couple of quickstart items covered in the sections below to handle before this
5463library can be included in the client Android application:
@@ -121,6 +130,9 @@ that the application set the option
121130 <!-- Complete the internals of the application tag (activities, etc.) below -->
122131</application >
123132```
133+ Note that unlike some samples to get other Android libraries up and running, there is no need to define references
134+ to the custom `` FileProvider `` implemented by the library. It is sufficient to just use the standardized wrappers
135+ to launch a new `` FileChooserActivity `` instance and use the file picker functionality bundled within that interface.
124136
125137## Sample client Java source code
126138
@@ -154,12 +166,27 @@ the results:
154166
155167This is a quick method to select a file and/or directory picked by the user:
156168``` java
157- public void actionButtonLaunchSingleFilePickerActivity(View btnView) {
169+ public void actionButtonLaunchSingleFilePickerActivity(View btnView) {
158170 FileChooserBuilder fpInst = FileChooserBuilder . getDirectoryChooserInstance(this );
159171 fpInst. showHidden(true );
172+ fpInst. setPickerInitialPath(FileChooserBuilder . BaseFolderPathType . BASE_PATH_DEFAULT );
173+ fpInst. launchFilePicker();
174+ }
175+ public void actionButtonLaunchSingleFilePickerActivity(View btnView) {
176+ FileChooserBuilder fpInst = FileChooserBuilder . getSingleFilePickerInstance(this );
177+ fpInst. showHidden(true );
160178 fpInst. setPickerInitialPath(FileChooserBuilder . BaseFolderPathType . BASE_PATH_TYPE_EXTERNAL_FILES_SCREENSHOTS );
161179 fpInst. launchFilePicker();
162180 }
181+ public void actionButtonLaunchOmnivorousMultiPickerActivity(View btnView) {
182+ FileChooserBuilder fpInst = new FileChooserBuilder (this );
183+ fpInst. setSelectionMode(FileChooserBuilder . SelectionModeType . SELECT_OMNIVORE );
184+ fpInst. setSelectMultiple(5 );
185+ fpInst. setActionCode(FileChooserBuilder . ACTIVITY_CODE_SELECT_MULTIPLE_FILES );
186+ fpInst. showHidden(true );
187+ fpInst. setPickerInitialPath(FileChooserBuilder . BaseFolderPathType . BASE_PATH_TYPE_EXTERNAL_FILES_DOWNLOADS );
188+ fpInst. launchFilePicker();
189+ }
163190```
164191
165192### Detailed list of non-display type options
@@ -173,15 +200,70 @@ These can be set using the ``AndroidFilePickerLight.Builder`` class as follows:
173200
174201### Extending file types for filtering and sorting purposes in the picker UI
175202
203+ Many other good file chooser libraries for Android implement extendable ways for users to filter,
204+ select and sort the files that are presented to the user. We choose to offer the same extendable
205+ functionality here while staying tightly coupled with more Java language standard constructs.
176206
207+ The following is an example of how to create a custom file filter for use with this library.
208+ The full interface specification is found in the source file
209+ [ FileFilter.java] ( https://github.com/maxieds/AndroidFileChooserLight/blob/master/AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileFilter.java#L35 ) :
210+ ``` java
211+ public static class FileFilterByRegex extends FileFilterBase {
212+ private Pattern patternSpec;
213+ public FileFilterByRegex (String regexPatternSpec , boolean inclExcl ) {
214+ patternSpec = Pattern . compile(regexPatternSpec);
215+ setIncludeExcludeMatchesOption(inclExcl);
216+ }
217+ public boolean fileMatchesFilter (String fileAbsName ) {
218+ if (patternSpec. matcher(fileAbsName). matches()) {
219+ return includeExcludeMatches == INCLUDE_FILES_IN_FILTER_PATTERN ;
220+ }
221+ return includeExcludeMatches == EXCLUDE_FILES_IN_FILTER_PATTERN ;
222+ }
223+ }
224+ ```
225+ The main interface in the base class for the example above extends the stock Java `` FilenameFilter ``
226+ interface. There is a difference in what our derived classes must implement. Namely, subject to the
227+ next defines, the code can decide whether to include or exclude the file matches based on whether the
228+ filename filter matches the user specified pattern:
229+ ``` java
230+ static final boolean INCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . INCLUDE_FILES_IN_FILTER_PATTERN ;
231+ static final boolean EXCLUDE_FILES_IN_FILTER_PATTERN = FileChooserBuilder . EXCLUDE_FILES_IN_FILTER_PATTERN ;
232+ ```
233+ Similarly, an overloaded sorting class that can be extended is sampled below:
234+ ``` java
235+ public static class FileItemsSortFunc implements Comparator<File > {
236+ public File [] sortFileItemsList (File [] folderContentsList ) {
237+ Arrays . sort(folderContentsList, this );
238+ return folderContentsList;
239+ }
240+ @Override
241+ public int compare (File f1 , File f2 ) {
242+ // default is standard lexicographical ordering (override the compare functor base classes for customized sorting):
243+ return f1. getAbsolutePath(). compareTo(f2. getAbsolutePath());
244+ }
245+ }
246+ ```
247+ Here is an example of how to utilize these customized classes with the library's core
248+ `` FileChooserBuilder `` class instances:
249+ ``` java
250+ FileChooserBuilder fcConfig = new FileChooserBuilder ();
251+ fcConfig. setFilesListSortCompareFunction(FileFilter . FileItemsSortFunc );
252+ // TODO
253+
254+ // Some defaults for convenience:
255+ fcConfig. filterByDefaultFileTypes(List<DefaultFileTypes > fileTypesList, boolean includeExcludeInList);
256+ fcConfig. filterByMimeTypes(List<String > fileTypesList, boolean includeExcludeInList);
257+ fcConfig. filterByRegex(String fileFilterPattern, boolean includeExcludeInList);
258+ ```
177259
178260### Configuring the client theme and UI look-and-feel properties
179261
180- #### Basic example (quickstart guide to using the file picker library)
181-
182-
183-
262+ This part of the library, while a primary motivator for writing it and a key feature it aims to have,
263+ is still under active development. I will add in documentation showing how to customize the file
264+ picker themes (color schemes, icons, and other properties) as they become ready to use.
184265
266+ #### Basic example (quickstart guide to using the file picker library)
185267
186268#### Full example (detailed usage of the current custom theme/UI display options)
187269
@@ -223,9 +305,7 @@ This functionality may be useful at some point for those willing to extend this
223305custom external file providers, e.g., to read and recurse into directories on Dropbox or GitHub.
224306I have a simple visual Toast-like display that can be updated and/or canceled in real time to
225307let the user know that the directory is loading and that the client application is just "thinking"
226- (as opposed to freezing with a runtime error). The stock progress bar looks something like the following screenshot:
227-
228- <img src =" https://raw.githubusercontent.com/maxieds/AndroidFilePickerLight/master/Screenshots/SampleApplicationDemo-ProgressBarDisplay.png " width =" 250 " />
308+ (as opposed to freezing with a runtime error).
229309
230310To invoke this progress bar display in realtime, consider calling the following code examples:
231311``` java
@@ -241,63 +321,3 @@ its demo application). The core of the progress bar is
241321shown by periodically posting Toast messages with a custom layout `` View `` . Please post a new issue message
242322if anyone using this library in their own application finds this useful, or amusing too.
243323
244- #### Overriding the default file and directory sorting (TODO)
245-
246- An example of how to do this is already seen by glancing through the sources.
247- In particular, we define an extendable base class as follows:
248- ``` java
249- public static class FileItemsSortFunc implements Comparator<File > {
250- public File [] sortFileItemsList (File [] folderContentsList ) {
251- Arrays . sort(folderContentsList, this );
252- return folderContentsList;
253- }
254- @Override
255- public int compare (File f1 , File f2 ) {
256- // default is standard lexicographical ordering (override the compare functor base classes for customized sorting):
257- return f1. getAbsolutePath(). compareTo(f2. getAbsolutePath());
258- }
259- }
260- ```
261- Subclasses that override the method above are free to sort the file
262- contents in the order that they are best displayed in the client application.
263- Some examples would be to override the default of placing directories at the top of the
264- files list, to perform a case-insensitive lexicographical sort (like happens on many Linux),
265- or otherwise to prioritize the file rankings where the most importantly valued presentations
266- are shown first.
267-
268- Note that in the source the custom objects to filter (match, then include/exclude) the full
269- directory listings, and then sort those files that remain are applied together. See, for example,
270- the next code:
271- ``` java
272- public static class FileFilterByRegex extends FileFilterBase {
273- private Pattern patternSpec;
274- public FileFilterByRegex (String regexPatternSpec , boolean inclExcl ) {
275- patternSpec = Pattern . compile(regexPatternSpec);
276- setIncludeExcludeMatchesOption(inclExcl);
277- }
278- public boolean fileMatchesFilter (String fileAbsName ) {
279- if (patternSpec. matcher(fileAbsName). matches()) {
280- return includeExcludeMatches == INCLUDE_FILES_IN_FILTER_PATTERN ;
281- }
282- return includeExcludeMatches == EXCLUDE_FILES_IN_FILTER_PATTERN ;
283- }
284- }
285- ```
286-
287- #### Extending the inclusion/exclusion mechanism of files by type
288-
289- The specification (by Java interface and a few utility derived instances) are found in the
290- library source file `` FileFilter.java `` . The bulk of the interface is reproduced as
291- follows:
292- ``` java
293- public interface FileFilterInterface {
294-
295- static final boolean INCLUDE_FILES_IN_FILTER_PATTERN = FilePickerBuilder . INCLUDE_FILES_IN_FILTER_PATTERN ;
296- static final boolean EXCLUDE_FILES_IN_FILTER_PATTERN = FilePickerBuilder . EXCLUDE_FILES_IN_FILTER_PATTERN ;
297-
298- void setIncludeExcludeMatchesOption (boolean includeExcludeParam );
299- boolean includeFileInSearchResults (FileTypes .FileType fileItem );
300- boolean fileMatchesFilter (FileTypes .FileType fileItem );
301-
302- }
303- ```
0 commit comments