Skip to content

Commit

Permalink
fix 鲁班压缩出现路径重复
Browse files Browse the repository at this point in the history
  • Loading branch information
周晓东 committed Jan 18, 2017
1 parent 478cf70 commit a0a64a5
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 145 deletions.
2 changes: 1 addition & 1 deletion simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.jph.simple"
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand Down
4 changes: 2 additions & 2 deletions takephoto_library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 42
versionName "4.0.2"
Expand All @@ -23,6 +23,6 @@ dependencies {
compile 'com.android.support:support-v4:25.0.0'
compile 'com.soundcloud.android.crop:lib_crop:1.0.0'
compile 'com.darsh.multipleimageselect:multipleimageselect:1.0.4'
compile 'me.shaohui.advancedluban:library:1.2.8'
compile 'me.shaohui.advancedluban:library:1.3.2'
}
//apply from: "bintrayUpload.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,91 @@
* Eamil:crazycodeboy@gmail.com
*/
public class CompressWithLuBan implements CompressImage {
private ArrayList<TImage> images;
private CompressListener listener;
private Context context;
private LubanOptions options;
private ArrayList<File> files = new ArrayList<>();
private ArrayList<TImage> images;
private CompressListener listener;
private Context context;
private LubanOptions options;
private ArrayList<File> files = new ArrayList<>();

public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images, CompressListener listener) {
options=config.getLubanOptions();
this.images = images;
this.listener = listener;
this.context = context;
}
public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images,
CompressListener listener) {
options = config.getLubanOptions();
this.images = images;
this.listener = listener;
this.context = context;
}

@Override
public void compress() {
if (images == null || images.isEmpty()) {
listener.onCompressFailed(images, " images is null");
return;
}
for (TImage image : images) {
if (image == null) {
listener.onCompressFailed(images, " There are pictures of compress is null.");
return;
}
files.add(new File(image.getOriginalPath()));
}
if (images.size() == 1) {
compressOne();
} else {
compressMulti();
}
@Override public void compress() {
if (images == null || images.isEmpty()) {
listener.onCompressFailed(images, " images is null");
return;
}
for (TImage image : images) {
if (image == null) {
listener.onCompressFailed(images, " There are pictures of compress is null.");
return;
}
files.add(new File(image.getOriginalPath()));
}
if (images.size() == 1) {
compressOne();
} else {
compressMulti();
}
}

private void compressOne() {
Luban.get(context).putGear(options.getGear())
.load(files.get(0))
.setMaxHeight(options.getMaxHeight())
.setMaxWidth(options.getMaxWidth())
.setMaxSize(options.getMaxSize()/1000)
.launch(new OnCompressListener() {
@Override
public void onStart() {
private void compressOne() {
Luban.compress(context, files.get(0))
.putGear(Luban.CUSTOM_GEAR)
.setMaxHeight(options.getMaxHeight())
.setMaxWidth(options.getMaxWidth())
.setMaxSize(options.getMaxSize() / 1000)
.launch(new OnCompressListener() {
@Override public void onStart() {

}
}

@Override
public void onSuccess(File file) {
TImage image=images.get(0);
image.setCompressPath(file.getPath());
image.setCompressed(true);
listener.onCompressSuccess(images);
}
@Override public void onSuccess(File file) {
TImage image = images.get(0);
image.setCompressPath(file.getPath());
image.setCompressed(true);
listener.onCompressSuccess(images);
}

@Override
public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}
@Override public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}

private void compressMulti() {
Luban.get(context).putGear(options.getGear())
.load(files)
.setMaxSize(options.getMaxSize()/1000) // limit the final image size(unit:Kb)
.setMaxHeight(options.getMaxHeight()) // limit image height
.setMaxWidth(options.getMaxWidth())
.launch(new OnMultiCompressListener() {
@Override
public void onStart() {
private void compressMulti() {
Luban.compress(context, files)
.putGear(Luban.CUSTOM_GEAR)
.setMaxSize(
options.getMaxSize() / 1000) // limit the final image size(unit:Kb)
.setMaxHeight(options.getMaxHeight()) // limit image height
.setMaxWidth(options.getMaxWidth())
.launch(new OnMultiCompressListener() {
@Override public void onStart() {

}
}

@Override
public void onSuccess(List<File> fileList) {
handleCompressCallBack(fileList);
}
@Override public void onSuccess(List<File> fileList) {
handleCompressCallBack(fileList);
}

@Override
public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}
@Override public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}

private void handleCompressCallBack(List<File> files) {
for (int i = 0, j = images.size(); i < j; i++) {
TImage image=images.get(i);
image.setCompressed(true);
image.setCompressPath(files.get(i).getPath());
}
listener.onCompressSuccess(images);
private void handleCompressCallBack(List<File> files) {
for (int i = 0, j = images.size(); i < j; i++) {
TImage image = images.get(i);
image.setCompressed(true);
image.setCompressPath(files.get(i).getPath());
}
listener.onCompressSuccess(images);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.io.Serializable;

import me.shaohui.advancedluban.Luban;

/**
* Luban配置类
* Author: crazycodeboy
Expand All @@ -13,76 +11,69 @@
* GitHub:https://github.com/crazycodeboy
* Eamil:crazycodeboy@gmail.com
*/
public class LubanOptions implements Serializable{
/**
* 压缩到的最大大小,单位B
*/
private int maxSize;
private int maxHeight;
private int maxWidth;
private int gear= Luban.CUSTOM_GEAR;
private LubanOptions(){}

public int getMaxSize() {
return maxSize;
}

public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}

public int getMaxHeight() {
return maxHeight;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
public class LubanOptions implements Serializable {
/**
* 压缩到的最大大小,单位B
*/
private int maxSize;
private int maxHeight;
private int maxWidth;

private LubanOptions() {
}

public int getMaxSize() {
return maxSize;
}

public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}

public int getMaxHeight() {
return maxHeight;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}

public int getMaxWidth() {
return maxWidth;
}

public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
}

public static class Builder {
private LubanOptions options;

public Builder() {
options = new LubanOptions();
}

public int getMaxWidth() {
return maxWidth;
public Builder setMaxSize(int maxSize) {
options.setMaxSize(maxSize);
return this;
}

public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
public Builder setMaxHeight(int maxHeight) {
options.setMaxHeight(maxHeight);
return this;
}

public int getGear() {
return gear;
public Builder setMaxWidth(int maxWidth) {
options.setMaxWidth(maxWidth);
return this;
}

public void setGear(int gear) {
this.gear = gear;
public Builder setGear(int gear) {
return this;
}

public static class Builder{
private LubanOptions options;

public Builder() {
options=new LubanOptions();
}

public Builder setMaxSize(int maxSize) {
options.setMaxSize(maxSize);
return this;
}

public Builder setMaxHeight(int maxHeight) {
options.setMaxHeight(maxHeight);
return this;
}

public Builder setMaxWidth(int maxWidth) {
options.setMaxWidth(maxWidth);
return this;
}

public Builder setGear(int gear) {
options.setGear(gear);
return this;
}
public LubanOptions create(){
return options;
}
public LubanOptions create() {
return options;
}
}
}

0 comments on commit a0a64a5

Please sign in to comment.