├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── cn
│ │ └── zfs
│ │ └── fileselectorexample
│ │ ├── MainActivity.kt
│ │ └── CheckPermissionsActivity.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-xhdpi
│ │ │ ├── fs_pdf.png
│ │ │ ├── fs_ppt.png
│ │ │ ├── fs_ps.png
│ │ │ ├── fs_zip.png
│ │ │ ├── fs_arrow.png
│ │ │ ├── fs_audio.png
│ │ │ ├── fs_excel.png
│ │ │ ├── fs_file.png
│ │ │ ├── fs_flash.png
│ │ │ ├── fs_html.png
│ │ │ ├── fs_text.png
│ │ │ ├── fs_word.png
│ │ │ └── fs_developer.png
│ │ ├── drawable
│ │ │ ├── fs_action_dialog_bg.xml
│ │ │ ├── fs_popun_menu_bg.xml
│ │ │ ├── fs_chkbox_bg.xml
│ │ │ ├── fs_simple_btn_bg.xml
│ │ │ ├── fs_ic_chk_uncheck.xml
│ │ │ ├── fs_ic_back.xml
│ │ │ ├── fs_ic_more.xml
│ │ │ ├── fs_ic_chk_checked.xml
│ │ │ ├── fs_ic_fork.xml
│ │ │ ├── fs_ic_folder.xml
│ │ │ ├── fs_ic_del.xml
│ │ │ └── fs_ic_select_all.xml
│ │ ├── anim
│ │ │ ├── fs_dialog_in_from_bottom.xml
│ │ │ └── fs_dialog_out_from_bottom.xml
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ └── colors.xml
│ │ └── layout
│ │ │ ├── fs_listview.xml
│ │ │ ├── fs_item_popup_menu.xml
│ │ │ ├── fs_dir_view.xml
│ │ │ ├── fs_dialog_selected_item.xml
│ │ │ ├── fs_file_item_view.xml
│ │ │ └── fs_activity_select_file.xml
│ │ ├── java
│ │ └── cn
│ │ │ └── wandersnail
│ │ │ └── fileselector
│ │ │ ├── OnFileSelectListener.java
│ │ │ ├── Language.java
│ │ │ ├── DirCell.java
│ │ │ ├── ViewHolder.java
│ │ │ ├── BaseHolder.java
│ │ │ ├── Item.java
│ │ │ ├── BaseListAdapter.java
│ │ │ ├── ActionDialog.java
│ │ │ ├── TextHolder.java
│ │ │ ├── FileSelector.java
│ │ │ ├── SelectedItemDialog.java
│ │ │ ├── Utils.java
│ │ │ ├── CharacterParser.java
│ │ │ └── SelectFileActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.gradle
2 | /.idea
3 | *.iml
4 | build
5 | /local.properties
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_pdf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_pdf.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_ppt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_ppt.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_ps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_ps.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_zip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_zip.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_arrow.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_audio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_audio.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_excel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_excel.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_file.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_flash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_flash.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_html.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_html.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_text.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_word.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_word.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/fs_developer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wandersnail/fileselector/HEAD/library/src/main/res/drawable-xhdpi/fs_developer.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 03 16:28:23 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.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_action_dialog_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_popun_menu_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/OnFileSelectListener.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * date: 2019/8/8 14:40
7 | * author: zengfansheng
8 | */
9 | public interface OnFileSelectListener {
10 | void onFileSelect(int requestCode, List paths);
11 | }
12 |
--------------------------------------------------------------------------------
/library/src/main/res/anim/fs_dialog_in_from_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/res/anim/fs_dialog_out_from_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/Language.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | /**
4 | * date: 2019/8/8 14:48
5 | * author: zengfansheng
6 | */
7 | public enum Language {
8 | SIMPLIFIED_CHINESE(0), TRADITIONAL_CHINESE(1), ENGLISH(2);
9 |
10 | int value;
11 |
12 | Language(int value) {
13 | this.value = value;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_chkbox_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_listview.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/DirCell.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * date: 2019/8/8 14:39
7 | * author: zengfansheng
8 | */
9 | class DirCell {
10 | int index;
11 | File location;
12 |
13 | DirCell() {
14 | }
15 |
16 | DirCell(int index, File location) {
17 | this.index = index;
18 | this.location = location;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_simple_btn_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.view.View;
4 | import android.widget.ImageView;
5 | import android.widget.TextView;
6 |
7 | /**
8 | * date: 2019/8/8 14:41
9 | * author: zengfansheng
10 | */
11 | abstract class ViewHolder extends BaseHolder- {
12 | TextView tvName;
13 | TextView tvDesc;
14 | ImageView iv;
15 | ImageView ivSelect;
16 | View chkView;
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | fileselector
3 | 设置
4 | 取消
5 | 当前应用缺少必要权限。\n\n请点击\"设置\"-\"权限\"-打开所需权限。
6 | 申请权限
7 | 应用需要打开修改系统设置权限
8 | 应用需要打开未知来源权限
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_chk_uncheck.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #5F51B5
4 | #4d3F9F
5 | #FF4081
6 |
7 | #008577
8 | #00574B
9 | #F3343C
10 | #BF2830
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_item_popup_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_back.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/BaseHolder.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * date: 2019/8/8 13:40
7 | * author: zengfansheng
8 | */
9 | abstract class BaseHolder {
10 | final View convertView;
11 |
12 | BaseHolder() {
13 | convertView = createConvertView();
14 | convertView.setTag(this);
15 | }
16 |
17 |
18 | /**
19 | * 设置数据
20 | */
21 | abstract void setData(T data, int position);
22 |
23 | /**
24 | * 创建界面
25 | */
26 | abstract View createConvertView();
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_more.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
8 |
9 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_dir_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4C61D9
4 | #3F51B5
5 | #FEFEFE
6 | #00000000
7 | #FFFFFF
8 | #050505
9 | #E1E1E1
10 | #989898
11 | #505050
12 | #bfbfbf
13 | #CCCCCC
14 | #b0b0b0
15 | #11000000
16 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_chk_checked.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_fork.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/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 | android.enableJetifier=true
10 | android.useAndroidX=true
11 | org.gradle.jvmargs=-Xmx1536m
12 | # When configured, Gradle will run in incubating parallel mode.
13 | # This option should only be used with decoupled projects. More details, visit
14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
15 | # org.gradle.parallel=true
16 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_folder.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_del.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | applicationId "cn.zfs.fileselectorexample"
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation "androidx.appcompat:appcompat:$appcompat_version"
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30 | implementation "com.github.bumptech.glide:glide:$glide_version"
31 | implementation "cn.wandersnail:common-utils:$common_utils_version"
32 | implementation "cn.wandersnail:common-base:$common_base_version"
33 | implementation project(':library')
34 | }
35 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/fs_ic_select_all.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/Item.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import java.io.File;
4 | import java.util.Objects;
5 |
6 | import androidx.annotation.NonNull;
7 |
8 | /**
9 | * date: 2019/8/8 14:44
10 | * author: zengfansheng
11 | */
12 | class Item implements Comparable
- {
13 | File file;
14 | boolean checked;
15 | String desc;
16 |
17 | Item(File file, boolean checked) {
18 | this.file = file;
19 | this.checked = checked;
20 | }
21 |
22 | Item(File file, boolean checked, String desc) {
23 | this.file = file;
24 | this.checked = checked;
25 | this.desc = desc;
26 | }
27 |
28 | @Override
29 | public int compareTo(@NonNull Item other) {
30 | if (file == null) {
31 | return -1;
32 | } else if (other.file == null) {
33 | return 1;
34 | }
35 | String s = CharacterParser.getSpelling(file.getName());
36 | String s1 = CharacterParser.getSpelling(other.file.getName());
37 | return s.compareTo(s1);
38 | }
39 |
40 | @Override
41 | public boolean equals(Object o) {
42 | if (this == o) return true;
43 | if (!(o instanceof Item)) return false;
44 | Item item = (Item) o;
45 | return Objects.equals(file, item.file);
46 | }
47 |
48 | @Override
49 | public int hashCode() {
50 | return Objects.hash(file);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/BaseListAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * date: 2019/8/8 13:43
13 | * author: zengfansheng
14 | */
15 | abstract class BaseListAdapter extends BaseAdapter {
16 | protected Context context;
17 | protected List data;
18 |
19 | BaseListAdapter(Context context) {
20 | this(context, new ArrayList());
21 | }
22 |
23 | BaseListAdapter(Context context, List data) {
24 | this.context = context;
25 | this.data = data;
26 | }
27 |
28 | void refresh(List data) {
29 | this.data.clear();
30 | this.data.addAll(data);
31 | notifyDataSetChanged();
32 | }
33 |
34 | @Override
35 | public int getCount() {
36 | return data.size();
37 | }
38 |
39 | @Override
40 | public T getItem(int position) {
41 | return data.get(position);
42 | }
43 |
44 | @Override
45 | public long getItemId(int position) {
46 | return position;
47 | }
48 |
49 |
50 | @SuppressWarnings("unchecked")
51 | @Override
52 | public View getView(int position, View convertView, ViewGroup parent) {
53 | BaseHolder holder;
54 | if (convertView == null) {
55 | holder = getHolder(position);
56 | } else {
57 | holder = (BaseHolder) convertView.getTag();
58 | }
59 | holder.setData(data.get(position), position);
60 | return holder.convertView;
61 | }
62 |
63 | abstract BaseHolder getHolder(int position);
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_dialog_selected_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
17 |
27 |
34 |
45 |
46 |
47 |
51 |
52 |
58 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
19 |
24 |
25 |
26 |
29 |
34 |
39 |
40 |
41 |
44 |
49 |
54 |
55 |
56 |
60 |
61 |
64 |
68 |
69 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/ActionDialog.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.Window;
9 | import android.view.WindowManager;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import androidx.annotation.NonNull;
17 | import androidx.core.content.ContextCompat;
18 | import cn.wandersnail.commons.util.UiUtils;
19 |
20 | /**
21 | * date: 2019/8/8 13:34
22 | * author: zengfansheng
23 | */
24 | class ActionDialog extends Dialog {
25 | ActionDialog(@NonNull Activity context, ArrayList items, final Callback callback) {
26 | super(context);
27 | Window window = getWindow();
28 | if (window != null) {
29 | window.requestFeature(Window.FEATURE_NO_TITLE);
30 | window.getDecorView().setPadding(0, 0, 0, 0);
31 | window.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.fs_action_dialog_bg));
32 | window.setWindowAnimations(R.style.FsDialogAnimFromBottom);
33 | window.setGravity(Gravity.BOTTOM);
34 | WindowManager.LayoutParams lp = window.getAttributes();
35 | lp.width = WindowManager.LayoutParams.MATCH_PARENT;
36 | lp.height = items.size() * UiUtils.dp2px(50f) + items.size();
37 | window.setAttributes(lp);
38 | }
39 | setContentView(R.layout.fs_listview);
40 | ListView lv = findViewById(R.id.lv);
41 | lv.setAdapter(new ActionAdapter(context, items));
42 | lv.setOnItemClickListener((parent, view, position, id) -> {
43 | dismiss();
44 | callback.onSelect(position);
45 | });
46 | }
47 |
48 | interface Callback {
49 | void onSelect(int position);
50 | }
51 |
52 | class ActionAdapter extends BaseListAdapter {
53 | ActionAdapter(Context context, List data) {
54 | super(context, data);
55 | }
56 |
57 | @Override
58 | BaseHolder getHolder(int position) {
59 | return new BaseHolder() {
60 | private TextView tv;
61 |
62 | @Override
63 | void setData(String data, int position) {
64 | tv.setText(data);
65 | }
66 |
67 | @Override
68 | View createConvertView() {
69 | View view = View.inflate(context, R.layout.fs_item_popup_menu, null);
70 | tv = view.findViewById(R.id.fsTv);
71 | return view;
72 | }
73 | };
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_file_item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
24 |
25 |
33 |
34 |
41 |
42 |
51 |
58 |
65 |
66 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/zfs/fileselectorexample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package cn.zfs.fileselectorexample
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.util.Log
7 | import cn.wandersnail.fileselector.FileSelector
8 | import cn.wandersnail.fileselector.Language
9 | import kotlinx.android.synthetic.main.activity_main.*
10 | import java.io.FilenameFilter
11 |
12 | class MainActivity : CheckPermissionsActivity() {
13 | private var selector: FileSelector? = null
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setTheme(R.style.AppThemeGreen)
18 | setContentView(R.layout.activity_main)
19 | selector = FileSelector().setScreenOrientation(false)
20 | .setThemeColor(getColorByAttrId(this, R.attr.colorPrimary), getColorByAttrId(this, R.attr.colorPrimaryDark))
21 | .showHiddenFiles(false)
22 | .setFilenameFilter(FilenameFilter { dir, name -> !name.endsWith(".txt") })
23 | //设置根目录,如果不设置,默认为内部存储,设置null列出所有存储路径作为根目录
24 | // selector!!.setRoot(null)
25 | btnSelectMultiFile.setOnClickListener {
26 | selector!!.setMultiSelectionEnabled(true)
27 | selector!!.setSelectionMode(FileSelector.FILES_ONLY)
28 | selector!!.select(this, 1)
29 | }
30 | btnSelectSingleFile.setOnClickListener {
31 | selector!!.setMultiSelectionEnabled(false)
32 | selector!!.setLanguage(Language.ENGLISH)
33 | selector!!.setSelectionMode(FileSelector.FILES_ONLY)
34 | selector!!.select(this, 2)
35 | }
36 | btnSelectSingleDir.setOnClickListener {
37 | selector!!.setSelectionMode(FileSelector.DIRECTORIES_ONLY)
38 | // selector!!.setLanguage(Language.TRADITIONAL_CHINESE)
39 | selector!!.setScreenOrientation(true)
40 | selector!!.setRoot(null)
41 | selector!!.setMultiSelectionEnabled(false)
42 | selector!!.select(this, 3)
43 | }
44 | btnSelectMultiDir.setOnClickListener {
45 | selector!!.setMultiSelectionEnabled(true)
46 | selector!!.setSelectionMode(FileSelector.DIRECTORIES_ONLY)
47 | selector!!.select(this, 4)
48 | }
49 | btnSelectMultiFileDir.setOnClickListener {
50 | selector!!.setMultiSelectionEnabled(true)
51 | selector!!.setSelectionMode(FileSelector.FILES_AND_DIRECTORIES)
52 | selector!!.select(this, 5)
53 | }
54 | btnSelectSingleFileDir.setOnClickListener {
55 | selector!!.setLanguage(Language.SIMPLIFIED_CHINESE)
56 | selector!!.setMultiSelectionEnabled(false)
57 | selector!!.setSelectionMode(FileSelector.FILES_AND_DIRECTORIES)
58 | selector!!.select(this, 6)
59 | }
60 | selector!!.setTitle("文件选择器")
61 | selector!!.setOnFileSelectListener { requestCode, paths ->
62 | Log.d("Main", "requestCode: $requestCode")
63 | tvResult.text = ""
64 | paths.forEach {
65 | tvResult.append("$it\n")
66 | }
67 | }
68 | }
69 |
70 | fun getColorByAttrId(context: Context, attr: Int): Int {
71 | val typedArray = context.obtainStyledAttributes(intArrayOf(attr))
72 | val color = typedArray.getColor(0, -0x1000000)
73 | typedArray.recycle()
74 | return color
75 | }
76 |
77 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
78 | super.onActivityResult(requestCode, resultCode, data)
79 | selector?.onActivityResult(requestCode, resultCode, data)
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 | apply plugin: 'maven'
4 |
5 | def lib_version = '1.0.4'
6 | def lib_group = 'cn.wandersnail'
7 | def lib_artifact = 'file-selector'
8 | def lib_packaging = 'aar'
9 | def lib_description = 'file-selector for Android'
10 | group = lib_group
11 | version = lib_version
12 |
13 | android {
14 | compileSdkVersion rootProject.ext.compileSdkVersion
15 | defaultConfig {
16 | minSdkVersion rootProject.ext.minSdkVersion
17 | targetSdkVersion rootProject.ext.targetSdkVersion
18 | versionCode 1
19 | versionName "$lib_version"
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | lintOptions {
29 | abortOnError false
30 | }
31 | compileOptions {
32 | sourceCompatibility JavaVersion.VERSION_1_8
33 | targetCompatibility JavaVersion.VERSION_1_8
34 | }
35 | }
36 |
37 | dependencies {
38 | compileOnly "androidx.appcompat:appcompat:$appcompat_version"
39 | compileOnly "com.github.bumptech.glide:glide:$glide_version"
40 | compileOnly "cn.wandersnail:common-utils:$common_utils_version"
41 | compileOnly "cn.wandersnail:common-base:$common_base_version"
42 | }
43 |
44 | task sourcesJar(type: Jar) {
45 | archiveClassifier.set('sources')
46 | from android.sourceSets.main.java.srcDirs
47 | }
48 |
49 | task javadoc(type: Javadoc) {
50 | source = android.sourceSets.main.java.srcDirs
51 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
52 | }
53 |
54 | task javadocJar(type: Jar, dependsOn: javadoc) {
55 | archiveClassifier.set('javadoc')
56 | from javadoc.destinationDir
57 | }
58 |
59 | artifacts {
60 | archives sourcesJar
61 | archives javadocJar
62 | }
63 |
64 | publish {
65 | repoName = "androidx"//仓库名
66 | userOrg = 'wandersnail' //bintray.com用户名
67 | groupId = lib_group //jcenter上的路径
68 | artifactId = lib_artifact //项目名称
69 | publishVersion = lib_version //版本号
70 | desc = lib_description
71 | website = 'https://github.com/wandersnail/fileselector'
72 | }
73 |
74 | if (project.getGradle().startParameter.taskNames.any { it.contains('bintrayUpload') }) {
75 | gradle.taskGraph.whenReady { taskGraph ->
76 | taskGraph.getAllTasks().find {
77 | it.path == ":$project.name:generatePomFileForReleasePublication"
78 | }.doLast {
79 | file("build/publications/release/pom-default.xml").delete()
80 | println 'Overriding pom-file to make sure we can sync to maven central!'
81 | pom {
82 | //noinspection GroovyAssignabilityCheck
83 | project {
84 | name lib_artifact
85 | artifactId lib_artifact
86 | packaging lib_packaging
87 | description lib_description
88 | url 'https://github.com/wandersnail/fileselector'
89 | version lib_version
90 |
91 | scm {
92 | url 'https://github.com/wandersnail'
93 | connection 'scm:git:https://github.com/wandersnail/fileselector.git'
94 | developerConnection 'scm:git:https://github.com/wandersnail/fileselector.git'
95 | }
96 |
97 | licenses {
98 | license {
99 | name 'The Apache License, Version 2.0'
100 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
101 | }
102 | }
103 |
104 | developers {
105 | developer {
106 | id 'wandersnail'
107 | name 'Zeng Fansheng'
108 | email 'bingmo977@qq.com'
109 | }
110 | }
111 | }
112 | }.writeTo("build/publications/release/pom-default.xml")
113 | }
114 | }
115 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 推荐一款工具箱【蜗牛工具箱】
2 |
3 | > 涵盖广,功能丰富。生活实用、效率办公、图片处理等等,还有隐藏的VIP功能,总之很多惊喜的功能。各大应用市场搜索【蜗牛工具箱】安装即可。
4 |
5 |
11 |
12 | **部分功能介绍**
13 |
14 | - 【滚动字幕】超实用应援打call神器,输入文字内容使文字在屏幕中滚动显示;
15 | - 【振动器】可自定义振动频率、时长,达到各种有意思的效果;
16 | - 【测量仪器】手机当直尺、水平仪、指南针、分贝仪;
17 | - 【文件加解密】可加密任意文件,可用于私密文件分享;
18 | - 【金额转大写】将阿拉伯数字类型的金额转成中文大写;
19 | - 【通信调试】BLE/SPP蓝牙、USB、TCP/UDP/MQTT通信调试;
20 | - 【二维码】调用相机扫描或扫描图片识别二维码,支持解析WiFi二维码获取密码,输入文字生成相应的二维码;
21 | - 【图片模糊处理】将图片进行高斯模糊处理,毛玻璃效果;
22 | - 【黑白图片上色】黑白图片变彩色;
23 | - 【成语词典】查询成语拼音、释义、出处、例句;
24 | - 【图片拼接】支持长图、4宫格、9宫格拼接;
25 | - 【自动点击】自动连点器,解放双手;
26 | - 【图片加水印】图片上添加自定义水印;
27 | - 【网页定时刷新】设定刷新后自动定时刷新网页;
28 | - 【应用管理】查看本机安装的应用详细信息,并可提取安装包分享;
29 | - 【BLE调试】低功耗蓝牙GATT通信调试,支持主从模式,可多设备同时连接,实时日志;
30 | - 【SPP蓝牙调试】经典蓝牙Socket通信调试,支持自定义UUID,多设备同时连接,实时日志;
31 | - 【USB调试】USB串口调试,兼容芯片多,实时日志;
32 | ……
33 | 已集成上百个小工具,持续更新中...
34 |
35 | 点击下方按钮或扫码下载【蜗牛工具箱】
36 |
37 | [](https://www.pgyer.com/8AN5OhVd)
38 |
39 |
40 |
41 | ----------------------------------------------
42 |
43 | # 文件选择器使用说明
44 |
45 | ## 代码托管
46 | [](https://maven-badges.herokuapp.com/maven-central/cn.wandersnail/file-selector)
47 | [](https://github.com/wandersnail/fileselector)
48 | [](https://gitee.com/fszeng/fileselector)
49 | # 使用方法
50 |
51 | 1. module的build.gradle中的添加依赖,自行修改为最新版本,同步后通常就可以用了:
52 | ```
53 | dependencies {
54 | ...
55 | implementation 'cn.wandersnail:file-selector:latestVersion'
56 | implementation 'com.github.bumptech.glide:glide:latestVersion'
57 | implementation 'cn.wandersnail:common-base:latestVersion'
58 | implementation 'cn.wandersnail:common-utils:latestVersion'
59 | }
60 | ```
61 |
62 | 2. 如果从jcenter下载失败。在project的build.gradle里的repositories添加内容,最好两个都加上,添加完再次同步即可。
63 | ```
64 | allprojects {
65 | repositories {
66 | ...
67 | mavenCentral()
68 | maven { url 'https://dl.bintray.com/wandersnail/androidx/' }
69 | }
70 | }
71 | ```
72 |
73 |
74 | class MainActivity : CheckPermissionsActivity() {
75 | private var selector: FileSelector? = null
76 |
77 | override fun onCreate(savedInstanceState: Bundle?) {
78 | super.onCreate(savedInstanceState)
79 | setContentView(R.layout.activity_main)
80 | selector = FileSelector().setScreenOrientation(false)
81 | .setFilenameFilter(object : FilenameFilter() {
82 | override fun accept(dir: File?, name: String?): Boolean {
83 | return name != null && !name.startsWith(".")
84 | }
85 | })
86 | //设置根目录,如果不设置,默认列出所有存储路径作为根目录
87 | // selector!!.setRoot(Environment.getExternalStorageDirectory())
88 | btnSelectMultiFile.setOnClickListener {
89 | selector!!.setMultiSelect(true)
90 | selector!!.setSelectFile(true)
91 | selector!!.select(this)
92 | }
93 | btnSelectSingleFile.setOnClickListener {
94 | selector!!.setMultiSelect(false)
95 | selector!!.setSelectFile(true)
96 | selector!!.select(this)
97 | }
98 | btnSelectSingleDir.setOnClickListener {
99 | selector!!.setSelectFile(false)
100 | selector!!.setMultiSelect(false)
101 | selector!!.select(this)
102 | }
103 | btnSelectMultiDir.setOnClickListener {
104 | selector!!.setMultiSelect(true)
105 | selector!!.setSelectFile(false)
106 | selector!!.select(this)
107 | }
108 | selector!!.setOnFileSelectListener {
109 | tvResult.text = ""
110 | it.forEach {
111 | tvResult.append("$it\n")
112 | }
113 | }
114 | }
115 |
116 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
117 | super.onActivityResult(requestCode, resultCode, data)
118 | selector?.onActivityResult(requestCode, resultCode, data)
119 | }
120 | }
121 |
122 |
123 | ## 示例效果
124 | 
125 | 
126 | 
127 | 
128 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/TextHolder.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.util.SparseArray;
4 |
5 | /**
6 | * date: 2019/8/8 14:54
7 | * author: zengfansheng
8 | */
9 | class TextHolder {
10 | static final int ALL_FILES = 0;
11 | static final int ROOT = 1;
12 | static final int OK = 2;
13 | static final int CANCEL = 3;
14 | static final int SELECTED_PATTERN = 4;
15 | static final int CLEAR = 7;
16 | static final int CLOSE = 8;
17 | static final int SINGLE_ITEM_PATTERN = 9;
18 | static final int MULTI_ITEM_PATTERN = 10;
19 | static final int SELECTED_ITEM_PATTERN = 11;
20 | static final int NEW_FOLDER = 12;
21 | static final int FOLDER_CREATE_SUCCESS = 13;
22 | static final int FOLDER_CREATE_FAILED = 14;
23 | static final int RENAME = 15;
24 | static final int DELETE = 16;
25 | static final int ENSURE_DELETE_PROMPT = 17;
26 | static final int RENAME_SUCCESS = 18;
27 | static final int RENAME_FAILED = 19;
28 | static final int SHOW_HIDDEN_FILES = 20;
29 | static final int DONOT_SHOW_HIDDEN_FILES = 21;
30 | static final int VIEW_SELECTED_PATTERN = 22;
31 |
32 | private SparseArray> lanArr = new SparseArray<>();
33 | Language language = Language.SIMPLIFIED_CHINESE;
34 |
35 | TextHolder() {
36 | SparseArray zhCN = new SparseArray<>();
37 | zhCN.put(ALL_FILES, "全部文件");
38 | zhCN.put(ROOT, "根目录");
39 | zhCN.put(OK, "确定");
40 | zhCN.put(CANCEL, "取消");
41 | zhCN.put(SELECTED_PATTERN, "已选(%d)");
42 | zhCN.put(CLEAR, "清空");
43 | zhCN.put(CLOSE, "关闭");
44 | zhCN.put(SINGLE_ITEM_PATTERN, "%d项");
45 | zhCN.put(MULTI_ITEM_PATTERN, "%d项");
46 | zhCN.put(SELECTED_ITEM_PATTERN, "已选%d项");
47 | zhCN.put(NEW_FOLDER, "新建文件夹");
48 | zhCN.put(FOLDER_CREATE_SUCCESS, "文件夹创建成功");
49 | zhCN.put(FOLDER_CREATE_FAILED, "文件夹创建失败");
50 | zhCN.put(RENAME, "重命名");
51 | zhCN.put(RENAME_SUCCESS, "重命名成功");
52 | zhCN.put(RENAME_FAILED, "重命名失败");
53 | zhCN.put(DELETE, "删除");
54 | zhCN.put(ENSURE_DELETE_PROMPT, "确定删除吗");
55 | zhCN.put(SHOW_HIDDEN_FILES, "显示隐藏文件");
56 | zhCN.put(DONOT_SHOW_HIDDEN_FILES, "不显示隐藏文件");
57 | zhCN.put(VIEW_SELECTED_PATTERN, "查看已选(%d)");
58 | lanArr.put(Language.SIMPLIFIED_CHINESE.value, zhCN);
59 |
60 | SparseArray zhTW = new SparseArray<>();
61 | zhTW.put(ALL_FILES, "全部文件");
62 | zhTW.put(ROOT, "根目錄");
63 | zhTW.put(OK, "確定");
64 | zhTW.put(CANCEL, "取消");
65 | zhTW.put(SELECTED_PATTERN, "已選(%d)");
66 | zhTW.put(CLEAR, "清空");
67 | zhTW.put(CLOSE, "關閉");
68 | zhTW.put(SINGLE_ITEM_PATTERN, "%d項");
69 | zhTW.put(MULTI_ITEM_PATTERN, "%d項");
70 | zhTW.put(SELECTED_ITEM_PATTERN, "已選%d項");
71 | zhTW.put(NEW_FOLDER, "新建資料夾");
72 | zhTW.put(FOLDER_CREATE_SUCCESS, "資料夾創建成功");
73 | zhTW.put(FOLDER_CREATE_FAILED, "資料夾創建失敗");
74 | zhTW.put(RENAME, "重命名");
75 | zhTW.put(RENAME_SUCCESS, "重命名成功");
76 | zhTW.put(RENAME_FAILED, "重命名失敗");
77 | zhTW.put(DELETE, "刪除");
78 | zhTW.put(ENSURE_DELETE_PROMPT, "確定刪除嗎");
79 | zhTW.put(SHOW_HIDDEN_FILES, "顯示隱藏文件");
80 | zhTW.put(DONOT_SHOW_HIDDEN_FILES, "不顯示隱藏文件");
81 | zhTW.put(VIEW_SELECTED_PATTERN, "查看已選(%d)");
82 | lanArr.put(Language.TRADITIONAL_CHINESE.value, zhTW);
83 |
84 | SparseArray en = new SparseArray<>();
85 | en.put(ALL_FILES, "All files");
86 | en.put(ROOT, "root");
87 | en.put(OK, "OK");
88 | en.put(CANCEL, "Cancel");
89 | en.put(SELECTED_PATTERN, "Selected(%d)");
90 | en.put(CLEAR, "Clear");
91 | en.put(CLOSE, "Close");
92 | en.put(SINGLE_ITEM_PATTERN, "%d item");
93 | en.put(MULTI_ITEM_PATTERN, "%d items");
94 | en.put(SELECTED_ITEM_PATTERN, "%d selected");
95 | en.put(NEW_FOLDER, "New Folder");
96 | en.put(FOLDER_CREATE_SUCCESS, "The folder creation successfully");
97 | en.put(FOLDER_CREATE_FAILED, "The folder creation failed");
98 | en.put(RENAME, "Rename");
99 | en.put(RENAME_SUCCESS, "Rename successfully");
100 | en.put(RENAME_FAILED, "Rename failed");
101 | en.put(DELETE, "Delete");
102 | en.put(ENSURE_DELETE_PROMPT, "Are you sure you want to delete it?");
103 | en.put(SHOW_HIDDEN_FILES, "Show hidden files");
104 | en.put(DONOT_SHOW_HIDDEN_FILES, "Don't show hidden files");
105 | en.put(VIEW_SELECTED_PATTERN, "View selected(%d)");
106 | lanArr.put(Language.ENGLISH.value, en);
107 | }
108 |
109 | String getText(int id) {
110 | return lanArr.get(language.value).get(id, "");
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/FileSelector.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Environment;
7 | import android.os.Handler;
8 | import android.os.Looper;
9 |
10 | import java.io.File;
11 | import java.io.FilenameFilter;
12 |
13 | import androidx.annotation.NonNull;
14 | import androidx.fragment.app.Fragment;
15 |
16 | /**
17 | * date: 2019/8/8 15:44
18 | * author: zengfansheng
19 | */
20 | public class FileSelector {
21 | public static final int FILES_ONLY = 0;
22 | public static final int DIRECTORIES_ONLY = 1;
23 | public static final int FILES_AND_DIRECTORIES = 2;
24 |
25 | private OnFileSelectListener listener;
26 | private boolean isLandscape;
27 | private File root = Environment.getExternalStorageDirectory();
28 | private int selectionMode = FILES_ONLY;
29 | private boolean isMultiSelectionEnabled;
30 | private FilenameFilter filenameFilter;
31 | private String title;
32 | private int[] themeColors;
33 | private Language language = Language.SIMPLIFIED_CHINESE;
34 | private boolean showHiddenFiles;
35 | private Handler handler;
36 |
37 | /**
38 | * 设置文件选择回调
39 | */
40 | public FileSelector setOnFileSelectListener(OnFileSelectListener listener) {
41 | this.listener = listener;
42 | return this;
43 | }
44 |
45 | /**
46 | * 设置屏幕方向
47 | */
48 | public FileSelector setScreenOrientation(boolean landscape) {
49 | isLandscape = landscape;
50 | return this;
51 | }
52 |
53 | /**
54 | * 设置根目录,默认是内部存储
55 | *
56 | * @param root 当设置为null时,列出当前所有可用储存设备
57 | */
58 | public FileSelector setRoot(File root) {
59 | this.root = root;
60 | return this;
61 | }
62 |
63 | /**
64 | * 设置是选择模式
65 | *
66 | * @param selectionMode {@link #FILES_ONLY}, {@link #FILES_AND_DIRECTORIES}, {@link #DIRECTORIES_ONLY}
67 | */
68 | public FileSelector setSelectionMode(int selectionMode) {
69 | this.selectionMode = selectionMode;
70 | return this;
71 | }
72 |
73 | /**
74 | * 设置是否多选
75 | */
76 | public FileSelector setMultiSelectionEnabled(boolean multiSelectionEnabled) {
77 | isMultiSelectionEnabled = multiSelectionEnabled;
78 | return this;
79 | }
80 |
81 | /**
82 | * 设置文件名过滤器
83 | */
84 | public FileSelector setFilenameFilter(FilenameFilter filenameFilter) {
85 | this.filenameFilter = filenameFilter;
86 | return this;
87 | }
88 |
89 | /**
90 | * 设置标题
91 | */
92 | public FileSelector setTitle(String title) {
93 | this.title = title;
94 | return this;
95 | }
96 |
97 | /**
98 | * 设置主题颜色
99 | */
100 | public FileSelector setThemeColor(int colorPrimary, int colorPrimaryDark) {
101 | this.themeColors = new int[]{colorPrimary, colorPrimaryDark};
102 | return this;
103 | }
104 |
105 | /**
106 | * 设置显示语言
107 | */
108 | public FileSelector setLanguage(Language language) {
109 | this.language = language;
110 | return this;
111 | }
112 |
113 | /**
114 | * 设置是否显示隐藏文件和文件夹
115 | */
116 | public FileSelector showHiddenFiles(boolean showHiddenFiles) {
117 | this.showHiddenFiles = showHiddenFiles;
118 | return this;
119 | }
120 |
121 | /**
122 | * 开始选择
123 | */
124 | public void select(@NonNull Activity activity, int requestCode) {
125 | activity.startActivityForResult(obtainIntent(activity), requestCode);
126 | }
127 |
128 | /**
129 | * 开始选择
130 | */
131 | public void select(@NonNull Fragment fragment, int requestCode) {
132 | if (fragment.getActivity() != null) {
133 | fragment.startActivityForResult(obtainIntent(fragment.getActivity()), requestCode);
134 | }
135 | }
136 |
137 | private Intent obtainIntent(Context context) {
138 | SelectFileActivity.filenameFilter = filenameFilter;
139 | Intent intent = new Intent(context, SelectFileActivity.class);
140 | intent.putExtra(SelectFileActivity.EXTRA_SELECTOR_HASH, toString());
141 | intent.putExtra(SelectFileActivity.EXTRA_IS_LANDSCAPE, isLandscape);
142 | intent.putExtra(SelectFileActivity.EXTRA_SELECTION_MODE, selectionMode);
143 | intent.putExtra(SelectFileActivity.EXTRA_IS_MULTI_SELECT, isMultiSelectionEnabled);
144 | intent.putExtra(SelectFileActivity.EXTRA_LANGUAGE, language.value);
145 | intent.putExtra(SelectFileActivity.EXTRA_SHOW_HIDDEN_FILES, showHiddenFiles);
146 |
147 | if (title != null) {
148 | intent.putExtra(SelectFileActivity.EXTRA_TITLE, title);
149 | }
150 | if (root != null) {
151 | intent.putExtra(SelectFileActivity.EXTRA_ROOT, root);
152 | }
153 | if (themeColors != null) {
154 | intent.putExtra(SelectFileActivity.EXTRA_THEME_COLORS, themeColors);
155 | }
156 | return intent;
157 | }
158 |
159 | /**
160 | * 将Activty或Fragment的结果传过来处理
161 | */
162 | public void onActivityResult(int requestCode, int resultCode, final Intent data) {
163 | if (resultCode == Activity.RESULT_OK) {
164 | if (listener != null && data != null) {
165 | String name = data.getStringExtra(SelectFileActivity.EXTRA_SELECTOR_NAME);
166 | String classHash = data.getStringExtra(SelectFileActivity.EXTRA_SELECTOR_HASH);
167 | if (SelectFileActivity.class.getName().equals(name) && toString().equals(classHash)) {
168 | if (handler == null) {
169 | handler = new Handler(Looper.getMainLooper());
170 | }
171 | handler.postDelayed(() -> listener.onFileSelect(requestCode, data.getStringArrayListExtra(SelectFileActivity.EXTRA_SELECTED_FILE_PATH_LIST)), 200);
172 | }
173 | }
174 | }
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/fs_activity_select_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
29 |
30 |
34 |
35 |
41 |
42 |
48 |
49 |
50 |
51 |
57 |
58 |
65 |
66 |
70 |
71 |
72 |
75 |
76 |
84 |
85 |
97 |
98 |
99 |
100 |
105 |
106 |
114 |
115 |
124 |
125 |
133 |
134 |
143 |
144 |
145 |
146 |
151 |
152 |
156 |
157 |
164 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/zfs/fileselectorexample/CheckPermissionsActivity.java:
--------------------------------------------------------------------------------
1 | package cn.zfs.fileselectorexample;
2 |
3 | import android.Manifest;
4 | import android.app.AlertDialog;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.content.pm.PackageManager;
8 | import android.net.Uri;
9 | import android.os.Build;
10 | import android.provider.Settings;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.appcompat.app.AppCompatActivity;
17 | import androidx.core.app.ActivityCompat;
18 | import androidx.core.content.ContextCompat;
19 |
20 | /**
21 | * Created by zeng on 2016/9/11.
22 | * 实现Android6.0的运行时权限检测
23 | */
24 | public class CheckPermissionsActivity extends AppCompatActivity {
25 | private static final int PERMISSON_REQUESTCODE = 0;
26 | private static final int REQUEST_CODE_WRITE_SETTINGS = 1;
27 | private static final int REQUEST_CODE_UNKNOWN_APP_SOURCES = 2;
28 | protected boolean hasPermission = true;
29 |
30 |
31 | //判断是否需要检测,防止不停的弹框/
32 | public boolean isNeedCheck = true;
33 |
34 | //需要进行检测的权限
35 | private List getNeedPermissions() {
36 | List list = new ArrayList<>();
37 | list.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
38 | // list.add(Manifest.permission.ACCESS_NETWORK_STATE);
39 | // list.add(Manifest.permission.READ_PHONE_STATE);
40 | // list.add(Manifest.permission.WRITE_SETTINGS);
41 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
42 | // list.add(Manifest.permission.REQUEST_INSTALL_PACKAGES);
43 | // }
44 | return list;
45 | }
46 |
47 | @Override
48 | protected void onResume() {
49 | super.onResume();
50 | if(isNeedCheck){
51 | checkPermissions(getNeedPermissions());
52 | }
53 | }
54 |
55 | private void checkPermissions(List permissions) {
56 | if (permissions.remove(Manifest.permission.WRITE_SETTINGS) &&
57 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
58 | if (!Settings.System.canWrite(this)) {
59 | showRequestWriteSettingDialog();
60 | return;
61 | }
62 | }
63 | if (permissions.remove(Manifest.permission.REQUEST_INSTALL_PACKAGES) &&
64 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
65 | if (!getPackageManager().canRequestPackageInstalls()) {
66 | showRequestUnknownAppSourceDialog();
67 | return;
68 | }
69 | }
70 | List needRequestPermissonList = findDeniedPermissions(permissions);
71 | if (needRequestPermissonList.size() > 0) {
72 | ActivityCompat.requestPermissions(this, needRequestPermissonList.toArray(new String[0]), PERMISSON_REQUESTCODE);
73 | } else {
74 | isNeedCheck = false;
75 | onPermissionsRequestResult(true);
76 | }
77 | }
78 |
79 | //获取权限集中需要申请权限的列表
80 | private List findDeniedPermissions(List permissions) {
81 | List needRequestPermissonList = new ArrayList<>();
82 | for (String perm : permissions) {
83 | if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED ||
84 | ActivityCompat.shouldShowRequestPermissionRationale(this, perm)) {
85 | needRequestPermissonList.add(perm);
86 | }
87 | }
88 | return needRequestPermissonList;
89 | }
90 |
91 | //检测是否所有的权限都已经授权
92 | private boolean verifyPermissions(int[] grantResults) {
93 | for (int result : grantResults) {
94 | if (result != PackageManager.PERMISSION_GRANTED) {
95 | return false;
96 | }
97 | }
98 | return true;
99 | }
100 |
101 | private void showRequestWriteSettingDialog() {
102 | showDialog(getString(R.string.request_permission), getString(R.string.need_write_setting), new DialogInterface.OnClickListener() {
103 | @Override
104 | public void onClick(DialogInterface dialogInterface, int i) {
105 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
106 | startActivityForResult(new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS), REQUEST_CODE_WRITE_SETTINGS);
107 | }
108 | }
109 | });
110 | }
111 |
112 | private void showRequestUnknownAppSourceDialog() {
113 | showDialog(getString(R.string.request_permission), getString(R.string.need_unknown_app_source), new DialogInterface.OnClickListener() {
114 | @Override
115 | public void onClick(DialogInterface dialogInterface, int i) {
116 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
117 | startActivityForResult(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES), REQUEST_CODE_UNKNOWN_APP_SOURCES);
118 | }
119 | }
120 | });
121 | }
122 |
123 | @Override
124 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] paramArrayOfInt) {
125 | if (requestCode == PERMISSON_REQUESTCODE) {
126 | if (!verifyPermissions(paramArrayOfInt)) {
127 | hasPermission = false;
128 | }
129 | isNeedCheck = false;
130 | onPermissionsRequestResult(hasPermission);
131 | if (!hasPermission) {
132 | showMissingPermissionDialog();
133 | }
134 | }
135 | }
136 |
137 | /**
138 | * 是否已获得所有申请的权限
139 | */
140 | public boolean isHasPermission() {
141 | return hasPermission;
142 | }
143 |
144 | /**
145 | * 权限申请结果
146 | * @param hasPermission true已获取所有申请的权限,false未全部获得
147 | */
148 | protected void onPermissionsRequestResult(boolean hasPermission) {}
149 |
150 | /**
151 | * 显示提示信息
152 | */
153 | private void showMissingPermissionDialog() {
154 | showDialog(getString(R.string.request_permission), getString(R.string.lack_permission_msg), new DialogInterface.OnClickListener() {
155 | @Override
156 | public void onClick(DialogInterface dialog, int which) {
157 | isNeedCheck = true;
158 | //启动应用的设置
159 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
160 | intent.setData(Uri.parse("package:" + getPackageName()));
161 | startActivity(intent);
162 | }
163 | });
164 | }
165 |
166 | private void showDialog(String title, String msg, DialogInterface.OnClickListener listener) {
167 | new AlertDialog.Builder(this)
168 | .setTitle(title)
169 | .setMessage(msg)
170 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
171 | @Override
172 | public void onClick(DialogInterface dialog, int which) {
173 | finish();
174 | }
175 | })
176 | .setCancelable(false)
177 | .setPositiveButton(R.string.setting, listener)
178 | .show();
179 | }
180 | }
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/SelectedItemDialog.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 | import android.widget.ListView;
12 | import android.widget.TextView;
13 |
14 | import com.bumptech.glide.Glide;
15 | import com.bumptech.glide.request.RequestOptions;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | import androidx.annotation.NonNull;
21 | import cn.wandersnail.commons.util.UiUtils;
22 |
23 | /**
24 | * date: 2019/8/8 16:30
25 | * author: zengfansheng
26 | */
27 | class SelectedItemDialog extends Dialog {
28 | private SelectFileActivity activity;
29 | private TextView tvTitle;
30 | private FileListAdapter adapter;
31 | private List- itemList = new ArrayList<>();
32 |
33 | SelectedItemDialog(@NonNull SelectFileActivity activity) {
34 | super(activity);
35 | this.activity = activity;
36 | Window window = getWindow();
37 | if (window != null) {
38 | window.requestFeature(Window.FEATURE_NO_TITLE);
39 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
40 | window.getDecorView().setPadding(0, 0, 0, 0);
41 | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
42 | window.setWindowAnimations(R.style.FsDialogAnimFromBottom);
43 | WindowManager.LayoutParams lp = window.getAttributes();
44 | lp.width = WindowManager.LayoutParams.MATCH_PARENT;
45 | lp.height = WindowManager.LayoutParams.MATCH_PARENT;
46 | window.setAttributes(lp);
47 | }
48 | setContentView(inflateView(activity));
49 | }
50 |
51 | private View inflateView(Context context) {
52 | View view = View.inflate(context, R.layout.fs_dialog_selected_item, null);
53 | tvTitle = view.findViewById(R.id.fsTvTitle);
54 | tvTitle.setText(String.format(activity.textHolder.getText(TextHolder.SELECTED_ITEM_PATTERN), itemList.size()));
55 | View statusBar = view.findViewById(R.id.fsStatusBar);
56 | ViewGroup.LayoutParams params = statusBar.getLayoutParams();
57 | params.height = UiUtils.getStatusBarHeight();
58 | statusBar.setLayoutParams(params);
59 | TextView tvClose = view.findViewById(R.id.fsTvClose);
60 | tvClose.setText(activity.textHolder.getText(TextHolder.CLOSE));
61 | tvClose.setOnClickListener(v -> dismiss());
62 | TextView tvClear = view.findViewById(R.id.fsTvClear);
63 | tvClear.setText(activity.textHolder.getText(TextHolder.CLEAR));
64 | tvClear.setOnClickListener(v -> activity.clearSelectedFileList());
65 | adapter = new FileListAdapter(activity, itemList);
66 | ListView lv = view.findViewById(R.id.fsLv);
67 | lv.setAdapter(adapter);
68 | return view;
69 | }
70 |
71 | void updateList(List
- selectItemList) {
72 | itemList.clear();
73 | itemList.addAll(selectItemList);
74 | tvTitle.setText(String.format(activity.textHolder.getText(TextHolder.SELECTED_ITEM_PATTERN), itemList.size()));
75 | adapter.notifyDataSetChanged();
76 | }
77 |
78 | private class FileListAdapter extends BaseListAdapter
- {
79 | FileListAdapter(Context context, List
- data) {
80 | super(context, data);
81 | }
82 |
83 | @Override
84 | BaseHolder
- getHolder(int position) {
85 | return new ViewHolder() {
86 | @Override
87 | void setData(Item data, int position) {
88 | chkView.setTag(position);
89 | tvName.setText(data.file.getName());
90 | String path = data.file.getAbsolutePath();
91 | if (data.file.isDirectory()) {
92 | tvDesc.setVisibility(View.GONE);
93 | Glide.with(context).load(R.drawable.fs_ic_folder).into(iv);
94 | } else {
95 | tvDesc.setText(data.file.getParentFile().getAbsolutePath());
96 | if (Utils.isApk(path)) {
97 | Glide.with(context).load(Utils.getApkThumbnail(context, path)).into(iv);
98 | } else if (Utils.isImage(path) || Utils.isVideo(path)) {
99 | Glide.with(context).setDefaultRequestOptions(new RequestOptions()
100 | .error(R.drawable.fs_file)).load(path).into(iv);
101 | } else if (Utils.isAudio(path)) {
102 | Glide.with(context).load(R.drawable.fs_audio).into(iv);
103 | } else if (Utils.isText(path)) {
104 | Glide.with(context).load(R.drawable.fs_text).into(iv);
105 | } else if (Utils.isPdf(path)) {
106 | Glide.with(context).load(R.drawable.fs_pdf).into(iv);
107 | } else if (Utils.isExcel(path)) {
108 | Glide.with(context).load(R.drawable.fs_excel).into(iv);
109 | } else if (Utils.isWord(path)) {
110 | Glide.with(context).load(R.drawable.fs_word).into(iv);
111 | } else if (Utils.isPPT(path)) {
112 | Glide.with(context).load(R.drawable.fs_ppt).into(iv);
113 | } else if (Utils.isZip(path)) {
114 | Glide.with(context).load(R.drawable.fs_zip).into(iv);
115 | } else if (Utils.isFlash(path)) {
116 | Glide.with(context).load(R.drawable.fs_flash).into(iv);
117 | } else if (Utils.isPs(path)) {
118 | Glide.with(context).load(R.drawable.fs_ps).into(iv);
119 | } else if (Utils.isHtml(path)) {
120 | Glide.with(context).load(R.drawable.fs_html).into(iv);
121 | } else if (Utils.isDeveloper(path)) {
122 | Glide.with(context).load(R.drawable.fs_developer).into(iv);
123 | } else {
124 | Glide.with(context).load(R.drawable.fs_file).into(iv);
125 | }
126 | }
127 | ivSelect.setSelected(data.checked);
128 | if (data.checked) {
129 | ivSelect.setColorFilter(activity.themeColors[0]);
130 | } else {
131 | ivSelect.setColorFilter(Color.LTGRAY);
132 | }
133 | }
134 |
135 | @Override
136 | View createConvertView() {
137 | View view = View.inflate(context, R.layout.fs_file_item_view, null);
138 | tvName = view.findViewById(R.id.fsTvName);
139 | tvDesc = view.findViewById(R.id.fsTvDesc);
140 | iv = view.findViewById(R.id.iv);
141 | ivSelect = view.findViewById(R.id.fsIvSelect);
142 | ivSelect.setVisibility(View.INVISIBLE);
143 | chkView = view.findViewById(R.id.fsChkView);
144 | chkView.setOnClickListener(v -> {
145 | int position1 = (int) chkView.getTag();
146 | Item item = getItem(position1);
147 | item.checked = false;
148 | activity.updateSelectedFileList(item, true);
149 | });
150 | return view;
151 | }
152 | };
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/Utils.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.content.Context;
4 | import android.content.pm.ApplicationInfo;
5 | import android.content.pm.PackageInfo;
6 | import android.content.pm.PackageManager;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.graphics.drawable.StateListDrawable;
10 | import android.util.TypedValue;
11 | import androidx.core.content.ContextCompat;
12 | import cn.wandersnail.commons.util.UiUtils;
13 |
14 | /**
15 | * date: 2019/8/8 13:57
16 | * author: zengfansheng
17 | */
18 | final class Utils {
19 | private static final String[] videoSuffixs = {".avi", ".wmv", ".wmp", ".wm", ".asf", ".mpg", ".mpeg", ".mpe", ".m1v", ".m2v", ".mpv2", ".mp2v", ".ts", ".tp", ".tpr", ".trp", ".vob", ".ifo", ".ogm", "ogv", ".mp4", ".m4v", ".m4p", ".m4b", ".3gp", ".3gpp", ".3g2", ".3gp2", ".mkv", ".rm", ".ram", "rmvb", ".rpm", ".flv", ".swf", ".mov", ".qt", ".amr", ".nsv", ".dpg", ".m2ts", ".m2t", ".mts", "dvr-ms", ".k3g", ".skm", ".evo", ".nsr", ".amv", ".divx", ".webm", ".wtv", ".f4v"};
20 | private static final String[] imageSuffixs = {".bmp", ".jpg", ".jpeg", ".png", ".gif"};
21 | private static final String[] audioSuffixs = {".mp3", ".mp2", ".wma", ".wav", ".ape", ".flac", ".ogg", ".m4a", ".m4r", ".aac", ".mid", ".ra"};
22 | private static final String[] pptSuffixs = {".ppt", ".pot", ".pps", ".pptx", ".pptm", ".ppsx", ".ppsm", ".potx", ".dps", ".potm"};
23 | private static final String[] wordSuffixs = {".doc", ".docx", ".docm", ".dot", ".dotx", ".dotm", ".rtf", ".tar", ".ace", ".wpt", ".wps"};
24 | private static final String[] excelSuffixs = {".et", ".csv", ".xl", ".xls", ".xlt", ".xlsx", ".xlsm", ".xlsb", ".xltx", ".xltm", ".xla", ".xlm", ".xlw"};
25 | private static final String[] zipSuffixs = {".rar", ".zip", ".7z", ".gz", ".arj", ".cab", ".jar", ".tar", ".ace"};
26 | private static final String[] psSuffixs = {".psd", ".pdd", ".eps", ".psb"};
27 | private static final String[] htmlSuffixs = {".htm", ".html", ".mht", ".mhtml"};
28 | private static final String[] developerSuffixs = {".db", ".db-journal", ".db3", ".sqlite", ".xml", ".wdb", ".mdf", ".dbf", ".properties", ".cfg", ".ini", ".sys"};
29 |
30 | /**
31 | * 获取Apk文件的图标
32 | */
33 | static Drawable getApkThumbnail(Context context, String path) {
34 | PackageManager pm = context.getApplicationContext().getPackageManager();
35 | PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
36 | if (packageInfo != null) {
37 | ApplicationInfo appInfo = packageInfo.applicationInfo;
38 | //获取apk的图标
39 | appInfo.sourceDir = path;
40 | appInfo.publicSourceDir = path;
41 | return appInfo.loadIcon(pm);
42 | }
43 | return null;
44 | }
45 |
46 | private static boolean isWhat(String[] suffixs, String path) {
47 | for (String suffix : suffixs) {
48 | if (path.toLowerCase().endsWith(suffix)) {
49 | return true;
50 | }
51 | }
52 | return false;
53 | }
54 |
55 | static int getPrimaryColor(Context context, int defaultColor) {
56 | TypedValue typedValue = new TypedValue();
57 | boolean found = false;
58 | try {
59 | int resId = context.getResources().getIdentifier("colorPrimary", "attr", context.getPackageName());
60 | if (resId > 0) {
61 | found = context.getTheme().resolveAttribute(resId, typedValue, true);
62 | }
63 | } catch (Exception ignore) {
64 | }
65 | return found ? typedValue.data : defaultColor;
66 | }
67 |
68 | static int getPrimaryDarkColor(Context context, int defaultColor) {
69 | TypedValue typedValue = new TypedValue();
70 | boolean found = false;
71 | try {
72 | int resId = context.getResources().getIdentifier("colorPrimaryDark", "attr", context.getPackageName());
73 | if (resId > 0) {
74 | found = context.getTheme().resolveAttribute(resId, typedValue, true);
75 | }
76 | } catch (Exception ignore) {
77 | }
78 | return found ? typedValue.data : defaultColor;
79 | }
80 |
81 | private static Drawable getShape(int color, int strokeWidth, int strokeColor) {
82 | GradientDrawable drawable = new GradientDrawable();
83 | drawable.setColor(color);
84 | drawable.setCornerRadius(UiUtils.dp2px(30f));
85 | drawable.setStroke(strokeWidth, strokeColor);
86 | return drawable;
87 | }
88 |
89 | static StateListDrawable getFillBlueBg(Context context, int[] colors) {
90 | Drawable pressed = getShape(colors[1], 0, colors[1]);
91 | Drawable normal = getShape(colors[0], 0, colors[0]);
92 | Drawable disable = getShape(ContextCompat.getColor(context, R.color.fsEditHint), 0, ContextCompat.getColor(context, R.color.fsEditHint));
93 | return createBg(normal, pressed, disable);
94 | }
95 |
96 | static StateListDrawable getFillGrayBg(Context context) {
97 | Drawable pressed = getShape(ContextCompat.getColor(context, R.color.fsEditHintDark), 0, ContextCompat.getColor(context, R.color.fsEditHintDark));
98 | Drawable normal = getShape(ContextCompat.getColor(context, R.color.fsEditHint), 0, ContextCompat.getColor(context, R.color.fsEditHint));
99 | Drawable disable = getShape(ContextCompat.getColor(context, R.color.fsEditHint), 0, ContextCompat.getColor(context, R.color.fsEditHint));
100 | return createBg(normal, pressed, disable);
101 | }
102 |
103 | static StateListDrawable getFrameBlueBg(Context context, int color) {
104 | Drawable pressed = getShape(color, 0, color);
105 | Drawable normal = getShape(ContextCompat.getColor(context, R.color.fsTransparent), UiUtils.dp2px(1f), color);
106 | return createBg(normal, pressed, null);
107 | }
108 |
109 | private static StateListDrawable createBg(Drawable normal, Drawable pressed, Drawable disable) {
110 | StateListDrawable drawable = new StateListDrawable();
111 | if (disable != null) {
112 | drawable.addState(new int[]{-android.R.attr.state_enabled}, disable);
113 | }
114 | drawable.addState(new int[]{android.R.attr.state_pressed}, pressed);
115 | drawable.addState(new int[0], normal);//normal一定要最后
116 | return drawable;
117 | }
118 |
119 | static boolean isVideo(String path) {
120 | return isWhat(videoSuffixs, path);
121 | }
122 |
123 | static boolean isImage(String path) {
124 | return isWhat(imageSuffixs, path);
125 | }
126 |
127 | static boolean isApk(String path) {
128 | return path.toLowerCase().endsWith(".apk");
129 | }
130 |
131 | static boolean isAudio(String path) {
132 | return isWhat(audioSuffixs, path);
133 | }
134 |
135 | static boolean isText(String path) {
136 | return path.toLowerCase().endsWith(".txt");
137 | }
138 |
139 | static boolean isPdf(String path) {
140 | return path.toLowerCase().endsWith(".pdf");
141 | }
142 |
143 | static boolean isZip(String path) {
144 | return isWhat(zipSuffixs, path);
145 | }
146 |
147 | static boolean isFlash(String path) {
148 | return path.toLowerCase().endsWith(".swf") || path.toLowerCase().endsWith(".fla");
149 | }
150 |
151 | static boolean isHtml(String path) {
152 | return isWhat(htmlSuffixs, path);
153 | }
154 |
155 | static boolean isPs(String path) {
156 | return isWhat(psSuffixs, path);
157 | }
158 |
159 | static boolean isWord(String path) {
160 | return isWhat(wordSuffixs, path);
161 | }
162 |
163 | static boolean isExcel(String path) {
164 | return isWhat(excelSuffixs, path);
165 | }
166 |
167 | static boolean isPPT(String path) {
168 | return isWhat(pptSuffixs, path);
169 | }
170 |
171 | static boolean isDeveloper(String path) {
172 | return isWhat(developerSuffixs, path);
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/CharacterParser.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | /**
4 | * Java汉字转换为拼音
5 | */
6 | class CharacterParser {
7 | private static int[] pyvalue = new int[]{-20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242,
8 | -20230, -20051, -20036, -20032, -20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775,
9 | -19774, -19763, -19756, -19751, -19746, -19741, -19739, -19728, -19725, -19715, -19540, -19531, -19525,
10 | -19515, -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, -19263, -19261, -19249,
11 | -19243, -19242, -19238, -19235, -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, -19003,
12 | -18996, -18977, -18961, -18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, -18731, -18722,
13 | -18710, -18697, -18696, -18526, -18518, -18501, -18490, -18478, -18463, -18448, -18447, -18446, -18239,
14 | -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, -17970, -17964,
15 | -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703, -17701,
16 | -17697, -17692, -17683, -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202,
17 | -17185, -16983, -16970, -16942, -16915, -16733, -16708, -16706, -16689, -16664, -16657, -16647, -16474,
18 | -16470, -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, -16419, -16412, -16407, -16403,
19 | -16401, -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, -16155,
20 | -15959, -15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701, -15681, -15667,
21 | -15661, -15659, -15652, -15640, -15631, -15625, -15454, -15448, -15436, -15435, -15419, -15416, -15408,
22 | -15394, -15385, -15377, -15375, -15369, -15363, -15362, -15183, -15180, -15165, -15158, -15153, -15150,
23 | -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, -14941,
24 | -14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, -14894, -14889,
25 | -14882, -14873, -14871, -14857, -14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594,
26 | -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345, -14170, -14159, -14151, -14149,
27 | -14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, -14092,
28 | -14090, -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, -13894, -13878, -13870,
29 | -13859, -13847, -13831, -13658, -13611, -13601, -13406, -13404, -13400, -13398, -13395, -13391, -13387,
30 | -13383, -13367, -13359, -13356, -13343, -13340, -13329, -13326, -13318, -13147, -13138, -13120, -13107,
31 | -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, -12875, -12871, -12860, -12858, -12852,
32 | -12849, -12838, -12831, -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, -12346,
33 | -12320, -12300, -12120, -12099, -12089, -12074, -12067, -12058, -12039, -11867, -11861, -11847, -11831,
34 | -11798, -11781, -11604, -11589, -11536, -11358, -11340, -11339, -11324, -11303, -11097, -11077, -11067,
35 | -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014, -10838, -10832, -10815,
36 | -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315,
37 | -10309, -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254};
38 | private static String[] pystr = new String[]{"a", "ai", "an", "ang", "ao", "ba", "bai", "ban", "bang", "bao",
39 | "bei", "ben", "beng", "bi", "bian", "biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", "can", "cang",
40 | "cao", "ce", "ceng", "cha", "chai", "chan", "chang", "chao", "che", "chen", "cheng", "chi", "chong", "chou",
41 | "chu", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan", "cui", "cun",
42 | "cuo", "da", "dai", "dan", "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong",
43 | "dou", "du", "duan", "dui", "dun", "duo", "e", "en", "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo",
44 | "fou", "fu", "ga", "gai", "gan", "gang", "gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua",
45 | "guai", "guan", "guang", "gui", "gun", "guo", "ha", "hai", "han", "hang", "hao", "he", "hei", "hen", "heng",
46 | "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo", "ji", "jia", "jian", "jiang",
47 | "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", "kan", "kang", "kao",
48 | "ke", "ken", "keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai",
49 | "lan", "lang", "lao", "le", "lei", "leng", "li", "lia", "lian", "liang", "liao", "lie", "lin", "ling",
50 | "liu", "long", "lou", "lu", "lv", "luan", "lue", "lun", "luo", "ma", "mai", "man", "mang", "mao", "me",
51 | "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu", "na", "nai",
52 | "nan", "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", "niao", "nie", "nin", "ning",
53 | "niu", "nong", "nu", "nv", "nuan", "nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", "pen",
54 | "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pu", "qi", "qia", "qian", "qiang", "qiao", "qie",
55 | "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", "re", "ren", "reng", "ri",
56 | "rong", "rou", "ru", "ruan", "rui", "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", "seng",
57 | "sha", "shai", "shan", "shang", "shao", "she", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai",
58 | "shuan", "shuang", "shui", "shun", "shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo", "ta",
59 | "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao", "tie", "ting", "tong", "tou", "tu", "tuan",
60 | "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu", "xi", "xia", "xian",
61 | "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", "yan", "yang",
62 | "yao", "ye", "yi", "yin", "ying", "yo", "yong", "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan",
63 | "zang", "zao", "ze", "zei", "zen", "zeng", "zha", "zhai", "zhan", "zhang", "zhao", "zhe", "zhen", "zheng",
64 | "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui", "zhun", "zhuo", "zi", "zong",
65 | "zou", "zu", "zuan", "zui", "zun", "zuo"};
66 |
67 | //汉字转成ASCII码
68 | private static int getChsAscii(String chs) {
69 | int asc = 0;
70 | try {
71 | byte[] bytes = chs.getBytes("gb2312");
72 | if (bytes.length > 2 || bytes.length <= 0) {
73 | throw new RuntimeException("illegal resource string");
74 | }
75 | if (bytes.length == 1) {
76 | asc = bytes[0];
77 | }
78 | if (bytes.length == 2) {
79 | int hightByte = 256 + bytes[0];
80 | int lowByte = 256 + bytes[1];
81 | asc = (256 * hightByte + lowByte) - 256 * 256;
82 | }
83 | } catch (Exception e) {
84 | System.out.println("ERROR:ChineseSpelling.class-getChsAscii(String chs)" + e);
85 | }
86 | return asc;
87 | }
88 |
89 | /**
90 | * 单字解析
91 | * @return 返回字母
92 | */
93 | static String convert(String str) {
94 | String result = null;
95 | int ascii = getChsAscii(str);
96 | if (ascii > 0 && ascii < 160) {
97 | result = String.valueOf((char) ascii);
98 | } else {
99 | for (int i = (pyvalue.length - 1); i >= 0; i--) {
100 | if (pyvalue[i] <= ascii) {
101 | result = pystr[i];
102 | break;
103 | }
104 | }
105 | }
106 | return result;
107 | }
108 |
109 | /**
110 | * 词组解析
111 | * @return 返回拼音
112 | */
113 | static String getSpelling(String chs) {
114 | String key, value;
115 | StringBuilder buffer = new StringBuilder();
116 | for (int i = 0; i < chs.length(); i++) {
117 | key = chs.substring(i, i + 1);
118 | if (key.getBytes().length >= 2) {
119 | value = convert(key);
120 | if (value == null) {
121 | value = "unknown";
122 | }
123 | } else {
124 | value = key;
125 | }
126 | buffer.append(value);
127 | }
128 | return buffer.toString();
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/wandersnail/fileselector/SelectFileActivity.java:
--------------------------------------------------------------------------------
1 | package cn.wandersnail.fileselector;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.IntentFilter;
9 | import android.content.pm.ActivityInfo;
10 | import android.content.pm.PackageManager;
11 | import android.graphics.Color;
12 | import android.os.Bundle;
13 | import android.os.Environment;
14 | import android.text.TextUtils;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.Window;
18 | import android.view.WindowManager;
19 | import android.view.animation.AlphaAnimation;
20 | import android.widget.AdapterView;
21 | import android.widget.EditText;
22 | import android.widget.FrameLayout;
23 | import android.widget.HorizontalScrollView;
24 | import android.widget.ImageView;
25 | import android.widget.LinearLayout;
26 | import android.widget.ListView;
27 | import android.widget.PopupWindow;
28 | import android.widget.RelativeLayout;
29 | import android.widget.ScrollView;
30 | import android.widget.TextView;
31 | import android.widget.Toast;
32 |
33 | import com.bumptech.glide.Glide;
34 | import com.bumptech.glide.request.RequestOptions;
35 |
36 | import java.io.File;
37 | import java.io.FilenameFilter;
38 | import java.util.ArrayList;
39 | import java.util.Collections;
40 | import java.util.Comparator;
41 | import java.util.List;
42 | import java.util.Objects;
43 |
44 | import androidx.annotation.NonNull;
45 | import androidx.annotation.Nullable;
46 | import androidx.appcompat.app.AlertDialog;
47 | import androidx.core.app.ActivityCompat;
48 | import androidx.core.content.ContextCompat;
49 | import cn.wandersnail.commons.util.ColorUtils;
50 | import cn.wandersnail.commons.util.FileUtils;
51 | import cn.wandersnail.commons.util.ShellUtils;
52 | import cn.wandersnail.commons.util.SystemUtils;
53 | import cn.wandersnail.commons.util.UiUtils;
54 | import cn.wandersnail.commons.util.entity.Storage;
55 |
56 | /**
57 | * date: 2019/8/8 16:51
58 | * author: zengfansheng
59 | */
60 | public class SelectFileActivity extends Activity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
61 | private static final int PERMISSON_REQUESTCODE = 10;
62 |
63 | public static final String EXTRA_SELECTION_MODE = "SELECTION_MODE";
64 | public static final String EXTRA_SELECTOR_HASH = "SELECTOR_HASH";
65 | public static final String EXTRA_SELECTOR_NAME = "SELECTOR_NAME";
66 | public static final String EXTRA_IS_MULTI_SELECT = "IS_MULTI_SELECT";
67 | public static final String EXTRA_IS_LANDSCAPE = "SCREEN_ORIENTATION";
68 | public static final String EXTRA_ROOT = "ROOT";
69 | public static final String EXTRA_SELECTED_FILE_PATH_LIST = "SELECTED_FILE_LIST";
70 | public static final String EXTRA_TITLE = "TITLE";
71 | public static final String EXTRA_THEME_COLORS = "THEME_COLORS";
72 | public static final String EXTRA_LANGUAGE = "LANGUAGE";
73 | public static final String EXTRA_SHOW_HIDDEN_FILES = "SHOW_HIDDEN_FILES";
74 | static FilenameFilter filenameFilter;
75 |
76 | private int selectionMode = FileSelector.FILES_ONLY;
77 | private boolean isMultiSelect;
78 | private List posList = new ArrayList<>();
79 | private List
- itemList = new ArrayList<>();
80 | private List
- selectItemList = new ArrayList<>();
81 | private boolean isSelectedAll;
82 | private File rootFile;
83 | private FileListAdapter adapter;
84 | private SelectedItemDialog selectedItemDialog;
85 | private String currentPath;//当前路径
86 | private List rootFiles = new ArrayList<>();
87 | private String title;//标题
88 | int[] themeColors;
89 | private String selectorHash;
90 | TextHolder textHolder = new TextHolder();
91 | private boolean showHiddenFiles;//设置是否显示隐藏文件和文件夹
92 | private View fsStatusBar;
93 | private RelativeLayout fsLayoutTitle;
94 | private ImageView fsIvClose;
95 | private TextView fsTvTitle;
96 | private ImageView fsIvMore;
97 | private ImageView fsIvAll;
98 | private TextView fsTvRoot;
99 | private HorizontalScrollView fsScrollView;
100 | private LinearLayout fsDirContainer;
101 | private ListView fsLv;
102 | private TextView fsTvSelected;
103 | private TextView fsTvOk;
104 | private View fsMaskView;
105 | private BroadcastReceiver mScanListener = new BroadcastReceiver() { // from class: com.android.rk.RockExplorer.16
106 | @Override // android.content.BroadcastReceiver
107 | public void onReceive(Context context, Intent intent) {
108 | String action = intent.getAction();
109 | if (action != null && (action.equals(Intent.ACTION_MEDIA_MOUNTED) || action.equals(Intent.ACTION_MEDIA_UNMOUNTED))) {
110 | File tmpCurDir = rootFile;
111 | if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
112 | String sdcardDir=Environment.getExternalStorageDirectory().getAbsolutePath();
113 | String changeDir="";
114 | if(intent.getData()!=null)
115 | {changeDir=intent.getData().getPath();}
116 | if (changeDir!=null&&!changeDir.equals(sdcardDir)) {
117 | loadFiles(null);
118 | posList.clear();
119 | fsDirContainer.removeAllViews();
120 | }
121 | }else{
122 | if(tmpCurDir==null|| Objects.equals(tmpCurDir.getAbsolutePath(), "/")){
123 | loadFiles(rootFile);
124 | posList.clear();
125 | fsDirContainer.removeAllViews();
126 | }
127 | }
128 |
129 | }
130 | }
131 | };
132 | private boolean isRegistered=false;
133 |
134 | public void registerBroadcastRec() {
135 | IntentFilter f = new IntentFilter();
136 | f.addAction("android.intent.action.MEDIA_MOUNTED");
137 | f.addAction("android.intent.action.MEDIA_UNMOUNTED");
138 | f.addAction("android.os.storage.action.VOLUME_STATE_CHANGED");
139 | f.addAction("android.intent.action.MEDIA_BAD_REMOVAL");
140 | f.addDataScheme("file");
141 | isRegistered=true;
142 | registerReceiver(this.mScanListener, f);
143 | }
144 | private void unRegisterBroadcast(){
145 | if(isRegistered) {
146 | unregisterReceiver(this.mScanListener);
147 | isRegistered=false;
148 | }
149 | }
150 | private void assignViews() {
151 | fsStatusBar = findViewById(R.id.fsStatusBar);
152 | fsLayoutTitle = findViewById(R.id.fsLayoutTitle);
153 | fsIvClose = findViewById(R.id.fsIvClose);
154 | fsTvTitle = findViewById(R.id.fsTvTitle);
155 | fsIvMore = findViewById(R.id.fsIvMore);
156 | fsIvAll = findViewById(R.id.fsIvAll);
157 | fsTvRoot = findViewById(R.id.fsTvRoot);
158 | fsScrollView = findViewById(R.id.fsScrollView);
159 | fsDirContainer = findViewById(R.id.fsDirContainer);
160 | fsLv = findViewById(R.id.fsLv);
161 | fsTvSelected = findViewById(R.id.fsTvSelected);
162 | fsTvOk = findViewById(R.id.fsTvOk);
163 | fsMaskView = findViewById(R.id.fsMaskView);
164 | }
165 |
166 |
167 | @Override
168 | protected void onCreate(@Nullable Bundle savedInstanceState) {
169 | super.onCreate(savedInstanceState);
170 | //沉浸状态栏
171 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
172 | getWindow().requestFeature(Window.FEATURE_NO_TITLE);
173 | getDataFromIntent();
174 | setContentView(R.layout.fs_activity_select_file);
175 | //先检查写权限
176 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
177 | ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
178 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSON_REQUESTCODE);
179 | } else {
180 | assignViews();
181 | initViews();
182 | initEvents();
183 | registerBroadcastRec();
184 | }
185 |
186 | }
187 |
188 | private void getDataFromIntent() {
189 | int language = getIntent().getIntExtra(EXTRA_LANGUAGE, -1);
190 | if (language != -1) {
191 | Language[] languages = Language.values();
192 | for (Language lan : languages) {
193 | if (lan.value == language) {
194 | textHolder.language = lan;
195 | break;
196 | }
197 | }
198 | }
199 | selectionMode = getIntent().getIntExtra(EXTRA_SELECTION_MODE, FileSelector.FILES_ONLY);
200 | isMultiSelect = getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECT, false);
201 | if (getIntent().getBooleanExtra(EXTRA_IS_LANDSCAPE, false)) {
202 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
203 | } else {
204 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
205 | }
206 | rootFile = (File) getIntent().getSerializableExtra(EXTRA_ROOT);
207 | if (rootFile == null) {
208 | if (ShellUtils.hasRootPermission()) {
209 | rootFile = new File("/");
210 | }
211 | }
212 | title = getIntent().getStringExtra(EXTRA_TITLE);
213 | int[] themeColors = getIntent().getIntArrayExtra(EXTRA_THEME_COLORS);
214 | if (themeColors == null) {
215 | this.themeColors = new int[]{Utils.getPrimaryColor(this, ContextCompat.getColor(this, R.color.fsColorPrimary)), Utils.getPrimaryDarkColor(this, ContextCompat.getColor(this, R.color.fsColorPrimaryDark))};
216 | } else {
217 | this.themeColors = themeColors;
218 | }
219 | showHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false);
220 | selectorHash = getIntent().getStringExtra(EXTRA_SELECTOR_HASH);
221 | }
222 |
223 | private Comparator
- itemComparator = (o1, o2) -> {
224 | if (o1 == null) {
225 | return -1;
226 | } else if (o2 == null) {
227 | return 1;
228 | }
229 | return o1.file.getName().compareToIgnoreCase(o2.file.getName());
230 | };
231 |
232 | //检测是否所有的权限都已经授权
233 | private boolean verifyPermissions(int[] grantResults) {
234 | for (int result : grantResults) {
235 | if (result != PackageManager.PERMISSION_GRANTED) {
236 | return false;
237 | }
238 | }
239 | return true;
240 | }
241 |
242 | @Override
243 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
244 | if (requestCode == PERMISSON_REQUESTCODE) {
245 | if (verifyPermissions(grantResults)) {
246 | initViews();
247 | } else {
248 | finish();
249 | }
250 | }
251 | }
252 |
253 | @Override
254 | protected void onDestroy() {
255 | filenameFilter = null;
256 | unRegisterBroadcast();
257 | super.onDestroy();
258 | }
259 |
260 | @Override
261 | public void onBackPressed() {
262 | if (!posList.isEmpty()) {
263 | View child = fsDirContainer.getChildAt(fsDirContainer.getChildCount() - 1);
264 | TextView tv = child.findViewById(R.id.fsTv);
265 | DirCell cell = (DirCell) tv.getTag();
266 | fsDirContainer.removeView(child);
267 | if (rootFiles.isEmpty()) {
268 | loadFiles(cell.location.getParentFile());
269 | } else {
270 | boolean isSecondLast = false;
271 | for (File file : rootFiles) {
272 | if (cell.location == file) {
273 | isSecondLast = true;
274 | loadFiles(null);
275 | break;
276 | }
277 | }
278 | if (!isSecondLast) {
279 | loadFiles(cell.location.getParentFile());
280 | }
281 | }
282 | int[] ints = posList.remove(posList.size() - 1);
283 | fsLv.setSelectionFromTop(ints[0], ints[1]);
284 | } else if (rootFile == null && currentPath != null) {
285 | loadFiles(null);
286 | } else {
287 | super.onBackPressed();
288 | }
289 | }
290 |
291 | private void addDir(File file) {
292 | View view = getLayoutInflater().inflate(R.layout.fs_dir_view, null);
293 | TextView tv = view.findViewById(R.id.fsTv);
294 | int childCount = fsDirContainer.getChildCount();
295 | tv.setTag(new DirCell(childCount, file));
296 | tv.setText(file.getName());
297 | tv.setOnClickListener(v -> {
298 | DirCell cell = (DirCell) v.getTag();
299 | //把当前之后的移除
300 | int count = fsDirContainer.getChildCount();
301 | if (cell.index < count - 1) {
302 | fsDirContainer.removeViews(cell.index + 1, count - cell.index - 1);
303 | }
304 | //清除之后的位置记录
305 | int[] ints = new int[2];
306 | for (int i = posList.size() -1; i >= 0; i--) {
307 | if (cell.index < i) {
308 | ints = posList.remove(posList.size() -1);
309 | } else {
310 | break;
311 | }
312 | }
313 | //更新列表
314 | loadFiles(cell.location);
315 | fsLv.setSelectionFromTop(ints[0], ints[1]);
316 | });
317 | fsDirContainer.addView(view);
318 | }
319 |
320 | private void initViews() {
321 | fsTvRoot.setText(textHolder.getText(TextHolder.ROOT));
322 | fsTvOk.setText(textHolder.getText(TextHolder.OK));
323 | ViewGroup.LayoutParams params = fsStatusBar.getLayoutParams();
324 | params.height = UiUtils.getStatusBarHeight();
325 | fsStatusBar.setLayoutParams(params);
326 | if (title == null) {
327 | fsTvTitle.setText(textHolder.getText(TextHolder.ALL_FILES));
328 | } else {
329 | fsTvTitle.setText(title);
330 | }
331 | fsTvOk.setTextColor(ColorUtils.createColorStateList(themeColors[0], themeColors[0], ContextCompat.getColor(this, R.color.fsDisable)));
332 | fsTvOk.setEnabled(false);
333 | updateSelectedText();
334 | selectedItemDialog = new SelectedItemDialog(this);
335 | adapter = new FileListAdapter(this, itemList);
336 | fsLv.setAdapter(adapter);
337 | fsLv.setOnItemClickListener(this);
338 | fsLv.setOnItemLongClickListener(this);
339 | loadFiles(rootFile);
340 | }
341 |
342 | private void initEvents() {
343 | fsIvClose.setOnClickListener(v -> finish());
344 | fsIvMore.setOnClickListener(v -> showPopupWindow());
345 | fsIvAll.setOnClickListener(v -> switchSelectAll(!isSelectedAll));
346 | fsTvSelected.setOnClickListener(v -> {
347 | selectedItemDialog.updateList(selectItemList);
348 | selectedItemDialog.show();
349 | });
350 | fsTvRoot.setOnClickListener(v -> {
351 | if (rootFile != null) {
352 | if (fsDirContainer.getChildCount() > 0) {
353 | loadFiles(rootFile);
354 | int[] ints = posList.remove(0);
355 | fsLv.setSelectionFromTop(ints[0], ints[1]);
356 | posList.clear();
357 | fsDirContainer.removeAllViews();
358 | }
359 | } else {
360 | loadFiles(null);
361 | posList.clear();
362 | fsDirContainer.removeAllViews();
363 | }
364 | });
365 | fsTvOk.setOnClickListener(v -> {
366 | Intent intent = new Intent();
367 | ArrayList pathList = new ArrayList<>();
368 | if (isMultiSelect) {
369 | for (Item item : selectItemList) {
370 | pathList.add(item.file.getAbsolutePath());
371 | }
372 | if (pathList.isEmpty() && currentPath != null) {
373 | pathList.add(currentPath);
374 | }
375 | } else {
376 | if (!selectItemList.isEmpty()) {
377 | pathList.add(selectItemList.get(0).file.getAbsolutePath());
378 | } else if (currentPath != null) {
379 | pathList.add(currentPath);
380 | }
381 | }
382 | intent.putExtra(EXTRA_SELECTED_FILE_PATH_LIST, pathList);
383 | intent.putExtra(EXTRA_SELECTOR_HASH, selectorHash);
384 | intent.putExtra(EXTRA_SELECTOR_NAME, SelectFileActivity.class.getName());
385 | setResult(Activity.RESULT_OK, intent);
386 | finish();
387 | });
388 | }
389 |
390 | private void loadFiles(File dir) {
391 | currentPath = dir == null ? null : dir.getAbsolutePath();
392 | itemList.clear();
393 | ArrayList
- dirList = new ArrayList<>();
394 | ArrayList
- fList = new ArrayList<>();
395 | if (dir == null) {
396 | rootFiles.clear();
397 | List list = SystemUtils.getStorages(this);
398 | if (list != null) {
399 | for (Storage storage : list) {
400 | File file = new File(storage.getPath());
401 | rootFiles.add(file);
402 | dirList.add(new Item(file, isSelectedItem(file), storage.getDescription()));
403 | }
404 | }
405 | } else {
406 | File[] files = dir.listFiles();
407 | if (files != null) {
408 | for (File file : files) {
409 | if (showHiddenFiles && file.getName().startsWith(".") && ((file.isDirectory() && selectionMode != FileSelector.FILES_ONLY) ||
410 | (file.isFile() && selectionMode != FileSelector.DIRECTORIES_ONLY))) {
411 | handleFileList(file, dirList, fList);
412 | } else if (!file.getName().startsWith(".") && (filenameFilter == null || filenameFilter.accept(dir, file.getName()))) {
413 | handleFileList(file, dirList, fList);
414 | }
415 | }
416 | }
417 | }
418 | Collections.sort(dirList, itemComparator);
419 | Collections.sort(fList, itemComparator);
420 | itemList.addAll(dirList);
421 | itemList.addAll(fList);
422 | RelativeLayout.LayoutParams ivAllLp = (RelativeLayout.LayoutParams) fsIvAll.getLayoutParams();
423 | if (dir == null) {
424 | fsIvMore.setVisibility(View.GONE);
425 | ivAllLp.addRule(RelativeLayout.ALIGN_PARENT_END);
426 | } else {
427 | fsIvMore.setVisibility(View.VISIBLE);
428 | ivAllLp.removeRule(RelativeLayout.ALIGN_PARENT_END);
429 | }
430 | fsIvAll.setLayoutParams(ivAllLp);
431 | //只有多选,并且当选择文件时,文件列表不为空,当选择文件夹时,文件夹列表不为空
432 | if (isMultiSelect && (selectionMode == FileSelector.FILES_ONLY && fList.size() > 0 ||
433 | (selectionMode == FileSelector.DIRECTORIES_ONLY && dirList.size() > 0) ||
434 | (selectionMode == FileSelector.FILES_AND_DIRECTORIES && (fList.size() > 0 || dirList.size() > 0)))) {
435 | fsIvAll.setVisibility(View.VISIBLE);
436 | } else {
437 | fsIvAll.setVisibility(View.INVISIBLE);
438 | }
439 | if (fsIvAll.getVisibility() == View.VISIBLE && selectItemList.containsAll(itemList)) {
440 | switchSelectAllState(true);
441 | }
442 | File file = new File(currentPath == null ? "" : currentPath);
443 | fsTvOk.setEnabled(!selectItemList.isEmpty() || selectionMode != FileSelector.FILES_ONLY && file.exists());
444 | adapter.notifyDataSetChanged();
445 | fsScrollView.post(() -> fsScrollView.fullScroll(ScrollView.FOCUS_RIGHT));
446 | }
447 |
448 | private void handleFileList(File file, List
- dirList, List
- fList) {
449 | if (selectionMode == FileSelector.DIRECTORIES_ONLY) {
450 | if (file.isDirectory()) {
451 | dirList.add(new Item(file, isSelectedItem(file)));
452 | }
453 | } else {
454 | if (file.isDirectory()) {
455 | dirList.add(new Item(file, isSelectedItem(file)));
456 | } else {
457 | fList.add(new Item(file, isSelectedItem(file)));
458 | }
459 | }
460 | }
461 |
462 | private boolean isSelectedItem(File file) {
463 | for (Item item : selectItemList) {
464 | if (item.file.equals(file)) {
465 | return true;
466 | }
467 | }
468 | return false;
469 | }
470 |
471 | private void switchSelectAll(boolean enable) {
472 | switchSelectAllState(enable);
473 | for (Item item : itemList) {
474 | //只全选指定类型
475 | if (selectionMode == FileSelector.FILES_AND_DIRECTORIES || (selectionMode == FileSelector.DIRECTORIES_ONLY &&
476 | item.file.isDirectory()) || (selectionMode == FileSelector.FILES_ONLY && item.file.isFile()) ||
477 | (currentPath == null && selectionMode != FileSelector.FILES_ONLY)) {
478 | item.checked = enable;
479 | updateSelectedFileList(item, false);
480 | }
481 | }
482 | updateViews();
483 | }
484 |
485 | private void switchSelectAllState(boolean selectAll) {
486 | isSelectedAll = selectAll;
487 | fsIvAll.setVisibility(isMultiSelect ? View.VISIBLE : View.INVISIBLE);
488 | if (isSelectedAll) {
489 | fsIvAll.setColorFilter(themeColors[0]);
490 | } else {
491 | fsIvAll.clearColorFilter();
492 | }
493 | }
494 |
495 | private void updateSelectedText() {
496 | fsTvSelected.setText(String.format(textHolder.getText(TextHolder.VIEW_SELECTED_PATTERN), selectItemList.size()));
497 | }
498 |
499 | @Override
500 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
501 | Item item = itemList.get(position);
502 | if (item.file.isDirectory() || currentPath == null) {
503 | switchSelectAllState(false);
504 | loadFiles(item.file);
505 | //记录点击条目所在文件夹的文件列表滚动到的位置
506 | posList.add(new int[]{fsLv.getFirstVisiblePosition(), fsLv.getChildAt(0).getTop()});
507 | //添加导航文件夹
508 | addDir(item.file);
509 | //进入的时候重置回到顶端位置
510 | fsLv.setSelectionFromTop(0, 0);
511 | }
512 | }
513 |
514 | @Override
515 | public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
516 | if (currentPath != null) {
517 | final Item item = itemList.get(position);
518 | ArrayList menuItems = new ArrayList<>();
519 | menuItems.add(textHolder.getText(TextHolder.RENAME));
520 | menuItems.add(textHolder.getText(TextHolder.DELETE));
521 | new ActionDialog(this, menuItems, position1 -> {
522 | switch(position1) {
523 | case 0:
524 | showInputDialog(textHolder.getText(TextHolder.RENAME), item.file.getName(),
525 | null, text -> handleRenameFile(text, item));
526 | break;
527 | case 1:
528 | new AlertDialog.Builder(SelectFileActivity.this)
529 | .setMessage(textHolder.getText(TextHolder.ENSURE_DELETE_PROMPT))
530 | .setNegativeButton(textHolder.getText(TextHolder.CANCEL), null)
531 | .setPositiveButton(textHolder.getText(TextHolder.OK), (dialog, which) -> {
532 | if (item.file.isFile()) {
533 | item.file.delete();
534 | } else {
535 | FileUtils.deleteDir(item.file);
536 | }
537 | loadFiles(new File(currentPath));
538 | }).show();
539 | break;
540 | }
541 | }).show();
542 | }
543 | return true;
544 | }
545 |
546 | private void handleRenameFile(String text, Item item) {
547 | File file = new File(currentPath, text);
548 | if (!file.exists()) {
549 | boolean b = item.file.renameTo(file);
550 | if (b) {
551 | Toast.makeText(this, textHolder.getText(TextHolder.RENAME_SUCCESS),
552 | Toast.LENGTH_SHORT).show();
553 | loadFiles(new File(currentPath));
554 | } else {
555 | Toast.makeText(this, textHolder.getText(TextHolder.RENAME_FAILED),
556 | Toast.LENGTH_SHORT).show();
557 | }
558 | } else {
559 | Toast.makeText(this, textHolder.getText(TextHolder.RENAME_FAILED),
560 | Toast.LENGTH_SHORT).show();
561 | }
562 | }
563 |
564 | private interface InputCallback {
565 | void onInput(String text);
566 | }
567 |
568 | private void showInputDialog(String title, String fill, String hint, final InputCallback callback) {
569 | FrameLayout layout = new FrameLayout(this);
570 | final EditText et = new EditText(this);
571 | if (!TextUtils.isEmpty(fill)) {
572 | et.setText(fill);
573 | et.setSelection(fill.length());
574 | }
575 | if (!TextUtils.isEmpty(hint)) {
576 | et.setHint(hint);
577 | }
578 | int padding = UiUtils.dp2px(8f);
579 | layout.setPadding(padding, 0, padding, 0);
580 | layout.addView(et);
581 | new AlertDialog.Builder(this)
582 | .setTitle(title)
583 | .setView(layout)
584 | .setNegativeButton(textHolder.getText(TextHolder.CANCEL), null)
585 | .setPositiveButton(textHolder.getText(TextHolder.OK), (dialog, which) -> {
586 | if (et.getText() != null && !et.getText().toString().trim().isEmpty()) {
587 | callback.onInput(et.getText().toString().trim());
588 | }
589 | }).show();
590 | }
591 |
592 | private class FileListAdapter extends BaseListAdapter
- {
593 | FileListAdapter(Context context, List
- data) {
594 | super(context, data);
595 | }
596 |
597 | @Override
598 | BaseHolder
- getHolder(int position) {
599 | return new ViewHolder() {
600 | @Override
601 | void setData(Item data, int position) {
602 | chkView.setTag(position);
603 | if (currentPath == null) {
604 | tvName.setText(data.desc);
605 | } else {
606 | tvName.setText(data.file.getName());
607 | }
608 | String path = data.file.getAbsolutePath();
609 | if (data.file.isDirectory() || currentPath == null) {
610 | //选择文件时,不可点击,不显示选框
611 | chkView.setClickable(selectionMode != FileSelector.FILES_ONLY);
612 | ivSelect.setVisibility(selectionMode == FileSelector.FILES_ONLY ? View.INVISIBLE : View.VISIBLE);
613 | int num = 0;
614 | //如果是选择文件夹,文件不计数
615 | File[] files = data.file.listFiles();
616 | if (files != null) {
617 | for (File file : files) {
618 | if (showHiddenFiles && file.getName().startsWith(".") && ((file.isDirectory() && selectionMode != FileSelector.FILES_ONLY) ||
619 | (file.isFile() && selectionMode != FileSelector.DIRECTORIES_ONLY))) {
620 | num++;
621 | } else if (!file.getName().startsWith(".") && (filenameFilter == null || filenameFilter.accept(data.file, file.getName()))) {
622 | num++;
623 | }
624 | }
625 | }
626 | tvDesc.setText(String.format(textHolder.getText(num > 1 ? TextHolder.MULTI_ITEM_PATTERN : TextHolder.SINGLE_ITEM_PATTERN), num));
627 | Glide.with(context).load(R.drawable.fs_ic_folder).into(iv);
628 | } else {
629 | chkView.setClickable(selectionMode != FileSelector.DIRECTORIES_ONLY);
630 | ivSelect.setVisibility(selectionMode != FileSelector.DIRECTORIES_ONLY ? View.VISIBLE : View.INVISIBLE);
631 | tvDesc.setText(FileUtils.formatFileSize(data.file.length()));
632 | if (Utils.isApk(path)) {
633 | Glide.with(context).load(Utils.getApkThumbnail(context, path)).into(iv);
634 | } else if (Utils.isImage(path) || Utils.isVideo(path)) {
635 | Glide.with(context).setDefaultRequestOptions(new RequestOptions()
636 | .error(R.drawable.fs_file)).load(path).into(iv);
637 | } else if (Utils.isAudio(path)) {
638 | Glide.with(context).load(R.drawable.fs_audio).into(iv);
639 | } else if (Utils.isText(path)) {
640 | Glide.with(context).load(R.drawable.fs_text).into(iv);
641 | } else if (Utils.isPdf(path)) {
642 | Glide.with(context).load(R.drawable.fs_pdf).into(iv);
643 | } else if (Utils.isExcel(path)) {
644 | Glide.with(context).load(R.drawable.fs_excel).into(iv);
645 | } else if (Utils.isWord(path)) {
646 | Glide.with(context).load(R.drawable.fs_word).into(iv);
647 | } else if (Utils.isPPT(path)) {
648 | Glide.with(context).load(R.drawable.fs_ppt).into(iv);
649 | } else if (Utils.isZip(path)) {
650 | Glide.with(context).load(R.drawable.fs_zip).into(iv);
651 | } else if (Utils.isFlash(path)) {
652 | Glide.with(context).load(R.drawable.fs_flash).into(iv);
653 | } else if (Utils.isPs(path)) {
654 | Glide.with(context).load(R.drawable.fs_ps).into(iv);
655 | } else if (Utils.isHtml(path)) {
656 | Glide.with(context).load(R.drawable.fs_html).into(iv);
657 | } else if (Utils.isDeveloper(path)) {
658 | Glide.with(context).load(R.drawable.fs_developer).into(iv);
659 | } else {
660 | Glide.with(context).load(R.drawable.fs_file).into(iv);
661 | }
662 | }
663 | ivSelect.setSelected(data.checked);
664 | if (data.checked) {
665 | ivSelect.setColorFilter(themeColors[0]);
666 | } else {
667 | ivSelect.setColorFilter(Color.LTGRAY);
668 | }
669 | }
670 |
671 | @Override
672 | View createConvertView() {
673 | View view = View.inflate(context, R.layout.fs_file_item_view, null);
674 | tvName = view.findViewById(R.id.fsTvName);
675 | tvDesc = view.findViewById(R.id.fsTvDesc);
676 | iv = view.findViewById(R.id.iv);
677 | ivSelect = view.findViewById(R.id.fsIvSelect);
678 | view.findViewById(R.id.fsivDel).setVisibility(View.INVISIBLE);
679 | chkView = view.findViewById(R.id.fsChkView);
680 | chkView.setOnClickListener(v -> {
681 | int position1 = (int) chkView.getTag();
682 | Item item = getItem(position1);
683 | item.checked = !item.checked;
684 | updateSelectedFileList(item, true);
685 | });
686 | return view;
687 | }
688 | };
689 | }
690 | }
691 |
692 | void clearSelectedFileList() {
693 | for (Item item : selectItemList) {
694 | item.checked = false;
695 | }
696 | selectItemList.clear();
697 | switchSelectAllState(false);
698 | updateViews();
699 | }
700 |
701 | private void updateViews() {
702 | File file = new File(currentPath == null ? "" : currentPath);
703 | fsTvOk.setEnabled(!selectItemList.isEmpty() || (selectionMode != FileSelector.FILES_ONLY && file.exists()));
704 | updateSelectedText();
705 | adapter.notifyDataSetChanged();
706 | selectedItemDialog.updateList(selectItemList);
707 | }
708 |
709 | void updateSelectedFileList(Item item, boolean needNotify) {
710 | if (item.checked) {
711 | if (!selectItemList.contains(item)) {
712 | //如果是单选,把已选的删除
713 | if (!isMultiSelect && !selectItemList.isEmpty()) {
714 | Item removeItem = selectItemList.remove(0);
715 | for (Item i : itemList) {
716 | if (i == removeItem) {
717 | i.checked = false;
718 | break;
719 | }
720 | }
721 | }
722 | selectItemList.add(item);
723 | }
724 | } else {
725 | selectItemList.remove(item);
726 | }
727 | if (needNotify) {
728 | updateViews();
729 | boolean b = true;
730 | for (Item it : itemList) {
731 | if ((selectionMode == FileSelector.FILES_AND_DIRECTORIES || (selectionMode == FileSelector.FILES_ONLY && it.file.isFile()) ||
732 | (selectionMode == FileSelector.DIRECTORIES_ONLY && it.file.isDirectory())) && !selectItemList.contains(it)) {
733 | b = false;
734 | }
735 | }
736 | switchSelectAllState(b);
737 | }
738 | }
739 |
740 | private void showPopupWindow() {
741 | ListView lv = (ListView) View.inflate(this, R.layout.fs_listview, null);
742 | ArrayList items = new ArrayList<>();
743 | items.add(textHolder.getText(TextHolder.NEW_FOLDER));
744 | items.add(textHolder.getText(showHiddenFiles ? TextHolder.DONOT_SHOW_HIDDEN_FILES : TextHolder.SHOW_HIDDEN_FILES));
745 | lv.setAdapter(new PopupMenuAdapter(this, items));
746 | int height = items.size() * UiUtils.dp2px(50f) + items.size();
747 | final PopupWindow popupWindow = new PopupWindow(lv, UiUtils.getDisplayScreenWidth(), height);
748 | popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.fs_popun_menu_bg));
749 | popupWindow.setFocusable(true);
750 | popupWindow.setOutsideTouchable(true);
751 | popupWindow.setOnDismissListener(() -> {
752 | //pop消失,去掉蒙层
753 | fsMaskView.clearAnimation();
754 | fsMaskView.setVisibility(View.GONE);
755 | });
756 | lv.setOnItemClickListener((parent, view, position, id) -> {
757 | popupWindow.dismiss();
758 | switch(position) {
759 | case 0:
760 | showInputDialog(textHolder.getText(TextHolder.NEW_FOLDER), null, null, text -> {
761 | File file = new File(currentPath, text);
762 | //不存在才新建
763 | if (!file.exists()) {
764 | if (file.mkdir()) {
765 | String msg = textHolder.getText(TextHolder.FOLDER_CREATE_SUCCESS);
766 | Toast.makeText(view.getContext(), msg, Toast.LENGTH_SHORT).show();
767 | loadFiles(new File(currentPath));
768 | } else {
769 | String msg = textHolder.getText(TextHolder.FOLDER_CREATE_FAILED);
770 | Toast.makeText(view.getContext(), msg, Toast.LENGTH_SHORT).show();
771 | }
772 | }
773 | });
774 | break;
775 | case 1:
776 | showHiddenFiles = !showHiddenFiles;
777 | loadFiles(currentPath == null ? null : new File(currentPath));
778 | break;
779 | }
780 | });
781 | //显示蒙层
782 | fsMaskView.setVisibility(View.VISIBLE);
783 | AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
784 | alphaAnimation.setDuration(300);
785 | alphaAnimation.setFillAfter(true);
786 | fsMaskView.startAnimation(alphaAnimation);
787 | popupWindow.showAsDropDown(fsLayoutTitle, 0, 1);
788 | }
789 |
790 | private class PopupMenuAdapter extends BaseListAdapter {
791 | PopupMenuAdapter(Context context, List data) {
792 | super(context, data);
793 | }
794 |
795 | @Override
796 | BaseHolder getHolder(int position) {
797 | return new BaseHolder() {
798 | TextView tv;
799 |
800 | @Override
801 | void setData(String data, int position) {
802 | if (position == 1) {
803 | tv.setText(textHolder.getText(showHiddenFiles ? TextHolder.DONOT_SHOW_HIDDEN_FILES : TextHolder.SHOW_HIDDEN_FILES));
804 | } else {
805 | tv.setText(data);
806 | }
807 | }
808 |
809 | @Override
810 | View createConvertView() {
811 | View view = View.inflate(context, R.layout.fs_item_popup_menu, null);
812 | tv = view.findViewById(R.id.fsTv);
813 | return view;
814 | }
815 | };
816 | }
817 | }
818 | }
819 |
--------------------------------------------------------------------------------