summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera
diff options
context:
space:
mode:
authorEino-Ville Talvala <etalvala@google.com>2011-10-19 12:09:54 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-19 12:09:54 -0700
commit7b52266b6f9af570f1fdb200a1d0fa7947344e1a (patch)
treef47c80871af09a79e5439e1841c6888874ac67c1 /src/com/android/camera
parent53d86908dc3e1cb54add568aa6bc325485e3efe5 (diff)
parent131cf9886c4f34431598be0b1f5b7aaa915277cc (diff)
downloadLegacyCamera-7b52266b6f9af570f1fdb200a1d0fa7947344e1a.zip
LegacyCamera-7b52266b6f9af570f1fdb200a1d0fa7947344e1a.tar.gz
LegacyCamera-7b52266b6f9af570f1fdb200a1d0fa7947344e1a.tar.bz2
Merge "Add hysteresis to orientation rounding." into ics-mr0
Diffstat (limited to 'src/com/android/camera')
-rw-r--r--src/com/android/camera/Camera.java6
-rw-r--r--src/com/android/camera/Util.java18
-rwxr-xr-xsrc/com/android/camera/VideoCamera.java5
-rwxr-xr-xsrc/com/android/camera/panorama/PanoramaActivity.java6
4 files changed, 21 insertions, 14 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 685319f..589a5c8 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -1184,10 +1184,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
if (mThumbnailView != null) mThumbnailView.setEnabled(enable);
}
- public static int roundOrientation(int orientation) {
- return ((orientation + 45) / 90 * 90) % 360;
- }
-
private class MyOrientationEventListener
extends OrientationEventListener {
public MyOrientationEventListener(Context context) {
@@ -1200,7 +1196,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == ORIENTATION_UNKNOWN) return;
- mOrientation = roundOrientation(orientation);
+ mOrientation = Util.roundOrientation(orientation, mOrientation);
// When the screen is unlocked, display rotation may change. Always
// calculate the up-to-date orientationCompensation.
int orientationCompensation = mOrientation
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index 768bf27..31a54d5 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -71,6 +71,9 @@ public class Util {
// Use the same setting among the Camera, VideoCamera and Panorama modes.
private static final float DEFAULT_CAMERA_BRIGHTNESS = 0.7f;
+ // Orientation hysteresis amount used in rounding, in degrees
+ public static final int ORIENTATION_HYSTERESIS = 5;
+
public static final String REVIEW_ACTION = "com.android.camera.action.REVIEW";
// Private intent extras. Test only.
@@ -345,6 +348,21 @@ public class Util {
return result;
}
+ public static int roundOrientation(int orientation, int orientationHistory) {
+ boolean changeOrientation = false;
+ if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
+ changeOrientation = true;
+ } else {
+ int dist = Math.abs(orientation - orientationHistory);
+ dist = Math.min( dist, 360 - dist );
+ changeOrientation = ( dist >= 45 + ORIENTATION_HYSTERESIS );
+ }
+ if (changeOrientation) {
+ return ((orientation + 45) / 90 * 90) % 360;
+ }
+ return orientationHistory;
+ }
+
public static Size getOptimalPreviewSize(Activity currentActivity,
List<Size> sizes, double targetRatio) {
// Use a very small tolerance because we want an exact match.
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index fa3a9d6..8960311 100755
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -500,9 +500,6 @@ public class VideoCamera extends ActivityBase
}
}
- public static int roundOrientation(int orientation) {
- return ((orientation + 45) / 90 * 90) % 360;
- }
private class MyOrientationEventListener
extends OrientationEventListener {
@@ -516,7 +513,7 @@ public class VideoCamera extends ActivityBase
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == ORIENTATION_UNKNOWN) return;
- mOrientation = roundOrientation(orientation);
+ mOrientation = Util.roundOrientation(orientation, mOrientation);
// When the screen is unlocked, display rotation may change. Always
// calculate the up-to-date orientationCompensation.
int orientationCompensation = mOrientation
diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java
index 48a455e..0e055e5 100755
--- a/src/com/android/camera/panorama/PanoramaActivity.java
+++ b/src/com/android/camera/panorama/PanoramaActivity.java
@@ -190,10 +190,6 @@ public class PanoramaActivity extends ActivityBase implements
public final boolean isValid;
}
- public static int roundOrientation(int orientation) {
- return ((orientation + 45) / 90 * 90) % 360;
- }
-
private class PanoOrientationEventListener extends OrientationEventListener {
public PanoOrientationEventListener(Context context) {
super(context);
@@ -205,7 +201,7 @@ public class PanoramaActivity extends ActivityBase implements
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == ORIENTATION_UNKNOWN) return;
- mDeviceOrientation = roundOrientation(orientation);
+ mDeviceOrientation = Util.roundOrientation(orientation, mDeviceOrientation);
// When the screen is unlocked, display rotation may change. Always
// calculate the up-to-date orientationCompensation.
int orientationCompensation = mDeviceOrientation