Gsensor 自动转屏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lf12345678910/article/details/53925707

frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

init(

// monitor for system gestures
        mSystemGestures = new SystemGesturesPointerEventListener(context,
                new SystemGesturesPointerEventListener.Callbacks() {
                    @Override

                    public void onUpOrCancel() {
                        mOrientationListener.onTouchEnd();
                    }

)

WindowOrientationListener.java

onTouchEnd( mOrientationJudge.onTouchEndLocked(whenElapsedNanos); )

        @Override
        public void onTouchEndLocked(long whenElapsedNanos) {
            mTouched = false;
            mTouchEndedTimestampNanos = whenElapsedNanos;
        }

Sensor.TYPE_DEVICE_ORIENTATION

Sensor.TYPE_GRAVITY

Sensor.TYPE_ACCELEROMETER

AccelSensorJudge ( Sensor.TYPE_GRAVITY )

onSensorChanged()  onProposedRotationChanged()  

isPredictedRotationAcceptableLocked()

 if (now < mPredictedRotationTimestampNanos + PROPOSAL_SETTLE_TIME_NANOS) {
                return false;
            }

            // The last flat state (time since picked up) must have been sufficiently long ago.
            if (now < mFlatTimestampNanos + PROPOSAL_MIN_TIME_SINCE_FLAT_ENDED_NANOS) {
                return false;
            }

            // The last swing state (time since last movement to put down) must have been
            // sufficiently long ago.
            if (now < mSwingTimestampNanos + PROPOSAL_MIN_TIME_SINCE_SWING_ENDED_NANOS) {
                return false;
            }

            // The last acceleration state must have been sufficiently long ago.
            if (now < mAccelerationTimestampNanos
                    + PROPOSAL_MIN_TIME_SINCE_ACCELERATION_ENDED_NANOS) {
                return false;
            }

            // The last touch must have ended sufficiently long ago.
            if (mTouched || now < mTouchEndedTimestampNanos
                    + PROPOSAL_MIN_TIME_SINCE_TOUCH_END_NANOS) {
                return false;
            }

PhoneWindowManager.java

MyOrientationListener

onProposedRotationChanged()  updateRotation

WindowManagerService.java

updateRotation()   updateRotationUnchecked()    updateRotationUncheckedLocked()   sendNewConfiguration() //activity重绘view

猜你喜欢

转载自blog.csdn.net/lf12345678910/article/details/53925707