summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-01-26 17:56:05 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-26 17:56:05 -0800
commitb40526a483e9d58aa61a13bca2cd18333a33267d (patch)
treeff914d1bf96ac031c2634cbb7658a53fc79308be
parent56734d4fef9c169860e6390fadccf2d92d513eec (diff)
parent855b4ca04f982c7110acd81b509c955df976926f (diff)
downloadLegacyCamera-b40526a483e9d58aa61a13bca2cd18333a33267d.zip
LegacyCamera-b40526a483e9d58aa61a13bca2cd18333a33267d.tar.gz
LegacyCamera-b40526a483e9d58aa61a13bca2cd18333a33267d.tar.bz2
Merge "Fix camera preview orientation when device is held in portrait." into honeycomb
-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();