Skip to content

Commit

Permalink
添加拍照返回图片的判断。
Browse files Browse the repository at this point in the history
  • Loading branch information
梁任彦 committed Nov 24, 2018
1 parent f7bd3b1 commit 7582cf7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.donkingliang.imageselectdemo.adapter.ImageAdapter;
import com.donkingliang.imageselector.utils.ImageSelector;
import com.donkingliang.imageselector.utils.ImageSelectorUtils;

import java.util.ArrayList;

Expand Down Expand Up @@ -42,6 +41,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && data != null) {
ArrayList<String> images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT);
boolean isCameraImage = data.getBooleanExtra(ImageSelector.IS_CAMERA_IMAGE, false);
// Log.d("ImageSelector", "是否是拍照图片:" + isCameraImage);
mAdapter.refresh(images);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ClipImageActivity extends Activity {
private FrameLayout btnBack;
private ClipImageView imageView;
private int mRequestCode;
private boolean isCameraImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -84,6 +85,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (data != null && requestCode == mRequestCode) {
ArrayList<String> images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT);
isCameraImage = data.getBooleanExtra(ImageSelector.IS_CAMERA_IMAGE, false);
Bitmap bitmap = ImageUtil.decodeSampledBitmapFromFile(images.get(0), 720, 1080);
if (bitmap != null) {
imageView.setBitmapData(bitmap);
Expand All @@ -108,6 +110,7 @@ private void confirm(Bitmap bitmap) {
selectImages.add(imagePath);
Intent intent = new Intent();
intent.putStringArrayListExtra(ImageSelector.SELECT_RESULT, selectImages);
intent.putExtra(ImageSelector.IS_CAMERA_IMAGE,isCameraImage);
setResult(RESULT_OK, intent);
}
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,14 @@ private void confirm() {
}

//点击确定,把选中的图片通过Intent传给上一个Activity。
setResult(images);
setResult(images,false);
finish();
}

private void setResult(ArrayList<String> images) {
private void setResult(ArrayList<String> images,boolean isCameraImage) {
Intent intent = new Intent();
intent.putStringArrayListExtra(ImageSelector.SELECT_RESULT, images);
intent.putExtra(ImageSelector.IS_CAMERA_IMAGE,isCameraImage);
setResult(RESULT_OK, intent);
}

Expand Down Expand Up @@ -515,7 +516,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(mPhotoPath))));
ArrayList<String> images = new ArrayList<>();
images.add(mPhotoPath);
setResult(images);
setResult(images,true);
finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
*/
public class ImageSelector {

//图片选择的结果
/**
* 图片选择的结果
*/
public static final String SELECT_RESULT = "select_result";

/**
* 是否是来自于相机拍照的图片,
* 只有本次调用相机拍出来的照片,返回时才为true。
* 当为true时,图片返回当结果有且只有一张图片。
*/
public static final String IS_CAMERA_IMAGE = "is_camera_image";

//最大的图片选择数
public static final String MAX_SELECT_COUNT = "max_select_count";
//是否单选
Expand Down

0 comments on commit 7582cf7

Please sign in to comment.