From a0a64a59762fa8554eb46b6ec544f70a5d46f551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=99=93=E4=B8=9C?= Date: Wed, 18 Jan 2017 13:40:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E9=B2=81=E7=8F=AD=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E8=B7=AF=E5=BE=84=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple/build.gradle | 2 +- takephoto_library/build.gradle | 4 +- .../takephoto/compress/CompressWithLuBan.java | 153 +++++++++--------- .../com/jph/takephoto/model/LubanOptions.java | 117 +++++++------- 4 files changed, 131 insertions(+), 145 deletions(-) diff --git a/simple/build.gradle b/simple/build.gradle index c2615986..09ff929b 100644 --- a/simple/build.gradle +++ b/simple/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "com.jph.simple" - minSdkVersion 9 + minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "1.0" diff --git a/takephoto_library/build.gradle b/takephoto_library/build.gradle index 6f4db6f2..712dafe8 100644 --- a/takephoto_library/build.gradle +++ b/takephoto_library/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "25.0.0" defaultConfig { - minSdkVersion 9 + minSdkVersion 14 targetSdkVersion 25 versionCode 42 versionName "4.0.2" @@ -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" \ No newline at end of file diff --git a/takephoto_library/src/main/java/com/jph/takephoto/compress/CompressWithLuBan.java b/takephoto_library/src/main/java/com/jph/takephoto/compress/CompressWithLuBan.java index b8533504..2503fad3 100644 --- a/takephoto_library/src/main/java/com/jph/takephoto/compress/CompressWithLuBan.java +++ b/takephoto_library/src/main/java/com/jph/takephoto/compress/CompressWithLuBan.java @@ -22,96 +22,91 @@ * Eamil:crazycodeboy@gmail.com */ public class CompressWithLuBan implements CompressImage { - private ArrayList images; - private CompressListener listener; - private Context context; - private LubanOptions options; - private ArrayList files = new ArrayList<>(); + private ArrayList images; + private CompressListener listener; + private Context context; + private LubanOptions options; + private ArrayList files = new ArrayList<>(); - public CompressWithLuBan(Context context, CompressConfig config, ArrayList images, CompressListener listener) { - options=config.getLubanOptions(); - this.images = images; - this.listener = listener; - this.context = context; - } + public CompressWithLuBan(Context context, CompressConfig config, ArrayList 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 fileList) { - handleCompressCallBack(fileList); - } + @Override public void onSuccess(List 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 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 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); + } } diff --git a/takephoto_library/src/main/java/com/jph/takephoto/model/LubanOptions.java b/takephoto_library/src/main/java/com/jph/takephoto/model/LubanOptions.java index 555bc2e1..c66cf1fb 100644 --- a/takephoto_library/src/main/java/com/jph/takephoto/model/LubanOptions.java +++ b/takephoto_library/src/main/java/com/jph/takephoto/model/LubanOptions.java @@ -2,8 +2,6 @@ import java.io.Serializable; -import me.shaohui.advancedluban.Luban; - /** * Luban配置类 * Author: crazycodeboy @@ -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; } + } }