├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── vip
│ │ └── upya
│ │ └── demo
│ │ └── sfof
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
└── 6.jpg
├── settings.gradle
└── sfoflibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── vip
│ └── upya
│ └── lib
│ └── sfof
│ ├── CurrentPathAdapter.java
│ ├── SelectFileOrFolderDialog.java
│ ├── SubfileAdapter.java
│ ├── UpyaBaseDialog.java
│ └── Utils.java
└── res
├── anim
├── upya_dialog_in.xml
└── upya_dialog_out.xml
├── drawable
├── svg_close.xml
├── svg_file.xml
├── svg_finish_disable.xml
├── svg_finish_enabled.xml
├── svg_folder.xml
├── svg_into.xml
├── svg_select_all.xml
├── svg_select_none.xml
└── svg_unknown_file.xml
├── layout
├── dialog_select_file_or_folder.xml
├── item_current_path.xml
└── item_subfile.xml
└── values
├── strings.xml
└── styles.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | *.apk
3 | /.gradle
4 | /.idea
5 | /build
6 | /captures
7 | .externalNativeBuild
8 | /local.properties
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 自述
2 | `UpyaSelectFileOrFolder`是一个用于挑选文件或文件夹,获取路径信息的库,可单选、多选、混选。😍
3 |
4 | # 截图
5 | | 单选文件 | 单选文件夹 | 单选文件和文件夹 |
6 | | ------------ | ------------ | ------------ |
7 | | | | |
8 |
9 | | 多选文件 | 多选文件夹 | 多选文件和文件夹 |
10 | | ------------ | ------------ | ------------ |
11 | | | | |
12 |
13 | # 依赖
14 |
15 | ### Gradle:
16 | * 步骤1:将以下代码添加到工程的build.gradle中:
17 | ```groovy
18 | allprojects {
19 | repositories {
20 | ...
21 | maven { url 'https://jitpack.io' }
22 | }
23 | }
24 | ```
25 |
26 | * 步骤2:添加依赖关系
27 |
28 | ```groovy
29 | android{
30 | ...
31 | // 需启用Java8
32 | compileOptions {
33 | targetCompatibility JavaVersion.VERSION_1_8
34 | sourceCompatibility JavaVersion.VERSION_1_8
35 | }
36 | }
37 |
38 | dependencies {
39 | ...
40 | // 将下方的 ${latestVersion} 替换为当前最新的版本,最新版本参见下文
41 | implementation 'com.github.TYUpya:UpyaSelectFileOrFolder:${latestVersion}'
42 |
43 | // PS:如果集成以上依赖后项目运行报错,请再添加以下赖
44 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
45 | }
46 | ```
47 |
48 | ### Maven:
49 | * 步骤1:
50 | ```xml
51 |
52 |
53 | jitpack.io
54 | https://jitpack.io
55 |
56 |
57 | ```
58 |
59 | * 步骤2:
60 |
61 | ```xml
62 |
63 |
64 | com.github.TYUpya
65 | UpyaSelectFileOrFolder
66 | ${latestVersion}
67 |
68 |
69 |
70 |
71 | androidx.recyclerview
72 | recyclerview
73 | 1.1.0
74 | runtime
75 |
76 | ```
77 |
78 | # 最新版本
79 | | latestVersion |
80 | | :------------: |
81 | | [](https://jitpack.io/#TYUpya/UpyaSelectFileOrFolder) |
82 |
83 | # 所需权限
84 | | 序号 | 权限 | 说明 |
85 | | :------------: | :------------: | :------------: |
86 | | 1 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | 读取储存的文件权限 |
87 |
88 | # 使用介绍
89 | * 调用示例之 单选文件
90 | ```java
91 | public void onClick01(View view) {
92 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FILE,
93 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
94 | @Override
95 | public void onSelectFileOrFolder(List selectedFileList) {
96 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
97 | }
98 | }).show();
99 | }
100 | ```
101 |
102 | * 调用示例之 多选文件
103 | ```java
104 | public void onClick02(View view) {
105 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FILE,
106 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
107 | @Override
108 | public void onSelectFileOrFolder(List selectedFileList) {
109 | mainText.setText("选择的文件:\n");
110 | for (File file : selectedFileList) {
111 | mainText.append(file.getAbsolutePath());
112 | mainText.append("\n");
113 | }
114 | }
115 | }).show();
116 | }
117 | ```
118 |
119 | * 调用示例之 单选文件夹
120 | ```java
121 | public void onClick03(View view) {
122 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FOLDER,
123 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
124 | @Override
125 | public void onSelectFileOrFolder(List selectedFileList) {
126 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
127 | }
128 | }).show();
129 | }
130 | ```
131 |
132 | * 调用示例之 多选文件夹
133 | ```java
134 | public void onClick04(View view) {
135 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FOLDER,
136 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
137 | @Override
138 | public void onSelectFileOrFolder(List selectedFileList) {
139 | mainText.setText("选择的文件:\n");
140 | for (File file : selectedFileList) {
141 | mainText.append(file.getAbsolutePath());
142 | mainText.append("\n");
143 | }
144 | }
145 | }).show();
146 | }
147 | ```
148 |
149 | * 调用示例之 单选文件和文件夹
150 | ```java
151 | public void onClick05(View view) {
152 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_UNLIMITED,
153 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
154 | @Override
155 | public void onSelectFileOrFolder(List selectedFileList) {
156 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
157 | }
158 | }).show();
159 | }
160 | ```
161 |
162 | * 调用示例之 多选文件和文件夹
163 | ```java
164 | public void onClick06(View view) {
165 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_UNLIMITED,
166 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
167 | @Override
168 | public void onSelectFileOrFolder(List selectedFileList) {
169 | mainText.setText("选择的文件:\n");
170 | for (File file : selectedFileList) {
171 | mainText.append(file.getAbsolutePath());
172 | mainText.append("\n");
173 | }
174 | }
175 | }).show();
176 | }
177 | ```
178 |
179 | # 混淆规则
180 | ```txt
181 | -dontwarn vip.upya.lib.sfof.**
182 | -keep class vip.upya.lib.sfof.**{*;}
183 | ```
184 |
185 | # 感谢
186 | 😂[나 자신](https://github.com/TYUpya "TYUpya")🤣
187 |
188 | # License
189 | ```text
190 | Copyright 2020 TYUpya
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 | ```
204 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 |
7 | compileOptions {
8 | targetCompatibility JavaVersion.VERSION_1_8
9 | sourceCompatibility JavaVersion.VERSION_1_8
10 | }
11 |
12 | defaultConfig {
13 | applicationId "vip.upya.demo.sfof"
14 | minSdkVersion 21
15 | targetSdkVersion 29
16 | versionCode 1
17 | versionName "1.0"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
31 | implementation project(':sfoflibrary')
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/vip/upya/demo/sfof/MainActivity.java:
--------------------------------------------------------------------------------
1 | package vip.upya.demo.sfof;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | import java.io.File;
10 | import java.util.List;
11 |
12 | import vip.upya.lib.sfof.SelectFileOrFolderDialog;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | private TextView mainText;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | mainText = findViewById(R.id.mainText);
23 | }
24 |
25 | /** 单选文件 */
26 | public void onClick01(View view) {
27 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FILE,
28 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
29 | @Override
30 | public void onSelectFileOrFolder(List selectedFileList) {
31 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
32 | }
33 | }).show();
34 | }
35 |
36 | /** 多选文件 */
37 | public void onClick02(View view) {
38 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FILE,
39 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
40 | @Override
41 | public void onSelectFileOrFolder(List selectedFileList) {
42 | mainText.setText("选择的文件:\n");
43 | for (File file : selectedFileList) {
44 | mainText.append(file.getAbsolutePath());
45 | mainText.append("\n");
46 | }
47 | }
48 | }).show();
49 | }
50 |
51 | /** 单选文件夹 */
52 | public void onClick03(View view) {
53 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FOLDER,
54 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
55 | @Override
56 | public void onSelectFileOrFolder(List selectedFileList) {
57 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
58 | }
59 | }).show();
60 | }
61 |
62 | /** 多选文件夹 */
63 | public void onClick04(View view) {
64 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_ONLY_FOLDER,
65 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
66 | @Override
67 | public void onSelectFileOrFolder(List selectedFileList) {
68 | mainText.setText("选择的文件:\n");
69 | for (File file : selectedFileList) {
70 | mainText.append(file.getAbsolutePath());
71 | mainText.append("\n");
72 | }
73 | }
74 | }).show();
75 | }
76 |
77 | /** 单选文件和文件夹 */
78 | public void onClick05(View view) {
79 | new SelectFileOrFolderDialog(this, true, SelectFileOrFolderDialog.CHOICEMODE_UNLIMITED,
80 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
81 | @Override
82 | public void onSelectFileOrFolder(List selectedFileList) {
83 | mainText.setText("选择的文件:" + selectedFileList.get(0).getAbsolutePath());
84 | }
85 | }).show();
86 | }
87 |
88 | /** 多选文件和文件夹 */
89 | public void onClick06(View view) {
90 | new SelectFileOrFolderDialog(this, false, SelectFileOrFolderDialog.CHOICEMODE_UNLIMITED,
91 | new SelectFileOrFolderDialog.OnSelectFileOrFolderListener() {
92 | @Override
93 | public void onSelectFileOrFolder(List selectedFileList) {
94 | mainText.setText("选择的文件:\n");
95 | for (File file : selectedFileList) {
96 | mainText.append(file.getAbsolutePath());
97 | mainText.append("\n");
98 | }
99 | }
100 | }).show();
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
27 |
28 |
29 |
33 |
34 |
40 |
41 |
47 |
48 |
49 |
53 |
54 |
60 |
61 |
67 |
68 |
69 |
72 |
73 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #0088FF
4 | #0066CC
5 | #F6F6F6
6 | #EEEEEE
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UpyaSelectFileOrFolder
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.3'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // github 仓库管理
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | # When configured, Gradle will run in incubating parallel mode.
10 | # This option should only be used with decoupled projects. More details, visit
11 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12 | # org.gradle.parallel=true
13 | # AndroidX package structure to make it clearer which packages are bundled with the
14 | # Android operating system, and which are packaged with your app's APK
15 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
16 | # Automatically convert third-party libraries to use AndroidX
17 | org.gradle.jvmargs=-Xmx2536m
18 | android.enableBuildCache=true
19 | android.useAndroidX=true
20 | android.enableJetifier=true
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 25 10:56:42 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/images/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/1.jpg
--------------------------------------------------------------------------------
/images/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/2.jpg
--------------------------------------------------------------------------------
/images/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/3.jpg
--------------------------------------------------------------------------------
/images/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/4.jpg
--------------------------------------------------------------------------------
/images/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/5.jpg
--------------------------------------------------------------------------------
/images/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TYUpya/UpyaSelectFileOrFolder/847a5ec45541d7a10ad65a5856ee3e192cb8902f/images/6.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':sfoflibrary'
2 | rootProject.name='UpyaSelectFileOrFolder'
3 |
--------------------------------------------------------------------------------
/sfoflibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sfoflibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group = 'com.github.TYUpya'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.2"
8 |
9 | compileOptions {
10 | targetCompatibility JavaVersion.VERSION_1_8
11 | sourceCompatibility JavaVersion.VERSION_1_8
12 | }
13 |
14 | defaultConfig {
15 | minSdkVersion 21
16 | targetSdkVersion 29
17 | versionCode 1
18 | versionName "1.0.1"
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 |
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | implementation 'androidx.appcompat:appcompat:1.1.0'
33 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
34 | }
35 |
--------------------------------------------------------------------------------
/sfoflibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/java/vip/upya/lib/sfof/CurrentPathAdapter.java:
--------------------------------------------------------------------------------
1 | package vip.upya.lib.sfof;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.TextView;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import java.io.File;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /** 当前文件路径 适配器 */
16 | @SuppressWarnings("all")
17 | public class CurrentPathAdapter extends RecyclerView.Adapter {
18 |
19 | private List listDatas;
20 | private OnCurrentPathRVItemClickListener onCurrentPathRVItemClickListener;
21 |
22 | public CurrentPathAdapter(OnCurrentPathRVItemClickListener onCurrentPathRVItemClickListener) {
23 | this.listDatas = new ArrayList<>();
24 | this.onCurrentPathRVItemClickListener = onCurrentPathRVItemClickListener;
25 | }
26 |
27 | @NonNull
28 | @Override
29 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
30 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_current_path, parent, false);
31 | return new ViewHolder(view);
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
36 | File file = listDatas.get(position);
37 | holder.itemCpText.setText(position == 0 ? "SD卡" : file.getName());
38 | holder.itemCpText.setOnClickListener(v -> {
39 | if (onCurrentPathRVItemClickListener != null)
40 | onCurrentPathRVItemClickListener.onCurrentPathRVItemClick(position, file);
41 | });
42 | }
43 |
44 | @Override
45 | public int getItemCount() {
46 | return this.listDatas.size();
47 | }
48 |
49 | /** 刷新数据 */
50 | public void onRefreshData(List list) {
51 | this.listDatas.clear();
52 | if (list != null && !list.isEmpty())
53 | this.listDatas.addAll(list);
54 | notifyDataSetChanged();
55 | }
56 |
57 | class ViewHolder extends RecyclerView.ViewHolder {
58 | TextView itemCpText;
59 |
60 | ViewHolder(@NonNull View itemView) {
61 | super(itemView);
62 | itemCpText = itemView.findViewById(R.id.itemCpText);
63 | }
64 | }
65 |
66 | /** RecyclerView Item 监听事件回调 */
67 | public interface OnCurrentPathRVItemClickListener {
68 | /** RecyclerView Item 单击 */
69 | default void onCurrentPathRVItemClick(int position, File bean) {
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/java/vip/upya/lib/sfof/SelectFileOrFolderDialog.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | 一、请在您的主项目AndroidManifest.xml文件添加以下权限
4 |
5 |
6 | 二、如果集成后项目运行报错,请在您的主项目build.gradle文件添加以下依赖
7 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
8 |
9 | */
10 | package vip.upya.lib.sfof;
11 |
12 | import android.app.Activity;
13 | import android.os.Environment;
14 | import android.view.KeyEvent;
15 | import android.view.View;
16 | import android.widget.ImageView;
17 | import android.widget.TextView;
18 | import android.widget.Toast;
19 |
20 | import androidx.recyclerview.widget.LinearLayoutManager;
21 | import androidx.recyclerview.widget.RecyclerView;
22 |
23 | import java.io.File;
24 | import java.io.FileFilter;
25 | import java.util.ArrayList;
26 | import java.util.Arrays;
27 | import java.util.HashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | /** 挑选文件或文件夹 弹窗 */
32 | @SuppressWarnings("all")
33 | public class SelectFileOrFolderDialog extends UpyaBaseDialog implements View.OnClickListener, View.OnLongClickListener, CurrentPathAdapter.OnCurrentPathRVItemClickListener, SubfileAdapter.OnSubfileRVItemClickListener {
34 |
35 | public static final int CHOICEMODE_ONLY_FILE = 1; // 只选文件
36 | public static final int CHOICEMODE_ONLY_FOLDER = 2; // 只选文件夹
37 | public static final int CHOICEMODE_UNLIMITED = 3; // 无限制选择
38 |
39 | private ImageView dialogSfofClose;
40 | private ImageView dialogSfofSelectAll;
41 | private ImageView dialogSfofFinish;
42 | private RecyclerView dialogSfofCurrentPathRView;
43 | private RecyclerView dialogSfofFilesRView;
44 |
45 | private CurrentPathAdapter mCurrentPathAdapter;
46 | private SubfileAdapter mSubfileAdapter;
47 | private List mCurrentFiles = new ArrayList<>();
48 | private List mSubFiles = new ArrayList<>();
49 | private Map mListPositions = new HashMap<>();
50 | private boolean mIsSingleChoice;
51 | private int mChoiceMode;
52 | private FileFilter mFileFilter;
53 | private OnSelectFileOrFolderListener mOnSelectFileOrFolderListener;
54 |
55 | /**
56 | * @param activity 界面对象
57 | * @param isSingleChoice true=单选;false=多选
58 | * @param choiceMode 选择模式;参照:CHOICEMODE_ONLY_FILE、CHOICEMODE_ONLY_FOLDER、CHOICEMODE_UNLIMITED
59 | * @param OnSelectFileOrFolderListener 监听器
60 | */
61 | public SelectFileOrFolderDialog(Activity activity, boolean isSingleChoice, int choiceMode, OnSelectFileOrFolderListener onSelectFileOrFolderListener) {
62 | super(activity, R.layout.dialog_select_file_or_folder, DIALOG_MODE_BOTTOM);
63 | this.mIsSingleChoice = isSingleChoice;
64 | this.mChoiceMode = choiceMode;
65 | this.mOnSelectFileOrFolderListener = onSelectFileOrFolderListener;
66 | setCancelable(false);
67 | getWindow().setWindowAnimations(R.style.UpyaAnimSelectFileOrFolderDialog);
68 |
69 | dialogSfofClose = findViewById(R.id.dialogSfofClose);
70 | dialogSfofSelectAll = findViewById(R.id.dialogSfofSelectAll);
71 | dialogSfofFinish = findViewById(R.id.dialogSfofFinish);
72 | dialogSfofCurrentPathRView = findViewById(R.id.dialogSfofCurrentPathRView);
73 | dialogSfofFilesRView = findViewById(R.id.dialogSfofFilesRView);
74 | dialogSfofClose.setOnClickListener(this);
75 | dialogSfofSelectAll.setOnClickListener(this);
76 | dialogSfofFinish.setOnClickListener(this);
77 | dialogSfofClose.setOnLongClickListener(this);
78 | dialogSfofSelectAll.setOnLongClickListener(this);
79 | dialogSfofFinish.setOnLongClickListener(this);
80 |
81 | TextView dialogSfofTitle = findViewById(R.id.dialogSfofTitle);
82 | switch (mChoiceMode) {
83 | case CHOICEMODE_ONLY_FILE:
84 | dialogSfofTitle.setText(R.string.dialogSfofTitle1);
85 | break;
86 | case CHOICEMODE_ONLY_FOLDER:
87 | dialogSfofTitle.setText(R.string.dialogSfofTitle2);
88 | break;
89 | case CHOICEMODE_UNLIMITED:
90 | dialogSfofTitle.setText(R.string.dialogSfofTitle3);
91 | break;
92 | }
93 |
94 | dialogSfofSelectAll.setVisibility(mIsSingleChoice ? View.GONE : View.VISIBLE);
95 | changeSfofSelectAllState(false);
96 | changeSfofFinishState(false);
97 |
98 | dialogSfofCurrentPathRView.setLayoutManager(new LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false));
99 | dialogSfofCurrentPathRView.setAdapter(mCurrentPathAdapter = new CurrentPathAdapter(this));
100 | dialogSfofFilesRView.setLayoutManager(new LinearLayoutManager(activity));
101 | dialogSfofFilesRView.setAdapter(mSubfileAdapter = new SubfileAdapter(isSingleChoice, mChoiceMode, this));
102 |
103 | mFileFilter = new FileFilter() {
104 | @Override
105 | public boolean accept(File pathname) {
106 | if (mChoiceMode == CHOICEMODE_ONLY_FOLDER) {
107 | return pathname.isDirectory();
108 | } else {
109 | return true;
110 | }
111 | }
112 | };
113 |
114 | setOnKeyListener((dialog, keyCode, event) -> {
115 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP) {
116 | rollbackFiles();
117 | return false;
118 | }
119 | return false;
120 | });
121 |
122 | Utils.mHandler.post(() -> {
123 | File sdFile = Environment.getExternalStorageDirectory();
124 | loadFiles(sdFile);
125 | });
126 | }
127 |
128 | @Override
129 | public void onClick(View v) {
130 | if (v.getId() == R.id.dialogSfofClose) {
131 | dismiss();
132 | } else if (v.getId() == R.id.dialogSfofSelectAll) {
133 | boolean isSelectAll = (boolean) dialogSfofSelectAll.getTag();
134 | Map selectedFileMap = mSubfileAdapter.getSelectedFileMap();
135 |
136 | for (File subFile : mSubFiles) {
137 | if (mChoiceMode == CHOICEMODE_ONLY_FILE && subFile.isDirectory())
138 | continue;
139 |
140 | String path = subFile.getAbsolutePath();
141 | if (isSelectAll) { // 需要全不选
142 | selectedFileMap.remove(path);
143 | } else { // 需要全选
144 | selectedFileMap.put(path, subFile);
145 | }
146 | }
147 |
148 | changeSfofSelectAllState(!isSelectAll);
149 | changeSfofFinishState(!selectedFileMap.isEmpty());
150 | mSubfileAdapter.notifyDataSetChanged();
151 | } else if (v.getId() == R.id.dialogSfofFinish) {
152 | if (mOnSelectFileOrFolderListener != null) {
153 | Map selectedFileMap = mSubfileAdapter.getSelectedFileMap();
154 | mOnSelectFileOrFolderListener.onSelectFileOrFolder(new ArrayList<>(selectedFileMap.values()));
155 | }
156 | dismiss();
157 | }
158 | }
159 |
160 | @Override
161 | public boolean onLongClick(View v) {
162 | if (v.getId() == R.id.dialogSfofClose) {
163 | Toast.makeText(getContext(), "关闭按钮", Toast.LENGTH_SHORT).show();
164 | } else if (v.getId() == R.id.dialogSfofSelectAll) {
165 | Toast.makeText(getContext(), "全选按钮", Toast.LENGTH_SHORT).show();
166 | } else if (v.getId() == R.id.dialogSfofFinish) {
167 | Toast.makeText(getContext(), "完成按钮", Toast.LENGTH_SHORT).show();
168 | }
169 | return true;
170 | }
171 |
172 | @Override
173 | public void dismiss() {
174 | super.dismiss();
175 | dialogSfofClose = null;
176 | dialogSfofSelectAll = null;
177 | dialogSfofFinish = null;
178 | dialogSfofCurrentPathRView = null;
179 | dialogSfofFilesRView = null;
180 | mCurrentFiles = null;
181 | mSubFiles = null;
182 | mListPositions = null;
183 | }
184 |
185 | @Override
186 | public void onCurrentPathRVItemClick(int position, File bean) {
187 | gotoFiles(bean);
188 | }
189 |
190 | @Override
191 | public void onSubfileRVItemClick(int position, File bean) {
192 | loadFiles(bean);
193 | }
194 |
195 | /** 选中文件回调/查询更新全选状态 */
196 | @Override
197 | public void onSubfileRVItemCBClick() {
198 | Map selectedFileMap = mSubfileAdapter.getSelectedFileMap();
199 | if (selectedFileMap.isEmpty()) {
200 | changeSfofSelectAllState(false);
201 | changeSfofFinishState(false);
202 | } else {
203 | if (dialogSfofSelectAll.getVisibility() == View.VISIBLE) {
204 | boolean isSelectAll = true;
205 | for (File subFile : mSubFiles) {
206 | if ((mChoiceMode == CHOICEMODE_ONLY_FILE && subFile.isFile()) || (mChoiceMode == CHOICEMODE_ONLY_FOLDER && subFile.isDirectory()) || (mChoiceMode == CHOICEMODE_UNLIMITED)) {
207 | if (!selectedFileMap.containsValue(subFile)) {
208 | isSelectAll = false;
209 | break;
210 | }
211 | }
212 | }
213 | changeSfofSelectAllState(isSelectAll);
214 | }
215 | changeSfofFinishState(true);
216 | }
217 | }
218 |
219 | /** 加载文件数据 */
220 | private void loadFiles(File currentFile) {
221 | if (!mCurrentFiles.isEmpty()) {
222 | int[] positionRecord = Utils.getPositionAndOffset((LinearLayoutManager) dialogSfofFilesRView.getLayoutManager());
223 | mListPositions.put(mCurrentFiles.get(mCurrentFiles.size() - 1).getAbsolutePath(), positionRecord);
224 | }
225 |
226 | mCurrentFiles.add(currentFile);
227 | File[] files = currentFile.listFiles(mFileFilter);
228 | mSubFiles.clear();
229 | if (files != null && files.length > 0) {
230 | mSubFiles.addAll(Arrays.asList(files));
231 | Utils.sortFileList(mSubFiles);
232 | }
233 |
234 | if (!mIsSingleChoice) {
235 | if (mSubFiles.isEmpty()) {
236 | dialogSfofSelectAll.setVisibility(View.GONE);
237 | } else {
238 | if (mChoiceMode == CHOICEMODE_ONLY_FILE) {
239 | boolean hasFile = false;
240 | for (File subFile : mSubFiles) {
241 | if (subFile.isFile()) {
242 | hasFile = true;
243 | break;
244 | }
245 | }
246 | dialogSfofSelectAll.setVisibility(hasFile ? View.VISIBLE : View.GONE);
247 | } else {
248 | dialogSfofSelectAll.setVisibility(View.VISIBLE);
249 | }
250 | }
251 | }
252 | onSubfileRVItemCBClick();
253 |
254 | mCurrentPathAdapter.onRefreshData(mCurrentFiles);
255 | mSubfileAdapter.onRefreshData(mSubFiles);
256 | dialogSfofFilesRView.scrollToPosition(0);
257 | Utils.mHandler.post(() -> dialogSfofCurrentPathRView.scrollToPosition(mCurrentFiles.size() - 1));
258 | }
259 |
260 | /** 回退文件数据 */
261 | private void rollbackFiles() {
262 | if (mCurrentFiles.size() <= 1) {
263 | dismiss();
264 | return;
265 | }
266 |
267 | mCurrentFiles.remove(mCurrentFiles.size() - 1);
268 | File currentFile = mCurrentFiles.get(mCurrentFiles.size() - 1);
269 | File[] files = currentFile.listFiles(mFileFilter);
270 | mSubFiles.clear();
271 | if (files != null && files.length > 0) {
272 | mSubFiles.addAll(Arrays.asList(files));
273 | Utils.sortFileList(mSubFiles);
274 | }
275 |
276 | if (!mIsSingleChoice) {
277 | if (mSubFiles.isEmpty()) {
278 | dialogSfofSelectAll.setVisibility(View.GONE);
279 | } else {
280 | if (mChoiceMode == CHOICEMODE_ONLY_FILE) {
281 | boolean hasFile = false;
282 | for (File subFile : mSubFiles) {
283 | if (subFile.isFile()) {
284 | hasFile = true;
285 | break;
286 | }
287 | }
288 | dialogSfofSelectAll.setVisibility(hasFile ? View.VISIBLE : View.GONE);
289 | } else {
290 | dialogSfofSelectAll.setVisibility(View.VISIBLE);
291 | }
292 | }
293 | }
294 | onSubfileRVItemCBClick();
295 |
296 | mCurrentPathAdapter.onRefreshData(mCurrentFiles);
297 | mSubfileAdapter.onRefreshData(mSubFiles);
298 | int[] positionRecord = mListPositions.get(currentFile.getAbsolutePath());
299 | ((LinearLayoutManager) dialogSfofFilesRView.getLayoutManager()).scrollToPositionWithOffset(positionRecord[0], positionRecord[1]);
300 | }
301 |
302 | /** 跳转到指定文件数据 */
303 | private void gotoFiles(File currentFile) {
304 | int index = mCurrentFiles.indexOf(currentFile);
305 | if (index + 1 == mCurrentFiles.size())
306 | return;
307 |
308 | mCurrentFiles.subList(index + 1, mCurrentFiles.size()).clear();
309 | File[] files = currentFile.listFiles(mFileFilter);
310 | mSubFiles.clear();
311 | if (files != null && files.length > 0) {
312 | mSubFiles.addAll(Arrays.asList(files));
313 | Utils.sortFileList(mSubFiles);
314 | }
315 |
316 | if (!mIsSingleChoice) {
317 | if (mSubFiles.isEmpty()) {
318 | dialogSfofSelectAll.setVisibility(View.GONE);
319 | } else {
320 | if (mChoiceMode == CHOICEMODE_ONLY_FILE) {
321 | boolean hasFile = false;
322 | for (File subFile : mSubFiles) {
323 | if (subFile.isFile()) {
324 | hasFile = true;
325 | break;
326 | }
327 | }
328 | dialogSfofSelectAll.setVisibility(hasFile ? View.VISIBLE : View.GONE);
329 | } else {
330 | dialogSfofSelectAll.setVisibility(View.VISIBLE);
331 | }
332 | }
333 | }
334 | onSubfileRVItemCBClick();
335 |
336 | mCurrentPathAdapter.onRefreshData(mCurrentFiles);
337 | mSubfileAdapter.onRefreshData(mSubFiles);
338 | int[] positionRecord = mListPositions.get(currentFile.getAbsolutePath());
339 | ((LinearLayoutManager) dialogSfofFilesRView.getLayoutManager()).scrollToPositionWithOffset(positionRecord[0], positionRecord[1]);
340 | }
341 |
342 | /** 改变全选按钮状态 */
343 | private void changeSfofSelectAllState(boolean isSelectAll) {
344 | dialogSfofSelectAll.setTag(isSelectAll);
345 | dialogSfofSelectAll.setImageResource(isSelectAll ? R.drawable.svg_select_all : R.drawable.svg_select_none);
346 | }
347 |
348 | /** 改变完成按钮状态 */
349 | private void changeSfofFinishState(boolean isEnabled) {
350 | dialogSfofFinish.setEnabled(isEnabled);
351 | dialogSfofFinish.setImageResource(isEnabled ? R.drawable.svg_finish_enabled : R.drawable.svg_finish_disable);
352 | }
353 |
354 | /** 挑选文件或文件夹 监听事件回调 */
355 | public interface OnSelectFileOrFolderListener {
356 | /**
357 | * 回调选中的文件列表
358 | *
359 | * @param selectedFileList 选择的文件或文件夹列表
360 | */
361 | default void onSelectFileOrFolder(List selectedFileList) {
362 | }
363 | }
364 |
365 | }
366 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/java/vip/upya/lib/sfof/SubfileAdapter.java:
--------------------------------------------------------------------------------
1 | package vip.upya.lib.sfof;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.CheckBox;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import java.io.File;
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.List;
17 | import java.util.Map;
18 |
19 | /** 子文件列表 适配器 */
20 | @SuppressWarnings("all")
21 | public class SubfileAdapter extends RecyclerView.Adapter {
22 |
23 | private List listDatas;
24 | private Map selectedFileMap;
25 | private boolean isSingleChoice;
26 | private int choiceMode;
27 | private OnSubfileRVItemClickListener onSubfileRVItemClickListener;
28 |
29 | public SubfileAdapter(boolean isSingleChoice, int choiceMode, OnSubfileRVItemClickListener onSubfileRVItemClickListener) {
30 | this.listDatas = new ArrayList<>();
31 | this.selectedFileMap = new HashMap<>();
32 | this.isSingleChoice = isSingleChoice;
33 | this.choiceMode = choiceMode;
34 | this.onSubfileRVItemClickListener = onSubfileRVItemClickListener;
35 | }
36 |
37 | @NonNull
38 | @Override
39 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
40 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_subfile, parent, false);
41 | return new ViewHolder(view);
42 | }
43 |
44 | @Override
45 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
46 | File file = listDatas.get(position);
47 | boolean isFile = file.isFile();
48 | boolean isDirectory = file.isDirectory();
49 |
50 | holder.itemSfName.setText(file.getName());
51 | holder.itemSfUpdateTime.setText("更新时间:" + Utils.getTimestampToDate("yyyy-MM-dd HH:mm:ss", file.lastModified()));
52 | if (isFile) {
53 | holder.itemSfImage.setImageResource(R.drawable.svg_file);
54 | holder.itemSfSize.setText("文件大小:" + Utils.formatFileSize(file.length()));
55 | holder.itemSfSize.setVisibility(View.VISIBLE);
56 | holder.itemView.setOnClickListener(null);
57 | } else if (isDirectory) {
58 | holder.itemSfImage.setImageResource(R.drawable.svg_folder);
59 | holder.itemSfSize.setVisibility(View.GONE);
60 | holder.itemView.setOnClickListener(v -> {
61 | if (onSubfileRVItemClickListener != null)
62 | onSubfileRVItemClickListener.onSubfileRVItemClick(position, file);
63 | });
64 | } else {
65 | holder.itemSfImage.setImageResource(R.drawable.svg_unknown_file);
66 | holder.itemSfSize.setVisibility(View.GONE);
67 | holder.itemView.setOnClickListener(null);
68 | }
69 |
70 | if (choiceMode == SelectFileOrFolderDialog.CHOICEMODE_ONLY_FILE) {
71 | if (isDirectory) {
72 | holder.itemSfCheck.setVisibility(View.GONE);
73 | } else {
74 | holder.itemSfCheck.setVisibility(View.VISIBLE);
75 | }
76 | } else {
77 | holder.itemSfCheck.setVisibility(View.VISIBLE);
78 | }
79 |
80 | holder.itemSfCheck.setOnCheckedChangeListener(null);
81 | if (holder.itemSfCheck.getVisibility() == View.VISIBLE) {
82 | holder.itemSfCheck.setChecked(selectedFileMap.containsKey(file.getAbsolutePath()));
83 | holder.itemSfCheck.setOnCheckedChangeListener((buttonView, isChecked) -> {
84 | if (isChecked) {
85 | if (isSingleChoice)
86 | selectedFileMap.clear();
87 |
88 | selectedFileMap.put(file.getAbsolutePath(), file);
89 |
90 | if (isSingleChoice)
91 | Utils.mHandler.postDelayed(this::notifyDataSetChanged, 100);
92 | } else {
93 | selectedFileMap.remove(file.getAbsolutePath());
94 | }
95 | if (onSubfileRVItemClickListener != null)
96 | onSubfileRVItemClickListener.onSubfileRVItemCBClick();
97 | });
98 | }
99 | }
100 |
101 | @Override
102 | public int getItemCount() {
103 | return this.listDatas.size();
104 | }
105 |
106 | /** 刷新数据 */
107 | public void onRefreshData(List list) {
108 | this.listDatas.clear();
109 | if (list != null && !list.isEmpty())
110 | this.listDatas.addAll(list);
111 | notifyDataSetChanged();
112 | }
113 |
114 | /** 获取选中的数据 */
115 | public Map getSelectedFileMap() {
116 | return selectedFileMap;
117 | }
118 |
119 | class ViewHolder extends RecyclerView.ViewHolder {
120 | ImageView itemSfImage;
121 | TextView itemSfName;
122 | TextView itemSfSize;
123 | TextView itemSfUpdateTime;
124 | CheckBox itemSfCheck;
125 |
126 | ViewHolder(@NonNull View itemView) {
127 | super(itemView);
128 | itemSfImage = itemView.findViewById(R.id.itemSfImage);
129 | itemSfName = itemView.findViewById(R.id.itemSfName);
130 | itemSfSize = itemView.findViewById(R.id.itemSfSize);
131 | itemSfUpdateTime = itemView.findViewById(R.id.itemSfUpdateTime);
132 | itemSfCheck = itemView.findViewById(R.id.itemSfCheck);
133 | }
134 | }
135 |
136 | /** RecyclerView Item 监听事件回调 */
137 | public interface OnSubfileRVItemClickListener {
138 | /** RecyclerView Item 点击 */
139 | default void onSubfileRVItemClick(int position, File bean) {
140 | }
141 |
142 | /** RecyclerView Item CheckBox 点击 */
143 | default void onSubfileRVItemCBClick() {
144 | }
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/java/vip/upya/lib/sfof/UpyaBaseDialog.java:
--------------------------------------------------------------------------------
1 | package vip.upya.lib.sfof;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.Gravity;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.Window;
9 | import android.widget.EditText;
10 | import android.widget.LinearLayout;
11 |
12 | import androidx.annotation.IdRes;
13 | import androidx.appcompat.app.AlertDialog;
14 |
15 | /** 基础 视图弹窗 */
16 | public class UpyaBaseDialog extends AlertDialog {
17 |
18 | protected static final int DIALOG_MODE_NONE = 0; // 不做设置
19 | protected static final int DIALOG_MODE_TOP = 1; // 整体布局重心向上,左右撑满(PS:状态栏不会被覆盖)
20 | protected static final int DIALOG_MODE_BOTTOM = 2; // 整体布局重心向下,左右撑满
21 |
22 | private View contentView;
23 | private int dialogMode;
24 |
25 | /** 默认不设置重力 构造函数 【layoutResID = 布局ID】 */
26 | public UpyaBaseDialog(Activity activity, int layoutResID) {
27 | super(activity, R.style.UpyaDialogBGT);
28 | contentView = LayoutInflater.from(activity).inflate(layoutResID, null);
29 | this.dialogMode = DIALOG_MODE_NONE;
30 | init(activity);
31 | }
32 |
33 | /** 自定义重力 构造函数 【layoutResID = 布局ID】【dialogMode = 布局模式】 */
34 | public UpyaBaseDialog(Activity activity, int layoutResID, int dialogMode) {
35 | super(activity, R.style.UpyaDialogBGT);
36 | contentView = LayoutInflater.from(activity).inflate(layoutResID, null);
37 | this.dialogMode = dialogMode;
38 | init(activity);
39 | }
40 |
41 | /** 自定义样式&重力 构造函数 【styleResID = 自定义样式 】【layoutResID = 布局ID】【dialogMode = 布局模式】 */
42 | public UpyaBaseDialog(Activity activity, int styleResID, int layoutResID, int dialogMode) {
43 | super(activity, styleResID);
44 | contentView = LayoutInflater.from(activity).inflate(layoutResID, null);
45 | this.dialogMode = dialogMode;
46 | init(activity);
47 | }
48 |
49 | /** 初始化参数 */
50 | private void init(Activity activity) {
51 | setView(new EditText(activity)); // 解决输入框无法获取焦点问题
52 | }
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(contentView);
58 |
59 | Window window = getWindow();
60 | if (window != null) {
61 | switch (dialogMode) {
62 | case DIALOG_MODE_NONE:
63 | window.setGravity(Gravity.CENTER);
64 | break;
65 | case DIALOG_MODE_TOP:
66 | window.setGravity(Gravity.TOP);
67 | window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
68 | break;
69 | case DIALOG_MODE_BOTTOM:
70 | window.setGravity(Gravity.BOTTOM);
71 | window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
72 | break;
73 | }
74 | }
75 | }
76 |
77 | @Override
78 | public T findViewById(@IdRes int id) {
79 | return contentView.findViewById(id);
80 | }
81 |
82 | @Override
83 | public void dismiss() {
84 | super.dismiss();
85 | contentView = null;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/java/vip/upya/lib/sfof/Utils.java:
--------------------------------------------------------------------------------
1 | package vip.upya.lib.sfof;
2 |
3 | import android.os.Handler;
4 | import android.view.View;
5 |
6 | import androidx.recyclerview.widget.LinearLayoutManager;
7 |
8 | import java.io.File;
9 | import java.text.SimpleDateFormat;
10 | import java.util.Collections;
11 | import java.util.List;
12 | import java.util.Locale;
13 |
14 | /** 工具类 */
15 | @SuppressWarnings("all")
16 | public class Utils {
17 |
18 | public static final Handler mHandler = new Handler();
19 |
20 | /** 时间戳 TO 字符串日期 */
21 | public static String getTimestampToDate(String format, long timestamp) {
22 | return new SimpleDateFormat(format, Locale.getDefault()).format(timestamp);
23 | }
24 |
25 | /**
26 | * 格式化文件大小
27 | *
28 | * @param length 文件大小(以Byte为单位)
29 | * @return String 格式化的常见文件大小(保留两位小数)
30 | */
31 | public static String formatFileSize(long length) {
32 | String result;
33 | int subString;
34 |
35 | if (length >= 1073741824) { // 如果文件长度大于1GB
36 | subString = String.valueOf((float) length / 1073741824).indexOf(".");
37 | result = ((float) length / 1073741824 + "000").substring(0, subString + 3) + "GB";
38 | } else if (length >= 1048576) { // 如果文件长度大于1MB且小于1GB
39 | subString = String.valueOf((float) length / 1048576).indexOf(".");
40 | result = ((float) length / 1048576 + "000").substring(0, subString + 3) + "MB";
41 | } else if (length >= 1024) { // 如果文件长度大于1KB且小于1MB
42 | subString = String.valueOf((float) length / 1024).indexOf(".");
43 | result = ((float) length / 1024 + "000").substring(0, subString + 3) + "KB";
44 | } else
45 | result = length + "B";
46 | return result;
47 | }
48 |
49 | /** 排序文件列表 */
50 | public static void sortFileList(List fileList) {
51 | Collections.sort(fileList, (o1, o2) -> {
52 | if (o1.isDirectory() && o2.isFile())
53 | return -1;
54 | if (o1.isFile() && o2.isDirectory())
55 | return 1;
56 | return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
57 | });
58 | }
59 |
60 | /** 记录RecyclerView当前位置 */
61 | public static int[] getPositionAndOffset(LinearLayoutManager linearLayoutManager) {
62 | int[] positionRecord = new int[2];
63 |
64 | View topView = linearLayoutManager.getChildAt(0);
65 | if (topView != null) {
66 | positionRecord[0] = linearLayoutManager.getPosition(topView);
67 | positionRecord[1] = topView.getTop();
68 | }
69 |
70 | return positionRecord;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/anim/upya_dialog_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
17 |
18 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/anim/upya_dialog_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
17 |
18 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_close.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_file.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_finish_disable.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_finish_enabled.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_folder.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_into.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_select_all.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_select_none.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/drawable/svg_unknown_file.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/layout/dialog_select_file_or_folder.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
15 |
16 |
20 |
21 |
29 |
30 |
39 |
40 |
48 |
49 |
57 |
58 |
59 |
63 |
64 |
68 |
69 |
73 |
74 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/layout/item_current_path.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/layout/item_subfile.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 |
25 |
31 |
32 |
38 |
39 |
45 |
46 |
47 |
52 |
53 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | UpyaSfof
4 | 请挑选文件
5 | 请挑选文件夹
6 | 请挑选文件或文件夹
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sfoflibrary/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------