summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-01-25 20:37:55 +0800
committerWu-cheng Li <wuchengli@google.com>2011-01-26 18:04:01 +0800
commit855b4ca04f982c7110acd81b509c955df976926f (patch)
treed51876d5635c9126abb456c571ce699a6587e33f /src
parentde0d58c0368407e37181c8236cc31c2da8b3491b (diff)
downloadLegacyCamera-855b4ca04f982c7110acd81b509c955df976926f.zip
LegacyCamera-855b4ca04f982c7110acd81b509c955df976926f.tar.gz
LegacyCamera-855b4ca04f982c7110acd81b509c955df976926f.tar.bz2
Fix camera preview orientation when device is held in portrait.
The problem is the rotation animation may still in progress during onCreate. When we start the preview in onCreate, the display rotation is still the value in portrait. So we check the display rotation again in surfaceChanged. If it is different, restart the preview. bug:3362860 Change-Id: Ib930c18d089114a3b5b9ca0f599e1ebdace73eb7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java14
-rw-r--r--src/com/android/camera/Util.java3
-rw-r--r--src/com/android/camera/VideoCamera.java16
3 files changed, 26 insertions, 7 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 84456e3..0a8cc99 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -190,6 +190,9 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
"android.intent.extra.quickCapture";
private boolean mPreviewing;
+ // The display rotation in degrees. This is only valid when mPreviewing is
+ // true.
+ private int mDisplayRotation;
private boolean mPausing;
private boolean mFirstTimeInitialized;
private boolean mIsImageCaptureIntent;
@@ -1646,7 +1649,13 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
// Ignore it.
if (mPausing || isFinishing()) return;
- if (mPreviewing && holder.isCreating()) {
+ // Set preview display if the surface is being created. Preview was
+ // already started. Also restart the preview if display rotation has
+ // changed. Sometimes this happens when the device is held in portrait
+ // and camera app is opened. Rotation animation takes some time and
+ // display rotation in onCreate may not be what we want.
+ if (mPreviewing && (Util.getDisplayRotation(this) == mDisplayRotation)
+ && holder.isCreating()) {
// Set preview display if the surface is being created and preview
// was already started. That means preview display was set to null
// and we need to set it now.
@@ -1730,7 +1739,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
if (mPreviewing) stopPreview();
setPreviewDisplay(mSurfaceHolder);
- Util.setCameraDisplayOrientation(this, mCameraId, mCameraDevice);
+ mDisplayRotation = Util.getDisplayRotation(this);
+ Util.setCameraDisplayOrientation(mDisplayRotation, mCameraId, mCameraDevice);
setCameraParameters(UPDATE_PARAM_ALL);
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index 3db0ec9..cfef950 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -310,13 +310,12 @@ public class Util {
return 0;
}
- public static void setCameraDisplayOrientation(Activity activity,
+ public static void setCameraDisplayOrientation(int degrees,
int cameraId, Camera camera) {
// See android.hardware.Camera.setCameraDisplayOrientation for
// documentation.
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
- int degrees = getDisplayRotation(activity);
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 8dea4cd..3e2c09b 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -195,6 +195,9 @@ public class VideoCamera extends NoSearchActivity
boolean mPausing = false;
boolean mPreviewing = false; // True if preview is started.
+ // The display rotation in degrees. This is only valid when mPreviewing is
+ // true.
+ private int mDisplayRotation;
private ContentResolver mContentResolver;
@@ -872,7 +875,8 @@ public class VideoCamera extends NoSearchActivity
mPreviewing = false;
}
setPreviewDisplay(mSurfaceHolder);
- Util.setCameraDisplayOrientation(this, mCameraId, mCameraDevice);
+ mDisplayRotation = Util.getDisplayRotation(this);
+ Util.setCameraDisplayOrientation(mDisplayRotation, mCameraId, mCameraDevice);
setCameraParameters();
try {
@@ -1006,6 +1010,8 @@ public class VideoCamera extends NoSearchActivity
return;
}
+ Log.v(TAG, "surfaceChanged. w=" + w + ". h=" + h);
+
mSurfaceHolder = holder;
if (mPausing) {
@@ -1024,8 +1030,12 @@ public class VideoCamera extends NoSearchActivity
if (mCameraDevice == null) return;
// Set preview display if the surface is being created. Preview was
- // already started.
- if (holder.isCreating()) {
+ // already started. Also restart the preview if display rotation has
+ // changed. Sometimes this happens when the device is held in portrait
+ // and camera app is opened. Rotation animation takes some time and
+ // display rotation in onCreate may not be what we want.
+ if (mPreviewing && (Util.getDisplayRotation(this) == mDisplayRotation)
+ && holder.isCreating()) {
setPreviewDisplay(holder);
} else {
stopVideoRecording();