android-25文件,GitHub - Angads25/android-filepicker: Selecting directories/files made a lot easier....

The project is no longer being maintained.

FilePicker

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

Developed by

Benchmark:

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d392532422d627269676874677265656e2e7376673f7374796c653d666c617468747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d6574686f647320616e642073697a652d323731207c203433204b422d6539316536332e737667

Where to Find:

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f616e6761647332352f6d6176656e2f66696c657069636b65722f696d616765732f646f776e6c6f61642e73766768747470733a2f2f6d6176656e2d6261646765732e6865726f6b756170702e636f6d2f6d6176656e2d63656e7472616c2f636f6d2e6769746875622e616e6761647332352f66696c657069636b65722f62616467652e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d46696c655069636b65722d626c75652e7376673f7374796c653d666c6174

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

Start by creating an instance of DialogProperties.

DialogProperties properties = new DialogProperties();

Now 'DialogProperties' has certain parameters.

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;

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");

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`.

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

Start by declaring FilePickerPreference in your settings xml file as:

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:"/>

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;

}

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

bf7db17cf6410ea8eadd2a100cf876ee.png

Theme.Holo

e6fd960d1adb3306f145e5a264d9d88b.png

Theme.Holo.Light

c80a7791a21daf1ed4a6c0eb68410404.png

Theme.Material

3422ea035b8afae5a8a46efaeb444773.png

Theme.DeviceDefault

61de6e8cf2efcd39f22a759efd779537.png

Performance

GPU Overdraw

8f890cdb87515587c09ed49e6d800d4f.png

GPU Rendering

9cde8f154d95c98831ddaf502c93aa79.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值