Search in sources :

Example 1 with TException

use of com.jph.takephoto.model.TException 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;
    }
}
Also used : TException(com.jph.takephoto.model.TException) Bitmap(android.graphics.Bitmap) TImage(com.jph.takephoto.model.TImage) TImage(com.jph.takephoto.model.TImage) CompressImage(com.jph.takephoto.compress.CompressImage) Image(com.darsh.multipleimageselect.models.Image) File(java.io.File)

Example 2 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TakePhotoImpl method onPickFromCaptureWithCrop.

@Override
public void onPickFromCaptureWithCrop(Uri outPutUri, CropOptions options) {
    this.fromType = TImage.FromType.CAMERA;
    if (PermissionManager.TPermissionType.WAIT.equals(permissionType))
        return;
    this.cropOptions = options;
    this.outPutUri = outPutUri;
    if (Build.VERSION.SDK_INT >= 23) {
        this.tempUri = TUriParse.getTempUri(contextWrap.getActivity());
    } else {
        this.tempUri = outPutUri;
    }
    try {
        TUtils.captureBySafely(contextWrap, new TIntentWap(IntentUtils.getCaptureIntent(this.tempUri), TConstant.RC_PICK_PICTURE_FROM_CAPTURE_CROP));
    } catch (TException e) {
        takeResult(TResult.of(TImage.of("", fromType)), e.getDetailMessage());
        e.printStackTrace();
    }
}
Also used : TException(com.jph.takephoto.model.TException) TIntentWap(com.jph.takephoto.model.TIntentWap)

Example 3 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TakePhotoImpl method selectPicture.

private void selectPicture(int defaultIndex, boolean isCrop) {
    this.fromType = TImage.FromType.OTHER;
    if (takePhotoOptions != null && takePhotoOptions.isWithOwnGallery()) {
        onPickMultiple(1);
        return;
    }
    if (PermissionManager.TPermissionType.WAIT.equals(permissionType))
        return;
    ArrayList<TIntentWap> intentWapList = new ArrayList<>();
    intentWapList.add(new TIntentWap(IntentUtils.getPickIntentWithDocuments(), isCrop ? TConstant.RC_PICK_PICTURE_FROM_DOCUMENTS_CROP : TConstant.RC_PICK_PICTURE_FROM_DOCUMENTS_ORIGINAL));
    intentWapList.add(new TIntentWap(IntentUtils.getPickIntentWithGallery(), isCrop ? TConstant.RC_PICK_PICTURE_FROM_GALLERY_CROP : TConstant.RC_PICK_PICTURE_FROM_GALLERY_ORIGINAL));
    try {
        TUtils.sendIntentBySafely(contextWrap, intentWapList, defaultIndex, isCrop);
    } catch (TException e) {
        takeResult(TResult.of(TImage.of("", fromType)), e.getDetailMessage());
        e.printStackTrace();
    }
}
Also used : TException(com.jph.takephoto.model.TException) ArrayList(java.util.ArrayList) TIntentWap(com.jph.takephoto.model.TIntentWap)

Example 4 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TImageFiles method getTempFile.

/**
     * 获取临时文件
     * @param context
     * @param photoUri
     * @return
     */
public static File getTempFile(Activity context, Uri photoUri) throws TException {
    String minType = getMimeType(context, photoUri);
    if (!checkMimeType(context, minType))
        throw new TException(TExceptionType.TYPE_NOT_IMAGE);
    File filesDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    if (!filesDir.exists())
        filesDir.mkdirs();
    File photoFile = new File(filesDir, UUID.randomUUID().toString() + "." + minType);
    return photoFile;
}
Also used : TException(com.jph.takephoto.model.TException) File(java.io.File)

Example 5 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TUriParse method getFilePathWithUri.

/**
     * 通过URI获取文件的路径
     * @param uri
     * @param activity
     * @return
     * Author JPH
     * Date 2016/6/6 0006 20:01
     */
public static String getFilePathWithUri(Uri uri, Activity activity) throws TException {
    if (uri == null) {
        Log.w(TAG, "uri is null,activity may have been recovered?");
        throw new TException(TExceptionType.TYPE_URI_NULL);
    }
    File picture = getFileWithUri(uri, activity);
    String picturePath = picture == null ? null : picture.getPath();
    if (TextUtils.isEmpty(picturePath))
        throw new TException(TExceptionType.TYPE_URI_PARSE_FAIL);
    if (!TImageFiles.checkMimeType(activity, TImageFiles.getMimeType(activity, uri)))
        throw new TException(TExceptionType.TYPE_NOT_IMAGE);
    return picturePath;
}
Also used : TException(com.jph.takephoto.model.TException) File(java.io.File)

Aggregations

TException (com.jph.takephoto.model.TException)7 TIntentWap (com.jph.takephoto.model.TIntentWap)3 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Bitmap (android.graphics.Bitmap)1 Image (com.darsh.multipleimageselect.models.Image)1 CompressImage (com.jph.takephoto.compress.CompressImage)1 TImage (com.jph.takephoto.model.TImage)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 List (java.util.List)1