Merge "Letterbox: Add rounded corners above a taskbar." into sc-v2-dev am: d565317582

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15897595

Change-Id: I04629ebbd0a836e8bb48ba8fb6a2954cc4d50161
This commit is contained in:
Mariia Sandrikova
2021-09-24 23:33:16 +00:00
committed by Automerger Merge Worker
3 changed files with 56 additions and 16 deletions

View File

@@ -4856,8 +4856,8 @@
<item name="config_fixedOrientationLetterboxAspectRatio" format="float" type="dimen">0.0</item> <item name="config_fixedOrientationLetterboxAspectRatio" format="float" type="dimen">0.0</item>
<!-- Corners radius for activity presented the letterbox mode. Values < 0 will be ignored and <!-- Corners radius for activity presented the letterbox mode. Values < 0 will be ignored and
corners of the activity won't be rounded. --> min between device bottom corner radii will be used instead. -->
<integer name="config_letterboxActivityCornersRadius">0</integer> <integer name="config_letterboxActivityCornersRadius">-1</integer>
<!-- Blur radius for the Option 3 in R.integer.config_letterboxBackgroundType. Values < 0 are <!-- Blur radius for the Option 3 in R.integer.config_letterboxBackgroundType. Values < 0 are
ignored and 0 is used. --> ignored and 0 is used. -->

View File

@@ -174,7 +174,7 @@ final class LetterboxConfiguration {
* Whether corners of letterboxed activities are rounded. * Whether corners of letterboxed activities are rounded.
*/ */
boolean isLetterboxActivityCornersRounded() { boolean isLetterboxActivityCornersRounded() {
return getLetterboxActivityCornersRadius() > 0; return getLetterboxActivityCornersRadius() != 0;
} }
/** /**

View File

@@ -38,6 +38,9 @@ import android.graphics.Color;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Slog; import android.util.Slog;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.RoundedCorner;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction; import android.view.SurfaceControl.Transaction;
import android.view.WindowManager; import android.view.WindowManager;
@@ -295,31 +298,66 @@ final class LetterboxUiController {
} }
private void updateRoundedCorners(WindowState mainWindow) { private void updateRoundedCorners(WindowState mainWindow) {
int cornersRadius =
// Don't round corners if letterboxed only for display cutout.
shouldShowLetterboxUi(mainWindow)
&& !mainWindow.isLetterboxedForDisplayCutout()
? Math.max(0, mLetterboxConfiguration.getLetterboxActivityCornersRadius())
: 0;
setCornersRadius(mainWindow, cornersRadius);
}
private void setCornersRadius(WindowState mainWindow, int cornersRadius) {
final SurfaceControl windowSurface = mainWindow.getClientViewRootSurface(); final SurfaceControl windowSurface = mainWindow.getClientViewRootSurface();
if (windowSurface != null && windowSurface.isValid()) { if (windowSurface != null && windowSurface.isValid()) {
Transaction transaction = mActivityRecord.getSyncTransaction(); Transaction transaction = mActivityRecord.getSyncTransaction();
transaction.setCornerRadius(windowSurface, cornersRadius);
if (!isLetterboxedNotForDisplayCutout(mainWindow)
|| !mLetterboxConfiguration.isLetterboxActivityCornersRounded()) {
transaction
.setWindowCrop(windowSurface, null)
.setCornerRadius(windowSurface, 0);
return;
}
final InsetsState insetsState = mainWindow.getInsetsState();
final InsetsSource taskbarInsetsSource =
insetsState.getSource(InsetsState.ITYPE_EXTRA_NAVIGATION_BAR);
Rect cropBounds = new Rect(mActivityRecord.getBounds());
// Activity bounds are in screen coordinates while (0,0) for activity's surface control
// is at the top left corner of an app window so offsetting bounds accordingly.
cropBounds.offsetTo(0, 0);
// Rounded cornerners should be displayed above the taskbar.
cropBounds.bottom = Math.min(cropBounds.bottom, taskbarInsetsSource.getFrame().top);
transaction
.setWindowCrop(windowSurface, cropBounds)
.setCornerRadius(windowSurface, getRoundedCorners(insetsState));
} }
} }
// Returns rounded corners radius based on override in
// R.integer.config_letterboxActivityCornersRadius or min device bottom corner radii.
// Device corners can be different on the right and left sides but we use the same radius
// for all corners for consistency and pick a minimal bottom one for consistency with a
// taskbar rounded corners.
private int getRoundedCorners(InsetsState insetsState) {
if (mLetterboxConfiguration.getLetterboxActivityCornersRadius() >= 0) {
return mLetterboxConfiguration.getLetterboxActivityCornersRadius();
}
return Math.min(
getInsetsStateCornerRadius(insetsState, RoundedCorner.POSITION_BOTTOM_LEFT),
getInsetsStateCornerRadius(insetsState, RoundedCorner.POSITION_BOTTOM_RIGHT));
}
private int getInsetsStateCornerRadius(
InsetsState insetsState, @RoundedCorner.Position int position) {
RoundedCorner corner = insetsState.getRoundedCorners().getRoundedCorner(position);
return corner == null ? 0 : corner.getRadius();
}
private boolean isLetterboxedNotForDisplayCutout(WindowState mainWindow) {
return shouldShowLetterboxUi(mainWindow)
&& !mainWindow.isLetterboxedForDisplayCutout();
}
private void updateWallpaperForLetterbox(WindowState mainWindow) { private void updateWallpaperForLetterbox(WindowState mainWindow) {
@LetterboxBackgroundType int letterboxBackgroundType = @LetterboxBackgroundType int letterboxBackgroundType =
mLetterboxConfiguration.getLetterboxBackgroundType(); mLetterboxConfiguration.getLetterboxBackgroundType();
boolean wallpaperShouldBeShown = boolean wallpaperShouldBeShown =
letterboxBackgroundType == LETTERBOX_BACKGROUND_WALLPAPER letterboxBackgroundType == LETTERBOX_BACKGROUND_WALLPAPER
&& shouldShowLetterboxUi(mainWindow)
// Don't use wallpaper as a background if letterboxed for display cutout. // Don't use wallpaper as a background if letterboxed for display cutout.
&& !mainWindow.isLetterboxedForDisplayCutout() && isLetterboxedNotForDisplayCutout(mainWindow)
// Check that dark scrim alpha or blur radius are provided // Check that dark scrim alpha or blur radius are provided
&& (getLetterboxWallpaperBlurRadius() > 0 && (getLetterboxWallpaperBlurRadius() > 0
|| getLetterboxWallpaperDarkScrimAlpha() > 0) || getLetterboxWallpaperDarkScrimAlpha() > 0)
@@ -375,6 +413,8 @@ final class LetterboxUiController {
pw.println(prefix + " letterboxBackgroundType=" pw.println(prefix + " letterboxBackgroundType="
+ letterboxBackgroundTypeToString( + letterboxBackgroundTypeToString(
mLetterboxConfiguration.getLetterboxBackgroundType())); mLetterboxConfiguration.getLetterboxBackgroundType()));
pw.println(prefix + " letterboxCornerRadius="
+ getRoundedCorners(mainWin.getInsetsState()));
if (mLetterboxConfiguration.getLetterboxBackgroundType() if (mLetterboxConfiguration.getLetterboxBackgroundType()
== LETTERBOX_BACKGROUND_WALLPAPER) { == LETTERBOX_BACKGROUND_WALLPAPER) {
pw.println(prefix + " isLetterboxWallpaperBlurSupported=" pw.println(prefix + " isLetterboxWallpaperBlurSupported="