PhotoView icon indicating copy to clipboard operation
PhotoView copied to clipboard

Is there is any way to disable medium scale

Open goeltarun opened this issue 9 years ago • 8 comments

Hi, In my application I only want two level of zoom, is there is any interface to do the same. Passing the same value in setScaleLevels for min and medium gives error.

goeltarun avatar Oct 27 '16 16:10 goeltarun

I have checked the source, found no way,unless you change the code.

kuafoo avatar Nov 09 '16 16:11 kuafoo

Did anyone make a patch?

CapnSpellcheck avatar Nov 17 '16 20:11 CapnSpellcheck

I put a patch on gist

CapnSpellcheck avatar Nov 17 '16 21:11 CapnSpellcheck

Ah by the way it needs an explanation: to disable medium zoom just call photoView.setMediumScale(-999) in onCreate or onCreateView etc.

CapnSpellcheck avatar Nov 17 '16 21:11 CapnSpellcheck

@CapnSpellcheck That will produce an IllegalArgumentException, cause PhotoViewAttacher checks the new scale when you set it. (v 1.3.1)

PhotoViewAttacher.java

    private static void checkZoomLevels(float minZoom, float midZoom,
                                        float maxZoom) {
        if (minZoom >= midZoom) {
            throw new IllegalArgumentException(
                    "Minimum zoom has to be less than Medium zoom. Call setMinimumZoom() with a more appropriate value");
        } else if (midZoom >= maxZoom) {
            throw new IllegalArgumentException(
                    "Medium zoom has to be less than Maximum zoom. Call setMaximumZoom() with a more appropriate value");
        }
    }

BeQuietLee avatar Apr 19 '17 07:04 BeQuietLee

That's why the patch includes PhotoViewAttacher ;-)

In any case, my patch is a suggestion, and works for me, I wanted a solution quickly. Anyone who wants to move this toward a PR, might want to formalize a bit more.

CapnSpellcheck avatar Apr 21 '17 07:04 CapnSpellcheck

try this

    photoViewAttacher.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return false;
        }
        boolean isMaximum = false;
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (!isMaximum) {
                photoViewAttacher.setScale(photoViewAttacher.getMaximumScale());
                isMaximum = true;
            } else {
                photoViewAttacher.setScale(photoViewAttacher.getMinimumScale());
                isMaximum = false;
            }
            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }
    });

Mrey3000 avatar Mar 26 '19 23:03 Mrey3000

if you double tap, medium scale is working. so, you can limit medium scale to its minimum scale. so the solution is :

// to avoid this exception  "Minimum zoom has to be less than Medium zoom. Call setMinimumZoom() with a more appropriate value");
photoView.setMediumScale (mPhotoView.getMinimumScale()+ 0.0001f)
photoView.minimumScale = mPhotoView.getMinimumScale()

wiztensai avatar Feb 16 '20 19:02 wiztensai