jayrambhia / CropperNoCropper

Instagram Style Image Cropper for Android (Library)
http://www.jayrambhia.com/project/nocropper-library
Apache License 2.0
475 stars 99 forks source link

Image was not panning while when triggering min zoom #16

Closed palmithor closed 7 years ago

palmithor commented 7 years ago

This pull requests fixes the issue: https://github.com/jayrambhia/CropperNoCropper/issues/10

jayrambhia commented 7 years ago

Thanks for the contribution. But there are so many changes (due to auto formatting and other stuff), I can't find what's the change that made it work. Can you explain what changes did you make to fix the issue?

palmithor commented 7 years ago

in onUP in CropperImageView I changed one if condition. From:

if (scaleX <= mMinZoom) 
// to:
if (scaleX < mMinZoom)

Otherwise the image was not panning correctly with min zoom when zooming far out.

I also added this to the end of fitToCenter() in the same class:

// If over scrolled, return back to the place.
        float tx = getMatrixValue(matrix, Matrix.MTRANS_X);
        float ty = getMatrixValue(matrix, Matrix.MTRANS_Y);
        float scaleX = getMatrixValue(matrix, Matrix.MSCALE_X);
        if (scaleX < mMinZoom) {
            float xx = getWidth() / 2 - mMinZoom * drawable.getIntrinsicWidth() / 2;
            float yy = getHeight() / 2 - mMinZoom * drawable.getIntrinsicHeight() / 2;
            animateAdjustmentWithScale(tx, xx, ty, yy, scaleX, mMinZoom);
        }

The reason I added this is that I think that if the user has preset a min zoom, the view should not allow setting the zoom level lover than that which can happen on fitToCenter. So I animated it to minZoom.

jayrambhia commented 7 years ago

Added code.