use of com.darsh.multipleimageselect.models.Image in project TakePhoto by crazycodeboy.
the class TakePhotoImpl method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case TConstant.RC_PICK_PICTURE_FROM_GALLERY_CROP:
if (resultCode == Activity.RESULT_OK && data != null) {
//从相册选择照片并裁剪
try {
onCrop(data.getData(), outPutUri, cropOptions);
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri, fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
case //从相册选择照片不裁剪
TConstant.RC_PICK_PICTURE_FROM_GALLERY_ORIGINAL:
if (resultCode == Activity.RESULT_OK) {
try {
takeResult(TResult.of(TImage.of(TUriParse.getFilePathWithUri(data.getData(), contextWrap.getActivity()), fromType)));
} catch (TException e) {
takeResult(TResult.of(TImage.of(data.getData(), fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
case //从文件选择照片不裁剪
TConstant.RC_PICK_PICTURE_FROM_DOCUMENTS_ORIGINAL:
if (resultCode == Activity.RESULT_OK) {
try {
takeResult(TResult.of(TImage.of(TUriParse.getFilePathWithDocumentsUri(data.getData(), contextWrap.getActivity()), fromType)));
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri, fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
case //从文件选择照片,并裁剪
TConstant.RC_PICK_PICTURE_FROM_DOCUMENTS_CROP:
if (resultCode == Activity.RESULT_OK) {
try {
onCrop(data.getData(), outPutUri, cropOptions);
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri, fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
case //拍取照片,并裁剪
TConstant.RC_PICK_PICTURE_FROM_CAPTURE_CROP:
if (resultCode == Activity.RESULT_OK) {
if (takePhotoOptions != null && takePhotoOptions.isCorrectImage())
ImageRotateUtil.of().correctImage(contextWrap.getActivity(), tempUri);
try {
onCrop(tempUri, Uri.fromFile(new File(TUriParse.parseOwnUri(contextWrap.getActivity(), outPutUri))), cropOptions);
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri, fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
case //拍取照片
TConstant.RC_PICK_PICTURE_FROM_CAPTURE:
if (resultCode == Activity.RESULT_OK) {
if (takePhotoOptions != null && takePhotoOptions.isCorrectImage())
ImageRotateUtil.of().correctImage(contextWrap.getActivity(), outPutUri);
try {
takeResult(TResult.of(TImage.of(TUriParse.getFilePathWithUri(outPutUri, contextWrap.getActivity()), fromType)));
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri, fromType)), e.getDetailMessage());
e.printStackTrace();
}
} else {
listener.takeCancel();
}
break;
//裁剪照片返回结果
case TConstant.RC_CROP:
case //裁剪照片返回结果
Crop.REQUEST_CROP:
if (resultCode == Activity.RESULT_OK) {
if (multipleCrop != null) {
cropContinue(true);
} else {
try {
TImage image = TImage.of(TUriParse.getFilePathWithUri(outPutUri, contextWrap.getActivity()), fromType);
image.setCropped(true);
takeResult(TResult.of(image));
} catch (TException e) {
takeResult(TResult.of(TImage.of(outPutUri.getPath(), fromType)), e.getDetailMessage());
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
//裁剪的照片没有保存
if (multipleCrop != null) {
if (data != null) {
//获取裁剪的结果数据
Bitmap bitmap = data.getParcelableExtra("data");
//将裁剪的结果写入到文件
TImageFiles.writeToFile(bitmap, outPutUri);
cropContinue(true);
} else {
cropContinue(false);
}
} else {
if (data != null) {
//获取裁剪的结果数据
Bitmap bitmap = data.getParcelableExtra("data");
//将裁剪的结果写入到文件
TImageFiles.writeToFile(bitmap, outPutUri);
TImage image = TImage.of(outPutUri.getPath(), fromType);
image.setCropped(true);
takeResult(TResult.of(image));
} else {
listener.takeCancel();
}
}
} else {
if (multipleCrop != null) {
cropContinue(false);
} else {
listener.takeCancel();
}
}
break;
case //多选图片返回结果
TConstant.RC_PICK_MULTIPLE:
if (resultCode == Activity.RESULT_OK && data != null) {
ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
if (cropOptions != null) {
try {
onCrop(MultipleCrop.of(TUtils.convertImageToUri(contextWrap.getActivity(), images), contextWrap.getActivity(), fromType), cropOptions);
} catch (TException e) {
cropContinue(false);
e.printStackTrace();
}
} else {
takeResult(TResult.of(TUtils.getTImagesWithImages(images, fromType)));
}
} else {
listener.takeCancel();
}
break;
default:
break;
}
}
Aggregations