本文整理汇总了Java中com.theartofdev.edmodo.cropper.CropImage类的典型用法代码示例。如果您正苦于以下问题:Java CropImage类的具体用法?Java CropImage怎么用?Java CropImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CropImage类属于com.theartofdev.edmodo.cropper包,在下文中一共展示了CropImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);
// For API >= 23 we need to check specifically that we have permissions to read external storage,
// but we don't know if we need to for the URI so the simplest is to try open the stream and see if we get error.
boolean requirePermissions = false;
if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
// request permissions and handle the result in onRequestPermissionsResult()
requirePermissions = true;
mCropImageUri = imageUri;
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
} else {
mCurrentFragment.setImageUri(imageUri);
}
}
}
示例2: showChooserDialog
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
public static void showChooserDialog(final BaseActivity activity, final Callback callback) {
PhotoHelper.callback = callback;
Nammu.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionCallback() {
@Override
public void permissionGranted() {
Intent intent = CropImage.getPickImageChooserIntent(activity);
activity.startActivityForResult(intent, CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE);
}
@Override
public void permissionRefused() {
callOnFailure(Failure.PERMISSION_DENIED);
}
});
}
示例3: handleCropResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
private void handleCropResult(CropImageView.CropResult result) {
if (result.getError() == null) {
Intent intent = new Intent(getActivity(), CropResultActivity.class);
intent.putExtra("SAMPLE_SIZE", result.getSampleSize());
if (result.getUri() != null) {
intent.putExtra("URI", result.getUri());
} else {
CropResultActivity.mImage = mCropImageView.getCropShape() == CropImageView.CropShape.OVAL
? CropImage.toOvalBitmap(result.getBitmap())
: result.getBitmap();
}
startActivity(intent);
} else {
Log.e("AIC", "Failed to crop image", result.getError());
Toast.makeText(getActivity(), "Image crop failed: " + result.getError().getMessage(), Toast.LENGTH_LONG).show();
}
}
示例4: onRequestPermissionsResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == CropImage.CAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
CropImage.startPickImageActivity(this);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
if (requestCode == CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE) {
if (mCropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mCurrentFragment.setImageUri(mCropImageUri);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
}
示例5: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_REQUEST_CODE && resultCode == RESULT_OK){
Uri imageUri = data.getData();
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1,1)
.start(this);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
mImageUri = result.getUri();
mProfilePicture.setImageURI(mImageUri);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Toast.makeText(CreateProfileActivity.this, "Failed to get profile picture, Try Again.", Toast.LENGTH_LONG).show();
}
}
}
示例6: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_REQUEST_CODE && resultCode == RESULT_OK){
Uri ImageUri = data.getData();
CropImage.activity(ImageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1,1)
.start(this);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
imageUri = result.getUri();
getProfilePicture.setImageURI(imageUri);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Toast.makeText(ViewEditProfileActivity.this, "Failed to get profile picture, please try again.", Toast.LENGTH_LONG).show();
}
}
}
示例7: startCropImageActivity
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
public static void startCropImageActivity(Activity activity, CropImageView.CropShape cropShape, boolean isAvatar) {
if (isAvatar) {
CropImage.activity()
.setMinCropResultSize(300, 300)
.setMaxCropResultSize(1280, 1280)
.setCropMenuCropButtonIcon(R.drawable.ic_content_white_cut_24dp)
.setCropShape(cropShape)
.start(activity);
} else {
CropImage.activity()
.setMinCropResultSize(1280, 720)
.setMaxCropResultSize(3840, 2160)
.setCropMenuCropButtonIcon(R.drawable.ic_content_white_cut_24dp)
.setCropShape(cropShape)
.start(activity);
}
}
示例8: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE:
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
File file = FunctionHelper.createFileFromUri(this, resultUri);
if (file == null) return;
if (view_ShowMenu == img_avatar) {
changeImage(img_avatar, file.getAbsolutePath());
} else if (view_ShowMenu == img_background) {
changeImage(img_background, file.getAbsolutePath());
}
view_ShowMenu = null;
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
@SuppressWarnings("ThrowableNotThrown") Exception error = result.getError();
Log.d(TAG, error.toString());
}
break;
}
}
示例9: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
addImageLabel.setVisibility(View.GONE);
CropImage.ActivityResult result = CropImage.getActivityResult(data);
Uri resultUri = result.getUri();
imageURi = resultUri;
if (resultUri != null) {
feedImage.setImageURI(resultUri);
}
}
}
}
示例10: onRequestPermissionsResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == CropImage.CAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
CropImage.startPickImageActivity(this);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
if (requestCode == CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE) {
if (cropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// required permissions granted, start crop image activity
startCropImageActivity(cropImageUri);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
}
示例11: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case GALLERY_CODE:
if (data != null) {
Uri uri = data.getData();
cropImage(uri);
}
break;
case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE:
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Uri picUri = result.getUri();
saveBImage(picUri);
demoIv.setImageURI(picUri);
//demoIv.setBackgroundColor(Color.TRANSPARENT);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
break;
}
}
示例12: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// handle result of pick image chooser
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);
if (isImageFileValid(imageUri)) {
this.imageUri = imageUri;
}
// For API >= 23 we need to check specifically that we have permissions to read external storage.
if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
// request permissions and handle the result in onRequestPermissionsResult()
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
} else {
// no permissions required or already grunted
onImagePikedAction();
}
}
}
示例13: onRequestPermissionsResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == CropImage.CAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
LogUtil.logDebug(TAG, "CAMERA_CAPTURE_PERMISSIONS granted");
CropImage.startPickImageActivity(this);
} else {
showSnackBar(R.string.permissions_not_granted);
LogUtil.logDebug(TAG, "CAMERA_CAPTURE_PERMISSIONS not granted");
}
}
if (requestCode == CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE) {
if (imageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// required permissions granted, start crop image activity
LogUtil.logDebug(TAG, "PICK_IMAGE_PERMISSIONS granted");
// if (isImageFileValid(imageUri)) {
onImagePikedAction();
// }
} else {
showSnackBar(R.string.permissions_not_granted);
LogUtil.logDebug(TAG, "PICK_IMAGE_PERMISSIONS not granted");
}
}
}
示例14: handleCropImageResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
protected void handleCropImageResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
if (ValidationUtil.checkImageMinSize(result.getCropRect())) {
imageUri = result.getUri();
loadImageToImageView();
} else {
showSnackBar(R.string.error_smaller_image);
}
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
LogUtil.logError(TAG, "crop image error", result.getError());
showSnackBar(R.string.error_fail_crop_image);
}
}
}
示例15: onActivityResult
import com.theartofdev.edmodo.cropper.CropImage; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE: {
if (resultCode == RESULT_OK) {
CropImage.activity(data.getData())
.setActivityTitle(getString(R.string.crop))
.setAspectRatio(1, 1)
.setFixAspectRatio(true)
.start(this);
}
break;
}
case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE: {
if (resultCode == RESULT_OK) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
returnUri(result.getUri());
}
break;
}
}
}