Java Code Examples for com.yalantis.ucrop.UCrop#REQUEST_CROP

The following examples show how to use com.yalantis.ucrop.UCrop#REQUEST_CROP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CropUtils.java    From CropUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 注意,调用时data为null的判断
 *
 * @param context
 * @param cropHandler
 * @param requestCode
 * @param resultCode
 * @param data
 */
public static void handleResult(Activity context, CropHandler cropHandler, int requestCode, int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_SELECT_PICTURE) {//第一次,选择图片后返回
            final Uri selectedUri = data.getData();
            if (selectedUri != null) {
                startCropActivity(context, data.getData());
            } else {
                Toast.makeText(context, "Cannot retrieve selected image", Toast.LENGTH_SHORT).show();
            }
        } else if (requestCode == UCrop.REQUEST_CROP) {//第二次返回,图片已经剪切好

            Uri finalUri = UCrop.getOutput(data);
            cropHandler.handleCropResult(finalUri,config.tag);

        } else if (requestCode == REQUEST_CAMERA) {//第一次,拍照后返回,因为设置了MediaStore.EXTRA_OUTPUT,所以data为null,数据直接就在uri中
            startCropActivity(context, uri);
        }
    }
    if (resultCode == UCrop.RESULT_ERROR) {
        cropHandler.handleCropError(data);
    }

}
 
Example 2
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case UCrop.REQUEST_MULTI_CROP:
                // 裁剪数据
                List<CutInfo> list = UCrop.getMultipleOutput(data);
                data.putParcelableArrayListExtra(UCrop.Options.EXTRA_OUTPUT_URI_LIST,
                        (ArrayList<? extends Parcelable>) list);
                // 已选数量
                data.putParcelableArrayListExtra(PictureConfig.EXTRA_SELECT_LIST,
                        (ArrayList<? extends Parcelable>) selectData);
                setResult(RESULT_OK, data);
                finish();
                break;
            case UCrop.REQUEST_CROP:
                if (data != null) {
                    data.putParcelableArrayListExtra(PictureConfig.EXTRA_SELECT_LIST,
                            (ArrayList<? extends Parcelable>) selectData);
                    setResult(RESULT_OK, data);
                }
                finish();
                break;
        }
    } else if (resultCode == UCrop.RESULT_ERROR) {
        Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
        ToastUtils.s(getContext(), throwable.getMessage());
    }
}
 
Example 3
Source File: PicCrop.java    From PicCrop with Apache License 2.0 5 votes vote down vote up
/**
 * 注意,调用时data为null的判断
 *
 * @param context
 * @param cropHandler
 * @param requestCode
 * @param resultCode
 * @param data
 */
public static void onActivityResult( int requestCode, int resultCode, Intent data,Activity context, CropHandler cropHandler) {

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_SELECT_PICTURE) {//第一次,选择图片后返回
            final Uri selectedUri = data.getData();
            if (selectedUri != null) {
                startCropActivity(context, data.getData());
            } else {
                Toast.makeText(context, "Cannot retrieve selected image", Toast.LENGTH_SHORT).show();
            }
        } else if (requestCode == UCrop.REQUEST_CROP) {//第二次返回,图片已经剪切好

            Uri finalUri = UCrop.getOutput(data);
            cropHandler.handleCropResult(finalUri,config.tag);

        } else if (requestCode == REQUEST_CAMERA) {//第一次,拍照后返回,因为设置了MediaStore.EXTRA_OUTPUT,所以data为null,数据直接就在uri中
            startCropActivity(context, uri);
        }
    }
    if (resultCode == UCrop.RESULT_ERROR) {
        cropHandler.handleCropError(data);
    }

}
 
Example 4
Source File: PictureActivity.java    From AndroidSamples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == UCrop.RESULT_ERROR) {
        mCameraTv.setText(UCrop.getError(data) + "");
        return;
    }
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case RESULT_CODE_1:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    cropRawPhoto(mProviderUri);
                } else {
                    cropRawPhoto(mUri);
                }
                break;
            case RESULT_CODE_2:
                LogUtils.i("onActivityResult: " + data.getData());
                cropRawPhoto(data.getData());
                break;
            case UCrop.REQUEST_CROP:
                LogUtils.i("onActivityResult: " + UCrop.getOutput(data));
                mCameraTv.setText(UCrop.getOutput(data) + "");
                Glide.with(this)
                        .load(UCrop.getOutput(data))
                        .into(mCameraImg);
                break;
            default:
                break;
        }
    }
}
 
Example 5
Source File: MatisseDemoActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {

            List<Uri> mUris = Matisse.obtainResult(data);
            mStrings = Matisse.obtainPathResult(data);

//            try {
//                ExifInterface mExifInterface = new ExifInterface(mStrings.get(0));
//                Log.e(TAG, "onActivityResult: " + mExifInterface.getAttribute(ExifInterface.TAG_GPS_ALTITUDE));
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
            mMyAdapter.setData(mStrings);

            Tools.getPhotoInfo(mStrings.get(0));


//            Uri destinationUri = Uri.fromFile(new File(getCacheDir(), "test.jpg"));
//            UCrop.of(mUris.get(0), destinationUri)
//                    .withAspectRatio(16, 9)
//                    .withMaxResultSize(maxWidth, maxHeight)
//                    .start(this);
        }

        if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
            final Uri resultUri = UCrop.getOutput(data);
            Intent mIntent = new Intent(MatisseDemoActivity.this, PhotoProcessActivity.class);
            mIntent.putExtra("url", resultUri);
            startActivity(mIntent);
        } else if (resultCode == UCrop.RESULT_ERROR) {
            final Throwable cropError = UCrop.getError(data);
        }
    }
 
Example 6
Source File: FragmentEditImage.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        String path;
        if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
            final Uri resultUri = UCrop.getOutput(data);
            path = AttachFile.getFilePathFromUri(resultUri);

            serCropAndFilterImage(path);

        } else if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { // result for crop
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                path = result.getUri().getPath();
                serCropAndFilterImage(path);
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
//                Exception error = result.getError();
            }
        }

    }
 
Example 7
Source File: EditFamilyActivity.java    From Pigeon with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_SELECT_PICTURE) {
            final Uri selectedUri = data.getData();
            if (selectedUri != null) {
                startCropActivity(data.getData());
            } else {
                ToastUtils.showToast(EditFamilyActivity.this, "类型不匹配");
            }
        } else if (requestCode == UCrop.REQUEST_CROP) {
            handleCropResult(data);
        }
    }
    if (resultCode == UCrop.RESULT_ERROR) {
        handleCropError(data);
    }
}
 
Example 8
Source File: UpdateUserInfoActivity.java    From Pigeon with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_SELECT_PICTURE) {
            final Uri selectedUri = data.getData();
            if (selectedUri != null) {
                startCropActivity(data.getData());
            } else {
                ToastUtils.showToast(UpdateUserInfoActivity.this,"类型不匹配");
            }
        } else if (requestCode == UCrop.REQUEST_CROP) {
            handleCropResult(data);
        }
    }
    if (resultCode == UCrop.RESULT_ERROR) {
        handleCropError(data);
    }
}
 
Example 9
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case PictureConfig.PREVIEW_VIDEO_CODE:
                if (data != null) {
                    List<LocalMedia> list = data.getParcelableArrayListExtra(PictureConfig.EXTRA_SELECT_LIST);
                    if (list != null && list.size() > 0) {
                        onResult(list);
                    }
                }
                break;
            case UCrop.REQUEST_CROP:
                singleCropHandleResult(data);
                break;
            case UCrop.REQUEST_MULTI_CROP:
                multiCropHandleResult(data);
                break;
            case PictureConfig.REQUEST_CAMERA:
                dispatchHandleCamera(data);
                break;
            default:
                break;
        }
    } else if (resultCode == RESULT_CANCELED) {
        previewCallback(data);
    } else if (resultCode == UCrop.RESULT_ERROR) {
        if (data != null) {
            Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
            if (throwable != null) {
                ToastUtils.s(getContext(), throwable.getMessage());
            }
        }
    }
}
 
Example 10
Source File: PictureSelectorCameraEmptyActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case UCrop.REQUEST_CROP:
                singleCropHandleResult(data);
                break;
            case PictureConfig.REQUEST_CAMERA:
                dispatchHandleCamera(data);
                break;
            default:
                break;
        }
    } else if (resultCode == RESULT_CANCELED) {
        if (config != null && PictureSelectionConfig.listener != null) {
            PictureSelectionConfig.listener.onCancel();
        }
        closeActivity();
    } else if (resultCode == UCrop.RESULT_ERROR) {
        if (data == null) {
            return;
        }
        Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
        ToastUtils.s(getContext(), throwable.getMessage());
    }
}
 
Example 11
Source File: PhotoEditorActivity.java    From react-native-photo-editor with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        if (data != null) {
            final Uri resultUri = UCrop.getOutput(data);
            if (resultUri != null) {
                try {
                    selectedImagePath = resultUri.toString();
                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver() , resultUri);
                    photoEditImageView.setImageBitmap(bitmap);
                } catch (Exception ex) {
                    System.out.println("NO IMAGE DATA FOUND");
                }
            } else {
                System.out.println("NO IMAGE DATA FOUND");
            }
        } else {
            System.out.println("NO RESULT");
        }
    }
}
 
Example 12
Source File: PostImage.java    From Hify with MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==UCrop.REQUEST_CROP && resultCode==RESULT_OK){

        long old_id=imagesList.get(selectedIndex).getId();
        String old_name=imagesList.get(selectedIndex).getName();
        String old_path=imagesList.get(selectedIndex).getOg_path();

        imagesList.remove(selectedIndex);
        imagesList.add(selectedIndex,new Images(old_name,old_path,UCrop.getOutput(data).getPath(),old_id));
        adapter=new PagerPhotosAdapter(this,imagesList);
        pager.setAdapter(adapter);
        indicator.setViewPager(pager);
        adapter.notifyDataSetChanged();
        pager.setCurrentItem(selectedIndex,true);

    }else if(resultCode==UCrop.RESULT_ERROR){
        Throwable throwable=UCrop.getError(data);
        throwable.printStackTrace();
        Toasty.error(this, "Error cropping : "+throwable.getMessage(), Toasty.LENGTH_SHORT,true).show();
    }

}
 
Example 13
Source File: ImagePickerActivity.java    From Android-Image-Picker-and-Cropping with GNU General Public License v3.0 4 votes vote down vote up
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case REQUEST_IMAGE_CAPTURE:
            if (resultCode == RESULT_OK) {
                cropImage(getCacheImagePath(fileName));
            } else {
                setResultCancelled();
            }
            break;
        case REQUEST_GALLERY_IMAGE:
            if (resultCode == RESULT_OK) {
                Uri imageUri = data.getData();
                cropImage(imageUri);
            } else {
                setResultCancelled();
            }
            break;
        case UCrop.REQUEST_CROP:
            if (resultCode == RESULT_OK) {
                handleUCropResult(data);
            } else {
                setResultCancelled();
            }
            break;
        case UCrop.RESULT_ERROR:
            final Throwable cropError = UCrop.getError(data);
            Log.e(TAG, "Crop error: " + cropError);
            setResultCancelled();
            break;
        default:
            setResultCancelled();
    }
}
 
Example 14
Source File: PhotoActivity.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == UCrop.REQUEST_CROP) {
            handleCropResult(data);
        }
    } else if (resultCode == UCrop.RESULT_ERROR) {
        handleCropError(data);
    }
}
 
Example 15
Source File: PreviewActivity.java    From sandriosCamera with MIT License 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        showImagePreview();
    }
}
 
Example 16
Source File: RegisterActivity.java    From Hify with MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==PICK_IMAGE){
        if(resultCode==RESULT_OK){
            imageUri=data.getData();
            // start crop activity
            UCrop.Options options = new UCrop.Options();
            options.setCompressionFormat(Bitmap.CompressFormat.PNG);
            options.setCompressionQuality(100);
            options.setShowCropGrid(true);

            UCrop.of(imageUri, Uri.fromFile(new File(getCacheDir(), "hify_user_profile_picture.png")))
                    .withAspectRatio(1, 1)
                    .withOptions(options)
                    .start(this);

        }
    }
    if (requestCode == UCrop.REQUEST_CROP) {
        if (resultCode == RESULT_OK) {
            imageUri = UCrop.getOutput(data);
            profile_image.setImageURI(imageUri);

        } else if (resultCode == UCrop.RESULT_ERROR) {
            Log.e("Error", "Crop error:" + UCrop.getError(data).getMessage());
        }
    }


}
 
Example 17
Source File: ProfileFragment.java    From Hify with MIT License 4 votes vote down vote up
@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if(requestCode==PICK_IMAGE){
          if(resultCode==RESULT_OK){
              imageUri=data.getData();
              // start crop activity
              UCrop.Options options = new UCrop.Options();
              options.setCompressionFormat(Bitmap.CompressFormat.PNG);
              options.setCompressionQuality(100);
              options.setShowCropGrid(true);

              UCrop.of(imageUri, Uri.fromFile(new File(rootView.getContext().getCacheDir(), "hify_user_profile_picture.png")))
                      .withAspectRatio(1, 1)
                      .withOptions(options)
                      .start(getActivity());

          }
      }
      if (requestCode == UCrop.REQUEST_CROP) {
          if (resultCode == RESULT_OK) {
              try {
                  File compressedFile= new Compressor(rootView.getContext()).setCompressFormat(Bitmap.CompressFormat.PNG).setQuality(70).setMaxHeight(96).setMaxWidth(96).compressToFile(new File(UCrop.getOutput(data).getPath()));
                  profile_pic.setImageURI(Uri.fromFile(compressedFile));
imageUri=Uri.fromFile(compressedFile);
                  Toasty.info(rootView.getContext(), "Profile picture uploaded, click Save details button to apply changes", Toasty.LENGTH_LONG,true).show();
              } catch (IOException e) {
                  e.printStackTrace();
                  Toasty.info(rootView.getContext(), "Profile photo updated click Save details to apply but unable to compress: "+e.getLocalizedMessage(), Toasty.LENGTH_SHORT,true).show();
                  profile_pic.setImageURI(imageUri);
                  imageUri = UCrop.getOutput(data);
              }
          } else if (resultCode == UCrop.RESULT_ERROR) {
              Log.e("Error", "Crop error:" + UCrop.getError(data).getMessage());
          }
      }

  }
 
Example 18
Source File: SingleMediaActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data != null && resultCode == RESULT_OK) {
        switch (requestCode) {
            case UCrop.REQUEST_CROP:
                final Uri imageUri = UCrop.getOutput(data);
                if (imageUri != null && imageUri.getScheme().equals("file")) {
                    try {
                        //copyFileToDownloads(imageUri);
                        // TODO: 21/08/16 handle this better
                        if (StorageHelper.copyFile(getApplicationContext(), new File(imageUri.getPath()), new File(this.album.getPath()))) {
                            //((ImageFragment) adapter.getRegisteredFragment(this.album.getCurrentMediaIndex())).displayMedia(true);
                            Toast.makeText(this, R.string.new_file_created, Toast.LENGTH_SHORT).show();
                        }
                        //adapter.notifyDataSetChanged();
                    } catch (Exception e) {
                        Log.e("ERROS - uCrop", imageUri.toString(), e);
                    }
                } else
                    StringUtils.showToast(getApplicationContext(), "errori random");
                break;
            default:
                super.onActivityResult(requestCode, resultCode, data);
                break;
        }
    }
}