Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.
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
Expand Up @@ -6,11 +6,11 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import android.widget.ImageView;
import android.widget.Toast;

import com.soundcloud.android.crop.Crop;
import com.soundcloud.android.crop.CropImageActivity;

import java.io.File;

Expand Down Expand Up @@ -52,7 +52,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)

private void beginCrop(Uri source) {
Uri outputUri = Uri.fromFile(new File(getCacheDir(), "cropped"));
new Crop(source).output(outputUri).asSquare().start(this);
Crop crop = new Crop(source);
crop.output(outputUri);
crop.widthMinSize(640);
crop.asSquare().start(this);
}

private void handleCrop(int resultCode, Intent result) {
Expand Down
12 changes: 12 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 @@ -26,6 +26,7 @@ static interface Extra {
String MAX_X = "max_x";
String MAX_Y = "max_y";
String ERROR = "error";
String MIN_X = "minimum_x";
}

private Intent cropIntent;
Expand Down Expand Up @@ -83,6 +84,17 @@ public Crop withMaxSize(int width, int height) {
return this;
}

/**
* Set minimum crop size
*
* @param width
* @return
*/
public Crop widthMinSize(int width) {
cropIntent.putExtra(Extra.MIN_X, width);
return this;
}

/**
* Send the crop Intent!
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class CropImageActivity extends MonitoredActivity {
// Output image
private int maxX;
private int maxY;
private int minX;
private int exifRotation;

private Uri sourceUri;
Expand All @@ -80,6 +81,15 @@ public void onCreate(Bundle icicle) {
finish();
return;
}
if (rotateBitmap.getWidth() < minX) {
try {
throw new Exception("Image size is small than your minimum size.");
} catch (Exception e) {
setResultException(e);
}
finish();
return;
}
startCrop();
}

Expand Down Expand Up @@ -117,6 +127,7 @@ private void setupFromIntent() {
aspectY = extras.getInt(Crop.Extra.ASPECT_Y);
maxX = extras.getInt(Crop.Extra.MAX_X);
maxY = extras.getInt(Crop.Extra.MAX_Y);
minX = extras.getInt(Crop.Extra.MIN_X, 25);
saveUri = extras.getParcelable(MediaStore.EXTRA_OUTPUT);
}

Expand Down Expand Up @@ -232,11 +243,32 @@ private void makeDefault() {
}
}

if (cropWidth < minX || cropHeight < minX) {
cropWidth = cropHeight = minX;

if (aspectX != 0 && aspectY != 0) {
if (aspectX > aspectY) {
cropHeight = cropWidth * aspectY / aspectX;
} else {
cropWidth = cropHeight * aspectX / aspectY;
}
}

if (cropHeight > height || cropWidth > width) {
try {
throw new Exception("Image size is small than your minimum size.");
} catch (Exception e) {
setResultException(e);
}
finish();
}
}

int x = (width - cropWidth) / 2;
int y = (height - cropHeight) / 2;

RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);
hv.setup(imageView.getUnrotatedMatrix(), imageRect, cropRect, aspectX != 0 && aspectY != 0);
hv.setup(imageView.getUnrotatedMatrix(), imageRect, cropRect, aspectX != 0 && aspectY != 0, minX);
imageView.add(hv);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum HandleMode { Changing, Always, Never }
private float handleRadius;
private float outlineWidth;
private boolean isFocused;
private int minX = 25;

public HighlightView(View context) {
viewContext = context;
Expand Down Expand Up @@ -118,6 +119,11 @@ public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean maintainAspe
modifyMode = ModifyMode.None;
}

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean maintainAspectRatio,int minX){
this.minX = minX;
setup(m, imageRect, cropRect, maintainAspectRatio);
}

private float dpToPx(float dp) {
return dp * viewContext.getResources().getDisplayMetrics().density;
}
Expand Down Expand Up @@ -326,7 +332,7 @@ void growBy(float dx, float dy) {
r.inset(-dx, -dy);

// Don't let the cropping rectangle shrink too fast
final float widthCap = 25F;
final float widthCap = minX;
if (r.width() < widthCap) {
r.inset(-(widthCap - r.width()) / 2F, 0F);
}
Expand Down