Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Jan 16, 2020
1 parent 6c6b321 commit 131ae94
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ protected void compressImage(final List<LocalMedia> result) {
.setTargetDir(config.compressSavePath)
.setCompressQuality(config.compressQuality)
.setFocusAlpha(config.focusAlpha)
.setRenameListener(filePath -> config.renameCompressFileName)
.setNewCompressFileName(config.renameCompressFileName)
.ignoreBy(config.minimumCompressSize).get();

// 线程切换
mHandler.sendMessage(mHandler.obtainMessage(MSG_ASY_COMPRESSION_RESULT_SUCCESS,
new Object[]{result, files}));
Expand All @@ -318,7 +319,7 @@ protected void compressImage(final List<LocalMedia> result) {
.setCompressQuality(config.compressQuality)
.setTargetDir(config.compressSavePath)
.setFocusAlpha(config.focusAlpha)
.setRenameListener(filePath -> config.renameCompressFileName)
.setNewCompressFileName(config.renameCompressFileName)
.setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.luck.picture.lib;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
Expand All @@ -21,6 +22,7 @@
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.observable.ImagesObservable;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.luck.picture.lib.tools.ScreenUtils;
import com.luck.picture.lib.tools.StringUtils;
import com.luck.picture.lib.tools.ToastUtils;
Expand Down Expand Up @@ -530,6 +532,9 @@ protected void onCheckedComplete() {
if (config.selectionMode == PictureConfig.SINGLE) {
selectImages.clear();
}
if (!TextUtils.isEmpty(image.getRealPath()) && image.getPath().startsWith("content://")) {
image.setRealPath(PictureFileUtils.getPath(getContext(), Uri.parse(image.getPath())));
}
selectImages.add(image);
onSelectedChange(true, image);
image.setNum(selectImages.size());
Expand Down Expand Up @@ -661,6 +666,7 @@ private void bothMimeTypeWith(String mimeType, LocalMedia image) {
cutInfo.setAndroidQToPath(media.getAndroidQToPath());
cutInfo.setId(media.getId());
cutInfo.setDuration(media.getDuration());
cutInfo.setRealPath(media.getRealPath());
cuts.add(cutInfo);
}
if (imageNum <= 0) {
Expand Down Expand Up @@ -709,6 +715,7 @@ private void separateMimeTypeWith(String mimeType, LocalMedia image) {
cutInfo.setAndroidQToPath(media.getAndroidQToPath());
cutInfo.setId(media.getId());
cutInfo.setDuration(media.getDuration());
cutInfo.setRealPath(media.getRealPath());
cuts.add(cutInfo);
}
startCrop(cuts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ private void bothMimeTypeWith(boolean eqImg, List<LocalMedia> images) {
cutInfo.setImageHeight(media.getHeight());
cutInfo.setMimeType(media.getMimeType());
cutInfo.setDuration(media.getDuration());
cutInfo.setRealPath(media.getRealPath());
cuts.add(cutInfo);
}
if (imageNum <= 0) {
Expand Down Expand Up @@ -722,6 +723,7 @@ private void separateMimeTypeWith(boolean eqImg, List<LocalMedia> images) {
cutInfo.setImageHeight(media.getHeight());
cutInfo.setMimeType(media.getMimeType());
cutInfo.setDuration(media.getDuration());
cutInfo.setRealPath(media.getRealPath());
cuts.add(cutInfo);
}
startCrop(cuts);
Expand Down Expand Up @@ -1281,6 +1283,7 @@ private void requestCamera(Intent data) {
}
int lastIndexOf = config.cameraPath.lastIndexOf("/") + 1;
media.setId(lastIndexOf > 0 ? ValueOf.toLong(config.cameraPath.substring(lastIndexOf)) : -1);
media.setRealPath(path);
} else {
File file = new File(config.cameraPath);
mimeType = PictureMimeType.getMimeType(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ protected void requestCamera(Intent data) {
}
int lastIndexOf = config.cameraPath.lastIndexOf("/") + 1;
media.setId(lastIndexOf > 0 ? ValueOf.toLong(config.cameraPath.substring(lastIndexOf)) : -1);
media.setRealPath(path);
if (config.isUseCustomCamera && data != null) {
// 自定义拍照时已经在应用沙盒内生成了文件
String mediaPath = data.getStringExtra(PictureConfig.EXTRA_MEDIA_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
ToastUtils.s(context, PictureMimeType.s(context, mimeType));
return;
}
if (SdkVersionUtils.checkedAndroid_Q()) {
image.setRealPath(newPath);
}
changeCheckboxState(contentHolder, image);
});
}
Expand All @@ -189,6 +192,9 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
if (index == -1) {
return;
}
if (SdkVersionUtils.checkedAndroid_Q()) {
image.setRealPath(newPath);
}
boolean eqResult =
PictureMimeType.eqImage(mimeType) && config.enablePreview
|| PictureMimeType.eqVideo(mimeType) && (config.enPreviewVideo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ File compress() throws IOException {
Bitmap tagBitmap = BitmapFactory.decodeStream(srcImg.open(), null, options);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
if (srcImg.getMedia() != null && Checker.SINGLE.isJPG(srcImg.getMedia().getMimeType())) {
tagBitmap = rotatingImage(tagBitmap, Checker.SINGLE.getOrientation(srcImg.open()));
int orientation = Checker.SINGLE.getOrientation(srcImg.open());
if (orientation > 0) {
tagBitmap = rotatingImage(tagBitmap, orientation);
}
}
if (tagBitmap != null) {
compressQuality = compressQuality <= 0 || compressQuality > 100 ? DEFAULT_QUALITY : compressQuality;
Expand All @@ -93,7 +96,6 @@ File compress() throws IOException {
fos.flush();
fos.close();
stream.close();

return tagImg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Luban implements Handler.Callback {
private static final int MSG_COMPRESS_ERROR = 2;

private String mTargetDir;
private String mNewFileName;
private boolean focusAlpha;
private boolean isCamera;
private int mLeastCompressSize;
Expand All @@ -54,6 +55,7 @@ private Luban(Builder builder) {
this.mPaths = builder.mPaths;
this.mediaList = builder.mediaList;
this.mTargetDir = builder.mTargetDir;
this.mNewFileName = builder.mNewFileName;
this.mRenameListener = builder.mRenameListener;
this.mStreamProviders = builder.mStreamProviders;
this.mCompressListener = builder.mCompressListener;
Expand Down Expand Up @@ -260,17 +262,19 @@ private File compressReal(Context context, InputStreamProvider path) throws IOEx
private File compressRealLocalMedia(Context context, InputStreamProvider path) throws IOException {
File result;
LocalMedia media = path.getMedia();
String newPath = isAndroidQ ? PictureFileUtils
.getPath(context, Uri.parse(path.getPath())) : path.getPath();
String newPath;
if (isAndroidQ) {
newPath = !TextUtils.isEmpty(media.getRealPath()) ? media.getRealPath() :
PictureFileUtils.getPath(context, Uri.parse(path.getPath()));
} else {
newPath = path.getPath();
}
String suffix = Checker.SINGLE.extSuffix(media != null ? path.getMedia().getMimeType() : "");
File outFile = getImageCacheFile(context, path, TextUtils.isEmpty(suffix) ? Checker.SINGLE.extSuffix(path) : suffix);
String filename = "";
if (mRenameListener != null) {
filename = mRenameListener.rename(newPath);
if (!TextUtils.isEmpty(filename)) {
filename = isCamera ? filename : StringUtils.rename(filename);
outFile = getImageCustomFile(context, filename);
}
if (!TextUtils.isEmpty(mNewFileName)) {
filename = isCamera ? mNewFileName : StringUtils.rename(mNewFileName);
outFile = getImageCustomFile(context, filename);
}
// 如果文件存在直接返回不处理
if (outFile.exists()) {
Expand Down Expand Up @@ -345,6 +349,7 @@ public boolean handleMessage(Message msg) {
public static class Builder {
private Context context;
private String mTargetDir;
private String mNewFileName;
private boolean focusAlpha;
private boolean isCamera;
private int compressQuality;
Expand Down Expand Up @@ -503,6 +508,7 @@ public Builder putGear(int gear) {
return this;
}

@Deprecated
public Builder setRenameListener(OnRenameListener listener) {
this.mRenameListener = listener;
return this;
Expand All @@ -518,6 +524,11 @@ public Builder setTargetDir(String targetDir) {
return this;
}

public Builder setNewCompressFileName(String newFileName) {
this.mNewFileName = newFileName;
return this;
}

public Builder isCamera(boolean isCamera) {
this.isCamera = isCamera;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public class LocalMedia implements Parcelable {
* original path
*/
private String path;

/**
* The real path,But you can't get access from AndroidQ
* <p>
* It could be empty
* <p/>
*/
private String realPath;

/**
* # Check the original button to get the return value
* original path
Expand Down Expand Up @@ -171,6 +180,13 @@ public void setDuration(long duration) {
this.duration = duration;
}

public String getRealPath() {
return realPath;
}

public void setRealPath(String realPath) {
this.realPath = realPath;
}

public boolean isChecked() {
return isChecked;
Expand Down Expand Up @@ -294,6 +310,7 @@ public int describeContents() {
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.id);
dest.writeString(this.path);
dest.writeString(this.realPath);
dest.writeString(this.originalPath);
dest.writeString(this.compressPath);
dest.writeString(this.cutPath);
Expand All @@ -316,6 +333,7 @@ public void writeToParcel(Parcel dest, int flags) {
protected LocalMedia(Parcel in) {
this.id = in.readLong();
this.path = in.readString();
this.realPath = in.readString();
this.originalPath = in.readString();
this.compressPath = in.readString();
this.cutPath = in.readString();
Expand Down
17 changes: 17 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/model/CutInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public class CutInfo implements Parcelable {
*/
private Uri httpOutUri;


/**
* The real path,But you can't get access from AndroidQ
*/
private String realPath;


public CutInfo() {
}

Expand Down Expand Up @@ -177,6 +184,14 @@ public void setDuration(long duration) {
this.duration = duration;
}

public String getRealPath() {
return realPath;
}

public void setRealPath(String realPath) {
this.realPath = realPath;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -197,6 +212,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.resultAspectRatio);
dest.writeLong(this.duration);
dest.writeParcelable(this.httpOutUri, flags);
dest.writeString(this.realPath);
}

protected CutInfo(Parcel in) {
Expand All @@ -213,6 +229,7 @@ protected CutInfo(Parcel in) {
this.resultAspectRatio = in.readFloat();
this.duration = in.readLong();
this.httpOutUri = in.readParcelable(Uri.class.getClassLoader());
this.realPath = in.readString();
}

public static final Creator<CutInfo> CREATOR = new Creator<CutInfo>() {
Expand Down

0 comments on commit 131ae94

Please sign in to comment.