Fix b/6064909: Photo might not be snapped back correctly.
Photo might not be snapped back if the animation wasn't actually started
because of no position/scale changes.
Change-Id: I6b5e938bffd954b848cae04514a06d0427151025
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index 9d2d459..349b1a9 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -388,7 +388,7 @@
mVideoPlayIcon.draw(canvas, x - s / 2, y - s / 2, s, s);
}
- if (mPositionController.advanceAnimation()) invalidate();
+ mPositionController.advanceAnimation();
}
private void stopCurrentSwipingIfNeeded() {
diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java
index 236c8aa..4baa2e0 100644
--- a/src/com/android/gallery3d/ui/PositionController.java
+++ b/src/com/android/gallery3d/ui/PositionController.java
@@ -400,8 +400,12 @@
private void startAnimation(
int targetX, int targetY, float scale, int kind) {
+ mAnimationKind = kind;
if (targetX == mCurrentX && targetY == mCurrentY
- && scale == mCurrentScale) return;
+ && scale == mCurrentScale) {
+ onAnimationComplete();
+ return;
+ }
mFromX = mCurrentX;
mFromY = mCurrentY;
@@ -420,25 +424,18 @@
}
mAnimationStartTime = SystemClock.uptimeMillis();
- mAnimationKind = kind;
if (mAnimationKind != ANIM_KIND_FLING) {
mAnimationDuration = ANIM_TIME[mAnimationKind];
}
- if (advanceAnimation()) mViewer.invalidate();
+ advanceAnimation();
}
- // Returns true if redraw is needed.
- public boolean advanceAnimation() {
+ public void advanceAnimation() {
if (mAnimationStartTime == NO_ANIMATION) {
- return false;
+ return;
} else if (mAnimationStartTime == LAST_ANIMATION) {
- mAnimationStartTime = NO_ANIMATION;
- if (mViewer.isInTransition()) {
- mViewer.notifyTransitionComplete();
- return false;
- } else {
- return startSnapbackIfNeeded();
- }
+ onAnimationComplete();
+ return;
}
long now = SystemClock.uptimeMillis();
@@ -478,7 +475,16 @@
}
}
mViewer.setPosition(mCurrentX, mCurrentY, mCurrentScale);
- return true;
+ mViewer.invalidate();
+ }
+
+ private void onAnimationComplete() {
+ mAnimationStartTime = NO_ANIMATION;
+ if (mViewer.isInTransition()) {
+ mViewer.notifyTransitionComplete();
+ } else {
+ if (startSnapbackIfNeeded()) mViewer.invalidate();
+ }
}
private void flingInterpolate(float progress) {
@@ -545,7 +551,7 @@
return startSnapback();
}
- public boolean startSnapback() {
+ private boolean startSnapback() {
boolean needAnimation = false;
float scale = mCurrentScale;