android-crop
android-crop copied to clipboard
Support minimum crop dimensions
:+1:
how
where is it?
Hi, Nice lib here. I cannot seem to find the support for minimum crop dimension. Has it been added yet?
I guess no luck with this huh?
I've found the solution for this, perhaps @jdamcd could integrate it into the library?
Basically in CropImageView, I modified onTouchEvent to look like this:
@Override
public boolean onTouchEvent(MotionEvent event) {
CropImageActivity cropImageActivity = (CropImageActivity) context;
if (cropImageActivity.isSaving()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
for (HighlightView hv : highlightViews) {
int edge = hv.getHit(event.getX(), event.getY());
motionEdge = edge;
motionHighlightView = hv;
lastX = event.getX();
lastY = event.getY();
motionHighlightView.setMode((edge == HighlightView.MOVE)
? HighlightView.ModifyMode.Move
: HighlightView.ModifyMode.Grow);
break;
}
break;
case MotionEvent.ACTION_UP:
if(motionHighlightView.cropRect.height() < 61) {
motionHighlightView.cropRect.inset(-10, -10);
}
if (motionHighlightView != null) {
centerBasedOnHighlightView(motionHighlightView);
motionHighlightView.setMode(HighlightView.ModifyMode.None);
}
motionHighlightView = null;
break;
case MotionEvent.ACTION_MOVE:
if(motionHighlightView.cropRect.height() < 60) {
break;
}
motionHighlightView.handleMotion(motionEdge, event.getX() - lastX, event.getY() - lastY);
lastX = event.getX();
lastY = event.getY();
ensureVisible(motionHighlightView);
break;
}
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
center(true, true);
break;
case MotionEvent.ACTION_MOVE:
// if we're not zoomed then there's no point in even allowing
// the user to move the image around. This call to center puts
// it back to the normalized location (with false meaning don't
// animate).
if (getScale() == 1F) {
center(true, true);
}
break;
}
return true;
}
The key is in ACTION_MOVE, I do the follow:
if(motionHighlightView.cropRect.height() < 60) { break; }
which stops the movement when the crop rect is < 60 (my desired min height).
I then reset the value in ACTION_UP as follows:
if(motionHighlightView.cropRect.height() < 61) { motionHighlightView.cropRect.inset(-10, -10); }
This creates a nice "bounce back" effect when the user goes beyond the minimum crop size.
:)
Thanks @yusufsaber :)
You're welcome @mustafasevgi !
:+1: any luck merging this?
Thanks @yusufsaber .
But I want to ask for more friendly method, such as setMiniWidth(int w) or setMiniHeight(int h).