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

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

Merge "[flexiglass] Prevents crash when disable flags are set" into main

parents d60e4761 2ccd4af1
Loading
Loading
Loading
Loading
+27 −20
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.offset
import androidx.compose.ui.unit.offset
import androidx.compose.ui.util.fastFirst
import androidx.compose.ui.util.fastFirstOrNull
import androidx.compose.ui.util.fastFirstOrNull
import com.android.systemui.shade.ui.composable.SingleShadeMeasurePolicy.LayoutId
import com.android.systemui.shade.ui.composable.SingleShadeMeasurePolicy.LayoutId
import kotlin.math.max
import kotlin.math.max
@@ -60,18 +59,20 @@ class SingleShadeMeasurePolicy(


        val shadeHeaderPlaceable =
        val shadeHeaderPlaceable =
            measurables
            measurables
                .fastFirst { it.layoutId == LayoutId.ShadeHeader }
                .fastFirstOrNull { it.layoutId == LayoutId.ShadeHeader }
                .measure(constraintsWithCutout)
                ?.measure(constraintsWithCutout)
        val mediaPlaceable =
        val mediaPlaceable =
            measurables
            measurables
                .fastFirstOrNull { it.layoutId == LayoutId.Media }
                .fastFirstOrNull { it.layoutId == LayoutId.Media }
                ?.measure(applyMediaConstraints(constraintsWithCutout, isMediaInRow))
                ?.measure(applyMediaConstraints(constraintsWithCutout, isMediaInRow))
        val quickSettingsPlaceable =
        val quickSettingsPlaceable =
            measurables
            measurables
                .fastFirst { it.layoutId == LayoutId.QuickSettings }
                .fastFirstOrNull { it.layoutId == LayoutId.QuickSettings }
                .measure(constraintsWithCutout)
                ?.measure(constraintsWithCutout)
        val notificationsPlaceable =
        val notificationsPlaceable =
            measurables.fastFirst { it.layoutId == LayoutId.Notifications }.measure(constraints)
            measurables
                .fastFirstOrNull { it.layoutId == LayoutId.Notifications }
                ?.measure(constraints)


        val notificationsTop =
        val notificationsTop =
            calculateNotificationsTop(
            calculateNotificationsTop(
@@ -84,23 +85,25 @@ class SingleShadeMeasurePolicy(
        onNotificationsTopChanged(notificationsTop)
        onNotificationsTopChanged(notificationsTop)


        return layout(constraints.maxWidth, constraints.maxHeight) {
        return layout(constraints.maxWidth, constraints.maxHeight) {
            shadeHeaderPlaceable.placeRelative(x = insetsLeft, y = insetsTop)
            shadeHeaderPlaceable?.placeRelative(x = insetsLeft, y = insetsTop)
            quickSettingsPlaceable.placeRelative(
            val statusBarHeaderHeight = shadeHeaderPlaceable?.height ?: 0
            quickSettingsPlaceable?.placeRelative(
                x = insetsLeft,
                x = insetsLeft,
                y = insetsTop + shadeHeaderPlaceable.height,
                y = insetsTop + statusBarHeaderHeight,
            )
            )


            if (mediaPlaceable != null)
            if (mediaPlaceable != null) {
                val quickSettingsHeight = quickSettingsPlaceable?.height ?: 0

                if (isMediaInRow) {
                if (isMediaInRow) {
                    // mediaPlaceable height ranges from 0 to qsHeight. We want it to be centered
                    // mediaPlaceable height ranges from 0 to qsHeight. We want it to be centered
                    // vertically when it's smaller than the QS
                    // vertically when it's smaller than the QS
                    val mediaCenteringOffset =
                    val mediaCenteringOffset = (quickSettingsHeight - mediaPlaceable.height) / 2
                        (quickSettingsPlaceable.height - mediaPlaceable.height) / 2
                    mediaPlaceable.placeRelative(
                    mediaPlaceable.placeRelative(
                        x = insetsLeft + constraintsWithCutout.maxWidth / 2,
                        x = insetsLeft + constraintsWithCutout.maxWidth / 2,
                        y =
                        y =
                            insetsTop +
                            insetsTop +
                                shadeHeaderPlaceable.height +
                                statusBarHeaderHeight +
                                mediaCenteringOffset +
                                mediaCenteringOffset +
                                mediaOffset(),
                                mediaOffset(),
                        zIndex = mediaZIndex(),
                        zIndex = mediaZIndex(),
@@ -108,30 +111,34 @@ class SingleShadeMeasurePolicy(
                } else {
                } else {
                    mediaPlaceable.placeRelative(
                    mediaPlaceable.placeRelative(
                        x = insetsLeft,
                        x = insetsLeft,
                        y = insetsTop + shadeHeaderPlaceable.height + quickSettingsPlaceable.height,
                        y = insetsTop + statusBarHeaderHeight + quickSettingsHeight,
                        zIndex = mediaZIndex(),
                        zIndex = mediaZIndex(),
                    )
                    )
                }
                }
            }


            // Notifications don't need to accommodate for horizontal insets
            // Notifications don't need to accommodate for horizontal insets
            notificationsPlaceable.placeRelative(x = 0, y = notificationsTop)
            notificationsPlaceable?.placeRelative(x = 0, y = notificationsTop)
        }
        }
    }
    }


    private fun calculateNotificationsTop(
    private fun calculateNotificationsTop(
        statusBarHeaderPlaceable: Placeable,
        statusBarHeaderPlaceable: Placeable?,
        quickSettingsPlaceable: Placeable,
        quickSettingsPlaceable: Placeable?,
        mediaPlaceable: Placeable?,
        mediaPlaceable: Placeable?,
        insetsTop: Int,
        insetsTop: Int,
        isMediaInRow: Boolean,
        isMediaInRow: Boolean,
    ): Int {
    ): Int {
        val mediaHeight = mediaPlaceable?.height ?: 0
        val mediaHeight = mediaPlaceable?.height ?: 0
        val statusBarHeaderHeight = statusBarHeaderPlaceable?.height ?: 0
        val quickSettingsHeight = quickSettingsPlaceable?.height ?: 0

        return insetsTop +
        return insetsTop +
            statusBarHeaderPlaceable.height +
            statusBarHeaderHeight +
            if (isMediaInRow) {
            if (isMediaInRow) {
                max(quickSettingsPlaceable.height, mediaHeight)
                max(quickSettingsHeight, mediaHeight)
            } else {
            } else {
                quickSettingsPlaceable.height + mediaHeight
                quickSettingsHeight + mediaHeight
            }
            }
    }
    }