Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Mar 30, 2018
1 parent f63a234 commit a6b8aa5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,24 @@ protected void removeImage(int id, boolean eqVideo) {
*
* @param data
*/
protected void isAudio(Intent data) {
protected String getAudioPath(Intent data) {
boolean compare_SDK_19 = Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT;
if (data != null && config.mimeType == PictureMimeType.ofAudio()) {
try {
Uri uri = data.getData();
String audioPath;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
final String audioPath;
if (compare_SDK_19) {
audioPath = uri.getPath();
} else {
audioPath = getAudioFilePathFromUri(uri);
}
PictureFileUtils.copyAudioFile(audioPath, cameraPath);
return audioPath;

} catch (Exception e) {
e.printStackTrace();
}
}
return "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,6 @@ public void onNext(Boolean aBoolean) {
if (aBoolean) {
Intent cameraIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
File cameraFile = PictureFileUtils.createCameraFile
(PictureSelectorActivity.this, config.mimeType,
outputCameraPath, config.suffixType);
cameraPath = cameraFile.getAbsolutePath();
Uri imageUri = parUri(cameraFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, PictureConfig.REQUEST_CAMERA);
}
} else {
Expand Down Expand Up @@ -504,7 +498,7 @@ public void onClick(View v) {
if (size < config.minSelectNum) {
String str = eqImg ? getString(R.string.picture_min_img_num, config.minSelectNum)
: getString(R.string.picture_min_video_num, config.minSelectNum);
ToastManage.s(mContext,str);
ToastManage.s(mContext, str);
return;
}
}
Expand Down Expand Up @@ -758,7 +752,7 @@ public void onNext(Boolean aBoolean) {
if (aBoolean) {
startCamera();
} else {
ToastManage.s(mContext,getString(R.string.picture_camera));
ToastManage.s(mContext, getString(R.string.picture_camera));
if (config.camera) {
closeActivity();
}
Expand Down Expand Up @@ -937,7 +931,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
handlerResult(medias);
break;
case PictureConfig.REQUEST_CAMERA:
isAudio(data);
cameraPath = getAudioPath(data);
// on take photo success
final File file = new File(cameraPath);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* package:com.luck.picture.lib.config
* email:[email protected]
* data:2017/5/24
* @author luck
*/

public final class PictureMimeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public class PictureFileUtils {

public static final String POSTFIX = ".JPEG";
public static final String POST_VIDEO = ".mp4";
public static final String POST_AUDIO = ".mp3";
public static final String APP_NAME = "PictureSelector";
public static final String CAMERA_PATH = "/" + APP_NAME + "/CameraImage/";
public static final String CAMERA_AUDIO_PATH = "/" + APP_NAME + "/CameraAudio/";
public static final String CROP_PATH = "/" + APP_NAME + "/CropImage/";

/**
Expand All @@ -64,17 +62,10 @@ public class PictureFileUtils {
* @return
*/
public static File createCameraFile(Context context, int type, String outputCameraPath, String format) {
String path;
if (type == PictureConfig.TYPE_AUDIO) {
path = !TextUtils.isEmpty(outputCameraPath)
? outputCameraPath : CAMERA_AUDIO_PATH;
} else {
path = !TextUtils.isEmpty(outputCameraPath)
? outputCameraPath : CAMERA_PATH;
}
return type == PictureConfig.TYPE_AUDIO ?
createMediaFile(context, path, type, format) :
createMediaFile(context, path, type, format);
String path = !TextUtils.isEmpty(outputCameraPath)
? outputCameraPath : CAMERA_PATH;

return createMediaFile(context, path, type, format);
}

/**
Expand Down Expand Up @@ -109,9 +100,6 @@ private static File createMediaFile(Context context, String parentPath, int type
case PictureConfig.TYPE_VIDEO:
tmpFile = new File(folderDir, fileName + POST_VIDEO);
break;
case PictureConfig.TYPE_AUDIO:
tmpFile = new File(folderDir, fileName + POST_AUDIO);
break;
}
return tmpFile;
}
Expand Down Expand Up @@ -318,8 +306,12 @@ public static void copyFile(@NonNull String pathFrom, @NonNull String pathTo) th
inputChannel.transferTo(0, inputChannel.size(), outputChannel);
inputChannel.close();
} finally {
if (inputChannel != null) inputChannel.close();
if (outputChannel != null) outputChannel.close();
if (inputChannel != null) {
inputChannel.close();
}
if (outputChannel != null) {
outputChannel.close();
}
}
}

Expand All @@ -329,9 +321,9 @@ public static void copyFile(@NonNull String pathFrom, @NonNull String pathTo) th
* will cause both files to become null.
* Simply skipping this step if the paths are identical.
*/
public static void copyAudioFile(@NonNull String pathFrom, @NonNull String pathTo) throws IOException {
public static boolean copyAudioFile(@NonNull String pathFrom, @NonNull String pathTo) throws IOException {
if (pathFrom.equalsIgnoreCase(pathTo)) {
return;
return false;
}

FileChannel outputChannel = null;
Expand All @@ -342,9 +334,14 @@ public static void copyAudioFile(@NonNull String pathFrom, @NonNull String pathT
inputChannel.transferTo(0, inputChannel.size(), outputChannel);
inputChannel.close();
} finally {
if (inputChannel != null) inputChannel.close();
if (outputChannel != null) outputChannel.close();
PictureFileUtils.deleteFile(pathFrom);
if (inputChannel != null) {
inputChannel.close();
}
if (outputChannel != null) {
outputChannel.close();
}
boolean success = PictureFileUtils.deleteFile(pathFrom);
return success;
}
}

Expand Down Expand Up @@ -485,8 +482,10 @@ public static String createDir(Context context, String filename, String director
path = new File(rootDir.getAbsolutePath() + "/PictureSelector");
}
if (!path.exists())
// 若不存在,创建目录,可以在应用启动的时候创建
// 若不存在,创建目录,可以在应用启动的时候创建
{
path.mkdirs();
}

return path + "/" + filename;
}
Expand Down Expand Up @@ -633,17 +632,19 @@ public static void deleteExternalCacheDirFile(Context mContext) {
*
* @param path
*/
public static void deleteFile(String path) {
public static boolean deleteFile(String path) {
try {
if (!TextUtils.isEmpty(path)) {
File file = new File(path);
if (file != null) {
file.delete();
return file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}

/**
Expand Down

0 comments on commit a6b8aa5

Please sign in to comment.