Giter Club home page Giter Club logo

android-filepicker's Introduction

The project is no longer being maintained.

FilePicker

Super Lite Android Library to select files/directories from Device Storage.

Developed by

Angad Singh (@angads25)

Benchmark:

API

Where to Find:

Download Maven Central Android Arsenal

Read all about internal classes and functions in the wiki.

Features

  • Easy to Implement.
  • No permissions required.
  • Files, Directory Selection.
  • Single or Multiple File selection.

Installation

  • Library is also Available in MavenCentral, So just put this in your app dependencies to use it:
    compile 'com.github.angads25:filepicker:1.1.1'

Usage

FilePickerDialog

  1. Start by creating an instance of DialogProperties.

        DialogProperties properties = new DialogProperties();

    Now 'DialogProperties' has certain parameters.

  2. Assign values to each Dialog Property using DialogConfig class.

        properties.selection_mode = DialogConfigs.SINGLE_MODE;
        properties.selection_type = DialogConfigs.FILE_SELECT;
        properties.root = new File(DialogConfigs.DEFAULT_DIR);
        properties.error_dir = new File(DialogConfigs.DEFAULT_DIR);
        properties.offset = new File(DialogConfigs.DEFAULT_DIR);
        properties.extensions = null;
  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.

        FilePickerDialog dialog = new FilePickerDialog(MainActivity.this,properties);
        dialog.setTitle("Select a File");
  4. Next, Attach DialogSelectionListener to FilePickerDialog as below,

        dialog.setDialogSelectionListener(new DialogSelectionListener() {
            @Override
            public void onSelectedFilePaths(String[] files) {
                //files is the array of the paths of files selected by the Application User.
            }
        });

    An array of paths is returned whenever user press the select button`.

  5. Use dialog.show() method to show dialog.

NOTE:

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.

        //Add this method to show Dialog when the required permission has been granted to the app.
        @Override
        public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) {
            switch (requestCode) {
                case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: {
                    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        if(dialog!=null)
                        {   //Show dialog if the read permission has been granted.
                            dialog.show();
                        }
                    }
                    else {
                        //Permission has not been granted. Notify the user.
                        Toast.makeText(MainActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }
That's It. You are good to proceed further.

FilePickerPreference

  1. Start by declaring FilePickerPreference in your settings xml file as:

       <com.github.angads25.filepicker.view.FilePickerPreference
           xmlns:app="http://schemas.android.com/apk/res-auto"
           android:key="your_preference_key"
           android:title="Pick a Directory"
           android:summary="Just a Summary"
           android:defaultValue="/sdcard:/mnt"
           app:titleText="Select Directories"
           app:error_dir="/mnt"
           app:root_dir="/sdcard"
           app:selection_mode="multi_mode"
           app:selection_type="dir_select"
           app:extensions="txt:pdf:"/>
  2. Implement Preference.OnPreferenceChangeListener to class requiring selected values and Override onPreferenceChange(Preference, Object) method. Check for preference key using Preference reference.

        @Override
        public boolean onPreferenceChange(Preference preference, Object o)
        {   if(preference.getKey().equals("your_preference_key"))
            {   ...
            }
            return false;
        }
  3. Typecast Object o into String Object and use split(String) function in String class to get array of selected files.

        @Override
        public boolean onPreferenceChange(Preference preference, Object o)
        {   if(preference.getKey().equals("your_preference_key"))
            {   String value=(String)o;
                String arr[]=value.split(":");
                ...
                ...
            }
            return false;
        }

    That's It. You are good to move further.

Important:

  • defaultValue, error_dir, root_dir, offset_dir must have valid directory/file paths.
  • defaultValue paths should end with ':'.
  • defaultValue can have multiple paths, there should be a ':' between two paths.
  • extensions must not have '.'.
  • extensions should end with ':' , also have ':' between two extensions. eg. /sdcard:/mnt:

Note:

FilePickerPreference stores selected directories/files as a String. It delimits multiple files/directories using ':' char.

Read more on implementation here.

Screenshot

Theme.Black

Screenshot 1

Theme.Holo

Screenshot 2

Theme.Holo.Light

Screenshot 3

Theme.Material

Screenshot 4

Theme.DeviceDefault

Screenshot 5

Performance

GPU Overdraw

Performance 1

GPU Rendering

Performance 2

Buy me a Coffee

If this project helped you reduce the development time, please consider donating :D

Buy me a Coffee

License

Copyright (C) 2016 Angad Singh

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.

android-filepicker's People

Contributors

alexeyvasilyev avatar avd10 avatar leonwebpro avatar nohkumado avatar npes87184 avatar parkerk avatar singhangadin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-filepicker's Issues

Can't select file

In the files listview, clicking on a directory will open the directory, but clicking on a file does nothing unless you click on the checkbox next to file. This makes user experience very inconvenient.

Is there any work-around to this or could you please fix this?

OnCancelListener is not called

Code:

myFilePickDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialogInterface) {
        ...
    }
});

It does not seem to be called when Cancel is selected..

Attribute title conflict with Android Toolbar

Hi,

Thanks for previous updates.

Currently theres a conflict with the title attribute on FilePickerPreference, I refer to the following compilation error:

Error:(271) Attribute "title" has already been defined
Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Applications/Android/sdk/build-tools/23.0.3/aapt'' finished with non-zero exit value 1

This seems to be an internal Android flaw as mentioned here:
http://stackoverflow.com/questions/18617413/attribute-title-has-already-been-defined-after-adding-after-adding-android-s

I think the conflict is because I am using android.support.v7.widget.Toolbar.

Please assist in getting a work around going.

Kind Regards

Willem

Allow to switch internal / external card

It seems that I can't find any options on your wiki to allow switch to internal / external card.
So it would be nice if you add this feature to this library.

Thanks :)

java.lang.NullPointerException: Attempt to get length of null array

type=1400 audit(0.0:4262): avc: denied { read } for name="/" dev="rootfs" ino=2 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=0 ppid=2834 pcomm="main" pgid=2834 pgcomm="main"

08-01 12:08:17.129 W/System.err(30056): java.lang.NullPointerException: Attempt to get length of null array
08-01 12:08:17.129 W/System.err(30056): 	at com.github.angads25.filepicker.filepicker.utils.Utility(SourceFile:72)
08-01 12:08:17.129 W/System.err(30056): 	at com.github.angads25.filepicker.view.FilePickerDialog.onStart(SourceFile:240)
08-01 12:08:17.129 W/System.err(30056): 	at android.app.Dialog.show(Dialog.java:302)
08-01 12:08:17.129 W/System.err(30056): 	at com.github.angads25.filepicker.view.FilePickerDialog.show(SourceFile:417)

Android: 7.1.1 (API: 25)
Manufacturer: Sony
Model: G8142
Device: G8142
Board: msm8998
Brand: Sony
Product: G8142
Screen: 1080x1776 (403dpi, xxhdpi)

NullPointerException on back item

Hello, when the first listview is loaded with directories and files of the specified path, and you press the first element to return (...), the application ends with errors. An uncontrolled nullPointerException is thrown.

Conceal hidden files/folders

I would message you if I knew how to :( I am not sure if this is the appropriate place to do this. I am new to github.

Is there a way to set a property to not show hidden files? My users are not so 'tech-savy' and when they see the dialog open with so many files starting with a period they have a hard time finding their files.

Is there already a way to adjust this?

Checkboxes not visible unless checked

My users do not like the behavior of the check boxes. They do not look like the screenshots. The check boxes are invisible until checked. It actually took us a while to realize we could even touch in that area to select a file.

I recommend you make the check boxes visible even when not checked. Either that or make the selection by clicking the file, but that would mess with the directory selection. Easiest way is to make all check boxes visible.

I know how to do it, but I am not sure how to recompile the library with my changes. I messed with android studio all day today and can't figure it out.

If you do this change then I would LOVE to use your library.

EDIT:
I should probably have mentioned... GREAT WORK!!! This library is awesome either way and looks great. It will be a huge time saver for me and looks better than some other ones I have seen. Just need this ooooooone tiny thing changed.

File name animation while scrolling

Hi
I really like your filepicker. It's simple to integrate and works without issues.
However there is one thing that's bothering me - the right-to-left animation of icons and file names while scrolling up or down. It does look nice and smooth, but it kind of doesn't fit in my app. My app is quite static and to suddenly have everything moving is a bit annoying.
Is there a simple way of switching these animations off?
Thanks.

Use colors from current theme

At the moment the library does not use colors for current app theme.
If I have the following theme assigned to the app

<resources>
    <style name="AppTheme.Dark.Cyan" parent="AppTheme.Dark">
        <item name="colorAccent">@color/material_cyan_300</item>
    </style>
</resources>

then filepicker still needs colorAccent in colors.xml to override button text.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorAccent">#ff9800</color>
<resources>

Check how this is done in android.support.v7.app.AlertDialog.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String java.io.File.getAbsolutePath()’ on a null object reference

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String java.io.File.getAbsolutePath()’ on a null object reference
at com.github.angads25.filepicker.view.FilePickerDialog.onItemClick(SourceFile:213)
at android.widget.AdapterView.performItemClick(AdapterView.java:334)
at android.widget.AbsListView.performItemClick(AbsListView.java:1531)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3664)
at android.widget.AbsListView$3.run(AbsListView.java:5585)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

Can't grant the permission (Screen Overlay Detected)

When I tried to grant the storage permission, android system's dialog is poped.

It says "Screen overlay detected - To change this permission setting you first have to turn off the screen overlay from Settings > Apps".

Usually this problem is caused by screen filter application but I don't use any of them.

Anyway I found that is caused by toast message.
[ FilePickerDialog.onShow() - Line203]
Toast.makeText(context,"Application needs you permission to access SD Card",Toast.LENGTH_LONG).show();

If I wait until the message disappears then I can get the app's storage permission.

Different method would be necessary to inform about permission.

Changing color

Hi
How to change colors or style of FilePickerDialog in code?
Getting color this way should help for changing themes:

int[] attrs = new int[] { R.attr.colorPrimary/* index 0 */}; TypedArray ta = obtainStyledAttributes(attrs); ta.getColor(0,0); ta.recycle();

Thank you
Love that lib :)

onSelectedFilePaths() returning deselected file paths

I have a requirement where user can select/deselect dirs paths. So after using dialog.markFiles(filePaths), and when the user is deselecting the path, still the onSelectedFilePaths() method returns deselected file paths along with selected paths.

No path return when I use DIR_SELECT

I have these config:

                DialogProperties properties = new DialogProperties();
                properties.selection_mode = DialogConfigs.SINGLE_MODE;
                properties.selection_type = DialogConfigs.DIR_SELECT;
                properties.root = new File("/sdcard/facedetect");
                properties.extensions=null;

                FilePickerDialog dialog = new FilePickerDialog(MainActivity.this, properties);
                dialog.setDialogSelectionListener(new DialogSelectionListener() {
                    @Override
                    public void onSelectedFilePaths(String[] files) {

                    }
                });
                dialog.show();

I have noticed that if I use DIR_SELECT , I cannot get the path from String[] files. Following is the screenshot

image

Return Directory Without Checkbox

I am using the FilePicker as a download file path selector. The user navigates to the directory they would like to save their files in and selects that folder. However, in the current implementation, that behavior does not work. Instead, the user is required to select their desired directory using the checkbox button.

I think that the library should return the file path the user navigated to without the checkbox requirement.

Remove params from application in AndroidManifest.xml

Please remove

android:allowBackup="true"
android:supportsRtl="true"

from AndroidManifest.xml file. Every app has their own policy regarding using backup or RTL. No reason for such params in 3d party library.

Also remove

uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"

This parameter also should be controllable by the app itself. Not by 3d party library.

select file by touching the full row

now if you touch the row (filename) it just lights up shortly and nothing else happens.
can you make an option so that this will select the file?
this would be the natural way people select things

Seemed there was a bug when selecting the file

could you please help me,
when I tried to select a file from the dialog file-listing it seemed a bit unresponsive.

here is the screenshot.

ezgif-632323787

and another question, is it possible to disable the animation when selecting files (the fly-in animation)?
and I also I want to make the selection by clicking the list item instead of the checkbox

Thank you

header text background

For some reason if I set the background color in my app, header looks weird (filepicker/src/main/res/layout/dialog_header.xml).

Can not move to external storage from internal storage in some devices

Hi,

In htc u11, if I try to click ".." in the root of internal storage. It will show "Directory cannot be accessed". I guess it is because the root ("/") can not be read. This will lead to fail to move to external storage through internal storage.

I have worked for it to add a dropdown in dir_picture to direct the current directory to external sdcard without entering "/", look picture.

imgur

Any other good ideas?

Thanks.

didn't find how to allways set the up path

hello,
the path given at instantiation is the root node for the dialog, meaning you can navigate up and down from there, but you can't get up....

now i give that path, from a stored variable, so as to move the user to a section of the filesystem where his files are supposed to be....

but once set, he can't escape the actual project to go to the next.... anyway to set a top-most root and an actual position ?

Single selection mode checkbox state

If I tap only if checkboxes or only on elements everything is ok.

But if I tap first on checkbox and after that I tap on other element, that element is not checked only if tap it once again.

Same thing if I check and element and after that a checkbox from other element.

So in those cases the selected state is interchanged somehow.

nullpointer on dir select

I am on version 1.02 and still getting a null pointer exception when I try to choose a directory:

java.lang.NullPointerException at com.github.angads25.filepicker.view.FilePickerDialog$1.onClick(FilePickerDialog.java:100)

This is my code:

DialogProperties properties = new DialogProperties();

        properties.selection_mode = DialogConfigs.SINGLE_MODE;
        properties.selection_type = DialogConfigs.DIR_SELECT;
        properties.root = new File(DialogConfigs.STORAGE_DIR);
        properties.extensions = null;
        FilePickerDialog dialog = new FilePickerDialog(getActivity(), properties);
        dialog.setDialogSelectionListener(new DialogSelectionListener() {
            @Override
            public void onSelectedFilePaths(String[] files) {
                Log.d(TAG, "onSelectedFilePaths: " + files.length);
                if (files.length > 0) {
                    //stuff
                }
            }
        });
        dialog.show();`

Animations and Theme

After switching to 1.0.3 I think I might switch back to 1.0.2. The animations are a bit too much. They definitely look cool, but my users aren't going to like it. It's hard to scroll quickly and find things and my app needs quick lookups :-/

Also when you select a file and stuff starts flying all over the screen it is too much. It almost looks like a glitch. Is it supposed to be doing all that just from hitting a checkbox? Is there a way for me to make just the check box "check" and "uncheck" without anything else moving?

One final question; can I change the colors? I need to make them match my app.

Thanks Angad.

Use color from provided theme

To help users of you Dialog dealing with the theme, you could as well simply implement a constructor of FilePickerDialog that gets the parameters of Dialog : public Dialog(@nonnull Context context, @StyleRes int themeResId) si that they can modifiy the theme.
Very simple to put in place : add this constructor :
public FilePickerDialog(Context context, DialogProperties properties, @StyleRes int themeResId) {
super(context, themeResId);
this.context = context;
this.properties = properties;
filter = new ExtensionFilter(properties);
internalList = new ArrayList<>();
}
and it's done !

small improvement in FilePickerDialog

BTW: Nice Work my Friend!! Love it!!
and here just an Idea for you i did it in my Fork:

in the File com.github.angads25.filepicker.view.FilePickerDialog:

@Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (internalList.size() > i) {
            FileListItem fitem = internalList.get(i);
            if (fitem.isDirectory()) {
             ....
            }
            else {
                if (view != null) {
                    CheckBox checkBox = (CheckBox)view.findViewById(R.id.file_mark);
                    checkBox.performClick();
                }
            }
        }
    }

So you can also click on the FileName to select an Item... it's pretty handy .. for me :-)

Filetype filtering

Is a filter for filetypes (e.g. RegEx based) planned? I need a file picker that only shows SVG files :)

Selecting a directory returns zero length array

The following code is used to select a directory:

DialogProperties properties=new DialogProperties();
properties.selection_mode= DialogConfigs.SINGLE_MODE;
properties.selection_type=DialogConfigs.DIR_SELECT;
properties.root=new File(DialogConfigs.DEFAULT_DIR);
properties.extensions=null;
fd = new FilePickerDialog(SettingsActivity.this, properties);
fd.setDialogSelectionListener(new DialogSelectionListener() {
    @Override
    public void onSelectedFilePaths(String[] files) {
        if(files == null){
            utility.doNothihng();
        }else if(files.length == 1){
            String sPathFolder = files[0];
        }
    }
});
fd.show();

The result is that files.length = 0. The selected folder is Download.

BTW, thanks a lot for this great tool.

Add more customize display item values

It would be interesting to add personalization in the first and second line, showing the size or by a text pattern with variables:
%size% %size_b% %size_kb% %size_mb% %size_gb%...
%lastmod_24% %lastmod_12%
%path%
%name%

Sample:
app:patternFirstLine="%name%
app:patternSecondLine="%size_mb% - %lastmod_24h%
app:patternTime = "YYY/mm/dd"

Is it possible to show directiores based on the files present in it Eg show only directiories which have pdf files

Will it be possible to show Directory only if pdf, txt, image file is present in that folder. I mean by default it is showing system Directories as well. I need to show only those directories which have at least one of the required files like pdf,txt, image.
I saw the Dialog properties where we can hide files other than specified in ext array passed as below.

 String ext[] =new String[] {"jpg","jpeg","png","gif"};
        properties.extensions=ext;

But here the problem I am facing is , it is still showing the folders which don't contain the above extns.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.