PhoneWindowManager.java的作用有很多,今天这里只讲一个,就是控制屏幕旋转90度
在这个类中有这个方法rotationForOrientationLw
if (mForceDefaultOrientation) {
return Surface.ROTATION_90; //90,180,270 改变这里就可以实现屏幕的旋转
}
要想从这个判断语句中进来,就需要将mForceDefaultOrientation的值设为true,在源码中前面有定义,初始值为false。
// Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
// http://developer.android.com/guide/practices/screens_support.html#range
mForceDefaultOrientation = true ;//longSizeDp >= 960 && shortSizeDp >= 720 &&
// res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
//For debug purposes the next line turns this feature off with:
// $ adb shell setprop config.override_forced_orient true
// $ adb shell wm size reset
// !"true".equals(SystemProperties.get("config.override_forced_orient"));
可以在上出标绿的地方将默认值设为true。
修改之前,setInitialDisplaySize这个方法中,如下:
// Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
// http://developer.android.com/guide/practices/screens_support.html#range
mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
//For debug purposes the next line turns this feature off with:
// $ adb shell setprop config.override_forced_orient true
// $ adb shell wm size reset
!"true".equals(SystemProperties.get("config.override_forced_orient"));