在android11 上实现平行视界效果

前言:

平行视界是谷歌为了解决大屏横屏设备 适配为手机等竖屏设备开发的APP , 在这类APP显示时 在横屏设备上不方便用户观看。

android 13 上平行视界的效果如下:

正文:

在android13前 ,各家有各自的解决方案,下面提供一种实现方案,如下:

frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java

  • // ---------#--------------#-----------

  • // | # # |

  • // | # # |

  • // | # # |

  • // | # # | 如果 显示器是横屏, app 是竖屏 , 则将显示的宽高 等比例缩放

  • // | # # |

  • // | # # |

  • // ---------#--------------#-----------

private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) {

// Use the effective "visual" dimensions based on current rotation

final int rotation = getRotation();

final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);

  • final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;

  • final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;

+// 如果 显示器是横屏, app 是竖屏 , 则将显示的宽高 等比例缩放

+// final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;

+// final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;

  • int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;

  • int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;

  • if( SystemProperties.getBoolean("persist.sys.landspace.display.portrait.app.enabled", false) ) {

  • int appOrientation = getOrientation();

  • if( rotated && appOrientation==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ){

  • dw = mBaseDisplayWidth*mBaseDisplayWidth/mBaseDisplayHeight;

  • dh = mBaseDisplayWidth;

  • Slog.d(TAG, "修改显示大小 dw "+dw +" dh "+dh );

  • }

  • }

// Update application display metrics.

final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(rotation);

final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();

@@ -4015,6 +4035,17 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

int height = displayInfo.logicalHeight;

int top = (physHeight - height) / 2;

out.set(left, top, left + width, top + height);

+// 在display 是横屏, app 是竖屏时 计算 window 的边框

  • if( SystemProperties.getBoolean("persist.sys.landspace.display.portrait.app.enabled", false) ) {

  • int appOrientation = getOrientation();

  • if( rotated && appOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ){

  • int appWidth = mBaseDisplayWidth*mBaseDisplayWidth/mBaseDisplayHeight;

  • int appHeight = mBaseDisplayWidth;

  • out.set(0, 0, appWidth, appHeight);

  • Slog.d(TAG, "计算window Bounds "+out);

  • }

  • }

}

frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java

@@ -1191,6 +1213,14 @@ public class DisplayRotation {

if (isAnyPortrait(preferredRotation)) {

return preferredRotation;

}

+// app 请求竖屏 ,display 修改返回横屏

  • if( SystemProperties.getBoolean("persist.sys.landspace.display.portrait.app.enabled", false) ) {

  • if( sensorRotation == Surface.ROTATION_90 ){

  • return mLandscapeRotation;

  • }else if( sensorRotation == Surface.ROTATION_270){

  • return mSeascapeRotation;

  • }

  • }

return mPortraitRotation;

case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:

相关推荐
虹科网络安全18 小时前
艾体宝干货|数据复制详解:类型、原理与适用场景
java·开发语言·数据库
axng pmje19 小时前
Java语法进阶
java·开发语言·jvm
汉克老师19 小时前
GESP2025年3月认证C++五级( 第三部分编程题(1、平均分配))
c++·算法·贪心算法·排序·gesp5级·gesp五级
rKWP8gKv719 小时前
Java微服务性能监控:Prometheus与Grafana集成方案
java·微服务·prometheus
老前端的功夫19 小时前
【Java从入门到入土】28:Stream API:告别for循环的新时代
java·开发语言·python
qq_4352879219 小时前
第9章 夸父逐日与后羿射日:死循环与进程终止?十个太阳同时值班的并行冲突
java·开发语言·git·死循环·进程终止·并行冲突·夸父逐日
小江的记录本19 小时前
【Kafka核心】架构模型:Producer、Broker、Consumer、Consumer Group、Topic、Partition、Replica
java·数据库·分布式·后端·搜索引擎·架构·kafka
yaoxin52112319 小时前
397. Java 文件操作基础 - 创建常规文件与临时文件
java·开发语言·python
前端摸鱼匠20 小时前
Vue 3 的v-bind合并行为:讲解v-bind与普通属性合并的规则
前端·javascript·vue.js·前端框架·ecmascript
REDcker20 小时前
浏览器端Web程序性能分析与优化实战 DevTools指标与工程清单
开发语言·前端·javascript·vue·ecmascript·php·js