Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f667dce5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make DisplayCutout.{left,top,right,bottom} be Int's" into main

parents 68dec914 26dd7d7a
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -17,16 +17,22 @@
package com.android.systemui.common.ui.compose.windowinsets

import android.view.DisplayCutout as ViewDisplayCutout
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlin.math.abs

/** Represents the global position of the bounds for the display cutout for this display */
/**
 * Represents the global position of the bounds for the display cutout for this display.
 *
 * Important: The bounds are expressed in raw pixels (and not dips) because these bounds should be
 * used either during layout or drawing but *not* during composition. This is because insets are
 * computed after composition but before layout. Moreover, these insets can be animated and we don't
 * want to recompose every frame.
 */
data class DisplayCutout(
    val left: Dp = 0.dp,
    val top: Dp = 0.dp,
    val right: Dp = 0.dp,
    val bottom: Dp = 0.dp,
    val left: Int = 0,
    val top: Int = 0,
    val right: Int = 0,
    val bottom: Int = 0,
    val location: CutoutLocation = CutoutLocation.NONE,
    /**
     * The original `DisplayCutout` for the `View` world; only use this when feeding it back to a
@@ -34,8 +40,9 @@ data class DisplayCutout(
     */
    val viewDisplayCutoutKeyguardStatusBarView: ViewDisplayCutout? = null,
) {
    fun width() = abs(right.value - left.value).dp
    fun height() = abs(bottom.value - top.value).dp
    fun width() = abs(right - left).dp

    fun height() = abs(bottom - top).dp
}

enum class CutoutLocation {
+8 −14
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.android.internal.policy.ScreenDecorationsUtils

@@ -70,14 +69,14 @@ fun ScreenDecorProvider(windowInsets: () -> WindowInsets?, content: @Composable
private fun WindowInsets?.toCutout(context: Context): DisplayCutout {
    val boundingRect = this?.displayCutout?.boundingRectTop
    val width = boundingRect?.let { boundingRect.right - boundingRect.left } ?: 0
    val left = boundingRect?.left?.toDp(context) ?: 0.dp
    val top = boundingRect?.top?.toDp(context) ?: 0.dp
    val right = boundingRect?.right?.toDp(context) ?: 0.dp
    val bottom = boundingRect?.bottom?.toDp(context) ?: 0.dp
    val left = boundingRect?.left ?: 0
    val top = boundingRect?.top ?: 0
    val right = boundingRect?.right ?: 0
    val bottom = boundingRect?.bottom ?: 0
    val location =
        when {
            width <= 0f -> CutoutLocation.NONE
            left <= 0.dp -> CutoutLocation.LEFT
            width <= 0 -> CutoutLocation.NONE
            left <= 0 -> CutoutLocation.LEFT
            right >= getDisplayWidth(context) -> CutoutLocation.RIGHT
            else -> CutoutLocation.CENTER
        }
@@ -86,13 +85,8 @@ private fun WindowInsets?.toCutout(context: Context): DisplayCutout {
}

// TODO(b/298525212): remove once Compose exposes window inset bounds.
private fun Int.toDp(context: Context): Dp {
    return (this.toFloat() / context.resources.displayMetrics.density).dp
}

// TODO(b/298525212): remove once Compose exposes window inset bounds.
private fun getDisplayWidth(context: Context): Dp {
private fun getDisplayWidth(context: Context): Int {
    val point = Point()
    checkNotNull(context.display).getRealSize(point)
    return point.x.toDp(context)
    return point.x
}
+2 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.ShadeCarrierG
import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.composeWrapper
import com.android.systemui.statusbar.policy.Clock
import com.android.systemui.util.composable.kairos.ActivatedKairosSpec
import kotlin.math.max
import kotlin.math.roundToInt
import kotlinx.coroutines.delay

@@ -474,7 +475,7 @@ private fun CutoutAwareShadeHeader(

        val screenWidth = constraints.maxWidth
        val cutoutWidthPx = cutoutWidth.roundToPx()
        val height = max(cutoutHeight + (cutoutTop * 2), statusBarHeight).roundToPx()
        val height = max(cutoutHeight.roundToPx() + (cutoutTop * 2), statusBarHeight.roundToPx())
        val childConstraints = Constraints.fixed((screenWidth - cutoutWidthPx) / 2, height)

        val startMeasurable = measurables[0][0]
+1 −9
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.layoutId
@@ -259,13 +258,6 @@ private fun ContentScope.SingleShade(
    mediaHost.expansion = if (usingCollapsedLandscapeMedia && isLandscape()) COLLAPSED else EXPANDED

    var maxNotifScrimTop by remember { mutableIntStateOf(0) }
    val tileSquishiness by
        animateContentFloatAsState(
            value = 1f,
            key = QuickSettings.SharedValues.TilesSquishiness,
            canOverflow = false,
        )

    val shouldPunchHoleBehindScrim =
        layoutState.isTransitioningBetween(Scenes.Gone, Scenes.Shade) ||
            layoutState.isTransitioning(from = Scenes.Lockscreen, to = Scenes.Shade)
@@ -308,7 +300,7 @@ private fun ContentScope.SingleShade(
            )
        }

    Box() {
    Box(modifier) {
        Box(
            modifier =
                Modifier.fillMaxSize()