diff options
author | Wu-cheng Li <wuchengli@google.com> | 2012-05-22 10:38:12 -0700 |
---|---|---|
committer | Angus Kong <shkong@google.com> | 2012-05-23 13:32:19 -0700 |
commit | 76507a9fd2581694942a662a57fbdd46d7a20036 (patch) | |
tree | a8e8482d8681efdf16fe9102febdda3f227b09ba /src | |
parent | 5c9d687d05669253490e06295003732e66dc4e75 (diff) | |
download | Camera-76507a9fd2581694942a662a57fbdd46d7a20036.tar.gz |
Fix wrong aspect ratio in switch camera animation.
bug:6539357
Change-Id: I8bcb8634d88a27d839fa6ccae102a0d94b5119fb
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/ActivityBase.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/CameraScreenNail.java | 17 | ||||
-rw-r--r-- | src/com/android/camera/SwitchAnimManager.java | 96 |
3 files changed, 78 insertions, 39 deletions
diff --git a/src/com/android/camera/ActivityBase.java b/src/com/android/camera/ActivityBase.java index 2c746d78..9a102b16 100644 --- a/src/com/android/camera/ActivityBase.java +++ b/src/com/android/camera/ActivityBase.java @@ -49,7 +49,7 @@ abstract public class ActivityBase extends AbstractGalleryActivity implements View.OnLayoutChangeListener { private static final String TAG = "ActivityBase"; - private static boolean LOGV = false; + private static final boolean LOGV = false; private static final int CAMERA_APP_VIEW_TOGGLE_TIME = 100; // milliseconds private int mResultCodeForTesting; private Intent mResultDataForTesting; @@ -366,6 +366,8 @@ abstract public class ActivityBase extends AbstractGalleryActivity return; } + mCameraScreenNail.setPreviewFrameLayoutSize(right - left, bottom - top); + // Find out the coordinates of the preview frame relative to GL // root view. View root = (View) getGLRoot(); diff --git a/src/com/android/camera/CameraScreenNail.java b/src/com/android/camera/CameraScreenNail.java index bf3deb2f..18a1946c 100644 --- a/src/com/android/camera/CameraScreenNail.java +++ b/src/com/android/camera/CameraScreenNail.java @@ -22,8 +22,6 @@ import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.RawTexture; import com.android.gallery3d.ui.SurfaceTextureScreenNail; -import android.util.Log; - /* * This is a ScreenNail which can displays camera preview. */ @@ -55,7 +53,7 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { // Animation. private CaptureAnimManager mCaptureAnimManager = new CaptureAnimManager(); - private SwitchAnimManager mSwitchAnimManager =new SwitchAnimManager(); + private SwitchAnimManager mSwitchAnimManager = new SwitchAnimManager(); private int mAnimState = ANIM_NONE; private RawTexture mAnimTexture; // Some methods are called by GL thread and some are called by main thread. @@ -134,6 +132,7 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { switch (mAnimState) { case ANIM_SWITCH_COPY_TEXTURE: copyPreviewTexture(canvas); + mSwitchAnimManager.setReviewDrawingSize(width, height); mListener.onPreviewTextureCopied(); mAnimState = ANIM_SWITCH_DARK_PREVIEW; // The texture is ready. Fall through to draw darkened @@ -145,7 +144,7 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { canvas.setAlpha(alpha); return; case ANIM_SWITCH_START: - mSwitchAnimManager.startAnimation(x, y, width, height); + mSwitchAnimManager.startAnimation(); mAnimState = ANIM_SWITCH_RUNNING; break; case ANIM_CAPTURE_START: @@ -160,7 +159,8 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { if (mAnimState == ANIM_CAPTURE_RUNNING) { drawn = mCaptureAnimManager.drawAnimation(canvas, this, mAnimTexture); } else { - drawn = mSwitchAnimManager.drawAnimation(canvas, this, mAnimTexture); + drawn = mSwitchAnimManager.drawAnimation(canvas, x, y, + width, height, this, mAnimTexture); } if (drawn) { mListener.requestRender(); @@ -216,4 +216,11 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { } } } + + // We need to keep track of the size of preview frame on the screen because + // it's needed when we do switch-camera animation. See comments in + // SwitchAnimManager.java. + public void setPreviewFrameLayoutSize(int width, int height) { + mSwitchAnimManager.setPreviewFrameLayoutSize(width, height); + } } diff --git a/src/com/android/camera/SwitchAnimManager.java b/src/com/android/camera/SwitchAnimManager.java index 36da7a8f..fa0d6e69 100644 --- a/src/com/android/camera/SwitchAnimManager.java +++ b/src/com/android/camera/SwitchAnimManager.java @@ -17,14 +17,16 @@ package com.android.camera; import android.os.SystemClock; +import android.util.Log; import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.RawTexture; /** * Class to handle the animation when switching between back and front cameras. - * The snapshot of the previous camera zooms in and fades out. The preview of - * the new camera zooms in and fades in. + * An image of the previous camera zooms in and fades out. The preview of the + * new camera zooms in and fades in. The image of the previous camera is called + * review in this class. */ public class SwitchAnimManager { private static final String TAG = "SwitchAnimManager"; @@ -35,55 +37,83 @@ public class SwitchAnimManager { public static final float INITIAL_DARKEN_ALPHA = 0.8f; private long mAnimStartTime; // milliseconds. - // The center of the preview and review - private float mCenterX; - private float mCenterY; - private int mDrawWidth; - private int mDrawHeight; + // The drawing width and height of the review image. This is saved when the + // texture is copied. + private int mReviewDrawingWidth; + private int mReviewDrawingHeight; + // The maximum width of the camera screen nail width from onDraw. We need to + // know how much the preview is scaled and scale the review the same amount. + // For example, the preview is not full screen in film strip mode. + private int mPreviewFrameLayoutWidth; public SwitchAnimManager() { } - // x, y, x and h: the rectangle area where the animation takes place. - public void startAnimation(int x, int y, int w, int h) { + public void setReviewDrawingSize(int width, int height) { + mReviewDrawingWidth = width; + mReviewDrawingHeight = height; + } + + // width: the width of PreviewFrameLayout view. + // height: the height of PreviewFrameLayout view. Not used. Kept for + // consistency. + public void setPreviewFrameLayoutSize(int width, int height) { + mPreviewFrameLayoutWidth = width; + } + + // w and h: the rectangle area where the animation takes place. + public void startAnimation() { mAnimStartTime = SystemClock.uptimeMillis(); - mDrawWidth = w; - mDrawHeight = h; - mCenterX = x + w / 2f; - mCenterY = y + h / 2f; } // Returns true if the animation has been drawn. // preview: camera preview view. // review: snapshot of the preview before switching the camera. - public boolean drawAnimation(GLCanvas canvas, CameraScreenNail preview, - RawTexture review) { + public boolean drawAnimation(GLCanvas canvas, int x, int y, int width, + int height, CameraScreenNail preview, RawTexture review) { long timeDiff = SystemClock.uptimeMillis() - mAnimStartTime; if (timeDiff > ANIMATION_DURATION) return false; - - // Calculate the position and the size of the preview and review. float fraction = timeDiff / ANIMATION_DURATION; - float previewScale = 1 - ZOOM_DELTA_PREVIEW * (1 - fraction); - float reviewScale = 1 + ZOOM_DELTA_REVIEW * fraction; - float previewWidth = mDrawWidth * previewScale; - float previewHeight = mDrawHeight * previewScale; - float reviewWidth = mDrawWidth * reviewScale; - float reviewHeight = mDrawHeight * reviewScale; - int previewX = Math.round(mCenterX - previewWidth / 2); - int previewY = Math.round(mCenterY - previewHeight / 2); - int reviewX = Math.round(mCenterX - reviewWidth / 2); - int reviewY = Math.round(mCenterY - reviewHeight / 2); - // Draw the preview and review. + // Calculate the position and the size of the preview. + float centerX = x + width / 2f; + float centerY = y + height / 2f; + float previewAnimScale = 1 - ZOOM_DELTA_PREVIEW * (1 - fraction); + float previewWidth = width * previewAnimScale; + float previewHeight = height * previewAnimScale; + int previewX = Math.round(centerX - previewWidth / 2); + int previewY = Math.round(centerY - previewHeight / 2); + + // Calculate the position and the size of the review. + float reviewAnimScale = 1 + ZOOM_DELTA_REVIEW * fraction; + + // Calculate how much preview is scaled. + // The scaling is done by PhotoView in Gallery so we don't have the + // scaling information but only the width and the height passed to this + // method. The inference of the scale ratio is done by matching the + // current width and the original width we have at first when the camera + // layout is inflated. + float scaleRatio = 1; + if (mPreviewFrameLayoutWidth != 0) { + scaleRatio = (float) width / mPreviewFrameLayoutWidth; + } else { + Log.e(TAG, "mPreviewFrameLayoutWidth is 0."); + } + float reviewWidth = mReviewDrawingWidth * reviewAnimScale * scaleRatio; + float reviewHeight = mReviewDrawingHeight * reviewAnimScale * scaleRatio; + int reviewX = Math.round(centerX - reviewWidth / 2); + int reviewY = Math.round(centerY - reviewHeight / 2); + + // Draw the preview. float alpha = canvas.getAlpha(); - canvas.setAlpha(fraction); // new camera preview fades in + canvas.setAlpha(fraction); // fade in preview.directDraw(canvas, previewX, previewY, Math.round(previewWidth), Math.round(previewHeight)); - // old camera preview fades out - canvas.setAlpha((1f - fraction) * INITIAL_DARKEN_ALPHA); - review.draw(canvas, reviewX, reviewY, (int) reviewWidth, - (int) reviewHeight); + // Draw the review. + canvas.setAlpha((1f - fraction) * INITIAL_DARKEN_ALPHA); // fade out + review.draw(canvas, reviewX, reviewY, Math.round(reviewWidth), + Math.round(reviewHeight)); canvas.setAlpha(alpha); return true; } |