Android Framework 常见解决方案(05)Android默认所有应用横屏 解决方案
程序员文章站
2022-06-03 23:39:04
1 原理屏幕 旋转的配置进行 锁屏,通过修改PhoneWindowManager.java 来实现。2 解决方案在文件 frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 中做如下修改:@@ -2252,6 +2252,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { ......
1 原理
屏幕 旋转的配置进行 锁屏,通过修改 PhoneWindowManager.java 来实现。
2 解决方案
在文件 frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 中做如下修改:
@@ -2252,6 +2252,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
final Resources res = mContext.getResources();
int shortSize, longSize;
if (width > height) {
shortSize = height;
longSize = width;
@@ -7150,7 +7151,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
@Override
public int rotationForOrientationLw(int orientation, int lastRotation) {
- if (false) {
+ //Initialize the rotation angles for each orientation once.
+ Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+ if(d.getWidth() > d.getHeight()){
+ mPortraitRotation = Surface.ROTATION_0;
+ mLandscapeRotation = Surface.ROTATION_0;
+ mUpsideDownRotation = Surface.ROTATION_90;
+ mSeascapeRotation = Surface.ROTATION_180;
+ }
+ if (false) {
Slog.v(TAG, "rotationForOrientationLw(orient="
+ orientation + ", last=" + lastRotation
+ "); user=" + mUserRotation + " "
本文地址:https://blog.csdn.net/vviccc/article/details/108807350