|
|
@@ -2,9 +2,10 @@ package com.mgtech.base_library.activityUtils;
|
|
|
|
|
|
import android.Manifest;
|
|
|
import android.content.Intent;
|
|
|
-import android.os.Parcelable;
|
|
|
+import android.os.Bundle;
|
|
|
import android.view.View;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
@@ -18,12 +19,13 @@ import com.mgtech.base_library.R;
|
|
|
import com.mgtech.base_library.R2;
|
|
|
import com.mgtech.base_library.base.BaseActivity;
|
|
|
import com.mgtech.base_library.util.GlideEngine;
|
|
|
-import com.mgtech.base_library.util.GlideUtil;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
|
import pub.devrel.easypermissions.AfterPermissionGranted;
|
|
|
import pub.devrel.easypermissions.EasyPermissions;
|
|
|
@@ -44,13 +46,13 @@ import static com.mgtech.base_library.router.RouterURLS.BASE_CAMERA_DIALOG_URL;
|
|
|
* @Version: 1.0
|
|
|
*/
|
|
|
@Route(path = BASE_CAMERA_DIALOG_URL)
|
|
|
-public class CameraDialogActivity extends BaseActivity {
|
|
|
- @Autowired(name="num")//图片个数
|
|
|
- int num ;
|
|
|
- @Autowired(name="x")//裁剪比例 x
|
|
|
- int numX ;
|
|
|
- @Autowired(name="y")//裁剪比例 y
|
|
|
- int numY ;
|
|
|
+public class CameraDialogActivity extends BaseActivity{
|
|
|
+ @Autowired(name = "num")//图片个数
|
|
|
+ int num;
|
|
|
+ @Autowired(name = "x")//裁剪比例 x
|
|
|
+ int numX;
|
|
|
+ @Autowired(name = "y")//裁剪比例 y
|
|
|
+ int numY;
|
|
|
private boolean isCamera;
|
|
|
|
|
|
@Override
|
|
|
@@ -60,7 +62,6 @@ public class CameraDialogActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -68,22 +69,23 @@ public class CameraDialogActivity extends BaseActivity {
|
|
|
getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
}
|
|
|
|
|
|
- @OnClick({R2.id.account_take_photo, R2.id.account_photo_album, R2.id.account_photo_cancel})
|
|
|
- public void OnClick(View view) {
|
|
|
+ @OnClick({R2.id.take_photo, R2.id.photo_album, R2.id.photo_cancel})
|
|
|
+ public void onClick(View view) {
|
|
|
int id = view.getId();
|
|
|
- if (id == R.id.account_take_photo) {
|
|
|
+ if (id == R.id.take_photo) {
|
|
|
isCamera = true;
|
|
|
methodRequiresCameraPermission();
|
|
|
- } else if (id == R.id.account_photo_album) {
|
|
|
+ } else if (id == R.id.photo_album) {
|
|
|
isCamera = false;
|
|
|
methodRequiresCameraPermission();
|
|
|
- } else if (id == R.id.account_photo_cancel) {
|
|
|
+ } else if (id == R.id.photo_cancel) {
|
|
|
setResult(RESULT_CANCELED);
|
|
|
finish();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
@@ -106,11 +108,11 @@ public class CameraDialogActivity extends BaseActivity {
|
|
|
//相册
|
|
|
PictureSelector.create(this)
|
|
|
.openGallery(PictureMimeType.ofImage())
|
|
|
- .maxSelectNum(num==0?5:num) //最大个数(默认5)
|
|
|
+ .maxSelectNum(num == 0 ? 5 : num) //最大个数(默认5)
|
|
|
.minSelectNum(1)//最小个数
|
|
|
.imageSpanCount(4)//每行显示的个数
|
|
|
.isEnableCrop(true) //是否裁剪
|
|
|
- .withAspectRatio(numX==0?1:numX, numY==0?1:numY)//裁剪比例1:1(默认)
|
|
|
+ .withAspectRatio(numX == 0 ? 1 : numX, numY == 0 ? 1 : numY)//裁剪比例1:1(默认)
|
|
|
.isCompress(true)//是否压缩
|
|
|
.isCamera(false) //是否显示拍照按钮
|
|
|
.isPreviewImage(true)
|
|
|
@@ -133,7 +135,7 @@ public class CameraDialogActivity extends BaseActivity {
|
|
|
List<LocalMedia> images;
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
if (requestCode == PictureConfig.CHOOSE_REQUEST) {
|
|
|
- List<String> imgs = new LinkedList<>() ;
|
|
|
+ List<String> imgs = new LinkedList<>();
|
|
|
images = PictureSelector.obtainMultipleResult(data);
|
|
|
//selectList = PictureSelector.obtainMultipleResult(data);
|
|
|
// 例如 LocalMedia 里面返回三种path
|
|
|
@@ -141,14 +143,14 @@ public class CameraDialogActivity extends BaseActivity {
|
|
|
// 2.media.getCutPath();为裁剪后path,需判断media.isCut();是否为true
|
|
|
// 3.media.getCompressPath();为压缩后path,需判断media.isCompressed();是否为true
|
|
|
// 如果裁剪并压缩了,以取压缩路径为准,因为是先裁剪后压缩的
|
|
|
- for (int i = 0;i<images.size();i++){
|
|
|
- if (images.get(i).isCut() && images.get(i).isCompressed()){// 裁剪并压缩了
|
|
|
+ for (int i = 0; i < images.size(); i++) {
|
|
|
+ if (images.get(i).isCut() && images.get(i).isCompressed()) {// 裁剪并压缩了
|
|
|
imgs.add(images.get(i).getCompressPath());
|
|
|
- }else if (images.get(i).isCompressed()){//只进行了压缩
|
|
|
+ } else if (images.get(i).isCompressed()) {//只进行了压缩
|
|
|
imgs.add(images.get(i).getCompressPath());
|
|
|
- }else if (images.get(i).isCut()){//只进行裁剪
|
|
|
+ } else if (images.get(i).isCut()) {//只进行裁剪
|
|
|
imgs.add(images.get(i).getCutPath());
|
|
|
- }else {//原图
|
|
|
+ } else {//原图
|
|
|
imgs.add(images.get(i).getPath());
|
|
|
}
|
|
|
}
|