SystemUI中设置横竖屏显示

时间:2022-11-29 14:31:00

SystemUI中快捷菜单有 “方向锁定” 。

RotationLockTile

  protected void handleClick() {
if (mController == null) return;
MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
final boolean newState = !mState.value;
mController.setRotationLocked(!newState);//这里执行方向锁定
refreshState(newState);
}

RotationLockControllerImpl

  public void setRotationLocked(boolean locked) {
RotationPolicy.setRotationLock(mContext, locked);//执行方向锁定
}

这个快捷菜单只能在手机已经显示横屏或竖屏后,才能执行,无法预设锁定方向。

2,StatusBarWindowManager中设置锁屏横屏显示。

private void adjustScreenOrientation(State state) {

        if (state.isKeyguardShowingAndNotOccluded()) {
//注释掉源码中对方向的处理
// if (mKeyguardScreenRotation) {
// mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
// } else {
// mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
// }
mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; //指定锁屏模式下,固定横屏显示。
} else {
mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}
}