Skip to content

Commit

Permalink
修复android10 文件夹显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
didikeeLuanon committed Jan 1, 2020
1 parent 883a852 commit 1c44549
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 63 deletions.
11 changes: 8 additions & 3 deletions androidx/src/main/java/com/androidx/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@
*/
public class LogUtils {
private static final String TAG = "AndroidX";
private static boolean DEBUG = false;

public static void setDebug(boolean debug){
DEBUG = debug;
}

public static void d(String message) {
if (BuildConfig.DEBUG) {
if (DEBUG) {
Log.d(TAG, message);
}
}

public static void w(String message) {
if (BuildConfig.DEBUG) {
if (DEBUG) {
Log.w(TAG, message);
}
}

public static void e(String message) {
if (BuildConfig.DEBUG) {
if (DEBUG) {
Log.e(TAG, message);
}
}
Expand Down
9 changes: 7 additions & 2 deletions androidx/src/main/java/com/androidx/media/MimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
*/
public final class MimeType {
public static final String UNKNOWN = "";
public static final String ALL = "*/*";
// image
public static final String IMAGE = "image/*";
public static final String PNG = "image/png";
public static final String JPEG = "image/jpeg";
public static final String GIF = "image/gif";
public static final String IMAGE = "image/*";
// video
public static final String VIDEO = "video/*";
public static final String MP4 = "video/mp4";
// audio
public static final String AUDIO = "audio/*";
public static final String MP3 = "audio/mpeg";
public static final String AAC = "audio/aac";
public static final String WAV = "audio/x-wav";

public static final String MP4 = "video/mp4";

}
51 changes: 51 additions & 0 deletions androidx/src/main/java/com/androidx/picker/AbsMediaLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.androidx.picker;

import android.text.TextUtils;

import java.io.File;

/**
* user author: didikee
* create time: 2020-01-01 20:01
* description:
*/
public abstract class AbsMediaLoader {

protected String[] getParentInfoFromData(String data) {
if (!TextUtils.isEmpty(data)) {
// 根据java系统来判断
File file = new File(data);
if (file.exists() && file.length() > 0) {
File imageParentFile = file.getParentFile();
if (imageParentFile != null) {
String parentName = imageParentFile.getName();
String parentPath = imageParentFile.getAbsolutePath();
return new String[]{parentName, parentPath};
}
}
}
return new String[]{"", ""};
}

protected String[] getParentInfoFromRelativePath(String relativePath) {
if (!TextUtils.isEmpty(relativePath)) {
// 根据相对路径来判断
// DCIM/MY FOLDER/SUB/demo.png
// android 10 DCIM/MY FOLDER/SUB
String parentName = "";
String parentPath = "";
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
int lastIndexOf = relativePath.lastIndexOf(File.separator);
if (lastIndexOf != -1) {
parentName = relativePath.substring(lastIndexOf + 1);
parentPath = relativePath.substring(0, lastIndexOf);
}
} else {
parentName = relativePath;
parentPath = relativePath;
}
return new String[]{parentName, parentPath};
}
return new String[]{"", ""};
}
}
39 changes: 10 additions & 29 deletions androidx/src/main/java/com/androidx/picker/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

import com.androidx.R;

import java.io.File;
import java.util.ArrayList;

/**
* user author: didikee
* create time: 2019-07-18 13:43
* description: 获取手机里的视频
*/
public class ImageLoader {
public class ImageLoader extends AbsMediaLoader {
public static final int IMAGE = 0;
public static final int IMAGE_WITHOUT_GIF = 1;
public static final int GIF = 2;
Expand Down Expand Up @@ -109,35 +108,15 @@ private ArrayList<MediaFolder> load(Context context, String mimeType) {
String parentName = "";
String parentPath = "";
if (!TextUtils.isEmpty(data)) {
// 根据java系统来判断
File file = new File(data);
if (!file.exists() || file.length() <= 0) {
continue;
}
File imageParentFile = file.getParentFile();
if (imageParentFile == null) {
continue;
}
parentName = imageParentFile.getName();
parentPath = imageParentFile.getAbsolutePath();
String[] parentInfo = getParentInfoFromData(data);
parentName = parentInfo[0];
parentPath = parentInfo[1];
}

if (!TextUtils.isEmpty(relativePath)) {
// 根据相对路径来判断
// DCIM/MY FOLDER/SUB/demo.png
// android 10 DCIM/MY FOLDER/SUB
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
int lastIndexOf = relativePath.lastIndexOf(File.separator);
if (lastIndexOf != -1) {
parentName = relativePath.substring(lastIndexOf + 1);
parentPath = relativePath.substring(0, lastIndexOf);
}
// if (split.length > 0) {
// parentName = split[split.length - 1];
// }
} else {
parentName = relativePath;
parentPath = relativePath;
}
String[] parentInfo = getParentInfoFromRelativePath(relativePath);
parentName = parentInfo[0];
parentPath = parentInfo[1];
}

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


/**
* 判断是否为gif
* @param displayName
Expand All @@ -202,4 +182,5 @@ private boolean isGif(String displayName, String mimeType) {
}
return false;
}

}
37 changes: 8 additions & 29 deletions androidx/src/main/java/com/androidx/picker/VideoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

import com.androidx.R;

import java.io.File;
import java.util.ArrayList;

/**
* user author: didikee
* create time: 2019-07-18 13:43
* description: 获取手机里的视频
*/
public class VideoLoader {
public class VideoLoader extends AbsMediaLoader{

public ArrayList<MediaFolder> getVideos(Context context) {
return getVideos(context, "");
Expand Down Expand Up @@ -89,35 +88,15 @@ public ArrayList<MediaFolder> getVideos(Context context, String folderPath) {
String parentName = "";
String parentPath = "";
if (!TextUtils.isEmpty(data)) {
// 根据java系统来判断
File file = new File(data);
if (!file.exists() || file.length() <= 0) {
continue;
}
File imageParentFile = file.getParentFile();
if (imageParentFile == null) {
continue;
}
parentName = imageParentFile.getName();
parentPath = imageParentFile.getAbsolutePath();
String[] parentInfo = getParentInfoFromData(data);
parentName = parentInfo[0];
parentPath = parentInfo[1];
}

if (!TextUtils.isEmpty(relativePath)) {
// 根据相对路径来判断
// DCIM/MY FOLDER/SUB/demo.png
// android 10 DCIM/MY FOLDER/SUB
if (!TextUtils.isEmpty(relativePath) && relativePath.contains(File.separator)) {
int lastIndexOf = relativePath.lastIndexOf(File.separator);
if (lastIndexOf != -1) {
parentName = relativePath.substring(lastIndexOf + 1);
parentPath = relativePath.substring(0, lastIndexOf);
}
// if (split.length > 0) {
// parentName = split[split.length - 1];
// }
} else {
parentName = relativePath;
parentPath = relativePath;
}
String[] parentInfo = getParentInfoFromRelativePath(relativePath);
parentName = parentInfo[0];
parentPath = parentInfo[1];
}

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

0 comments on commit 1c44549

Please sign in to comment.