android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

Support minimum crop dimensions

Open jdamcd opened this issue 10 years ago • 10 comments

jdamcd avatar Mar 16 '14 17:03 jdamcd

:+1:

pozuelog avatar Apr 29 '14 10:04 pozuelog

how

xiaoxxaoniao avatar Jul 08 '14 06:07 xiaoxxaoniao

where is it?

xiaoxxaoniao avatar Jul 08 '14 06:07 xiaoxxaoniao

Hi, Nice lib here. I cannot seem to find the support for minimum crop dimension. Has it been added yet?

tochie-daniels avatar Aug 14 '14 09:08 tochie-daniels

I guess no luck with this huh?

yusufsaber avatar Dec 04 '14 19:12 yusufsaber

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.

:)

yusufsaber avatar Dec 04 '14 21:12 yusufsaber

Thanks @yusufsaber :)

mustafasevgi avatar Mar 18 '15 17:03 mustafasevgi

You're welcome @mustafasevgi !

yusufsaber avatar Apr 01 '15 14:04 yusufsaber

:+1: any luck merging this?

procedurallygenerated avatar Feb 18 '16 10:02 procedurallygenerated

Thanks @yusufsaber .

But I want to ask for more friendly method, such as setMiniWidth(int w) or setMiniHeight(int h).

wisekingokok avatar Apr 06 '16 15:04 wisekingokok