Is there is any way to disable medium scale
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.
I have checked the source, found no way,unless you change the code.
Did anyone make a patch?
I put a patch on gist
Ah by the way it needs an explanation: to disable medium zoom just call
photoView.setMediumScale(-999)
in onCreate or onCreateView etc.
@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");
}
}
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.
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;
}
});
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()