// LetterboxUiController.java voidupdateLetterboxSurface(WindowState winHint){ final WindowState w = mActivityRecord.findMainWindow(); if (w != winHint && winHint != null && w != null) { return; } // 对界面四周需要显示的 Layer 进行位置计算 layoutLetterbox(winHint); if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) { // 对 Surface 执行创建、参数设置等操作 mLetterbox.applySurfaceChanges(mActivityRecord.getSyncTransaction()); } }
voidlayoutLetterbox(WindowState winHint){ final WindowState w = mActivityRecord.findMainWindow(); if (w == null || winHint != null && w != winHint) { return; } updateRoundedCorners(w); updateWallpaperForLetterbox(w); // 是否进入 Letterbox 模式的关键判断 if (shouldShowLetterboxUi(w)) { if (mLetterbox == null) { // 把具体逻辑委托给 Letterbox mLetterbox = new Letterbox(() -> mActivityRecord.makeChildSurface(null), mActivityRecord.mWmService.mTransactionFactory, mLetterboxConfiguration::isLetterboxActivityCornersRounded, this::getLetterboxBackgroundColor, this::hasWallpaperBackgroudForLetterbox, this::getLetterboxWallpaperBlurRadius, this::getLetterboxWallpaperDarkScrimAlpha); mLetterbox.attachInput(w); } mActivityRecord.getPosition(mTmpPoint); // Get the bounds of the "space-to-fill". The transformed bounds have the highest // priority because the activity is launched in a rotated environment. In multi-window // mode, the task-level represents this. In fullscreen-mode, the task container does // (since the orientation letterbox is also applied to the task). final Rect transformedBounds = mActivityRecord.getFixedRotationTransformDisplayBounds(); final Rect spaceToFill = transformedBounds != null ? transformedBounds : mActivityRecord.inMultiWindowMode() ? mActivityRecord.getRootTask().getBounds() : mActivityRecord.getRootTask().getParent().getBounds(); // 位置计算 mLetterbox.layout(spaceToFill, w.getFrame(), mTmpPoint); } elseif (mLetterbox != null) { mLetterbox.hide(); } }