当前位置: 移动技术网 > IT编程>开发语言>Java > Android Framework 常见解决方案(05)Android默认所有应用横屏 解决方案

Android Framework 常见解决方案(05)Android默认所有应用横屏 解决方案

2020年09月26日  | 移动技术网IT编程  | 我要评论
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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网