在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:

相关推荐
Hello eveybody几秒前
介绍最大公因数和最小公约数(C++)
java·开发语言·c++
ckhcxy1 分钟前
抽象类和接口
java·开发语言
橘白3162 分钟前
GVHMR
人工智能·算法·机器人·机器人数据·视频动捕
Gerardisite2 分钟前
私域运营新利器:RPA驱动外部群多模态互动
java·人工智能·python·微信·自动化
宵时待雨3 分钟前
优选算法专题3:二分查找
数据结构·c++·算法·leetcode·职场和发展
代码飞一会儿4 分钟前
算法与数据结构之树——让数据查找更加迅速
算法
工业甲酰苯胺4 分钟前
2026 产业 AI 爆发:JNPF 助企业少走 3 年弯路
人工智能·算法·低代码
贾斯汀玛尔斯6 分钟前
每天学一个算法--最短路径问题与三类基本算法
算法
漫游的渔夫6 分钟前
RAG 落地 3 个月,我才发现排序(Rerank)比检索更重要
前端·人工智能
我头发多我先学6 分钟前
C++ AVL 树:平衡原理到完整实现(自平衡二叉搜索树)
开发语言·数据结构·c++·算法