Skip to content

Commit ad1f4a2

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Implement a max time bound for rotation. (DO NOT MERGE)" into ics-mr1
2 parents 5d58eb0 + 8fd86f3 commit ad1f4a2

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

core/java/android/view/WindowOrientationListener.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ static final class SensorEventListenerImpl implements SensorEventListener {
229229
//
230230
// The basic idea is to ignore intermediate poses of the device while the
231231
// user is picking up, putting down or turning the device.
232+
private long mProposalTime;
232233
private int mProposalRotation;
233234
private long mProposalAgeMS;
235+
private boolean mProposalSettled;
234236

235237
// A historical trace of tilt and orientation angles. Used to determine whether
236238
// the device posture has settled down.
@@ -306,10 +308,10 @@ static final class SensorEventListenerImpl implements SensorEventListener {
306308
// The ideal tilt angle is 0 (when the device is vertical) so the limits establish
307309
// how close to vertical the device must be in order to change orientation.
308310
private static final int[][] TILT_TOLERANCE = new int[][] {
309-
/* ROTATION_0 */ { -20, 70 },
310-
/* ROTATION_90 */ { -20, 60 },
311-
/* ROTATION_180 */ { -20, 50 },
312-
/* ROTATION_270 */ { -20, 60 }
311+
/* ROTATION_0 */ { -25, 70 },
312+
/* ROTATION_90 */ { -25, 65 },
313+
/* ROTATION_180 */ { -25, 60 },
314+
/* ROTATION_270 */ { -25, 65 }
313315
};
314316

315317
// The gap angle in degrees between adjacent orientation angles for hysteresis.
@@ -322,7 +324,11 @@ static final class SensorEventListenerImpl implements SensorEventListener {
322324
// The number of milliseconds for which the device posture must be stable
323325
// before we perform an orientation change. If the device appears to be rotating
324326
// (being picked up, put down) then we keep waiting until it settles.
325-
private static final int SETTLE_TIME_MS = 200;
327+
private static final int SETTLE_TIME_MIN_MS = 200;
328+
329+
// The maximum number of milliseconds to wait for the posture to settle before
330+
// accepting the current proposal regardless.
331+
private static final int SETTLE_TIME_MAX_MS = 500;
326332

327333
// The maximum change in magnitude that can occur during the settle time.
328334
// Tuning this constant particularly helps to filter out situations where the
@@ -331,17 +337,17 @@ static final class SensorEventListenerImpl implements SensorEventListener {
331337
SensorManager.STANDARD_GRAVITY * 0.2f;
332338

333339
// The maximum change in tilt angle that can occur during the settle time.
334-
private static final int SETTLE_TILT_ANGLE_MAX_DELTA = 5;
340+
private static final int SETTLE_TILT_ANGLE_MAX_DELTA = 8;
335341

336342
// The maximum change in orientation angle that can occur during the settle time.
337-
private static final int SETTLE_ORIENTATION_ANGLE_MAX_DELTA = 5;
343+
private static final int SETTLE_ORIENTATION_ANGLE_MAX_DELTA = 8;
338344

339345
public SensorEventListenerImpl(WindowOrientationListener orientationListener) {
340346
mOrientationListener = orientationListener;
341347
}
342348

343349
public int getProposedRotation() {
344-
return mProposalAgeMS >= SETTLE_TIME_MS ? mProposalRotation : -1;
350+
return mProposalSettled ? mProposalRotation : -1;
345351
}
346352

347353
@Override
@@ -440,9 +446,6 @@ public void onSensorChanged(SensorEvent event) {
440446
}
441447

442448
// Determine the proposed orientation.
443-
// The confidence of the proposal is 1.0 when it is ideal and it
444-
// decays exponentially as the proposal moves further from the ideal
445-
// angle, tilt and magnitude of the proposed orientation.
446449
if (!isTiltAngleAcceptable(nearestRotation, tiltAngle)
447450
|| !isOrientationAngleAcceptable(nearestRotation,
448451
orientationAngle)) {
@@ -471,7 +474,7 @@ public void onSensorChanged(SensorEvent event) {
471474
final int proposedRotation = getProposedRotation();
472475
if (log) {
473476
final float proposalConfidence = Math.min(
474-
mProposalAgeMS * 1.0f / SETTLE_TIME_MS, 1.0f);
477+
mProposalAgeMS * 1.0f / SETTLE_TIME_MIN_MS, 1.0f);
475478
Slog.v(TAG, "Result: currentRotation=" + mOrientationListener.mCurrentRotation
476479
+ ", proposedRotation=" + proposedRotation
477480
+ ", timeDeltaMS=" + timeDeltaMS
@@ -557,11 +560,13 @@ private boolean isOrientationAngleAcceptable(int proposedRotation, int orientati
557560
private void clearProposal() {
558561
mProposalRotation = -1;
559562
mProposalAgeMS = 0;
563+
mProposalSettled = false;
560564
}
561565

562566
private void updateProposal(int rotation, long timestampMS,
563567
float magnitude, int tiltAngle, int orientationAngle) {
564568
if (mProposalRotation != rotation) {
569+
mProposalTime = timestampMS;
565570
mProposalRotation = rotation;
566571
mHistoryIndex = 0;
567572
mHistoryLength = 0;
@@ -593,11 +598,17 @@ private void updateProposal(int rotation, long timestampMS,
593598
break;
594599
}
595600
age = timestampMS - mHistoryTimestampMS[olderIndex];
596-
if (age >= SETTLE_TIME_MS) {
601+
if (age >= SETTLE_TIME_MIN_MS) {
597602
break;
598603
}
599604
}
600605
mProposalAgeMS = age;
606+
if (age >= SETTLE_TIME_MIN_MS
607+
|| timestampMS - mProposalTime >= SETTLE_TIME_MAX_MS) {
608+
mProposalSettled = true;
609+
} else {
610+
mProposalSettled = false;
611+
}
601612
}
602613

603614
private static int angleAbsoluteDelta(int a, int b) {

0 commit comments

Comments
 (0)