Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Return Crop Coordinates (cropX,cropY,cropWidth,cropHeight) in Intent. #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.soundcloud.android.crop.example;

import com.soundcloud.android.crop.Crop;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
Expand All @@ -11,6 +9,8 @@
import android.widget.ImageView;
import android.widget.Toast;

import com.soundcloud.android.crop.Crop;

import java.io.File;

public class MainActivity extends Activity {
Expand Down Expand Up @@ -57,6 +57,12 @@ private void beginCrop(Uri source) {
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
resultView.setImageURI(Crop.getOutput(result));

int x = result.getExtras().getInt(Crop.KEY_CROP_X);
int y = result.getExtras().getInt(Crop.KEY_CROP_Y);
int w = result.getExtras().getInt(Crop.KEY_CROP_WIDTH);
int h = result.getExtras().getInt(Crop.KEY_CROP_HEIGHT);
Toast.makeText(this,x + "," + y + "," + w + "," + h,Toast.LENGTH_LONG).show();
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/main/java/com/soundcloud/android/crop/Crop.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class Crop {
public static final int REQUEST_PICK = 9162;
public static final int RESULT_ERROR = 404;

public static final String KEY_CROP_X = "CropX";
public static final String KEY_CROP_Y = "CropY";
public static final String KEY_CROP_WIDTH = "CropWidth";
public static final String KEY_CROP_HEIGHT = "CropHeight";

interface Extra {
String ASPECT_X = "aspect_x";
String ASPECT_Y = "aspect_y";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class CropImageActivity extends MonitoredActivity {
private CropImageView imageView;
private HighlightView cropView;

private Rect croppingRect;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Expand Down Expand Up @@ -301,6 +303,8 @@ private void onSaveClicked() {
imageView.center();
imageView.highlightViews.clear();
}

croppingRect = r;
saveImage(croppedImage);
}

Expand Down Expand Up @@ -431,7 +435,16 @@ public boolean isSaving() {
}

private void setResultUri(Uri uri) {
setResult(RESULT_OK, new Intent().putExtra(MediaStore.EXTRA_OUTPUT, uri));
Intent intent = new Intent();
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
if(croppingRect!=null) {
intent.putExtra(Crop.KEY_CROP_X, croppingRect.left);
intent.putExtra(Crop.KEY_CROP_Y, croppingRect.top);
intent.putExtra(Crop.KEY_CROP_WIDTH, croppingRect.width());
intent.putExtra(Crop.KEY_CROP_HEIGHT, croppingRect.height());
}

setResult(RESULT_OK,intent);
}

private void setResultException(Throwable throwable) {
Expand Down