99import com .jph .takephoto .app .TakePhoto ;
1010import com .jph .takephoto .compress .CompressConfig ;
1111import com .jph .takephoto .model .CropOptions ;
12+ import com .jph .takephoto .model .LubanOptions ;
1213import com .jph .takephoto .model .TakePhotoOptions ;
1314
1415import java .io .File ;
1516
17+ import me .shaohui .advancedluban .Luban ;
18+
1619
1720/**
1821 * - 支持通过相机拍照获取图片
3639 */
3740public class CustomHelper {
3841 private View rootView ;
39- private RadioGroup rgCrop ,rgCompress ,rgFrom ,rgCropSize ,rgCropTool ,rgShowProgressBar ,rgPickTool ;
40- private EditText etCropHeight ,etCropWidth ,etLimit ,etSize ,etPx ;
42+ private RadioGroup rgCrop ,rgCompress ,rgFrom ,rgCropSize ,rgCropTool ,rgShowProgressBar ,rgPickTool , rgCompressTool ;
43+ private EditText etCropHeight ,etCropWidth ,etLimit ,etSize ,etHeightPx , etWidthPx ;
4144 public static CustomHelper of (View rootView ){
4245 return new CustomHelper (rootView );
4346 }
@@ -48,6 +51,7 @@ private CustomHelper(View rootView) {
4851 private void init (){
4952 rgCrop = (RadioGroup ) rootView .findViewById (R .id .rgCrop );
5053 rgCompress = (RadioGroup ) rootView .findViewById (R .id .rgCompress );
54+ rgCompressTool = (RadioGroup ) rootView .findViewById (R .id .rgCompressTool );
5155 rgCropSize = (RadioGroup ) rootView .findViewById (R .id .rgCropSize );
5256 rgFrom = (RadioGroup ) rootView .findViewById (R .id .rgFrom );
5357 rgPickTool = (RadioGroup ) rootView .findViewById (R .id .rgPickTool );
@@ -57,7 +61,8 @@ private void init(){
5761 etCropWidth = (EditText ) rootView .findViewById (R .id .etCropWidth );
5862 etLimit = (EditText ) rootView .findViewById (R .id .etLimit );
5963 etSize = (EditText ) rootView .findViewById (R .id .etSize );
60- etPx = (EditText ) rootView .findViewById (R .id .etPx );
64+ etHeightPx = (EditText ) rootView .findViewById (R .id .etHeightPx );
65+ etWidthPx = (EditText ) rootView .findViewById (R .id .etWidthPx );
6166
6267
6368
@@ -118,10 +123,26 @@ private void configCompress(TakePhoto takePhoto){
118123 return ;
119124 }
120125 int maxSize = Integer .parseInt (etSize .getText ().toString ());
121- int maxPixel = Integer .parseInt (etPx .getText ().toString ());
126+ int width = Integer .parseInt (etCropWidth .getText ().toString ());
127+ int height = Integer .parseInt (etHeightPx .getText ().toString ());
122128 boolean showProgressBar =rgShowProgressBar .getCheckedRadioButtonId ()==R .id .rbShowYes ? true :false ;
123- CompressConfig config = new CompressConfig .Builder ().setMaxSize (maxSize ).setMaxPixel (maxPixel ).create ();
129+ CompressConfig config ;
130+ if (rgCompressTool .getCheckedRadioButtonId ()==R .id .rbCompressWithOwn ){
131+ config =new CompressConfig .Builder ()
132+ .setMaxSize (maxSize )
133+ .setMaxPixel (width >=height ? width :height )
134+ .create ();
135+ }else {
136+ LubanOptions option =new LubanOptions .Builder ()
137+ .setGear (Luban .CUSTOM_GEAR )
138+ .setMaxHeight (height )
139+ .setMaxWidth (width )
140+ .setMaxSize (maxSize )
141+ .create ();
142+ config =CompressConfig .ofLuban (option );
143+ }
124144 takePhoto .onEnableCompress (config ,showProgressBar );
145+
125146 }
126147 private CropOptions getCropOptions (){
127148 if (rgCrop .getCheckedRadioButtonId ()!=R .id .rbCropYes )return null ;
0 commit comments