Skip to content

Commit 1c44549

Browse files
author
didikeeLuanon
committed
修复android10 文件夹显示问题
1 parent 883a852 commit 1c44549

5 files changed

Lines changed: 84 additions & 63 deletions

File tree

androidx/src/main/java/com/androidx/LogUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@
1111
*/
1212
public class LogUtils {
1313
private static final String TAG = "AndroidX";
14+
private static boolean DEBUG = false;
15+
16+
public static void setDebug(boolean debug){
17+
DEBUG = debug;
18+
}
1419

1520
public static void d(String message) {
16-
if (BuildConfig.DEBUG) {
21+
if (DEBUG) {
1722
Log.d(TAG, message);
1823
}
1924
}
2025

2126
public static void w(String message) {
22-
if (BuildConfig.DEBUG) {
27+
if (DEBUG) {
2328
Log.w(TAG, message);
2429
}
2530
}
2631

2732
public static void e(String message) {
28-
if (BuildConfig.DEBUG) {
33+
if (DEBUG) {
2934
Log.e(TAG, message);
3035
}
3136
}

androidx/src/main/java/com/androidx/media/MimeType.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
*/
88
public final class MimeType {
99
public static final String UNKNOWN = "";
10+
public static final String ALL = "*/*";
11+
// image
12+
public static final String IMAGE = "image/*";
1013
public static final String PNG = "image/png";
1114
public static final String JPEG = "image/jpeg";
1215
public static final String GIF = "image/gif";
13-
public static final String IMAGE = "image/*";
16+
// video
1417
public static final String VIDEO = "video/*";
18+
public static final String MP4 = "video/mp4";
1519
// audio
20+
public static final String AUDIO = "audio/*";
1621
public static final String MP3 = "audio/mpeg";
1722
public static final String AAC = "audio/aac";
1823
public static final String WAV = "audio/x-wav";
1924

20-
public static final String MP4 = "video/mp4";
25+
2126
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.androidx.picker;
2+
3+
import android.text.TextUtils;
4+
5+
import java.io.File;
6+
7+
/**
8+
* user author: didikee
9+
* create time: 2020-01-01 20:01
10+
* description:
11+
*/
12+
public abstract class AbsMediaLoader {
13+
14+
protected String[] getParentInfoFromData(String data) {
15+
if (!TextUtils.isEmpty(data)) {
16+
// 根据java系统来判断
17+
File file = new File(data);
18+
if (file.exists() && file.length() > 0) {
19+
File imageParentFile = file.getParentFile();
20+
if (imageParentFile != null) {
21+
String parentName = imageParentFile.getName();
22+
String parentPath = imageParentFile.getAbsolutePath();
23+
return new String[]{parentName, parentPath};
24+
}
25+
}
26+
}
27+
return new String[]{"", ""};
28+
}
29+
30+
protected String[] getParentInfoFromRelativePath(String relativePath) {
31+
if (!TextUtils.isEmpty(relativePath)) {
32+
// 根据相对路径来判断
33+
// DCIM/MY FOLDER/SUB/demo.png
34+
// android 10 DCIM/MY FOLDER/SUB
35+
String parentName = "";
36+
String parentPath = "";
37+
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
38+
int lastIndexOf = relativePath.lastIndexOf(File.separator);
39+
if (lastIndexOf != -1) {
40+
parentName = relativePath.substring(lastIndexOf + 1);
41+
parentPath = relativePath.substring(0, lastIndexOf);
42+
}
43+
} else {
44+
parentName = relativePath;
45+
parentPath = relativePath;
46+
}
47+
return new String[]{parentName, parentPath};
48+
}
49+
return new String[]{"", ""};
50+
}
51+
}

androidx/src/main/java/com/androidx/picker/ImageLoader.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
import com.androidx.R;
1313

14-
import java.io.File;
1514
import java.util.ArrayList;
1615

1716
/**
1817
* user author: didikee
1918
* create time: 2019-07-18 13:43
2019
* description: 获取手机里的视频
2120
*/
22-
public class ImageLoader {
21+
public class ImageLoader extends AbsMediaLoader {
2322
public static final int IMAGE = 0;
2423
public static final int IMAGE_WITHOUT_GIF = 1;
2524
public static final int GIF = 2;
@@ -109,35 +108,15 @@ private ArrayList<MediaFolder> load(Context context, String mimeType) {
109108
String parentName = "";
110109
String parentPath = "";
111110
if (!TextUtils.isEmpty(data)) {
112-
// 根据java系统来判断
113-
File file = new File(data);
114-
if (!file.exists() || file.length() <= 0) {
115-
continue;
116-
}
117-
File imageParentFile = file.getParentFile();
118-
if (imageParentFile == null) {
119-
continue;
120-
}
121-
parentName = imageParentFile.getName();
122-
parentPath = imageParentFile.getAbsolutePath();
111+
String[] parentInfo = getParentInfoFromData(data);
112+
parentName = parentInfo[0];
113+
parentPath = parentInfo[1];
123114
}
115+
124116
if (!TextUtils.isEmpty(relativePath)) {
125-
// 根据相对路径来判断
126-
// DCIM/MY FOLDER/SUB/demo.png
127-
// android 10 DCIM/MY FOLDER/SUB
128-
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
129-
int lastIndexOf = relativePath.lastIndexOf(File.separator);
130-
if (lastIndexOf != -1) {
131-
parentName = relativePath.substring(lastIndexOf + 1);
132-
parentPath = relativePath.substring(0, lastIndexOf);
133-
}
134-
// if (split.length > 0) {
135-
// parentName = split[split.length - 1];
136-
// }
137-
} else {
138-
parentName = relativePath;
139-
parentPath = relativePath;
140-
}
117+
String[] parentInfo = getParentInfoFromRelativePath(relativePath);
118+
parentName = parentInfo[0];
119+
parentPath = parentInfo[1];
141120
}
142121

143122
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE));
@@ -190,6 +169,7 @@ private ArrayList<MediaFolder> load(Context context, String mimeType) {
190169
return mediaFolders;
191170
}
192171

172+
193173
/**
194174
* 判断是否为gif
195175
* @param displayName
@@ -202,4 +182,5 @@ private boolean isGif(String displayName, String mimeType) {
202182
}
203183
return false;
204184
}
185+
205186
}

androidx/src/main/java/com/androidx/picker/VideoLoader.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
import com.androidx.R;
1313

14-
import java.io.File;
1514
import java.util.ArrayList;
1615

1716
/**
1817
* user author: didikee
1918
* create time: 2019-07-18 13:43
2019
* description: 获取手机里的视频
2120
*/
22-
public class VideoLoader {
21+
public class VideoLoader extends AbsMediaLoader{
2322

2423
public ArrayList<MediaFolder> getVideos(Context context) {
2524
return getVideos(context, "");
@@ -89,35 +88,15 @@ public ArrayList<MediaFolder> getVideos(Context context, String folderPath) {
8988
String parentName = "";
9089
String parentPath = "";
9190
if (!TextUtils.isEmpty(data)) {
92-
// 根据java系统来判断
93-
File file = new File(data);
94-
if (!file.exists() || file.length() <= 0) {
95-
continue;
96-
}
97-
File imageParentFile = file.getParentFile();
98-
if (imageParentFile == null) {
99-
continue;
100-
}
101-
parentName = imageParentFile.getName();
102-
parentPath = imageParentFile.getAbsolutePath();
91+
String[] parentInfo = getParentInfoFromData(data);
92+
parentName = parentInfo[0];
93+
parentPath = parentInfo[1];
10394
}
95+
10496
if (!TextUtils.isEmpty(relativePath)) {
105-
// 根据相对路径来判断
106-
// DCIM/MY FOLDER/SUB/demo.png
107-
// android 10 DCIM/MY FOLDER/SUB
108-
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
109-
int lastIndexOf = relativePath.lastIndexOf(File.separator);
110-
if (lastIndexOf != -1) {
111-
parentName = relativePath.substring(lastIndexOf + 1);
112-
parentPath = relativePath.substring(0, lastIndexOf);
113-
}
114-
// if (split.length > 0) {
115-
// parentName = split[split.length - 1];
116-
// }
117-
} else {
118-
parentName = relativePath;
119-
parentPath = relativePath;
120-
}
97+
String[] parentInfo = getParentInfoFromRelativePath(relativePath);
98+
parentName = parentInfo[0];
99+
parentPath = parentInfo[1];
121100
}
122101

123102
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));

0 commit comments

Comments
 (0)