diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-02-18 15:12:47 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-02-18 16:02:25 +0800 |
commit | 232700d54651dcaefb378dc22bdb008a9815d1cd (patch) | |
tree | 5156271a4bb4607542dd9e70c5b230e87240b4d0 /src/com/android/camera/VideoCamera.java | |
parent | 56178dab31ef40c6465312466981778f39c1f355 (diff) | |
download | LegacyCamera-232700d54651dcaefb378dc22bdb008a9815d1cd.zip LegacyCamera-232700d54651dcaefb378dc22bdb008a9815d1cd.tar.gz LegacyCamera-232700d54651dcaefb378dc22bdb008a9815d1cd.tar.bz2 |
Fix wrong preview orientation when device is held upside down.
Suppose a user opens camera app and press home to exit.
The user holds the device upside down and opens camera again.
The animation takes some time so camera app will get the old
rotation value in onResume and surfaceChanged. Besides, framework
does not have a callback for it. The solution is to poll the
rotation value for 5 seconds. If it changes, restart the preview.
bug:3362860
Change-Id: I065e8601e321361d8db405f9c587ec2a5bce050c
Diffstat (limited to 'src/com/android/camera/VideoCamera.java')
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 3e2c09b..0870de6 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -92,6 +92,7 @@ public class VideoCamera extends NoSearchActivity private static final String LAST_THUMB_PATH = Storage.THUMBNAILS + "/video_last_thumb"; + private static final int CHECK_DISPLAY_ROTATION = 3; private static final int CLEAR_SCREEN_DELAY = 4; private static final int UPDATE_RECORD_TIME = 5; private static final int ENABLE_SHUTTER_BUTTON = 6; @@ -162,6 +163,7 @@ public class VideoCamera extends NoSearchActivity private MediaRecorder mMediaRecorder; private boolean mMediaRecorderRecording = false; private long mRecordingStartTime; + private long mOnResumeTime; // The video file that the hardware camera is about to record into // (or is recording into.) private String mVideoFilename; @@ -248,6 +250,22 @@ public class VideoCamera extends NoSearchActivity break; } + case CHECK_DISPLAY_ROTATION: { + // Restart the preview if display rotation has changed. + // Sometimes this happens when the device is held upside + // down and camera app is opened. Rotation animation will + // take some time and the rotation value we have got may be + // wrong. Framework does not have a callback for this now. + if ((Util.getDisplayRotation(VideoCamera.this) != mDisplayRotation) + && !mMediaRecorderRecording) { + startPreview(); + } + if (SystemClock.uptimeMillis() - mOnResumeTime < 5000) { + mHandler.sendEmptyMessageDelayed(CHECK_DISPLAY_ROTATION, 100); + } + break; + } + default: Log.v(TAG, "Unhandled message: " + msg.what); break; @@ -843,6 +861,11 @@ public class VideoCamera extends NoSearchActivity if (!mIsVideoCaptureIntent) { updateThumbnailButton(); } + + if (mPreviewing) { + mOnResumeTime = SystemClock.uptimeMillis(); + mHandler.sendEmptyMessageDelayed(CHECK_DISPLAY_ROTATION, 100); + } } private void setPreviewDisplay(SurfaceHolder holder) { @@ -944,6 +967,8 @@ public class VideoCamera extends NoSearchActivity } mOrientationListener.disable(); + + mHandler.removeMessages(CHECK_DISPLAY_ROTATION); } @Override |