Fixed image stuck after zoom end between max and min

This commit is contained in:
DrKLO 2014-06-11 03:33:45 +04:00
parent 0c49c20656
commit 512aeaf2bb
2 changed files with 31 additions and 18 deletions

View file

@ -81,7 +81,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 243 versionCode 244
versionName "1.4.15" versionName "1.4.15"
} }
} }

View file

@ -142,6 +142,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private boolean doubleTap = false; private boolean doubleTap = false;
private boolean invalidCoords = false; private boolean invalidCoords = false;
private boolean canDragDown = true; private boolean canDragDown = true;
private boolean zoomAnimation = false;
private int switchImageAfterAnimation = 0; private int switchImageAfterAnimation = 0;
private VelocityTracker velocityTracker = null; private VelocityTracker velocityTracker = null;
@ -1409,20 +1410,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
doubleTap = false; doubleTap = false;
moving = false; moving = false;
zooming = false; zooming = false;
float moveToX = translationX; checkMinMax(false);
float moveToY = translationY;
updateMinMax(scale);
if (translationX < minX) {
moveToX = minX;
} else if (translationX > maxX) {
moveToX = maxX;
}
if (translationY < minY) {
moveToY = minY;
} else if (translationY > maxY) {
moveToY = maxY;
}
animateTo(scale, moveToX, moveToY);
return true; return true;
} }
@ -1515,7 +1503,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
invalidCoords = true; invalidCoords = true;
if (scale < 1.0f) { if (scale < 1.0f) {
updateMinMax(1.0f); updateMinMax(1.0f);
animateTo(1.0f, 0, 0); animateTo(1.0f, 0, 0, true);
} else if(scale > 3.0f) { } else if(scale > 3.0f) {
float atx = (pinchCenterX - containerView.getWidth() / 2) - ((pinchCenterX - containerView.getWidth() / 2) - pinchStartX) * (3.0f / pinchStartScale); float atx = (pinchCenterX - containerView.getWidth() / 2) - ((pinchCenterX - containerView.getWidth() / 2) - pinchStartX) * (3.0f / pinchStartScale);
float aty = (pinchCenterY - containerView.getHeight() / 2) - ((pinchCenterY - containerView.getHeight() / 2) - pinchStartY) * (3.0f / pinchStartScale); float aty = (pinchCenterY - containerView.getHeight() / 2) - ((pinchCenterY - containerView.getHeight() / 2) - pinchStartY) * (3.0f / pinchStartScale);
@ -1530,7 +1518,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else if (aty > maxY) { } else if (aty > maxY) {
aty = maxY; aty = maxY;
} }
animateTo(3.0f, atx, aty); animateTo(3.0f, atx, aty, true);
} else {
checkMinMax(true);
} }
zooming = false; zooming = false;
} else if (draggingDown) { } else if (draggingDown) {
@ -1579,6 +1569,23 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return false; return false;
} }
private void checkMinMax(boolean zoom) {
float moveToX = translationX;
float moveToY = translationY;
updateMinMax(scale);
if (translationX < minX) {
moveToX = minX;
} else if (translationX > maxX) {
moveToX = maxX;
}
if (translationY < minY) {
moveToY = minY;
} else if (translationY > maxY) {
moveToY = maxY;
}
animateTo(scale, moveToX, moveToY, zoom);
}
private void goToNext() { private void goToNext() {
float extra = 0; float extra = 0;
if (scale != 1) { if (scale != 1) {
@ -1598,6 +1605,10 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} }
private void animateTo(float newScale, float newTx, float newTy) { private void animateTo(float newScale, float newTx, float newTy) {
animateTo(newScale, newTx, newTy, false);
}
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom) {
if (switchImageAfterAnimation == 0) { if (switchImageAfterAnimation == 0) {
toggleOverlayView(true); toggleOverlayView(true);
} }
@ -1605,6 +1616,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
Utilities.unlockOrientation(parentActivity); Utilities.unlockOrientation(parentActivity);
return; return;
} }
zoomAnimation = isZoom;
animateToScale = newScale; animateToScale = newScale;
animateToX = newTx; animateToX = newTx;
animateToY = newTy; animateToY = newTy;
@ -1655,6 +1667,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
animationStartTime = 0; animationStartTime = 0;
updateMinMax(scale); updateMinMax(scale);
Utilities.unlockOrientation(parentActivity); Utilities.unlockOrientation(parentActivity);
zoomAnimation = false;
} }
if (switchImageAfterAnimation != 0) { if (switchImageAfterAnimation != 0) {
if (switchImageAfterAnimation == 1) { if (switchImageAfterAnimation == 1) {
@ -1710,7 +1723,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
sideImage = rightImage; sideImage = rightImage;
} }
if (sideImage != null) { if (!zoomAnimation && !zooming && sideImage != null) {
changingPage = true; changingPage = true;
canvas.translate(k * containerView.getWidth() / 2, -currentTranslationY); canvas.translate(k * containerView.getWidth() / 2, -currentTranslationY);
canvas.scale(1.0f / scale, 1.0f / scale); canvas.scale(1.0f / scale, 1.0f / scale);