Skip to content

Instantly share code, notes, and snippets.

@vibin
Created August 18, 2017 07:03
Show Gist options
  • Save vibin/fcf54c5e7ab63b9184432cc44c9a1494 to your computer and use it in GitHub Desktop.
Save vibin/fcf54c5e7ab63b9184432cc44c9a1494 to your computer and use it in GitHub Desktop.
regCoverPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Crop.pickImage(getActivity(), EditProfileDialog.this, REQUEST_CODE_PICK_COVER);
}
});
regUserProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Crop.pickImage(getActivity(), EditProfileDialog.this, REQUEST_CODE_PICK_PROFILE);
}
});
//Handling the result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_PROFILE && resultCode == Activity.RESULT_OK) {
beginCropProfile(data.getData());
}else if(requestCode == REQUEST_CODE_PICK_COVER && resultCode == Activity.RESULT_OK){
beginCropCover(data.getData());
} else if(requestCode == REQUEST_CODE_CROP_PROFILE || requestCode == REQUEST_CODE_CROP_COVER){
handleCrop(requestCode, resultCode, data);
}
}
private void beginCropProfile(Uri source) {
Uri destination = Uri.fromFile(new File(getActivity().getCacheDir(), "cropped"));
Crop.of(source, destination).withAspect(ASPECT_X, ASPECT_Y).start(getActivity(), EditProfileDialog.this, REQUEST_CODE_CROP_PROFILE);
}
private void beginCropCover(Uri source) {
Uri destination = Uri.fromFile(new File(getActivity().getCacheDir(), "cropped"));
Crop.of(source, destination).asSquare().start(getActivity(), EditProfileDialog.this, REQUEST_CODE_CROP_COVER);
}
private void handleCrop(int requestCode, int resultCode, Intent result) {
if (requestCode == REQUEST_CODE_CROP_COVER && resultCode == Activity.RESULT_OK) {
regCoverPhoto.setImageURI(Crop.getOutput(result));
mCoverPhotoUri = Crop.getOutput(result);
uploadCoverToStorage();
Log.d(TAG,"ResultCover: " + Crop.getOutput(result).toString());
} else if(requestCode == REQUEST_CODE_CROP_PROFILE && resultCode == Activity.RESULT_OK){
regUserProfile.setImageURI(Crop.getOutput(result));
mProfilePhotoUri = Crop.getOutput(result);
uploadProfileToStorage();
Log.d(TAG,"ResultProfile: " + Crop.getOutput(result).toString());
} else if (resultCode == Crop.RESULT_ERROR) {
Snackbar.make(getView(), Crop.getError(result).getMessage(), Snackbar.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment