直播app开发,系统之窗口横屏锁定以屏幕方向介绍

发布时间 2023-05-30 14:11:46作者: 云豹科技-苏凌霄

直播app开发,系统之窗口横屏锁定以屏幕方向介绍

android源码中通过PhoneWindowManager.java来管理窗口的显示,为WMS的一个主要部分。其源码地址如下:

 


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

PhoneWindowManager关于屏幕方向控制的主要代码如下:

 


    int mLandscapeRotation = 0;  // default landscape rotation
    int mSeascapeRotation = 0;   // "other" landscape rotation, 180 degrees from mLandscapeRotation
    int mPortraitRotation = 0;   // default portrait rotation
    int mUpsideDownRotation = 0; // "other" portrait rotation
@Override
    public void setInitialDisplaySize(Display display, int width, int height, int density) {
        ...代码省略
        final Resources res = mContext.getResources();
        int shortSize, longSize;
        if (width > height) {
            shortSize = height;
            longSize = width;
            mLandscapeRotation = Surface.ROTATION_0;
            mSeascapeRotation = Surface.ROTATION_180;
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mPortraitRotation = Surface.ROTATION_90;
                mUpsideDownRotation = Surface.ROTATION_270;
            } else {
                mPortraitRotation = Surface.ROTATION_270;
                mUpsideDownRotation = Surface.ROTATION_90;
            }
        } else {
            shortSize = width;
            longSize = height;
            mPortraitRotation = Surface.ROTATION_0;
            mUpsideDownRotation = Surface.ROTATION_180;
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mLandscapeRotation = Surface.ROTATION_270;
                mSeascapeRotation = Surface.ROTATION_90;
            } else {
                mLandscapeRotation = Surface.ROTATION_90;
                mSeascapeRotation = Surface.ROTATION_270;
            }
        }

 

 以上就是 直播app开发,系统之窗口横屏锁定以屏幕方向介绍,更多内容欢迎关注之后的文章