Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

[![](https://jitpack.io/v/me.rosuh/AndroidFilePicker.svg)](https://jitpack.io/#me.rosuh/AndroidFilePicker)

[中文简体](https://github.com/rosuH/AndroidFilePicker/blob/master/README_CN.md)
[中文简体](./README_CN.md)

If you're using `0.x` version, checkout the [README_0.x](./README_0.x.md) file.

Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector framework. Some of his characteristics are described below:

Expand All @@ -22,30 +24,35 @@ Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, li
- Apply different themes, including four built-in themes and custom themes
- More to find out yourself

| Rail Style(default) | Reply Style | Crane Style | Shrine Style |
| Rail | Reply | Crane | Shrine |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/default_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/reply_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/crane_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/shrine_theme.png) |

## Version Compatibility
It depends on your targetAPI.

- `targetAPI <= 28`, no problem at all ;)
- `targetAPI == 29`, please enable `requestLegacyExternalStorage` feature for your project : D
- `targetAPI == 29`
- When running on Android 11 and above, only media files (images, audio and video) can be read, but nothing else can be accessed (e.g. PDF documents, apk binary files, etc.)
- `targetAPI > 33`, may be you are finding [photo picker](https://developer.android.com/about/versions/14/changes/partial-photo-video-access?hl=zh-cn#media-reselection)
- `targetAPI == 33`
- Handle [media permissions](https://developer.android.com/training/data-storage/shared/media#access-other-apps-files) by your onw
- This lib will only show media files which your app has permission to access
- `targetAPI <= 33`
- Set `android:requestLegacyExternalStorage="true"` in your `AndroidManifest.xml` file
- Handler `android.permission.READ_EXTERNAL_STORAGE` permission by your own
- This lib will show all files in your storage

Please check out this issue: [All About Scope Storage. ](https://github.com/rosuH/AndroidFilePicker/issues/146)
## Download

Gradle:
[Gradle](https://docs.jitpack.io/android/#installing):

In your project `build.gradle`:

```xml
allprojects {
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url 'https://jitpack.io' }
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
```
Expand All @@ -65,11 +72,8 @@ Check out [releases page](https://github.com/rosuH/AndroidFilePicker/releases) t

### Permission

The library requires one permissions:

- `android.permission.READ_EXTERNAL_STORAGE`

If you do not have permission to apply, this framework will check and apply at startup.
You should request permission by yourself, this lib will not request permission for you.
See [Version Compatibility](#version-compatibility) for more details.

### Launch 🚀

Expand Down
124 changes: 124 additions & 0 deletions README_0.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
![Banner](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/AndroidFilePicker_Banner_Dr_Sugiyama.png)

# Android File Picker🛩️

[![](https://jitpack.io/v/me.rosuh/AndroidFilePicker.svg)](https://jitpack.io/#me.rosuh/AndroidFilePicker)

[中文简体](./README_CN_1.x.md)

Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector framework. Some of his characteristics are described below:

- Launcher in Activity or Fragment
- Start with a single line of code
- Browse and select all files in local storage
- Custom Root path to start
- Built-in default file type and file discriminator
- Or you can implement the file type yourself
- Built in Single Choice mode and Multiple Choice mode.
- Custom list filter
- Just want to show pictures(Or videos, audio...)? No problem!
- Of course, you can just display the folder
- Custom item click event: only need to implement the listener
- Apply different themes, including four built-in themes and custom themes
- More to find out yourself

| Rail Style(default) | Reply Style | Crane Style | Shrine Style |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/default_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/reply_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/crane_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/shrine_theme.png) |

## Version Compatibility
It depends on your targetAPI.

- `targetAPI <= 28`, no problem at all ;)
- `targetAPI == 29`, please enable `requestLegacyExternalStorage` feature for your project : D
- `targetAPI == 29`
- When running on Android 11 and above, only media files (images, audio and video) can be read, but nothing else can be accessed (e.g. PDF documents, apk binary files, etc.)

Please check out this issue: [All About Scope Storage. ](https://github.com/rosuH/AndroidFilePicker/issues/146)
## Download

Gradle:

In your project `build.gradle`:

```xml
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

In your module `build.gradle`:

```xml
dependencies {
implementation 'me.rosuh:AndroidFilePicker:$latest_version'
}
```
This lib now support AndroidX, check the version below.

Check out [releases page](https://github.com/rosuH/AndroidFilePicker/releases) to see more versions.

## Usage 📑

### Permission

The library requires one permissions:

- `android.permission.READ_EXTERNAL_STORAGE`

If you do not have permission to apply, this framework will check and apply at startup.

### Launch 🚀

```kotlin
FilePickerManager
.from(context)
.forResult(FilePickerManager.REQUEST_CODE)
```



### Receive Result

In `onActivityResult()` callback of the starting `Activity` or `Fragment`:

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
FilePickerManager.instance.REQUEST_CODE -> {
if (resultCode == Activity.RESULT_OK) {
val list = FilePickerManager.instance.obtainData()
// do your work
} else {
Toast.makeText(this@SampleActivity, "You didn't choose anything~", Toast.LENGTH_SHORT).show()
}
}
}
}
```

The result is a path list of the selected file (`ArrayList<String>()`).


## Docs

- [Source Code Explanation](https://github.com/rosuH/AndroidFilePicker/wiki/4.-%E7%A4%BA%E4%BE%8B%E5%8F%8A%E8%A7%A3%E9%87%8A).

- [Change Log](https://github.com/rosuH/AndroidFilePicker/wiki/Change-Log)

- [TODO](https://github.com/rosuH/AndroidFilePicker/wiki/TODO)



---

## Special Thanks To:

- [whichName](https://github.com/whichname)
- [Matisse](https://github.com/zhihu/Matisse)
- [Default Icon Author Shulk](http://iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.d9df05512&cid=11271)
- [Theme Color](https://material.io/design/material-studies/about-our-material-studies.html)
- [Empty icon](https://github.com/rosuH/AndroidFilePicker/blob/master/filepicker/src/main/res/drawable/ic_empty_file_list_file_picker.xml) made by [freepik](https://www.freepik.com/) from www.flaticon.com
167 changes: 38 additions & 129 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,153 +1,62 @@
![Banner](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/AndroidFilePicker_Banner_Dr_Sugiyama.png)

# AndroidFilePicker
# Android File Picker🛩️

[![](https://jitpack.io/v/me.rosuh/AndroidFilePicker.svg)](https://jitpack.io/#me.rosuh/AndroidFilePicker)

如果你使用的是 `1.x` 版本,请查看 [README_0.x](./README_CN_0.x.md) 文件。

它没有像 Rocky、Cosmos 或 Fish 这样的名字。Android File Picker,正如其名,是一个本地文件选择框架。以下是它的一些特点:

它没有像 Rocky,Cosmos 或是 Peppa 这样的名字。 Android File Picker 正如其名,是一个本地文件选择器框架。 他的一些特征如下所述:

- 在 `Activity` 或 `Fragment` 中启动
- 从一行代码开始
- 浏览本地存储中的所有文件
- 内置默认文件类型和文件鉴别器
- 或者您可以自己实现文件类型
- 内置了单选模式和多选模式
- 在 Activity 或 Fragment 中启动
- 一行代码启动
- 浏览和选择本地存储中的所有文件
- 自定义根路径开始
- 内置默认文件类型和文件区分器
- 或者你可以自己实现文件类型
- 内置单选模式和多选模式。
- 自定义列表过滤器
- 只想显示图片(或视频,音频......)? 没问题!
- 当然,您也可只显示文件夹
- 自定义`item`点击事件:只需要实现监听器
- 四个内置主题和自定义主题
- 还有更多待您自己探索的特性(?)


- 只想显示图片(或视频、音频...)?没问题!
- 当然,你也可以只显示文件夹
- 自定义条目点击事件:只需实现监听器
- 应用不同的主题,包括四个内置主题和自定义主题
- 更多功能等你发现

| Rail Style(default) | Reply Style | Crane Style | Shrine Style |
| Rail | Reply | Crane | Shrine |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/default_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/reply_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/crane_theme.png) | ![](https://raw.githubusercontent.com/rosuH/AndroidFilePicker/master/images/shrine_theme.png) |

## 版本兼容性
这取决于您的 targetAPI
取决于你的 targetAPI

- `targetAPI <= 28`,完全没有问题 ;)
- `targetAPI == 29`,请为您的项目启用 `requestLegacyExternalStorage` 特性:D
- `targetAPI == 29`
- 当运行于 Android 11以及以上的平台时,仅可以读取媒体文件(图片、音视频),除此均无法访问(比如PDF文档、apk 二进制文件等)
- `targetAPI > 33`,也许你正在寻找 [照片选择器](https://developer.android.com/about/versions/14/changes/partial-photo-video-access?hl=zh-cn#media-reselection)
- `targetAPI == 33`
- 处理[媒体权限](https://developer.android.com/training/data-storage/shared/media#access-other-apps-files)由你自己处理
- 此库将仅显示你的应用有权限访问的媒体文件
- `targetAPI <= 33`
- 在你的 `AndroidManifest.xml` 文件中设置 `android:requestLegacyExternalStorage="true"`
- 由你自己处理 `android.permission.READ_EXTERNAL_STORAGE` 权限
- 此库将显示存储中的所有文件

请参看 issue: [All About Scope Storage. ](https://github.com/rosuH/AndroidFilePicker/issues/146)
## 下载使用
## 下载

1. 在你的项目中添加依赖
[Gradle](https://docs.jitpack.io/android/#installing):

现在项目 `build.gradle` 配置文件添加仓库
在项目的 `build.gradle` 文件中

```xml
allprojects {
```gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url 'https://jitpack.io' }
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
```
在模块的 build.gradle 文件中:

然后在子模块(`app`)的配置文件添加依赖:

```xml
```gradle
dependencies {
implementation 'me.rosuh:AndroidFilePicker:latest_version'
}
```

`latest_version` 请自行替换成 [最新版本](https://github.com/rosuH/AndroidFilePicker/releases)



## 使用

### 权限

此库需要一个权限:

- `android.permission.READ_EXTERNAL_STORAGE`

如果您没有提前授予,这个库会自动申请该权限的。

### 开始使用

简单的链式调用示意:

```kotlin
FilePickerManager
.from(context)
.forResult(FilePickerManager.REQUEST_CODE)
```

现在你已经起飞了🛩️...(真的只有两行)


### 获取结果

*获取结果*:`onActivityResult`接受消息,然后调用`FilePickerManager.obtainData()`获取保存的数据,**结果是所选取文件的路径列表(`ArrayList<String>()`)**

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
FilePickerManager.instance.REQUEST_CODE -> {
if (resultCode == Activity.RESULT_OK) {
val list = FilePickerManager.instance.obtainData()
// do your work
} else {
Toast.makeText(this@SampleActivity, "没有选择任何东西~", Toast.LENGTH_SHORT).show()
}
}
}
implementation 'me.rosuh:AndroidFilePicker:$latest_version'
}
```

### 更多示例

来翻翻我写的[飞行手册](https://github.com/rosuH/AndroidFilePicker/wiki)吧?

或者想看看[主题配色](https://github.com/rosuH/AndroidFilePicker/wiki/3.-%E9%85%8D%E7%BD%AE%E9%80%89%E9%A1%B9#2-%E4%B8%BB%E9%A2%98%E5%B1%95%E7%A4%BA)?

## 功能 & 特点

1. 链式调用
2. 默认选中实现
- 点击条目(`item`)无默认实现
- 点击`CheckBox`为选中
- 长按条目为更改选中状态:选中/取消选中
3. 内置四种主题配色 + 可自定义配色
- 查看主题颜色示意图,然后调用`setTheme()`传入自定义主题
4. 默认实现多种文件类型
- 实现`IFileType`接口来实现你的文件类型
- 实现`AbstractFileType`抽象类来实现你的文件类型甄别器
5. 公开文件过滤接口
- 实现`AbstractFileFilter`抽象类来定制你自己的文件过滤器,这样可以控制文件列表的展示内容
6. 多种可配置选项
1. 选中时是否忽略文件夹
2. 是否显示隐藏文件夹(以符号`.`开头的,视为隐藏文件或隐藏文件夹)
3. 可配置导航栏的文本,默认显示、多选文本、取消选择文本以及根目录默认名称
7. 公开条目(`item`)选择监听器,可自定义条目被点击的实现

## 其他

- [部分源码说明](https://github.com/rosuH/AndroidFilePicker/wiki/%E9%83%A8%E5%88%86%E6%BA%90%E7%A0%81%E8%AF%B4%E6%98%8E)。

- [更新日志](https://github.com/rosuH/AndroidFilePicker/wiki/Change-Log)

- [TODO](https://github.com/rosuH/AndroidFilePicker/wiki/TODO)



---

## Special Thanks To:

- [*1 @whichName](https://github.com/whichname)
- [BRVAH](https://github.com/CymChad/BaseRecyclerViewAdapterHelper)
- [Matisse](https://github.com/zhihu/Matisse)
- [默认图标作者 Shulk](http://iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.d9df05512&cid=11271)
- [主题配色](https://material.io/design/material-studies/about-our-material-studies.html)
- [Empty icon](https://github.com/rosuH/AndroidFilePicker/blob/master/filepicker/src/main/res/drawable/ic_empty_file_list_file_picker.xml) made by [freepik](https://www.freepik.com/) from www.flaticon.com
```
Loading