summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2012-03-20 16:37:05 +0800
committerYuli Huang <yuli@google.com>2012-03-21 17:29:09 +0800
commit54fe02fa80770e26d35c0e132ca23b81c99de945 (patch)
tree1fbac754ea5ae36e0ecd2d8741e283a42c75c4b3 /src/com/android/gallery3d/ui
parent706a7cf399bc0297a80802a311e843e517d32241 (diff)
downloadandroid_packages_apps_Snap-54fe02fa80770e26d35c0e132ca23b81c99de945.tar.gz
android_packages_apps_Snap-54fe02fa80770e26d35c0e132ca23b81c99de945.tar.bz2
android_packages_apps_Snap-54fe02fa80770e26d35c0e132ca23b81c99de945.zip
Fix incorrect initial position/scale of opening animations.
1. Initial position of opening animation isn't correctly offset if the position repository isn't properly offset by the action bar height. 2. Initial scale of opening animation should match the thumbnail instead of using a fixed value 240. This CL is part of efforts to fix b:6016973. Change-Id: I620705357ba7594d43685e47488928f9fc93d9f6
Diffstat (limited to 'src/com/android/gallery3d/ui')
-rw-r--r--src/com/android/gallery3d/ui/PhotoView.java30
-rw-r--r--src/com/android/gallery3d/ui/PositionController.java25
2 files changed, 27 insertions, 28 deletions
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index dee23bda0..3ec245f7d 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -19,14 +19,13 @@ package com.android.gallery3d.ui;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Message;
import android.view.MotionEvent;
import com.android.gallery3d.R;
import com.android.gallery3d.app.GalleryActivity;
-import com.android.gallery3d.data.Path;
-import com.android.gallery3d.ui.PositionRepository.Position;
public class PhotoView extends GLView {
@SuppressWarnings("unused")
@@ -91,11 +90,9 @@ public class PhotoView extends GLView {
private int mImageRotation;
- private Path mOpenedItemPath;
- private GalleryActivity mActivity;
+ private Rect mOpenAnimationRect;
public PhotoView(GalleryActivity activity) {
- mActivity = activity;
mTileView = new TileImageView(activity);
addComponent(mTileView);
Context context = activity.getAndroidContext();
@@ -120,7 +117,7 @@ public class PhotoView extends GLView {
case MSG_SHOW_LOADING: {
if (mLoadingState == LOADING_INIT) {
// We don't need the opening animation
- mOpenedItemPath = null;
+ mOpenAnimationRect = null;
mLoadingSpinner.startAnimation();
mLoadingState = LOADING_TIMEOUT;
@@ -233,7 +230,7 @@ public class PhotoView extends GLView {
mHandler.removeMessages(MSG_SHOW_LOADING);
mLoadingState = LOADING_FAIL;
// We don't want the opening animation after loading failure
- mOpenedItemPath = null;
+ mOpenAnimationRect = null;
} else if (mLoadingState != LOADING_INIT) {
mLoadingState = LOADING_INIT;
mHandler.removeMessages(MSG_SHOW_LOADING);
@@ -730,24 +727,19 @@ public class PhotoView extends GLView {
mTileView.prepareTextures();
}
- public void setOpenedItem(Path itemPath) {
- mOpenedItemPath = itemPath;
+ public void setOpenAnimationRect(Rect rect) {
+ mOpenAnimationRect = rect;
}
public void showVideoPlayIcon(boolean show) {
mShowVideoPlayIcon = show;
}
- // Returns the position saved by the previous page.
- public Position retrieveSavedPosition() {
- if (mOpenedItemPath != null) {
- Position position = PositionRepository
- .getInstance(mActivity).get(
- System.identityHashCode(mOpenedItemPath));
- mOpenedItemPath = null;
- return position;
- }
- return null;
+ // Returns the opening animation rectangle saved by the previous page.
+ public Rect retrieveOpenAnimationRect() {
+ Rect r = mOpenAnimationRect;
+ mOpenAnimationRect = null;
+ return r;
}
public void openAnimationStarted() {
diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java
index 1c9aba83c..09fbc1706 100644
--- a/src/com/android/gallery3d/ui/PositionController.java
+++ b/src/com/android/gallery3d/ui/PositionController.java
@@ -17,11 +17,12 @@
package com.android.gallery3d.ui;
import android.content.Context;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.util.FloatMath;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.ui.PositionRepository.Position;
+import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.util.GalleryUtils;
class PositionController {
@@ -140,14 +141,20 @@ class PositionController {
mScaleMin = getMinimalScale(mImageW, mImageH);
- // Start animation from the saved position if we have one.
- Position position = mViewer.retrieveSavedPosition();
- if (position != null) {
- // The animation starts from 240 pixels and centers at the image
- // at the saved position.
- float scale = 240f / Math.min(width, height);
- mCurrentX = Math.round((mViewW / 2f - position.x) / scale) + mImageW / 2;
- mCurrentY = Math.round((mViewH / 2f - position.y) / scale) + mImageH / 2;
+ // Start animation from the saved rectangle if we have one.
+ Rect r = mViewer.retrieveOpenAnimationRect();
+ if (r != null) {
+ // The animation starts from the specified rectangle; the image
+ // should be scaled and centered as the thumbnail shown in the
+ // rectangle to minimize janky opening animation. Note: The below
+ // implementation depends on how thumbnails are drawn and placed.
+ float size = MediaItem.getTargetSize(
+ MediaItem.TYPE_MICROTHUMBNAIL);
+ float scale = (size / Math.min(width, height)) * Math.min(
+ r.width() / size, r.height() / size);
+
+ mCurrentX = Math.round((mViewW / 2f - r.centerX()) / scale) + mImageW / 2;
+ mCurrentY = Math.round((mViewH / 2f - r.centerY()) / scale) + mImageH / 2;
mCurrentScale = scale;
mViewer.openAnimationStarted();
startSnapback();