* It is called each time the orientation determination transitions from being
* uncertain to being certain again, even if it is the same orientation as before.
*
+ * This should only be called on the Handler thread.
+ *
* @param rotation The new orientation of the device, one of the Surface.ROTATION_* constants.
* @see android.view.Surface
*/
@Override
public void onSensorChanged(SensorEvent event) {
+ int newRotation;
synchronized (mLock) {
mDesiredRotation = (int) event.values[0];
- evaluateRotationChangeLocked();
+ newRotation = evaluateRotationChangeLocked();
+ }
+ if (newRotation >=0) {
+ onProposedRotationChanged(newRotation);
}
}
unscheduleRotationEvaluationLocked();
}
- public void evaluateRotationChangeLocked() {
+ public int evaluateRotationChangeLocked() {
unscheduleRotationEvaluationLocked();
if (mDesiredRotation == mProposedRotation) {
- return;
+ return -1;
}
final long now = SystemClock.elapsedRealtimeNanos();
if (isDesiredRotationAcceptableLocked(now)) {
mProposedRotation = mDesiredRotation;
- onProposedRotationChanged(mProposedRotation);
+ return mProposedRotation;
} else {
scheduleRotationEvaluationIfNecessaryLocked(now);
}
+ return -1;
}
private boolean isDesiredRotationAcceptableLocked(long now) {
private Runnable mRotationEvaluator = new Runnable() {
@Override
public void run() {
+ int newRotation;
synchronized (mLock) {
mRotationEvaluationScheduled = false;
- evaluateRotationChangeLocked();
+ newRotation = evaluateRotationChangeLocked();
+ }
+ if (newRotation >= 0) {
+ onProposedRotationChanged(newRotation);
}
}
};