am ad1f4a2c: Merge "Implement a max time bound for rotation. (DO NOT MERGE)" into ics-mr1
* commit 'ad1f4a2ca825b8524c6bed494a7cf3ca70ee7e28': Implement a max time bound for rotation. (DO NOT MERGE)
This commit is contained in:
@@ -229,8 +229,10 @@ public abstract class WindowOrientationListener {
|
|||||||
//
|
//
|
||||||
// The basic idea is to ignore intermediate poses of the device while the
|
// The basic idea is to ignore intermediate poses of the device while the
|
||||||
// user is picking up, putting down or turning the device.
|
// user is picking up, putting down or turning the device.
|
||||||
|
private long mProposalTime;
|
||||||
private int mProposalRotation;
|
private int mProposalRotation;
|
||||||
private long mProposalAgeMS;
|
private long mProposalAgeMS;
|
||||||
|
private boolean mProposalSettled;
|
||||||
|
|
||||||
// A historical trace of tilt and orientation angles. Used to determine whether
|
// A historical trace of tilt and orientation angles. Used to determine whether
|
||||||
// the device posture has settled down.
|
// the device posture has settled down.
|
||||||
@@ -306,10 +308,10 @@ public abstract class WindowOrientationListener {
|
|||||||
// The ideal tilt angle is 0 (when the device is vertical) so the limits establish
|
// The ideal tilt angle is 0 (when the device is vertical) so the limits establish
|
||||||
// how close to vertical the device must be in order to change orientation.
|
// how close to vertical the device must be in order to change orientation.
|
||||||
private static final int[][] TILT_TOLERANCE = new int[][] {
|
private static final int[][] TILT_TOLERANCE = new int[][] {
|
||||||
/* ROTATION_0 */ { -20, 70 },
|
/* ROTATION_0 */ { -25, 70 },
|
||||||
/* ROTATION_90 */ { -20, 60 },
|
/* ROTATION_90 */ { -25, 65 },
|
||||||
/* ROTATION_180 */ { -20, 50 },
|
/* ROTATION_180 */ { -25, 60 },
|
||||||
/* ROTATION_270 */ { -20, 60 }
|
/* ROTATION_270 */ { -25, 65 }
|
||||||
};
|
};
|
||||||
|
|
||||||
// The gap angle in degrees between adjacent orientation angles for hysteresis.
|
// The gap angle in degrees between adjacent orientation angles for hysteresis.
|
||||||
@@ -322,7 +324,11 @@ public abstract class WindowOrientationListener {
|
|||||||
// The number of milliseconds for which the device posture must be stable
|
// The number of milliseconds for which the device posture must be stable
|
||||||
// before we perform an orientation change. If the device appears to be rotating
|
// before we perform an orientation change. If the device appears to be rotating
|
||||||
// (being picked up, put down) then we keep waiting until it settles.
|
// (being picked up, put down) then we keep waiting until it settles.
|
||||||
private static final int SETTLE_TIME_MS = 200;
|
private static final int SETTLE_TIME_MIN_MS = 200;
|
||||||
|
|
||||||
|
// The maximum number of milliseconds to wait for the posture to settle before
|
||||||
|
// accepting the current proposal regardless.
|
||||||
|
private static final int SETTLE_TIME_MAX_MS = 500;
|
||||||
|
|
||||||
// The maximum change in magnitude that can occur during the settle time.
|
// The maximum change in magnitude that can occur during the settle time.
|
||||||
// Tuning this constant particularly helps to filter out situations where the
|
// Tuning this constant particularly helps to filter out situations where the
|
||||||
@@ -331,17 +337,17 @@ public abstract class WindowOrientationListener {
|
|||||||
SensorManager.STANDARD_GRAVITY * 0.2f;
|
SensorManager.STANDARD_GRAVITY * 0.2f;
|
||||||
|
|
||||||
// The maximum change in tilt angle that can occur during the settle time.
|
// The maximum change in tilt angle that can occur during the settle time.
|
||||||
private static final int SETTLE_TILT_ANGLE_MAX_DELTA = 5;
|
private static final int SETTLE_TILT_ANGLE_MAX_DELTA = 8;
|
||||||
|
|
||||||
// The maximum change in orientation angle that can occur during the settle time.
|
// The maximum change in orientation angle that can occur during the settle time.
|
||||||
private static final int SETTLE_ORIENTATION_ANGLE_MAX_DELTA = 5;
|
private static final int SETTLE_ORIENTATION_ANGLE_MAX_DELTA = 8;
|
||||||
|
|
||||||
public SensorEventListenerImpl(WindowOrientationListener orientationListener) {
|
public SensorEventListenerImpl(WindowOrientationListener orientationListener) {
|
||||||
mOrientationListener = orientationListener;
|
mOrientationListener = orientationListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProposedRotation() {
|
public int getProposedRotation() {
|
||||||
return mProposalAgeMS >= SETTLE_TIME_MS ? mProposalRotation : -1;
|
return mProposalSettled ? mProposalRotation : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -440,9 +446,6 @@ public abstract class WindowOrientationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine the proposed orientation.
|
// Determine the proposed orientation.
|
||||||
// The confidence of the proposal is 1.0 when it is ideal and it
|
|
||||||
// decays exponentially as the proposal moves further from the ideal
|
|
||||||
// angle, tilt and magnitude of the proposed orientation.
|
|
||||||
if (!isTiltAngleAcceptable(nearestRotation, tiltAngle)
|
if (!isTiltAngleAcceptable(nearestRotation, tiltAngle)
|
||||||
|| !isOrientationAngleAcceptable(nearestRotation,
|
|| !isOrientationAngleAcceptable(nearestRotation,
|
||||||
orientationAngle)) {
|
orientationAngle)) {
|
||||||
@@ -471,7 +474,7 @@ public abstract class WindowOrientationListener {
|
|||||||
final int proposedRotation = getProposedRotation();
|
final int proposedRotation = getProposedRotation();
|
||||||
if (log) {
|
if (log) {
|
||||||
final float proposalConfidence = Math.min(
|
final float proposalConfidence = Math.min(
|
||||||
mProposalAgeMS * 1.0f / SETTLE_TIME_MS, 1.0f);
|
mProposalAgeMS * 1.0f / SETTLE_TIME_MIN_MS, 1.0f);
|
||||||
Slog.v(TAG, "Result: currentRotation=" + mOrientationListener.mCurrentRotation
|
Slog.v(TAG, "Result: currentRotation=" + mOrientationListener.mCurrentRotation
|
||||||
+ ", proposedRotation=" + proposedRotation
|
+ ", proposedRotation=" + proposedRotation
|
||||||
+ ", timeDeltaMS=" + timeDeltaMS
|
+ ", timeDeltaMS=" + timeDeltaMS
|
||||||
@@ -557,11 +560,13 @@ public abstract class WindowOrientationListener {
|
|||||||
private void clearProposal() {
|
private void clearProposal() {
|
||||||
mProposalRotation = -1;
|
mProposalRotation = -1;
|
||||||
mProposalAgeMS = 0;
|
mProposalAgeMS = 0;
|
||||||
|
mProposalSettled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProposal(int rotation, long timestampMS,
|
private void updateProposal(int rotation, long timestampMS,
|
||||||
float magnitude, int tiltAngle, int orientationAngle) {
|
float magnitude, int tiltAngle, int orientationAngle) {
|
||||||
if (mProposalRotation != rotation) {
|
if (mProposalRotation != rotation) {
|
||||||
|
mProposalTime = timestampMS;
|
||||||
mProposalRotation = rotation;
|
mProposalRotation = rotation;
|
||||||
mHistoryIndex = 0;
|
mHistoryIndex = 0;
|
||||||
mHistoryLength = 0;
|
mHistoryLength = 0;
|
||||||
@@ -593,11 +598,17 @@ public abstract class WindowOrientationListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
age = timestampMS - mHistoryTimestampMS[olderIndex];
|
age = timestampMS - mHistoryTimestampMS[olderIndex];
|
||||||
if (age >= SETTLE_TIME_MS) {
|
if (age >= SETTLE_TIME_MIN_MS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mProposalAgeMS = age;
|
mProposalAgeMS = age;
|
||||||
|
if (age >= SETTLE_TIME_MIN_MS
|
||||||
|
|| timestampMS - mProposalTime >= SETTLE_TIME_MAX_MS) {
|
||||||
|
mProposalSettled = true;
|
||||||
|
} else {
|
||||||
|
mProposalSettled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int angleAbsoluteDelta(int a, int b) {
|
private static int angleAbsoluteDelta(int a, int b) {
|
||||||
|
|||||||
Reference in New Issue
Block a user