diff options
author | Steve Howard <showard@google.com> | 2010-08-16 11:41:58 -0700 |
---|---|---|
committer | Steve Howard <showard@google.com> | 2010-08-18 14:22:19 -0700 |
commit | 5eb49583e2f0b82d7a48182ffed5f409b4f85dc5 (patch) | |
tree | 2c91210ef2921794ac55e7488accb1cc2e6138c2 | |
parent | baf3869b88ab4e31f792dbe08f61725bc3619ea8 (diff) | |
download | frameworks_base-5eb49583e2f0b82d7a48182ffed5f409b4f85dc5.zip frameworks_base-5eb49583e2f0b82d7a48182ffed5f409b4f85dc5.tar.gz frameworks_base-5eb49583e2f0b82d7a48182ffed5f409b4f85dc5.tar.bz2 |
Improve orientation sensing when waking up while flat.
This change makes the window manager pass the currently displayed
orientation to the WindowOrientationListener each time to calls to get
the currently sensed orientation. Now, when the
WindowOrientationListener doesn't know for sure what the orientation
of the device should be (for example, if the sensed orientation is
flat on a table), then it trusts the already-displayed orientation,
rather than trusting whatever sensors reading it most recently
received.
The main use case this addresses is:
* user uses device in portrait
* user turns off device, puts it in pocket
* while in pocket, screen gets turned on, activating orientaiton
sensor, which senses landscape orientation
* screen timed out
* user takes device out, places it on a table (or looks down at it,
holding it flat), and unlocks it
Previously, when the device was unlocked, the
WindowOrientationListener would return landscape orientation based on
its previous sensor readings. Now, it will override those previous
readings because it knows they never actually took effect and the
device is presently flat.
This change also slightly modifies the way we handle flat orientation,
now completely ignoring data when the tilt distrust is nonzero (even
if the current sensor reading shows non-tilted).
Change-Id: Ia4950a41827f8c53a80487d0c2e83b556df781b9
-rwxr-xr-x | core/java/android/view/WindowOrientationListener.java | 38 | ||||
-rwxr-xr-x | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java | 4 |
2 files changed, 24 insertions, 18 deletions
diff --git a/core/java/android/view/WindowOrientationListener.java b/core/java/android/view/WindowOrientationListener.java index fed55dc..55d11bb 100755 --- a/core/java/android/view/WindowOrientationListener.java +++ b/core/java/android/view/WindowOrientationListener.java @@ -103,11 +103,11 @@ public abstract class WindowOrientationListener { } } - public int getCurrentRotation() { + public int getCurrentRotation(int lastRotation) { if (mEnabled) { - return mSensorEventListener.getCurrentRotation(); + return mSensorEventListener.getCurrentRotation(lastRotation); } - return -1; + return lastRotation; } /** @@ -153,9 +153,15 @@ public abstract class WindowOrientationListener { private static final int ROTATION_270 = 2; // Mapping our internal aliases into actual Surface rotation values - private static final int[] SURFACE_ROTATIONS = new int[] { + private static final int[] INTERNAL_TO_SURFACE_ROTATION = new int[] { Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_270}; + // Mapping Surface rotation values to internal aliases. + // We have no constant for Surface.ROTATION_180. That should never happen, but if it + // does, we'll arbitrarily choose a mapping. + private static final int[] SURFACE_TO_INTERNAL_ROTATION = new int[] { + ROTATION_0, ROTATION_90, ROTATION_90, ROTATION_270}; + // Threshold ranges of orientation angle to transition into other orientation states. // The first list is for transitions from ROTATION_0, the next for ROTATION_90, etc. // ROTATE_TO defines the orientation each threshold range transitions to, and must be kept @@ -243,8 +249,12 @@ public abstract class WindowOrientationListener { return (float) SAMPLING_PERIOD_MS / (timeConstantMs + SAMPLING_PERIOD_MS); } - int getCurrentRotation() { - return SURFACE_ROTATIONS[mRotation]; + int getCurrentRotation(int lastRotation) { + if (mTiltDistrust > 0) { + // we really don't know the current orientation, so trust what's currently displayed + mRotation = SURFACE_TO_INTERNAL_ROTATION[lastRotation]; + } + return INTERNAL_TO_SURFACE_ROTATION[mRotation]; } private void calculateNewRotation(float orientation, float tiltAngle) { @@ -267,7 +277,7 @@ public abstract class WindowOrientationListener { if (localLOGV) Log.i(TAG, " new rotation = " + rotation); mRotation = rotation; - mOrientationListener.onOrientationChanged(getCurrentRotation()); + mOrientationListener.onOrientationChanged(INTERNAL_TO_SURFACE_ROTATION[mRotation]); } private float lowpassFilter(float newValue, float oldValue, float alpha) { @@ -306,7 +316,8 @@ public abstract class WindowOrientationListener { mTiltAngle = lowpassFilter(newTiltAngle, mTiltAngle, alpha); float absoluteTilt = Math.abs(mTiltAngle); - if (checkFullyTilted(absoluteTilt)) { + checkFullyTilted(absoluteTilt); + if (mTiltDistrust > 0) { return; // when fully tilted, ignore orientation entirely } @@ -347,11 +358,9 @@ public abstract class WindowOrientationListener { * get un-tilted. * * @param absoluteTilt the absolute value of the current tilt angle - * @return true if the phone is fully tilted */ - private boolean checkFullyTilted(float absoluteTilt) { - boolean fullyTilted = absoluteTilt > MAX_TILT; - if (fullyTilted) { + private void checkFullyTilted(float absoluteTilt) { + if (absoluteTilt > MAX_TILT) { if (mRotation == ROTATION_0) { mOrientationAngle = 0; } else if (mRotation == ROTATION_90) { @@ -366,7 +375,6 @@ public abstract class WindowOrientationListener { } else if (mTiltDistrust > 0) { mTiltDistrust--; } - return fullyTilted; } /** @@ -389,8 +397,8 @@ public abstract class WindowOrientationListener { */ private void filterOrientation(float absoluteTilt, float orientationAngle) { float alpha = DEFAULT_LOWPASS_ALPHA; - if (mTiltDistrust > 0 || mAccelerationDistrust > 1) { - // when fully tilted, or under more than a transient acceleration, distrust heavily + if (mAccelerationDistrust > 1) { + // when under more than a transient acceleration, distrust heavily alpha = ACCELERATING_LOWPASS_ALPHA; } else if (absoluteTilt > PARTIAL_TILT || mAccelerationDistrust == 1) { // when tilted partway, or under transient acceleration, distrust lightly diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index e2e6f1a..274124b 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -2076,9 +2076,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { return mDeskDockRotation; } else { if (useSensorForOrientationLp(orientation)) { - // If the user has enabled auto rotation by default, do it. - int curRotation = mOrientationListener.getCurrentRotation(); - return curRotation >= 0 ? curRotation : lastRotation; + return mOrientationListener.getCurrentRotation(lastRotation); } return Surface.ROTATION_0; } |